PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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
  8. get.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. is.subgraph <- function(query, target) {
  21. if (class(query) == 'character') {
  22. query <- parse.smiles(query)
  23. do.aromaticity(query)
  24. do.typing(query)
  25. }
  26. if (!is.list(target)) target <- list(target)
  27. if (!all(unlist(lapply(target, class)) == 'jobjRef'))
  28. stop("targets must be a list of IAtomContainer objects or a single IAtomContainer object")
  29. method <- 'TurboSubStructure'
  30. isoType <- .jcall("org.openscience.cdk.smsd.interfaces.Algorithm",
  31. "Lorg/openscience/cdk/smsd/interfaces/Algorithm;",
  32. "valueOf", method)
  33. iso <- .jnew("org.openscience.cdk.smsd.Isomorphism",
  34. isoType, TRUE);
  35. unlist(lapply(target, function(x) {
  36. .jcall(iso, "V", "init", query, x, TRUE, TRUE)
  37. .jcall(iso, "V", "setChemFilters", FALSE, FALSE, FALSE)
  38. .jcall(iso, "Z", "isSubgraph")
  39. }))
  40. }