Replies: 4 comments 1 reply
-
Oh yeah, and |
Beta Was this translation helpful? Give feedback.
-
@jranke — meant to tag you in this since you mentioned interest in displaying images |
Beta Was this translation helpful? Give feedback.
-
Thanks @Aariq, this is great! I looked at the webchem functions, I think all functions that generate images have |
Beta Was this translation helpful? Give feedback.
-
Some similar code using library(chents)
library(purrr)
library(tibble)
library(gt)
# Get SMILES from PubChem, internally using webchem,
# and SVG, internally using RDKit
chemicals <- c("caffeine", "vanillin")
chent_list <- map(chemicals, \(x) chent$new(x))
#> PubChem:
#> Trying to get chemical information from RDKit using PubChem_Canonical SMILES
#> CN1C=NC2=C1C(=O)N(C(=O)N2C)C
#> Did not find chyaml file ./caffeine.yaml
#> PubChem:
#> Trying to get chemical information from RDKit using PubChem_Canonical SMILES
#> COC1=C(C=CC(=C1)C=O)O
#> RDKit mw is 152.149
#> mw is 152.15
#> Did not find chyaml file ./vanillin.yaml
# Make a table with name, SMILES and svg
chent_table <- map(chent_list,
\(x) {
tibble(name = x$identifier,
SMILES = x$smiles,
svg = x$svg)
}) |>
list_rbind()
# Show table
print(chent_table)
#> # A tibble: 2 × 3
#> name SMILES svg
#> <chr> <chr> <chr>
#> 1 caffeine CN1C=NC2=C1C(=O)N(C(=O)N2C)C "<?xml version='1.0' encoding='iso-8859…
#> 2 vanillin COC1=C(C=CC(=C1)C=O)O "<?xml version='1.0' encoding='iso-8859…
# Display structure of first element using the chent plot method
plot(chent_list[[1]]) # I was expecting this to work, too, but it does not
gt(chent_table) |>
fmt_markdown(columns = svg)
<style>#brjbnrgaqz table {
font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
#brjbnrgaqz thead, #brjbnrgaqz tbody, #brjbnrgaqz tfoot, #brjbnrgaqz tr, #brjbnrgaqz td, #brjbnrgaqz th { #brjbnrgaqz p { #brjbnrgaqz .gt_table { #brjbnrgaqz .gt_caption { #brjbnrgaqz .gt_title { #brjbnrgaqz .gt_subtitle { #brjbnrgaqz .gt_heading { #brjbnrgaqz .gt_bottom_border { #brjbnrgaqz .gt_col_headings { #brjbnrgaqz .gt_col_heading { #brjbnrgaqz .gt_column_spanner_outer { #brjbnrgaqz .gt_column_spanner_outer:first-child { #brjbnrgaqz .gt_column_spanner_outer:last-child { #brjbnrgaqz .gt_column_spanner { #brjbnrgaqz .gt_spanner_row { #brjbnrgaqz .gt_group_heading { #brjbnrgaqz .gt_empty_group_heading { #brjbnrgaqz .gt_from_md > :first-child { #brjbnrgaqz .gt_from_md > :last-child { #brjbnrgaqz .gt_row { #brjbnrgaqz .gt_stub { #brjbnrgaqz .gt_stub_row_group { #brjbnrgaqz .gt_row_group_first td { #brjbnrgaqz .gt_row_group_first th { #brjbnrgaqz .gt_summary_row { #brjbnrgaqz .gt_first_summary_row { #brjbnrgaqz .gt_first_summary_row.thick { #brjbnrgaqz .gt_last_summary_row { #brjbnrgaqz .gt_grand_summary_row { #brjbnrgaqz .gt_first_grand_summary_row { #brjbnrgaqz .gt_last_grand_summary_row_top { #brjbnrgaqz .gt_striped { #brjbnrgaqz .gt_table_body { #brjbnrgaqz .gt_footnotes { #brjbnrgaqz .gt_footnote { #brjbnrgaqz .gt_sourcenotes { #brjbnrgaqz .gt_sourcenote { #brjbnrgaqz .gt_left { #brjbnrgaqz .gt_center { #brjbnrgaqz .gt_right { #brjbnrgaqz .gt_font_normal { #brjbnrgaqz .gt_font_bold { #brjbnrgaqz .gt_font_italic { #brjbnrgaqz .gt_super { #brjbnrgaqz .gt_footnote_marks { #brjbnrgaqz .gt_asterisk { #brjbnrgaqz .gt_indent_1 { #brjbnrgaqz .gt_indent_2 { #brjbnrgaqz .gt_indent_3 { #brjbnrgaqz .gt_indent_4 { #brjbnrgaqz .gt_indent_5 { #brjbnrgaqz .katex-display { #brjbnrgaqz div.Reactable > div.rt-table > div.rt-thead > div.rt-tr.rt-tr-group-header > div.rt-th-group:after {
Created on 2024-12-09 with reprex v2.1.1 |
Beta Was this translation helpful? Give feedback.
-
Before I forget and I lose this train of thought / link again, I wanted to mention that
gt
can pretty easily display SVG images where the SVG is stored as a character column in a data frame. I can't remember which if anywebchem
functions can return SVGs, but having the SVG as just text in the returned tibble might be a cool option.There's some example code (not using
webchem
) from a workshop I ran here. This is what the output looks like:Beta Was this translation helpful? Give feedback.
All reactions