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

Cassandra gmso #756

Merged
merged 52 commits into from
Sep 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
665feb6
Add fixed length bonds and angles to potential templates library.
rsdefever Jun 24, 2021
bd6ad75
Working to make MCF writer feature complete. Tests in progress.
rsdefever Jun 24, 2021
a6ce48d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2021
a97826c
Add dimensions to Fixed Bond and Angle templates
emarinri Aug 11, 2023
c9bd1d1
Update keys in OPLS dihedral parameters dict
emarinri Aug 11, 2023
014b7ae
Fix typed OPLS ethane test for MCF format
emarinri Aug 11, 2023
f41d5a9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2023
f8e044c
Add typed ethane test.
emarinri Aug 13, 2023
059ee03
Fix code style
emarinri Aug 13, 2023
48fd600
Add fixture to parse mcf into sections
emarinri Aug 13, 2023
aed4c44
Support Pydantic v1 and v2 (#752)
mattwthompson Aug 11, 2023
76415a8
Update MCF with GMSO builtin top site sorting
emarinri Aug 15, 2023
f093262
Use PotentialFilters to check for unique atomtypes
emarinri Aug 15, 2023
44a0928
Add test to check charge neutrality
emarinri Aug 15, 2023
b9efc1b
Add test for incompatible expressions
emarinri Aug 15, 2023
f9f2759
Test full MCF for Mie-Xe and LJ-Ar
emarinri Aug 16, 2023
5442297
Check charge neutrality in each molecule test
emarinri Aug 16, 2023
86902e6
Add exception for not neutral system in MCF writer
emarinri Aug 16, 2023
00cc2bc
Move parsing and neutrality check as utils
emarinri Aug 17, 2023
73d24de
Merge branch 'main' into cassandra-gmso
daico007 Sep 2, 2023
6094aba
Merge branch 'main' into cassandra-gmso
daico007 Sep 6, 2023
51fdad8
minor docstring/comment fixes, swap out simplify with symengine expand
daico007 Sep 11, 2023
5f4ca3c
Merge branch 'main' of https://github.com/mosdef-hub/gmso into cassan…
daico007 Sep 11, 2023
1dc0a3e
[pre-commit.ci] pre-commit autoupdate (#763)
pre-commit-ci[bot] Sep 12, 2023
a1c3fb5
Test for 0.5 factor of OPLS dihedral potential
emarinri Sep 12, 2023
4578812
Test to account for 0.5 factor in harmonic angles
emarinri Sep 12, 2023
6668363
Test for rigid angles using the TIP3P model
emarinri Sep 12, 2023
80c9be3
MCF writer test with topology with 10 argon mols
emarinri Sep 13, 2023
2b0c7ee
Tentative output of multiple MCF from one Topology
emarinri Sep 13, 2023
8317de4
Merge branch 'main' into cassandra-gmso
daico007 Sep 13, 2023
3951954
Change psi to phi and consts for ethylene xml test
emarinri Sep 14, 2023
9579252
Test for 0.5 factor in OPLS dihedrals
emarinri Sep 14, 2023
ae69a8c
Add cassandra test for gmso
CalCraven Sep 18, 2023
750d755
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2023
a7df9bc
Add test for two atom fragment
emarinri Sep 16, 2023
685f8b8
Test for molecule with one ring
emarinri Sep 16, 2023
1252d2b
Change nitrogen test to ethane ua
emarinri Sep 19, 2023
ec3a5dd
Add ethane rigid reference xml
emarinri Sep 19, 2023
a30d7bd
Use Fourier dihedrals as MCF standard dihedrals.
emarinri Sep 19, 2023
64b5b8f
Fix dihedral type output fourier to opls
emarinri Sep 19, 2023
ad68575
Match MCF GMSO Angle header to mb Angle header
emarinri Sep 20, 2023
0759365
Add a test comparing gmso and mbuild mcf writers
emarinri Sep 20, 2023
cf4e0c0
Use the Fourier converter for ethylene dihedrals
emarinri Sep 20, 2023
f462d5b
Write atom type masses instead of atom masses to account for UA beads
emarinri Sep 20, 2023
2a40bbf
Output correct case for dihedral styles in MCFs
emarinri Sep 20, 2023
c12a120
Merge branch 'main' into cassandra-gmso
daico007 Sep 20, 2023
6ff41e2
Merge branch 'cassandra-gmso' of https://github.com/emarinri/gmso int…
emarinri Sep 20, 2023
c1b9c19
Run an energy calculation to compare GMSO and mBuild MCF writers
emarinri Sep 20, 2023
dcdc342
Merge branch 'main' into cassandra-gmso
daico007 Sep 21, 2023
3c12947
Update gmso/tests/test_mcf.py
daico007 Sep 21, 2023
a1f4853
Update gmso/tests/test_mcf.py
daico007 Sep 21, 2023
f38cfb6
Merge branch 'main' into cassandra-gmso
daico007 Sep 22, 2023
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
116 changes: 113 additions & 3 deletions gmso/tests/test_mcf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import subprocess

import mbuild as mb
import numpy as np
Expand Down Expand Up @@ -48,10 +49,32 @@
if len(line) > 1:
if line[1] == "Fragment_Connectivity":
mcf_idx["Fragment_Connectivity"] = idx
if len(line) > 1:
if line[1] == "Intra_Scaling":
mcf_idx["Intra_Scaling"] = idx

return mcf_data, mcf_idx


def run_cassandra(cassandra, inp_file):
"""Calls Cassandra. Taken from mosdef_cassandra v0.3.2"""
cassandra_cmd = "{cassandra} {inp_file}".format(
cassandra=cassandra, inp_file=inp_file
)
p = subprocess.Popen(
cassandra_cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
out, err = p.communicate()

if p.returncode != 0 or "error" in err.lower() or "error" in out.lower():
return 1, out, err
return 0, out, err


def is_charge_neutral(mcf_data, mcf_idx):
n_sites = int(mcf_data[mcf_idx["Atom_Info"] + 1][0])
net_q = 0.0
Expand Down Expand Up @@ -228,8 +251,8 @@

# Modified dihedrals
# next(iter(top.dihedral_types)).set_expression("c0 * c1 * c2 * c3 * c4 * c5")
# with pytest.raises(EngineIncompatibilityError):
# top.save("dihedral.mcf")

def test_typed_ethylene(self):
ethylene = mb.load("C=C", smiles=True)
Expand Down Expand Up @@ -369,9 +392,21 @@

@pytest.mark.skipif(not has_cassandra, reason="cassandra is not installed")
def test_in_cassandra(self, typed_ethane):
"""
This test runs a single point energy calculation in Cassandra using an MCF
generated by gmso and compare the total energy
to the energy of a simulation run with a MCF file generated using mosdef_cassandra
(which involves using a parmed.Structure)
"""
from mosdef_cassandra.utils.detect import detect_cassandra_binaries
from mosdef_cassandra.writers.writers import write_input

from gmso.external.convert_parmed import to_parmed

write_mcf(typed_ethane, "top.mcf")
# First run the mosdef_cassandra simulation. Mosdef_cassandra generates an input file
# as well as an MCF. Later, we will use a mosdef_cassandra
# input file as a template and replace the MCF file with the GMSO MCF file

box = mb.Box([3.0, 3.0, 3.0])
species = to_parmed(typed_ethane)
system = mc.System([box], [species], mols_to_add=[[5]])
Expand All @@ -381,11 +416,86 @@
system=system,
moveset=moveset,
run_type="equilibration",
run_length=100,
run_length=0,
temperature=300.0 * u.K,
run_name="nvt_mbuild",
seeds=[12356, 64321],
)

py, fraglib_setup, cassandra = detect_cassandra_binaries()

# TODO: not sure why the cassandra MCF writer of mBuild
# outputs a different intramolecular exclusions relative
# to the GMSO writer. This is a temporary fix to make the
# test pass. We should investigate this further.
# Also, try to use the function top.set_lj_scale() and see how
# to update subtopologies.
Comment on lines +427 to +432
Copy link
Member

Choose a reason for hiding this comment

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

Is this something we need to look into now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not think this is something we have to worry about for now.


write_mcf(typed_ethane, "gmso.mcf")
mcf_data, mcf_idx = parse_mcf("gmso.mcf")
mcf_data[mcf_idx["Intra_Scaling"] + 1][0:4] = [
"0.0",
"0.0",
"0.0",
"1.0",
]
mcf_data[mcf_idx["Intra_Scaling"] + 2][0:4] = [
"0.0",
"0.0",
"0.0",
"1.0",
]
with open("gmso.mcf", mode="w") as f:
for line in mcf_data:
f.write(" ".join(line) + "\n")

inp_file = write_input(
system=system,
moveset=moveset,
run_type="equilibration",
run_length=0,
temperature=300.0 * u.K,
run_name="top",
run_name="nvt_gmso",
seeds=[12356, 64321],
)

with open(inp_file, mode="r") as f:
lines = f.read()
lines = lines.replace("species1.mcf", "gmso.mcf")
# The fragment files section is empty unless
# restart option is used in mosdef_cassandra.
# See the mosdef_cassandra.writers.inp_functions.generate_input
lines = lines.replace(
"# Fragment_Files",
"# Fragment_Files\nspecies1/frag1/frag1.dat 1\nspecies1/frag2/frag2.dat 2\n",
)

with open(inp_file, mode="w") as f:
f.writelines(lines)

# Run the simulation with the GMSO MCF file
code, out, err = run_cassandra(cassandra, inp_file)

assert code == 0
assert "complete" in out

# Parse log files
with open("nvt_gmso.out.log", mode="r") as f:
lines = f.readlines()
for line in lines:
daico007 marked this conversation as resolved.
Show resolved Hide resolved
if "Total system energy" in line:
energy = float(line.split()[-1])
break

with open("nvt_mbuild.out.log", mode="r") as f:
lines = f.readlines()
for line in lines:
daico007 marked this conversation as resolved.
Show resolved Hide resolved
if "Total system energy" in line:
energy_ref = float(line.split()[-1])
break

assert np.isclose(energy, energy_ref, rtol=1e-3)
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
Fixed Show fixed Hide fixed

@pytest.mark.skipif(not has_parmed, reason="ParmEd is not installed")
def test_parmed_vs_gmso(self, parmed_ethane):
"""
Expand Down
Loading