I'm studying the quantum chemistry calculation and now trying to implement the basic methods.
For example, given a water molecule, $M = {(\ce{O}, R_\ce{O}), (\ce{H}, R_\ce{H}), (\ce{H}, R_\ce{H})}$, where $R = [X, Y, Z]$ is the atomic position, the Cartesian Gaussian-type orbital $\psi$ on $r$, where $r = [x, y, z]$ is an arbitrary position, can be written as follows: $$\psi(r) = N (x-X)^l (y-Y)^m (z-Z)^n \exp(-\alpha ||r-R||^2),$$ where $N$ is the normalization term, $\alpha$ is the orbital exponent, and $||r-R||$ is the distance between $r$ and $R$. The term of $(x-X)^l (y-Y)^m (z-Z)^n$ is the Cartesian harmonics.
However, I believe that, because a water molecule can be described by any Cartesian coordinates if all the atomic distances (i.e., $\ce{O-H}$, $\ce{O-H}$, and $\ce{H-H}$) are correct, $\psi(r)$ can not be determined to a single value.
For example, the following two Cartesian coordinates represent the same water molecule.
O 0.00000 0.00000 0.11779
H 0.00000 0.75545 -0.47116
H 0.00000 -0.75545 -0.47116
O -0.034 0.978 0.0076
H 0.065 0.021 0.0015
H 0.87 1.30 0.00069
However, $\psi(r)$ is different because the above equation has the term of $(x-X)^l (y-Y)^m (z-Z)^n$. If the equation has only the distance term (i.e., $\exp(-\alpha ||r-R||^2)$), $\psi(r)$ has always the same value and I can implement this very easily only using the distance matrix.
How can I deal with this problem and implement the Cartesian harmonics?
Postscript: Of course, I know the spherical harmonics but I believe that even if the angles, θ and φ, are used, the problem is the same; how can I determine the θ and φ or the orientation of the 2px (2py or 2pz) orbital of each atom in a molecule? For example, in the following figure, specifically how can I determine the 2px of the H orbital in a water molecule? Of course, I know the 2px (2py or 2pz) is along with the H-O bond in this case; however, how can I determine the θ, φ, and orientation of 2px, 2py, and 2pz orbitals of each atom in arbitrary other more complex molecule and calculate the LCAO?