PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/rcdk/inst/unitTests/runit.match.R

http://github.com/rajarshi/cdkr
R | 78 lines | 67 code | 11 blank | 0 comment | 2 complexity | 15b7646c9eca24623e69c8995f50eeec MD5 | raw file
 1test.match1 <- function()
 2{
 3  m <- parse.smiles('CCCCc1cccc(Cl)c1')[[1]]
 4  q <- 'cCl'
 5  checkTrue(matches(q,m))
 6}
 7
 8test.match2 <- function()
 9{
10  m <- parse.smiles('CCCCc1cccc(Cl)c1')[[1]]
11  q <- 'CCCCc'
12  checkTrue(matches(q,m))
13}
14
15test.match3 <- function()
16{
17  m1 <- parse.smiles('CCCCc1cccc(Cl)c1')[[1]]
18  m2 <- parse.smiles('CC(N)(N)CC=O')[[1]]
19  q <- '[CD2]'
20  checkTrue(all(matches(q,list(m1,m2))))
21  checkEquals(2, length(matches(q,list(m1,m2))))
22}
23
24test.match4 <- function()
25{
26
27  smiles <- c('CCC', 'c1ccccc1', 'C(C)(C=O)C(CCNC)C1CC1C(=O)')
28  mols <- sapply(smiles, parse.smiles)
29  mappings <- matches("CCCC", mols, TRUE)
30  checkEquals(3, length(mappings))
31  checkTrue(!mappings[[1]]$match)
32  checkTrue(!mappings[[2]]$match)
33  checkTrue(mappings[[3]]$match)
34
35  checkTrue(is.null(mappings[[1]]$mapping))
36  checkTrue(is.null(mappings[[2]]$mapping))
37
38  checkEquals(13, length(mappings[[3]]$mapping))
39  m <- sapply(mappings[[3]]$mapping, function(x) length(x))
40  checkTrue(all(m == 4))
41}
42
43
44test.mcs1 <- function() {
45  mols <- parse.smiles(c("NCc1ccccc1OC(=N)CCN", "c1ccccc1OC(=N)"))
46  lapply(mols, do.aromaticity)
47  lapply(mols, do.typing) 
48  mcs <- get.mcs(mols[[1]], mols[[2]], TRUE)
49  checkEquals("org.openscience.cdk.AtomContainer2", .jclass(mcs))
50  checkEquals(9, get.atom.count(mcs))
51}
52
53test.mcs3 <- function() {
54  mols <- parse.smiles(c("c1cccc(COC(=O)NC(CC(C)C)C(=O)NC(CCc2ccccc2)C(=O)COC)c1", "c1cccc(COC(=O)NC(CC(C)C)C(=O)NCC#N)c1"))
55  lapply(mols, do.aromaticity)
56  lapply(mols, do.typing) 
57  mcs <- get.mcs(mols[[1]], mols[[2]], TRUE)
58  checkEquals("org.openscience.cdk.AtomContainer2", .jclass(mcs))
59  checkEquals(21, get.atom.count(mcs))
60}
61
62test.mcs2 <- function() {
63  mols <- parse.smiles(c("NCc1ccccc1OC(=N)CCN", "c1ccccc1OC(=N)"))
64  lapply(mols, do.aromaticity)
65  lapply(mols, do.typing) 
66  mcs <- get.mcs(mols[[1]], mols[[2]], FALSE)
67  checkTrue(inherits(mcs, "matrix"))
68  checkEquals(9, nrow(mcs))
69  checkEquals(2, ncol(mcs))
70}
71
72test.aromaticity.match <- function() {
73  smiles <- c("CCC", "c1ccccc1", "C(C)(C=O)C(CCNC)C1CC1C(=O)")
74  mols <- parse.smiles(smiles)
75  query <- "[#6]=O"
76doesMatch <- matches(query, mols)
77  checkTrue(all(doesMatch == c(FALSE,FALSE,TRUE)))
78}