# Cartesian internal coordinate converter

Hi,

Is there any psi4 python module that can directly convert between Cartesian and internal coordinate? I found in an output file, there is always a Cartesian coordinate. I would like to have something which just converts the coordinate, without doing the calculation.

Thank you very much.

1 Like

Not that I am aware of. In the future psi4 will switch to a python-based optimizer https://github.com/psi-rking/optking/tree/master/optking from the current C++ implementation.

Perhaps @Rollin_King could comment if pyoptking has a conversion function easily accessible?

Do you mean that you would just like to know the values of the internal coordinates of a molecule? Or do you want to do something more complex?

What I would like to have is, from internal to Cartesian, i.e., the input is an internal coordinate (including the elements, neighborhood information as in “”, O “2” 1.40, “1” 100.0, and the values, 1.40, 100.0) as in the example below, e.g.,

input

H
O 1 0.90
O 2 1.40 1 100.0
H 3 0.90 2 100.0 1 115.0

output

``````                       X                  Y                   Z
``````
``````------------   -----------------  -----------------  -----------------  -----------------
H            0.865344357633     0.737012462184     0.447995357691
O            0.102966517591     0.692385655726    -0.028227780300
O           -0.102966517591    -0.692385655726    -0.028227780300
H           -0.865344357633    -0.737012462184     0.447995357691
``````

without running the electronic structure calculation.

The opposite, input Cartesian output internal (including list of atoms, which one was used to label internal value), is also interesting, but less important to me.

Thank you very much.

If you just want the Cartesian coordinates for a given Z-matrix, the molecule object can handle it. this works:

``````molecule hooh {
H
O 1 0.90
O 2 1.40 1 100.0
H 3 0.90 2 100.0 1 115.0
}
set {
basis = cc-pvdz
}
hooh.print_out()``````
1 Like

I got one more question. By the following python code

import psi4
psi4.set_memory(‘500 MB’)
h2o = psi4.geometry("""
O
H 1 0.96
H 1 0.96 2 104.5
“”")
output = h2o.print_out()
print(type(output))
print(output)
#psi4.energy(‘scf/cc-pvdz’)

The output is

Memory set to 476.837 MiB by Python driver.
Molecular point group: c2v
Full point group: C2v
Geometry (in Angstrom), charge = 0, multiplicity = 1:
Center X Y Z Mass
------------ ----------------- ----------------- ----------------- -----------------
O 0.000000000000 0.000000000000 -0.065775570547 15.994914619570
H 0.000000000000 -0.759061990794 0.521953018286 1.007825032230
H 0.000000000000 0.759061990794 0.521953018286 1.007825032230
<class ‘NoneType’>
None

It seems I cannot get the output Cartesian coordinate into a python variable by output = h2o.print_out(), then subtract relevant information. How to further handle .print_out() results?

Thank you very much

Once the molecule object is constructed, you can access data on it using: https://psicode.org/psi4manual/master/psi4api.html#psi4.core.Molecule

Thanks. I tried

print( h2o.full_geometry() )

<psi4.core.Matrix object at 0x7f544d2def68>

still cannot access the data, it seems

To work with Matrix objects in NumPy, see the relevant page of the documentation.

Thanks for the link. I tried a bit the following code

import psi4
import numpy as np

# Build the Psi4 data objects

mat = psi4.Matrix(3, 3)
vec = psi4.Vector(3)

# Convert to a NumPy array

numpy_mat = np.array(mat)
numpy_vec = np.array(vec)

`psi4.core.Matrix`. The documentation is apparently out of date…