Learn R Programming

rcdk (version 3.4.7.1)

generate.formula: Generate molecular formulae given a target mass and a set of elements and counts.

Description

These functions generate a list of cdkFormula objects or strings given a mass and a set of elements and their possible counts (specified as a range). generate.formula.iter employs recently updated code making it much faster than generate.formula.

In addition, generate.formula.iter returns an iterator, using which very large sets of formulae can be generated without excessive memory consumption. By default this method returns molecular formulae as strings, rather than cdkFormula objects. By default this method does not perform any validation, and even if validation = TRUE no validation is performed. generate.formula can perform validation, but this results in significantly slower run times.

Usage

generate.formula(mass, window=0.01, elements=list(c("C",0,50),c("H",0,50),
                                                  c("N",0,50),c("O",0,50),
                                                  c("S",0,50)),
                 validation=FALSE, charge=0.0)
generate.formula.iter(mass, window = 0.01,
                              elements = list(
                                C=c(0,50),
                                H=c(0,50),
                                N=c(0,50),
                                O=c(0,50),
                                S=c(0,50)),
                              validation = FALSE,
                              charge = 0.0,
                              as.string=TRUE)

Arguments

mass

The mass value from which to be generate the formulas.

window

The window accuracy in the same units as mass.

elements

Elements to take into account.

validation

TRUE, if the method should only generate valid formulas. If FALSE, nonsensical formulae my be generated which must be filtered out by the user

charge

The charge value of the formula.

as.string

If TRUE the formula is returned as a string, otherwise as a IMolecularFormula object

Value

List of IMolecularFormula objects or strings, representing molecular formulae

See Also

get.formula, set.charge.formula, get.isotopes.pattern, isvalid.formula

Examples

Run this code
# NOT RUN {
mfSet <- generate.formula(18.03383,charge=1,
                          elements=list(c("C",0,50),c("H",0,50),c("N",0,50)))
for (i in mfSet) {
  print(i)
}

mit <- generate.formula.iter(18.03383,charge=1,
                          elements=list(C=c(0,50), H=c(0,50), N=c(0,50)))
hit <- itertools::ihasNext(mit)
while (itertools::hasNext(hit)) 
  print(iterators::nextElem(hit))			  
# }

Run the code above in your browser using DataLab