7-contacts.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #!/usr/bin/env bash
  2. export VMDNOCUDA=1
  3. #export VMDNOOPTIX=1
  4. export VMDNOOSPRAY=1
  5. #######################################################################################
  6. ## ADJUSTABLE PARAMETERS ##
  7. #######################################################################################
  8. # set sel1 and sel1 name
  9. sel1=("chain A and name CA" "SrtA")
  10. # set sel2 and sel2 name
  11. #sel2=("chain B and resname PHQ" "{/Arial-Italic Boc}")
  12. sel2=("chain B" "SS")
  13. # only run specific systems
  14. #my_systems=("ALL")
  15. systems_names=('ALL' '+{/Arial-Italic Boc} +Ca^{2+}' 'no_CA' '+{/Arial-Italic Boc} −Ca^{2+}' 'no_PHQ' '−{/Arial-Italic Boc} +Ca^{2+}' 'no_PHQ_no_CA' '−{/Arial-Italic Boc} −Ca^{2+}')
  16. # cutoff
  17. cutoff=3.0
  18. # combine?
  19. combine=1
  20. #######################################################################################
  21. ## FUNCTIONS ##
  22. #######################################################################################
  23. # set folder name for output files
  24. out_dir="$(basename ${0})"
  25. out_dir="${out_dir%%.*}"
  26. # set output suffix
  27. suffix="${sel1[0]}_vs_${sel2[0]}"
  28. suffix="${suffix// /_}"
  29. #######################################################################################
  30. ## CALC CONTACTS ##
  31. #######################################################################################
  32. function calc_contacts() {
  33. systems=()
  34. for (( i = 0 ; i < ${#systems_names[@]} ; i+=2 )); do
  35. systems+=(${systems_names[i]})
  36. done
  37. mkdir -p ${out_dir}
  38. for system in ${systems[@]}; do
  39. psf=$(ls 1-concat/combined/${system}-*.psf)
  40. dcd=$(ls 1-concat/combined/${system}-*.dcd)
  41. echo 'set numframes [expr {[molinfo top get numframes] - 1}]' > temp.tcl
  42. echo 'set totframes [expr $numframes + 1]' >> temp.tcl
  43. echo "set A [atomselect top \""${sel1[0]}"\"]" >> temp.tcl
  44. echo "set B [atomselect top \""${sel2[0]}"\"]" >> temp.tcl
  45. # cycle over the trajectory
  46. echo 'for {set i 0} {$i <= $numframes} {incr i} {' >> temp.tcl
  47. echo ' foreach resID [$A get resid] {' >> temp.tcl
  48. echo ' set A_temp [atomselect top "resid $resID"]' >> temp.tcl
  49. echo ' $A_temp frame $i' >> temp.tcl
  50. echo ' $B frame $i' >> temp.tcl
  51. echo ' $A_temp update' >> temp.tcl
  52. echo ' $B update' >> temp.tcl
  53. echo " foreach {listA tmp} [measure contacts ${cutoff} \$A_temp \$B] break" >> temp.tcl
  54. echo ' if {[llength $listA] > 0} {' >> temp.tcl
  55. echo ' lappend contactTable($resID) $i' >> temp.tcl
  56. echo ' } else {' >> temp.tcl
  57. echo ' lappend contactTable($resID)' >> temp.tcl
  58. echo ' }' >> temp.tcl
  59. echo ' $A_temp delete' >> temp.tcl
  60. echo ' }' >> temp.tcl
  61. echo ' puts $i' >> temp.tcl
  62. echo '}' >> temp.tcl
  63. # open output file for writing
  64. echo "set fContAB \""${out_dir}/${system}-${suffix}-contacts.csv"\"" >> temp.tcl
  65. echo 'set fcAB [open $fContAB w]' >> temp.tcl
  66. # calculate percentage
  67. echo 'foreach resID [lsort -integer [array names contactTable]] {' >> temp.tcl
  68. echo ' set frames [llength $contactTable($resID)]' >> temp.tcl
  69. echo ' set percentage [expr 100.0 * $frames / $totframes]' >> temp.tcl
  70. # write to file
  71. echo ' puts $fcAB "$resID $percentage"' >> temp.tcl
  72. echo ' flush $fcAB' >> temp.tcl
  73. # set user values
  74. echo ' set sel1 [atomselect top "resid $resID"]' >> temp.tcl
  75. echo ' for {set i 0} {$i <= $numframes} {incr i} {' >> temp.tcl
  76. echo ' $sel1 frame $i' >> temp.tcl
  77. echo ' $sel1 set user $percentage' >> temp.tcl
  78. echo ' }' >> temp.tcl
  79. echo ' $sel1 delete' >> temp.tcl
  80. echo '}' >> temp.tcl
  81. # close output files
  82. echo 'close $fcAB' >> temp.tcl
  83. echo 'exit' >> temp.tcl
  84. vmd -dispdev text -eofexit ${psf} ${dcd} < "temp.tcl"
  85. sync
  86. rm "temp.tcl"
  87. plot_contacts "${system}"
  88. done
  89. if (( ${combine} != 0 )); then
  90. plot_combined_contacts "${systems_names[@]}"
  91. fi
  92. }
  93. function plot_contacts() {
  94. echo 'set terminal pngcairo enhanced size 1600,1200 font "arial,24" linewidth 2' > temp
  95. echo "set output \"${out_dir}/${1}-${suffix}-contacts.png\"" >> temp
  96. echo 'set autoscale' >> temp
  97. echo "set title \"${sel1[1]}-${sel2[1]} contacts\" font \"arial,40\"" >> temp
  98. echo 'set xlabel "Residue" font "arial,32"' >> temp
  99. echo 'set ylabel "% Contacts" font "arial,32"' >> temp
  100. echo 'set border 1+2' >> temp
  101. echo 'set xtics nomirror out' >> temp
  102. echo 'set ytics nomirror' >> temp
  103. echo 'set grid' >> temp
  104. echo 'set grid noxtics' >> temp
  105. echo 'set key box off' >> temp
  106. echo '#set yrange [-25:0]' >> temp
  107. echo '#set format y "%+-2.f"' >> temp
  108. echo 'set style data lines' >> temp
  109. echo 'set xzeroaxis ls 8' >> temp
  110. echo "plot "${out_dir}/${1}-${suffix}-contacts.csv" using 1:2 with impulses ls 8" >> temp
  111. echo 'exit' >> temp
  112. gnuplot temp
  113. rm temp
  114. }
  115. # probably want to handle this one manually
  116. function plot_combined_contacts() {
  117. systems=()
  118. names=()
  119. for (( i = 0 ; i < ${#systems_names[@]} ; i+=2 )); do
  120. systems+=(${systems_names[${i}]})
  121. done
  122. for (( i = 1 ; i < ${#systems_names[@]} ; i+=2 )); do
  123. names+=("${systems_names[${i}]}")
  124. done
  125. echo 'set terminal pngcairo enhanced size 2400,1200 font "arial,24" linewidth 2' > temp
  126. echo "set output \"${out_dir}/combined-${suffix}-contacts.png\"" >> temp
  127. echo 'set autoscale' >> temp
  128. echo "set title \"${sel1[1]}-${sel2[1]} contacts\" font \"arial,40\"" >> temp
  129. echo 'set xlabel "Residue" font "arial,32"' >> temp
  130. echo 'set ylabel "% Contacts" font "arial,32"' >> temp
  131. echo 'set border 1+2' >> temp
  132. echo 'set xtics nomirror out rotate' >> temp
  133. echo 'set ytics nomirror' >> temp
  134. echo 'set grid' >> temp
  135. echo 'set grid noxtics' >> temp
  136. echo 'set key box top center' >> temp
  137. echo '#set style data histogram' >> temp
  138. echo 'set style fill solid border' >> temp
  139. echo '#set xzeroaxis ls 8' >> temp
  140. # linetypes
  141. echo '#set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb "black"' >> temp
  142. echo 'set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb "red"' >> temp
  143. echo 'set style line 2 pi 0 lw 1 ps 1 pt 0 lc rgb "green"' >> temp
  144. echo 'set style line 3 pi 0 lw 1 ps 1 pt 0 lc rgb "blue"' >> temp
  145. echo 'set style line 4 pi 0 lw 1 ps 1 pt 0 lc rgb "orange"' >> temp
  146. # thin out xtic labels
  147. echo 'every(col) = (int(column(col))%10 ==0)?stringcolumn(1):""' >> temp
  148. # plot
  149. echo 'plot \' >> temp
  150. for (( i = 0 ; i < ${#systems[@]} ; i++ )); do
  151. if [ $i -eq $((${#systems[@]} - 1)) ]; then
  152. echo "\"${out_dir}/${systems[$i]}-${suffix}-contacts.csv\" using 2:xticlabels(every(1)) with histogram ls $((${i} + 1)) title \""${names[$i]}"\"" >> temp
  153. else
  154. echo "\"${out_dir}/${systems[$i]}-${suffix}-contacts.csv\" using 2:xticlabels(every(1)) with histogram ls $((${i} + 1)) title \""${names[$i]}"\", \\" >> temp
  155. fi
  156. done
  157. echo 'exit' >> temp
  158. gnuplot temp
  159. #rm temp
  160. }
  161. calc_contacts