from __future__ import print_function
from time import gmtime, strftime
print('updated: ', strftime("%Y-%m-%d", gmtime()))
from IPython.display import Image
Image("images/real_time_md.png")
Or any one that wants to use this notebook for teaching or demonstration
amber.conda install nglview==0.5.1 -c ambermd
amber.jupyter notebook notebook.ipynb # notebook.ipynb is the name of this notebook
# you can make your own notebook and copy commands in this notebook
The peptide used in this demonstration is CLN025, a variant of chignolin
This tutorial uses GBNeck2 + ff14SBonlysc
You can use any text editor but we can create/edit files in this notebook by %%file
command
%%file leap.in
source leaprc.protein.ff14SBonlysc
x = sequence {TYR TYR ASP PRO GLU THR GLY THR TRP TYR}
set default PBradii mbondi3
saveamberparm x peptide.top peptide.crd
savepdb x peptide.pdb
quit
!$AMBERHOME/bin/tleap -f leap.in > leap.log
!ls peptide.*
%%file min.in
Stage 1 - minimisation
&cntrl
imin=1, maxcyc=1000, ncyc=500,
cut=999.,
igb=8,
ntb=0,
ntpr=100
/
%%file md.in
md.in, 100 ps
&cntrl
imin = 0, nstlim = 50000, dt = 0.002,
ntx = 1, irest = 0, ig = -1,
ntt=3, tempi = 300.0, temp0 = 300.0, gamma_ln = 1.0,
ntc = 2, ntf = 2,
ntwx = 25000, ntwe = 0, ntwr = 100, ntpr = 25000,
cut = 999.0,
ntb = 0,
igb = 8, gbsa = 0,
nscm = 25000,
ioutfm = 1,
/
!$AMBERHOME/bin/sander -O -i min.in -p peptide.top -c peptide.crd -r min.rst7
!ls min.rst7
# use pytraj for reading coordinates from rst7 file
import pytraj as pt
# use nglview for visualizing this notebook
import nglview as nv
from time import time, sleep
def get_coordinates():
# return coordinates in restart file
# we reuse topology from reference structure to avoid reload
traj = pt.load('md.rst', top=ref.top)
# perform superpose to min.rst7 to remove translation and rotation
# superpose is similiar to cpptraj's rms
traj.superpose(mask='@CA', ref=ref)
return traj.xyz[0]
def update_view(view, delay=1, timeout=300):
# update coordinates every `delay` second, default 1 second
from time import sleep
coordinates = get_coordinates()
view.coordinates_dict = {0: coordinates}
sleep(delay)
def run_view(view, delay=1., timeout=300):
# stop viewing after `timeout` seconds, default 300 (5 minutes)
start = time()
stop = start
while stop - start < timeout:
update_view(view, delay=delay)
stop = time()
def run_md():
# run md simulation via sander
import os
import subprocess
# you can use sander.MPI, pmemd, pmemd.MPI, pmemd.cuda too
# need to provide absolute directory for sander
sander = os.getenv('AMBERHOME') + '/bin/sander'
cm = "{sander} -O -i md.in -o md.out -p peptide.top -c min.rst7 -r md.rst -x md.nc".format(sander=sander)
# we will run sander in background so we can keep using this notebook
print('running {}'.format(cm))
return subprocess.Popen(cm.split())
# load minimized struture and use it as reference for superposing
ref = pt.load('min.rst7', top='peptide.top')
# view starting structure (min.rst7)
view = nv.show_pytraj(ref)
view
view.clear_representations()
# add more representation here
view.add_ball_and_stick()
view.add_cartoon()
view.parameters = dict(camera_type='perpective',
background_color='black',
fog_near=60,
clip_dist=0)
# run MD simulation in background so we can keep using this notebook
process = run_md()
# If you want to kill sander job, please use choose Kernel --> Interupt (top page)
# If you want to run again (fresh MD), run previous step first (process = run_md()), then run this cell
# change the timeout if needed
# I am using 20 seconds, but you can make it run for few days too
run_view(view, timeout=20)
Real time visualization does not slow down the speed of your simulation if your simulation and this notebook are running in different CPU.
You can also run pmemd.cuda on GPU and use this notebook, just need to update run_md
method
It's not necessarily to run MD simulation in this notebook, pytraj/nglview only load and visualize your restart file
See also: pytraj and nglview tutorials