-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for fragment detection and molecule generation; correct bug…
… in distance check Signed-off-by: Marcel Müller <[email protected]>
- Loading branch information
Showing
8 changed files
with
201 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
8 | ||
Generated by mlmgen-v0.1.1.dev19+gdad8d7d.d20240813 | ||
H 1.8881922 0.0434471 6.4036416 | ||
H 2.3614382 1.5848368 4.1324938 | ||
B 2.9665417 3.1071877 6.8367337 | ||
B 1.2903809 -0.0355866 5.2252287 | ||
O 2.8188111 2.2115904 7.6804091 | ||
O 2.9569763 3.4427774 5.6277026 | ||
I 0.1039807 -1.5020698 4.4901998 | ||
Os 2.3947779 1.4743942 5.6803414 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
15 | ||
Generated by mlmgen-v0.1.1.dev19+gdad8d7d.d20240813 | ||
H 1.8881922 0.0434471 6.4036416 | ||
H 2.3614382 1.5848368 4.1324938 | ||
H 4.4075523 -1.1311187 4.6335760 | ||
H -18.8463718 31.0433592 0.1833077 | ||
H 3.8825457 -0.5200946 4.7973741 | ||
H 15.1931043 11.9104232 -29.4429174 | ||
B 2.9665417 3.1071877 6.8367337 | ||
B 1.2903809 -0.0355866 5.2252287 | ||
O 2.8188111 2.2115904 7.6804091 | ||
O 2.9569763 3.4427774 5.6277026 | ||
Ne -12.5685006 -25.1495934 -12.9021224 | ||
Ne 5.1386813 1.5739968 5.9230793 | ||
I 0.1039807 -1.5020698 4.4901998 | ||
Os 2.3947779 1.4743942 5.6803414 | ||
Tl -15.2759053 -25.7803943 -13.4756278 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Test the miscellaneous functions in the molecules module. | ||
""" | ||
|
||
import pytest | ||
import numpy as np | ||
from mlmgen.molecules.miscellaneous import set_random_charge # type: ignore | ||
|
||
|
||
# CAUTION: We use 0-based indexing for atoms and molecules! | ||
@pytest.mark.parametrize( | ||
"atom_types, expected_charge", | ||
[ | ||
(np.array([5, 7, 0]), [-1, 1]), | ||
(np.array([5, 7, 0, 0]), [-2, 0, 2]), | ||
], | ||
ids=["odd", "even"], | ||
) | ||
def test_set_random_charge(atom_types, expected_charge): | ||
""" | ||
Test the set_random_charge function. | ||
""" | ||
assert set_random_charge(atom_types) in expected_charge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Test the postprocessing functions in the molecules module. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
import numpy as np | ||
import pytest | ||
from mlmgen.molecules import detect_fragments # type: ignore | ||
from mlmgen.molecules.molecule import Molecule # type: ignore | ||
|
||
|
||
@pytest.fixture | ||
def mol_H6O2B2Ne2I1Os1Tl1() -> Molecule: | ||
""" | ||
Load the molecule H6O2B2Ne2I1Os1Tl1 from 'fixtures/H6O2B2Ne2I1Os1Tl1.xyz'. | ||
""" | ||
mol = Molecule("H6O2B2Ne2I1Os1Tl1") | ||
# get the Path of this file | ||
path = Path(__file__).resolve().parent | ||
xyz_file = path / "fixtures/H6O2B2Ne2I1Os1Tl1.xyz" | ||
mol.read_xyz_from_file(xyz_file) | ||
return mol | ||
|
||
|
||
@pytest.fixture | ||
def mol_H2O2B2I1Os1() -> Molecule: | ||
""" | ||
Load the molecule H2O2B2I1Os1 from 'fixtures/H2O2B2I1Os1.xyz'. | ||
""" | ||
mol = Molecule("H2O2B2I1Os1") | ||
# get the Path of this file | ||
path = Path(__file__).resolve().parent | ||
xyz_file = path / "fixtures/H2O2B2I1Os1.xyz" | ||
mol.read_xyz_from_file(xyz_file) | ||
return mol | ||
|
||
|
||
def test_detect_fragments_H6O2B2Ne2I1Os1Tl1( | ||
mol_H6O2B2Ne2I1Os1Tl1: Molecule, | ||
mol_H2O2B2I1Os1: Molecule, | ||
) -> None: | ||
""" | ||
Test the detection of fragments in the molecule H2O2B2I1Os1. | ||
""" | ||
fragmols = detect_fragments(mol_H6O2B2Ne2I1Os1Tl1, verbosity=0) | ||
assert len(fragmols) == 7 | ||
|
||
# check that the first fragment is equal to the molecule H2O2B2I1Os1 | ||
assert np.allclose(fragmols[0].xyz, mol_H2O2B2I1Os1.xyz) |