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();This class offers two implementations: The Round Robin algorithm (Böcker, Sebastian et. al.. Bioinformatics. 2008. 24) on mass ranges (Unknown BibTeXML type: Duehrkop2013) is used on most inputs. For special cases (e.g. single elements, extremely large mass ranges) a full enumeration algorithm (Pluskal, Tomas et. al.. Analytical Chemistry. 2012. 84) is used. The Round Robin algorithm was originally developed for the SIRIUS 3 software. The full enumeration algorithm was originally developed for a MZmine 2 framework module, published in Pluskal et al. (Pluskal, Tomas et. al.. Analytical Chemistry. 2012. 84).
Modifier and Type | Field and Description |
---|---|
protected org.openscience.cdk.formula.IFormulaGenerator |
formulaGenerator
The chosen implementation
|
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.
|
protected void |
checkInputParameters(IChemObjectBuilder builder,
double minMass,
double maxMass,
MolecularFormulaRange mfRange)
Checks if input parameters are valid and throws an IllegalArgumentException otherwise.
|
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).
|
protected final org.openscience.cdk.formula.IFormulaGenerator formulaGenerator
public MolecularFormulaGenerator(IChemObjectBuilder builder, double minMass, double maxMass, MolecularFormulaRange mfRange)
minMass
- Lower boundary of the target mass rangemaxMass
- Upper boundary of the target mass rangemfRange
- A range of elemental compositions defining the search spaceIllegalArgumentException
- 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
public IMolecularFormula getNextFormula()
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()
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.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.protected void checkInputParameters(IChemObjectBuilder builder, double minMass, double maxMass, MolecularFormulaRange mfRange)
Copyright © 2022. All rights reserved.