-
Notifications
You must be signed in to change notification settings - Fork 0
/
WritePDB.R
97 lines (81 loc) · 3.1 KB
/
WritePDB.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Writing AMBER compliant PDB structure complexes
# This code works ONLY if your structure files (PDB) are in the working directory AND the filename is a a single capital letter [A-Z] with the extension .pdb
library("Rpdb")
library("gWidgets")
options(guiToolkit="RGtk2")
readpdb <- function(x){
read.pdb(x, ATOM = TRUE, HETATM = TRUE, CRYST1 = TRUE, CONECT = TRUE, TITLE = TRUE, REMARK = TRUE, MODEL = 1)
}
savepdb <- function(...){
write.pdb(pdbs, file = "temp.pdb")
x <- readLines("temp.pdb")
cleanpdb <- x[grep(x, pattern = "[A-Z]{3}\\s{1}[A]{1}\\s{2}")]
cleanpdb <- append(cleanpdb, "TER")
chains <- chains[-1]
for (i in chains){
cleanpdb <- append(cleanpdb, x[grep(x, pattern = paste0("[A-Z]{3}\\s{1}[", i, "]{1}\\s{2}"))])
cleanpdb <- append(cleanpdb, "TER")
}
cleanpdb <- append(cleanpdb, "END")
writeLines(cleanpdb, "complex.pdb")
file.remove("temp.pdb")
}
chainname <- function(x){
for (i in 1:length(x)){
x[[i]][["atoms"]][["chainid"]] <- paste("", LETTERS, sep = "")[i]
}
return(x)
}
buttonpress <- function(h, ...){
rgl.clear(type = "all")
struc1 <- Txyz(pdbs[[1]], x = svalue(xval), y = svalue(yval), z = svalue(zval))
print(svalue(zval))
struc2 <- merge(struc1, pdbs[[2]])
pdbs <- pdbs[-2]
pdbs[[1]] <- struc2
pdbs <<- pdbs
}
redraw <- function(...){
a <- Txyz(pdbs[[1]], x = svalue(xval))
aggr <- merge(a, pdbs[[2]])
return(c(rgl.clear(type = "all"), visualize(aggr, add = TRUE)))
}
redraw_y <- function(...){
a <- Txyz(pdbs[[1]], y = svalue(yval))
aggr <- merge(a, pdbs[[2]])
return(c(rgl.clear(type = "all"), visualize(aggr, add = TRUE)))
}
redraw_z <- function(...){
a <- Txyz(pdbs[[1]], z = svalue(zval))
aggr <- merge(a, pdbs[[2]])
return(c(rgl.clear(type = "all"), visualize(aggr, add = TRUE)))
}
z_view <- function(...){
return(view3d(theta = 0, phi = 0))
}
x_view <- function(...){
return(view3d(theta = 90, phi = 0))
}
y_view <- function(...){
return(view3d(theta = 0, phi = 90))
}
fils <- list.files(path = ".", pattern = "[A-Z]{1}.pdb")
chains <- paste("", LETTERS, sep = "")[1:length(fils)]
pdbs <- lapply(fils, readpdb)
pdbs <- chainname(pdbs)
window <- gwindow("Translation", visible=FALSE)
group <- ggroup(horizontal = FALSE, cont = window, expand = TRUE)
label <- glabel("x-axis", cont = group)
xval <- gslider(from=-100, to=100, by=5, value=0, expand=TRUE, container = group, handler = redraw)
label <- glabel("y-axis", cont = group)
yval <- gslider(from=-100, to=100, by=5, value=0, expand=TRUE, container = group, handler = redraw_y)
label <- glabel("z-axis", cont = group)
zval <- gslider(from=-100, to=100, by=5, value=0, expand=TRUE, container = group, handler = redraw_z)
z_set <- gbutton(text = "Z view", border = TRUE, container = group, handler = z_view)
x_set <- gbutton(text = "X view", border = TRUE, container = group, handler = x_view)
y_set <- gbutton(text = "Y view", border = TRUE, container = group, handler = y_view)
merger <- gaction("Merge", handler=buttonpress)
mergebtn <- gbutton(action=merger, cont=group)
saves <- gaction("Save", handler=savepdb)
mergebtn <- gbutton(action=saves, cont=group)
visible(window) <- TRUE