Skip to content

Commit

Permalink
added tests for frequency and molecule optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
rdguha1995 committed Jan 8, 2024
1 parent d1299d1 commit e304b50
Show file tree
Hide file tree
Showing 32 changed files with 75 additions and 15 deletions.
11 changes: 9 additions & 2 deletions tests/qchem/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ def check_qin(
ref_qin_path = ref_path / "inputs" / "mol.qin.gz"
ref_qin = QCInput.from_file(ref_qin_path)
script_directory = Path(__file__).resolve().parent
user_qin_path = script_directory / "mol.qin.gz"
user_qin = QCInput.from_file(user_qin_path)
# defaults = {"sym_ignore": True, "symmetry": False, "xc_grid": 3}
job_name = ref_path.stem
print(f"The job name is {job_name}")
if job_name == "water_single_point":
user_qin_path = script_directory / "sp.qin.gz"
elif job_name == "water_optimization":
user_qin_path = script_directory / "opt.qin.gz"
elif job_name == "water_frequency":
user_qin_path = script_directory / "freq.qin.gz"
user_qin = QCInput.from_file(user_qin_path)

keys_to_check = (
set(user_qin.as_dict()) if qin_settings is None else set(qin_settings)
Expand Down
Binary file added tests/qchem/freq.qin.gz
Binary file not shown.
79 changes: 66 additions & 13 deletions tests/qchem/jobs/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
from pathlib import Path

import numpy as np
from emmet.core.qc_tasks import TaskDoc

# from emmet.core.vasp.calculation import IonicStep, VaspObject
Expand All @@ -15,9 +16,7 @@
from pymatgen.core.structure import Molecule
from pytest import approx

from atomate2.qchem.jobs.core import (
SinglePointMaker,
)
from atomate2.qchem.jobs.core import FreqMaker, OptMaker, SinglePointMaker

curr_dir = Path(os.path.dirname(sys.argv[0]))

Expand All @@ -26,15 +25,14 @@

# Construct the full path
mol_path = curr_dir / file_name
H2O_structure = Molecule.from_file(mol_path)
# print(H2O_structure)
H2O_structure = Molecule.from_file(file_name)


def test_single_point_maker(mock_qchem, clean_dir, structure=H2O_structure):
# jstore = jobflow.SETTINGS.JOB_STORE

# mapping from job name to directory containing test files
ref_paths = {"single_point": "single_point"}
ref_paths = {"single_point": "water_single_point"}

# settings passed to fake_run_vasp; adjust these to check for certain INCAR settings
# fake_run_qchem_kwargs = {"single_point": {"qin_settings": None}}
Expand All @@ -45,19 +43,74 @@ def test_single_point_maker(mock_qchem, clean_dir, structure=H2O_structure):

# generate job
job = SinglePointMaker().make(structure)
print(job.__dict__)
print(job)

# run the flow or job and ensure that it finished running successfully
responses = run_locally(job, create_folders=True, ensure_success=True)

# validate job outputs
output1 = responses[job.uuid][1].output
print(output1.output)
assert isinstance(output1, TaskDoc)
assert output1.output.final_energy == approx(-76.4451488262)

# with jstore.additional_stores["data"] as s:
# doc = s.query_one({"job_uuid": job.uuid})
# dd = doc["data"]
# assert dd["@class"] == "Chgcar"

def test_opt_maker(mock_qchem, clean_dir, structure=H2O_structure):
ref_paths = {"optimization": "water_optimization"}
fake_run_qchem_kwargs = {}
mock_qchem(ref_paths, fake_run_qchem_kwargs)

job = OptMaker().make(structure)

responses = run_locally(job, create_folders=True, ensure_success=True)
opt_geometry = {
"@module": "pymatgen.core.structure",
"@class": "Molecule",
"charge": 0,
"spin_multiplicity": 1,
"sites": [
{
"name": "O",
"species": [{"element": "O", "occu": 1}],
"xyz": [-0.8001136722, 2.2241304324, -0.0128020517],
"properties": {},
"label": "O",
},
{
"name": "H",
"species": [{"element": "H", "occu": 1}],
"xyz": [0.1605037895, 2.195300528, 0.0211059581],
"properties": {},
"label": "H",
},
{
"name": "H",
"species": [{"element": "H", "occu": 1}],
"xyz": [-1.0782701173, 1.6278690395, 0.6883760935],
"properties": {},
"label": "H",
},
],
"properties": {},
}

output1 = responses[job.uuid][1].output
assert isinstance(output1, TaskDoc)
assert sorted(opt_geometry.items()) == sorted(
output1.output.optimized_molecule.as_dict().items()
)
assert output1.output.final_energy == approx(-76.450849061819)


def test_freq(mock_qchem, clean_dir, structure=H2O_structure):
ref_paths = {"frequency": "water_frequency"}
fake_run_qchem_kwargs = {}
mock_qchem(ref_paths, fake_run_qchem_kwargs)

job = FreqMaker().make(structure)

responses = run_locally(job, create_folders=True, ensure_success=True)
ref_freqs = np.array([1643.03, 3446.82, 3524.32])
output1 = responses[job.uuid][1].output
assert np.array_equal(
np.array(output1.calcs_reversed[0].output.frequencies), ref_freqs
)
assert output1.output.final_energy == approx(-76.449405011)
Binary file added tests/qchem/opt.qin.gz
Binary file not shown.
Binary file added tests/qchem/sp.qin.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit e304b50

Please sign in to comment.