Skip to content

Commit

Permalink
Add test case for MOFs from Aditya's JACS paper
Browse files Browse the repository at this point in the history
  • Loading branch information
ralf-meyer committed Dec 20, 2023
1 parent 93fbfe2 commit c33449c
Show file tree
Hide file tree
Showing 25 changed files with 1,250 additions and 24 deletions.
105 changes: 81 additions & 24 deletions tests/informatics/test_MOF_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,40 @@
import json
import numpy as np
import pandas as pd
from molSimplify.Informatics.MOF.MOF_descriptors import get_MOF_descriptors
from molSimplify.Informatics.MOF.MOF_descriptors import get_MOF_descriptors, get_primitive

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'get_primitive' is not used.
from molSimplify.utils.timer import DebugTimer


@pytest.fixture
def RACs_names(depth=3):

def generate_names(starts, properties, depth, scope="all"):
names = []
for start in starts:
for prop in properties:
for d in range(depth + 1):
if scope is None:
names.append(f"{start}-{prop}-{d}")
else:
names.append(f"{start}-{prop}-{d}-{scope}")
return names
def ref_names():
def RACs_names(depth=3, Gval=True, alpha=True):

def generate_names(starts, properties, depth, scope="all"):
names = []
for start in starts:
for prop in properties:
for d in range(depth + 1):
if scope is None:
names.append(f"{start}-{prop}-{d}")
else:
names.append(f"{start}-{prop}-{d}-{scope}")
return names

properties = ["chi", "Z", "I", "T", "S", "Gval"]
properties = ["chi", "Z", "I", "T", "S"]
if Gval:
properties.append("Gval")

names = generate_names(["f", "mc", "D_mc"], properties, depth)
# f-lig does not include the "scope"
names.extend(generate_names(["f-lig"], properties, depth, scope=None))
names = generate_names(["f", "mc", "D_mc"], properties, depth)
# f-lig does not include the "scope"
names.extend(generate_names(["f-lig"], properties, depth, scope=None))

# Same for the starts that include the additional property alpha
properties.append("alpha")
names.extend(
generate_names(["lc", "D_lc", "func", "D_func"], properties, depth))
return names
# Same for the starts that include the additional property alpha
if alpha:
properties.append("alpha")
names.extend(
generate_names(["lc", "D_lc", "func", "D_func"], properties, depth))
return names
return RACs_names


@pytest.mark.parametrize(
Expand All @@ -42,7 +47,7 @@ def generate_names(starts, properties, depth, scope="all"):
"odac-21735",
"odac-21816",
])
def test_get_MOF_descriptors(resource_path_root, tmpdir, name, RACs_names):
def test_get_MOF_descriptors_ODAC(resource_path_root, tmpdir, name, ref_names):
# NOTE All the .cif files were converted to primitive unit cell using the
# MOF_descriptors.get_primitive() function

Expand All @@ -59,7 +64,7 @@ def test_get_MOF_descriptors(resource_path_root, tmpdir, name, RACs_names):
/ name / f"{name}.json", "r") as fin:
ref = json.load(fin)

assert full_names == RACs_names
assert full_names == ref_names()
np.testing.assert_allclose(full_descriptors, ref["descriptors"], atol=1e-6)

lc_descriptors = pd.read_csv(tmpdir / "lc_descriptors.csv")
Expand All @@ -69,3 +74,55 @@ def test_get_MOF_descriptors(resource_path_root, tmpdir, name, RACs_names):
sbu_descriptors = pd.read_csv(tmpdir / "sbu_descriptors.csv")
sbu_ref = pd.read_csv(resource_path_root / "refs" / "MOF_descriptors" / name / "sbu_descriptors.csv")
assert all(sbu_descriptors == sbu_ref)


@pytest.mark.parametrize(
"name",
[
"FOKYIP_clean",
"SETDUS_clean",
"UXUPEK_clean",
"NEXXIZ_clean",
# "ETECIR_clean",
# "FAVGUH_clean", Disagreement on all ligand center RACs
"YICDAR_clean",
"VONBIK_clean",
])
def test_get_MOF_descriptors_JACS(resource_path_root, tmpdir, name, ref_names):
"""
Tests a handful of the MOFs used in
Nandy et al., J. Am. Chem. Soc. 2021, 143, 42, 17535-17547
https://doi.org/10.1021/jacs.1c07217
"""
# NOTE All the .cif files were converted to primitive unit cell using the
# MOF_descriptors.get_primitive() function

with DebugTimer("get_MOF_descriptors()"):
full_names, full_descriptors = get_MOF_descriptors(
str(resource_path_root / "inputs" / "cif_files" / f"{name}.cif"),
depth=3,
path=str(tmpdir),
xyzpath=str(tmpdir / "test.xyz"),
Gval=False,
)

with open(resource_path_root / "refs" / "MOF_descriptors"
/ name / f"{name}.json", "r") as fin:
ref = json.load(fin)

