library(rcdk)
## Loading required package: rcdklibs
## Loading required package: rJava
#Basic Structural Analysis
#No.of Atoms and bonds
molecule_1 <- parse.smiles('C(Cl)(Cl)(Cl)Cl')[[1]]
atoms <- get.atoms(molecule_1)
cat('No. of atoms =', length(atoms), '\n')
## No. of atoms = 5
bonds <- get.bonds(molecule_1)
cat('No. of bonds =', length(bonds), '\n')
## No. of bonds = 4
#Visualization
img <- view.image.2d(molecule_1)
plot(1:10, 1:10, pch=19)
rasterImage(img, 1,6, 5,10)

#Adding information to the molecule
set.property(molecule_1, "title", "Carbon Tetra Chloride")
set.property(molecule_1, "Atom Count", 5)
set.property(molecule_1, "No.of.Bonds",4)
set.property(molecule_1,"Mass",152)
get.property(molecule_1,"title")
## [1] "Carbon Tetra Chloride"
#sub structure matching
mols_match <- parse.smiles(c('CC(C)(C)C','c1ccc(Cl)cc1C(=O)O', 'CCC(N)(N)CC'))
#Alkyl Carbon [CX4]
query <- '[CX4]'
#carbon chlorine bond
query_1 <- '[#6][Cl]'
matches(query, mols_match)
##          CC(C)(C)C.match c1ccc(Cl)cc1C(=O)O.match        CCC(N)(N)CC.match 
##                     TRUE                    FALSE                     TRUE
matches(query_1,molecule_1)
## match 
##  TRUE