Package 'chents'

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.3.6
Built: 2024-11-03 05:06:28 UTC
Source: https://github.com/jranke/chents

Help Index


An R6 class for chemical entities with associated data

Description

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.

Format

An R6Class generator object

Public fields

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

rdkit

List of information obtained with RDKit

mol

<rdkit.Chem.rdchem.Mol> object

svg

SVG code

Picture

Graph as a picture object obtained using grImport

Pict_font_size

Font size as extracted from the intermediate PostScript file

pdf_height

Height of the MediaBox in the pdf after cropping

p0

Vapour pressure in Pa

cwsat

Water solubility in mg/L

PUF

Plant uptake factor

chyaml

List of information obtained from a YAML file

TPs

List of transformation products as chent objects Add a transformation product to the internal list

transformations

Data frame of observed transformations Add a line in the internal dataframe holding observed transformations

soil_degradation

Dataframe of modelling DT50 values Add a line in the internal dataframe holding modelling DT50 values

soil_ff

Dataframe of formation fractions

soil_sorption

Dataframe of soil sorption data Add soil sorption data

Methods

Public methods


Method new()

Creates a new instance of this R6 class.

Usage
chent$new(
  identifier,
  smiles = NULL,
  inchikey = NULL,
  pubchem = TRUE,
  pubchem_from = c("name", "smiles", "inchikey"),
  rdkit = TRUE,
  template = NULL,
  chyaml = TRUE
)
Arguments
identifier

Identifier to be stored in the object

smiles

Optional user provided SMILES code

inchikey

Optional user provided InChI Key

pubchem

Should an attempt be made to retrieve chemical information from PubChem via the webchem package?

pubchem_from

Possibility to select the argument that is used to query pubchem

rdkit

Should an attempt be made to retrieve chemical information from a local rdkit installation via python and the reticulate package?

template

An optional SMILES code to be used as template for RDKit

chyaml

Should we look for a identifier.yaml file in the working directory? Try to get chemical information from PubChem


Method try_pubchem()

Usage
chent$try_pubchem(query, from = "name")
Arguments
query

Query string to be passed to get_cid

from

Passed to get_cid Get chemical information from PubChem for a known PubChem CID


Method get_pubchem()

Usage
chent$get_pubchem(pubchem_cid)
Arguments
pubchem_cid

CID Get chemical information from RDKit if available


Method get_rdkit()

Usage
chent$get_rdkit(template = NULL)
Arguments
template

Optional template specified as a SMILES code Obtain information from a YAML file


Method get_chyaml()

Usage
chent$get_chyaml(
  repo = c("wd", "local", "web"),
  chyaml = paste0(URLencode(self$identifier), ".yaml")
)
Arguments
repo

Should the file be looked for in the current working directory, a local git repository under ⁠~/git/chyaml⁠, or from the web (not implemented).

chyaml

The filename to be looked for Add a vapour pressure


Method add_p0()

Usage
chent$add_p0(p0, T = NA, source = NA, page = NA, remark = "")
Arguments
p0

The vapour pressure in Pa

T

Temperature

source

An acronym specifying the source of the information

page

The page from which the information was taken

remark

A remark Add a water solubility


Method add_cwsat()

Usage
chent$add_cwsat(cwsat, T = NA, pH = NA, source = NA, page = NA, remark = "")
Arguments
cwsat

The water solubility in mg/L

T

Temperature

pH

The pH value

source

An acronym specifying the source of the information

page

The page from which the information was taken

remark

A remark Add a plant uptake factor


Method add_PUF()

Usage
chent$add_PUF(
  PUF = 0,
  source = "focus_generic_gw_2014",
  page = 41,
  remark = "Conservative default value"
)
Arguments
PUF

The plant uptake factor, a number between 0 and 1

source

An acronym specifying the source of the information

page

The page from which the information was taken

remark

A remark


Method add_TP()

Usage
chent$add_TP(x, smiles = NULL, pubchem = FALSE)
Arguments
x

A chent object, or an identifier to generate a chent object

smiles

A SMILES code for defining a chent object

pubchem

Should chemical information be obtained from PubChem?


Method add_transformation()

Usage
chent$add_transformation(
  study_type,
  TP_identifier,
  max_occurrence,
  remark = "",
  source = NA,
  pages = NA
)
Arguments
study_type

A characterisation of the study type

TP_identifier

An identifier of one of the transformation products in self$TPs

max_occurrence

The maximum observed occurrence of the transformation product, expressed as a fraction of the amount that would result from stochiometric transformation

remark

A remark

source

An acronym specifying the source of the information

pages

The page from which the information was taken


Method add_soil_degradation()

Usage
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
)
Arguments
soils

Names of the soils

DT50_mod

The modelling DT50 in the sense of regulatory pesticide fate modelling

DT50_mod_ref

The normalised modelling DT50 in the sense of regulatory pesticide fate modelling

type

The soil type

country

The country (mainly for field studies)

pH_orig

The pH stated in the study

pH_medium

The medium in which this pH was measured

pH_H2O

The pH extrapolated to pure water

perc_OC

The percentage of organic carbon in the soil

temperature

The temperature during the study in degrees Celsius

moisture

The moisture during the study

category

Is it a laboratory ('lab') or field study ('field')

