#!/bin/bash
#SBATCH --time=4:00:00
#SBATCH --nodes=1
#SBATCH --account=owner-guest
#SBATCH --partition=lonepeak-guest
set -x

cpptraj='/uufs/chpc.utah.edu/sys/spack/linux-rocky8-nehalem/gcc-8.5.0/amber-20.20-e3y74ad3qouojwko32d5z6uhvttrm2hz/bin/cpptraj'


# for systems with 24 bases
cat > ~/ff-battles/analysis/term-dist24.cpptraj << EOF
parm vacuo.topo
trajin vacuo-aggregate.nc 1 last 10

distance T1 out data/terminal-dist-top1.dat :1&!@H= :24&!@H= time 0.02
hist T1 norm min 0 max 10 bins 500 out data/terminal-dist-top1.hist
distance T2 out data/terminal-dist-top2.dat :2&!@H= :23&!@H= time 0.02
hist T2 norm min 0 max 10 bins 500 out data/terminal-dist-top2.hist
distance B1 out data/terminal-dist-bottom1.dat :12&!@H= :13&!@H= time 0.02
hist B1 norm min 0 max 10 bins 500 out data/terminal-dist-bottom1.hist
distance B2 out data/terminal-dist-bottom2.dat :11&!@H= :14&!@H= time 0.02
hist B2 norm min 0 max 10 bins 500 out data/terminal-dist-bottom2.hist
run

EOF

## reference structure
cat > ~/ff-battles/analysis/term-dist24-ref.cpptraj << EOF
parm start.pdb
trajin start.pdb

distance T1 out data-ref/terminal-dist-top1.dat :1&!@H= :24&!@H= time 0.02
distance T2 out data-ref/terminal-dist.top2.dat :2&!@H= :23&!@H= time 0.02
distance B1 out data-ref/terminal-dist-bottom1.dat :12&!@H= :13&!@H= time 0.02
distance B2 out data-ref/terminal-dist-bottom2.dat :11&!@H= :14&!@H= time 0.02
run

EOF


# for systems with 12 bases
cat > ~/ff-battles/analysis/term-dist12.cpptraj << EOF
parm vacuo.topo
trajin vacuo-aggregate.nc 1 last 10

distance T1 out data/terminal-dist-top1.dat :1&!@H= :12&!@H= time 0.02
hist T1 norm min 0 max 10 bins 500 out data/terminal-dist-top1.hist
distance T2 out data/terminal-dist-top2.dat :2&!@H= :11&!@H= time 0.02
hist T2 norm min 0 max 10 bins 500 out data/terminal-dist-top2.hist
distance B1 out data/terminal-dist-bottom1.dat :6&!@H= :7&!@H= time 0.02
hist B1 norm min 0 max 10 bins 500 out data/terminal-dist-bottom1.hist
distance B2 out data/terminal-dist-bottom2.dat :5&!@H= :8&!@H= time 0.02
hist B2 norm min 0 max 10 bins 500 out data/termin-dist-bottom2.hist
run

EOF

## reference structure
cat > ~/ff-battles/analysis/term-dist12-ref.cpptraj << EOF
parm start.pdb
trajin start.pdb

distance T1 out data-ref/terminal-dist-top1.dat :1&!@H= :12&!@H= time 0.02
distance T2 out data-ref/terminal-dist-top2.dat :2&!@H= :11&!@H= time 0.02
distance B1 out data-ref/terminal-dist-bottom1.dat :6&!@H= :7&!@H= time 0.02
distance B2 out data-ref/terminal-dist-bottom2.dat :5&!@H= :8&!@H= time 0.02
run

EOF


# for systems with 20 bases
cat > ~/ff-battles/analysis/term-dist20.cpptraj << EOF
parm vacuo.topo
trajin vacuo-aggregate.nc 1 last 10

distance T1 out data/terminal-dist-top1.dat :1&!@H= :20&!@H= time 0.02
hist T1 norm min 0 max 10 bins 500 out data/terminal-dist-top1.hist
distance T2 out data/terminal-dist-top2.dat :2&!@H= :19&!@H= time 0.02
hist T2 norm min 0 max 10 bins 500 out data/terminal-dist-top2.hist
distance B1 out data/terminal-dist-bottom1.dat :10&!@H= :11&!@H= time 0.02
hist B1 norm min 0 max 10 bins 500 out data/terminal-dist-bottom1.hist
distance B2 out data/terminal-dist-bottom2.dat :9&!@H= :12&!@H= time 0.02
hist B2 norm min 0 max 10 bins 500 out data/terminal-dist-bottom2.hist
run

