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

introduce more general fragmentation test #34

Merged
merged 2 commits into from
Sep 16, 2024
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
29 changes: 29 additions & 0 deletions test/fixtures/C13H14.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
27
XYZ file generated by Avogadro.
C -3.89040 1.99100 -0.00000
C -4.02680 0.60350 -0.00000
C -2.89350 -0.20830 0.00000
C -1.62370 0.36710 0.00000
H -3.00000 -1.29040 0.00000
C -2.62060 2.56660 -0.00000
C -1.48720 1.75470 0.00000
H -2.51440 3.64870 -0.00000
H -4.72547 2.41014 -0.05516
H -5.01710 0.15470 0.00000
H -1.81561 -0.88583 -2.43646
H 0.13224 -0.36655 0.76367
C -3.46846 -0.00090 -2.29110
C -2.58384 0.41194 -2.42614
C -4.46494 1.38711 -2.26956
H -4.15642 -0.99674 -2.19618
C -0.98984 1.36664 -2.22371
H -0.04316 1.26762 -2.41645
C -3.35847 2.53475 -2.09517
C -1.79945 2.16401 -2.13219
H -5.08593 1.97986 -2.35395
H -1.45478 3.39792 -1.81901
H -3.80661 3.50015 -2.26079
H -0.51264 2.19643 0.00000
C -0.68480 -0.69801 0.15746
H -1.16476 -1.52968 0.62954
H -0.31863 -0.99558 -0.80289
17 changes: 17 additions & 0 deletions test/fixtures/C7H8.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
15

C -3.92822833036995 1.96432093560546 0.62157575642424
C -4.12348090129541 0.59558759251302 0.57376967392366
C -3.03747857134253 -0.25907351392770 0.51942684687914
C -1.74159802338474 0.23892621267053 0.51235642166947
H -3.19667870717782 -1.32775033564467 0.48239910213616
C -2.64080719756196 2.47160711796854 0.61409596611734
C -1.55734176910219 1.61463498015929 0.55983863383019
H -2.48025573405657 3.53952821534543 0.64999745894259
H -4.77440551551237 2.63405350408406 0.66390613955572
H -5.12565950974504 0.19165590433204 0.57921484920548
H 0.28242223890343 -0.28503647701491 0.98320934851746
H -0.55378035137604 2.01638780449344 0.55334107071640
C -0.56432434664417 -0.68420602079331 0.42876403999537
H -0.81083301669431 -1.66824638917295 0.82046696760621
H -0.26050639196391 -0.79926111783838 -0.61204235704981
36 changes: 29 additions & 7 deletions test/test_molecules/test_refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@
from mindlessgen.molecules import iterative_optimization # type: ignore
from mindlessgen.qm import XTB, get_xtb_path # type: ignore

TESTSDIR = Path(__file__).resolve().parents[1]


@pytest.fixture
def mol_C13H14() -> Molecule:
"""
Load the molecule C13H14 from 'fixtures/C13H14.xyz'.
"""
molfile = TESTSDIR / "fixtures/C13H14.xyz"
mol = Molecule.read_mol_from_file(molfile)
return mol


@pytest.fixture
def mol_C7H8() -> Molecule:
"""
Load the molecule C7H8 from 'fixtures/C7H8.xyz'.
"""
molfile = TESTSDIR / "fixtures/C7H8.xyz"
mol = Molecule.read_mol_from_file(molfile)
return mol


@pytest.fixture
def mol_C2H2N2O1Co1Ge2Ta1Hg1() -> Molecule:
Expand Down Expand Up @@ -92,15 +114,15 @@ def test_detect_fragments_H6O2B2Ne2I1Os1Tl1(


@pytest.mark.optional
def test_iterative_optimization(
mol_C2H2N2O1Co1Ge2Ta1Hg1: Molecule, mol_C2H1N2O1Co1Ge2Ta1Hg1_frag: Molecule
) -> None:
def test_iterative_optimization(mol_C13H14: Molecule, mol_C7H8: Molecule) -> None:
"""
Test the iterative optimization of the molecule H6O2B2Ne2I1Os1Tl1.
"""
# initialize a configuration object
config = ConfigManager()
config.refine.hlgap = 0.1
config.refine.hlgap = 0.001 # TODO: Change charge assignment such that
# fragment charge is not completely random anymore. Currently, that's the
# reason for a virtually switched off HL gap check (fragment can be -2, 0, 2)
config.refine.max_frag_cycles = 1
if config.refine.engine == "xtb":
try:
Expand All @@ -112,15 +134,15 @@ def test_iterative_optimization(
engine = XTB(xtb_path, config.xtb)
else:
raise NotImplementedError("Engine not implemented.")
mol = mol_C2H2N2O1Co1Ge2Ta1Hg1
mol = mol_C13H14
mol_opt = iterative_optimization(
mol,
engine=engine,
config_generate=config.generate,
config_refine=config.refine,
verbosity=0,
verbosity=2,
)
mol_ref = mol_C2H1N2O1Co1Ge2Ta1Hg1_frag
mol_ref = mol_C7H8

# assert number of atoms in mol_opt is equal to number of atoms in mol_ref
assert mol_opt.num_atoms == mol_ref.num_atoms
Expand Down
2 changes: 1 addition & 1 deletion test/test_qm/test_xtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_xtb_optimize_xtb(coordinates_ethanol: np.ndarray) -> None:
[-1.17300591097528, 0.85675047762011, 0.75712732702203],
]
),
rtol=1e-3,
atol=1e-4,
)


Expand Down