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

Add support for hoomd.md.improper.Periodic in to_hoomd_forcefield #807

Merged
merged 21 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9be2fce
add dict entry for periodic impropers
chrisjonesBSU Mar 7, 2024
cd2ce51
add sign factor (d) to Periodic Improper
chrisjonesBSU Mar 8, 2024
e08f9d5
Change key name to match GAFF, hard code d = 1
chrisjonesBSU Mar 8, 2024
0cd676d
remove d param from template
chrisjonesBSU Mar 8, 2024
8965e68
Remove d from expression
chrisjonesBSU Mar 8, 2024
75aba93
change d from int to float
chrisjonesBSU Mar 8, 2024
d865f79
Merge branch 'main' of github.com:mosdef-hub/gmso into hoomd-dihedrals
chrisjonesBSU Mar 28, 2024
8678d12
Merge branch 'hoomd-dihedrals' of github.com:chrisjonesBSU/gmso into …
chrisjonesBSU Mar 28, 2024
200ddc4
Merge branch 'main' of github.com:mosdef-hub/gmso into hoomd-dihedrals
chrisjonesBSU Apr 3, 2024
d987099
update python version, remove ethanol from unit test
chrisjonesBSU Apr 3, 2024
8533746
if wild card in member classes, use member types instead
chrisjonesBSU Apr 5, 2024
3f17683
use wildcard check for all forcefield writers
chrisjonesBSU Apr 5, 2024
fea5640
fix typo in env files
chrisjonesBSU Apr 5, 2024
a42748e
Fix variable name.
chrisjonesBSU Apr 5, 2024
4497a3c
use .get() for d parameter
chrisjonesBSU Apr 15, 2024
81212ec
Merge branch 'main' of github.com:mosdef-hub/gmso into hoomd-dihedrals
chrisjonesBSU Apr 29, 2024
8564317
fix conflicts
chrisjonesBSU May 6, 2024
c8cc00d
Merge branch 'main' into hoomd-dihedrals
daico007 May 6, 2024
9268768
Merge branch 'main' into hoomd-dihedrals
chrisjonesBSU May 7, 2024
44bc437
Merge branch 'main' into hoomd-dihedrals
daico007 May 16, 2024
62f1e9f
change box size and seed for packing in test
chrisjonesBSU May 16, 2024
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
4 changes: 2 additions & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: gmso-dev
channels:
- conda-forge
dependencies:
- python>=3.8
- python=>3.8, <3.12
- boltons
- numpy
- sympy
Expand All @@ -12,7 +12,7 @@ dependencies:
- pydantic>=2
- networkx
- pytest
- mbuild>=0.11.0
- mbuild>=0.17.0
- openbabel>=3.0.0
- foyer>=0.11.3
- forcefield-utilities>=0.2.1
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: gmso
channels:
- conda-forge
dependencies:
- python>=3.8
- python>=3.8, <3.12
- boltons
- numpy
- sympy
Expand Down
72 changes: 59 additions & 13 deletions gmso/external/convert_hoomd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
)
from gmso.utils.geometry import coord_shift
from gmso.utils.io import has_gsd, has_hoomd
from gmso.utils.sorting import sort_by_classes, sort_connection_members
from gmso.utils.sorting import (
sort_by_classes,
sort_by_types,
sort_connection_members,
)
from gmso.utils.units import convert_params_units

if has_gsd:
Expand All @@ -43,6 +47,8 @@
"mass": u.g / u.mol, # aka amu
}

hoomd_version = hoomd.version.version.split(".")


