#!/bin/sh # the next line restarts using tclsh \ exec tclsh "$0" "$@" # ______________________________________ Path settings # Charmrun path is in the "simulate" procedure definition # set nlst {++nodelist /NAMD/nodelists/}; # ==> nodelist launch substring # set nodelist {MscL_3new_nodes_8p}; # ==> nodelist. If nodelist variable is absent the simulation is considered to be local set processors 2; # ==> Number of processors in the cluster/workstation simulation set namd2 {/NAMD/NAMD_2.5_Linux-i686/namd2}; # ==> namd launch substring for Linux set namd2win {/Program Files/University of Illinois/NAMD_2.5_Win32-i686/namd2.exe}; # ==> namd launch substring for windows set simConfigFileName {sim-mscs-cry-chnl-big-oct-cor-l109s_wtr_f_salt.conf}; # ==> Simulation Configuration file name set resumeCrushedSimulation 1; # ==> Option to resume the crushed simulation if remains of it are found in the working folder # set minConfigFileName {min-mscs-cry-chnl-big-oct-cor-l109s_wtr_f_salt.conf}; # ==> Minimization Configuration file name set minConfigFileName {}; # ==> Minimization Configuration file name set equilConfigFileName {}; # ==> Equilibration Configuration file name # ______________________________________ Procedures declaration proc execBash {bashCommand {simulationDescription "Simulation"}} { # Procedure writes received bash shell command into the bash_command file, and executes it set bashCommandFile [open ./bash_command w] puts $bashCommandFile $bashCommand close $bashCommandFile puts "$simulationDescription started" exec {./bash_command} puts "$simulationDescription finished" } proc simulate {currentFileNameBase {outputFileNameBase ""} {simulationDescription ""}} { global chrn nlst nodelist namd2 workingFolder fileNameBase processors namd2win if {[llength $outputFileNameBase] == 0} { set outputFileNameBase $currentFileNameBase } # Output fileName provided catch {file copy "$workingFolder/$outputFileNameBase.namd" "$workingFolder/$outputFileNameBase.namd.old"} if {[string index [pwd] 0]=="/"} {; # Autodetection of the operational system # Linux if {[catch {set nodelist}]!=0||[llength $nodelist]==0} {; # Nodelist is absent. Simulation on the local node set chrn {/NAMD/NAMD_2.5_Linux-i686/charmrun ++local ++p 2}; # ==> Charmrun launch substring execBash "$chrn $namd2 $workingFolder/$currentFileNameBase.conf | tee $workingFolder/$outputFileNameBase.namd" $simulationDescription } else {; # Nodelist is present. Simulation from the root node on the (part of) cluster set chrn {/NAMD/NAMD_2.5_Linux-i686/charmrun ++p}; # ==> Charmrun launch substring execBash "$chrn $processors $nlst$nodelist $namd2 $workingFolder/$currentFileNameBase.conf | tee $workingFolder/$outputFileNameBase.namd" $simulationDescription } } else { # Windows if {[catch {set processors}]} {set processors 1} puts "$simulationDescription started" exec "$namd2win" "+p$processors" "$workingFolder/$currentFileNameBase.conf" > "$workingFolder/$outputFileNameBase.namd" puts "$simulationDescription finished" }; # Autodetection of the operational system } proc send_simple_message {recipient email_server subject body} { package require smtp package require mime set token [mime::initialize -canonical text/plain -string $body] mime::setheader $token Subject $subject smtp::sendmessage $token -recipients $recipient -servers $email_server -username anishkin -password AGAAGA -originator Cluster_Spirit mime::finalize $token } # ______________________________________ autodetect fileNames and pathways set fileLook [open $simConfigFileName r]; # Open configuration file while {[gets $fileLook line] >= 0} { catch { if {[llength $line] >= 3} { set lineRecognize [lindex $line 1] switch -regexp $lineRecognize { "^workingFolder$" { set workingFolder [lindex $line 2] if {$workingFolder=="."} {set workingFolder [pwd]} cd $workingFolder } "^simStatusFileName$" { set simStatusFileName [lindex $line 2] } "^startupFileNameBase$" { set startupFileNameBase [lindex $line 2] } "^outputFileNameBase$" { set outputFileNameBase [lindex $line 2] } "^firstTimestep$" { set firstTimestep [lindex $line 2] } "^lastTimestep$" { set lastTimestep [lindex $line 2] } default {} } } } } close $fileLook set fileNameBase {mscl_c-o-int_opn-eql}; # FileName base for configuration and log files # ______________________________________ Computational part puts "Simulation batch started" if {$resumeCrushedSimulation==0} { # All possible remains of previous simulation attempt are removed # Delete simulation status file from previous batch catch {file delete $simStatusFileName} # Delete simulation end mark file from previous batch catch {file delete $simStatusFileName.end} # Delete simulation status log file from previous batch catch {file delete $simStatusFileName.log} set cyclesCounter 0 } else { if {[file exists $simStatusFileName]==1} { # Remains of previous simulation are found set cyclesCounter -1 puts "===================================== Resuming the crushed simulation" } else { # Remains of previous simulation are not found set cyclesCounter 0 # Delete simulation status log file from previous batch catch {file delete $simStatusFileName.log} } # Delete simulation end mark file from previous batch catch {file delete $simStatusFileName.end} } if {$cyclesCounter==0&&[llength $minConfigFileName]>0} { # beginning of the simulation regsub {\.conf$} $minConfigFileName "" minFileNameBase if {[catch {simulate $minFileNameBase $minFileNameBase "Minimization"}]==0} { # Succesful minimization puts "_______________________________________________ Minimization finished" } else { error "_______________________________________________ Minimization failed" } } if {$cyclesCounter==0&&[llength $equilConfigFileName]>0} { # beginning of the simulation regsub {\.conf$} $equilConfigFileName "" equilFileNameBase if {[catch {simulate $equilFileNameBase $equilFileNameBase "Equilibration"}]==0} { # Succesful Equilibration puts "_______________________________________________ Equilibration finished" } else { error "_______________________________________________ Equilibration failed" } } puts "cyclesCounter $cyclesCounter" # ______ Looped cycle of simmetric target calculation and constrained simulation while {1} { # puts "cyclesCounter $cyclesCounter" # Define the firstTimestepCycle - first timestep for this simulation cycle. NAMD log file will be named with this suffix if {$cyclesCounter==0} { # The very first cycle - take coordinates from minimization set firstTimestepCycle $firstTimestep } else { # Some simulations were already performed. Find out the firstTimestep of the last simulation cycle set fileLook [open $simStatusFileName r] # read status file and recognize data while {[gets $fileLook line] >= 0} { set lineRecognize [lindex $line 0] switch -regexp $lineRecognize { "^firstTimestepCycle$" { # First Timestep from the previous simulation set firstTimestepCycle [lindex $line 1] } default { } } } close $fileLook # Check if the previous simulation finished successfully set suffixIn [format "_%0[string length $lastTimestep]i" [expr {$firstTimestepCycle}]] if {[file exists $outputFileNameBase$suffixIn.xsc]==1} { # Previous simulation cycle finished successfully. Read the final timestep from there set fileLook [open $outputFileNameBase$suffixIn.xsc r] while {[gets $fileLook line] >= 0} { set lineRecognize [lindex $line 0] } close $fileLook set firstTimestepCycle $lineRecognize } else { # Previous simulation cycle was not finished successfully. Try to read the restart file from the crushed simulation if {[file exists $outputFileNameBase$suffixIn.restart.xsc]==1} { # Previous simulation cycle made the restart file set fileLook [open $outputFileNameBase$suffixIn.restart.xsc r] while {[gets $fileLook line] >= 0} { set lineRecognize [lindex $line 0] } close $fileLook set firstTimestepCycle $lineRecognize } else { # No restart file found. Leaving firstTimestep as it was for the previous simulation cycle } } if {$cyclesCounter==-1} {set cyclesCounter 0}; # Start resuming of the crushed simulation } set suffixOut [format "_%0[string length $lastTimestep]i" $firstTimestepCycle] incr cyclesCounter regsub {\.conf$} $simConfigFileName "" simConfigFileNameBase simulate $simConfigFileNameBase "$outputFileNameBase$suffixOut" "simulation cycle (Timestep $firstTimestep : $firstTimestepCycle : $lastTimestep)" catch {simulate $simConfigFileNameBase "$outputFileNameBase$suffixOut" "simulation cycle (Timestep $firstTimestep : $firstTimestepCycle : $lastTimestep)"} # Check, if target is reached. Break if yes if {[file exists $simStatusFileName.end] == 1} { puts "============================= Simulation lastTimestep reached" break } } puts "Simulation batch finished" catch { set diskInfo [exec df] set freeSpaceKb [lindex $diskInfo 10] send_simple_message anishkin@icqmail.com smtp.icqmail.com "Simulation $simConfigFileName finished!" "[clock format [clock seconds]] Simulation $simConfigFileName finished! Free disk space is $freeSpaceKb Kb" }