######## user defined parameters ######## set file_to_save /home/RChen/Documents/data/mscs_d/pdb/posre_protein_backbone.itp;# position restraint file to be saved set file_to_load /home/RChen/Documents/data/mscs_d/pdb/system.gro; # the .gro/.pdb file to be used set atoms_to_restrain "protein and backbone"; #test in VMD Graphics/Representations if unconfident set fc_x 1000; #force constant for x axis set fc_y 1000; #force constant for y axis set fc_z 1000; #force constant for z axis ####### end of user defined parameters ##### proc make_bak {file_to_save} { set filelist [glob -nocomplain "${file_to_save}.bak.*"] if {[llength $filelist] == 0} { set i 1; } else { set numlist ""; foreach filename $filelist { lappend numlist [lindex [split $filename "."] end] } set numlist [lsort -integer $numlist] set i [expr [lindex $numlist end] + 1] } exec mv ${file_to_save} ${file_to_save}.bak.${i} return "${file_to_save} is moved to ${file_to_save}.bak.${i}" } if {[file exists ${file_to_save}]} { set bakinfo [make_bak $file_to_save] } set fs [open ${file_to_save} a+] set time_now [clock format [clock seconds] -format {%b. %d, %Y %I:%M:%S %p}]; puts $fs "; created by [exec whoami] on $time_now"; puts $fs "; Structure file is: $file_to_load"; puts $fs "; atomselection is: $atoms_to_restrain"; puts $fs "\[ position_restraints \]" puts $fs "; atom type fx fy fz" set filetype [string range $file_to_load end-2 end] mol load ${filetype} ${file_to_load} set sel [atomselect top "${atoms_to_restrain}"] foreach index [$sel get index] { puts $fs "[format "%6s" [expr $index + 1]] [format "%3s" 1] ${fc_x} ${fc_y} ${fc_y}" } close $fs if [info exists bakinfo] {puts "\n$bakinfo"} puts "\nfile $file_to_save created\n" exit;