-
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
Update create_hoomd_simulation
to support new HOOMD v3 API
#698
Conversation
This draft is a work in progress. It works with the HOOMD branch Also note that the API in |
closes #696 |
Codecov Report
@@ Coverage Diff @@
## master #698 +/- ##
==========================================
- Coverage 82.25% 82.24% -0.01%
==========================================
Files 57 58 +1
Lines 4706 4969 +263
==========================================
+ Hits 3871 4087 +216
- Misses 835 882 +47
Continue to review full report at Codecov.
|
Few API changes:
|
We need to expose the neighbor list we create/use in |
Updated testing script: import mbuild as mb
from foyer import Forcefield
from mbuild.formats.hoomd_simulation import create_hoomd_simulation, save_forcefield
import hoomd
smiles = "CCCCCCCCCCCC"
mb_dodecane = mb.load(smiles, smiles=True)
box = mb.box.Box([10, 10, 10])
my_box = mb.packing.fill_box(mb_dodecane, n_compounds=10, box=box)
my_box_pmd = my_box.to_parmed(box=box)
ff = Forcefield(name="oplsaa")
struc = ff.apply(
my_box_pmd,
assert_bond_params=True,
assert_angle_params=True,
assert_dihedral_params=False,
)
snapshot, forcefield, nl, values = create_hoomd_simulation(
struc, r_cut=1.2, auto_scale=True
)
langevin = hoomd.md.methods.Langevin(filter=hoomd.filter.All(), kT=1.0, seed=1)
integrator = hoomd.md.Integrator(dt=0.0001, methods=[langevin], forces=forcefield)
gsd = hoomd.dump.GSD(
filename="traj.gsd",
trigger=hoomd.trigger.Periodic(int(1e5)),
overwrite=True,
)
for force in forcefield:
if isinstance(force, hoomd.md.pair.LJ):
force.r_cut.default = 1.2
save_forcefield(forcefield, nl, overwrite=True)
sim = hoomd.Simulation(hoomd.device.CPU())
sim.create_state_from_snapshot(snapshot)
sim.operations.integrator = integrator
sim.operations.add(gsd)
sim.operations.schedule()
sim.run(3e5) |
Also quick note, currently is there is a bug where |
Okay assuming you have created a from mbuild.formats.hoomd_simulation import load_forcefield
import hoomd
forcefield, nl = load_forcefield()
langevin = hoomd.md.methods.Langevin(filter=hoomd.filter.All(), kT=1.0, seed=1)
integrator = hoomd.md.Integrator(dt=0.0001, methods=[langevin], forces=forcefield)
gsd = hoomd.dump.GSD(
filename="traj.gsd", trigger=hoomd.trigger.Periodic(int(1e5)), overwrite=True,
)
sim = hoomd.Simulation(hoomd.device.CPU())
sim.create_state_from_gsd("traj.gsd")
sim.operations.integrator = integrator
sim.operations.add(gsd)
sim.operations.schedule()
sim.run(3e5) |
We should think about keeping support for |
Replaced by #871 |
PR Summary:
Change
create_hoomd_simulation
to work with the new HOOMD v3 API. It now returns a snapshot and a forcefield (which is a list of HOOMD force compute objects).create_hoomd_simulation
no longer needs to initialize a HOOMDDevice
orSimulation
context.Users can inspect and modify the returned objects as needed before constructing a simulation using them.
Example:
Here is an example snippet which is an adaptation of https://github.com/cmelab/CG-Tutorial
Call
create_hoomd_simulation
:Construct the integrator and GSD output:
Modify an object in the force field:
Assemble and run the simulation:
PR Checklist