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 option to enforce PBC when retrieving coords #8

Merged
merged 1 commit into from
Apr 27, 2024

Conversation

SimonBoothroyd
Copy link
Collaborator

Description

This PR adds an option to the HREMD config that enables enforcing PBC when writting to trajectory files.

Supersedes #3

Status

  • Ready to go

Copy link

codecov bot commented Mar 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.94%. Comparing base (8ba6628) to head (7b23742).

Additional details and impacted files
@@           Coverage Diff           @@
##             main       #8   +/-   ##
=======================================
  Coverage   95.94%   95.94%           
=======================================
  Files          46       46           
  Lines        3008     3010    +2     
=======================================
+ Hits         2886     2888    +2     
  Misses        122      122           
Flag Coverage Δ
unittests 95.94% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

getVelocities=True,
getForces=True,
getEnergy=True,
enforcePeriodicBox=enforce_pbc,

Choose a reason for hiding this comment

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

Is there a reason you're not using the config object like you are above in hremd.py?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm yeah this function doesn't have a solo config, but rather a list of configs for each step, so there wasn't really a single good place to put this in a config or without changing the overall func signature that i could see.

Copy link

@tomschultz-roivant tomschultz-roivant left a comment

Choose a reason for hiding this comment

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

Also are there tests that should be added for this?

@SimonBoothroyd
Copy link
Collaborator Author

because this is a more visual thing, i did a test locally by running:

import pathlib

import openmm.app
import openmm.unit
import parmed

import femto.md.config
import femto.md.hremd
import femto.md.simulate

topology = parmed.load_file("argon_start.pdb", structure=True)

system = openmm.System()
for i in range(100):
    system.addParticle(39.948 * openmm.unit.amu)
lj = openmm.NonbondedForce()
lj.setNonbondedMethod(openmm.NonbondedForce.CutoffPeriodic)
lj.setCutoffDistance(8.5 * openmm.unit.angstrom)
for i in range(100):
    lj.addParticle(
        0.0, 3.405 * openmm.unit.angstrom, 0.238 * openmm.unit.kilocalories_per_mole
    )
system.addForce(lj)

integrator = openmm.LangevinIntegrator(
    90.0 * openmm.unit.kelvin,
    1.0 / openmm.unit.picosecond,
    0.002 * openmm.unit.picoseconds,
)
simulation = openmm.app.Simulation(topology.topology, system, integrator)

for wrap in [False, True]:
    simulation.context.setPeriodicBoxVectors(*topology.box_vectors)
    simulation.context.setPositions(topology.positions)

    femto.md.hremd.run_hremd(
        simulation,
        [{}],
        femto.md.config.HREMD(
            n_warmup_steps=0,
            n_cycles=1500,
            n_steps_per_cycle=10,
            trajectory_interval=100,
            trajectory_enforce_pbc=wrap,
        ),
        output_dir=pathlib.Path(f"wrap-{wrap}"),
    )

for wrap in [False, True]:
    final = femto.md.simulate.simulate_state(
        system,
        topology,
        {},
        [
            femto.md.config.Minimization(),
            femto.md.config.Simulation(
                integrator=femto.md.config.LangevinIntegrator(),
                temperature=90.0 * openmm.unit.kelvin,
                pressure=None,
                n_steps=15000,
            ),
        ],
        femto.md.constants.OpenMMPlatform.CPU,
        enforce_pbc=wrap,
    )
    openmm.app.PDBFile.writeFile(
        topology.topology, final.getPositions(), f"final-{wrap}.pdb"
    )

and visualising the final structure / trajectories and everything looked good!

i can try and think of a smoke test if you'd prefer?

@SimonBoothroyd SimonBoothroyd merged commit 36009c5 into main Apr 27, 2024
3 checks passed
@SimonBoothroyd SimonBoothroyd deleted the enforce-pbc branch April 27, 2024 10:10
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

2 participants