CDK-R / cdkr

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

Update depictions in rcdk #41

Closed schymane closed 7 years ago

schymane commented 7 years ago

The depictions in latest rcdk don't yet take advantage of the latest developments shown at https://cdkdepict-openchem.rhcloud.com/depict.html - if these could be upgraded that would be wonderful! Thank you. See emails earlier today :-)

schymane commented 7 years ago

smiles <- "CC(=O)Nc1ccc(O)cc1" d_smiles <- "[2H]Oc1ccc(cc1)N([2H])C(C)=O" d_smiles2 <- "[D]Oc1ccc(cc1)N([D])C(C)=O" LAS_smiles <- "OS(=O)(=O)Oc1ccc(cc1)C(CCC)CCC" SPAC_smiles <- "OS(=O)(=O)Oc1ccc(cc1)C(CC(=O)O)CCC" LAS_gen_smiles <- "[H]OS(=O)(=O)c1ccc(cc1)C([(CH2)m]C)[(CH2)n][H]" # SPAC_gen_smiles <- "[H]OS(=O)(=O)c1ccc(cc1)C([(CH2)m]C(=O)O)[(CH2)n][H]" # SPADC_gen_smiles <- "[H]OS(=O)(=O)c1ccc(cc1)C([(CH2)m]C(=O)O)[(CH2)n]C(=O)O" # DATS_gen_smiles <- "[H]OS(=O)(=O)c1ccc2c(c1)C(CCC2[(CH2)m][H])[(CH2)n][H]" PEGs_gen_smiles <- "[H][(O][CH2][CH2)m]O[H]" PEGs_gen_smiles2 <- "[H ][(O][ CH2][CH2)m]O[H ]" PEGs_gen_smiles3 <- "[H][(OCH2CH2)m]O[H]"

smiles_list <- c(smiles, d_smiles, d_smiles2, LAS_smiles, SPAC_smiles, LAS_gen_smiles, SPAC_gen_smiles, SPADC_gen_smiles, DATS_gen_smiles, PEGs_gen_smiles, PEGs_gen_smiles2, PEGs_gen_smiles3)

mols <- parse.smiles(smiles_list, kekulise = FALSE)

pdf("test_smiles.pdf")

for (i in 1:length(mols)) { img <- tryCatch({ (view.image.2d(mols[[i]], width = 150, height = 150)) }, error = function(e) { img <- "" print(paste("Invalid SMILES not rendered: ", smiles, sep="")) }) if (length(img)>2) { plot.new() plot.window(xlim=c(0,200), ylim=c(0,100)) rasterImage(img, 0,0, 100,100) } } dev.off()

rajarshi commented 7 years ago

Added SMILES for easy ingestion depicttest.txt

schymane commented 7 years ago

Examples taken from https://cdkdepict-openchem.rhcloud.com/depict.html

m <- parse.smiles("Cl.Cl.c1ccccc1-c1ccccc1 |m:1:4.5.6.7.8.9,3:10.11.12.13.14.15|")[[1]] img <- view.image.2d(m, 500,500) Error in .jnew("org/guha/rcdk/view/MoleculeImage", molecule) : org.openscience.cdk.exception.CDKException: Molecule must be connected

m <- parse.smiles('CC(C)C@HC(*)=O |$;;;;;_AP1;;_AP2;$|')[[1]] img <- view.image.2d(m, 500,500) rasterImage(img, 0,2, 8,10) plots, but does not reproduce the same image on above website

m <- parse.smiles("CCOCCOCCO |Sg:n:3,4,5::ht|")[[1]] img <- view.image.2d(m, 500,500) Error in .jnew("org/guha/rcdk/view/MoleculeImage", molecule) : java.lang.NullPointerException

Do I need to handle CxSMILES differently?

[1] rcdklibs_1.5.14 rJava_0.9-8 rcdk_3.3.9 fingerprint_3.5.4

rajarshi commented 7 years ago

Ah, I forgot to update view.image.2d. Can you try these with view.molecule.2d. Also I see your running 3.3.9, but the latest code in Github is 3.4.0 (or 3.4.0.1 by the time you read this)

schymane commented 7 years ago

I ran this this morning and again now:

library(devtools) install_github("rajarshi/cdkr", subdir="rcdklibs") install_github("rajarshi/cdkr", subdir="rcdk")

This still gets me 3.3.9. Wrong branch?

R version 3.2.5 (2016-04-14) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

locale: [1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252 [4] LC_NUMERIC=C LC_TIME=English_Australia.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] rcdklibs_1.5.14 rJava_0.9-8 rcdk_3.3.9 fingerprint_3.5.4 devtools_1.9.1

loaded via a namespace (and not attached): [1] httr_1.2.1 R6_2.2.0 parallel_3.2.5 tools_3.2.5 curl_2.2 memoise_0.2.1 iterators_1.0.8 [8] itertools_0.1-3 digest_0.6.10 png_0.1-7

schymane commented 7 years ago

view.molecule.2d didn't work this morning, I thought I was doing something wrong so switched to view.image.2d - same again now - also an error in documentation. But I guess this is because I have the wrong version...

m <- parse.smiles('c1ccccc1C(=O)NC')[[1]] Error in fetch(key) : lazy-load database 'C:/DATA/R/R/win-library/3.2/rcdk/help/rcdk.rdb' is corrupt Error in fetch(key) : lazy-load database 'C:/DATA/R/R/win-library/3.2/rcdk/help/rcdk.rdb' is corrupt Error in fetch(key) : lazy-load database 'C:/DATA/R/R/win-library/3.2/rcdk/help/rcdk.rdb' is corrupt

img <- view.molecule.2d(m) Error in .jnew("org/guha/rcdk/view/ViewMolecule2D", molecule, as.integer(cellx), : java.lang.NoSuchMethodError: org.openscience.cdk.depict.DepictionGenerator.withMappedRxnAlign(Z)Lorg/openscience/cdk/depict/DepictionGenerator;

schymane commented 7 years ago

https://github.com/rajarshi/cdkr/blob/master/rcdk/DESCRIPTION Lists 3.3.9, but last commit 5 hrs ago. Strange.

rajarshi commented 7 years ago

Just pushed some major refactoring that should have everything in sync. The version you should see is 3.4.1. Also, the workflow for depictions is a bit different now. In general, you create a depiction object and then get the depiction:

m <- parse.smiles("Cl*.Cl*.c1ccccc1-c1ccccc1 |m:1:4.5.6.7.8.9,3:10.11.12.13.14.15|")[[1]]
dep <- get.depictor(width=300, height=300, style='nob')
copy.image.to.clipboard(m, dep)
img <- view.image.2d(m, dep)

Also, it looks like you need to manually remove your rCDK installation (R CMD REMOVE rcdk) and reinstall from Github

schymane commented 7 years ago

First part successful :-) other attached packages: [1] rcdklibs_1.5.14 rJava_0.9-8 rcdk_3.4.1 fingerprint_3.5.4 devtools_1.9.1

schymane commented 7 years ago

... and the rest seems to work too :-) awesome, thanks!