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

Update molecule mapping #475

Merged
merged 84 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
aebc211
Adapt molecule mapper to take arbitrary dict with non-regular species…
SamTov Jan 21, 2022
6050087
Update tqdm descriptions and run black + isort.
SamTov Jan 21, 2022
461d072
add tensor cutoff test for molecule mapping.
SamTov Jan 21, 2022
562e809
add smiles string tests for various molecules.
SamTov Jan 21, 2022
b94b4b8
Merge branch 'main' into SamTov_Molecule_Mapping
SamTov Jan 21, 2022
03ca751
Fix issues in ADF calculator and transformations.py
SamTov Jan 21, 2022
bf0b6ef
change minibatch default to avoid issue with minibatching in adf.
SamTov Jan 21, 2022
58cbd3c
run black and isort
SamTov Jan 21, 2022
ae58bf1
run black and isort
SamTov Jan 21, 2022
7146614
add comprehensive molecule mapping tests and update ADF to work with …
SamTov Jan 21, 2022
5f6ba4d
fix flake8 problem
SamTov Jan 21, 2022
866fc63
more flake8 fixes.
SamTov Jan 21, 2022
2ba8de5
update loading bars lengths in file readers and add mapping notebook.
SamTov Jan 22, 2022
b4b47f5
Update RDF and ADF to work with atom selection, issues still with RDF.
SamTov Jan 22, 2022
04f9205
run black and isort
SamTov Jan 22, 2022
c6017c6
Fix indexing error in molecule mapping and update tests
SamTov Jan 23, 2022
baace8e
update tests to enforce no molecules in species dict and run formatters.
SamTov Jan 23, 2022
2132e92
set remainder to True for any operation if a remainder exists. Move m…
SamTov Jan 23, 2022
0385007
Merge branch 'main' into SamTov_Molecule_Mapping
SamTov Jan 24, 2022
346a9cc
more small updates
SamTov Jan 24, 2022
c9f7b2c
Merge remote-tracking branch 'origin/SamTov_Molecule_Mapping' into Sa…
SamTov Jan 24, 2022
ad9a237
Merge branch 'main' into SamTov_Molecule_Mapping
SamTov Jan 24, 2022
d799194
Fix ensemble loop generator such that it correclty computes the remai…
SamTov Jan 25, 2022
8d92f09
Merge remote-tracking branch 'origin/SamTov_Molecule_Mapping' into Sa…
SamTov Jan 25, 2022
f46a495
fix critical bug in ensemble generator which renders system propertie…
SamTov Jan 25, 2022
baac20b
run black and isort
SamTov Jan 25, 2022
34eec7b
Fix persistent bug in RDF and ADF computations.
SamTov Jan 25, 2022
829994e
run black and isort
SamTov Jan 25, 2022
230ce9f
Merge branch 'main' into SamTov_Molecule_Mapping
SamTov Jan 25, 2022
368d7f8
move all graph related operations into graph module and trim molecula…
SamTov Jan 26, 2022
c823a3b
run black and isort
SamTov Jan 26, 2022
237c23c
update tests to run with new API.
SamTov Jan 26, 2022
b49f110
update molecular mapping example and fix small bugs.
SamTov Jan 26, 2022
716ac30
run black and isort
SamTov Jan 26, 2022
7876121
fix flake8 complaint
SamTov Jan 26, 2022
3de95d5
Fix issues with mapper.
SamTov Jan 26, 2022
ec1f25d
add data class for test case.
SamTov Jan 27, 2022
7c4edb7
fix flake8 complaint
SamTov Jan 27, 2022
975b4b0
add numbers to smiles string.
SamTov Jan 27, 2022
3f70ce2
update RDF doc string.
SamTov Jan 27, 2022
c7fb82a
fix remainder decleration and naming.
SamTov Jan 27, 2022
a0330c4
implement molecule data class and move bmim test to integration test.
SamTov Jan 27, 2022
f48b573
run black and isort
SamTov Jan 27, 2022
675ce61
add test for molecule class.
SamTov Jan 27, 2022
dd677ab
run black and isort
SamTov Jan 27, 2022
6463235
remove assigning of unused variables to make flake happy
SamTov Jan 27, 2022
bfe6536
remove indices from molecules.
SamTov Jan 27, 2022
13017c0
Add data to functional test and allow ADF to return max value angle.
SamTov Jan 27, 2022
6636fa0
resolve flake8 complaints
SamTov Jan 27, 2022
f855102
adjust add_experiment test to work again.
SamTov Jan 27, 2022
7dd2729
Start new functional test on proper data and add example.
SamTov Jan 28, 2022
d6273e3
get tests running and remove exclamation marks from comments. Please …
SamTov Jan 28, 2022
f3de358
add mol_pbc argument to molecules and update tests.
SamTov Jan 28, 2022
6a64769
run black and isort
SamTov Jan 28, 2022
119c7c6
resolve flake8 issues
SamTov Jan 28, 2022
f4a722f
Merge branch 'main' into SamTov_Molecule_Mapping
PythonFZ Jan 28, 2022
acd12d0
Remove unused variable
SamTov Jan 28, 2022
94fd6e1
remove old data manager code.
SamTov Jan 31, 2022
854fca7
Add pytest fixture
SamTov Jan 31, 2022
ee80299
move if statement to isinstance
SamTov Jan 31, 2022
a3af13d
Move to mdsuite properties
SamTov Jan 31, 2022
548ff32
shorten mass computation.
SamTov Jan 31, 2022
7052eed
move function out of class method
SamTov Jan 31, 2022
5a142bc
adapt reshape call
SamTov Jan 31, 2022
fc52e12
remove return statement.
SamTov Jan 31, 2022
abdb92b
Change pass to exception raise.
SamTov Jan 31, 2022
559a9bf
remove assert statement.
SamTov Jan 31, 2022
b04555b
remove redundant 0 instantiation.
SamTov Jan 31, 2022
b8ec7bc
update properties
SamTov Jan 31, 2022
24dc27a
adapt get mass array method.
SamTov Jan 31, 2022
98b8619
change build to get
SamTov Jan 31, 2022
413096d
split one-liner into two liner
SamTov Jan 31, 2022
42b89f1
adapt frame rate
SamTov Jan 31, 2022
556e75f
assert almost equal on water mass
SamTov Jan 31, 2022
84b4e87
convert strings to dunders
SamTov Jan 31, 2022
9992849
remove old code.
SamTov Jan 31, 2022
836ea79
add test for BMIM, update example.
SamTov Jan 31, 2022
b903601
add unit test for shifted function.
SamTov Jan 31, 2022
7cac760
change name to highlight idx
SamTov Jan 31, 2022
b8747e9
fix ambiguous loop
SamTov Jan 31, 2022
03b932f
Move loop to cumsum
SamTov Jan 31, 2022
85d3ae8
Fix final review comments
SamTov Jan 31, 2022
fb8ee66
adjust slice for speed
SamTov Jan 31, 2022
f73025f
fix false argument in test
SamTov Jan 31, 2022
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
107 changes: 107 additions & 0 deletions CI/functional_tests/test_water_study.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""
MDSuite: A Zincwarecode package.

