From bfa20a8c262580e38d30cfa95e75d1b01b568d07 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 19 Feb 2019 23:19:31 +0100 Subject: Use rsvg instead of grConvert as grConvert is not on CRAN --- ChangeLog | 2 +- DESCRIPTION | 5 ++--- NAMESPACE | 1 + R/chent.R | 39 ++++++++++++++++++-------------------- docs/authors.html | 2 +- docs/index.html | 2 +- docs/reference/chent.html | 4 ++-- docs/reference/draw_svg.chent.html | 2 +- docs/reference/index.html | 2 +- docs/reference/pai.html | 2 +- docs/reference/plot.chent.html | 2 +- docs/reference/pp.html | 2 +- docs/reference/print.chent.html | 2 +- docs/reference/print.pai.html | 2 +- 14 files changed, 33 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31a1fcc..31c099d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -commit 433f66e88d96aaf745116b97d7fdaa6ce2abde30 +commit a7e2c2008699b590325ccd848562881251676faf Author: Johannes Ranke Date: 2019-02-19 20:46:18 +0100 diff --git a/DESCRIPTION b/DESCRIPTION index f45a6c3..451e6c5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: chents Type: Package Title: Chemical Entities as R Objects -Version: 0.2-6 +Version: 0.2-7 Date: 2019-02-19 Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"), email = "jranke@uni-bremen.de")) @@ -15,13 +15,12 @@ Imports: webchem, R6, yaml, + rsvg, grImport Suggests: knitr, testthat, PythonInR, - grConvert -Remotes: sjp/grConvert License: GPL LazyLoad: yes LazyData: yes diff --git a/NAMESPACE b/NAMESPACE index 987a658..e6ced73 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ importFrom(R6,R6Class) importFrom(grImport,PostScriptTrace) importFrom(grImport,grid.picture) importFrom(grImport,readPicture) +importFrom(rsvg,rsvg_ps) importFrom(utils,head) importFrom(webchem,cid_compinfo) importFrom(webchem,get_cid) diff --git a/R/chent.R b/R/chent.R index c80cf06..f6a8b09 100644 --- a/R/chent.R +++ b/R/chent.R @@ -28,6 +28,7 @@ #' @importFrom webchem get_cid cid_compinfo #' @importFrom grImport PostScriptTrace readPicture #' @importFrom yaml yaml.load_file +#' @importFrom rsvg rsvg_ps #' @field identifier The identifier that was used to initiate the object, with attribute 'source' #' @field inchikey InChI Key, with attribute 'source' #' @field smiles SMILES code, with attribute 'source' @@ -193,26 +194,22 @@ chent <- R6Class("chent", PythonInR::pyExec("d2d.DrawMolecule(mol)") PythonInR::pyExec("d2d.FinishDrawing()") self$svg <- PythonInR::pyGet("d2d.GetDrawingText()") - - if (!requireNamespace("grConvert")) { - stop("grConvert is not available, self$Picture will not be created") - } else { - # Convert to PostScript, remembering size properties - svgfile <- tempfile(fileext = ".svg") - writeLines(self$svg, svgfile) - psfile <- tempfile(fileext = ".ps") - 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)) - } + svgfile <- tempfile(fileext = ".svg") + psfile <- tempfile(fileext = ".ps") + writeLines(self$svg, svgfile) + rsvg::rsvg_ps(svgfile, psfile) + + # Get size properties useful for plotting + 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"), chyaml = paste0(URLencode(self$identifier), ".yaml")) { @@ -610,7 +607,7 @@ rdkit_available <- function() PythonInR::pyConnect() } sink(tempfile()) - try_rdkit <- try(PythonInR::pyImport("Chem", from = "rdkit"), + try_rdkit <- try(PythonInR::pyImport("Chem", from = "rdkit"), silent = TRUE) sink() if (inherits(try_rdkit, "try-error")) { diff --git a/docs/authors.html b/docs/authors.html index 5ac526d..3274797 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -60,7 +60,7 @@ chents - 0.2.6 + 0.2.7 diff --git a/docs/index.html b/docs/index.html index f463fe0..6d69e3f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -35,7 +35,7 @@ chents - 0.2.6 + 0.2.7 diff --git a/docs/reference/chent.html b/docs/reference/chent.html index 369b0a0..3d0928c 100644 --- a/docs/reference/chent.html +++ b/docs/reference/chent.html @@ -65,7 +65,7 @@ python bindings are installed and configured for use with PythonInR." /> chents - 0.2.6 + 0.2.7 @@ -149,7 +149,7 @@ configured for use with PythonInR

oct <- chent$new("1-octanol", smiles = "CCCCCCCCO")
#> PubChem:
#> https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/cids/JSON
#> https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/property/MolecularFormula,MolecularWeight,CanonicalSMILES,IsomericSMILES,InChI,InChIKey,IUPACName,XLogP,TPSA,Complexity,Charge,HBondDonorCount,HBondAcceptorCount/JSON
#> https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/cid/synonyms/JSON
#> #> Initialize Python Version 2.7.13 (default, Sep 26 2018, 18:42:22) #> [GCC 6.3.0 20170516]
#> Trying to get chemical information from RDKit using User SMILES -#> CCCCCCCCO
#> Lade nötigen Namensraum: grConvert
#> Did not find chyaml file ./1-octanol.yaml
print(oct)
#> <chent> +#> CCCCCCCCO
#> Did not find chyaml file ./1-octanol.yaml
print(oct)
#> <chent> #> Identifier $identifier 1-octanol #> InChI Key $inchikey KBPLFHHGFOOTCA-UHFFFAOYSA-N #> SMILES string $smiles: diff --git a/docs/reference/draw_svg.chent.html b/docs/reference/draw_svg.chent.html index 54fec7c..582aa0c 100644 --- a/docs/reference/draw_svg.chent.html +++ b/docs/reference/draw_svg.chent.html @@ -63,7 +63,7 @@ chents - 0.2.6 + 0.2.7
diff --git a/docs/reference/index.html b/docs/reference/index.html index e05a1c4..f08563c 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -60,7 +60,7 @@ chents - 0.2.6 + 0.2.7 diff --git a/docs/reference/pai.html b/docs/reference/pai.html index d90bcc9..e240e11 100644 --- a/docs/reference/pai.html +++ b/docs/reference/pai.html @@ -64,7 +64,7 @@ Additional chemical information is retrieved from the internet if available." /> chents - 0.2.6 + 0.2.7 diff --git a/docs/reference/plot.chent.html b/docs/reference/plot.chent.html index 026c25f..fddd2e8 100644 --- a/docs/reference/plot.chent.html +++ b/docs/reference/plot.chent.html @@ -63,7 +63,7 @@ chents - 0.2.6 + 0.2.7 diff --git a/docs/reference/pp.html b/docs/reference/pp.html index 8dbed29..aa660cb 100644 --- a/docs/reference/pp.html +++ b/docs/reference/pp.html @@ -63,7 +63,7 @@ chents - 0.2.6 + 0.2.7 diff --git a/docs/reference/print.chent.html b/docs/reference/print.chent.html index 8ab91bc..8f0dd0d 100644 --- a/docs/reference/print.chent.html +++ b/docs/reference/print.chent.html @@ -63,7 +63,7 @@ chents - 0.2.6 + 0.2.7 diff --git a/docs/reference/print.pai.html b/docs/reference/print.pai.html index 7f8c6f3..add2687 100644 --- a/docs/reference/print.pai.html +++ b/docs/reference/print.pai.html @@ -63,7 +63,7 @@ chents - 0.2.6 + 0.2.7 -- cgit v1.2.1