Ok this one appears tough. The function you have mentioned is actually denoted by $Q$ and not by $P$. Let $$Q(q) = 1 + 240\sum_{n = 1}^{\infty}\frac{n^{3}q^{n}}{1 - q^{n}}$$ This is a kind of Eisentein series in modern language and is a modular form of weight $4$. The function is deeply connected with the theory of elliptic integrals/functions and theta functions.
Let $0 < k < 1$ and define $$k' = \sqrt{1 - k^{2}}, K = K(k) = \int_{0}^{\pi/2}\frac{dx}{\sqrt{1 - k^{2}\sin^{2}x}}, K' = K(k'), q = \exp\left(-\pi\frac{K'}{K}\right)$$ then it can be proved that $$Q(q) = \left(\frac{2K}{\pi}\right)^{4}\left(1 + 14k^{2} + k^{4}\right)$$ It is further known that the value of $k$ is algebraic if $q = e^{-\pi\sqrt{n}}$ where $n$ is a positive rational number.
You mention a specific value of $q$ such that $$\log q = -\frac{\pi}{x}\cdot 2^{2^{-k}\cdot n}$$ so that $$\frac{K'}{K} = \frac{2^{2^{-k}\cdot n}}{x}$$ and it appears that $x$ is real and $n$ is a positive integer in your question. Note that if $q = 0$ then $k = 0$ and $K = \pi/2$ so that $Q(q) = 1$. If we let $x \to 0^{+}$ in your formula the LHS becomes $Q(0) = 1$ and RHS is $0$. So definitely we can't have the formula valid for $x \to 0^{+}$. The evaluation of $Q(q)$ for values of $q$ other than $\exp(-\pi\sqrt{n})$ is really difficult. I wonder if there is a simple way to evaluate $Q(q)$ for some arbitrary value of $q$.
I am highly doubtful of a formula for $Q(q)$ which gives its value in closed form for all values of $q$ in a certain sub-interval of $(0, 1)$. Can you let us know how you arrived at this formula (or at least give some specific values of $k, n, x$ for which you think it is true)?
Also the values of $e^{\pi\sqrt{n}}$ being close to integer is not so much of a mystery as people think it is. See this question Approximation of $e^{\pi\sqrt{n}}$ using Ramanujan's Class Invariants