Skip to content

Commit

Permalink
Add basic example with sample files (#58)
Browse files Browse the repository at this point in the history
* Add basic example with sample files

* Delete unused lines and platform hardcoding
  • Loading branch information
sukritsingh authored Feb 28, 2025
1 parent 95bfd46 commit 5e59ee1
Show file tree
Hide file tree
Showing 5 changed files with 59,552 additions and 0 deletions.
74 changes: 74 additions & 0 deletions examples/basic-example/colvar
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#! FIELDS time d1 d2 sigma_d1 sigma_d2 height biasf
#! SET multivariate false
#! SET kerneltype stretched-gaussian
0.1 0.498655081695887 1.382666461806092 0.1 0.1 0.3 -1
0.2 0.494599870944836 1.381001666792562 0.1 0.1 0.3 -1
0.3 0.482054172223331 1.370704645530069 0.1 0.1 0.3 -1
0.4 0.4802341097780686 1.361491094986752 0.1 0.1 0.3 -1
0.5 0.4993848231973986 1.361376811182213 0.1 0.1 0.3 -1
0.6 0.5106914765537734 1.366276948267733 0.1 0.1 0.3 -1
0.7000000000000001 0.4758365157631398 1.359340797509302 0.1 0.1 0.3 -1
0.8 0.4745513049085021 1.324543560528104 0.1 0.1 0.3 -1
0.9 0.4851896562326835 1.333380370894482 0.1 0.1 0.3 -1
1 0.4897829234848108 1.31943150711531 0.1 0.1 0.3 -1
1.1 0.5248804290384005 1.319737018871575 0.1 0.1 0.3 -1
1.2 0.5143430357331654 1.290236196907636 0.1 0.1 0.3 -1
1.3 0.4808774621251345 1.304135284100731 0.1 0.1 0.3 -1
1.4 0.4733715013757555 1.31539881909632 0.1 0.1 0.3 -1
1.5 0.4991673005262661 1.319912632266878 0.1 0.1 0.3 -1
1.6 0.5214534255686132 1.322998256434019 0.1 0.1 0.3 -1
1.7 0.5483945882182972 1.343353550537617 0.1 0.1 0.3 -1
1.8 0.5594861385845762 1.367260563769174 0.1 0.1 0.3 -1
1.9 0.5531922219593026 1.368926230290174 0.1 0.1 0.3 -1
2 0.5200974078799517 1.368993533580745 0.1 0.1 0.3 -1
2.1 0.5337348196804841 1.320686366649015 0.1 0.1 0.3 -1
2.2 0.4925144648334505 1.318244519481564 0.1 0.1 0.3 -1
2.3 0.4701473642209666 1.286367094240368 0.1 0.1 0.3 -1
2.4 0.4656128791786588 1.298805544664715 0.1 0.1 0.3 -1
2.5 0.4860758972313766 1.29690608363821 0.1 0.1 0.3 -1
2.6 0.4768939875332491 1.288672408626634 0.1 0.1 0.3 -1
2.7 0.4674798547686493 1.286690702917634 0.1 0.1 0.3 -1
2.8 0.4724381440010745 1.295248254256846 0.1 0.1 0.3 -1
2.9 0.4490870657519744 1.287652383079436 0.1 0.1 0.3 -1
3 0.441268173646763 1.299752250277727 0.1 0.1 0.3 -1
3.1 0.43702273631009 1.291142279738861 0.1 0.1 0.3 -1
3.2 0.4550974270367029 1.234497993011694 0.1 0.1 0.3 -1
3.3 0.4779039645408391 1.243147463916595 0.1 0.1 0.3 -1
3.4 0.490700288573867 1.26358104326537 0.1 0.1 0.3 -1
3.5 0.4526664766712185 1.216663253011851 0.1 0.1 0.3 -1
3.6 0.450294687545042 1.230540130757497 0.1 0.1 0.3 -1
3.7 0.4588793624545481 1.21528204720095 0.1 0.1 0.3 -1
3.8 0.4789855718549996 1.229185391267451 0.1 0.1 0.3 -1
3.9 0.5156279520936156 1.235816294427036 0.1 0.1 0.3 -1
4 0.4977005488500051 1.266587786338612 0.1 0.1 0.3 -1
4.1 0.5022691370000626 1.25547288018717 0.1 0.1 0.3 -1
4.2 0.4941219013631646 1.286006453745929 0.1 0.1 0.3 -1
4.3 0.4640315353942189 1.23357211647468 0.1 0.1 0.3 -1
4.4 0.4733546835469054 1.24482898706356 0.1 0.1 0.3 -1
4.5 0.4738358445938695 1.263520881966086 0.1 0.1 0.3 -1
4.600000000000001 0.4821882599810979 1.279901644884053 0.1 0.1 0.3 -1
4.7 0.499220154350828 1.320681568970071 0.1 0.1 0.3 -1
4.8 0.4916666109921281 1.36673296988298 0.1 0.1 0.3 -1
4.9 0.4830066242668785 1.362410518605849 0.1 0.1 0.3 -1
5 0.5039263074774837 1.360754095467146 0.1 0.1 0.3 -1
5.100000000000001 0.5401507372253738 1.377420609939865 0.1 0.1 0.3 -1
5.2 0.5268877559123072 1.339739972864384 0.1 0.1 0.3 -1
5.3 0.481805393857138 1.320411895988865 0.1 0.1 0.3 -1
5.4 0.4551215518248061 1.271206339378599 0.1 0.1 0.3 -1
5.5 0.4527488150018485 1.279667381663764 0.1 0.1 0.3 -1
5.600000000000001 0.4392219851703806 1.294950550665045 0.1 0.1 0.3 -1
5.7 0.4158425680169793 1.336023647468042 0.1 0.1 0.3 -1
5.8 0.3851632910069447 1.319372993357186 0.1 0.1 0.3 -1
5.9 0.3623843756949884 1.347775047582042 0.1 0.1 0.3 -1
6 0.3645139106354769 1.370681001292249 0.1 0.1 0.3 -1
6.100000000000001 0.3958232136378107 1.354173205356781 0.1 0.1 0.3 -1
6.2 0.4180516484585129 1.312838063485847 0.1 0.1 0.3 -1
6.3 0.4415778505975485 1.297038459535324 0.1 0.1 0.3 -1
6.4 0.4870318901303162 1.275773397679056 0.1 0.1 0.3 -1
6.5 0.5252077967730521 1.281103378057729 0.1 0.1 0.3 -1
6.600000000000001 0.5509405530919623 1.260765530137411 0.1 0.1 0.3 -1
6.7 0.5888266499954234 1.301774753689998 0.1 0.1 0.3 -1
6.8 0.6344563993627238 1.295806969235325 0.1 0.1 0.3 -1
6.9 0.6390447357244761 1.318389921593274 0.1 0.1 0.3 -1
7 0.6175163115571576 1.338183933078174 0.1 0.1 0.3 -1
7.100000000000001 0.5939166696737974 1.337053651536157 0.1 0.1 0.3 -1
83 changes: 83 additions & 0 deletions examples/basic-example/plumed-metad-sim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from openmm.app import *
from openmm import *
from openmm.unit import *
import bz2
from openmmplumed import PlumedForce

sim_temp = 300.0 * kelvin
H_mass = 4.0 * amu
time_step = 0.002 * picosecond
nb_cutoff = 10.0 * angstrom
box_padding = 12.0 * angstrom
salt_conc = 0.15 * molar
current_file="apo-met-meta"

# Misc parameters
restraint_distance = 0.0 * angstroms
restart_freq = 10
log_freq = 10
prd_steps = 100
iterations = 500000

# unpack the equilbirated system
bz2_file = f'system.xml.bz2'
with bz2.open(bz2_file, 'rb') as infile:
system = XmlSerializer.deserialize(infile.read().decode())

# unpack the state
bz2_file = f'state.xml.bz2'
with bz2.open(bz2_file, 'rb') as infile:
state = XmlSerializer.deserialize(infile.read().decode())

# get topology info from equilibrated protein
pdb = PDBFile('receptor_equilibrated.pdb')
positions=pdb.positions
topology=pdb.topology

# Add barostat
system.addForce(openmm.MonteCarloBarostat(1*bar, sim_temp))

# Generate collective variables
# here we have 2 distances together using the PLUMED syntax
# Remember: Add +1 to each atom index when adding to PLUMED
script = """
d1: DISTANCE ATOMS=2465,975
d2: DISTANCE ATOMS=2465,642
METAD ARG=d1,d2 SIGMA=0.1,0.1 HEIGHT=0.3 PACE=50 FILE=colvar"""
system.addForce(PlumedForce(script))

integrator = LangevinIntegrator(sim_temp, 1.0/picosecond, time_step)

# put everything together into a simulation object
simulation = Simulation(pdb.topology, system, integrator)

# Only use the below line if you're loading from a previous checkpoint
# simulation.loadCheckpoint("%s.chk" % current_file)

# Reporters
simulation.reporters.append(DCDReporter(''+current_file+''+ '.dcd', restart_freq))
simulation.reporters.append(CheckpointReporter(''+current_file+''+ '.chk',
min(prd_steps, 10*restart_freq)))
simulation.reporters.append(StateDataReporter(open('log.' + current_file+'', 'w'),
log_freq,
step=True,
potentialEnergy=True,
kineticEnergy=True,
totalEnergy=True,
temperature=True,
volume=True,
density=True,
speed=True))

# Set positions
simulation.context.setPositions(positions)

# minimize
print(' initial : %s' % (simulation.context.getState(getEnergy=True).getPotentialEnergy()))
simulation.minimizeEnergy()
print(' final : %s' % (simulation.context.getState(getEnergy=True).getPotentialEnergy()))

for i in range(iterations):
simulation.step(10)


Loading

0 comments on commit 5e59ee1

Please sign in to comment.