PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 38ms app.codeStats 0ms

/rcdk/R/smsd.R

http://github.com/rajarshi/cdkr
R | 43 lines | 33 code | 3 blank | 7 comment | 7 complexity | cfd019a5371732e41290cafc9fa99f2f MD5 | raw file
 1#' get.mcs
 2#' 
 3#' 
 4#' @param mol1 Required. First molecule to compare. Should be a `jobjRef` representing an `IAtomContainer`
 5#' @param mol2 Required. Second molecule to compare. Should be a `jobjRef` representing an `IAtomContainer`
 6#' @param as.molecule Optional. Default \code{TRUE}.
 7#' @export
 8get.mcs <- function(mol1, mol2, as.molecule = TRUE) {
 9  if (as.molecule) {
10    return(.jcall("org.guha.rcdk.util.Misc",
11           "Lorg/openscience/cdk/interfaces/IAtomContainer;",
12           "getMcsAsNewContainer", mol1, mol2))
13  } else {
14    arr <- .jcall("org.guha.rcdk.util.Misc",
15           "[[I",
16           "getMcsAsAtomIndexMapping", mol1, mol2)
17    do.call('rbind', lapply(arr, .jevalArray, rawJNIRefSignature = "[I"))
18  }
19}
20
21is.subgraph <- function(query, target) {
22  if (class(query) == 'character') {
23    query <- parse.smiles(query)
24    do.aromaticity(query)
25    do.typing(query)
26  }
27
28  if (!is.list(target)) target <- list(target)
29  if (!all(unlist(lapply(target, class)) == 'jobjRef'))
30    stop("targets must be a list of IAtomContainer objects or a single IAtomContainer object")
31  
32  method <- 'TurboSubStructure'
33  isoType <- .jcall("org.openscience.cdk.smsd.interfaces.Algorithm",
34                    "Lorg/openscience/cdk/smsd/interfaces/Algorithm;",
35                    "valueOf", method)
36  iso <- .jnew("org.openscience.cdk.smsd.Isomorphism",
37               isoType, TRUE);
38  unlist(lapply(target, function(x) {
39    .jcall(iso, "V", "init", query, x, TRUE, TRUE)
40    .jcall(iso, "V", "setChemFilters", FALSE, FALSE, FALSE)
41    .jcall(iso, "Z", "isSubgraph")
42  }))
43}