License
-------
This program and the accompanying materials are made available under the terms
of the Eclipse Public License v2.0 which accompanies this distribution, and is
available at https://www.eclipse.org/legal/epl-v20.html

SPDX-License-Identifier: EPL-2.0

Copyright Contributors to the Zincwarecode Project.

Contact Information
-------------------
email: [email protected]
github: https://github.com/zincware
web: https://zincwarecode.com/

Citation
--------
If you use this module please cite us with:

Summary
-------
Functional test for the analysis of a GROMACS water simulation.
"""
from typing import List

import pytest
from zinchub import DataHub

import mdsuite as mds
import mdsuite.file_io.chemfiles_read
from mdsuite.utils import Units


@pytest.fixture(scope="session")
def traj_files(tmp_path_factory) -> List[str]:
"""Download trajectory file into a temporary directory and keep it for all tests"""
temporary_path = tmp_path_factory.getbasetemp()

water = DataHub(url="https://github.com/zincware/DataHub/tree/main/Water_14_Gromacs")
water.get_file(temporary_path)
file_paths = [(temporary_path / f).as_posix() for f in water.file_raw]
return file_paths


@pytest.fixture()
def mdsuite_project(traj_files, tmp_path) -> mdsuite.Project:
"""
Create the MDSuite project and add data to be used for the rest of the tests.

