Skip to content

Commit

Permalink
Move qcschem.py. Add nmo check.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajjenkins1 committed Nov 28, 2024
1 parent 6aa731d commit 8decebc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
1 change: 0 additions & 1 deletion pyscf/lib/test/qcschema_result.json

This file was deleted.

29 changes: 20 additions & 9 deletions pyscf/lib/libqcschema.py → pyscf/tools/qcschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def load_qcschema_molecule(qcschema_dict, to_Angstrom=False, xyz=False, mol_sele
= 2 initial_molecule in GO or traj qcschema
= 3 final_molecule in GO or traj qcschema
= 4 a specific step in the GO or traj qcschema, specify with 'step' arg.
step: for geometry optimization or trajectory, which have mutliple molecules in a qcschema output.
This specifies which step to load the molecule from.
to_Angstrom (optional): convert coordinates to Angstrom (default is Bohr)
xyz (optional): controls output (see below)
Expand Down Expand Up @@ -130,7 +131,7 @@ def load_qcschema_scf_info(qcschema_dict):
'''

# Restricted wfn has schema scf_occupations_a occ of 1 or 0.
# Need to double if RHF/RKS/ROHF
# Need to double if rhf/rks/rohf
method = qcschema_dict["keywords"]["scf"]["method"]
if(method == 'rks' or method == 'roks' or method == 'rhf' or method == 'rohf'):
OccFactor = 2.0
Expand All @@ -141,13 +142,23 @@ def load_qcschema_scf_info(qcschema_dict):
elif(method == 'gks' or method == 'ghf'):
OccFactor = 1.0
have_beta = False
else:
raise RuntimeError('qcschema: cannot determine method..exit')
return

# Need to reshape MO coefficients for PySCF shape.
# NOTE: assumes NMO=NAO which isn't the case if linear dependencies etc.
nmo = qcschema_dict["properties"]["calcinfo_nbasis"]
nao = nmo

# Get the 4 things that PySCF wants
# need to reshape MO coefficients for PySCF shape.
nao = qcschema_dict["properties"]["calcinfo_nbasis"]
# nmo info often missing
try:
nmo = qcschema_dict["properties"]["calcinfo_nmo"]
except:
# key not provided..so we make an assumption
# note: assumes nmo=nao which isn't the case if linear dependencies etc.
# ..so may give error when reading coeffs
nmo = nao
assert nmo == nao

# get the 4 things that PySCF wants
# ...remembering to reshape coeffs and scale occupancies.
e_tot = float( qcschema_dict["properties"]["return_energy"] )
mo_coeff = np.reshape(qcschema_dict["wavefunction"]["scf_orbitals_a"],(nao,nmo))
Expand All @@ -167,7 +178,7 @@ def load_qcschema_scf_info(qcschema_dict):
mo_energy = np.vstack( (mo_energy, mo_energy_beta) )
# etot obviously doesn't need manipulation

# Convert to dictionary for PySCF
# convert to dictionary for PySCF
scf_dic = {'e_tot' : e_tot,
'mo_energy': mo_energy,
'mo_occ' : mo_occ,
Expand Down
Loading

0 comments on commit 8decebc

Please sign in to comment.