# For now we are using a workaround because polarization descriptors
# are now added by default.
# Here they should be compared to ref_names(Gval=False, alpha=False)
assert full_names == ref_names(Gval=False, alpha=True)
np.testing.assert_allclose(
# Get only the subset of descriptors without the property alpha
[d for d, n in zip(full_descriptors, full_names) if "alpha" not in n],
ref["descriptors"], atol=1e-6)

lc_descriptors = pd.read_csv(tmpdir / "lc_descriptors.csv")
lc_ref = pd.read_csv(resource_path_root / "refs" / "MOF_descriptors" / name / "lc_descriptors.csv")
assert all(lc_descriptors == lc_ref)

sbu_descriptors = pd.read_csv(tmpdir / "sbu_descriptors.csv")
sbu_ref = pd.read_csv(resource_path_root / "refs" / "MOF_descriptors" / name / "sbu_descriptors.csv")
assert all(sbu_descriptors == sbu_ref)
142 changes: 142 additions & 0 deletions tests/testresources/inputs/cif_files/FOKYIP_clean.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# generated using pymatgen
data_NdH7(C5O2)3
_symmetry_space_group_name_H-M 'P 1'
_cell_length_a 13.68320000
_cell_length_b 13.75910000
_cell_length_c 14.21196035
_cell_angle_alpha 118.95140427
_cell_angle_beta 97.82313437
_cell_angle_gamma 90.00000000
_symmetry_Int_Tables_number 1
_chemical_formula_structural NdH7(C5O2)3
_chemical_formula_sum 'Nd4 H28 C60 O24'
_cell_volume 2312.78840258
_cell_formula_units_Z 4
loop_
_symmetry_equiv_pos_site_id
_symmetry_equiv_pos_as_xyz
1 'x, y, z'
loop_
_atom_site_type_symbol
_atom_site_label
_atom_site_symmetry_multiplicity
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
Nd Nd0 1 0.53886000 0.61409000 0.66014000 1.0
Nd Nd1 1 0.96114000 0.95395000 0.33986000 1.0
Nd Nd2 1 0.46114000 0.38591000 0.33986000 1.0
Nd Nd3 1 0.03886000 0.04605000 0.66014000 1.0
H H4 1 0.41200000 0.82990000 0.01580000 1.0
H H5 1 0.37210000 0.86050000 0.18020000 1.0
H H6 1 0.38310000 0.53660000 0.08760000 1.0
H H7 1 0.42170000 0.50620000 0.92320000 1.0
H H8 1 0.24470000 0.83310000 0.26440000 1.0
H H9 1 0.31480000 0.83410000 0.54860000 1.0
H H10 1 0.44190000 0.62950000 0.29080000 1.0
H H11 1 0.08800000 0.81410000 0.98420000 1.0
H H12 1 0.12790000 0.68030000 0.81980000 1.0
H H13 1 0.11690000 0.44900000 0.91240000 1.0
H H14 1 0.07830000 0.58300000 0.07680000 1.0
H H15 1 0.25530000 0.56870000 0.73560000 1.0
H H16 1 0.18520000 0.28550000 0.45140000 1.0
H H17 1 0.05810000 0.33870000 0.70920000 1.0
H H18 1 0.58800000 0.17010000 0.98420000 1.0
H H19 1 0.62790000 0.13950000 0.81980000 1.0
H H20 1 0.61690000 0.46340000 0.91240000 1.0
H H21 1 0.57830000 0.49380000 0.07680000 1.0
H H22 1 0.75530000 0.16690000 0.73560000 1.0
H H23 1 0.68520000 0.16590000 0.45140000 1.0
H H24 1 0.55810000 0.37050000 0.70920000 1.0
H H25 1 0.91200000 0.18590000 0.01580000 1.0
H H26 1 0.87210000 0.31970000 0.18020000 1.0
H H27 1 0.88310000 0.55100000 0.08760000 1.0
H H28 1 0.92170000 0.41700000 0.92320000 1.0
H H29 1 0.74470000 0.43130000 0.26440000 1.0
H H30 1 0.81480000 0.71450000 0.54860000 1.0
H H31 1 0.94190000 0.66130000 0.29080000 1.0
C C32 1 0.46206000 0.64384000 0.85110000 1.0
C C33 1 0.42455000 0.66336000 0.95322000 1.0
C C34 1 0.40720000 0.77099000 0.03018000 1.0
C C35 1 0.38260000 0.78861000 0.12842000 1.0
C C36 1 0.37304000 0.70268000 0.15222000 1.0
C C37 1 0.38877000 0.59593000 0.07406000 1.0
C C38 1 0.41298000 0.57838000 0.97580000 1.0
C C39 1 0.35106000 0.73052000 0.26256000 1.0
C C40 1 0.28095000 0.80681000 0.30654000 1.0
C C41 1 0.26459000 0.84423000 0.41370000 1.0
C C42 1 0.32109000 0.80561000 0.47576000 1.0
C C43 1 0.38686000 0.72494000 0.43014000 1.0
C C44 1 0.40002000 0.68586000 0.32234000 1.0
C C45 1 0.18486000 0.92266000 0.45704000 1.0
C C46 1 0.44081000 0.68159000 0.49910000 1.0
C C47 1 0.03794000 0.79274000 0.14890000 1.0
C C48 1 0.07545000 0.71014000 0.04678000 1.0
C C49 1 0.09280000 0.74081000 0.96982000 1.0
C C50 1 0.11740000 0.66019000 0.87158000 1.0
C C51 1 0.12696000 0.55046000 0.84778000 1.0
C C52 1 0.11123000 0.52187000 0.92594000 1.0
C C53 1 0.08702000 0.60258000 0.02420000 1.0
C C54 1 0.14894000 0.46796000 0.73744000 1.0
C C55 1 0.21905000 0.50027000 0.69346000 1.0
C C56 1 0.23541000 0.43053000 0.58630000 1.0
C C57 1 0.17891000 0.32985000 0.52424000 1.0
C C58 1 0.11314000 0.29480000 0.56986000 1.0
C C59 1 0.09998000 0.36352000 0.67766000 1.0
C C60 1 0.31514000 0.46562000 0.54296000 1.0
C C61 1 0.05919000 0.18249000 0.50090000 1.0
C C62 1 0.53794000 0.35616000 0.14890000 1.0
C C63 1 0.57545000 0.33664000 0.04678000 1.0
C C64 1 0.59280000 0.22901000 0.96982000 1.0
C C65 1 0.61740000 0.21139000 0.87158000 1.0
C C66 1 0.62696000 0.29732000 0.84778000 1.0
C C67 1 0.61123000 0.40407000 0.92594000 1.0
C C68 1 0.58702000 0.42162000 0.02420000 1.0
C C69 1 0.64894000 0.26948000 0.73744000 1.0
C C70 1 0.71905000 0.19319000 0.69346000 1.0
C C71 1 0.73541000 0.15577000 0.58630000 1.0
C C72 1 0.67891000 0.19439000 0.52424000 1.0
C C73 1 0.61314000 0.27506000 0.56986000 1.0
C C74 1 0.59998000 0.31414000 0.67766000 1.0
C C75 1 0.81514000 0.07734000 0.54296000 1.0
C C76 1 0.55919000 0.31841000 0.50090000 1.0
C C77 1 0.96206000 0.20726000 0.85110000 1.0
C C78 1 0.92455000 0.28986000 0.95322000 1.0
C C79 1 0.90720000 0.25919000 0.03018000 1.0
C C80 1 0.88260000 0.33981000 0.12842000 1.0
C C81 1 0.87304000 0.44954000 0.15222000 1.0
C C82 1 0.88877000 0.47813000 0.07406000 1.0
C C83 1 0.91298000 0.39742000 0.97580000 1.0
C C84 1 0.85106000 0.53204000 0.26256000 1.0
C C85 1 0.78095000 0.49973000 0.30654000 1.0
C C86 1 0.76459000 0.56947000 0.41370000 1.0
C C87 1 0.82109000 0.67015000 0.47576000 1.0
C C88 1 0.88686000 0.70520000 0.43014000 1.0
C C89 1 0.90002000 0.63648000 0.32234000 1.0
C C90 1 0.68486000 0.53438000 0.45704000 1.0
C C91 1 0.94081000 0.81751000 0.49910000 1.0
O O92 1 0.48420000 0.54884000 0.78706000 1.0
O O93 1 0.47199000 0.72510000 0.83360000 1.0
O O94 1 0.47098000 0.58491000 0.45558000 1.0
O O95 1 0.45544000 0.74311000 0.60114000 1.0
O O96 1 0.17232000 0.95149000 0.55446000 1.0
O O97 1 0.13841000 0.95222000 0.39698000 1.0
O O98 1 0.01580000 0.76178000 0.21294000 1.0
O O99 1 0.02801000 0.89150000 0.16640000 1.0
O O100 1 0.02902000 0.12933000 0.54442000 1.0
O O101 1 0.04456000 0.14197000 0.39886000 1.0
O O102 1 0.32768000 0.39703000 0.44554000 1.0
O O103 1 0.36159000 0.55524000 0.60302000 1.0
O O104 1 0.51580000 0.45116000 0.21294000 1.0
O O105 1 0.52801000 0.27490000 0.16640000 1.0
O O106 1 0.52902000 0.41509000 0.54442000 1.0
O O107 1 0.54456000 0.25689000 0.39886000 1.0
O O108 1 0.82768000 0.04851000 0.44554000 1.0
O O109 1 0.86159000 0.04778000 0.60302000 1.0
O O110 1 0.98420000 0.23822000 0.78706000 1.0
O O111 1 0.97199000 0.10850000 0.83360000 1.0
O O112 1 0.97098000 0.87067000 0.45558000 1.0
O O113 1 0.95544000 0.85803000 0.60114000 1.0
O O114 1 0.67232000 0.60297000 0.55446000 1.0
O O115 1 0.63841000 0.44476000 0.39698000 1.0
Loading

0 comments on commit c33449c

Please sign in to comment.