# 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 # Parameters: # fileNameFormat - a Tcl format string which describes the fileName/numbering # used. # start - "frame number" of first PDB file in sequence # end - "frame number" of last PDB file in sqeuence # #Examples: # To load a sequence of PDB files named 0.pdb 1.pdb 2.pdb 3.pdb # one would call this proc with: animatepdbs "%d.pdb" 0 3 # # To load a sequence of PDB files named foo0000.pdb foo0001.pdb foo0002.pdb # one would call this proc with: animatepdbs "foo%04d.pdb" 0 2 # ______________________ User parameters section ==> set outFrames 500; # ==> Maximal number of frames in the output file set configFileName {/simulations/test_steered_simulation/update_parameters_conf.txt}; # ==> Symmetrization Configuration file name # ______________________ 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 } 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 [filterFileListRegexp [exec ls] $fileNameMask]] set start [scan [lindex $fileList 0] $fileNameFormat] set end [scan [lindex $fileList end] $fileNameFormat] puts "[llength $fileList] file(s) found: from [lindex $fileList 0] 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!" } # ______________________________________ 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] cd $workingFolder } default {} } } close $fileLook # __________________________ Executable part # Read from temporary file with list of filemasks for consolidation and make consolidation set fileLook [open "$workingFolder/consolidation_temp.txt" r] while {[gets $fileLook line] >= 0} { # coordinates2dcd "$workingFolder" "$line" {} $outFrames if {[regexp {.namd$} $line]} { # NAMD output log file if {[catch { set fileNameMask [regsub {%[0-9]*[dui]{1}} $line "\[0-9\]*"] set fileList [lsort [filterFileListRegexp [exec ls] $fileNameMask]] execBash "cat $fileList > [lindex $fileList 0]_all-namd-logs.txt" "$line Logs consolidation" }]!=0} { puts "Consolidation of '$line' unsuccessful" } else { puts "Consolidation of '$line' finished" } } elseif {[regexp {.xsc$} $line]} { # XSC cell file if {[catch { set fileNameMask [regsub {%[0-9]*[dui]{1}} $line "\[0-9\]*"] set fileList [lsort [filterFileListRegexp [exec ls] $fileNameMask]] execBash "cat $fileList > [lindex $fileList 0]_all-xsc.txt" "$line Logs consolidation" }]!=0} { puts "Consolidation of '$line' unsuccessful" } else { puts "Consolidation of '$line' finished" } } else { # Coordinate files if {[catch {coordinates2dcd "$workingFolder" "$line" {} $outFrames}]!=0} { puts "Consolidation of '$fileMask' unsuccessful" } else { puts "Consolidation of '$fileMask' finished" } } } close $fileLook exit