@TestClass(value="org.openscience.cdk.formula.MolecularFormulaGeneratorTest") public class MolecularFormulaGenerator extends Object
IsotopeFactory ifac = Isotopes.getInstance(); IIsotope c = ifac.getMajorIsotope("C"); IIsotope h = ifac.getMajorIsotope("H"); IIsotope n = ifac.getMajorIsotope("N"); IIsotope o = ifac.getMajorIsotope("O"); IIsotope p = ifac.getMajorIsotope("P"); IIsotope s = ifac.getMajorIsotope("S"); MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(c, 0, 50); mfRange.addIsotope(h, 0, 100); mfRange.addIsotope(o, 0, 50); mfRange.addIsotope(n, 0, 50); mfRange.addIsotope(p, 0, 10); mfRange.addIsotope(s, 0, 10); MolecularFormulaGenerator mfg = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange); double minMass = 133.003; double maxMass = 133.005; IMolecularFormulaSet mfSet = mfg.getAllFormulas();The code was originally developed for a MZmine 2 framework module, published in Pluskal et al. [Pluskal2012 (not found in db)].
Constructor and Description |
---|
MolecularFormulaGenerator(IChemObjectBuilder builder,
double minMass,
double maxMass,
MolecularFormulaRange mfRange)
Initiate the MolecularFormulaGenerator.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancel the current search.
|
IMolecularFormulaSet |
getAllFormulas()
Generates a
IMolecularFormulaSet by repeatedly calling getNextFormula() until all possible formulas are generated. |
double |
getFinishedPercentage()
Returns a value between 0.0 and 1.0 indicating what portion of the search
space has been examined so far by this MolecularFormulaGenerator.
|
IMolecularFormula |
getNextFormula()
Returns next generated formula or null in case no new formula was found
(search is finished).
|
public MolecularFormulaGenerator(IChemObjectBuilder builder, double minMass, double maxMass, MolecularFormulaRange mfRange) throws CDKException
minMass
- Lower boundary of the target mass rangemaxMass
- Upper boundary of the target mass rangemfRange
- A range of elemental compositions defining the search spaceCDKException
- In case some of the isotopes in mfRange has undefined exact
mass or in case illegal parameters are provided (e.g.,
negative mass values or empty MolecularFormulaRange)MolecularFormulaRange
@TestMethod(value="testGetNextFormula") public IMolecularFormula getNextFormula()
@TestMethod(value="testGetAllFormulas") public IMolecularFormulaSet getAllFormulas()
IMolecularFormulaSet
by repeatedly calling getNextFormula()
until all possible formulas are generated. There is no
guaranteed order to the formulas in the resulting
IMolecularFormulaSet
.
Note: if some formulas were already generated by calling getNextFormula()
on this MolecularFormulaGenerator instance, those
formulas will not be included in the returned
IMolecularFormulaSet
.getNextFormula()
@TestMethod(value="testGetFinishedPercentage") public double getFinishedPercentage()
getNextFormula()
, this method returns 0. After
all possible formulas are generated, this method returns 1.0 (the exact
returned value might be slightly off due to rounding errors). This method
can be called from any thread.@TestMethod(value="testCancel") public void cancel()
getNextFormula()
method, that
method call will return immediately with null return value. If another
thread is executing the getAllFormulas()
method, that method call
will return immediately, returning all formulas generated until this
moment. The search cannot be restarted once canceled - any subsequent
calls to getNextFormula()
will return null.Copyright © 2014. All Rights Reserved.