cpanse / uvpd

Ultra HRMS in combination with UVPD fragmentation for enhanced structural identification of organic micropollutants
https://doi.org/10.3390/molecules25184189
0 stars 0 forks source link

R code snippet SMILES to structure for uvpd shiny application #9

Open cpanse opened 5 years ago

cpanse commented 5 years ago

as on the ASMS poster

Screenshot 2019-06-03 at 15 55 15

andreamizzi commented 5 years ago

from rcdk Vignette: https://cran.r-project.org/web/packages/rcdk/vignettes/using-rcdk.html#visualization

Visualization The rcdk package supports 2D rendering of chemical structures. This can be used to view the structure of individual molecules or multiple molecules in a tabular format. It is also possible to view a molecular-data table, where one of the columns is the 2D image and the remainder can contain data associated with the molecules.

Due to Java event handling issues on OS X, depictions are handled using an external helper, which means that depiction generation can be slower on OS X compared to other platforms.

Molecule visualization is performed using the view.molecule.2d function. This handles individual molecules as well as a list of molecules. In the latter case, the depictions are arranged in a grid (with 4 columns by default).

smiles <- c('CCC', 'CCN', 'CCN(C)(C)', 'c1ccccc1Cc1ccccc1', 'C1CCC1CC(CN(C)(C))CC(=O)CC') mols <- parse.smiles(smiles) view.molecule.2d(mols[[1]]) view.molecule.2d(mols) The CDK depiction routines allow for extensive customization. These customizations can be accessed by creating a depictor object using get.depictor, which allows you to specify the size of the depiction, the depiction style (black and white, color on white, etc.), atom annotations (e.g., atom index), whether functional group abbreviations should be used or not and so on.

depictor <- get.depictor(style='cob', abbr='reagents', width=300, height=300) view.molecule.2d(mols[[5]], depictor=depictor) Once you have a depictor object, you can set individual properties using the $ notation. This can be useful if you plan to generate a lot of depictions so that a new depictor is not recreated for each new structure.

depictor <- get.depictor(style='cob', abbr='reagents', width=300, height=300) view.molecule.2d(mols[[5]], depictor=depictor) depictor$setStyle('cow') view.molecule.2d(mols[[5]], depictor=depictor) The method also allows you to highlight substructures using SMARTS. This is useful in highlight commen substructures in a set of molecules

depictor <- get.depictor(style='cob', abbr='reagents', sma='N(C)(C)') view.molecule.2d(mols, depictor=depictor) In many cases, it is useful to view a “molecular spreadsheet”, which is a table of molecular structures along with information (numeric or textual) related to the molecules being viewed. The data is arranged in a spreadsheet like manner, with one of the columns being molecules and the remainder being textual or numeric information.

This can be achieved using the view.table method which takes a list of molecule objects and a data.frame containing the associated data. As expected, the number of rows in the data.frame should equal the length of the molecule list. Note that currently, there is not explicit binding between the rows of the data.frame and the elements of the list containing the molecules. Thus the user should take care that the ordering of the data.frame matches that of the list.

smiles <- c('CCC', 'CCN', 'CCN(C)(C)','c1ccccc1Cc1ccccc1') mols <- parse.smiles(smiles) dframe <- data.frame(x = runif(4), toxicity = factor(c('Toxic', 'Toxic', 'Nontoxic', 'Nontoxic')), solubility = c('yes', 'yes', 'no', 'yes')) view.table(mols, dframe) While the view.molecule.2d function is useful to visualize structures, the depictions can’t be included in other visualizations such as plots. For such use cases, the view.image.2d function produces a raster image that can be included in plots. This function handles one molecule at a time.

img <- view.image.2d(parse.smiles("B(C@HNC(=O)C@HNC(=O)C2=NC=CN=C2)(O)O")[[1]]) plot(1:10, 1:10, pch=19) rasterImage(img, 1,6, 5,10)

Finally, the copy.image.to.clipboard function allows you to copy a depiction to the system clipboard, from where it can be pasted into other applications. This can be more convenient than saving a raster image.