/** * This method does not work for Round Robin as the algorithm only enumerates formulas which really have the * searched mass range (except for false positives due to rounding errors). As the exact number of molecular formulas * with a given mass is unknown (calculating it is as expensive as enumerating them) there is no way to give a * progress number. Therefore, the method returns just 0 if it's enumerating and 1 if it's done. */ @Override public double getFinishedPercentage() { if (done) return 1d; final int[] lastDecomposition = this.lastDecomposition; if (lastDecomposition == null) return 0; double result = 0.0; double remainingPerc = 1.0; for (int i = lastDecomposition.length - 1; i >= 0; i--) { double max = mfRange.getIsotopeCountMax(decomposer.weights.get(i).getOwner()); if (i > 0) max += 1.0; result += remainingPerc * ((double) lastDecomposition[i] / max); remainingPerc /= max; } return result; }
/** * Clones this MolecularFormulaExpand object and its content. I should * integrate into ChemObject. * * @return The cloned object */ @Override public Object clone() throws CloneNotSupportedException { MolecularFormulaRange clone = new MolecularFormulaRange(); Iterator<IIsotope> iterIso = this.isotopes().iterator(); while (iterIso.hasNext()) { IIsotope isotope = iterIso.next(); clone.addIsotope((IIsotope) isotope.clone(), getIsotopeCountMin(isotope), getIsotopeCountMax(isotope)); } return clone; }
/** * Returns the maximal occurrence of the IIsotope into IMolecularFormula * from this MolelecularFormulaRange. * * @param mfRange The MolecularFormulaRange to analyze * @return A IMolecularFormula containing the maximal occurrence of each isotope */ public static IMolecularFormula getMaximalFormula(MolecularFormulaRange mfRange, IChemObjectBuilder builder) { IMolecularFormula formula = builder.newInstance(IMolecularFormula.class); for (IIsotope isotope : mfRange.isotopes()) { formula.addIsotope(isotope, mfRange.getIsotopeCountMax(isotope)); } return formula; }
/** * Initiate the MolecularFormulaGenerator. * * @param minMass * Lower boundary of the target mass range * @param maxMass * Upper boundary of the target mass range * @param mfRange * A range of elemental compositions defining the search space * @throws IllegalArgumentException * 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) * @see MolecularFormulaRange */ RoundRobinFormulaGenerator(final IChemObjectBuilder builder, final double minMass, final double maxMass, final MolecularFormulaRange mfRange) { this.builder = builder; final List<IIsotope> isotopes = new ArrayList<>(mfRange.getIsotopeCount()); for (IIsotope iso : mfRange.isotopes()) { if (mfRange.getIsotopeCountMin(iso) >= 0 && mfRange.getIsotopeCountMax(iso) > 0) isotopes.add(iso); } this.decomposer = DecomposerFactory.getInstance().getDecomposerFor(isotopes.toArray(new IIsotope[isotopes.size()])).decomposeIterator(minMass, maxMass, mfRange); this.done = false; this.mfRange = mfRange; }
for (int i = 0; i < boundsarray.length; i++) { IIsotope el = weights.get(i).getOwner(); int max = boundaries.getIsotopeCountMax(el); int min = boundaries.getIsotopeCountMin(el); if (min >= 0 || max >= 0) {
for (int i = 0; i < isotopes.length; i++) { minCounts[i] = mfRange.getIsotopeCountMin(isotopes[i]); maxCounts[i] = mfRange.getIsotopeCountMax(isotopes[i]);
int maxx = mfRange.getIsotopeCountMax(isotopes_TO.get(elem_Pos.get(possChan).intValue())); int minn = mfRange.getIsotopeCountMin(isotopes_TO.get(elem_Pos.get(possChan).intValue()));
/** * Validate the occurrence of this IMolecularFormula. * * @param formula Parameter is the IMolecularFormula * @return An ArrayList containing 9 elements in the order described above */ @Override public double validate(IMolecularFormula formula) throws CDKException { logger.info("Start validation of ", formula); ensureDefaultOccurElements(formula.getBuilder()); double isValid = 1.0; Iterator<IElement> itElem = MolecularFormulaManipulator.elements(formula).iterator(); while (itElem.hasNext()) { IElement element = itElem.next(); int occur = MolecularFormulaManipulator.getElementCount(formula, element); IIsotope elemIsotope = formula.getBuilder().newInstance(IIsotope.class, element.getSymbol()); if ((occur < mfRange.getIsotopeCountMin(elemIsotope)) || (occur > mfRange.getIsotopeCountMax(elemIsotope))) { isValid = 0.0; break; } } return isValid; }
if (formula.getIsotopeCount(isotope) != 0) { if ((formula.getIsotopeCount(isotope) < formulaRange.getIsotopeCountMin(isotope)) || (formula.getIsotopeCount(isotope) > formulaRange.getIsotopeCountMax(isotope))) { flagCorrect = false; break;
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testGetIsotopeCountMax_IIsotope() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); IIsotope carb = builder.newInstance(IIsotope.class, "C"); IIsotope h1 = builder.newInstance(IIsotope.class, "H"); mfRange.addIsotope(carb, 0, 10); mfRange.addIsotope(h1, 0, 10); Assert.assertEquals(2, mfRange.getIsotopeCount()); Assert.assertEquals(10, mfRange.getIsotopeCountMax(carb)); Assert.assertEquals(10, mfRange.getIsotopeCountMax(h1)); }
mfRange.addIsotope(isotope, occur_new, occur_new); } else { int occur_old_Max = mfRange.getIsotopeCountMax(isotope); int occur_old_Min = mfRange.getIsotopeCountMin(isotope); if (occur_new > occur_old_Max) { for (IIsotope isotope : mfRange.isotopes()) { if (!mf.contains(isotope)) { int occurMax = mfRange.getIsotopeCountMax(isotope); mfRange.addIsotope(isotope, 0, occurMax);
Assert.assertEquals(2, mfRange.getIsotopeCountMin(flu)); Assert.assertEquals(4, mfRange.getIsotopeCountMin(h1)); Assert.assertEquals(5, mfRange.getIsotopeCountMax(carb)); Assert.assertEquals(8, mfRange.getIsotopeCountMax(flu)); Assert.assertEquals(10, mfRange.getIsotopeCountMax(h1)); Assert.assertEquals(2, ((MolecularFormulaRange) clone).getIsotopeCountMin(flu)); Assert.assertEquals(4, ((MolecularFormulaRange) clone).getIsotopeCountMin(h1)); Assert.assertEquals(5, ((MolecularFormulaRange) clone).getIsotopeCountMax(carb)); Assert.assertEquals(8, ((MolecularFormulaRange) clone).getIsotopeCountMax(flu)); Assert.assertEquals(10, ((MolecularFormulaRange) clone).getIsotopeCountMax(h1));
final Element element = periodicTable.get(atomicNumber); int min = range.getIsotopeCountMin(isotope); int max = range.getIsotopeCountMax(isotope);
final Element element = periodicTable.get(atomicNumber); int min = range.getIsotopeCountMin(isotope); int max = range.getIsotopeCountMax(isotope);
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testSetParameters() throws Exception { IRule rule = new ElementRule(); Object[] params = new Object[1]; MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(builder.newInstance(IIsotope.class, "C"), 1, 10); mfRange.addIsotope(builder.newInstance(IIsotope.class, "H"), 1, 10); params[0] = mfRange; rule.setParameters(params); Object[] objects = rule.getParameters(); Assert.assertEquals(1, objects.length); MolecularFormulaRange mfRange2 = (MolecularFormulaRange) objects[0]; Assert.assertEquals(mfRange.getIsotopeCount(), mfRange2.getIsotopeCount()); Assert.assertEquals(mfRange.getIsotopeCountMin(new Isotope("C")), mfRange2.getIsotopeCountMin(new Isotope("C"))); Assert.assertEquals(mfRange.getIsotopeCountMax(new Isotope("C")), mfRange2.getIsotopeCountMax(new Isotope("C"))); }
mfRange.getIsotopeCountMax(builder.newInstance(IIsotope.class, "C"))); Assert.assertEquals(formula.getIsotopeCount(builder.newInstance(IIsotope.class, "H")), mfRange.getIsotopeCountMax(builder.newInstance(IIsotope.class, "H"))); Assert.assertEquals(formula.getIsotopeCount(builder.newInstance(IIsotope.class, "N")), mfRange.getIsotopeCountMax(builder.newInstance(IIsotope.class, "N"))); Assert.assertEquals(formula.getIsotopeCount(builder.newInstance(IIsotope.class, "O")), mfRange.getIsotopeCountMax(builder.newInstance(IIsotope.class, "O")));
Assert.assertEquals(9, mfRange.getIsotopeCountMax(builder.newInstance(IIsotope.class, "C"))); Assert.assertEquals(5, mfRange.getIsotopeCountMin(builder.newInstance(IIsotope.class, "H"))); Assert.assertEquals(20, mfRange.getIsotopeCountMax(builder.newInstance(IIsotope.class, "H"))); Assert.assertEquals(0, mfRange.getIsotopeCountMin(builder.newInstance(IIsotope.class, "N"))); Assert.assertEquals(4, mfRange.getIsotopeCountMax(builder.newInstance(IIsotope.class, "N"))); Assert.assertEquals(2, mfRange.getIsotopeCountMin(builder.newInstance(IIsotope.class, "O"))); Assert.assertEquals(7, mfRange.getIsotopeCountMax(builder.newInstance(IIsotope.class, "O")));
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testDefault() throws Exception { IRule rule = new ElementRule(); Object[] objects = rule.getParameters(); // MolecularFormulaRange needs a build to create isotopes Assert.assertEquals(1, objects.length); Assert.assertNull(objects[0]); // when we do a validation... rule.validate(new MolecularFormula()); // a default option is created objects = rule.getParameters(); Assert.assertEquals(1, objects.length); Assert.assertNotNull(objects[0]); MolecularFormulaRange mfRange = (MolecularFormulaRange) objects[0]; Assert.assertEquals(93, mfRange.getIsotopeCount()); Assert.assertEquals(0, mfRange.getIsotopeCountMin(new Isotope("C"))); Assert.assertEquals(50, mfRange.getIsotopeCountMax(new Isotope("C"))); }