Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding of input Molecule coordinates in cclib TaskDocument #411

Merged
merged 8 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading