CDK-R / cdkr

Integrating R and the CDK
https://cdk-r.github.io/cdkr/
42 stars 27 forks source link

depiction with kekulise=FALSE #49

Closed schymane closed 7 years ago

schymane commented 7 years ago

The new depiction with kekulise=TRUE looks awesome, but with kekulise=FALSE rather bizarre. In earlier versions this would have been the aromatic delocalised ring representation - any reason for the change? Should I "block" the kekulise=FALSE option? I'd rather keep it in for backwards compatibility...

smiles <- "OS(=O)(=O)c1ccc(cc1)C(CC(=O)O)CC(=O)O" plot.new() plot.window(xlim=c(0,200), ylim=c(0,100)) mol <- parse.smiles(smiles,kekulise=TRUE)[[1]] img <- view.image.2d(mol) rasterImage(img, 0,0, 100,100) mol <- parse.smiles(smiles,kekulise=FALSE)[[1]] img <- view.image.2d(mol) rasterImage(img, 100,0, 200,100)

image

rajarshi commented 7 years ago

I haven't come across this representation, but I'm guessing this is because in absence of kekulization the bond orders are not set properly. As a result the dashed line represents an undefined/unset bond order

In general, keukilze should always be TRUE. The option of FALSE is to force parsing in some cases. An example is imidazole. If represented as an aromatic SMILES with no explicit H, parsing will fail, but you can force it to by setting kekulize=FALSE.

So in short, you should set kekulize=TRUE by default, but if you want to support ill-defined SMILES allow the option of FALSE

library(rcdk)
> is.null(parse.smiles('c1cncn1', kekulise=TRUE)[[1]])
[1] TRUE
> is.null(parse.smiles('c1cncn1', kekulise=FALSE)[[1]])
[1] FALSE
> is.null(parse.smiles('c1c[nH]cn1', kekulise=TRUE)[[1]])
[1] FALSE
schymane commented 7 years ago

Thanks for the clarification - if the SMILES is invalid this can be caught, but can be plotted if you set kekulise=FALSE:

library(rcdk) library(RChemMass) plot.new() plot.window(xlim=c(0,200), ylim=c(0,100)) is.null(parse.smiles('c1cncn1', kekulise=TRUE)[[1]]) [1] TRUE renderSMILES.rcdk("c1cncn1",kekulise=TRUE) [1] "Invalid SMILES not rendered: c1cncn1" is.null(parse.smiles('c1cncn1', kekulise=FALSE)[[1]]) [1] FALSE renderSMILES.rcdk("c1cncn1",kekulise=FALSE)

image

but if the SMILES is valid it's harder to catch the error, you can plot either without error:

plot.new() plot.window(xlim=c(0,200), ylim=c(0,100)) is.null(parse.smiles('c1c[nH]cn1', kekulise=TRUE)[[1]]) [1] FALSE renderSMILES.rcdk("c1c[nH]cn1",kekulise=TRUE) is.null(parse.smiles('c1c[nH]cn1', kekulise=FALSE)[[1]]) [1] FALSE renderSMILES.rcdk("c1c[nH]cn1",kekulise=FALSE, coords=c(100,0,200,100))

image

I'll update my documentation to reflect that, thanks!