Skip to content

Instantly share code, notes, and snippets.

@kdaily
Forked from Vessy/3D_net.R
Last active August 29, 2015 13:59
Show Gist options
  • Save kdaily/11002140 to your computer and use it in GitHub Desktop.
Save kdaily/11002140 to your computer and use it in GitHub Desktop.
library("igraph")
rm(list = ls())
##########################################################################
# Read data
dataSet <- read.table("http://www.vesnam.com/Rblog/wp-content/uploads/2013/07/lesmis.txt",
header = FALSE, sep = "\t")
# Create a graph. Use simplify to ensure that there are no duplicated edges or self loops
gD <- simplify(graph.data.frame(dataSet, directed=FALSE))
# Calculate degree for all nodes
degAll <- degree(gD, v = V(gD), mode = "all")
coord3D <- layout.fruchterman.reingold(gD, dim = 3)
nType <- 1
write2mol2 <- function(x, ...) write.table(x, sep="\t", row.names = FALSE,
col.names = FALSE, quote = FALSE, ...)
write2mol2("@<TRIPOS>MOLECULE", file="3D_lesmis.mol2")
write2mol2("Les Miserables", file="3D_lesmis.mol2", append = TRUE)
write2mol2(data.frame(vcount(gD), ecount(gD), nType), file="3D_lesmis.mol2", append=TRUE)
write2mol2("SMALL", file = "3D_lesmis.mol2", append = TRUE)
write2mol2("NO_CHARGES\n", file = "3D_lesmis.mol2", append = TRUE)
write2mol2("@<TRIPOS>ATOM", file = "3D_lesmis.mol2", append = TRUE)
isIn2 <- factor(cut(degAll, breaks = c(0, 1, 2, 5, 10, 15, Inf)),
labels=c("He", "Na", "O", "Au", "P", "Cl"))
hlpL <- data.frame(i=1:vcount(gD),
name=V(gD)$name,
coord3D[, 1:3],
isIn2,
isType=1,
0.0)
write2mol2(hlpL, file="3D_lesmis.mol2", append=TRUE)
write2mol2("@<TRIPOS>BOND", file = "3D_lesmis.mol2", append = TRUE)
isType <- 1
hlpL <- data.frame(i=1:ecount(gD),
get.edges(gD, 1:ecount(gD)),
isType=1)
write2mol2(hlpL, file = "3D_lesmis.mol2", append = TRUE)
################################
# Visualization adjustments using jmol scripts
#
# _He; spacefill 0.2; wireframe 10; color bonds blue; font label 10;
# select _Na; spacefill 0.4; wireframe 12; color bonds purple; font label 12;
# select _O; spacefill 0.6; wireframe 14; color bonds red; font label 14;
# select _Au; spacefill 0.8; wireframe 16; color bonds yellow; font label 16;
# select _P; spacefill 1.0; wireframe 18; color bonds orange; font label 18;
# select _Cl; spacefill 1.5; wireframe 20; color bonds green; font label 20;
#
# select _He; label hide;
# select _Na; label hide;
# select _O; label hide
################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment