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

load("xrayPCA_Tstates.RData")
load("projected.RData")

id <- substr(basename(pdbs$id), 1, 6)

hl.ind <-  c(grep("1XCK_A", id), 
             grep("1SX3_A", id), grep("1AON_N", id) )
hl.col <- c("red", "green", "orange")


at.offset=3
mtext.cex=0.75
line=.4
xlim=c(-60,120)
ylim=c(-50,60)
pdf("confplots_EQ_and_Tstates.pdf", w=8, h=4)
par(mfcol=c(2,4), mar=c(3,3,1.5,1), mgp=c(2,1,0))

if (FALSE) {
conf.plot( sim171$cis$proj, pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim129$cis$proj[,1]), lty=2, col="grey60")
  abline(h=mean(sim129$cis$proj[,2]), lty=2, col="grey60")
mtext("(A) WT-ATP (cis)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)

conf.plot( sim171$trans$proj, pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim129$trans$proj[,1]), lty=2, col="grey60")
  abline(h=mean(sim129$trans$proj[,2]), lty=2, col="grey60")
mtext("(B) WT-ATP (trans)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
}

conf.plot( sim129$cis$proj, pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim129$cis$proj[,1]), lty=2, col="grey60")
  abline(h=mean(sim129$cis$proj[,2]), lty=2, col="grey60")
mtext("(A) WT-ATP (cis)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)

conf.plot( sim129$trans$proj, pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim129$trans$proj[,1]), lty=2, col="grey60")
  abline(h=mean(sim129$trans$proj[,2]), lty=2, col="grey60")
mtext("(B) WT-ATP (trans)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)

conf.plot( sim116$cis$proj, pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim116$cis$proj[,1]), lty=2, col="grey60")
  abline(h=mean(sim116$cis$proj[,2]), lty=2, col="grey60")
mtext("(C) WT-APO (cis)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)

conf.plot( sim116$trans$proj, pc.xray, mtext="", xlim=xlim, ylim=ylim,
            hl.ind=hl.ind, hl.col=hl.col)
  abline(v=mean(sim116$trans$proj[,1]), lty=2, col="grey60")
  abline(h=mean(sim116$trans$proj[,2]), lty=2, col="grey60")
 mtext("(D) WT-APO (trans)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)



## EQ_domain
load("../13_xrayPCA_EQ/xrayPCA_EQ.RData")
load("../13_xrayPCA_EQ/projected.RData")


#pdb.closed <- read.pdb("1XCK_chainA_noWAT_noH.pdb")
#inds <- atom.select(pdb, "///500:515///CA/")
#ca.inds <- atom.select(pdb.closed, "calpha")


##e1 <- gaps.pos$f.inds[atom2xyz(6:134)]
#e2 <- gaps.pos$f.inds[atom2xyz(408:518)]
#eq <- c(e1,e2)
id <- substr(basename(pdbs$id), 1, 6)


hl.ind <-  c(grep("1XCK_A", id), grep("1AON_A", id),
             grep("1SX3_A", id), grep("1AON_N", id) )
hl.col <- c("red", "yellow", "green", "orange")

##xlim=c(-20,25); ylim=c(-20,20);
xlim=c(-30,23); ylim=c(-20,15);


if (FALSE) {
conf.plot( d3, pc.xray, mtext="", xlim=xlim, ylim=ylim,
           hl.ind=hl.ind, hl.col=hl.col)
abline(v=mean(d3[,1]), lty=2, col="grey60")
abline(h=mean(d3[,2]), lty=2, col="grey60")
mtext("(E) WT-ATP (cis)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)

conf.plot( d4, pc.xray, mtext="", xlim=xlim, ylim=ylim,
          hl.ind=hl.ind, hl.col=hl.col)
abline(v=mean(d4[,1]), lty=2, col="grey60")
abline(h=mean(d4[,2]), lty=2, col="grey60")
mtext("(F) WT-ATP (trans)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)
}

conf.plot( d5, pc.xray, mtext="", xlim=xlim, ylim=ylim,
          hl.ind=hl.ind, hl.col=hl.col)
abline(v=mean(d5[,1]), lty=2, col="grey60")
abline(h=mean(d5[,2]), lty=2, col="grey60")
mtext("(E) WT-ATP (cis)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)


conf.plot( d6, pc.xray, mtext="", xlim=xlim, ylim=ylim,
          hl.ind=hl.ind, hl.col=hl.col)
abline(v=mean(d6[,1]), lty=2, col="grey60")
abline(h=mean(d6[,2]), lty=2, col="grey60")
mtext("(F) WT-ATP (trans)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)


conf.plot( d1, pc.xray, mtext="", xlim=xlim, ylim=ylim,
          hl.ind=hl.ind, hl.col=hl.col)
abline(v=mean(d1[,1]), lty=2, col="grey60")
abline(h=mean(d1[,2]), lty=2, col="grey60")
mtext("(G) WT-APO (cis)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)


conf.plot( d2, pc.xray, mtext="", xlim=xlim, ylim=ylim,
          hl.ind=hl.ind, hl.col=hl.col)
abline(v=mean(d2[,1]), lty=2, col="grey60")
abline(h=mean(d2[,2]), lty=2, col="grey60")
mtext("(H) WT-APO (trans)", side=3, line=line, cex=mtext.cex, at=xlim[1]-at.offset, adj=0)


dev.off()


