From f43f7f9dec2337c8db62f0ddb167986af59a033e Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 13 Mar 2026 13:53:10 +0100 Subject: Explain consequence of chent objects being R6 objects --- docs/index.html | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) (limited to 'docs/index.html') diff --git a/docs/index.html b/docs/index.html index ec6ba42..aa6d358 100644 --- a/docs/index.html +++ b/docs/index.html @@ -54,8 +54,8 @@

When first defining a chemical entity, some chemical information is retrieved from the PubChem website using the webchem package.

 library(chents)
-caffeine <- chent$new("caffeine")
-#> Querying PubChem for name caffeine ...
+caffeine <- chent$new("Caffeine")
+#> Querying PubChem for name Caffeine ...
 #> Get chemical information from RDKit using PubChem SMILES
 #> CN1C=NC2=C1C(=O)N(C(=O)N2C)C

If Python and RDKit (> 2015.03) are installed and configured for use with the reticulate package, some additional chemical information including a 2D graph are computed.

@@ -63,7 +63,7 @@
 print(caffeine)
 #> <chent>
-#> Identifier $identifier caffeine 
+#> Identifier $identifier Caffeine 
 #> InChI Key $inchikey RYYVLZVUVIJVGH-UHFFFAOYSA-N 
 #> SMILES string $smiles:
 #>                        PubChem 
@@ -81,8 +81,8 @@
 

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 BCPC compendium first.

-delta <- pai$new("deltamethrin")
-#> Querying BCPC for deltamethrin ...
+delta <- pai$new("Deltamethrin")
+#> Querying BCPC for Deltamethrin ...
 #> Querying PubChem for inchikey OWZREIFADZCYQD-NSHGMRRFSA-N ...
 #> Get chemical information from RDKit using PubChem SMILES
 #> 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
@@ -107,6 +107,57 @@
 
 Sys.setenv(RETICULATE_PYTHON="/usr/bin/python3")
+
+

Using R6 classes +

+

Note that the chent objects defined by this package are R6 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

+
+but <- chent$new("Butane", smiles = "CCCC", pubchem = FALSE)
+#> Get chemical information from RDKit using user SMILES
+#> CCCC
+print(but)
+#> <chent>
+#> Identifier $identifier Butane 
+#> InChI Key $inchikey NA 
+#> SMILES string $smiles:
+#>   user 
+#> "CCCC" 
+#> Molecular weight $mw: 58.1
+

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 chent object:

+
+but_pubchem <- but
+but_pubchem$try_pubchem()
+#> Querying PubChem for name Butane ...
+print(but)
+#> <chent>
+#> Identifier $identifier Butane 
+#> InChI Key $inchikey IJDNQMDRQITEOD-UHFFFAOYSA-N 
+#> SMILES string $smiles:
+#>    user PubChem 
+#>  "CCCC"  "CCCC" 
+#> Molecular weight $mw: 58.1 
+#> PubChem synonyms (up to 10):
+#>  [1] "BUTANE"              "n-Butane"            "106-97-8"           
+#>  [4] "Diethyl"             "Methylethylmethane"  "Butanen"            
+#>  [7] "Butani"              "Butyl hydride"       "HC 600"             
+#> [10] "A 21 (lowing agent)"
+

You can create a derived, independent object using the clone() method that will not be affectd by operations on the original object:

+
+but_new <- chent$new("Butane", smiles = "CCCC", pubchem = FALSE)
+#> Get chemical information from RDKit using user SMILES
+#> CCCC
+but_clone <- but_new$clone()
+but_new$try_pubchem()
+#> Querying PubChem for name Butane ...
+but_clone
+#> <chent>
+#> Identifier $identifier Butane 
+#> InChI Key $inchikey NA 
+#> SMILES string $smiles:
+#>   user 
+#> "CCCC" 
+#> Molecular weight $mw: 58.1
+