Skip to content

Commit

Permalink
QCSchemaWriter: write MO coefficients and energies
Browse files Browse the repository at this point in the history
  • Loading branch information
berquist committed Feb 8, 2023
1 parent 7ec3f59 commit 9c3034e
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion cclib/io/qcschemawriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
)
from cclib.parser.utils import convertor, find_package

import numpy as np

_found_qcschema = find_package("qcschema")
if _found_qcschema:
import qcschema
Expand Down Expand Up @@ -81,9 +83,11 @@ def as_dict(self, validate=True):
# FIXME
method = "HF"

basis_set_name = metadata["basis_set"].lower()

qcschema_dict["model"] = {
"method": method.lower(),
"basis": metadata["basis_set"].lower(),
"basis": basis_set_name,
}

scf_total_energy = convertor(self.ccdata.scfenergies[-1], "eV", "hartree")
Expand Down Expand Up @@ -183,6 +187,44 @@ def as_dict(self, validate=True):
}
)

qcschema_dict["wavefunction"] = {
"basis": {"name": basis_set_name, "center_data": {}, "atom_map": []},
# TODO in latest schema version
# "restricted": bool,
}

has_beta = len(self.ccdata.homos) == 2

if hasattr(self.ccdata, "gbasis"):
pass

# FIXME Again, since we currently do not know if the (natural) orbital
# coefficients and eigenvalues come from diagonalizing a (correlated)
# density matrix, we assume that they are from SCF.
if hasattr(self.ccdata, "moenergies"):
qcschema_dict["wavefunction"]["scf_eigenvalues_a"] = self.ccdata.moenergies[
0
].tolist()
if has_beta:
qcschema_dict["wavefunction"][
"scf_eigenvalues_b"
] = self.ccdata.moenergies[1].tolist()

if hasattr(self.ccdata, "mocoeffs"):
mocoeffs_a = self.ccdata.mocoeffs[0]
# Sometimes we don't parse all MOs and fill missing ones with NaN,
# which isn't allowed by QCSchema.
if not np.isnan(mocoeffs_a).any():
qcschema_dict["wavefunction"]["scf_orbitals_a"] = (
mocoeffs_a.transpose().tolist()
)
if has_beta:
mocoeffs_b = self.ccdata.mocoeffs[1]
if not np.isnan(mocoeffs_b).any():
qcschema_dict["wavefunction"]["scf_orbitals_b"] = (
mocoeffs_b.transpose().tolist()
)

if driver == "energy":
return_result = return_energy
elif driver == "gradient":
Expand Down

0 comments on commit 9c3034e

Please sign in to comment.