#!/bin/tcsh

rm -r compare-runs
mkdir compare-runs

foreach T (280.00 286.04 292.18 298.41 304.74 311.17 317.69 324.31 331.03 337.85 344.79 351.82 358.97 366.22 373.59 381.07 388.67 396.40)
	mkdir compare-runs/$T	
	foreach prop (COM-hist_Run1.dat dihed_a2-hist_Run1.dat dihed_b2-hist_Run1.dat dihed_c1-hist_Run1.dat dihed_c2-hist_Run1.dat dihed_d1-hist_Run1.dat dihed_d2-hist_Run1.dat dihed_e1-hist_Run1.dat dihed_g1-hist_Run1.dat dihed_g2-hist_Run1.dat dihed_z1-hist_Run1.dat distO2O4-hist_Run1.dat rmsd-hist_Run1.dat)
		perl ../../../scripts/avg-err-2dataset.perl ./run1/analysis/conf-temp/$T/$prop ./run2/analysis/conf-temp/$T/$prop ./compare-runs/$T/$prop
	end
end
perl ../../../scripts/avg-err-2dataset.perl ./run1/analysis/stack-temp/temperature_dG_.dat ./run2/analysis/stack-temp/temperature_dG_.dat ./compare-runs/temperature_dG_.dat
perl ../../../scripts/avg-err-2dataset.perl ./run1/analysis/stack-temp/temperature_stacked-Percentage.dat ./run2/analysis/stack-temp/temperature_stacked-Percentage.dat ./compare-runs/temperature_stacked-Percentage_.dat

cd compare-runs/
mkdir kde-pca-298
cd kde-pca-298

cat << EOF > pt-kde-pca.in
parm ../../run1/build/full.topo.hmr [traj]

autoimage origin

trajin ../../run1/traj.1.01 remdtraj remdtrajtemp 298.41 trajnames ../../run1/traj.1.02,../../run1/traj.1.03,../../run1/traj.1.04,../../run1/traj.1.05,../../run1/traj.1.06,../../run1/traj.1.07,../../run1/traj.1.08,../../run1/traj.1.09,../../run1/traj.1.10,../../run1/traj.1.11,../../run1/traj.1.12,../../run1/traj.1.13,../../run1/traj.1.14,../../run1/traj.1.15,../../run1/traj.1.16,../../run1/traj.1.17,../../run1/traj.1.18,

trajin ../../run2/traj.1.01 remdtraj remdtrajtemp 298.41 trajnames ../../run2/traj.1.02,../../run2/traj.1.03,../../run2/traj.1.04,../../run2/traj.1.05,../../run2/traj.1.06,../../run2/traj.1.07,../../run2/traj.1.08,../../run2/traj.1.09,../../run2/traj.1.10,../../run2/traj.1.11,../../run2/traj.1.12,../../run2/traj.1.13,../../run2/traj.1.14,../../run2/traj.1.15,../../run2/traj.1.16,../../run2/traj.1.17,../../run2/traj.1.18,


rmsd :1,2&!@H= first

average avg.rst restart
createcrd crd1
run

reference avg.rst [avg]

crdaction crd1 rms ref [avg] :1-2&!@H=

crdaction crd1 matrix covar :1-2&!@H= name DinucCovar

runanalysis diagmatrix DinucCovar out evecs.dat vecs 20

crdaction crd1 projection T1 modes evecs.dat beg 1 end 10 :1-2&!@H= crdframes 1,50000 out T1.dat
crdaction crd1 projection T2 modes evecs.dat beg 1 end 10 :1-2&!@H= crdframes 50001,100000 out T2.dat
kde T1:1 kldiv T2:1 klout KL-PC.agr bins 400 name TREMD-1
kde T1:2 kldiv T2:2 klout KL-PC.agr bins 400 name TREMD-2
kde T1:3 kldiv T2:3 klout KL-PC.agr bins 400 name TREMD-3
kde T1:4 kldiv T2:4 klout KL-PC.agr bins 400 name TREMD-4
kde T1:5 kldiv T2:5 klout KL-PC.agr bins 400 name TREMD-5
kde T1:6 kldiv T2:6 klout KL-PC.agr bins 400 name TREMD-6
kde T1:7 kldiv T2:7 klout KL-PC.agr bins 400 name TREMD-7
kde T1:8 kldiv T2:8 klout KL-PC.agr bins 400 name TREMD-8
kde T1:9 kldiv T2:9 klout KL-PC.agr bins 400 name TREMD-9
kde T1:10 kldiv T2:10 klout KL-PC.agr bins 400 name TREMD-10

kde T1:1 out kde-PC.agr bins 400 name KDE1-1
kde T2:1 out kde-PC.agr bins 400 name KDE1-2

hist T1:1,*,*,*,200 out pca.hist.agr normint name PC1-RUN1
hist T1:2,*,*,*,200 out pca.hist.agr normint name PC2-RUN1
hist T1:3,*,*,*,200 out pca.hist.agr normint name PC3-RUN1
hist T1:4,*,*,*,200 out pca.hist.agr normint name PC4-RUN1
hist T1:5,*,*,*,200 out pca.hist.agr normint name PC5-RUN1

hist T2:1,*,*,*,200 out pca.hist.agr normint name PC1-RUN2
hist T2:2,*,*,*,200 out pca.hist.agr normint name PC2-RUN2
hist T2:3,*,*,*,200 out pca.hist.agr normint name PC3-RUN2
hist T2:4,*,*,*,200 out pca.hist.agr normint name PC4-RUN2
hist T2:5,*,*,*,200 out pca.hist.agr normint name PC5-RUN2
run
modes eigenval name evecs.dat out modes-fraction.dat
EOF

cat << EOF > cpptraj.runit
#!/bin/tcsh
#SBATCH -A cheatham-lp
#SBATCH -p cheatham-lp
#SBATCH -J kde
#SBATCH -o logtest.o%j
#SBATCH -N 1
#SBATCH -n 8
#SBATCH -t 05:00:00


ource /uufs/chpc.utah.edu/common/home/u0827715/Amber/GIT/amber-lonepeak/amber.csh
setenv AMBERHOME /uufs/chpc.utah.edu/common/home/u0827715/Amber/GIT/amber-lonepeak

cpptraj.OMP -i pt-kde-pca.in > pt-kde-pca.log
EOF

qsub cpptraj.runit

cd ../
