| Title: | Chemical Entities as R Objects |
|---|---|
| Description: | Utilities for dealing with chemical entities and associated data as R objects. If Python and 'RDKit' (> 2015.03) are installed and configured for use with 'reticulate', some basic chemoinformatics functions like the calculation of molecular weight and plotting of chemical structures in R graphics are available. |
| Authors: | Johannes Ranke [aut, cre, cph] |
| Maintainer: | Johannes Ranke <[email protected]> |
| License: | GPL |
| Version: | 0.4.1 |
| Built: | 2026-05-18 09:14:05 UTC |
| Source: | https://github.com/jranke/chents |
The class is initialised with an identifier. Chemical information is retrieved from the internet. Additionally, it can be generated using RDKit if RDKit and its python bindings are installed.
An R6::R6Class generator object
identifier(character(1))
The identifier that was used to initiate the object, with attribute 'source'
inchikey(character(1))
InChI Key, with attribute 'source'
smiles(character())
SMILES code(s), with attribute 'source'
mw(numeric(1))
Molecular weight, with attribute 'source'
pubchem(list())
List of information retrieved from PubChem
rdkitList of information obtained with RDKit
mol<rdkit.Chem.rdchem.Mol> object
svgSVG code
PictureGraph as a grImport::Picture object obtained using the grImport package
Pict_font_sizeFont size as extracted from the intermediate PostScript file
pdf_heightHeight of the MediaBox in the pdf after cropping
p0Vapour pressure in Pa
cwsatWater solubility in mg/L
PUFPlant uptake factor
chyamlList of information obtained from a YAML file
TPsList of transformation products as chent objects
transformationsData frame of observed transformations
soil_degradationDataframe of modelling DT50 values
soil_ffDataframe of formation fractions
soil_sorptionDataframe of soil sorption data
new()
Creates a new instance of this R6 class.
chent$new(
identifier,
smiles = NULL,
inchikey = NULL,
pubchem = TRUE,
pubchem_from = c("name", "smiles", "inchikey"),
rdkit = TRUE,
template = NULL,
chyaml = FALSE
)identifierIdentifier to be stored in the object
smilesOptional user provided SMILES code
inchikeyOptional user provided InChI Key
pubchemShould an attempt be made to retrieve chemical information from PubChem via the webchem package?
pubchem_fromPossibility to select the argument that is used to query pubchem
rdkitShould an attempt be made to retrieve chemical information from a local rdkit installation via python and the reticulate package?
templateAn optional SMILES code to be used as template for RDKit
chyamlShould we look for a identifier.yaml file in the working directory?
try_pubchem()
Try to get chemical information from PubChem
chent$try_pubchem(query = self$identifier, from = "name")
get_pubchem()
Get chemical information from PubChem for a known PubChem CID
chent$get_pubchem(pubchem_cid)
pubchem_cidCID
get_rdkit()
Get chemical information from RDKit if available
chent$get_rdkit(template = NULL)
templateAn optional SMILES code to be used as template for RDKit
get_chyaml()
Obtain information from a YAML file
chent$get_chyaml(
repo = c("wd", "local", "web"),
chyaml = paste0(URLencode(self$identifier), ".yaml")
)repoShould the file be looked for in the current working
directory, a local git repository under ~/git/chyaml, or from
the web (not implemented).
chyamlThe filename to be looked for
add_p0()
Add a vapour pressure
chent$add_p0(p0, T = NA, source = NA, page = NA, remark = "")
p0The vapour pressure in Pa
TTemperature
sourceAn acronym specifying the source of the information
pageThe page from which the information was taken
remarkA remark
add_cwsat()
Add a water solubility
chent$add_cwsat(cwsat, T = NA, pH = NA, source = NA, page = NA, remark = "")
cwsatThe water solubility in mg/L
TTemperature
pHpH value
sourceAn acronym specifying the source of the information
pageThe page from which the information was taken
remarkA remark
add_PUF()
Add a plant uptake factor
chent$add_PUF( PUF = 0, source = "focus_generic_gw_2014", page = 41, remark = "Conservative default value" )
PUFThe plant uptake factor, a number between 0 and 1
sourceAn acronym specifying the source of the information
pageThe page from which the information was taken
remarkA remark
add_TP()
Add a transformation product to the internal list
chent$add_TP(x, smiles = NULL, pubchem = FALSE)
add_transformation()
Add a line in the internal dataframe holding observed transformations
chent$add_transformation( study_type, TP_identifier, max_occurrence, remark = "", source = NA, pages = NA )
study_typeA characterisation of the study type
TP_identifierAn identifier of one of the transformation products
in self$TPs
max_occurrenceThe maximum observed occurrence of the transformation product, expressed as a fraction of the amount that would result from stochiometric transformation
remarkA remark
sourceAn acronym specifying the source of the information
pagesThe pages from which the information was taken
add_soil_degradation()
Add a line in the internal dataframe holding modelling DT50 values
chent$add_soil_degradation( soils, DT50_mod, DT50_mod_ref, type = NA, country = NA, pH_orig = NA, pH_medium = NA, pH_H2O = NA, perc_OC = NA, temperature = NA, moisture = NA, category = "lab", formulation = NA, model = NA, chi2 = NA, remark = "", source, page = NA )
soilsNames of the soils
DT50_modThe modelling DT50 in the sense of regulatory pesticide fate modelling
DT50_mod_refThe normalised modelling DT50 in the sense of regulatory pesticide fate modelling
typeThe soil type
countryThe country (mainly for field studies)
pH_origThe pH stated in the study
pH_mediumThe medium in which this pH was measured
pH_H2OThe pH extrapolated to pure water
perc_OCThe percentage of organic carbon in the soil
temperatureThe temperature during the study in degrees Celsius
moistureThe moisture during the study
categoryIs it a laboratory ('lab') or field study ('field')
formulationName of the formulation applied, if it was not the technical active ingredient
modelThe degradation model used for deriving DT50_mod
chi2The relative error as defined in FOCUS kinetics
remarkA remark
sourceAn acronym specifying the source of the information
pageThe page from which the information was taken
add_soil_ff()
Add one or more formation fractions for degradation in soil
chent$add_soil_ff(target, soils, ff = 1, remark = "", source, page = NA)
targetThe identifier(s) of the transformation product
soilsThe soil name(s) in which the transformation was observed
ffThe formation fraction(s)
remarkA remark
sourceAn acronym specifying the source of the information
pageThe page from which the information was taken
add_soil_sorption()
Add soil sorption data
chent$add_soil_sorption( soils, Kf, Kfoc, N, type = NA, pH_orig = NA, pH_medium = NA, pH_H2O = NA, perc_OC = NA, perc_clay = NA, CEC = NA, remark = "", source, page = NA )
soilsNames of the soils
KfThe sorption constant in L/kg, either linear (then N is 1)
or according to Freundlich
KfocThe constant from above, normalised to soil organic carbon
NThe Freundlich exponent
typeThe soil type
pH_origThe pH stated in the study
pH_mediumThe medium in which this pH was measured
pH_H2OThe pH extrapolated to pure water
perc_OCThe percentage of organic carbon in the soil
perc_clayThe percentage of clay in the soil
CECThe cation exchange capacity
remarkA remark
sourceAn acronym specifying the source of the information
pageThe page from which the information was taken
pdf()
Write a PDF image of the structure
chent$pdf( file = paste0(self$identifier, ".pdf"), dir = "structures/pdf", template = NULL )
fileThe file to write to
dirThe directory to write the file to
templateAn optional SMILES code to be used as template for RDKit
png()
Write a PNG image of the structure
chent$png( file = paste0(self$identifier, ".png"), dir = "structures/png", antialias = "gray" )
fileThe file to write to
dirThe directory to write the file to
antialiasPassed to png
emf()
Write an EMF image of the structure using emf
chent$emf(file = paste0(self$identifier, ".emf"), dir = "structures/emf")
fileThe file to write to
dirThe directory to write the file to
clone()
The objects of this class are cloneable with this method.
chent$clone(deep = FALSE)
deepWhether to make a deep clone.
# Don't run examples per default, as PubChem may be unavailable ## Not run: caffeine <- chent$new("caffeine") print(caffeine) if (!is.null(caffeine$Picture)) { plot(caffeine) } oct <- chent$new("1-octanol", smiles = "CCCCCCCCO", pubchem = FALSE) print(oct) ## End(Not run)# Don't run examples per default, as PubChem may be unavailable ## Not run: caffeine <- chent$new("caffeine") print(caffeine) if (!is.null(caffeine$Picture)) { plot(caffeine) } oct <- chent$new("1-octanol", smiles = "CCCCCCCCO", pubchem = FALSE) print(oct) ## End(Not run)
Draw SVG graph from a chent object using RDKit
draw_svg.chent( x, width = 300, height = 150, filename = paste0(names(x$identifier), ".svg"), subdir = "svg" )draw_svg.chent( x, width = 300, height = 150, filename = paste0(names(x$identifier), ".svg"), subdir = "svg" )
x |
The chent object to be plotted |
width |
The desired width in pixels |
height |
The desired height in pixels |
filename |
The filename |
subdir |
The path to which the file should be written |
This class is derived from chent. It makes it easy to create a chent from the ISO common name of a pesticide active ingredient, and additionally stores the ISO name as well as the complete result of querying the BCPC compendium using bcpc_query.
An R6::R6Class generator object
chents::chent -> pai
isoISO common name of the active ingredient according to ISO 1750
bcpcInformation retrieved from the BCPC compendium available online at <pesticidecompendium.bcpc.org>
chents::chent$add_PUF()chents::chent$add_TP()chents::chent$add_cwsat()chents::chent$add_p0()chents::chent$add_soil_degradation()chents::chent$add_soil_ff()chents::chent$add_soil_sorption()chents::chent$add_transformation()chents::chent$emf()chents::chent$get_chyaml()chents::chent$get_pubchem()chents::chent$get_rdkit()chents::chent$pdf()chents::chent$png()chents::chent$try_pubchem()new()
Create a new pai object
pai$new( iso, identifier = iso, smiles = NULL, inchikey = NULL, bcpc = TRUE, pubchem = TRUE, pubchem_from = "auto", rdkit = TRUE, template = NULL, chyaml = FALSE )
isoThe ISO common name to be used in the query of the BCPC compendium
identifierAlternative identifier used for querying pubchem
smilesOptional user provided SMILES code
inchikeyOptional user provided InChI Key
bcpcShould the BCPC compendium be queried?
pubchemShould an attempt be made to retrieve chemical information from PubChem via the webchem package?
pubchem_fromPossibility to select the argument that is used to query pubchem
rdkitShould an attempt be made to retrieve chemical information from a local rdkit installation via python and the reticulate package?
templateAn optional SMILES code to be used as template for RDKit
chyamlShould we look for a identifier.yaml file in the working
clone()
The objects of this class are cloneable with this method.
pai$clone(deep = FALSE)
deepWhether to make a deep clone.
# Don't run examples per default, as PubChem may be unavailable ## Not run: atr <- pai$new("atrazine") print(atr) if (!is.null(atr$Picture)) { plot(atr) } # We can also define pais that are not found on the BCPC site decanol <- pai$new("1-Decanol") print(decanol) ## End(Not run)# Don't run examples per default, as PubChem may be unavailable ## Not run: atr <- pai$new("atrazine") print(atr) if (!is.null(atr$Picture)) { plot(atr) } # We can also define pais that are not found on the BCPC site decanol <- pai$new("1-Decanol") print(decanol) ## End(Not run)
Plot method for chent objects
## S3 method for class 'chent' plot(x, ...)## S3 method for class 'chent' plot(x, ...)
x |
The chent object to be plotted |
... |
Further arguments passed to grImport::grid.picture |
# Don't run examples per default, as PubChem may be unavailable ## Not run: caffeine <- chent$new("caffeine") print(caffeine) if (!is.null(caffeine$Picture)) { plot(caffeine) } ## End(Not run)# Don't run examples per default, as PubChem may be unavailable ## Not run: caffeine <- chent$new("caffeine") print(caffeine) if (!is.null(caffeine$Picture)) { plot(caffeine) } ## End(Not run)
Contains basic information about the active ingredients in the product
An R6::R6Class generator object.
nameThe name of the product
aisA list of active ingredients
concentrationsThe concentration of the ais
concentration_unitsDefaults to g/L
densityThe density of the product
density_unitsDefaults to g/L
new()
Creates a new instance of this R6 class.
ppp$new( name, ..., concentrations, concentration_units = "g/L", density = 1000, density_units = "g/L" )
nameThe name of the product
...Identifiers of the active ingredients
concentrationsConcentrations of the active ingredients
concentration_unitsDefaults to g/L
densityThe density
density_unitsDefaults to g/L
clone()
The objects of this class are cloneable with this method.
ppp$clone(deep = FALSE)
deepWhether to make a deep clone.
Printing method for chent objects
## S3 method for class 'chent' print(x, ...)## S3 method for class 'chent' print(x, ...)
x |
The chent object to be printed |
... |
Further arguments for compatibility with the S3 method |
Printing method for pai objects (pesticidal active ingredients)
## S3 method for class 'pai' print(x, ...)## S3 method for class 'pai' print(x, ...)
x |
The chent object to be printed |
... |
Further arguments for compatibility with the S3 method |
Printing method for ppp objects (plant protection products)
## S3 method for class 'ppp' print(x, ...)## S3 method for class 'ppp' print(x, ...)
x |
The chent object to be printed |
... |
Further arguments for compatibility with the S3 method |