summaryrefslogtreecommitdiff
path: root/docs/reference/chent.md
blob: 40716ce2d270bb282b977060bf11ea6857873a3e (plain) (blame)
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
# An R6 class for chemical entities with associated data

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 [R6::R6Class](https://r6.r-lib.org/reference/R6Class.html) 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()`](https://rdrr.io/r/base/character.html))  
  SMILES code(s), with attribute 'source'

- `mw`:

  (`numeric(1)`)  
  Molecular weight, with attribute 'source'

- `pubchem`:

  ([`list()`](https://rdrr.io/r/base/list.html))  
  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
  [grImport::Picture](https://rdrr.io/pkg/grImport/man/Picture-class.html)
  object obtained using the grImport package

- `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

- `transformations`:

  Data frame of observed transformations

- `soil_degradation`:

  Dataframe of modelling DT50 values

- `soil_ff`:

  Dataframe of formation fractions

- `soil_sorption`:

  Dataframe of soil sorption data

## Methods

### Public methods

- [`chent$new()`](#method-chent-new)

- [`chent$try_pubchem()`](#method-chent-try_pubchem)

- [`chent$get_pubchem()`](#method-chent-get_pubchem)

- [`chent$get_rdkit()`](#method-chent-get_rdkit)

- [`chent$get_chyaml()`](#method-chent-get_chyaml)

- [`chent$add_p0()`](#method-chent-add_p0)

- [`chent$add_cwsat()`](#method-chent-add_cwsat)

- [`chent$add_PUF()`](#method-chent-add_PUF)

- [`chent$add_TP()`](#method-chent-add_TP)

- [`chent$add_transformation()`](#method-chent-add_transformation)

- [`chent$add_soil_degradation()`](#method-chent-add_soil_degradation)

- [`chent$add_soil_ff()`](#method-chent-add_soil_ff)

- [`chent$add_soil_sorption()`](#method-chent-add_soil_sorption)

- [`chent$pdf()`](#method-chent-pdf)

- [`chent$png()`](#method-chent-png)

- [`chent$emf()`](#method-chent-emf)

- [`chent$clone()`](#method-chent-clone)

------------------------------------------------------------------------

### Method `new()`

Creates a new instance of this
[R6](https://r6.r-lib.org/reference/R6Class.html) class.

#### Usage

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

#### 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?

------------------------------------------------------------------------

### Method `try_pubchem()`

Try to get chemical information from PubChem

#### Usage

    chent$try_pubchem(query = self$identifier, from = "name")

#### Arguments

- `query`:

  Query string to be passed to
  [get_cid](https://docs.ropensci.org/webchem/reference/get_cid.html)

- `from`:

  Passed to
  [get_cid](https://docs.ropensci.org/webchem/reference/get_cid.html)

------------------------------------------------------------------------

### Method `get_pubchem()`

Get chemical information from PubChem for a known PubChem CID

#### Usage

    chent$get_pubchem(pubchem_cid)

#### Arguments

- `pubchem_cid`:

  CID

------------------------------------------------------------------------

### Method `get_rdkit()`

Get chemical information from RDKit if available

#### Usage

    chent$get_rdkit(template = NULL)

#### Arguments

- `template`:

  An optional SMILES code to be used as template for RDKit

------------------------------------------------------------------------

### Method `get_chyaml()`

Obtain information from a YAML file

#### 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

------------------------------------------------------------------------

### Method `add_p0()`

Add a vapour pressure

#### 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

------------------------------------------------------------------------

### Method `add_cwsat()`

Add a water solubility

#### 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`:

  pH value

- `source`:

  An acronym specifying the source of the information

- `page`:

  The page from which the information was taken

- `remark`:

  A remark

------------------------------------------------------------------------

### Method `add_PUF()`

Add a plant uptake factor

#### 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()`

Add a transformation product to the internal list

#### Usage

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

#### Arguments

- `x`:

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

- `smiles`:

  Optional user provided SMILES code

- `pubchem`:

  Should chemical information be obtained from PubChem?

------------------------------------------------------------------------

### Method `add_transformation()`

Add a line in the internal dataframe holding observed transformations

#### 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 pages from which the information was taken

------------------------------------------------------------------------

### Method `add_soil_degradation()`

Add a line in the internal dataframe holding modelling DT50 values

#### 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()`

Add one or more formation fractions for degradation in soil

#### 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)

- `remark`:

  A remark

- `source`:

  An acronym specifying the source of the information

- `page`:

  The page from which the information was taken

------------------------------------------------------------------------

### Method `add_soil_sorption()`

Add soil sorption data

#### 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

- `soils`:

  Names of the soils

- `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

- `type`:

  The soil type

- `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

- `perc_clay`:

  The percentage of clay in the soil

- `CEC`:

  The cation exchange capacity

- `remark`:

  A remark

- `source`:

  An acronym specifying the source of the information

- `page`:

  The page from which the information was taken

------------------------------------------------------------------------

### Method [`pdf()`](https://rdrr.io/r/grDevices/pdf.html)

Write a PDF image of the structure

#### 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`:

  An optional SMILES code to be used as template for RDKit

------------------------------------------------------------------------

### Method [`png()`](https://rdrr.io/r/grDevices/png.html)

Write a PNG image of the structure

#### Usage

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

#### Arguments

- `file`:

  The file to write to

- `dir`:

  The directory to write the file to

- `antialias`:

  Passed to [png](https://rdrr.io/r/grDevices/png.html)

------------------------------------------------------------------------

### Method `emf()`

Write an EMF image of the structure using
[emf](https://rdrr.io/pkg/devEMF/man/emf.html)

#### Usage

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

#### Arguments

- `file`:

  The file to write to

- `dir`:

  The directory to write the file 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

``` r
# Don't run examples per default, as PubChem may be unavailable
# \dontrun{
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
print(caffeine)
#> <chent>
#> Identifier $identifier caffeine 
#> InChI Key $inchikey RYYVLZVUVIJVGH-UHFFFAOYSA-N 
#> SMILES string $smiles:
#>                        PubChem 
#> "CN1C=NC2=C1C(=O)N(C(=O)N2C)C" 
#> Molecular weight $mw: 194.2 
#> PubChem synonyms (up to 10):
#>  [1] "caffeine"                "58-08-2"                
#>  [3] "Guaranine"               "1,3,7-Trimethylxanthine"
#>  [5] "Methyltheobromine"       "Theine"                 
#>  [7] "Thein"                   "Cafeina"                
#>  [9] "Caffein"                 "Cafipel"                
if (!is.null(caffeine$Picture)) {
  plot(caffeine)
}

oct <- chent$new("1-octanol", smiles = "CCCCCCCCO", pubchem = FALSE)
#> Get chemical information from RDKit using user SMILES
#> CCCCCCCCO
print(oct)
#> <chent>
#> Identifier $identifier 1-octanol 
#> InChI Key $inchikey NA 
#> SMILES string $smiles:
#>        user 
#> "CCCCCCCCO" 
#> Molecular weight $mw: 130.2 
# }
```

Contact - Imprint