-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from zincware/SamTov_Molecule_Mapping
Update molecule mapping and fix critical bugs.
- Loading branch information
Showing
34 changed files
with
6,799 additions
and
622 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ __pycache__/ | |
*.py[cod] | ||
*$py.class | ||
|
||
*.pymon | ||
|
||
tmp/ | ||
|
||
# C extensions | ||
|
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,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: zincwarecode@gmail.com | ||
github: https://github.com/zincware | ||
web: https://zincwarecode.com/ | ||
Citation | ||
-------- | ||
If you use this module please cite us with: | ||
Summary | ||
------- | ||
Perform a functional test on two molten salts. | ||
""" | ||
from typing import Tuple | ||
|
||
import pytest | ||
from zinchub import DataHub | ||
|
||
import mdsuite as mds | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def traj_files(tmp_path_factory) -> Tuple[str, str]: | ||
"""Download trajectory file into a temporary directory and keep it for all tests""" | ||
temporary_path = tmp_path_factory.getbasetemp() | ||
|
||
NaCl_file = DataHub(url="https://github.com/zincware/DataHub/tree/main/NaCl_rnd_md") | ||
NaCl_file.get_file(temporary_path) | ||
NaCl_out = (temporary_path / NaCl_file.file_raw).as_posix() | ||
|
||
KCl_file = DataHub(url="https://github.com/zincware/DataHub/tree/main/KCl_rnd_md") | ||
KCl_file.get_file(temporary_path) | ||
KCl_out = (temporary_path / KCl_file.get_file(temporary_path)).as_posix() | ||
|
||
return NaCl_out, KCl_out | ||
|
||
|
||
@pytest.fixture() | ||
def mdsuite_project(traj_files, tmp_path) -> mds.Project: | ||
""" | ||
Create the MDSuite project and add data to be used for the rest of the tests. | ||
Parameters | ||
---------- | ||
traj_files : tuple | ||
Files include: | ||
* NaCl Simulation | ||
* KCl Simulation | ||
tmp_path : Path | ||
Temporary path that may be changed into. | ||
Returns | ||
------- | ||
project: mdsuite.Project | ||
An MDSuite project to be tested. | ||
""" | ||
project = mds.Project(storage_path=tmp_path.as_posix()) | ||
|
||
na_cl_file, k_cl_file = traj_files | ||
|
||
project.add_experiment( | ||
name="NaCl", | ||
timestep=0.002, | ||
temperature=1200.0, | ||
units="metal", | ||
simulation_data=na_cl_file, | ||
) | ||
project.add_experiment( | ||
name="KCl", | ||
timestep=0.002, | ||
temperature=1200.0, | ||
units="metal", | ||
simulation_data=k_cl_file, | ||
) | ||
|
||
return project | ||
|
||
|
||
def test_analysis(): | ||
""" | ||
Perform analysis on these MD simulations and ensure the outcomes are as expected. | ||
Returns | ||
------- | ||
Test the following: | ||
* Two experiments added to a project successfully | ||
Notes | ||
----- | ||
TODO: Add correct tests when all post-RDF calculators are fixed. | ||
""" | ||
pass |
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,159 @@ | ||
""" | ||
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: zincwarecode@gmail.com | ||
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-15, | ||
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.CoordinateUnwrapper() | ||
return project | ||
|
||
|
||
def test_water_analysis(mdsuite_project): | ||
""" | ||
Run a functional test by performing a study on an MD simulation of water | ||
Notes | ||
----- | ||
The diffusion, angle, and eventually coordination data tested here are comparable | ||
with values taken from experiment and published studies. | ||
""" | ||
|
||
water = mdsuite_project.experiments["water_sim"] | ||
|
||
water_molecule = mds.Molecule( | ||
name="water", smiles="[H]O[H]", amount=14, cutoff=1.7, mol_pbc=True | ||
) | ||
|
||
water.run.MolecularMap(molecules=[water_molecule]) | ||
atomistic_adf = mdsuite_project.run.AngularDistributionFunction(plot=False) | ||
mdsuite_project.run.RadialDistributionFunction(plot=False) | ||
molecule_adf = mdsuite_project.run.AngularDistributionFunction( | ||
plot=False, molecules=True, norm_power=8 | ||
) | ||
mdsuite_project.run.RadialDistributionFunction(plot=False, molecules=True) | ||
atomistic_diffusion = mdsuite_project.run.EinsteinDiffusionCoefficients( | ||
plot=False, data_range=500 | ||
) | ||
molecular_diffusion = mdsuite_project.run.EinsteinDiffusionCoefficients( | ||
plot=False, molecules=True, data_range=500 | ||
) | ||
|
||
water_group = water.molecules["water"]["groups"]["0"] | ||
atom_group_adf = mdsuite_project.run.AngularDistributionFunction( | ||
atom_selection=water_group, number_of_configurations=100, plot=False | ||
) | ||
atom_group_diffusion = mdsuite_project.run.EinsteinDiffusionCoefficients( | ||
atom_selection=water_group, data_range=2500, plot=False | ||
) | ||
|
||
# Test ADF output | ||
assert atomistic_adf["water_sim"].data_dict["O_H_H"]["max_peak"] == pytest.approx( | ||
109.5, rel=0.1 | ||
) | ||
assert molecule_adf["water_sim"].data_dict["water_water_water"][ | ||
"max_peak" | ||
] == pytest.approx(104.8, rel=0.1) | ||
|
||
# Test diffusion data | ||
assert atomistic_diffusion["water_sim"].data_dict["O"][ | ||
"diffusion_coefficient" | ||
] == pytest.approx(4.1e-3, rel=0.01) | ||
assert atomistic_diffusion["water_sim"].data_dict["H"][ | ||
"diffusion_coefficient" | ||
] == pytest.approx(5.05e-3, rel=0.01) | ||
assert molecular_diffusion["water_sim"].data_dict["water"][ | ||
"diffusion_coefficient" | ||
] == pytest.approx(4.3e-3, rel=0.01) | ||
|
||
# Test group selected data | ||
assert atom_group_adf["water_sim"].data_dict["O_H_H"]["max_peak"] == pytest.approx( | ||
109.5, 0.1 | ||
) | ||
assert atom_group_diffusion["water_sim"].data_dict["O"][ | ||
"diffusion_coefficient" | ||
] == pytest.approx(2.9e-4, rel=0.1) | ||
assert atom_group_diffusion["water_sim"].data_dict["H"][ | ||
"diffusion_coefficient" | ||
] == pytest.approx(3.0e-4, rel=0.1) |
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
Oops, something went wrong.