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

Tleap InterMol support #146

Merged
merged 13 commits into from
Oct 24, 2020
2 changes: 2 additions & 0 deletions devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: paprika-dev
channels:
- conda-forge
- omnia
- mwt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thought about getting intermol onto conda-forge? I can't even find this channel after spending five minutes of Googling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's just my "personal" channel where I dump stuff from time to time. It's not really intended to be used by others, although I didn't put anything in place to prevent that. I don't believe I advertised this build, but again there's nothing hidden about it.

Putting it on conda-forge is something that probably should be done at some point. It should be feasible - the deps are really light - but some of the package structure might need a refresh. I can take it on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I didn't even connect mwt with @mattwthompson. Ha.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I found the package by searching Intermol on the anaconda website. It's not urgent, but if you can get it to conda-forge then 😍

dependencies:

# Base depends
Expand All @@ -16,6 +17,7 @@ dependencies:
- ambertools >=20.0
- pyyaml
- plumed
- intermol

# devtools
- isort
Expand Down
73 changes: 73 additions & 0 deletions paprika/tests/test_tleap.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,76 @@ def test_multiple_pdb_files(clean_files):
assert "b = loadpdb cb6-but-minimized.pdb" in lines
assert "combine" in lines
assert "savepdb model multi.pdb" in lines


def test_conversions(clean_files):
""" Test that conversion methods work in Tleap module. """
temporary_directory = os.path.join(os.path.dirname(__file__), "tmp")

but_frcmod = os.path.abspath(
os.path.join(os.path.dirname(__file__), "../data/cb6-but/but.frcmod")
)
but_mol2 = os.path.abspath(
os.path.join(os.path.dirname(__file__), "../data/cb6-but/but.mol2")
)

sys = System()
sys.template_lines = [
"source leaprc.gaff",
f"loadamberparams {but_frcmod}",
f"BUT = loadmol2 {but_mol2}",
f"model = loadmol2 {but_mol2}",
]
sys.output_path = temporary_directory
sys.output_prefix = "but"
sys.pbc_type = None
sys.neutralize = False
sys.build()

from paprika.utils import is_file_and_not_empty

# Gromacs ParmEd test
sys.convert_to_gromacs(overwrite=True)
top_file = os.path.join(sys.output_path, sys.output_prefix + ".top")
gro_file = os.path.join(sys.output_path, sys.output_prefix + ".gro")
assert is_file_and_not_empty(top_file) is True
assert is_file_and_not_empty(gro_file) is True

# Gromacs InterMol test
sys.convert_to_gromacs(toolkit=System.ConversionToolkit.InterMol)
assert is_file_and_not_empty(top_file) is True
assert is_file_and_not_empty(gro_file) is True
top_file = os.path.join(sys.output_path, sys.output_prefix + "_from_amber.top")
gro_file = os.path.join(sys.output_path, sys.output_prefix + "_from_amber.gro")
assert is_file_and_not_empty(top_file) is True
assert is_file_and_not_empty(gro_file) is True
Comment on lines +437 to +438
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally out of scope here, but if for any reason you find yourself needing to also compare the energies before and after conversion, InterMol does that pretty well. I'll be working on doing this independently elsewhere in the next month or two, so it could possibly be something you can get for free in the future.

Copy link
Collaborator Author

@jeff231li jeff231li Oct 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would be a better way for testing, but you would need the MD executables to evaluate the energies?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but they're mostly/all conda installable (save Desmond, I think) so it's possible to do that in a separate CI build

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will (most) probably need help in configuring the CI build (sometime in the future). This will be useful to test the simulation wrappers as well.


# CHARMM ParmEd test
sys.convert_to_charmm()
psf_file = os.path.join(sys.output_path, sys.output_prefix + ".psf")
crd_file = os.path.join(sys.output_path, sys.output_prefix + ".crd")

assert is_file_and_not_empty(psf_file) is True
assert is_file_and_not_empty(crd_file) is True

# CHARMM Intermol test
sys.convert_to_charmm(toolkit=System.ConversionToolkit.InterMol)
rtf_file = os.path.join(sys.output_path, sys.output_prefix + ".rtf")
prm_file = os.path.join(sys.output_path, sys.output_prefix + ".prm")

assert is_file_and_not_empty(psf_file) is True
assert is_file_and_not_empty(crd_file) is True
assert is_file_and_not_empty(rtf_file) is True
assert is_file_and_not_empty(prm_file) is True

# LAMMPS test
sys.convert_to_lammps()
input_file = os.path.join(sys.output_path, sys.output_prefix + ".input")
lmp_file = os.path.join(sys.output_path, sys.output_prefix + ".lmp")
assert is_file_and_not_empty(input_file) is True
assert is_file_and_not_empty(lmp_file) is True

# DESMOND test
sys.convert_to_desmond()
cms_file = os.path.join(sys.output_path, sys.output_prefix + ".cms")
assert is_file_and_not_empty(cms_file) is True
45 changes: 44 additions & 1 deletion paprika/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@
"""

import os
import shutil

from paprika.utils import make_window_dirs, strip_prmtop
import pytest

from paprika.utils import is_file_and_not_empty, make_window_dirs, strip_prmtop


@pytest.fixture
def clean_files(directory=os.path.join(os.path.dirname(__file__), "tmp")):
# This happens before the test function call
if os.path.isdir(directory):
shutil.rmtree(directory)
os.makedirs(directory)
yield
# This happens after the test function call
shutil.rmtree(directory)


def test_mkdirs():
Expand All @@ -24,3 +38,32 @@ def test_strip_prmtop():
residues = [r.name for r in cb6_only.residues]
assert "CB6" in residues
assert "BUT" not in residues


def test_is_file_and_not_empty(clean_files):
# Check for existing file
but_frcmod = os.path.abspath(
os.path.join(os.path.dirname(__file__), "../data/cb6-but/but.frcmod")
)

assert os.path.isfile(but_frcmod)
assert os.path.getsize(but_frcmod) != 0
assert is_file_and_not_empty(but_frcmod)

# Check for emtpy
path = os.path.join(os.path.dirname(__file__), "tmp", "testfile1")
with open(path, "w") as f:
pass

assert os.path.isfile(path)
assert os.path.getsize(path) == 0
assert not is_file_and_not_empty(path)

# Check file after writing
path = os.path.join(os.path.dirname(__file__), "tmp", "testfile2")
with open(path, "w") as f:
f.write("Hello World\n")

assert os.path.isfile(path)
assert os.path.getsize(path) != 0
assert is_file_and_not_empty(path)
Loading