# Script reading structure files (in any VMD-readable format), adding them as frames in trajectory and saving the trajectory in peaces (to avoid extremely big DCD files) # Inspired John Stone's animatepdbs # ______________________ User parameters section ==> set outFrames 200; # ==> Maximal number of frames in the output file set workingFolder {/NAMD/simulations/mscl_c-o-int/pull-tm1-tm2-ends-g10_cls-opn/00000-00099} cd $workingFolder set start {}; # Autodetect start number set end {}; # Autodetect end number # set start 0 # set end 1999 set fileMasksList { pull-tm1-tm2-ends-g10_cls-opn_%05d.dcd pull-tm1-tm2-ends-g10_cls-opn_%05d.coor pull-tm1-tm2-ends-g10_cls-opn_%05d.vel pull-tm1-tm2-ends-g10_cls-opn_%05d.xsc pull-tm1-tm2-ends-g10_cls-opn_%05d.xst pull-tm1-tm2-ends-g10_cls-opn_%05d.namd pull-tm1-tm2-ends-g10_cls-opn_tgt.pdb_%05d.dcd } # ______________________ Additional consolidation steps set execute {} # set execute { # cat *.namd > all_namd_logs.txt # cat *.xsc > all_xsc.txt # } # ______________________ Procedures declaration proc filterFileList {fileList mask} { set newFileList {} foreach fileName $fileList { if {[string match -nocase $mask $fileName]==1} { lappend newFileList $fileName } } return $newFileList } proc filterFileListRegexp {fileList mask} { set newFileList {} set mask "\^$mask\$" foreach fileName $fileList { if {[regexp $mask $fileName]==1} { lappend newFileList $fileName } } return $newFileList } # ______________________________________ 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 coordinates2dcd {filesPath fileNameFormat {fileType ""} {outFrames ""} {start ""} {end ""}} { if {[llength $filesPath] > 0} {; # Go to the working folder cd $filesPath } # ____ Autodetect the first and last files numbers if {([llength $start] == 0)|([llength $end] == 0)} {; #start or end numbers were not specified set fileNameMask [regsub {%[0-9]*[dui]{1}} $fileNameFormat "\[0-9\]*"] set fileList [lsort [filterFileList [exec ls] $fileNameMask]] set start [scan [lindex $fileList 0] $fileNameFormat] set end [scan [lindex $fileList end] $fileNameFormat] puts "[expr {[llength $fileList]-1}] file(s) found: from [lindex $fileList 1] to [lindex $fileList end]" } # ____ Load the first file set fileName [format $fileNameFormat [expr {$start}]] puts "Reading initial file $fileName in the sequence" if {[llength $fileType]>0} { mol new $fileName type $fileType waitfor all } else { if {[catch {mol new $fileName waitfor all}]!=0} {mol new $fileName type pdb waitfor all} } # ____ Load the rest of files set firstDcdFrame 0 set filesRead 1 puts "Reading coordinates files and writing sets of frames into DCD..." incr start for {set i $start} {$i <= $end} {incr i 1} { set fileName [format $fileNameFormat [expr {$i}]] if {[llength $fileType]>0} { mol addfile $fileName type $fileType waitfor all } else { if {[catch {mol addfile $fileName waitfor all}]!=0} {mol addfile $fileName type pdb waitfor all} } incr filesRead set framesRead [molinfo top get numframes] if {[llength $outFrames]>0} { if {$framesRead>=$outFrames} {; # Maximal number of frames in the output file reached set lastDcdFrame [expr {$firstDcdFrame+$framesRead-1}] set firstDcdFrameString [format "%0[string length $end]d" $firstDcdFrame] set lastDcdFrameString [format "%0[string length $end]d" $lastDcdFrame] animate write dcd [join "[molinfo top get name] _frames $firstDcdFrameString to $lastDcdFrameString .dcd" {}] beg 0 end [expr {$outFrames-1}] waitfor all set firstDcdFrame [expr {$lastDcdFrame+1}] animate delete beg 0 end [expr {$outFrames-1}] } } } if {[molinfo top get numframes]>0} { set lastDcdFrame [expr {$firstDcdFrame+[molinfo top get numframes]-1}] set firstDcdFrameString [format "%0[string length $end]d" $firstDcdFrame] set lastDcdFrameString [format "%0[string length $end]d" $lastDcdFrame] animate write dcd [join "[molinfo top get name] _frames $firstDcdFrameString to $lastDcdFrameString .dcd" {}] waitfor all animate delete all } puts "[expr {$lastDcdFrame+1}] frames from $filesRead files read" puts "Writing DCD trajectory finished!" } # __________________________ Executable part catch {execBash $execute "Logs consolidation"} # Read from temporary file with list of filemasks for consolidation and make consolidation foreach fileMask $fileMasksList { # puts "coordinates2dcd $workingFolder $fileMask {} $outFrames $start $end" if {[regexp {.namd$} $fileMask]} { # NAMD output log file if {[catch { set fileNameMask [regsub {%[0-9]*[dui]{1}} $fileMask "\[0-9\]*"] set fileList [lsort [filterFileListRegexp [exec ls] $fileNameMask]] execBash "cat $fileList > [lindex $fileList 0]_all-namd-logs.txt" "$fileMask Logs consolidation" }]!=0} { puts "Consolidation of '$fileMask' unsuccessful" } else { puts "Consolidation of '$fileMask' finished" } } elseif {[regexp {.xsc$} $fileMask]} { # XSC cell file if {[catch { set fileNameMask [regsub {%[0-9]*[dui]{1}} $fileMask "\[0-9\]*"] set fileList [lsort [filterFileListRegexp [exec ls] $fileNameMask]] execBash "cat $fileList > [lindex $fileList 0]_all-xsc.txt" "$fileMask Logs consolidation" }]!=0} { puts "Consolidation of '$fileMask' unsuccessful" } else { puts "Consolidation of '$fileMask' finished" } } elseif {[regexp {.xst$} $fileMask]} { # XSC cell file if {[catch { set fileNameMask [regsub {%[0-9]*[dui]{1}} $fileMask "\[0-9\]*"] set fileList [lsort [filterFileListRegexp [exec ls] $fileNameMask]] execBash "cat $fileList > [lindex $fileList 0]_all-xst.txt" "$fileMask Logs consolidation" }]!=0} { puts "Consolidation of '$fileMask' unsuccessful" } else { puts "Consolidation of '$fileMask' finished" } } else { # Coordinate files if {[regexp {.vel$} $fileMask]} {; # Define Velocity filetype set fileType namdbin } else { set fileType {} } if {[catch {coordinates2dcd "$workingFolder" "$fileMask" $fileType $outFrames $start $end}]!=0} { puts "Consolidation of '$fileMask' unsuccessful" } else { puts "Consolidation of '$fileMask' finished" } } } exit