# YASARA MACRO # TOPIC: 3. Molecular Dynamics # TITLE: Play back a molecular dynamics trajectory # REQUIRES: Dynamics # AUTHOR: Elmar Krieger # LICENSE: GPL # DESCRIPTION: This macro plays provides an interactive molecular dynamics trajectory player # You can either set the target structure by clicking on Options > Macro > Set target, # or by uncommenting the line below and specifying it directly. #MacroTarget = 'c:\MyProject\1crn' # Set playback waittime (1 is maximum playback speed) waittime=12 # Choose trajectory format, sim or xtc format='sim' # Forcefield to use (these is a YASARA commands, so no '=' used) # Note that the force field has no influence on the trajectory playback. ForceField AMBER03 # In case the simulation was run without 'CorrectDrift on' and the solute diffused # through a periodic boundary, you can keep it centered here by specifying the number # of an atom close to the core of the solute, which will be kept at the cell center. central=0 # No changes required below this point! # Speed up playback using short dummy cutoff and no longrange forces Cutoff 2.62 Longrange None # Do we have a target? if MacroTarget=='' RaiseError "This macro requires a target. Either edit the macro file or click Options > Macro > Set target to choose a target structure" # Do we have a scene with water? scene = FileSize (MacroTarget)_water.sce if not scene RaiseError 'Could not find initial scene file (MacroTarget)_water.sce. Click Options > Macro > Set target and choose the target structure for which a simulation has been run before' # Load the scene Clear LoadSce (MacroTarget)_water # Pick a nice style Style Backbone=Ribbon,Sidechain=Stick Console off # Create the MD trajectory player user interface # Print headline to the HUD PrintHUD Font Arial,Height=20,Color=White,Spacing=1.5 PosText X=160,Y=8,Justify=Center Print 'MD Trajectory Player' FillRect X=25,Y=30,Width=270,Height=1,Color=White Font Height=15,Spacing=1.5 PosText X=25,Y=50,Justify=Left Print 'Snapshot:\nTime:' # Create the clickable timer on the right Font MonoSpaced,Spacing=1 gpos=240,120 FillRect (gpos1),(gpos2+5),Width=32,Height=241,Color=White for i=0 to 10 PosText (gpos1/8+6),(gpos2/12+i*2+1),Justify=Left Print '(i*10)%' FillRect (gpos1+32),(gpos2+i*24+5),Width=8,Height=1,Color=White # Top and bottom button have half the height if !i y=gpos2+6 h=12 else y=gpos2+i*24-7 h=24-12*(i==10) ShowButton X=(gpos1+16),Y=(y),Width=30,Height=(h),Border=0, Color=(i*320/11),Action='Go ClickTimer,GoPar=(i)' PosText (gpos1/8+3),(gpos2/12+22),Justify=Center Print 'Click' PosText (gpos1/8+3),(gpos2/12+23),Justify=Center Print 'above' # Create the buttons Font Arial,Height=14,Color=White,Spacing=1.5 ShowButton 'Play',X=70,Y=120 ShowButton 'Pause',X=160,Y=120 ShowButton 'Step backward',X=120,Y=170 ShowButton 'Step forward',X=120,Y=220 ShowButton 'Fast backward',X=120,Y=270 ShowButton 'Fast forward',X=120,Y=320 ShowButton 'Rewind to start',X=120,Y=370 Wait 1 firstsnapshot=00000 if format=='sim' # Quickly determine the last snapshot number lastsnapshot=firstsnapshot step=10000 for j=1 to 5 for k=1 to 9 sim = FileSize (MacroTarget)(lastsnapshot+step).sim if not sim break lastsnapshot=lastsnapshot+step step=step/10 else # It would take too long to scan the XTC file for the last snapshot lastsnapshot=-1 xtcfilename = '(MacroTarget)(firstsnapshot).xtc' step=1 delay=waittime i=firstsnapshot # Main playback loop MainLoop: while 1 if i<0 or (lastsnapshot!=-1 and i>lastsnapshot) Go RewindToStart # Show the snapshot number, clearing the area before FillRect X=125,Y=48,Width=190,Height=50 Font Height=15,Spacing=1.5 PosText X=125,Y=50,Justify=Left Print '(0+i)/(0+lastsnapshot+1)\n' if lastsnapshot>0 # Show the '>' at the timer on the right FillRect X=(gpos1-20),Y=(gpos2),Width=15,Height=260 PosText X=(gpos1-20),Y=(gpos2+240*i/lastsnapshot-1) Print '>' # Load next snapshot if format=='sim' sim = FileSize (MacroTarget)(i).sim LoadSim (MacroTarget)(i) else last = LoadXTC (xtcfilename),(i+1) if last lastsnapshot=0+i i=i+step # Show the snapshot time PosText X=125,Y=50 simtime=Time Print '\n(0.0+simtime/1000) ps' if central # Keep a chosen atom at the center of the cell (Cell returns center as values 7-9) _,_,_,_,_,_,cen() = Cell pos() = PosAtom (central) MoveAtom all,(cen-pos) # Make sure that the simulation does not continue while we wait Sim Pause if step # Wait a bit Wait (delay) else # Pause mode, wait until next click Wait forever # Press the Play button Play: step=1 delay=waittime Go MainLoop # Press the Pause button Pause: step=0 delay=waittime Go MainLoop # Press the step forward button StepForward: i=i+1 Go MainLoop # Press the step backward button StepBackward: i=i-1 Go MainLoop # Press the fast forward button FastForward: step=1 delay=1 Go MainLoop # Press the fast backward button FastBackward: step=-1 delay=1 Go MainLoop # Press the rewind to start button RewindToStart: i=firstsnapshot if step<0 Go Play Go MainLoop # Click the timer on the right ClickTimer: if lastsnapshot!='?' i=lastsnapshot*GoPar/10 Go MainLoop