aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2016-10-15 01:01:21 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2016-10-15 01:01:21 +0200
commit363046c178398593dea33712ba281fb5556541a6 (patch)
treeb15fcb693d884c478889318ade2c77f0569c8f81
parent9d7f213fbed4baa5d0bafdb8ea6c584cccb1d73f (diff)
Meta infos for pdf and self$Picture, png function
-rw-r--r--ChangeLog12
-rw-r--r--GNUmakefile2
-rw-r--r--R/chent.R41
-rw-r--r--man/chent.Rd4
4 files changed, 53 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 735092e..9f85d81 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+commit e85f61000c139492ec6497aa3c6206a66b54d783
+Author: Johannes Ranke <jranke@uni-bremen.de>
+Date: 2016-10-14 15:24:43 +0200
+
+ Better handling of ambiguous names and "source"s
+
+commit 70e16d8ca726ed9d894bd219018838ce4b0f22a0
+Author: Johannes Ranke <jranke@uni-bremen.de>
+Date: 2016-10-13 20:13:27 +0200
+
+ chents for windows!
+
commit 6cfe5fbd827ca37f24134e8356e8144520ee1265
Author: Johannes Ranke <jranke@uni-bremen.de>
Date: 2016-10-13 17:28:14 +0200
diff --git a/GNUmakefile b/GNUmakefile
index dfea847..52adf68 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -54,7 +54,7 @@ test: build
quickcheck: build
@echo "Running check..."
- "$(R_HOME)/bin/R" CMD check $(TGZ)
+ "$(R_HOME)/bin/R" CMD check $(TGZ) --no-tests
@echo "DONE."
check: build
diff --git a/R/chent.R b/R/chent.R
index 6606992..bbb46b3 100644
--- a/R/chent.R
+++ b/R/chent.R
@@ -36,6 +36,8 @@
#' @field rdkit List of information obtained with RDKit, if installed and
#' configured for use with PythonInR
#' @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
#' @field chyaml List of information obtained from a YAML file
#' @field degradation List of degradation endpoints
#' @example inst/examples/octanol.R
@@ -51,6 +53,8 @@ chent <- R6Class("chent",
pubchem = NULL,
rdkit = NULL,
Picture = NULL,
+ Pict_font_size = NULL,
+ pdf_height = NULL,
chyaml = NULL,
degradation = NULL,
initialize = function(identifier, smiles = NULL, smiles_source = 'user',
@@ -110,7 +114,12 @@ chent <- R6Class("chent",
}
},
get_pubchem = function(pubchem_cid) {
- self$pubchem = as.list(webchem::pc_prop(pubchem_cid, from = "cid"))
+ self$pubchem = as.list(webchem::pc_prop(pubchem_cid, from = "cid",
+ properties = c("MolecularFormula", "MolecularWeight",
+ "CanonicalSMILES", "IsomericSMILES",
+ "InChI", "InChIKey", "IUPACName",
+ "XLogP", "TPSA", "Complexity", "Charge",
+ "HBondDonorCount", "HBondAcceptorCount")))
self$pubchem$synonyms = webchem::pc_synonyms(pubchem_cid, from ="cid")[[1]]
self$smiles["PubChem_Canonical"] <- self$pubchem$CanonicalSMILES
@@ -171,6 +180,10 @@ chent <- R6Class("chent",
xmlfile <- tempfile(fileext = ".xml")
cmd <- paste0("Draw.MolToFile(mol, '", psfile, "')")
PythonInR::pyExec(cmd)
+ 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)
PostScriptTrace(psfile, outfilename = xmlfile)
unlink(paste0("capture", basename(psfile)))
self$Picture <- readPicture(xmlfile)
@@ -263,11 +276,11 @@ chent <- R6Class("chent",
if (!exists(to, self$TPs)) stop(to, " was not found in TPs")
self$ff[i, ] <- c(from, to, ff, comment, pages)
},
- pdf = function(file = paste0(self$identifier, ".pdf"), dir = "structures") {
- if (!dir.exists("structures")) {
+ pdf = function(file = paste0(self$identifier, ".pdf"), dir = "structures/pdf") {
+ if (!dir.exists(dir)) {
message("Directory '", dir, "' does not exist")
- message("Creating directory '", dir, "'")
- dir.create(dir)
+ message("Trying to create directory '", dir, "'")
+ dir.create(dir, recursive = TRUE)
}
path = file.path(dir, file)
message("Creating file '", path, "'")
@@ -276,6 +289,24 @@ chent <- R6Class("chent",
dev.off()
message("Cropping file '", path, "' using pdfcrop")
system(paste("pdfcrop --margin 10", path, path, "> /dev/null"))
+
+ # Get the height of the MediaBox
+ head <- readLines(path, n = 20, skipNul = TRUE)
+ m_line <- suppressWarnings(grep("MediaBox", head, value = TRUE))
+ self$pdf_height <- as.numeric(gsub("/MediaBox \\[.* (.*)\\]", "\\1", m_line))
+ },
+ png = function(file = paste0(self$identifier, ".png"), dir = "structures/png",
+ antialias = 'gray') {
+ if (!dir.exists(dir)) {
+ message("Directory '", dir, "' does not exist")
+ message("Trying to create directory '", dir, "'")
+ dir.create(dir, recursive = TRUE)
+ }
+ path = file.path(dir, file)
+ message("Creating file '", path, "'")
+ png(path, antialias = antialias)
+ plot(self)
+ dev.off()
}
)
)
diff --git a/man/chent.Rd b/man/chent.Rd
index e2a0c77..62d6e01 100644
--- a/man/chent.Rd
+++ b/man/chent.Rd
@@ -31,6 +31,10 @@ configured for use with PythonInR}
\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}
+
+\item{\code{pdf_height}}{Height of the MediaBox in the pdf after cropping}
+
\item{\code{chyaml}}{List of information obtained from a YAML file}
\item{\code{degradation}}{List of degradation endpoints}

Contact - Imprint