def make_qc_input(qchem: QChem, atoms: Atoms) -> QCInput:
"""
Make a QCInput object. It will, by default, create a QCInput from the QChem
calculator kwargs. If `qchem.qchem_dict_set_params` is specified, it will create a
QCInput from a QChemDictSet, merging the two QCInput objects and taking the latter
as higher priority.
Parameters
----------
qchem
The QChem object.
Returns
-------
QCInput
The QCInput object.
"""
atoms.charge = qchem.charge # type: ignore[attr-defined]
atoms.spin_multiplicity = qchem.spin_multiplicity # type: ignore[attr-defined]
molecule = AseAtomsAdaptor().get_molecule(atoms)
if qchem.qchem_dict_set_params:
# Get minimal parameters needed to instantiate a QChemDictSet
if "molecule" in qchem.qchem_dict_set_params:
msg = "Do not specify `molecule` in `qchem_dict_set_params`"
raise NotImplementedError(msg)
if "job_type" not in qchem.qchem_dict_set_params and qchem.rem.get("job_type"):
qchem.qchem_dict_set_params["job_type"] = qchem.rem["job_type"]
if "basis_set" not in qchem.qchem_dict_set_params and qchem.rem.get("basis"):
qchem.qchem_dict_set_params["basis_set"] = qchem.rem["basis"]
if "scf_algorithm" not in qchem.qchem_dict_set_params and qchem.rem.get(
"scf_algorithm"
):
qchem.qchem_dict_set_params["scf_algorithm"] = qchem.rem["scf_algorithm"]
if "qchem_version" not in qchem.qchem_dict_set_params:
qchem.qchem_dict_set_params["qchem_version"] = 6
# Make QChemDictSet
qc_dict_set = QChemDictSet(molecule, **qchem.qchem_dict_set_params)
for prop in [
"rem",
"opt",
"pcm",
"solvent",
"smx",
"scan",
"van_der_waals",
"plots",
"nbo",
"geom_opt",
"svp",
"pcm_nonels",
]:
prop1 = getattr(qchem, prop)
if prop2 := getattr(qc_dict_set, prop):
setattr(qchem, prop, recursive_dict_merge(prop2, prop1))
for prop in ["vdw_mode", "cdft", "almo_coupling"]:
prop2 = getattr(qc_dict_set, prop)
if prop2 and not prop1:
setattr(qchem, prop, prop2)
qchem.rem = sort_dict(
get_rem_swaps(qchem.rem, restart=qchem.prev_orbital_coeffs is not None)
)
return QCInput(
molecule,
qchem.rem,
opt=qchem.opt,
pcm=qchem.pcm,
solvent=qchem.solvent,
smx=qchem.smx,
scan=qchem.scan,
van_der_waals=qchem.van_der_waals,
vdw_mode=qchem.vdw_mode,
plots=qchem.plots,
nbo=qchem.nbo,
geom_opt=qchem.geom_opt,
cdft=qchem.cdft,
almo_coupling=qchem.almo_coupling,
svp=qchem.svp,
pcm_nonels=qchem.pcm_nonels,
)