File: matrix.R

package info (click to toggle)
r-cran-rcdk 3.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 860 kB
  • sloc: makefile: 14; sh: 13
file content (37 lines) | stat: -rwxr-xr-x 1,547 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#' Get adjacency matrix for a molecule.
#'
#' The adjacency matrix for a molecule with \eqn{N} non-hydrogen atoms is an
#' \eqn{N \times N} matrix where the element [\eqn{i},\eqn{j}] is set to 1
#' if atoms \eqn{i} and \eqn{j} are connected by a bond, otherwise set to 0.
#'
#' @param mol A \code{jobjRef} object with Java class \code{IAtomContainer}
#' @return A \eqn{N \times N} numeric matrix
#' @author Rajarshi Guha \email{rajarshi.guha@gmail.com}
#' @seealso \code{\link{get.connection.matrix}}
#' @examples
#' m <- parse.smiles("CC=C")[[1]]
#' get.adjacency.matrix(m)
#' @export
get.adjacency.matrix <- function(mol) {
    am <- .jcall('org.openscience.cdk.graph.matrix.AdjacencyMatrix','[[I','getMatrix', mol)
    do.call(rbind, lapply(am, .jevalArray))
}

#' Get connection matrix for a molecule.
#'
#' The connection matrix for a molecule with \eqn{N} non-hydrogen atoms is an
#' \eqn{N \times N} matrix where the element [\eqn{i},\eqn{j}] is set to the 
#' bond order if atoms \eqn{i} and \eqn{j} are connected by a bond, otherwise set to 0.
#'
#' @param mol A \code{jobjRef} object with Java class \code{IAtomContainer}
#' @return A \eqn{N \times N} numeric matrix
#' @author Rajarshi Guha \email{rajarshi.guha@gmail.com}
#' @seealso \code{\link{get.adjacency.matrix}}
#' @examples
#' m <- parse.smiles("CC=C")[[1]]
#' get.connection.matrix(m)
#' @export
get.connection.matrix <- function(mol) {
    cm <- .jcall('org.openscience.cdk.graph.matrix.ConnectionMatrix','[[D','getMatrix', mol)
    do.call(rbind, lapply(cm, .jevalArray))
}