Parameters
----------
traj_files : list
Files include:
* Water Simulation
tmp_path : Path
Temporary path that may be changed into.

Returns
-------
project: mdsuite.Project
An MDSuite project to be tested.
"""
gmx_units = Units(
time=1e-12,
length=1e-10,
energy=1.6022e-19,
NkTV2p=1.6021765e6,
boltzmann=8.617343e-5,
temperature=1,
pressure=100000,
)
project = mds.Project(storage_path=tmp_path.as_posix())

file_reader = mdsuite.file_io.chemfiles_read.ChemfilesRead(
traj_file_path=traj_files[2], topol_file_path=traj_files[0]
)

project.add_experiment(
name="water_sim",
timestep=0.002,
temperature=300.0,
units=gmx_units,
simulation_data=file_reader,
)
project.run.CoordinateWrapper()
return project


def test_water_analysis(mdsuite_project):
"""Run a functional test by performing a study on an MD simulation of water"""

water = mdsuite_project.experiments["water_sim"]

water.run.MolecularMap(
molecules={"water": {"smiles": "[H]O[H]", "amount": 14, "cutoff": 1.7}}
)
mdsuite_project.run.AngularDistributionFunction(plot=False)
mdsuite_project.run.RadialDistributionFunction(plot=False)
mdsuite_project.run.AngularDistributionFunction(plot=False, molecules=True)
mdsuite_project.run.RadialDistributionFunction(plot=False, molecules=True)
mdsuite_project.run.EinsteinDiffusionCoefficients(plot=False)
mdsuite_project.run.EinsteinDiffusionCoefficients(plot=False, molecules=True)
mdsuite_project.run.GreenKuboDiffusionCoefficients(plot=False)
SamTov marked this conversation as resolved.
Show resolved Hide resolved
206 changes: 206 additions & 0 deletions CI/integration_tests/transformations/test_molecular_mapping_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
"""
MDSuite: A Zincwarecode package.

License
-------
This program and the accompanying materials are made available under the terms
of the Eclipse Public License v2.0 which accompanies this distribution, and is
available at https://www.eclipse.org/legal/epl-v20.html

SPDX-License-Identifier: EPL-2.0

Copyright Contributors to the Zincwarecode Project.

Contact Information
-------------------
email: [email protected]
github: https://github.com/zincware
web: https://zincwarecode.com/

Citation
--------
If you use this module please cite us with:

Summary
-------
Test the outcome of molecular mapping.
"""
from typing import List

import pytest
from zinchub import DataHub

import mdsuite
import mdsuite.file_io.chemfiles_read
import mdsuite.transformations
from mdsuite.utils import Units


@pytest.fixture(scope="session")
def traj_files(tmp_path_factory) -> List[str]:
"""Download trajectory file into a temporary directory and keep it for all tests"""
temporary_path = tmp_path_factory.getbasetemp()

water = DataHub(url="https://github.com/zincware/DataHub/tree/main/Water_14_Gromacs")
water.get_file(temporary_path)
file_paths = [(temporary_path / f).as_posix() for f in water.file_raw]
return file_paths


@pytest.fixture()
def mdsuite_project(traj_files, tmp_path) -> mdsuite.Project:
"""
Create the MDSuite project and add data to be used for the rest of the tests.

Parameters
----------
traj_files : list
Files include:
* Water Simulation
tmp_path : Path
Temporary path that may be changed into.

Returns
-------
project: mdsuite.Project
An MDSuite project to be tested.
"""
gmx_units = Units(
time=1e-12,
length=1e-10,
energy=1.6022e-19,
NkTV2p=1.6021765e6,
boltzmann=8.617343e-5,
temperature=1,
pressure=100000,
)
project = mdsuite.Project(storage_path=tmp_path.as_posix())

file_reader_1 = mdsuite.file_io.chemfiles_read.ChemfilesRead(
traj_file_path=traj_files[2], topol_file_path=traj_files[0]
)
file_reader_2 = mdsuite.file_io.chemfiles_read.ChemfilesRead(
traj_file_path=traj_files[2], topol_file_path=traj_files[1]
christophlohrmann marked this conversation as resolved.
Show resolved Hide resolved
)
project.add_experiment(
name="simple_water",
timestep=0.002,
temperature=300.0,
units=gmx_units,
simulation_data=file_reader_1,
)
project.add_experiment(
name="ligand_water",
timestep=0.002,
temperature=300.0,
units=gmx_units,
simulation_data=file_reader_2,
)

project.run.CoordinateWrapper()

return project


def test_water_molecule_smiles(mdsuite_project):
"""
Test that water molecules are built correctly using a SMILES string. Also check
that the molecule information is stored correctly in the experiment.

