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


pdb.closed <- read.pdb("1XCK_apo_dimer_noH.pdb")
ca.inds <- atom.select(pdb.closed, "calpha")


#adapted.core <- c(core$c1A.xyz-3, core$c1A.xyz-1575)
adapted.core <- core.md
      
### THIS IS FOR 20-50 ns only ###
sim171b <- NULL
prefix171b <- "/net/lutefisk/slars/groel_md/1XCK_rhodanese/171_1XCK_rhodanese_ATP/results/traj_dimers/"

prefix <- "20-50ns_noWAT_1500frames_noATP_noH_chain_"

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

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

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

## 1XCK RHOD

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

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


#sim171$xyzfit <- NULL
sim171b$xyzfit <- NULL
save(sim171b, file="projected_1XCK-rhod.RData")






