1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Chemical Entities as R Objects • chents</title>
<script src="deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet">
<script src="deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet">
<link href="deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet">
<script src="deps/headroom-0.11.0/headroom.min.js"></script><script src="deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="deps/search-1.0.0/fuse.min.js"></script><script src="deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="pkgdown.js"></script><meta property="og:title" content="Chemical Entities as R Objects">
<meta name="description" content="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.">
<meta property="og:description" content="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.">
</head>
<body>
<a href="#main" class="visually-hidden-focusable">Skip to contents</a>
<nav class="navbar navbar-expand-lg fixed-top bg-light" data-bs-theme="light" aria-label="Site navigation"><div class="container">
<a class="navbar-brand me-2" href="index.html">chents</a>
<small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">0.4.1</small>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar" class="collapse navbar-collapse ms-3">
<ul class="navbar-nav me-auto">
<li class="nav-item"><a class="nav-link" href="reference/index.html">Reference</a></li>
<li class="nav-item"><a class="nav-link" href="news/index.html">Changelog</a></li>
</ul>
<ul class="navbar-nav">
<li class="nav-item"><form class="form-inline" role="search">
<input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="search.json">
</form></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/jranke/chents/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li>
</ul>
</div>
</div>
</nav><div class="container template-home">
<div class="row">
<main id="main" class="col-md-9"><div class="section level1">
<div class="page-header"><h1 id="chents">chents<a class="anchor" aria-label="anchor" href="#chents"></a>
</h1></div>
<p><a href="https://pkgdown.jrwb.de/chents/"><img src="https://img.shields.io/badge/docs-jrwb.de-blue.svg" alt="Online documentation"></a> <a href="https://jranke.r-universe.dev/chents" class="external-link"><img src="https://jranke.r-universe.dev/badges/chents" alt="R-Universe status"></a> <a href="https://pkgdown.jrwb.de/chents/coverage/coverage.html"><img src="https://img.shields.io/badge/coverage-jrwb.de-blue.svg" alt="Code coverage"></a></p>
<p>When working with data on chemical substances, we often need a reliable link between the data and the chemical identity of the substances. The R package <strong>chents</strong> provides a way to define an R object corresponding to a chemically defined substances (“chemical entity”) and to collect related information.</p>
<p>When first defining a chemical entity, some chemical information is retrieved from the <a href="https://pubchem.ncbi.nlm.nih.gov/" class="external-link">PubChem</a> website using the <a href="https://docs.ropensci.org/webchem/" class="external-link">webchem</a> package.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://pkgdown.jrwb.de/chents/">chents</a></span><span class="op">)</span></span>
<span><span class="va">caffeine</span> <span class="op"><-</span> <span class="va"><a href="reference/chent.html">chent</a></span><span class="op">$</span><span class="fu">new</span><span class="op">(</span><span class="st">"Caffeine"</span><span class="op">)</span></span>
<span><span class="co">#> Querying PubChem for name Caffeine ...</span></span>
<span><span class="co">#> Get chemical information from RDKit using PubChem SMILES</span></span>
<span><span class="co">#> CN1C=NC2=C1C(=O)N(C(=O)N2C)C</span></span></code></pre></div>
<p>If Python and <a href="https://rdkit.org" class="external-link">RDKit</a> (> 2015.03) are installed and configured for use with the <a href="https://rstudio.github.io/reticulate/" class="external-link">reticulate</a> package, some additional chemical information including a 2D graph are computed.</p>
<p>The print method gives an overview of the information that was collected.</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">caffeine</span><span class="op">)</span></span>
<span><span class="co">#> <chent></span></span>
<span><span class="co">#> Identifier $identifier Caffeine </span></span>
<span><span class="co">#> InChI Key $inchikey RYYVLZVUVIJVGH-UHFFFAOYSA-N </span></span>
<span><span class="co">#> SMILES string $smiles:</span></span>
<span><span class="co">#> PubChem </span></span>
<span><span class="co">#> "CN1C=NC2=C1C(=O)N(C(=O)N2C)C" </span></span>
<span><span class="co">#> Molecular weight $mw: 194.2 </span></span>
<span><span class="co">#> PubChem synonyms (up to 10):</span></span>
<span><span class="co">#> [1] "caffeine" "58-08-2" </span></span>
<span><span class="co">#> [3] "Guaranine" "1,3,7-Trimethylxanthine"</span></span>
<span><span class="co">#> [5] "Methyltheobromine" "Theine" </span></span>
<span><span class="co">#> [7] "Thein" "Cafeina" </span></span>
<span><span class="co">#> [9] "Caffein" "Cafipel"</span></span></code></pre></div>
<p>There is a very simple plotting method for the chemical structure.</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">caffeine</span><span class="op">)</span></span></code></pre></div>
<p><img src="reference/figures/README-unnamed-chunk-4-1.png"><!-- --></p>
<p>If you have a so-called ISO common name of a pesticide active ingredient, you can use the ‘pai’ class derived from the ‘chent’ class, which starts with querying the <a href="http://www.bcpcpesticidecompendium.org/" class="external-link">BCPC compendium</a> first.</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">delta</span> <span class="op"><-</span> <span class="va"><a href="reference/pai.html">pai</a></span><span class="op">$</span><span class="fu">new</span><span class="op">(</span><span class="st">"Deltamethrin"</span><span class="op">)</span></span>
<span><span class="co">#> Querying BCPC for Deltamethrin ...</span></span>
<span><span class="co">#> Querying PubChem for inchikey OWZREIFADZCYQD-NSHGMRRFSA-N ...</span></span>
<span><span class="co">#> Get chemical information from RDKit using PubChem SMILES</span></span>
<span><span class="co">#> CC1([C@H]([C@H]1C(=O)O[C@H](C#N)C2=CC(=CC=C2)OC3=CC=CC=C3)C=C(Br)Br)C</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">delta</span><span class="op">)</span></span></code></pre></div>
<p><img src="reference/figures/README-unnamed-chunk-5-1.png"><!-- --></p>
<p>Additional information can be read from a local .yaml file. This information can be leveraged e.g. by the <a href="https://pkgdown.jrwb.de/pfm/reference/PEC_soil.html" class="external-link">PEC_soil</a> function of the ‘pfm’ package. However, this functionality is to be superseded by a dedicated package, defining data for the environmental risk assessment on chemicals, in particular on active ingredients of plant protection products.</p>
<div class="section level2">
<h2 id="installation">Installation<a class="anchor" aria-label="anchor" href="#installation"></a>
</h2>
<p>You can conveniently install chents from the repository kindly made available by the R-Universe project:</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html" class="external-link">install.packages</a></span><span class="op">(</span><span class="st">"chents"</span>,</span>
<span> repos <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"https://jranke.r-universe.dev"</span>, <span class="st">"https://cran.r-project.org"</span><span class="op">)</span><span class="op">)</span></span></code></pre></div>
<p>In order to profit from the chemoinformatics, you need to install RDKit and its python bindings. On a Debian type Linux distribution, just use</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" tabindex="-1"></a><span class="fu">sudo</span> apt install python3-rdkit</span></code></pre></div>
<p>If you use this package on Windows or MacOS, I would be happy to include installation instructions here if you share them with me, e.g. via a Pull Request.</p>
</div>
<div class="section level2">
<h2 id="configuration-of-the-python-version-to-use">Configuration of the Python version to use<a class="anchor" aria-label="anchor" href="#configuration-of-the-python-version-to-use"></a>
</h2>
<p>On Debian type Linux distributions, you can use the following line in your global or project specific <code>.Rprofile</code> file to tell the <code>reticulate</code> package to use the system Python version that will find the RDKit installed in the system location.</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/Sys.setenv.html" class="external-link">Sys.setenv</a></span><span class="op">(</span>RETICULATE_PYTHON<span class="op">=</span><span class="st">"/usr/bin/python3"</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="using-r6-classes">Using R6 classes<a class="anchor" aria-label="anchor" href="#using-r6-classes"></a>
</h2>
<p>Note that the <code>chent</code> objects defined by this package are <a href="https://r6.r-lib.org/articles/Introduction.html" class="external-link">R6</a> classes. Therefore, if you think you make a copy by assigning them to a new name, the objects will still be connected, because only the reference is copied. For example, you can create a molecule without retrieving data from PubChem</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">but</span> <span class="op"><-</span> <span class="va"><a href="reference/chent.html">chent</a></span><span class="op">$</span><span class="fu">new</span><span class="op">(</span><span class="st">"Butane"</span>, smiles <span class="op">=</span> <span class="st">"CCCC"</span>, pubchem <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span><span class="co">#> Get chemical information from RDKit using user SMILES</span></span>
<span><span class="co">#> CCCC</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">but</span><span class="op">)</span></span>
<span><span class="co">#> <chent></span></span>
<span><span class="co">#> Identifier $identifier Butane </span></span>
<span><span class="co">#> InChI Key $inchikey NA </span></span>
<span><span class="co">#> SMILES string $smiles:</span></span>
<span><span class="co">#> user </span></span>
<span><span class="co">#> "CCCC" </span></span>
<span><span class="co">#> Molecular weight $mw: 58.1</span></span></code></pre></div>
<p>If you then assign a new name and add PubChem information to the object with the new name, the information will also be added to the original <code>chent</code> object:</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">but_pubchem</span> <span class="op"><-</span> <span class="va">but</span></span>
<span><span class="va">but_pubchem</span><span class="op">$</span><span class="fu">try_pubchem</span><span class="op">(</span><span class="op">)</span></span>
<span><span class="co">#> Querying PubChem for name Butane ...</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/print.html" class="external-link">print</a></span><span class="op">(</span><span class="va">but</span><span class="op">)</span></span>
<span><span class="co">#> <chent></span></span>
<span><span class="co">#> Identifier $identifier Butane </span></span>
<span><span class="co">#> InChI Key $inchikey IJDNQMDRQITEOD-UHFFFAOYSA-N </span></span>
<span><span class="co">#> SMILES string $smiles:</span></span>
<span><span class="co">#> user PubChem </span></span>
<span><span class="co">#> "CCCC" "CCCC" </span></span>
<span><span class="co">#> Molecular weight $mw: 58.1 </span></span>
<span><span class="co">#> PubChem synonyms (up to 10):</span></span>
<span><span class="co">#> [1] "BUTANE" "n-Butane" "106-97-8" </span></span>
<span><span class="co">#> [4] "Diethyl" "Methylethylmethane" "Butanen" </span></span>
<span><span class="co">#> [7] "Butani" "Butyl hydride" "HC 600" </span></span>
<span><span class="co">#> [10] "A 21 (lowing agent)"</span></span></code></pre></div>
<p>You can create a derived, independent object using the <code>clone()</code> method that will not be affected by operations on the original object:</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">but_new</span> <span class="op"><-</span> <span class="va"><a href="reference/chent.html">chent</a></span><span class="op">$</span><span class="fu">new</span><span class="op">(</span><span class="st">"Butane"</span>, smiles <span class="op">=</span> <span class="st">"CCCC"</span>, pubchem <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span><span class="co">#> Get chemical information from RDKit using user SMILES</span></span>
<span><span class="co">#> CCCC</span></span>
<span><span class="va">but_clone</span> <span class="op"><-</span> <span class="va">but_new</span><span class="op">$</span><span class="fu">clone</span><span class="op">(</span><span class="op">)</span></span>
<span><span class="va">but_new</span><span class="op">$</span><span class="fu">try_pubchem</span><span class="op">(</span><span class="op">)</span></span>
<span><span class="co">#> Querying PubChem for name Butane ...</span></span>
<span><span class="va">but_clone</span></span>
<span><span class="co">#> <chent></span></span>
<span><span class="co">#> Identifier $identifier Butane </span></span>
<span><span class="co">#> InChI Key $inchikey NA </span></span>
<span><span class="co">#> SMILES string $smiles:</span></span>
<span><span class="co">#> user </span></span>
<span><span class="co">#> "CCCC" </span></span>
<span><span class="co">#> Molecular weight $mw: 58.1</span></span></code></pre></div>
</div>
</div>
</main><aside class="col-md-3"><div class="links">
<h2 data-toc-skip>Links</h2>
<ul class="list-unstyled">
<li><a href="https://github.com/jranke/chents/" class="external-link">Browse source code</a></li>
</ul>
</div>
<div class="license">
<h2 data-toc-skip>License</h2>
<ul class="list-unstyled">
<li>GPL</li>
</ul>
</div>
<div class="citation">
<h2 data-toc-skip>Citation</h2>
<ul class="list-unstyled">
<li><a href="authors.html#citation">Citing chents</a></li>
</ul>
</div>
<div class="developers">
<h2 data-toc-skip>Developers</h2>
<ul class="list-unstyled">
<li>Johannes Ranke <br><small class="roles"> Author, maintainer, copyright holder </small> </li>
</ul>
</div>
</aside>
</div>
<footer><div class="pkgdown-footer-left">
<p>Developed by Johannes Ranke.</p>
</div>
<div class="pkgdown-footer-right">
<p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.2.0.</p>
</div>
</footer>
</div>
</body>
</html>
|