def to_gsd_snapshot(
top,
Expand Down Expand Up @@ -678,13 +684,15 @@
harmonic_bond_potential = templates["HarmonicBondPotential"]
harmonic_angle_potential = templates["HarmonicAnglePotential"]
periodic_torsion_potential = templates["PeriodicTorsionPotential"]
harmonic_torsion_potential = templates["HarmonicTorsionPotential"]
opls_torsion_potential = templates["OPLSTorsionPotential"]
rb_torsion_potential = templates["RyckaertBellemansTorsionPotential"]
accepted_potentials = (
lennard_jones_potential,
harmonic_bond_potential,
harmonic_angle_potential,
periodic_torsion_potential,
harmonic_torsion_potential,
opls_torsion_potential,
rb_torsion_potential,
)
Expand Down Expand Up @@ -993,8 +1001,11 @@
):
for btype in btypes:
# TODO: Unit conversion
member_classes = sort_by_classes(btype)
container.params["-".join(member_classes)] = {
members = sort_by_classes(btype)
# If wild card in class, sort by types instead
if "*" in members:
members = sort_by_types(btype)
container.params["-".join(members)] = {
"k": btype.parameters["k"],
"r0": btype.parameters["r_eq"],
}
Expand Down Expand Up @@ -1063,8 +1074,11 @@
agtypes,
):
for agtype in agtypes:
member_classes = sort_by_classes(agtype)
container.params["-".join(member_classes)] = {
members = sort_by_classes(agtype)
# If wild card in class, sort by types instead
if "*" in members:
members = sort_by_types(atype)
container.params["-".join(members)] = {
"k": agtype.parameters["k"],
"t0": agtype.parameters["theta_eq"],
}
Expand Down Expand Up @@ -1120,7 +1134,6 @@
},
}

hoomd_version = hoomd.version.version.split(".")
if int(hoomd_version[0]) >= 4 or (
int(hoomd_version[0]) == 3 and int(hoomd_version[1]) >= 8
):
Expand Down Expand Up @@ -1307,12 +1320,24 @@
base_units,
)

itype_group_map = {
"HarmonicImproperPotenial": {
"container": hoomd.md.improper.Harmonic,
"parser": _parse_harmonic_improper,
},
}
if int(hoomd_version[0]) >= 4 and int(hoomd_version[1]) >= 5:
itype_group_map = {
"HarmonicImproperPotential": {
"container": hoomd.md.improper.Harmonic,
"parser": _parse_harmonic_improper,
},
"PeriodicTorsionPotential": {
"container": hoomd.md.improper.Periodic,
"parser": _parse_periodic_improper,
},
}
else:
itype_group_map = {
"HarmonicImproperPotential": {
"container": hoomd.md.improper.Harmonic,
"parser": _parse_harmonic_improper,
},
}

improper_forces = list()
for group in groups:
Expand All @@ -1330,14 +1355,35 @@
itypes,
):
for itype in itypes:
member_types = sort_by_classes(itype)
members = sort_by_classes(itype)
# If wild card in class, sort by types instead
if "*" in members:
members = sort_by_types(itype)
Fixed Show fixed Hide fixed
container.params["-".join(member_types)] = {
"k": itype.parameters["k"],
"chi0": itype.parameters["phi_eq"], # diff nomenclature?
}
return container


def _parse_periodic_improper(
daico007 marked this conversation as resolved.
Show resolved Hide resolved
container,
itypes,
):
for itype in itypes:
members = sort_by_classes(itype)
# If wild card in class, sort by types instead
if "*" in members:
members = sort_by_types(itype)
container.params["-".join(members)] = {
"k": itype.parameters["k"],
"chi0": itype.parameters["phi_eq"],
"n": itype.parameters["n"],
"d": 1.0,
chrisjonesBSU marked this conversation as resolved.
Show resolved Hide resolved
}
return container


def _validate_base_units(base_units, top, auto_scale, potential_types=None):
"""Validate the provided base units, infer units (based on top's positions and masses) if none is provided."""
if base_units and auto_scale:
Expand Down
6 changes: 3 additions & 3 deletions gmso/tests/test_hoomd.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ def test_gaff_sim(self, gaff_forcefield):
"length": u.nm,
"energy": u.kJ / u.mol,
}
ethanol = mb.load("CCO", smiles=True)
ethanol.box = mb.Box([5, 5, 5])
top = ethanol.to_gmso()
benzene = mb.load("c1ccccc1", smiles=True)
benzene.box = mb.Box([5, 5, 5])
top = benzene.to_gmso()
parameterized_top = apply(
top, gaff_forcefield, identify_connections=True
)
Expand Down
Loading