You can use any text editor but we can create/edit files in this notebook by %%file command
In [2]:
%%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
# use pytraj for reading coordinates from rst7 fileimportpytrajaspt# use nglview for visualizing this notebookimportnglviewasnv
In [10]:
fromtimeimporttime,sleepdefget_coordinates():# return coordinates in restart file# we reuse topology from reference structure to avoid reloadtraj=pt.load('md.rst',top=ref.top)# perform superpose to min.rst7 to remove translation and rotation# superpose is similiar to cpptraj's rmstraj.superpose(mask='@CA',ref=ref)returntraj.xyz[0]defupdate_view(view,delay=1,timeout=300):# update coordinates every `delay` second, default 1 secondfromtimeimportsleepcoordinates=get_coordinates()view.coordinates_dict={0:coordinates}sleep(delay)defrun_view(view,delay=1.,timeout=300):# stop viewing after `timeout` seconds, default 300 (5 minutes)start=time()stop=startwhilestop-start<timeout:update_view(view,delay=delay)stop=time()defrun_md():# run md simulation via sanderimportosimportsubprocess# you can use sander.MPI, pmemd, pmemd.MPI, pmemd.cuda too# need to provide absolute directory for sandersander=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 notebookprint('running {}'.format(cm))returnsubprocess.Popen(cm.split())
In [11]:
# load minimized struture and use it as reference for superposingref=pt.load('min.rst7',top='peptide.top')# view starting structure (min.rst7)view=nv.show_pytraj(ref)view
In [12]:
view.clear_representations()# add more representation hereview.add_ball_and_stick()view.add_cartoon()view.parameters=dict(camera_type='perpective',background_color='black',fog_near=60,clip_dist=0)
In [13]:
# run MD simulation in background so we can keep using this notebookprocess=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 toorun_view(view,timeout=20)