Skip to content

Commit

Permalink
Add writer_kwargs to MDAReporter and speed up testing (#9)
Browse files Browse the repository at this point in the history
* Add code for serializing simulation.

(cherry picked from commit 5e1584c)

* Add serialized XML files for integrator, system, and state.

(cherry picked from commit 17b11e1)

* Move villin.pdb to sit alongside other serialized simulation files.

(cherry picked from commit 44f4304)

* Add a writer_kwargs argument to MDAReporter.

(cherry picked from commit b3032d6)

* Update Changelog.

(cherry picked from commit 9c7e1a8)

* Update tests to use a serialized simulation, this makes it so we don't have to reinstantiate the simulation with each test and SIGNIFICANTLY speeds up the test suite.

* Update changelog

* Better document test data creation.

* Correct outputs for describeNextReport and add testing.
  • Loading branch information
orionarcher authored Apr 5, 2024
1 parent d665b3d commit d2d1b1d
Show file tree
Hide file tree
Showing 10 changed files with 59,014 additions and 53 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ The rules for this file:
* accompany each entry with github issue/PR number (Issue #xyz)
-->

## [Unreleased]
## v0.1.1

### Authors
<!-- GitHub usernames of contributors to this release -->
- @sef43, @richardjgowers, @orionarcher

### Added
<!-- New added features -->
- Serialized simulation used in testing to speed up
- Added writer_kwargs to `MDAReporter` instantiation
- Added `MDAReporter` core logic and documentation

### Fixed
<!-- Bug fixes -->
Expand Down
6 changes: 5 additions & 1 deletion mdareporter/data/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
from pkg_resources import resource_filename

MDANALYSIS_LOGO = resource_filename(__name__, "mda.txt")
VILLIN_PDB = resource_filename(__name__, "villin.pdb")
VILLIN_PDB = resource_filename(__name__, "villin_simulation/villin.pdb")
INTEGRATOR_XML = resource_filename(__name__, "villin_simulation/integrator.xml")
SYSTEM_XML = resource_filename(__name__, "villin_simulation/system.xml")
STATE_XML = resource_filename(__name__, "villin_simulation/state.xml")

3 changes: 3 additions & 0 deletions mdareporter/data/villin_simulation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains a serialized simulation for use in testing.

The `integrator.xml`, `state.xml`, and `system.xml` here were generated by serialize_simulation.py.
2 changes: 2 additions & 0 deletions mdareporter/data/villin_simulation/integrator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" ?>
<Integrator constraintTolerance="1e-05" friction="1" randomSeed="0" stepSize=".004" temperature="300" type="LangevinMiddleIntegrator" version="1"/>
39 changes: 39 additions & 0 deletions mdareporter/data/villin_simulation/serialize_simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from openmm.app import ForceField, Simulation, PME, HBonds
from openmm import LangevinMiddleIntegrator
from openmm.unit import nanometer, picosecond, kelvin

from openmm.app import PDBFile, Topology
from openmm.openmm import XmlSerializer
from mdareporter.data.files import VILLIN_PDB


pdb = PDBFile(VILLIN_PDB)

forcefield = ForceField("amber14-all.xml", "amber14/tip3pfb.xml")
system = forcefield.createSystem(
pdb.topology, nonbondedMethod=PME, nonbondedCutoff=1 * nanometer, constraints=HBonds
)
integrator = LangevinMiddleIntegrator(300 * kelvin, 1 / picosecond, 0.004 * picosecond)
simulation = Simulation(pdb.topology, system, integrator)
simulation.context.setPositions(pdb.positions)
simulation.minimizeEnergy()


pdb.writeFile(
simulation.topology,
simulation.context.getState(getPositions=True).getPositions(),
open("output.pdb", "w"),
)
system_xml = XmlSerializer.serialize(system)
integrator_xml = XmlSerializer.serialize(integrator)
state_xml = XmlSerializer.serialize(
simulation.context.getState(getPositions=True, getVelocities=True)
)

# write to files
with open("system.xml", "w") as f:
f.write(system_xml)
with open("integrator.xml", "w") as f:
f.write(integrator_xml)
with open("state.xml", "w") as f:
f.write(state_xml)
17,746 changes: 17,746 additions & 0 deletions mdareporter/data/villin_simulation/state.xml

Large diffs are not rendered by default.

Loading

0 comments on commit d2d1b1d

Please sign in to comment.