library(bio3d)
library(ncdf)
source("dmat_funs.R")
pdb <- read.pdb("1XCK_chainALM_noWAT_noH.pdb")


t <- seq(1,500, 1)
sim116 <- NULL
prefix <- "50ns_noWAT_500frames_noH_chain_"
prefix116 <- "/net/gulrotkake/slars/groel_md/1XCK/116_1XCK_apo/results/traj_trimer/"

for ( i in c(1,2,3,4,5,7) ) {
  tmptrj <- read.ncdf(paste(prefix116, prefix, i , ".nc", sep=""))
  sim116$trj = rbind(sim116$trj, tmptrj)
}

t <- seq(1,500, 1)
sim129 <- NULL
prefix <- "50ns_noWAT_500frames_noATP_noH_chain_"
prefix129 <- "/net/gulrotkake/slars/groel_md/1XCK/129_1XCK_MGATP/results/traj_trimer/"
for ( i in c(1,2,3,4,5,7) ) {
  tmptrj <- read.ncdf(paste(prefix129, prefix, i , ".nc", sep=""))
  sim129$trj$atp = rbind(sim129$trj$atp, tmptrj[t,])
}

t <- seq(1,500, 1)
sim171 <- NULL
prefix <- "50ns_noWAT_500frames_noATP_noH_chain_"
prefix171 <- "/net/lutefisk/slars/groel_md/1XCK_rhodanese/171_1XCK_rhodanese_ATP/results/traj_trimer"
for ( i in c(1,2,3,4,5,7) ) {
  tmptrj <- read.ncdf(paste(prefix129, prefix, i , ".nc", sep=""))
  sim171$trj$atp = rbind(sim171$trj$atp, tmptrj[t,])
}



dists.116 <- c()
dists.129 <- c()
dists.171 <- c()

##nrow(diff.table1) ) {
mask="433,1477" 
inds.tmp <- atom.select(pdb, resno=mask)

dm.inds( rbind(pdb$xyz,pdb$xyz), pdb, inds.tmp)

d1 <- dm.inds( sim116$trj, pdb, inds.tmp)
d2 <- dm.inds( sim129$trj$atp, pdb, inds.tmp)
d3 <- dm.inds( sim171$trj$atp, pdb, inds.tmp)

pdf('hist.pdf', w=12, h=5)
par(mfcol=c(1,3))
hist(d1, xlim=c(2,15), breaks=20)
hist(d2, xlim=c(2,15), breaks=20)
hist(d3, xlim=c(2,15), breaks=20)
dev.off()


dists.116.mat <- matrix(dists.116, nrow=nrow(diff.table1), byrow=T)
dists.129.mat <- matrix(dists.129, nrow=nrow(diff.table1), byrow=T)


