Some beginner questions


I’m pretty new to Psi and quantum chemistry in general, and I have some starting questions:

  1. is it possible to read in an .xyz file for calculations? I found “qcdb.Molecule.init_with_xyz” but I don’t know how to use it for calculations!

  2. Is there a way to extract the MO - energies and write them to a separate file?

I searched the manual and documentation but didn’t find a proper answer to this,




I never used this functionality, but from the Psi4 manual you should be able to do
H2O = qcdb.Molecule.init_with_xyz('')
and then perform your computation on the water molecule.

I do not think there is a way to export the MO energies to a separate file. You should probably write a script to do that, I would advise to look into Python, it’s pretty easy to learn and can do everything you need. There is a lot of tutorials and help available on the Internet for Python.

For 2) you can do the following:

 ... normal input
scf_e, scf_wfn = energy('SCF', return_wfn=True)
eigvecs = scf_wfn.epsilon_a()

eigvecs is now a Psi4 Vector object which you can iterator over, print, and store using normal python techniques. You can also convert to a numpy array and save easily:

import numpy as np
np_eigvecs = np.array(eigvecs)'scf_eigenvalues.csv', np_eigvecs)

Hi and thanks for your answers,

@jgonthier exactly this does NOT work for me. The problem is that H20 is not a molecule object (pointer if you print it), it is just a simple string with all the information

@dgasmith Thanks a lot, this works fine for me, exactly what I was looking for :smile:

Oh, I see… Maybe @loriab has some insight?

Yeah, sorry, I should have noticed the above wouldn’t work. This is slightly more complicated than it ought to be b/c our internal C++ Molecule class doesn’t export its init_with_xyz to Python. But the below works and should orient you to what’s going on.

# read from XYZ file into a Molecule in the python qcdb.Molecule class
#   note that though not properly in the XYZ file spec, can convey charge/multiplicity here
#   contents of
#       4
#       1 1
#       O 0.0 0.0 0.0
#       H 1.0 0.0 0.0
#       H 0.0 1.0 0.0
#       H 0.0 0.0 1.0
qmol = qcdb.Molecule.init_with_xyz('')  

# create a Psi4 C++ class Molecule from that python Molecule
lmol = geometry(qmol.create_psi4_string_from_molecule())

# odd little line that does some initialization of the molecule
#   * if you're doing the above, then setting some options and running energy(),
#     then energy() will handle this step and you don't need this line and can 
#     comment it out
#   * but if you want to probe the molecule a bit *before* running energy(),
#     as we do in the next section by printing NRE, etc., then you *do* need
#     this line, otherwise your molecule will look empty ("No atoms in this molecule.")

# stuff you can do: print NRE to screen, print geometry to output file
print lmol.nuclear_repulsion_energy()

# more interesting stuff you can do: run SCF
set basis cc-pvdz

# just checking we get the same answers
compare_values(-76.28175456610472, get_variable('HF TOTAL ENERGY'), 5, 'HF E')

Thank you very much @jgonthier and @loriab, finally all my issues are solved.

You guys really did a great job with Psi4,