library(gclus)
library(maptools)
library(bio3d)
source("confplot_funs.R")
load("pca_dimers.RData")

#adapted.core <- c(core$c1A.xyz-3, core$c1A.xyz-1575)
adapted.core <- core.md

pdb.e434k <- read.pdb("3FBH_chainAB_noWAT_noH.amb.pdb.1")
ca.inds.e434k <- atom.select(pdb.e434k, "calpha")

trj.inds <- seq(1, 1500, by=1)

sim191 <- NULL
prefix191 <- "/net/lutefisk/slars/groel_md/1XCK/191_1XCK_E434K/results/traj_dimers/"
prefix <- "20-50ns_noWAT_1500frames_noATP_noH_chain_"

for ( i in 1:6 ) {
  tmptrj <- read.ncdf(paste(prefix191, prefix, i , ".nc", sep=""))
  sim191$xyzfit[[i]] <- fit.xyz(fixed = pdbs$xyz[1,gaps.pos$f.inds],
                                mobile = tmptrj[trj.inds, ca.inds.e434k$xyz],
                                fixed.inds = adapted.core,
                                mobile.inds = adapted.core,
                                full.pdbs = FALSE)
}

for ( i in 8:13 ) {
  tmptrj <- read.ncdf(paste(prefix191, prefix, i , ".nc", sep=""))
  sim191$xyzfit[[i]] <- fit.xyz(fixed = pdbs$xyz[1,gaps.pos$f.inds],
                                mobile = tmptrj[trj.inds, ca.inds.e434k$xyz],
                                fixed.inds = adapted.core,
                                mobile.inds = adapted.core,
                                full.pdbs = FALSE)
}

## E434K
tmptrj <- NULL
for ( i in 1:6 ) {
  tmptrj=rbind(tmptrj, sim191$xyzfit[[i]])
}
sim191$cis$proj <- pca.project(tmptrj, pc.xray)

tmptrj <- NULL
for ( i in 8:13 ) {
  tmptrj=rbind(tmptrj, sim191$xyzfit[[i]])
}
sim191$trans$proj <- pca.project(tmptrj, pc.xray)


sim191$xyzfit <- NULL
save(sim191, file="projected_1XCK-E434K.RData")



