aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2016-12-05 16:00:39 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2016-12-05 18:29:42 +0100
commit762114a5ea6393cc73a09616b937397349c1a259 (patch)
tree788a32aa4e83022074876d831e8e9d5ad7c3ab5e
parent363046c178398593dea33712ba281fb5556541a6 (diff)
Use new rdkit drawing code
This is SVG only, therefore use grConvert to convert to postscript before importing using grImport. SVG size is currently hardcoded.
-rw-r--r--DESCRIPTION13
-rw-r--r--R/chent.R24
-rw-r--r--man/chent.Rd2
3 files changed, 28 insertions, 11 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
index c50c9b4..a753034 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -2,18 +2,19 @@ Package: chents
Type: Package
Title: Chemical Entities as R Objects
Version: 0.2-5
-Date: 2016-10-14
+Date: 2016-12-05
Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"),
email = "jranke@uni-bremen.de"))
Description: Utilities for dealing with chemical entities and associated
- data as R objects. If Python and RDKit are installed and configured for use
- with 'PythonInR', some basic chemoinformatics functions like the calculation
- of molecular weight and plotting of chemical structures in R graphics are
- available.
+ data as R objects. If Python and RDKit (> 2015.03) are installed and
+ configured for use with 'PythonInR', some basic chemoinformatics functions
+ like the calculation of molecular weight and plotting of chemical
+ structures in R graphics are available.
Imports:
webchem,
R6,
grImport,
+ grConvert,
yaml
Suggests:
knitr,
@@ -25,4 +26,4 @@ LazyData: yes
Encoding: UTF-8
VignetteBuilder: knitr
URL: http://cgit.jrwb.de/chents
-RoxygenNote: 5.0.1
+RoxygenNote: 5.0.1.9000
diff --git a/R/chent.R b/R/chent.R
index bbb46b3..b493bc2 100644
--- a/R/chent.R
+++ b/R/chent.R
@@ -35,6 +35,7 @@
#' @field pubchem List of information retreived from PubChem
#' @field rdkit List of information obtained with RDKit, if installed and
#' configured for use with PythonInR
+#' @field svg SVG code
#' @field Picture Graph as a \code{\link{picture}} object obtained using grImport
#' @field Pict_font_size Font size as extracted from the intermediate PostScript file
#' @field pdf_height Height of the MediaBox in the pdf after cropping
@@ -52,6 +53,7 @@ chent <- R6Class("chent",
mw = NULL,
pubchem = NULL,
rdkit = NULL,
+ svg = NULL,
Picture = NULL,
Pict_font_size = NULL,
pdf_height = NULL,
@@ -174,19 +176,31 @@ chent <- R6Class("chent",
}
}
- # Create a grImport Picture
+ # Create an SVG representation
PythonInR::pyImport("Draw", from = "rdkit.Chem")
+ PythonInR::pyImport("rdMolDraw2D", from = "rdkit.Chem.Draw")
+ PythonInR::pyImport("rdDepictor", from = "rdkit.Chem")
+ PythonInR::pyExec("rdDepictor.Compute2DCoords(mol)")
+ PythonInR::pyExec("d2d = rdMolDraw2D.MolDraw2DSVG(200,250)")
+ PythonInR::pyExec("d2d.DrawMolecule(mol)")
+ PythonInR::pyExec("d2d.FinishDrawing()")
+ self$svg <- PythonInR::pyGet("d2d.GetDrawingText()")
+ svgfile <- tempfile(fileext = ".svg")
+ writeLines(self$svg, svgfile)
+
+ # Convert to PostScript, remembering size properties
psfile <- tempfile(fileext = ".ps")
- xmlfile <- tempfile(fileext = ".xml")
- cmd <- paste0("Draw.MolToFile(mol, '", psfile, "')")
- PythonInR::pyExec(cmd)
+ suppressMessages(grConvert::convertPicture(svgfile, psfile))
ps_font_line <- grep("Tm$", readLines(psfile), value = TRUE)[1]
ps_font_size <- gsub(" .*$", "", ps_font_line)
-
self$Pict_font_size = as.numeric(ps_font_size)
+
+ # Read in to create Picture
+ xmlfile <- tempfile(fileext = ".xml")
PostScriptTrace(psfile, outfilename = xmlfile)
unlink(paste0("capture", basename(psfile)))
self$Picture <- readPicture(xmlfile)
+ unlink(c(xmlfile, psfile, svgfile))
}
},
get_chyaml = function(repo = c("wd", "local", "web"),
diff --git a/man/chent.Rd b/man/chent.Rd
index 62d6e01..4957a89 100644
--- a/man/chent.Rd
+++ b/man/chent.Rd
@@ -29,6 +29,8 @@ python bindings are installed and configured for use with PythonInR.
\item{\code{rdkit}}{List of information obtained with RDKit, if installed and
configured for use with PythonInR}
+\item{\code{svg}}{SVG code}
+
\item{\code{Picture}}{Graph as a \code{\link{picture}} object obtained using grImport}
\item{\code{Pict_font_size}}{Font size as extracted from the intermediate PostScript file}

Contact - Imprint