-
Notifications
You must be signed in to change notification settings - Fork 1
/
3dPlotTest.r
32 lines (27 loc) · 1.1 KB
/
3dPlotTest.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
#install.packages("plotly")
library(plotly)
#install.packages("Rpdb")
library(Rpdb)
library(datasets)
#Read PDB File
#filename<-readline(prompt = "Enter File Name: ")
filename<-"3ptb.pdb"
#filename<-"4x0l.pdb"
textMat<-read.pdb(filename, ATOM = TRUE, HETATM = TRUE)
#Make Datasets
d <- data.frame(textMat$atoms$x1,textMat$atoms$x2,textMat$atoms$x3)
#Testing for Cluster Size 5
c <- kmeans(d,5)
d2 <- data.frame(textMat$atoms$x1,textMat$atoms$x2,textMat$atoms$x3,c$cluster)
plot_ly(d2, x = ~textMat.atoms.x1, y = ~textMat.atoms.x2, z = ~textMat.atoms.x3, color = ~c.cluster)
#WSS to determine optimum clusters
maxClusters <- 50
wss <- numeric(maxClusters)
#Squaring WSS values to get sharper changes
for (i in 2:maxClusters){wss[i] <- sum(kmeans(d,i)$withinss)*sum(kmeans(d,i)$withinss)}
plot(1:maxClusters, wss, type = "b")
optClusters <- 15
#Plot K-Means for Optimum Clusters
c <- kmeans(d,optClusters)
d2 <- data.frame(textMat$atoms$x1,textMat$atoms$x2,textMat$atoms$x3,c$cluster)
plot_ly(d2, x = ~textMat.atoms.x1, y = ~textMat.atoms.x2, z = ~textMat.atoms.x3, color = ~c.cluster)