Browse Source

Add some trajectory analysis scripts

cryobry 5 years ago
parent
commit
d28cafc5b6

+ 227 - 0
trajectory_analysis/1-concat.sh

@@ -0,0 +1,227 @@
+#!/usr/bin/env bash
+export VMDNOCUDA=1
+#export VMDNOOPTIX=1
+export VMDNOOSPRAY=1
+
+#######################################################################################
+## ADJUSTABLE PARAMETERS                                                             ##
+#######################################################################################
+
+# number of frames to skip (i.e. from equilibration)
+skip=0
+# set folder name that contains the jobs
+job_folder="4-jobs"
+# set atom selection for concatenation
+concat_sel="chain A"
+# set atom selection to unwrap
+unwrap_sel="chain A"
+# set atom selection to wrap to
+wrap_to_sel="chain A"
+# set atom selection to wrap
+wrap_sel="chain A"
+# set atom selection for alignment
+align_sel="chain A"
+# set atom selection for EDA
+eda_sel="chain A and name CA"
+
+#######################################################################################
+## SET VARS                                                                          ##
+#######################################################################################
+
+# set folder name for output files
+out_dir="$(basename ${0})"
+out_dir="${out_dir%%.*}"
+
+# create suffixes for output files
+concat_sel_s="${concat_sel// /_}"
+eda_sel_s="${eda_sel// /_}"
+
+#######################################################################################
+## FUNCTIONS                                                                         ##
+#######################################################################################
+
+function get_systems() {
+  systems=()
+  all_systems=()
+  _jobs=( $(ls -d ../${job_folder}/*/*/) )
+  for _job in ${_jobs[@]}; do
+    all_systems+=( $(basename ${_job}) )
+  done
+  systems+=( $(for _system in ${all_systems[@]}; do echo ${_system}; done | sort -u) )
+}
+
+#######################################################################################
+## CONCATENATE, UNWRAP, ALIGN INDVIDUAL REPLICATES                                   ##
+#######################################################################################
+
+function concat_individual() {
+
+  get_systems
+
+  for system in "${systems[@]}"; do
+    
+    dcds=()
+    jobs=( $(ls -d ../${job_folder}/*/${system}/) )
+    
+    for job in ${jobs[@]}; do
+      job=${job%%/}
+      rel_job_path=${job#../${job_folder}/}
+      mkdir -p ${out_dir}/individual/${rel_job_path}
+      dcds=( $(ls ${job}/*sim_*.dcd | sort -V) )
+      
+      for dcd in ${dcds[@]}; do
+        filename=${dcd##*/}
+        filename=${filename%%.*}
+        # UNWRAP AND ALIGN
+        echo 'package require pbctools' > temp.tcl
+        echo "pbc unwrap -all -sel \""${unwrap_sel}"\"" >> temp.tcl
+        echo "pbc wrap -sel \""${wrap_sel}"\" -all -compound chain -center com -centersel \""${wrap_to_sel}"\"" >> temp.tcl
+        echo "set out [atomselect top \""${concat_sel}"\"]" >> temp.tcl
+        echo "animate write dcd ${out_dir}/individual/${rel_job_path}/temp-${filename}-${concat_sel_s}.dcd sel \$out waitfor all" >> temp.tcl
+        for (( i=0; i<1; i++)); do
+	        echo "\$out writepsf ${out_dir}/individual/${rel_job_path}/${system}-${concat_sel_s}.psf" >> temp.tcl
+          echo "\$out writepdb ${out_dir}/individual/${rel_job_path}/${system}-${concat_sel_s}.pdb" >> temp.tcl
+	      done
+
+        echo "sync" >> temp.tcl
+        echo 'exit' >> temp.tcl
+
+        # run temp.tcl
+        vmd -dispdev text -eofexit ${job}/${system}_solv_ion.psf ${dcd} < "temp.tcl"
+        sync
+        
+        rm "temp.tcl"
+      done
+      
+      dcds=( $(ls ${out_dir}/individual/${rel_job_path}/temp-*-${concat_sel_s}.dcd | sort -V) )
+      
+      echo "set ref [atomselect top \""${align_sel}"\" frame 0]" > temp.tcl
+      echo "set sel [atomselect top \""${align_sel}"\"]" >> temp.tcl
+      echo 'set all [atomselect top "all"]' >> temp.tcl
+      echo 'set n [molinfo top get numframes]' >> temp.tcl
+      echo 'for { set i 1 } { $i < $n } { incr i } {' >> temp.tcl
+      echo '  $sel frame $i' >> temp.tcl
+      echo '  $all frame $i' >> temp.tcl
+      echo '  $all move [measure fit $sel $ref]' >> temp.tcl
+      echo '}' >> temp.tcl
+      echo "animate write dcd ${out_dir}/individual/${rel_job_path}/${system}-${concat_sel_s}.dcd beg ${skip} waitfor all" >> temp.tcl
+      echo "sync" >> temp.tcl
+      echo 'exit' >> temp.tcl
+
+      # run temp.tcl
+      vmd -dispdev text -eofexit ${out_dir}/individual/${rel_job_path}/${system}-${concat_sel_s}.psf ${dcds[@]} < "temp.tcl"
+      sync
+      rm "temp.tcl" 
+      rm ${out_dir}/individual/${rel_job_path}/temp*
+    done
+  done
+}
+
+#######################################################################################
+## CONCATENATE AND ALIGN ALL REPLICATES                                              ##
+#######################################################################################
+
+function concat_combined() {
+
+  get_systems
+  
+  mkdir -p ${out_dir}/combined
+  
+  for system in ${systems[@]}; do
+  
+
+    # create dcd array and copy pdb/psf
+    dcds=( $(ls ${out_dir}/individual/*/${system}/${system}-${concat_sel_s}.dcd | sort -V) )
+    psfs=( $(ls ${out_dir}/individual/*/${system}/${system}-${concat_sel_s}.psf | sort -V) )
+    pdbs=( $(ls ${out_dir}/individual/*/${system}/${system}-${concat_sel_s}.pdb | sort -V) )
+    
+    cp ${psfs[1]} ${out_dir}/combined/${system}-${concat_sel_s}.psf
+    cp ${pdbs[1]} ${out_dir}/combined/${system}-${concat_sel_s}.pdb
+
+    # ALIGN
+    echo "set ref [atomselect top \""${align_sel}"\" frame 0]" >> temp.tcl
+    echo "set sel [atomselect top \""${align_sel}"\"]" >> temp.tcl
+    echo 'set all [atomselect top "all"]' >> temp.tcl
+    echo 'set n [molinfo top get numframes]' >> temp.tcl
+    echo 'for { set i 1 } { $i < $n } { incr i } {' >> temp.tcl
+    echo '  $sel frame $i' >> temp.tcl
+    echo '  $all frame $i' >> temp.tcl
+    echo '  $all move [measure fit $sel $ref]' >> temp.tcl
+    echo '}' >> temp.tcl
+    # write aligned trr and dcd output files
+    echo "animate write trr ${out_dir}/combined/${system}-${concat_sel_s}.trr waitfor all" >> temp.tcl
+    echo "animate write dcd ${out_dir}/combined/${system}-${concat_sel_s}.dcd waitfor all" >> temp.tcl
+    echo 'sync' >> temp.tcl
+    echo 'exit' >> temp.tcl
+
+    vmd -dispdev text -eofexit ${out_dir}/combined/${system}-${concat_sel_s}.psf ${dcds[@]} < "temp.tcl"
+    rm "temp.tcl"
+    sync
+
+  done
+}
+
+#######################################################################################
+## CONCATENATE AND ALIGN ALL SYSTEMS (EDA)                                           ##
+#######################################################################################
+
+function concat_eda() {
+
+  get_systems
+  
+  mkdir -p ${out_dir}/eda/
+  
+  # concat systems to eda_sel
+  for system in ${systems[@]}; do
+
+    echo "set out [atomselect top \""${eda_sel}"\"]" > temp.tcl
+    echo "set last_out [atomselect top \""${eda_sel}"\" frame 0]" >> temp.tcl
+    
+    # write aligned dcd
+    echo "animate write dcd ${out_dir}/eda/${system}-${eda_sel_s}.dcd sel \$out waitfor all" >> temp.tcl
+    echo "\$last_out writepsf ${out_dir}/eda/${system}-${eda_sel_s}.psf" >> temp.tcl
+    echo "\$last_out writepdb ${out_dir}/eda/${system}-${eda_sel_s}.pdb" >> temp.tcl
+    echo 'sync' >> temp.tcl
+    echo 'exit' >> temp.tcl
+    
+    vmd -dispdev text -eofexit ${out_dir}/combined/${system}-${concat_sel_s}.psf ${out_dir}/combined/${system}-${concat_sel_s}.dcd < "temp.tcl"
+    sync
+    rm "temp.tcl"
+  done
+  
+  dcds=( $(ls ${out_dir}/eda/*-${eda_sel_s}.dcd | sort -V) )
+  psfs=( $(ls ${out_dir}/eda/*-${eda_sel_s}.psf | sort -V) )
+  pdbs=( $(ls ${out_dir}/eda/*-${eda_sel_s}.pdb | sort -V) )
+  
+  cp ${psfs[1]} ${out_dir}/eda/combined-${eda_sel_s}.psf
+  cp ${pdbs[1]} ${out_dir}/eda/combined-${eda_sel_s}.pdb
+  
+  # concat and align
+  echo "set ref [atomselect top \""${eda_sel}"\" frame 0]" > temp.tcl
+  echo "set sel [atomselect top \""${eda_sel}"\"]" >> temp.tcl
+  echo 'set all [atomselect top "all"]' >> temp.tcl
+  echo 'set n [molinfo top get numframes]' >> temp.tcl
+  echo 'for { set i 1 } { $i < $n } { incr i } {' >> temp.tcl
+  echo '  $sel frame $i' >> temp.tcl
+  echo '  $all frame $i' >> temp.tcl
+  echo '  $all move [measure fit $sel $ref]' >> temp.tcl
+  echo '}' >> temp.tcl
+  echo "animate write dcd ${out_dir}/eda/combined-${eda_sel_s}.dcd waitfor all" >> temp.tcl
+  echo 'sync' >> temp.tcl
+  echo 'exit' >> temp.tcl
+    
+  vmd -dispdev text -eofexit ${out_dir}/eda/combined-${eda_sel_s}.psf ${dcds[@]} < "temp.tcl"
+  
+  sync
+  rm temp.tcl
+  for system in ${systems[@]}; do
+    rm "${out_dir}/eda/${system}-${eda_sel_s}.dcd"
+    rm "${out_dir}/eda/${system}-${eda_sel_s}.pdb"
+    rm "${out_dir}/eda/${system}-${eda_sel_s}.psf"
+  done
+}
+
+concat_individual
+#concat_combined
+#concat_eda
+

+ 106 - 0
trajectory_analysis/11-rmsd-equilibration.sh

@@ -0,0 +1,106 @@
+#!/usr/bin/env bash
+export VMDNOCUDA=1
+#export VMDNOOPTIX=1
+export VMDNOOSPRAY=1
+
+. functions.sh
+
+#######################################################################################
+## ADJUSTABLE PARAMETERS                                                             ##
+#######################################################################################
+
+# set atom selection for alignment
+align_sel=${1?"chain A and name CA and resid 81 to 103 118 to 138 195 to 215 221 to 241 308 to 328 331 to 350 860 to 88 912 to 932 991 to 1011 1014 to 1034 1103 to 1123 1129 to 1149"}
+# set atom selection for rmsd calculation
+rmsd_sel=${2?"chain A and name CA and resid 81 to 103 118 to 138 195 to 215 221 to 241 308 to 328 331 to 350 860 to 88 912 to 932 991 to 1011 1014 to 1034 1103 to 1123 1129 to 1149"}
+
+#######################################################################################
+## SET VARS                                                                          ##
+#######################################################################################
+
+# set folder name for output files
+set_and_make_out_dir
+# Get array of concatenated, indvidual jobs
+get_jobs_individual
+
+#######################################################################################
+## CALCULATE RMSD                                                                    ##
+#######################################################################################
+
+function calc_rmsd() {
+
+  for _job in ${_jobs_individual}; do
+  
+    get_system_and_date ${_job}
+    psf=$(ls ${_job}/*.psf)
+    dcd=$(ls ${_job}/*.dcd)
+  
+    # load trajectory
+    echo "mol new ${psf}" > temp.tcl
+    echo "mol addfile ${dcd} waitfor all" >> temp.tcl
+  
+    # ALIGN
+    echo "set align_ref [atomselect top \""${align_sel}"\" frame 0]" >> temp.tcl
+    echo "set align_sel [atomselect top \""${align_sel}"\"]" >> temp.tcl
+    echo "set rmsd_ref [atomselect top \""${rmsd_sel}"\" frame 0]" >> temp.tcl
+    echo "set rmsd_sel [atomselect top \""${rmsd_sel}"\"]" >> temp.tcl
+    echo 'set all [atomselect top "all"]' >> temp.tcl
+    echo 'set n [molinfo top get numframes]' >> temp.tcl
+    echo "set fp [open "${out_dir}/${_system}-${_date}.csv" w]" >> temp.tcl
+    echo 'for { set i 1 } { $i < $n } { incr i } {' >> temp.tcl
+    echo '  $align_sel frame $i' >> temp.tcl
+    echo '  $rmsd_sel frame $i' >> temp.tcl
+    echo '  $all frame $i' >> temp.tcl
+    echo '  $all move [measure fit $align_sel $align_ref]' >> temp.tcl
+    # CALC RMSD
+    echo '  puts $fp "$i [measure rmsd $rmsd_sel $rmsd_ref]"' >> temp.tcl
+    echo '}' >> temp.tcl
+    echo 'close $fp'  >> temp.tcl
+    echo 'exit' >> temp.tcl
+  
+    vmd -dispdev text -eofexit < "temp.tcl"
+    sync
+    rm "temp.tcl"
+    
+    plot_rmsd ${_system} "${out_dir}/${_system}-${_date}"
+    
+  done
+  
+}
+
+
+function plot_rmsd() {
+gnuplot -persist <<-GNUPLOT_INPUT
+  set terminal pngcairo enhanced size 1200,1200 font "arial,24" linewidth 2
+  set output "${2}.png"
+  set autoscale
+  #set title "Backbone RMSD" font "arial,40"
+  #set xlabel "Time (ns)" font "arial,32"
+  #set ylabel "RMSD (Å)" font "arial,32"
+  set border 1+2
+  #set xtics nomirror
+  set ytics nomirror 1
+  set grid
+  set grid noxtics
+  set key box off
+  #set yrange [0:4]
+  #set xrange [0:120]
+  #set format y "%+-2.f"
+  set style data lines
+  set xzeroaxis ls 8
+  
+  # linetypes
+  #set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb '#000000'
+
+  plot "${2}.csv" using (\$1 / 50):(\$2 + 1) with linespoints ls 8 pi 0 pt 0
+  
+  exit
+
+GNUPLOT_INPUT
+}
+  
+
+
+calc_rmsd
+
+

+ 21 - 0
trajectory_analysis/2-ndx.sh

@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+out_dir="$(basename ${0})"
+out_dir="${out_dir%%.*}"
+
+# create array of system names
+
+ARR1=()
+for i in 1-concat/individual/*/*/ ; do
+    ARR1+=($(basename ${i}))
+done
+
+# make directory and create ndx files
+
+mkdir -p "${out_dir}"
+
+while read system; do
+    ARR2=("${out_dir}/individual/*/${system}/${system}-*.pdb")
+    ARR3=("${out_dir}/individual/*/${system}/${system}.ndx")
+    gmx make_ndx -f ${ARR2[1]} -n ${ARR3[1]} -o "${out_dir}/${system}.ndx"
+done < <(echo ${ARR1[@]} | tr " " "\n" | sort -u)

+ 53 - 0
trajectory_analysis/3-cluster.sh

@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+
+#######################################################################################
+## ADJUSTABLE PARAMETERS                                                             ##
+#######################################################################################
+
+# set folder name that contains the jobs
+job_folder="4-new_jobs"
+
+#######################################################################################
+## CLUSTER ANALYSIS                                                                  ##
+#######################################################################################
+
+out_dir="$(basename ${0})"
+out_dir="${out_dir%%.*}"
+
+# create array of systems
+
+function get_systems() {
+  systems=()
+  all_systems=()
+  _jobs=( $(ls -d ../${job_folder}/*/*/) )
+  for _job in ${_jobs[@]}; do
+    all_systems+=( $(basename ${_job}) )
+  done
+  systems+=( $(for _system in ${all_systems[@]}; do echo ${_system}; done | sort -u) )
+}
+get_systems
+
+for system in ${systems[@]}; do
+    mkdir -p ${out_dir}/median/${system}
+    mkdir -p ${out_dir}/average/${system}
+
+    # median clusters
+
+    # on SrtA
+    ( echo 'chA_&_CA_&_r_66-205' 'System' | gmx cluster -f 1-concat/combined/${system}-*.trr -s 1-concat/combined/${system}-*.pdb -n 2-ndx/${system}.ndx -g ${out_dir}/median/${system}/${system}.log -cutoff 0.2 -fit -method gromos -o ${out_dir}/median/${system}/${system}.xpm -dist ${out_dir}/median/${system}/${system}.xvg -cl ${out_dir}/median/${system}/${system}.pdb ) &
+	
+    # on ligand
+    ( echo 'chB' 'System' | gmx cluster -f 1-concat/combined/${system}-*.trr -s 1-concat/combined/${system}-*.pdb -n 2-ndx/${system}.ndx -g ${out_dir}/median/${system}/${system}_ligand.log -cutoff 0.2 -fit -method gromos -o ${out_dir}/median/${system}/${system}_ligand.xpm -dist ${out_dir}/median/${system}/${system}_ligand.xvg -cl ${out_dir}/median/${system}/${system}_ligand.pdb ) &
+
+    # average clusters
+
+    # on SrtA
+    ( echo 'chA_&_CA_&_r_66-205' 'System' | gmx cluster -f 1-concat/combined/${system}-*.trr -s 1-concat/combined/${system}-*.pdb -n 2-ndx/${system}.ndx -g ${out_dir}/average/${system}/${system}_av.log -cutoff 0.2 -fit -method gromos -o ${out_dir}/average/${system}/${system}_av.xpm -dist ${out_dir}/average/${system}/${system}_av.xvg -av -cl ${out_dir}/average/${system}/${system}_av.pdb ) &
+	
+    # on ligand
+    ( echo 'chB' 'System' | gmx cluster -f 1-concat/combined/${system}-*.trr -s 1-concat/combined/${system}-*.pdb -n 2-ndx/${system}.ndx -g ${out_dir}/average/${system}/${system}_ligand_av.log -cutoff 0.2 -fit -method gromos -o ${out_dir}/average/${system}/${system}_ligand_av.xpm -dist ${out_dir}/average/${system}/${system}_ligand_av.xvg -av -cl ${out_dir}/average/${system}/${system}_ligand_av.pdb ) &
+
+  wait
+
+done
+

+ 89 - 0
trajectory_analysis/4-rmsf.py

@@ -0,0 +1,89 @@
+#!/usr/bin/env python3
+
+from prody import *
+from pylab import *
+import matplotlib.pyplot as plt
+import itertools
+import os
+import glob
+import re
+ion()
+prody.confProDy(auto_show=False)
+
+# set output dir
+out_dir = os.path.splitext(os.path.basename(sys.argv[0]))[0]
+out_file = out_dir + "/combined"
+
+# create output dir
+if not os.path.exists(out_dir):
+    os.makedirs(out_dir)
+
+# create palette
+colors = itertools.cycle(["red", "blue", "green", "orange"])
+
+# parse files
+in_files=os.listdir("1-concat/eda/")
+out_files=os.listdir(out_dir)
+systems = []
+get_systems=os.listdir("1-concat/combined/")
+for filename in get_systems:
+  if filename.endswith(".pdb"):
+     systems.append(re.sub('-.*','',filename))
+my_pdb=glob.glob("1-concat/eda/combined*.pdb")
+
+# if system_names file is present, set names from there
+if os.path.exists('system_names'):
+  exec(open('system_names').read())
+else:
+  systems=sorted(systems)
+
+# load pdb
+structure = parsePDB(my_pdb[0])
+
+# load trajectory
+if os.path.exists(out_file + '_prody.dcd'):
+  trajectory = parseDCD(out_file + '_prody.dcd')
+  trajectory.setCoords(structure)
+  trajectory.setAtoms(structure.all)
+else:
+  dcd = glob.glob('1-concat/eda/combined-*.dcd')
+  trajectory = parseDCD(dcd[0])
+  trajectory.setCoords(structure)
+  trajectory.setAtoms(structure.all)
+  trajectory.superpose()
+  # save aligned dcd
+  writeDCD(out_file + '_prody.dcd', trajectory)
+
+# calculate frame increments
+num_frames = DCDFile.numFrames(trajectory)
+num_systems = len(systems)
+frame_incr = int(num_frames / num_systems - 1)
+res_nums = AtomGroup.getResnums(structure)
+first_res = res_nums[0]
+last_res = res_nums[-1]
+
+# create rmsf figure
+first_frame = 0
+last_frame = frame_incr
+plt.figure(figsize=(12, 6))
+for system in systems:
+  rmsf = calcRMSF(trajectory[first_frame:last_frame])
+  print(rmsf)
+  plt.plot(res_nums, rmsf, label=system, color=next(colors), linewidth=1.5)
+  first_frame = last_frame + 1
+  last_frame = first_frame + frame_incr
+title('RMSF', size=20)
+plt.xlabel('Residue #', size=16)
+plt.ylabel('Angstroms', size=16)
+plt.xlim([first_res,last_res])
+ax = subplot(1,1,1)
+handles, labels = ax.get_legend_handles_labels()
+labels, handles = zip(*sorted(zip(labels, handles), key=lambda t: t[0]))
+plt.legend(handles, labels, loc='upper left')
+ax.grid(True)
+plt.savefig(out_file + '_rmsf.png', dpi=300, format='png')
+plt.close('all[')
+
+
+
+

+ 161 - 0
trajectory_analysis/5-eda.py

@@ -0,0 +1,161 @@
+#!/usr/bin/env python3
+
+from prody import *
+from pylab import *
+import matplotlib.pyplot as plt
+import itertools
+import os
+import glob
+import re
+ion()
+prody.confProDy(auto_show=False)
+
+#######################################################################################
+## ADJUSTABLE PARAMETERS                                                             ##
+#######################################################################################
+
+# set specific system names to visualize
+#visualize=[]
+
+#show=["ALL", "no_PHQ"]
+
+#######################################################################################
+## JOB CONTROL                                                                       ##
+#######################################################################################
+
+# set output dir
+out_dir = os.path.splitext(os.path.basename(sys.argv[0]))[0]
+out_file = out_dir + "/combined"
+
+# create palette
+colors = itertools.cycle(["red", "blue", "green", "orange"])
+
+# create output dir
+if not os.path.exists(out_dir):
+    os.makedirs(out_dir)
+
+# parse files
+in_files=os.listdir("1-concat/eda/")
+out_files=os.listdir(out_dir)
+systems = []
+get_systems=os.listdir("1-concat/combined/")
+for filename in get_systems:
+  if filename.endswith(".pdb"):
+    systems.append(re.sub('-.*','',filename))
+my_pdb=glob.glob("1-concat/eda/combined*.pdb")
+
+# if system_names file is present, set names from there
+if os.path.exists('system_names'):
+  exec(open('system_names').read())
+else:
+  systems=sorted(systems)
+
+# load pdb
+structure = parsePDB(my_pdb[0])
+structure_select = structure.select("resnum 88:203")
+
+# load trajectory
+if os.path.exists(out_file + '_prody.dcd'):
+  trajectory = parseDCD(out_file + '_prody.dcd')
+  trajectory.setCoords(structure_select)
+  trajectory.setAtoms(structure_select)
+else:
+  combined_dcd = glob.glob('1-concat/eda/combined-*.dcd')
+  trajectory = parseDCD(combined_dcd[0])
+  trajectory.setCoords(structure)
+  trajectory.setAtoms(structure_select)
+  trajectory.superpose()
+  # save aligned dcd
+  writeDCD(out_file + '_prody.dcd', trajectory)
+
+# calculate frame increments
+num_frames = DCDFile.numFrames(trajectory)
+num_systems = len(systems)
+frame_incr = int(num_frames / num_systems - 1)
+res_nums = structure_select.getResnums()
+first_res = res_nums[0]
+last_res = res_nums[-1]
+
+# calculate covariance and modes
+if os.path.exists(out_file + '.eda.npz'):
+  eda_trajectory = loadModel(out_file + '.eda.npz')
+else:
+  eda_trajectory = EDA(combined_dcd[0])
+  eda_trajectory.buildCovariance(trajectory, aligned=True)
+  eda_trajectory.calcModes(n_modes=10)
+  saveModel(eda_trajectory, filename=out_file)
+  
+for mode in eda_trajectory[:4]:
+  print(calcFractVariance(mode))
+
+# write VMD files
+writeNMD(out_file, eda_trajectory[:10], structure_select)
+
+# create EDA rmsf figures
+def my_showSqFlucts(modes, *args, **kwargs):
+    """Show square fluctuations using :func:`~matplotlib.pyplot.plot`.  See
+    also :func:`.calcSqFlucts`."""
+
+    import matplotlib.pyplot as plt
+    sqf = calcSqFlucts(modes)
+    if not 'label' in kwargs:
+        kwargs['label'] = str(modes)
+    show = plt.plot(res_nums,sqf, *args, **kwargs)
+    plt.xlabel('Residue #')
+    plt.ylabel('Square fluctuations')
+    plt.xlim([first_res,last_res])
+    plt.title(str(modes))
+    return show
+for i in range(0, 4):
+  j = i + 1
+  plt.figure(figsize=(8, 6))
+  my_showSqFlucts(eda_trajectory[i])
+  title('RMSF (EDA Mode ' + str(j) + ')')
+  plt.savefig(out_file + '_rmsf_mode_' + str(j) + '.png', dpi=300, format='png')
+  plt.close('all[')
+
+# create cross-corr figure
+def my_showCrossCorr(modes, *args, **kwargs):
+    import matplotlib.pyplot as plt
+    arange = np.arange(first_res - 1 ,last_res)
+    cross_correlations = np.zeros((arange[-1]+2, arange[-1]+2))
+    cross_correlations[arange[0]+1:,
+                       arange[0]+1:] = calcCrossCorr(modes)
+    kwargs['interpolation'] = 'bilinear'
+    kwargs['origin'] = 'lower'
+    show = plt.imshow(cross_correlations, *args, **kwargs), plt.colorbar()
+    plt.axis([arange[0]+0.5, arange[-1]+1.5, arange[0]+0.5, arange[-1]+1.5])
+    plt.title('Cross-correlations for {0}'.format(str(modes)))
+    plt.xlabel('Residue')
+    plt.ylabel('Residue')
+    return show
+
+plt.figure(figsize=(8, 6))
+my_showCrossCorr(eda_trajectory)
+title('Cross-correlation matrix')
+plt.savefig(out_file + '_corr.png', dpi=300, format='png')
+plt.close('all')
+
+# create projection figures
+plt.figure(figsize=(8, 6))
+showProjection(trajectory[:frame_incr], eda_trajectory[0,1], color='red', marker='.', label=systems[0])
+showProjection(trajectory[frame_incr + 1:frame_incr * 2 + 1], eda_trajectory[0,1], color='green', marker='.', label=systems[1]);
+legend(markerscale=2, numpoints=1, handletextpad=0.25)
+title('EDA')
+plt.savefig(out_file + '_proj1_2.png', dpi=300, format='png')
+plt.close('all')
+
+plt.figure(figsize=(8, 6))
+showProjection(trajectory[:frame_incr], eda_trajectory[2,3], color='red', marker='.', label=systems[0])
+showProjection(trajectory[frame_incr + 1:frame_incr * 2 + 1], eda_trajectory[2,3], color='green', marker='.', label=systems[1]);
+legend(markerscale=2, numpoints=1, handletextpad=0.25)
+title('EDA')
+plt.savefig(out_file + '_proj3_4.png', dpi=300, format='png')
+plt.close('all')
+
+
+
+
+
+
+        

+ 175 - 0
trajectory_analysis/6-energy.sh

@@ -0,0 +1,175 @@
+#!/usr/bin/env bash
+export VMDNOCUDA=1
+#export VMDNOOPTIX=1
+export VMDNOOSPRAY=1
+
+#######################################################################################
+## ADJUSTABLE PARAMETERS                                                             ##
+#######################################################################################
+
+# set step size for dcd file incrementing
+step_size=10000000
+# set folder name that contains the jobs
+job_folder="4-new_jobs"
+# set sel1
+sel1="chain B and not resname PHQ"
+# set sel2
+sel2="chain A"
+# only run specific systems
+my_systems=("ALL")
+
+#######################################################################################
+## FUNCTIONS                                                                         ##
+#######################################################################################
+
+function get_systems() {
+  systems=()
+  all_systems=()
+  _jobs=( $(ls -d ../${job_folder}/*/*/) )
+  for _job in ${_jobs[@]}; do
+    all_systems+=( $(basename ${_job}) )
+  done
+  systems+=( $(for _system in ${all_systems[@]}; do echo ${_system}; done | sort -u) )
+}
+
+function get_ffs() {
+  ffs=()
+  for ff in ../0-forcefields/*; do
+    if [[ -f "${ff}" ]]; then
+      ffs+=(${ff})
+    fi
+  done
+}
+
+#######################################################################################
+## ENERGY ANALYSIS                                                                   ##
+#######################################################################################
+
+# set folder name for output files
+out_dir="$(basename ${0})"
+out_dir="${out_dir%%.*}2"
+
+function namd_energy() {
+
+  get_systems
+  get_ffs
+  
+  mkdir -p ${out_dir}
+  
+  ffs_energy=""
+  for ff in ${ffs[@]}; do
+    ffs_energy+="-par \"${ff}\" "
+  done
+    
+
+  for system in "${systems[@]}"; do
+
+    if echo ${my_systems[@]} | grep -w ${system} > /dev/null; then
+      
+      jobs=( $(ls -d ../${job_folder}/*/${system}/) )
+      
+      for job in ${jobs[@]}; do
+        job=${job%%/}
+        date=${job#*/*/}
+        date=${date%/*}
+        dcds=( $(ls ${job}/*sim_*.dcd | sort -V) )
+        xscs=( $(ls ${job}/*sim_*.xsc | sort -V) )
+      
+        # Run NAMDEnergy
+        echo 'package require namdenergy' > temp.tcl
+        echo "set sel1 [atomselect top \"${sel1}\"]" >> temp.tcl
+        echo "set sel2 [atomselect top \"${sel2}\"]" >> temp.tcl
+        echo "namdenergy -vdw -elec -nonb -sel \$sel1 \$sel2 -ofile \""${out_dir}/${system}-${date}.csv"\" -tempname \""${system}-${date}"\" -switch 10 -cutoff 12 -diel 1.0 -T 310 -timemult 2 -stride 10000 -extsys "${xscs[0]}" -pme ${ffs_energy} -exe "/home/bryan/bin/namd2" -plot" >> temp.tcl
+        echo 'exit' >> temp.tcl
+
+        # run temp.tcl
+        vmd -dispdev text -eofexit ${job}/${system}_solv_ion.psf ${dcds[@]:1} < "temp.tcl"
+        rm "temp.tcl"
+      done
+  
+    awk 'FNR == 1 { nfiles++; ncols = NF }
+       { for (i = 1; i < NF; i++) sum[FNR,i] += $i
+         if (FNR > maxnr) maxnr = FNR
+       }
+       END {
+           for (line = 1; line <= maxnr; line++)
+           {
+               for (col = 1; col < ncols; col++)
+                    printf "  %.2f", sum[line,col]/nfiles;
+               printf "\n"
+           }
+       }' ${out_dir}/${system}-* > ${out_dir}/${system}-combined.csv
+   fi
+   
+   rm FFTW_NAMD*
+   
+   plot_energy ${system} ${out_dir}/${system}-combined
+     
+  done
+}
+
+function plot_energy() {
+gnuplot -persist <<-GNUPLOT_INPUT
+  set terminal pngcairo enhanced size 1600,1200 font "arial,24" linewidth 2
+  set output "${2}.png"
+  set autoscale
+  set title "SrtA-{/Arial-Italic Boc} interaction energy" font "arial,40"
+  set xlabel "Time (ns)" font "arial,32"
+  set ylabel "Energy (kcal/mol)" font "arial,32"
+  set border 1+2
+  #set xtics nomirror
+  set ytics nomirror
+  set grid
+  set grid noxtics
+  set key box off
+  set yrange [-25:0]
+  #set format y "%+-2.f"
+  set style data lines
+  set xzeroaxis ls 8
+  
+  # linetypes
+  #set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb '#000000'
+
+  plot "${2}.csv" using (\$1 / 50):5 with linespoints ls 8 pi 0 pt 0
+  
+  exit
+
+GNUPLOT_INPUT
+}
+
+function plot_energy2() {
+gnuplot -persist <<-GNUPLOT_INPUT
+  set terminal pngcairo enhanced size 1600,1200 font "arial,24" linewidth 2
+  set output "ALL-combined-both.png"
+  set datafile separator ","
+  set autoscale
+  set title "SrtA-{/Arial-Italic Boc} interaction energy" font "arial,40"
+  set xlabel "Time (ns)" font "arial,32"
+  set ylabel "Energy (kcal/mol)" font "arial,32"
+  set border 1+2
+  #set xtics nomirror
+  set ytics nomirror
+  set grid
+  set grid noxtics
+  set key box right bottom
+  set yrange [-80:0]
+  #set format y "%+-2.f"
+  set style data filledcurves
+  #set xzeroaxis ls 8
+  
+  # linetypes
+  set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb '#696969'
+  set style line 2 pi 0 lw 1 ps 1 pt 0 lc rgb 'black'
+
+  plot 'ALL-combined-both.csv' using (\$1 / 50):(\$3 + \$4) title 'SS peptide' with filledcurves y1=0 ls 1, \
+  '' using (\$1 / 50):(\$3) title '{/Arial-Italic Boc}' with filledcurves y1=0 ls 2
+  
+  exit
+
+GNUPLOT_INPUT
+}
+
+namd_energy
+
+
+

+ 210 - 0
trajectory_analysis/7-contacts.sh

@@ -0,0 +1,210 @@
+#!/usr/bin/env bash
+export VMDNOCUDA=1
+#export VMDNOOPTIX=1
+export VMDNOOSPRAY=1
+
+#######################################################################################
+## ADJUSTABLE PARAMETERS                                                             ##
+#######################################################################################
+
+# set sel1 and sel1 name
+sel1=("chain A and name CA" "SrtA")
+# set sel2 and sel2 name
+#sel2=("chain B and resname PHQ" "{/Arial-Italic Boc}")
+sel2=("chain B" "SS")
+# only run specific systems
+#my_systems=("ALL")
+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+}')
+# cutoff
+cutoff=3.0
+# combine?
+combine=1
+
+#######################################################################################
+## FUNCTIONS                                                                         ##
+#######################################################################################
+
+# set folder name for output files
+out_dir="$(basename ${0})"
+out_dir="${out_dir%%.*}"
+
+# set output suffix
+suffix="${sel1[0]}_vs_${sel2[0]}"
+suffix="${suffix// /_}"
+
+
+#######################################################################################
+## CALC CONTACTS                                                                     ##
+#######################################################################################
+
+function calc_contacts() {
+
+  systems=()
+  
+  for (( i = 0 ; i < ${#systems_names[@]} ; i+=2 )); do
+    systems+=(${systems_names[i]})
+  done
+  
+  mkdir -p ${out_dir}
+  
+  for system in ${systems[@]}; do
+    
+    psf=$(ls 1-concat/combined/${system}-*.psf)
+    dcd=$(ls 1-concat/combined/${system}-*.dcd)
+
+    echo 'set numframes [expr {[molinfo top get numframes] - 1}]' > temp.tcl
+    echo 'set totframes [expr $numframes + 1]' >> temp.tcl
+    echo "set A [atomselect top \""${sel1[0]}"\"]" >> temp.tcl
+    echo "set B [atomselect top \""${sel2[0]}"\"]" >> temp.tcl
+    
+    # cycle over the trajectory
+    echo 'for {set i 0} {$i <= $numframes} {incr i} {' >> temp.tcl
+    echo '  foreach resID [$A get resid] {' >> temp.tcl
+    echo '    set A_temp [atomselect top "resid $resID"]' >> temp.tcl
+    echo '    $A_temp frame $i' >> temp.tcl
+    echo '    $B frame $i' >> temp.tcl
+    echo '    $A_temp update' >> temp.tcl
+    echo '    $B update' >> temp.tcl
+    echo "    foreach {listA tmp} [measure contacts ${cutoff} \$A_temp \$B] break" >> temp.tcl
+    echo '    if {[llength $listA] > 0} {' >> temp.tcl
+    echo '      lappend contactTable($resID) $i' >> temp.tcl
+    echo '    } else {'  >> temp.tcl
+    echo '      lappend contactTable($resID)' >> temp.tcl
+    echo '    }' >> temp.tcl
+    echo '    $A_temp delete' >> temp.tcl
+    echo '  }' >> temp.tcl
+    echo '  puts $i' >> temp.tcl
+    echo '}' >> temp.tcl
+    
+    # open output file for writing
+    echo "set fContAB \""${out_dir}/${system}-${suffix}-contacts.csv"\"" >> temp.tcl
+    echo 'set fcAB [open $fContAB w]' >> temp.tcl
+    # calculate percentage
+    echo 'foreach resID [lsort -integer [array names contactTable]] {' >> temp.tcl
+    echo '  set frames [llength $contactTable($resID)]' >> temp.tcl
+    echo '  set percentage [expr 100.0 * $frames / $totframes]' >> temp.tcl
+    # write to file
+    echo '  puts $fcAB "$resID $percentage"' >> temp.tcl
+    echo '  flush $fcAB' >> temp.tcl
+    # set user values
+    echo '  set sel1 [atomselect top "resid $resID"]' >> temp.tcl
+    echo '  for {set i 0} {$i <= $numframes} {incr i} {' >> temp.tcl
+    echo '    $sel1 frame $i' >> temp.tcl
+    echo '    $sel1 set user $percentage' >> temp.tcl
+    echo '  }' >> temp.tcl
+    echo '  $sel1 delete' >> temp.tcl
+    echo '}' >> temp.tcl
+    # close output files
+    echo 'close $fcAB' >> temp.tcl
+    echo 'exit' >> temp.tcl
+    
+    vmd -dispdev text -eofexit ${psf} ${dcd} < "temp.tcl"
+    sync
+    rm "temp.tcl"
+  
+    plot_contacts "${system}"
+    
+  done
+    
+  if (( ${combine} != 0 )); then
+    plot_combined_contacts "${systems_names[@]}"
+  fi
+  
+}
+
+function plot_contacts() {
+
+  echo 'set terminal pngcairo enhanced size 1600,1200 font "arial,24" linewidth 2' > temp
+  echo "set output \"${out_dir}/${1}-${suffix}-contacts.png\"" >> temp
+  echo 'set autoscale' >> temp
+  echo "set title \"${sel1[1]}-${sel2[1]} contacts\" font \"arial,40\"" >> temp
+  echo 'set xlabel "Residue" font "arial,32"' >> temp
+  echo 'set ylabel "% Contacts" font "arial,32"' >> temp
+  echo 'set border 1+2' >> temp
+  echo 'set xtics nomirror out' >> temp
+  echo 'set ytics nomirror' >> temp
+  echo 'set grid' >> temp
+  echo 'set grid noxtics' >> temp
+  echo 'set key box off' >> temp
+  echo '#set yrange [-25:0]' >> temp
+  echo '#set format y "%+-2.f"' >> temp
+  echo 'set style data lines' >> temp
+  echo 'set xzeroaxis ls 8' >> temp
+  
+  echo "plot "${out_dir}/${1}-${suffix}-contacts.csv" using 1:2 with impulses ls 8" >> temp
+  
+  echo 'exit' >> temp
+
+  gnuplot temp
+  rm temp
+}
+
+
+# probably want to handle this one manually
+function plot_combined_contacts() {
+
+  systems=()
+  names=()
+  
+  for (( i = 0 ; i < ${#systems_names[@]} ; i+=2 )); do
+    systems+=(${systems_names[${i}]})
+  done
+  
+  for (( i = 1 ; i < ${#systems_names[@]} ; i+=2 )); do
+    names+=("${systems_names[${i}]}")
+  done
+
+  echo 'set terminal pngcairo enhanced size 2400,1200 font "arial,24" linewidth 2' > temp
+  echo "set output \"${out_dir}/combined-${suffix}-contacts.png\"" >> temp
+  echo 'set autoscale' >> temp
+  echo "set title \"${sel1[1]}-${sel2[1]} contacts\" font \"arial,40\"" >> temp
+  echo 'set xlabel "Residue" font "arial,32"' >> temp
+  echo 'set ylabel "% Contacts" font "arial,32"' >> temp
+  echo 'set border 1+2' >> temp
+  echo 'set xtics nomirror out rotate' >> temp
+  echo 'set ytics nomirror' >> temp
+  echo 'set grid' >> temp
+  echo 'set grid noxtics' >> temp
+  echo 'set key box top center' >> temp
+  echo '#set style data histogram' >> temp
+  echo 'set style fill solid border' >> temp
+  echo '#set xzeroaxis ls 8' >> temp
+  
+  # linetypes
+  echo '#set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb "black"' >> temp
+  echo 'set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb "red"' >> temp
+  echo 'set style line 2 pi 0 lw 1 ps 1 pt 0 lc rgb "green"' >> temp
+  echo 'set style line 3 pi 0 lw 1 ps 1 pt 0 lc rgb "blue"' >> temp
+  echo 'set style line 4 pi 0 lw 1 ps 1 pt 0 lc rgb "orange"' >> temp
+
+  # thin out xtic labels
+  echo 'every(col) = (int(column(col))%10 ==0)?stringcolumn(1):""' >> temp
+
+  # plot
+  echo 'plot \' >> temp
+  
+  for (( i = 0 ; i < ${#systems[@]} ; i++ )); do
+    if [ $i -eq $((${#systems[@]} - 1)) ]; then
+      echo "\"${out_dir}/${systems[$i]}-${suffix}-contacts.csv\" using 2:xticlabels(every(1)) with histogram ls $((${i} + 1)) title \""${names[$i]}"\"" >> temp
+    else
+      echo "\"${out_dir}/${systems[$i]}-${suffix}-contacts.csv\" using 2:xticlabels(every(1)) with histogram ls $((${i} + 1)) title \""${names[$i]}"\", \\" >> temp
+    fi
+  done
+  
+  echo 'exit' >> temp
+
+  gnuplot temp
+  #rm temp
+
+}
+
+
+calc_contacts
+
+
+
+
+
+
+
+

+ 148 - 0
trajectory_analysis/7-contacts2.sh

@@ -0,0 +1,148 @@
+#!/usr/bin/env bash
+export VMDNOCUDA=1
+#export VMDNOOPTIX=1
+export VMDNOOSPRAY=1
+
+#######################################################################################
+## ADJUSTABLE PARAMETERS                                                             ##
+#######################################################################################
+
+# set sel1 and sel1 name
+sel1=("resid 171" "acceptor")
+# set sel2 and sel2 name
+#sel2=("chain B and resname PHQ" "{/Arial-Italic Boc}")
+sel2=("resid 140 204" "donor")
+# job folder
+job_folder="4-jobs"
+# cutoff
+cutoff=3.0
+
+
+#######################################################################################
+## FUNCTIONS                                                                         ##
+#######################################################################################
+
+# set folder name for output files
+out_dir="$(basename ${0})"
+out_dir="${out_dir%%.*}"
+
+# set output suffix
+suffix="${sel1[0]}_vs_${sel2[0]}"
+suffix="${suffix// /_}"
+
+# create array of systems
+
+function get_systems() {
+  systems=()
+  all_systems=()
+  _jobs=( $(ls -d 1-concat/combined/*.pdb) )
+  for _job in ${_jobs[@]}; do
+    all_systems+=( $( basename ${_job%-*.pdb} ) )
+  done
+  systems+=( $(for _system in ${all_systems[@]}; do echo ${_system}; done | sort -u) )
+}
+get_systems
+
+
+#######################################################################################
+## CALC CONTACTS                                                                     ##
+#######################################################################################
+
+function calc_contacts_num() {
+  
+  mkdir -p ${out_dir}
+  echo ${systems[@]}
+  
+  for system in ${systems[@]}; do
+    
+    psf=$(ls 1-concat/combined/${system}-*.psf)
+    dcd=$(ls 1-concat/combined/${system}-*.dcd)
+  
+    echo 'set n [molinfo top get numframes]' > temp.tcl
+    echo "set sel1 [atomselect top \""${sel1[0]}"\"]" >> temp.tcl
+    echo "set sel2 [atomselect top \""${sel2[0]}"\"]" >> temp.tcl
+    echo "set fp [open "${out_dir}/${system}-${suffix}.csv" w]" >> temp.tcl
+    
+    # cycle over the trajectory
+    echo 'for {set i 0} {$i <= $n} {incr i} {' >> temp.tcl
+    echo '  $sel1 frame $i' >> temp.tcl
+    echo '  $sel2 frame $i' >> temp.tcl
+    echo "  set contacts [measure contacts ${cutoff} \$sel1 \$sel2]" >> temp.tcl
+    echo '  set count [llength [lindex $contacts 0]]' >> temp.tcl
+    echo '  puts $fp "${i} ${count}"' >> temp.tcl
+    echo '}'  >> temp.tcl
+    echo 'close $fp'  >> temp.tcl
+    
+    vmd -dispdev text -eofexit ${psf} ${dcd} < "temp.tcl"
+    sync
+    rm "temp.tcl"
+    
+  done
+  
+}
+  
+  
+calc_contacts_num
+  
+function plot_contacts_num() {
+
+  systems=()
+  names=()
+  
+  for (( i = 0 ; i < ${#systems_names[@]} ; i+=2 )); do
+    systems+=(${systems_names[${i}]})
+  done
+  
+  for (( i = 1 ; i < ${#systems_names[@]} ; i+=2 )); do
+    names+=("${systems_names[${i}]}")
+  done
+
+  echo 'set terminal pngcairo enhanced size 1600,1200 font "arial,24" linewidth 2' > temp
+  echo "set output \"${out_dir}/combined-${suffix}.png\"" >> temp
+  echo 'set autoscale' >> temp
+  echo "set title \"${sel1[1]}-${sel2[1]} contacts\" font \"arial,40\"" >> temp
+  echo 'set xlabel "ns" font "arial,32"' >> temp
+  echo 'set ylabel "# Contacts" font "arial,32"' >> temp
+  echo 'set border 1+2' >> temp
+  echo 'set xtics nomirror out' >> temp
+  echo 'set ytics nomirror' >> temp
+  echo 'set grid' >> temp
+  echo 'set grid noxtics' >> temp
+  echo 'set key box top right' >> temp
+  echo '#set yrange [-25:0]' >> temp
+  echo '#set format y "%+-2.f"' >> temp
+  echo 'set style data lines' >> temp
+  echo '#set xzeroaxis ls 8' >> temp
+  
+  # linetypes
+  echo '#set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb "black"' >> temp
+  echo 'set style line 1 pi 0 lw 1 ps 1 pt 0 lc rgb "red"' >> temp
+  echo 'set style line 2 pi 0 lw 1 ps 1 pt 0 lc rgb "green"' >> temp
+  echo 'set style line 3 pi 0 lw 1 ps 1 pt 0 lc rgb "blue"' >> temp
+  echo 'set style line 4 pi 0 lw 1 ps 1 pt 0 lc rgb "orange"' >> temp
+  
+  # plot
+  echo 'plot \' >> temp
+  
+  for (( i = 0 ; i < ${#systems[@]} ; i++ )); do
+    if [ $i -eq $((${#systems[@]} - 1)) ]; then
+      echo "\"${out_dir}/${systems[$i]}-${suffix}.csv\" using 1:2 with linespoints ls $((${i} + 1)) title \""${names[$i]}"\"" >> temp
+    else
+      echo "\"${out_dir}/${systems[$i]}-${suffix}.csv\" using 1:2 with linespoints ls $((${i} + 1)) title \""${names[$i]}"\", \\" >> temp
+    fi
+  done
+  
+  echo 'exit' >> temp
+
+  gnuplot temp
+  #rm temp
+}
+  
+  
+  
+  
+  
+  
+  
+  
+  

+ 24 - 0
trajectory_analysis/functions.sh

@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+function get_jobs_individual() {
+  export _jobs_individual=(1-concat/individual/*/*/)
+}
+
+
+function get_system_and_date() {
+  echo "${1%%/*}"
+  _system="${1#*/*/*/}"
+  export _system="${_system%/}"
+  _date="${1#*/*/*}"
+  export _date="${_date%/*/}"
+}
+
+function set_and_make_out_dir() {
+  caller_output=$( caller )
+  script_name=${caller_output#*/}
+  script_name="${script_name%.*}"
+  export out_dir="${script_name}/"
+  mkdir -p "${out_dir}" 
+}
+
+

+ 7 - 0
trajectory_analysis/test.sh

@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+. functions.sh
+
+set_and_make_out_dir
+echo "${out_dir}"
+#echo "${script_name}"