Skip to content

Commit

Permalink
explain double read_pattern() in comment with ref to GH issue
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Jan 25, 2024
1 parent 05c788e commit e6ad078
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pymatgen/io/qchem/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ def __init__(self, filename: str):
temp_dict = read_pattern(
self.text,
{"final_energy": r"\s*Total\s+energy in the final basis set\s+=\s*([\d\-\.]+)"},
) or read_pattern(
) or read_pattern( # support Q-Chem 6.1.1+ (gh-3580)
self.text,
{"final_energy": r"\s+Total energy\s+=\s+([\d\-\.]+)"},
)

if temp_dict.get("final_energy") is not None:
self.data["final_energy"] = float(temp_dict.get("final_energy")[-1][0])
if e_final_match := temp_dict.get("final_energy"):
self.data["final_energy"] = float(e_final_match[-1][0])

# Check if calculation is using dft_d and parse relevant info if so
self.data["using_dft_d3"] = read_pattern(self.text, {"key": r"dft_d\s*= d3"}, terminate_on_match=True).get(
Expand Down
11 changes: 7 additions & 4 deletions tests/io/qchem/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
__maintainer__ = "Samuel Blau"
__email__ = "samblau1@gmail.com"

single_job_dict = loadfn(os.path.join(os.path.dirname(__file__), "single_job.json"))
multi_job_dict = loadfn(os.path.join(os.path.dirname(__file__), "multi_job.json"))
module_dir = os.path.dirname(__file__)
single_job_dict = loadfn(f"{module_dir}/single_job.json")
multi_job_dict = loadfn(f"{module_dir}/multi_job.json")

property_list = {
"errors",
Expand Down Expand Up @@ -523,8 +524,10 @@ def test_nbo_3_c(self):
assert perturb_ene[0]["perturbation energy"][3209] == 3.94

def test_qchem_6_1_1(self):
data = QCOutput(f"{TEST_FILES_DIR}/qchem/6.1.1.wb97xv.out.gz").data
assert data["final_energy"] == -76.43205015
qc_out = QCOutput(f"{TEST_FILES_DIR}/qchem/6.1.1.wb97xv.out.gz")
assert qc_out.data["final_energy"] == -76.43205015
n_vals = sum(1 for val in qc_out.data.values() if val is not None)
assert n_vals == 21


def test_gradient(tmp_path):
Expand Down

0 comments on commit e6ad078

Please sign in to comment.