-
Notifications
You must be signed in to change notification settings - Fork 81
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
Snapshot converter, hoomd simulation module #622
Conversation
This pull request introduces 8 alerts when merging ad0353a into ed96251 - view on LGTM.com new alerts:
|
Codecov Report
@@ Coverage Diff @@
## master #622 +/- ##
==========================================
- Coverage 90.81% 82.56% -8.26%
==========================================
Files 50 52 +2
Lines 3898 4290 +392
==========================================
+ Hits 3540 3542 +2
- Misses 358 748 +390
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a typo fix and changing the hoomd imports to use _import
.
I can try this on a few UA systems later when you think its ready to test.
mbuild/formats/hoomd_simulation.py
Outdated
ref_energy=1.0, mixing_rule='lorentz', r_cut=1.2, | ||
snapshot_kwargs={}, | ||
pppm_kwargs={'Nx':1, 'Ny':1, 'Nz':1, 'order':4}): | ||
import hoomd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should probably do an _import
here, right? Since hoomd is not a requirement.
mbuild/formats/hoomd_simulation.py
Outdated
return harmonic_angle | ||
|
||
def _init_hoomd_dihedrals(structure, ref_energy=1.0): | ||
# Identify the uniqeu dihedral types before setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Identify the uniqeu dihedral types before setting | |
# Identify the unique dihedral types before setting |
mbuild/formats/hoomd_snapshot.py
Outdated
ref_energy=1.0, rigid_bodies=None, shift_coords=True, | ||
write_special_pairs=True): | ||
"""Convert parmed.Structure to hoomd.data.Snapshot""" | ||
import hoomd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here for the _import
…ization, docuemtnatoin
…ng FF translations, passing bad inputs
Barring some other issues with dependency syntax breaking foyer (netwworkx), I think this PR is ready to be looked at
import mbuild as mb
from foyer import Forcefield
from mbuild.examples import Ethane
compound = Ethane()
mixture_box = mb.fill_box(compound, n_compounds=10, box=[10,10,10])
ff = Forcefield(name='oplsaa')
struc = ff.apply(mixture_box)
struc.save('stuff.mol2', overwrite=True)
from mbuild.formats.hoomd_simulation import create_hoomd_simulation
create_hoomd_simulation(struc, ref_distance=10, r_cut=1.2, snapshot_kwargs={'shift_coords':True})
import hoomd
import hoomd.md
import hoomd.group
all = hoomd.group.all()
hoomd.md.integrate.mode_standard(dt=0.0001)
integrator = hoomd.md.integrate.nvt(group=all, kT=2.5, tau=1)
hoomd.dump.dcd('query.dcd', period=10, group=all, phase=0, overwrite=True,
unwrap_full=False)
hoomd.run(1e3) |
This pull request introduces 8 alerts when merging c924855 into ed96251 - view on LGTM.com new alerts:
|
import mbuild as mb
import parmed as pmd
import foyer
from mbuild.examples import Ethane
import hoomd
eth = Ethane()
cmpd = mb.fill_box(eth, n_compounds=10, box=[10,10,10])
ff = foyer.Forcefield(name='oplsaa')
structure = ff.apply(cmpd)
for atom in structure.atoms:
atom.charge = 0
from mbuild.formats.hoomd_simulation import create_hoomd_simulation
create_hoomd_simulation(structure, ref_distance=10)
all = hoomd.group.all()
hoomd.md.integrate.mode_standard(dt=0.0000001)
hoomd.md.integrate.nve(all)
hoomd.run(1)
total_energy = 0
for force in hoomd.context.current.forces:
force_energy = force.get_energy(all)
print((force, force_energy))
total_energy += force_energy
print("Hoomd energy:{}".format(total_energy))
import simtk.openmm as openmm
import simtk.unit as unit
omm_system = structure.createSystem()
integrator = openmm.VerletIntegrator(1.0)
omm_context = openmm.Context(omm_system, integrator)
omm_context.setPositions(structure.positions)
omm_state = omm_context.getState(getEnergy=True)
omm_energy = omm_state.getPotentialEnergy().in_units_of(unit.kilocalories_per_mole)
print("Openmm energy:{}".format(omm_energy))
If charges are included, I get a lot of malloc errors |
This pull request introduces 8 alerts when merging 7ebe624 into ed96251 - view on LGTM.com new alerts:
|
For a box of two chargeless 30-anes (alkane with length 30):
From this, it looks like bonds, angles, and LJs are converted correctly.
|
This pull request introduces 8 alerts when merging ab79fdc into d6ad4db - view on LGTM.com new alerts:
|
@ahy3nz Can you put a script to replicate the 30-anes results in a gist or something so we don't have to rewrite it? The 10 ethane simulation in your previous comment seemed to have agreeing total energies, but was the dihedral energy off in that one too? |
For time sensitivity and calling it a day with this PR, I think this is ready to go. We're doing well translating bonded-parameters (with hoomd 2.8.0, and we also check for hoomd version). There might be some issues with nonbonded interactions, but diagnosing those issues might take longer. So for now I think this is ready for review before we do rigorous energy comparisons that could take a while If anyone's interested, try adapting this code: import mbuild as mb
from foyer import Forcefield
from mbuild.examples import Ethane
compound = Ethane()
mixture_box = mb.fill_box(compound, n_compounds=10, box=[10,10,10])
ff = Forcefield(name='oplsaa')
struc = ff.apply(mixture_box)
struc.save('stuff.mol2', overwrite=True)
from mbuild.formats.hoomd_simulation import create_hoomd_simulation
create_hoomd_simulation(struc, ref_distance=10, r_cut=1.2, snapshot_kwargs={'shift_coords':True})
import hoomd
import hoomd.md
import hoomd.group
all = hoomd.group.all()
hoomd.md.integrate.mode_standard(dt=0.0001)
integrator = hoomd.md.integrate.nvt(group=all, kT=2.5, tau=1)
hoomd.dump.dcd('query.dcd', period=10, group=all, phase=0, overwrite=True,
unwrap_full=False)
hoomd.run(1e3) |
@mosdef-hub/mosdef-contributors |
I will test this PR with one of our systems and if it works I will then review it! Thanks for all the hard work @ahy3nz I'm really excited for your energy validation project. |
Our lab has used this for atomistic and coarse-grain systems without issue, |
Could one of the UMich folks have a look at this? I am less familiar with the internals of HOOMD so I am hesitant to review it myself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks great.
I don't see constrain.distance
. Is this not supported, or are you not targeting any force fields that use hard distance constraints?
|
||
def _check_hoomd_version(): | ||
version = hoomd.__version__ | ||
version_numbers = version.split('.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check and error for major version >= 3.
With the current foyer Forcefield schema and As for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I wouldn't worry about the rigid body code for this PR.
Okay! Will deal with rigid bodies in another PR - I think this is good to go if someone wants to try putting together some mbuild + foyer + hoomd systems |
It works pretty well: https://github.com/cmelab/CG-Tutorial |
Add HOOMD snapshot and simulation converters
PR Summary:
Attempt at #619 and #570 . Given a parameterized structure, create a hoomd simulation, with all topological and force field information successfully preserved.
This code works all the way until the you hit
hoomd.run
when the simulation crashes. But it looks like we're successfully parametrizing bond and nonbonded interactions:An intermediate step was generating
hoomd.data.Snapshot
fromparmed.Structure
PR Checklist