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