Skip to content

Commit

Permalink
Merge pull request #411 from arosen93/cclib-fix
Browse files Browse the repository at this point in the history
Fix encoding of input `Molecule` coordinates in cclib `TaskDocument`
  • Loading branch information
utf committed Jun 29, 2023
2 parents 72b78c7 + 4aca411 commit fbfe68f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/atomate2/common/schemas/cclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Type, TypeVar, Union

import numpy as np
from emmet.core.structure import MoleculeMetadata
from monty.dev import requires
from monty.json import jsanitize
Expand Down Expand Up @@ -163,9 +162,9 @@ def from_logfile(
cclib_obj.metadata.get("coord_type", None) == "xyz"
and cclib_obj.metadata.get("coords", None) is not None
):
coords_obj = np.array(cclib_obj.metadata["coords"])
input_species = [Element(e) for e in coords_obj[:, 0]]
input_coords = coords_obj[:, 1:].tolist()
coords_obj = cclib_obj.metadata["coords"]
input_species = [Element(row[0]) for row in coords_obj]
input_coords = [row[1:] for row in coords_obj]
input_molecule = Molecule(
input_species,
input_coords,
Expand Down
12 changes: 9 additions & 3 deletions tests/common/schemas/test_cclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ def test_cclib_taskdoc(test_dir):
assert "Could not parse" in str(e.value)

# Test a population analysis
doc = TaskDocument.from_logfile(p, ".out", analysis="MBO").dict()
doc = TaskDocument.from_logfile(p, "psi_test.out", analysis="MBO").dict()
assert doc["attributes"]["mbo"] is not None

# Let's try with two analysis (also check case-insensitivity)
doc = TaskDocument.from_logfile(p, ".out", analysis=["mbo", "density"]).dict()
doc = TaskDocument.from_logfile(
p, "psi_test.out", analysis=["mbo", "density"]
).dict()
assert doc["attributes"]["mbo"] is not None
assert doc["attributes"]["density"] is not None

Expand All @@ -75,7 +77,7 @@ def test_cclib_taskdoc(test_dir):
p / "psi_test.cube", "wb"
) as f_out:
shutil.copyfileobj(f_in, f_out)
doc = TaskDocument.from_logfile(p, ".out", analysis=["Bader"]).dict()
doc = TaskDocument.from_logfile(p, "psi_test.out", analysis=["Bader"]).dict()
os.remove(p / "psi_test.cube")
assert doc["attributes"]["bader"] is not None

Expand All @@ -89,6 +91,10 @@ def test_cclib_taskdoc(test_dir):
doc = TaskDocument.from_logfile(p, ".log", additional_fields={"test": "hi"})
assert doc.dict()["test"] == "hi"

# Test that the dict printing works
task = TaskDocument.from_logfile(p, "orca.out")
task.dict()

# test document can be jsanitized
d = jsanitize(doc, enum_values=True)

Expand Down
Binary file added tests/test_data/schemas/orca.out.gz
Binary file not shown.

0 comments on commit fbfe68f

Please sign in to comment.