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

Conversation

chrisjonesBSU
Copy link
Contributor

@chrisjonesBSU chrisjonesBSU commented Mar 8, 2024

This PR starts adding support for periodic improper potentials as they were recently added to Hoomd version 4.5.

I'm running into some issues, I figured I'd get the PR submitted so there are some other eyes on it as well. Here is a gist of the notebook I'm testing it out with..

One note: I made some changes to the environment file because I was having issues with mBuild plugins using mBuild < 17. This is a separate issue, but the pinned versions in environment-dev.yml are changed here to fix that for now.

The contents of the notebook is basically the unit test we have for using GAFF, but with benzene instead of ethanol.

import mbuild as mb
import unyt as u
import gmso
from gmso.external import from_mbuild, to_hoomd_forcefield, to_hoomd_snapshot
from gmso.core.forcefield import ForceField
from gmso.parameterization import apply
from gmso.utils.io import get_fn



benzene = mb.load("c1ccccc1", smiles=True)
benzene.box = mb.Box([5, 5, 5,])
top = from_mbuild(benzene)

base_units = dict(mass=u.g/u.mol, length=u.nm, energy=u.kJ/u.mol)
gaff = ForceField(get_fn("gmso_xmls/test_ffstyles/gaff.xml"))
paramaterized_top = apply(top=top, forcefields=gaff, identify_connections=True)
snap, _ = to_hoomd_snapshot(top, base_units=base_units)
forces, _ = to_hoomd_forcefield(top, r_cut=1.4, base_units=base_units)

It looks like hoomd improper force params are being written with the wild cards?

>>> improper_force = forces["impropers"][0]
>>> for param in improper_force.params:
>>>    print(param)
>>>    print(improper_force.params[param])

ca-*-*-ha
_HOOMDDict{'k': 4.6024, 'n': 2, 'd': 1, 'chi0': 3.141592653589793}

This doesn't match the snapshot improper types

>>> print(snap.impropers.types)
['ca-ca-ca-ha']

I'll keep working on this, but wanted to get it out there for review; maybe I'm missing something obvious at the moment.

@chrisjonesBSU chrisjonesBSU added the WIP work in progress - do not merge label Mar 8, 2024
environment-dev.yml Outdated Show resolved Hide resolved
gmso/external/convert_hoomd.py Show resolved Hide resolved
gmso/tests/test_hoomd.py Outdated Show resolved Hide resolved
@chrisjonesBSU chrisjonesBSU removed the WIP work in progress - do not merge label Apr 5, 2024
@chrisjonesBSU chrisjonesBSU marked this pull request as ready for review April 5, 2024 20:11
@chrisjonesBSU
Copy link
Contributor Author

chrisjonesBSU commented Apr 5, 2024

So, there is kind of a band-aid fix in here that I think is sort of related to #767, but when the forcefield uses wild cards, these carry over into member_classes, so the force entry to hoomd looks something like [ca, *, *, ha] while the snapshot's particle types are [ca, ca, ca, ha].

Right now, the snapshot writer uses sort_connection_members while the forcefield writer(s) use sort_by_classes

The band-aid fix is to check for * in the forcefield members, and if it's found, use sort_by_types instead.

IMO, I think this is fine for now, but there is still the overall larger issue of having more flexibility in both giving instructions on what to use in the writers (types vs classes) as well as flexibility in combining them (as is discussed in #767)

@chrisjonesBSU
Copy link
Contributor Author

This should be ready to merge, the only test failing is test_charmm_improper_ff which is unrelated to this PR.

Copy link
Contributor

@CalCraven CalCraven left a comment

Choose a reason for hiding this comment

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

Lets get #815 merged in to main and to this PR, then I think it's good to go.

@CalCraven
Copy link
Contributor

Raise and issue about python < 3.12 though once this is merged, since we'll want to fix that when we get to that issue.

Copy link
Member

@daico007 daico007 left a comment

Choose a reason for hiding this comment

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

LGTM!

@daico007 daico007 merged commit 9b7ae65 into mosdef-hub:main May 16, 2024
12 checks passed
@chrisjonesBSU chrisjonesBSU deleted the hoomd-dihedrals branch May 16, 2024 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants