library(bio3d)
library(car)
source("confplot_funs.R")

pdb <- read.pdb("1XCK_apo_dimer_noH.pdb")


load("pca_dimers.RData")
id <- substr(basename(pdbs$id), 1, 7)

col <- seq(1, length(id))
col = 0
t.inds <- c(grep("1XCK", id), grep("2NWC", id))
atp.trans <- c(grep("1SX4", id), grep("1AON", id), grep("1SVT", id), grep("1PF9", id))
atp.cis <- c(grep("1SX3", id), grep("1KP8", id))
r.inds <- grep("2C7E", id)

col[t.inds] = "red"
col[atp.trans] = "orange"
col[atp.cis] = "green"
col[r.inds] = "blue"

                    
cex.axis=1.1
cex.lab=1.1
cex=0.9
at.offset=3
ylim=c(-35,23); xlim=c(-42,50);
mtext.cex=0.68
line=.4


load("projected.RData")
load("projected_1XCK-rhod.RData")



hl.ind <-  c(grep("1XCK_AB", id), grep("2C7E_AB", id), 
             grep("1SX3_AB", id), grep("1AON_MN", id) )
hl.col <- c("red", "blue", "green", "orange")


xlim=c(-60,255)
ylim=c(-50,90)



pdf("conformerplot_individuals.pdf", w=12, h=10)
par(mfrow=c(5,6), mgp=c(2,.9,0), mar=c(3,3,2,1))

labels <- c("A-B", "B-C", "C-D", "D-E", "E-F", "F-G")

for ( i in 1:6 ) {
  inds <- seq(1, 1500,1) + (1500* (i-1))
  
  conf.plot( sim116$cis$proj[inds,], pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim116$cis$proj[inds,1]), lty=2, col="grey60")
  abline(h=mean(sim116$cis$proj[inds,2]), lty=2, col="grey60")
  mtext("(A) GroEL (cis)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
  mtext(paste("Chains", labels[i]), side=3, line=-1, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
  
}

labels <- c("H-I", "I-J", "J-K", "K-L", "L-M", "M-N")
for ( i in 1:6 ) {
  inds <- seq(1, 1500,1) + (1500* (i-1))
  
  conf.plot( sim116$trans$proj[inds,], pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim116$trans$proj[inds,1]), lty=2, col="grey60")
  abline(h=mean(sim116$trans$proj[inds,2]), lty=2, col="grey60")
  mtext("(B) GroEL (trans)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
  mtext(paste("Chains", labels[i]), side=3, line=-1, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
}

labels <- c("A-B", "B-C", "C-D", "D-E", "E-F", "F-G")
for ( i in 1:6 ) {
  inds <- seq(1, 1500,1) + (1500* (i-1))
 
conf.plot( sim129$cis$proj[inds,], pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim129$cis$proj[inds,1]), lty=2, col="grey60")
  abline(h=mean(sim129$cis$proj[inds,2]), lty=2, col="grey60")
  label=expression(paste("(C) GroEL ATP"[7], " (cis)"))
  mtext(label, side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
  mtext(paste("Chains", labels[i]), side=3, line=-1, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
}


for ( i in 1:6 ) {
  inds <- seq(1, 1000,1) + (1000* (i-1))
 
conf.plot( sim129b$cis$proj[inds,], pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim129b$cis$proj[inds,1]), lty=2, col="grey60")
  abline(h=mean(sim129b$cis$proj[inds,2]), lty=2, col="grey60")
label=expression(paste("(D) GroEL ATP"[7], " (cis)"))
mtext(label, side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
  #mtext("350 K", side=3, line=-1,  cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
  mtext(paste("Chains", labels[i], "350K"), side=3, line=-1, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
}



for ( i in 1:6 ) {
  inds <- seq(1, 1500,1) + (1500* (i-1))
 
conf.plot(sim171b$cis$proj[inds,], pc.xray, mtext="", xlim=xlim, ylim=ylim,
          hl.ind=hl.ind, hl.col=hl.col)
abline(v=mean(sim171b$cis$proj[inds,1]), lty=2, col="grey60")
abline(h=mean(sim171b$cis$proj[inds,2]), lty=2, col="grey60")
label=expression(paste("(E) GroEL"[Rhod], " ATP"[7], " (cis)"))
mtext(label, side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
  mtext(paste("Chains", labels[i]), side=3, line=-1, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
}

dev.off()