Parameters
----------
mdsuite_project : Callable
Callable that returns an MDSuite project created in a temporary
directory.

Returns
-------
Tests that the molecule groups detected are done so correctly and that the
constructed trajectory is also correct.
"""
reference_molecules = {
"water": {
"n_particles": 14,
"indices": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
SamTov marked this conversation as resolved.
Show resolved Hide resolved
"mass": 18.015,
"groups": {
"0": {"H": [0, 1], "O": [0]},
"1": {"H": [2, 3], "O": [1]},
"2": {"H": [4, 5], "O": [2]},
"3": {"H": [6, 7], "O": [3]},
"4": {"H": [8, 9], "O": [4]},
"5": {"H": [10, 11], "O": [5]},
"6": {"H": [12, 13], "O": [6]},
"7": {"H": [14, 15], "O": [7]},
"8": {"H": [16, 17], "O": [8]},
"9": {"H": [18, 19], "O": [9]},
"10": {"H": [20, 21], "O": [10]},
"11": {"H": [22, 23], "O": [11]},
"12": {"H": [24, 25], "O": [12]},
"13": {"H": [26, 27], "O": [13]},
},
}
}
mdsuite_project.experiments["simple_water"].run.MolecularMap(
molecules={"water": {"smiles": "[H]O[H]", "amount": 14, "cutoff": 1.7}}
)
molecules = mdsuite_project.experiments["simple_water"].molecules
assert molecules == reference_molecules

assert "water" not in mdsuite_project.experiments["simple_water"].species


def test_water_molecule_reference_dict(mdsuite_project):
"""
Test that water molecules are built correctly using a reference dict.

Parameters
----------
mdsuite_project : Callable
Callable that returns an MDSuite project created in a temporary
directory.

Returns
-------
Tests that the molecule groups detected are done so correctly and that the
constructed trajectory is also correct.
"""
mdsuite_project.experiments["ligand_water"].species["OW"].mass = [15.999]
mdsuite_project.experiments["ligand_water"].species["HW1"].mass = [1.00784]
mdsuite_project.experiments["ligand_water"].species["HW2"].mass = [1.00784]
reference_molecules = {
"water": {
"n_particles": 14,
"indices": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
"mass": 18.014680000000002,
"groups": {
"0": {"HW1": [0], "OW": [0], "HW2": [0]},
"1": {"HW1": [1], "OW": [1], "HW2": [1]},
"2": {"HW1": [2], "OW": [2], "HW2": [2]},
"3": {"HW1": [3], "OW": [3], "HW2": [3]},
"4": {"HW1": [4], "OW": [4], "HW2": [4]},
"5": {"HW1": [5], "OW": [5], "HW2": [5]},
"6": {"HW1": [6], "OW": [6], "HW2": [6]},
"7": {"HW1": [7], "OW": [7], "HW2": [7]},
"8": {"HW1": [8], "OW": [8], "HW2": [8]},
"9": {"HW1": [9], "OW": [9], "HW2": [9]},
"10": {"HW1": [10], "OW": [10], "HW2": [10]},
"11": {"HW1": [11], "OW": [11], "HW2": [11]},
"12": {"HW1": [12], "OW": [12], "HW2": [12]},
"13": {"HW1": [13], "OW": [13], "HW2": [13]},
},
}
}
mdsuite_project.experiments["ligand_water"].run.MolecularMap(
molecules={
"water": {
"reference": {"OW": 1, "HW1": 1, "HW2": 1},
"amount": 14,
"cutoff": 1.7,
}
}
)
molecules = mdsuite_project.experiments["ligand_water"].molecules
assert molecules == reference_molecules

assert "water" not in mdsuite_project.experiments["ligand_water"].species
Loading