Psi4 .xyz reading/writing

Hi all,

I’m running into an issue when I’m loading an .xyz file into psi4 due to the differences after the decimal place for the coordinates. The below code returns a slightly differently positioned molecule than the initial input and I was wondering if there was a way to get a more precise match to the original?

import psi4

with open(“UPIRUI_uff_psi4.xyz”,“r”) as xyz_f:
xyz = xyz_f.read()

print(xyz)
psi4_mol = psi4.geometry(xyz)
print(psi4_mol.save_string_xyz())

UPIRUI_uff_psi4.xyz (2.3 KB)

UPIRUI_output_print.txt (4.4 KB)

This is terminal output for the above.

For future, please read our guidance on asking questions, and follow it. Your code isn’t properly formatted.

As for your actual question: This is a consequence of Psi shifting the origin of the coordinate system to the center of mass. I can disable it by adding “nocom” to the end of your output file, but then I also need to remove the first two lines of the xyz file (number of atoms and molecule name) when I do that. Behind-the-scenes, specifying “nocom” changes the rules for how the molecule string is parsed.

Whether there’s a way to specify nocom while staying closer to xyz format is a question for @loriab.

Seconding @jmisiewicz on why the geometry is adjusting to Psi4’s internal standard orientation.

For this, I’d read the file into a string (e.g., with open(xyzfile) as fp: mstr = fp.read()) and then create the mol with from_string. The filetype xyz+ is optional here, and the au on the first line just helps show the preservation of coords since .geometry() always returns in bohr. The fix_ flags are what you’re after. Note that you’ll have to activate(mol) or pass it in via energy(..., molecule=mol) since this procedure doesn’t activate the mol to run in any future calcs as the line psi4.geometry(mstr) you had does.

import psi4

mstr = """
3 au
stuff
O 4 4 4
H 3 4 4
H 4 3 4
"""

mol = psi4.Molecule.from_string(mstr, dtype="xyz+")
print(mol.geometry().np)

mol = psi4.Molecule.from_string(mstr, dtype="xyz+", fix_com=True, fix_orientation=True)
print(mol.geometry().np)

mol = psi4.Molecule.from_string(mstr, fix_com=True, fix_orientation=True)
print(mol.geometry().np)

output:

[[ 0.00000000e+00  0.00000000e+00  7.91357658e-02]
 [-7.07106781e-01 -2.16489014e-17 -6.27971015e-01]
 [ 7.07106781e-01  2.16489014e-17 -6.27971015e-01]]
[[4. 4. 4.]
 [3. 4. 4.]
 [4. 3. 4.]]
[[4. 4. 4.]
 [3. 4. 4.]
 [4. 3. 4.]]

Apologies for the formatting but thank you for your responses, adding the fix_'s has sorted my problem.

1 Like