#!/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 8; # ==> Number of processors in the cluster simulation set namd2 {/NAMD/NAMD_2.5_Linux-i686/namd2}; # ==> namd launch substring set configFileName {update_parameters_conf.txt}; # ==> Parametrization Configuration file name set simConfigFileName {pull-tm1-tm2-ends-g10_cls-opn.conf}; # ==> Simulation Configuration file name set chargesAdjustmentFrequency -1; # ==> How often (in cycles) to adjust charges in PSF to imitate nonuniform dielectric permeability of the medium. <-1> - no adjustment. set resumeCrushedSimulation 1; # ==> Option to resume the crushed simulation if remains of it are found in the working folder set minConfigFileName {}; # ==> Minimization 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 if {[llength $outputFileNameBase] == 0} { # No output fileName provided catch {file copy "$workingFolder/$currentFileNameBase.namd" "$workingFolder/$currentFileNameBase.namd.old"} 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/$currentFileNameBase.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/$currentFileNameBase.namd" $simulationDescription } } else { # Output fileName provided catch {file copy "$workingFolder/$outputFileNameBase.namd" "$workingFolder/$outputFileNameBase.namd.old"} 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 } } } 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 # find out what is the name of simmetrization status file and total number of steps set fileLook [open $configFileName r]; # Open configuration file while {[gets $fileLook line] >= 0} { set lineRecognize [lindex $line 0] switch -regexp $lineRecognize { "^workingFolder$" {; # Simulation files path set workingFolder [lindex $line 1] if {$workingFolder=="."} {set workingFolder [pwd]} cd $workingFolder } "^statusFileName$" {; # Status file name set statusFileName [lindex $line 1] } "^parametrizationStepsMax$" {; # Maximal possible number of parametrization steps, before it stops (if was not stopped earlier by other criterion). set parametrizationStepsMax [lindex $line 1] } "^coordinates$" {; # Protein coordinates, used by parametrization procedure set coordinates [lindex $line 1] } "^coordinatesFileType$" {; # Coordinates File type set coordinatesFileType [lindex $line 1] } "^outputCoordinatesFileName$" {; # Output coordinates file name set outputCoordinatesFileName [lindex $line 1] } "^outputConstantsFileName$" {; # Output constants file name set outputConstantsFileName [lindex $line 1] } "^logOutputFiles$" {; # Option to keep log (numbered copies) of all output files - parametrized structure, constants file, status file set logOutputFiles [lindex $line 1] } "^logOutputFormat$" {; # Format to keep log of structure-format output files (target coordinates and spring constants) set logOutputFormat [lindex $line 1] } default {} } } close $fileLook set tempCoordinatesFileName $coordinates set fileLook [open $simConfigFileName r]; # Open configuration file set parametersFound 0 while {([gets $fileLook line] >= 0)&($parametersFound<2)} { if {[llength $line] >= 3} { set lineRecognize [lindex $line 1] switch -regexp $lineRecognize { "^startupFileNameBase$" {; # Simulation files path set startupFileNameBase [lindex $line 2] incr parametersFound } "^outputFileNameBase$" {; # Simulation files path set outputFileNameBase [lindex $line 2] incr parametersFound } default {} } } } close $fileLook #set fileNameBase {mscs-cry-cor}; # 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 parametrization status file from previous batch catch {file delete $statusFileName} # Delete parametrization result file from previous batch catch {file delete [join "$outputCoordinatesFileName _final.pdb" {}]} # Delete parametrization status log file from previous batch catch {file delete [join "$statusFileName _log.txt" {}]} set cyclesCounter 0 } else { if {[file exists $statusFileName]==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 parametrization status log file from previous batch catch {file delete [join "$statusFileName _log.txt" {}]} } # Delete parametrization result file from previous batch catch {file delete [join "$outputCoordinatesFileName _final.pdb" {}]} } 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" } } # ______ Looped cycle of simmetric target calculation and constrained simulation while {1} { # Rename coordinates for VMD input set repeatSimulation 0; # Flag to repeat the last step of simulation - if it was unsuccessful if {$cyclesCounter==0} { # The very first cycle - take coordinates from minimization set oldCoordinatesFileName "$startupFileNameBase.coor" file rename -force $oldCoordinatesFileName $tempCoordinatesFileName set suffixOut [format "_%0[string length $parametrizationStepsMax]i" 0] } else { # Some simulations were already performed. Find out the last step that was performed set fileLook [open $statusFileName r]; # open configuration file set parametersFound 0 while {([gets $fileLook line] >= 0)&($parametersFound<1)} {; # read configuration file and recognize data set lineRecognize [lindex $line 0] switch -regexp $lineRecognize { "^parametrizationCyclesCompleted$" {; # Number of minimization cycles completed up to the moment set parametrizationCyclesCompleted [lindex $line 1] if {$cyclesCounter==-1} {set cyclesCounter [expr {$parametrizationCyclesCompleted+1}]}; # Start resuming of the crushed simulation incr parametersFound } default {} } } close $fileLook set suffixOut [format "_%0[string length $parametrizationStepsMax]i" [expr {$parametrizationCyclesCompleted+1}]] set suffixOutOld [format "_%0[string length $parametrizationStepsMax]i" $parametrizationCyclesCompleted] set oldCoordinatesFileName "$outputFileNameBase$suffixOutOld.coor" if {[catch {file rename -force $oldCoordinatesFileName $tempCoordinatesFileName}]!=0} { set repeatSimulation 1; # Flag to repeat the last step of simulation - if it was unsuccessful puts "_______________________________________________ Repeating the last cycle" } } if {$repeatSimulation==0} { # The last step of simulation was successful # Calculate simmetric target structure execBash "vmd -dispdev text -eofexit -e $workingFolder/update_parameters.vmd > $workingFolder/update_parameters_output.log" "Parametric target calculation (cycle $cyclesCounter of $parametrizationStepsMax)" # Check, if target is reached. Break if yes if {[file exists [join "$outputCoordinatesFileName _final.pdb" {}]] == 1} { puts "============================= Parametrization target reached" # Rename coordinates back for NAMD input file rename -force $tempCoordinatesFileName $oldCoordinatesFileName break } # If necessary, adjust charges in PSF to imitate nonuniform dielectric permeability of the medium if {($chargesAdjustmentFrequency>0)&(($cyclesCounter%$chargesAdjustmentFrequency)==0)} { execBash "vmd -dispdev text -eofexit -e $workingFolder/adjust_charges_by_dielectric.vmd > $workingFolder/adj_output.log" "Charges adjustment (cycle $cyclesCounter of $parametrizationStepsMax)" #catch {exec "zip -9qmor tree2.zip tree.txt"} } # Rename coordinates back for NAMD input file rename -force $tempCoordinatesFileName $oldCoordinatesFileName # Perform next cycle of constrained simulation incr cyclesCounter } catch {simulate $outputFileNameBase "$outputFileNameBase$suffixOut" "Parametrization cycle [expr {$cyclesCounter-1}] of $parametrizationStepsMax"} puts "_______________________________________________ Cycle finished" } puts "============================= Consolidating output files..." # Create temporary file with list of filemasks for consolidation set fileLook [open {consolidation_temp.txt} w] # puts $fileLook "$parametrizationCyclesCompleted\$tpreviousRmsd\t$previousConstant" set suffixOut "_%0[string length $parametrizationStepsMax]d" puts $fileLook "$outputFileNameBase$suffixOut.coor" puts $fileLook "$outputFileNameBase$suffixOut.dcd" if {$logOutputFiles == 1} {; # Files from parametrization vmd script switch $logOutputFormat { "pdb" {set logOutputFormatExtension "pdb"} "dcd" {set logOutputFormatExtension "dcd"} "namdbin" {set logOutputFormatExtension "coor"} default {set logOutputFormatExtension "pdb"} } puts $fileLook "$outputCoordinatesFileName$suffixOut$logOutputFormatExtension" puts $fileLook "$outputConstantsFileName$suffixOut$logOutputFormatExtension" } puts $fileLook "$outputFileNameBase$suffixOut.namd" puts $fileLook "$outputFileNameBase$suffixOut.xsc" close $fileLook # Start consolidating vmd script execBash "vmd -dispdev text -eofexit -e $workingFolder/consolidate_output_files.vmd" "Output consolidation" # Remove temporary file with list of filemasks for consolidation # catch {file delete {consolidation_temp.txt}} 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" }