CDK-R / cdkr

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

Remove atoms with CDK #141

Closed xdomingoal closed 3 months ago

xdomingoal commented 1 year ago

How can you remove a specific atom from a molecule (IAtomContainer) using CDK in R?

zachcp commented 1 year ago

Hi, here is an example.


# devtools::install_github("CDK-R/depict")

library(rcdk)
library(depict)

mol <- depict::parse_smiles("C1CCCCC1")

depiction() %>%
  depict(mol) %>%
  get_image() %>%
  grid::grid.raster()

# use rJava `as.list` method to view the Java iterator as a list
list_of_atoms <- as.list(mol$atoms())

# delete the atom of interest
mol$removeAtom(list_of_atoms[[1]])

depiction() %>%
  depict(mol) %>%
  get_image() %>%
  grid::grid.raster()
Screen Shot 2023-03-21 at 7 20 20 AM Screen Shot 2023-03-21 at 7 20 52 AM