Skip to content

Commit

Permalink
Move pymatgen import to get_primitive() function
Browse files Browse the repository at this point in the history
  • Loading branch information
ralf-meyer committed Dec 17, 2023
1 parent 91d0b45 commit 450c8dd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
5 changes: 2 additions & 3 deletions molSimplify/Informatics/MOF/MOF_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@

### Defining pymatgen function for getting primitive, since molSimplify does not depend on pymatgen.
# This function is commented out and should be uncommented if used.
from pymatgen.io.cif import CifParser


def get_primitive(datapath, writepath, occupancy_tolerance=1):
Expand All @@ -75,10 +74,10 @@ def get_primitive(datapath, writepath, occupancy_tolerance=1):
None
"""

from pymatgen.io.cif import CifParser

Check warning on line 77 in molSimplify/Informatics/MOF/MOF_descriptors.py

View check run for this annotation

Codecov / codecov/patch

molSimplify/Informatics/MOF/MOF_descriptors.py#L77

Added line #L77 was not covered by tests
s = CifParser(datapath, occupancy_tolerance=occupancy_tolerance).get_structures()[0]
sprim = s.get_primitive_structure()
sprim.to("cif", writepath) # Output structure to a file.
sprim.to(writepath, "cif") # Output structure to a file.

Check warning on line 80 in molSimplify/Informatics/MOF/MOF_descriptors.py

View check run for this annotation

Codecov / codecov/patch

molSimplify/Informatics/MOF/MOF_descriptors.py#L80

Added line #L80 was not covered by tests


'''<<<< END OF CODE TO COMPUTE PRIMITIVE UNIT CELLS >>>>'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
# This MOF RAC generator assumes that pymatgen is installed. #
# Pymatgen is used to get the primitive cell. #
#########################################################################################
from pymatgen.io.cif import CifParser


def get_primitive(datapath, writepath):
from pymatgen.io.cif import CifParser

Check warning on line 29 in molSimplify/Informatics/MOF/MOF_descriptors_alternate_functional.py

View check run for this annotation

Codecov / codecov/patch

molSimplify/Informatics/MOF/MOF_descriptors_alternate_functional.py#L29

Added line #L29 was not covered by tests
s = CifParser(datapath, occupancy_tolerance=1).get_structures()[0]
sprim = s.get_primitive_structure()
sprim.to("cif",writepath)
sprim.to("cif", writepath)

Check warning on line 32 in molSimplify/Informatics/MOF/MOF_descriptors_alternate_functional.py

View check run for this annotation

Codecov / codecov/patch

molSimplify/Informatics/MOF/MOF_descriptors_alternate_functional.py#L32

Added line #L32 was not covered by tests


'''<<<< END OF CODE TO COMPUTE PRIMITIVE UNIT CELLS >>>>'''

#########################################################################################
Expand Down
2 changes: 1 addition & 1 deletion molSimplify/Informatics/MOF/cluster_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
# This MOF RAC generator assumes that pymatgen is installed. #
# Pymatgen is used to get the primitive cell. #
#########################################################################################
from pymatgen.io.cif import CifParser


def get_primitive(datapath, writepath):
from pymatgen.io.cif import CifParser

Check warning on line 25 in molSimplify/Informatics/MOF/cluster_extraction.py

View check run for this annotation

Codecov / codecov/patch

molSimplify/Informatics/MOF/cluster_extraction.py#L25

Added line #L25 was not covered by tests
s = CifParser(datapath, occupancy_tolerance=1).get_structures()[0]
sprim = s.get_primitive_structure()
sprim.to("cif", writepath)
Expand Down
8 changes: 4 additions & 4 deletions tests/informatics/test_MOF_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ def RACs_names(starts, properties, depth, scope="all"):


@pytest.mark.parametrize(
"name",
"cif_file",
["odac-21383.cif",
"odac-21433.cif",
"odac-21478.cif",
"odac-21735.cif",
"odac-21816.cif"])
def test_get_MOF_descriptors(resource_path_root, tmpdir, name, ref_names):
def test_get_MOF_descriptors(resource_path_root, tmpdir, cif_file, ref_names):
with DebugTimer("get_MOF_descriptors()"):
full_names, full_descriptors = get_MOF_descriptors(
str(resource_path_root / "inputs" / "cif_files" / name),
str(resource_path_root / "inputs" / "cif_files" / cif_file),
depth=3,
path=str(tmpdir),
xyzpath=str(tmpdir / "test.xyz"),
Gval=True,
)

with open(resource_path_root / "refs" / "MOF_descriptors"
/ name.replace("cif", "json"), "r") as fin:
/ cif_file.replace("cif", "json"), "r") as fin:
ref = json.load(fin)

assert full_names == ref_names
Expand Down

0 comments on commit 450c8dd

Please sign in to comment.