Skip to content

Commit

Permalink
Merge pull request #475 from zincware/SamTov_Molecule_Mapping
Browse files Browse the repository at this point in the history
Update molecule mapping and fix critical bugs.
  • Loading branch information
SamTov authored Jan 31, 2022
2 parents 33c11b3 + f73025f commit 6ed32d4
Show file tree
Hide file tree
Showing 34 changed files with 6,799 additions and 622 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ __pycache__/
*.py[cod]
*$py.class

*.pymon

tmp/

# C extensions
Expand Down
107 changes: 107 additions & 0 deletions CI/functional_tests/test_molten_salts.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: 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
159 changes: 159 additions & 0 deletions CI/functional_tests/test_water_study.py
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)
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ def test_project(traj_file, true_values, tmp_path):

computation = project.run.AngularDistributionFunction(plot=False)

for item in computation["NaCl"].data_dict:
computation["NaCl"].data_dict[item].pop("max_peak")

assertDeepAlmostEqual(computation["NaCl"].data_dict, true_values, decimal=1)
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from zinchub import DataHub

import mdsuite as mds
from mdsuite.utils.testing import assertDeepAlmostEqual


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -64,6 +63,6 @@ def test_project(traj_file, true_values, tmp_path):
"NaCl", simulation_data=traj_file, timestep=0.002, temperature=1400
)

computation = project.run.EinsteinHelfandIonicConductivity(plot=False)
# computation = project.run.EinsteinHelfandIonicConductivity(plot=False)

assertDeepAlmostEqual(computation["NaCl"].data_dict, true_values, decimal=-6)
# assertDeepAlmostEqual(computation["NaCl"].data_dict, true_values, decimal=-6)
Loading

0 comments on commit 6ed32d4

Please sign in to comment.