PageRenderTime 28ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/rcdk/R/bonds.R

http://github.com/rajarshi/cdkr
R | 73 lines | 26 code | 7 blank | 40 comment | 6 complexity | e86c4316081045dae14f345aba6f9a33 MD5 | raw file
  1. ##get.bond.order <- function(bond) {
  2. ## stop("Doesn't work at this point")
  3. ## if (is.null(attr(bond, 'jclass')) ||
  4. ## attr(bond, "jclass") != "org/openscience/cdk/interfaces/IBond") {
  5. ## stop("Must supply an IBond object")
  6. ## }
  7. ##
  8. ## bo <- .jcall(bond, "Lorg/openscience/cdk/interfaces/IBond.Order;", "getBondOrder")
  9. ## bo
  10. ##}
  11. ##
  12. #' Get the atom connected to an atom in a bond.
  13. #'
  14. #' This function returns the atom that is connected to a
  15. #' specified in a specified bond. Note that this function assumes
  16. #' 2-atom bonds, mainly because the CDK does not currently
  17. #' support other types of bonds
  18. #'
  19. #' @param bond A \code{jObjRef} representing an `IBond` object
  20. #' @param atom A \code{jObjRef} representing an `IAtom` object
  21. #' @return A \code{jObjRef} representing an `IAtom`` object
  22. #' @seealso \code{\link{get.atoms}}
  23. #' @export
  24. #' @author Rajarshi Guha (\email{rajarshi.guha@@gmail.com})
  25. get.connected.atom <- function(bond, atom) {
  26. if (is.null(attr(bond,"jclass")) || is.null(attr(atom,"jclass")))
  27. stop("Must supply an IBond object or Bond")
  28. if (!.check.class(bond, "org/openscience/cdk/interfaces/IBond") &&
  29. !.check.class(bond, "org/openscience/cdk/Bond"))
  30. stop("Must supply an IBond or Bond object")
  31. if (.check.class(bond, "org/openscience/cdk/Bond"))
  32. bond <- .jcast(bond, "org/openscience/cdk/interfaces/IBond")
  33. if (!.check.class(atom, "org/openscience/cdk/interfaces/IAtom") &&
  34. !.check.class(atom, "org/openscience/cdk/Atom"))
  35. stop("Must supply an IAtom or Atom object")
  36. if (.check.class(atom, "org/openscience/cdk/Atom"))
  37. atom <- .jcast(atom, "org/openscience/cdk/interfaces/IAtom")
  38. .jcall(bond, "Lorg/openscience/cdk/interfaces/IAtom;", "getConnectedAtom", atom);
  39. }
  40. #' Get an object representing bond order
  41. #'
  42. #' This function returns a Java enum representing a
  43. #' bond order. This can be used to modify the order
  44. #' of pre-existing bonds
  45. #'
  46. #' @param order A character vector that can be one of single, double, triple,
  47. #' quadruple, quintuple, sextuple or unset. Case is ignored
  48. #' @return A \code{jObjRef} representing an `Order` enum object
  49. #' @export
  50. #' @author Rajarshi Guha (\email{rajarshi.guha@@gmail.com})
  51. #' \dontrun{
  52. #' m <- parse.smiles('CCN')[[1]]
  53. #' b <- get.bonds(m)[[1]]
  54. #' b$setOrder(get.bond.order("double"))
  55. #' }
  56. get.bond.order <- function(order = 'single') {
  57. switch(tolower(order),
  58. single = get("BOND_ORDER_SINGLE", envir = .rcdk.GlobalEnv),
  59. double = get("BOND_ORDER_DOUBLE", envir = .rcdk.GlobalEnv),
  60. triple = get("BOND_ORDER_TRIPLE", envir = .rcdk.GlobalEnv),
  61. quadruple = get("BOND_ORDER_QUADRUPLE", envir = .rcdk.GlobalEnv),
  62. quintuple = get("BOND_ORDER_QUINTUPLE", envir = .rcdk.GlobalEnv),
  63. sextuple = get("BOND_ORDER_SEXTUPLE", envir = .rcdk.GlobalEnv),
  64. unset = get("BOND_ORDER_UNSET", envir = .rcdk.GlobalEnv),
  65. )
  66. }