7-contacts2.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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=("resid 171" "acceptor")
  10. # set sel2 and sel2 name
  11. #sel2=("chain B and resname PHQ" "{/Arial-Italic Boc}")
  12. sel2=("resid 140 204" "donor")
  13. # job folder
  14. job_folder="4-jobs"
  15. # cutoff
  16. cutoff=3.0
  17. #######################################################################################
  18. ## FUNCTIONS ##
  19. #######################################################################################
  20. # set folder name for output files
  21. out_dir="$(basename ${0})"
  22. out_dir="${out_dir%%.*}"
  23. # set output suffix
  24. suffix="${sel1[0]}_vs_${sel2[0]}"
  25. suffix="${suffix// /_}"
  26. # create array of systems
  27. function get_systems() {
  28. systems=()
  29. all_systems=()
  30. _jobs=( $(ls -d 1-concat/combined/*.pdb) )
  31. for _job in ${_jobs[@]}; do
  32. all_systems+=( $( basename ${_job%-*.pdb} ) )
  33. done
  34. systems+=( $(for _system in ${all_systems[@]}; do echo ${_system}; done | sort -u) )
  35. }
  36. get_systems
  37. #######################################################################################
  38. ## CALC CONTACTS ##
  39. #######################################################################################
  40. function calc_contacts_num() {
  41. mkdir -p ${out_dir}
  42. echo ${systems[@]}
  43. for system in ${systems[@]}; do
  44. psf=$(ls 1-concat/combined/${system}-*.psf)
  45. dcd=$(ls 1-concat/combined/${system}-*.dcd)
  46. echo 'set n [molinfo top get numframes]' > temp.tcl
  47. echo "set sel1 [atomselect top \""${sel1[0]}"\"]" >> temp.tcl
  48. echo "set sel2 [atomselect top \""${sel2[0]}"\"]" >> temp.tcl
  49. echo "set fp [open "${out_dir}/${system}-${suffix}.csv" w]" >> temp.tcl
  50. # cycle over the trajectory
  51. echo 'for {set i 0} {$i <= $n} {incr i} {' >> temp.tcl
  52. echo ' $sel1 frame $i' >> temp.tcl
  53. echo ' $sel2 frame $i' >> temp.tcl
  54. echo " set contacts [measure contacts ${cutoff} \$sel1 \$sel2]" >> temp.tcl
  55. echo ' set count [llength [lindex $contacts 0]]' >> temp.tcl
  56. echo ' puts $fp "${i} ${count}"' >> temp.tcl
  57. echo '}' >> temp.tcl
  58. echo 'close $fp' >> temp.tcl
  59. vmd -dispdev text -eofexit ${psf} ${dcd} < "temp.tcl"
  60. sync
  61. rm "temp.tcl"
  62. done
  63. }
  64. calc_contacts_num
  65. function plot_contacts_num() {
  66. systems=()
  67. names=()
  68. for (( i = 0 ; i < ${#systems_names[@]} ; i+=2 )); do
  69. systems+=(${systems_names[${i}]})
  70. done
  71. for (( i = 1 ; i < ${#systems_names[@]} ; i+=2 )); do
  72. names+=("${systems_names[${i}]}")
  73. done
  74. echo 'set terminal pngcairo enhanced size 1600,1200 font "arial,24" linewidth 2' > temp
  75. echo "set output \"${out_dir}/combined-${suffix}.png\"" >> temp
  76. echo 'set autoscale' >> temp
  77. echo "set title \"${sel1[1]}-${sel2[1]} contacts\" font \"arial,40\"" >> temp
  78. echo 'set xlabel "ns" font "arial,32"' >> temp
  79. echo 'set ylabel "# Contacts" font "arial,32"' >> temp
  80. echo 'set border 1+2' >> temp
  81. echo 'set xtics nomirror out' >> temp
  82. echo 'set ytics nomirror' >> temp
  83. echo 'set grid' >> temp
  84. echo 'set grid noxtics' >> temp
  85. echo 'set key box top right' >> temp
  86. echo '#set yrange [-25:0]' >> temp
  87. echo '#set format y "%+-2.f"' >> temp
  88. echo 'set style data lines' >> temp
  89. echo '#set xzeroaxis ls 8' >> temp
  90. # linetypes
  91. echo '#set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb "black"' >> temp
  92. echo 'set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb "red"' >> temp
  93. echo 'set style line 2 pi 0 lw 1 ps 1 pt 0 lc rgb "green"' >> temp
  94. echo 'set style line 3 pi 0 lw 1 ps 1 pt 0 lc rgb "blue"' >> temp
  95. echo 'set style line 4 pi 0 lw 1 ps 1 pt 0 lc rgb "orange"' >> temp
  96. # plot
  97. echo 'plot \' >> temp
  98. for (( i = 0 ; i < ${#systems[@]} ; i++ )); do
  99. if [ $i -eq $((${#systems[@]} - 1)) ]; then
  100. echo "\"${out_dir}/${systems[$i]}-${suffix}.csv\" using 1:2 with linespoints ls $((${i} + 1)) title \""${names[$i]}"\"" >> temp
  101. else
  102. echo "\"${out_dir}/${systems[$i]}-${suffix}.csv\" using 1:2 with linespoints ls $((${i} + 1)) title \""${names[$i]}"\", \\" >> temp
  103. fi
  104. done
  105. echo 'exit' >> temp
  106. gnuplot temp
  107. #rm temp
  108. }