formulation

Name of the formulation applied, if it was not the technical active ingredient

model

The degradation model used for deriving DT50_mod

chi2

The relative error as defined in FOCUS kinetics

remark

A remark

source

An acronym specifying the source of the information

page

The page from which the information was taken


Method add_soil_ff()

Usage
chent$add_soil_ff(target, soils, ff = 1, remark = "", source, page = NA)
Arguments
target

The identifier(s) of the transformation product

soils

The soil name(s) in which the transformation was observed

ff

The formation fraction(s)


Method add_soil_sorption()

Usage
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
)
Arguments
Kf

The sorption constant in L/kg, either linear (then N is 1) or according to Freundlich

Kfoc

The constant from above, normalised to soil organic carbon

N

The Freundlich exponent

perc_clay

The percentage of clay in the soil

CEC

The cation exchange capacity Write a PDF image of the structure


Method pdf()

Usage
chent$pdf(
  file = paste0(self$identifier, ".pdf"),
  dir = "structures/pdf",
  template = NULL
)
Arguments
file

The file to write to

dir

The directory to write the file to

template

A template expressed as SMILES to use in RDKit Write a PNG image of the structure


Method png()

Usage
chent$png(
  file = paste0(self$identifier, ".png"),
  dir = "structures/png",
  antialias = "gray"
)
Arguments
antialias

Passed to png Write an EMF image of the structure using emf


Method emf()

Usage
chent$emf(file = paste0(self$identifier, ".emf"), dir = "structures/emf")
Arguments
file

The file to write to


Method clone()

The objects of this class are cloneable with this method.

Usage
chent$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

oct <- chent$new("1-octanol", smiles = "CCCCCCCCO", pubchem = FALSE)
print(oct)
if (!is.null(oct$Picture)) {
  plot(oct)
}

caffeine <- chent$new("caffeine")
print(caffeine)
if (!is.null(caffeine$Picture)) {
  plot(caffeine)
}

Draw SVG graph from a chent object using RDKit

Description

Draw SVG graph from a chent object using RDKit

Usage

draw_svg.chent(
  x,
  width = 300,
  height = 150,
  filename = paste0(names(x$identifier), ".svg"),
  subdir = "svg"
)

Arguments

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


An R6 class for pesticidal active ingredients and associated data

Description

The class is initialised with an identifier which is generally an ISO common name. Additional chemical information is retrieved from the internet if available.

Format

An R6Class generator object

Super class

chents::chent -> pai

Public fields

iso

ISO common name of the active ingredient according to ISO 1750

bcpc

Information retrieved from the BCPC compendium available online at <pesticidecompendium.bcpc.org> Creates a new instance of this R6 class.

Methods

Public methods

Inherited methods

Method new()

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.

Usage
pai$new(
  iso,
  identifier = iso,
  smiles = NULL,
  inchikey = NULL,
  bcpc = TRUE,
  pubchem = TRUE,
  pubchem_from = "auto",
  rdkit = TRUE,
  template = NULL,
  chyaml = TRUE
)
Arguments
iso

The ISO common name to be used in the query of the BCPC compendium

identifier

Alternative identifier used for querying pubchem


Method clone()

The objects of this class are cloneable with this method.

Usage
pai$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

# On Travis, we get a certificate validation error,
# likely because the system (xenial) is so old,
# therefore don't run this example on Travis
if (Sys.getenv("TRAVIS") == "") {

atr <- pai$new("atrazine")
print(atr)
if (!is.null(atr$Picture)) {
  plot(atr)
}

}

Plot method for chent objects

Description

Plot method for chent objects

Usage

## S3 method for class 'chent'
plot(x, ...)

Arguments

x

The chent object to be plotted

...

Further arguments passed to grid.picture

Examples

caffeine <- chent$new("caffeine")
print(caffeine)
if (!is.null(caffeine$Picture)) {
  plot(caffeine)
}

R6 class for a plant protection product with at least one active ingredient

Description

Contains basic information about the active ingredients in the product

Format

An R6Class generator object.

Public fields

name

The name of the product

ais

A list of active ingredients

concentrations

The concentration of the ais

concentration_units

Defaults to g/L

density

The density of the product

density_units

Defaults to g/L Creates a new instance of this R6 class.

...

Identifiers of the active ingredients

concentrations

Concentrations of the active ingredients

concentration_units

Defaults to g/L

density

The density

density_units

Defaults to g/L Printing method

Active bindings

...

Identifiers of the active ingredients

Methods

Public methods


Method new()

Usage
ppp$new(
  name,
  ...,
  concentrations,
  concentration_units = "g/L",
  density = 1000,
  density_units = "g/L"
)

Method print()

Usage
ppp$print()

Method clone()

The objects of this class are cloneable with this method.

Usage
ppp$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


Printing method for chent objects

Description

Printing method for chent objects

Usage

## S3 method for class 'chent'
print(x, ...)

Arguments

x

The chent object to be printed

...

Further arguments for compatibility with the S3 method


Printing method for pai objects (pesticidal active ingredients)

Description

Printing method for pai objects (pesticidal active ingredients)

Usage

## S3 method for class 'pai'
print(x, ...)

Arguments

x

The chent object to be printed

...

Further arguments for compatibility with the S3 method