aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorRanke Johannes <johannes.ranke@agroscope.admin.ch>2024-06-20 14:57:23 +0200
committerRanke Johannes <johannes.ranke@agroscope.admin.ch>2024-06-20 14:57:23 +0200
commit81dd5ed73a48ba811304ab9211d501b973eb640c (patch)
tree1903f61b5e0f91b7e10acb42e3631d24674ce6e2 /R
parent463787e347b00bf4076027ffbcb69166bcc6646d (diff)
Fix rdkit availability, prefer user/isomeric SMILES
In cases that the user specifies an isomeric SMILES, we want to use that with rdkit. If the user does not specify a SMILES, we prefer the isomeric one from PubChem over the canonical one, where stereochemistry is not defined.
Diffstat (limited to 'R')
-rw-r--r--R/chent.R11
-rw-r--r--R/zzz.R2
2 files changed, 9 insertions, 4 deletions
diff --git a/R/chent.R b/R/chent.R
index 4375305..aee95f0 100644
--- a/R/chent.R
+++ b/R/chent.R
@@ -118,9 +118,14 @@ chent <- R6Class("chent",
if (is.null(self$smiles)) {
message("RDKit would need a SMILES code")
} else {
+ available_smiles <- names(self$smiles)
+ smiles_preference <- c("user", "PubChem_Isomeric", "PubChem_Canonical")
+ smiles_preferred_i <- min(match(available_smiles, smiles_preference))
+ smiles_preferred <- smiles_preference[smiles_preferred_i]
+
message("Trying to get chemical information from RDKit using ",
- names(self$smiles)[1], " SMILES\n",
- self$smiles[1])
+ smiles_preferred, " SMILES\n",
+ self$smiles[smiles_preferred])
self$get_rdkit(template = template)
self$mw <- self$rdkit$mw
attr(self$mw, "source") <- "rdkit"
@@ -196,7 +201,7 @@ chent <- R6Class("chent",
#' Get chemical information from RDKit if available
#' @param template Optional template specified as a SMILES code
get_rdkit = function(template = NULL) {
- if(!rdkit_available) {
+ if (!rdkit_available) {
stop("RDKit is not available")
}
self$rdkit <- list()
diff --git a/R/zzz.R b/R/zzz.R
index f18e559..fc39fbf 100644
--- a/R/zzz.R
+++ b/R/zzz.R
@@ -1,6 +1,6 @@
.onLoad = function(libname, pkgname) {
conf <- reticulate::py_discover_config("rdkit")
- rdkit_available <- conf$available
+ rdkit_available <- reticulate::py_module_available("rdkit")
rdkit_module <- try(
reticulate::import("rdkit"),
silent = TRUE)

Contact - Imprint