EOF

## reference structure 
cat > ~/ff-battles/analysis/term-dist20-ref.cpptraj << EOF
parm start.pdb
trajin start.pdb

distance T1 out data-ref/terminal-dist-top1.dat :1&!@H= :20&!@H= time 0.02
distance T2 out data-ref/terminal-dist-top2.dat :2&!@H= :19&!@H= time 0.02
distance B1 out data-ref/terminal-dist-bottom1.dat :10&!@H= :11&!@H= time 0.02
distance B2 out data-ref/terminal-dist-bottom2.dat :9&!@H= :12&!@H= time 0.02
run

EOF


# for systems with 36 bases
cat > ~/ff-battles/analysis/term-dist36.cpptraj << EOF
parm vacuo.topo
trajin vacuo-aggregate.nc 1 last 10

distance T1 out data/terminal-dist-top1.dat :1&!@H= :36&!@H= time 0.02
hist T1 norm min 0 max 10 bins 500 out data/terminal-dist-top1.hist
distance T2 out data/terminal-dist-top2.dat :2&!@H= :35&!@H= time 0.02
hist T2 norm min 0 max 10 bins 500 out data/terminal-dist-top2.hist
distance B1 out data/terminal-dist-bottom1.dat :18&!@H= :19&!@H= time 0.02
hist B1 norm min 0 max 10 bins 500 out data/terminal-dist-bottom1.hist
distance B2 out data/terminal-dist-bottom2.dat :17&!@H= :20&!@H= time 0.02
hist B2 norm min 0 max 10 bins 500 out data/terminal-dist-bottom2.hist
run

EOF

## reference structure
cat > ~/ff-battles/analysis/term-dist36-ref.cpptraj << EOF
parm start.pdb
trajin start.pdb

distance T1 out data-ref/terminal-dist-top1.dat :1&!@H= :36&!@H= time 0.02
distance T2 out data-ref/terminal-dist-top2.dat :2&!@H= :35&!@H= time 0.02
distance B1 out data-ref/terminal-dist-bottom1.dat :18&!@H= :19&!@H= time 0.02
distance B2 out data-ref/terminal-dist-bottom2.dat :17&!@H= :20&!@H= time 0.02
run

EOF





for sim in 1fzx ddd;
do
	cd ~/ff-battles/$sim/
	pwd
	sleep 1
	cpptraj -i ~/ff-battles/analysis/term-dist24-ref.cpptraj
	for ff in bsc1 OL15 OL21 tumuc1;
	do
		for wat in tip3p opc;
		do
			cd ~/ff-battles/$sim/$ff/$wat/
			pwd
			sleep 1
			pwd
			cpptraj -i ~/ff-battles/analysis/term-dist24.cpptraj
		done
	done
done

for sim in 1ick;
do
	cd ~/ff-battles/$sim/
	pwd
	sleep 1
	cpptraj -i ~/ff-battles/analysis/term-dist12-ref.cpptraj
	for ff in bsc1 OL15 OL21 tumuc1;
	do
		for wat in tip3p opc;
		do
			cd ~/ff-battles/$sim/$ff/$wat/
			pwd
			sleep 1 
			pwd
			cpptraj -i ~/ff-battles/analysis/term-dist12.cpptraj
		done
	done
done

for sim in 1sk5 3ggi;
do
	cd ~/ff-battles/$sim/
	pwd
	sleep 1
	cpptraj -i ~/ff-battles/analysis/term-dist20-ref.cpptraj
	for ff in bsc1 OL15 OL21 tumuc1;
	do
		for wat in tip3p opc;
		do
			cd ~/ff-battles/$sim/$ff/$wat/
			pwd
			sleep 1
			pwd
			cpptraj -i ~/ff-battles/analysis/term-dist20.cpptraj
		done
	done
done

for sim in gaac;
do
	cd ~/ff-battles/$sim/
	pwd
	sleep 1
	cpptraj -i ~/ff-battles/analysis/term-dist36-ref.cpptraj
	for ff in bsc1 OL15 OL21 tumuc1;
	do
		for wat in tip3p opc;
		do
			cd ~/ff-battles/$sim/$ff/$wat/
			pwd
			sleep 1
			pwd
			cpptraj -i ~/ff-battles/analysis/term-dist36.cpptraj
		done
	done
done

rm ~/ff-battles/analysis/term-dist*.cpptraj



echo 'Job done!'



