/** * 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 minimal occurrence of the IIsotope into IMolecularFormula * from this MolelecularFormulaRange. * * @param mfRange The MolecularFormulaRange to analyze * @return A IMolecularFormula containing the minimal occurrence of each isotope */ public static IMolecularFormula getMinimalFormula(MolecularFormulaRange mfRange, IChemObjectBuilder builder) { IMolecularFormula formula = builder.newInstance(IMolecularFormula.class); for (IIsotope isotope : mfRange.isotopes()) { formula.addIsotope(isotope, mfRange.getIsotopeCountMin(isotope)); } return formula; }
IIsotope el = weights.get(i).getOwner(); int max = boundaries.getIsotopeCountMax(el); int min = boundaries.getIsotopeCountMin(el); if (min >= 0 || max >= 0) { boundsarray[i] = max - min;
/** * 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; }
/** * 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; }
for (IIsotope isotope : formulaRange.isotopes()) { if (formula.getIsotopeCount(isotope) != 0) { if ((formula.getIsotopeCount(isotope) < formulaRange.getIsotopeCountMin(isotope)) || (formula.getIsotopeCount(isotope) > formulaRange.getIsotopeCountMax(isotope))) { flagCorrect = false; break; } else if (formulaRange.getIsotopeCountMin(isotope) != 0) { flagCorrect = false; break;
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testGetIsotopeCountMin_IIsotope() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); IIsotope carb = builder.newInstance(IIsotope.class, "C"); IIsotope h1 = builder.newInstance(IIsotope.class, "H"); IIsotope flu = builder.newInstance(IIsotope.class, "F"); mfRange.addIsotope(carb, 0, 10); mfRange.addIsotope(h1, 0, 10); Assert.assertEquals(2, mfRange.getIsotopeCount()); Assert.assertEquals(0, mfRange.getIsotopeCountMin(carb)); Assert.assertEquals(0, mfRange.getIsotopeCountMin(h1)); Assert.assertEquals(-1, mfRange.getIsotopeCountMin(flu)); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testGetIsotopeCountMin_IIsotope3() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); IIsotope carb1 = builder.newInstance(IIsotope.class, "C"); IIsotope h1 = builder.newInstance(IIsotope.class, "H"); IIsotope carb2 = builder.newInstance(IIsotope.class, "C"); IIsotope h2 = builder.newInstance(IIsotope.class, "H"); mfRange.addIsotope(carb1, 0, 10); mfRange.addIsotope(h1, 0, 10); mfRange.addIsotope(carb2, 5, 10); mfRange.addIsotope(h2, 5, 10); Assert.assertEquals(2, mfRange.getIsotopeCount()); Assert.assertEquals(5, mfRange.getIsotopeCountMin(carb1)); Assert.assertEquals(5, mfRange.getIsotopeCountMin(h1)); Assert.assertEquals(5, mfRange.getIsotopeCountMin(carb2)); Assert.assertEquals(5, mfRange.getIsotopeCountMin(h2)); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testRemoveAllIsotopes() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); IIsotope carb = builder.newInstance(IIsotope.class, "C"); IIsotope flu = builder.newInstance(IIsotope.class, "F"); IIsotope h1 = builder.newInstance(IIsotope.class, "H"); mfRange.addIsotope(carb, 0, 10); mfRange.addIsotope(flu, 0, 10); mfRange.addIsotope(h1, 0, 10); // remove the Fluorine mfRange.removeAllIsotopes(); Assert.assertEquals(0, mfRange.getIsotopeCount()); Assert.assertEquals(-1, mfRange.getIsotopeCountMin(carb)); Assert.assertEquals(-1, mfRange.getIsotopeCountMin(h1)); Assert.assertEquals(-1, mfRange.getIsotopeCountMin(flu)); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testGetIsotopeCountMin_IIsotope4() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); IIsotope carb1 = builder.newInstance(IIsotope.class, "C"); IIsotope h1 = builder.newInstance(IIsotope.class, "H"); IIsotope carb2 = builder.newInstance(IIsotope.class, "C"); carb2.setNaturalAbundance(13.0876689); IIsotope h2 = builder.newInstance(IIsotope.class, "H"); h2.setNaturalAbundance(2.0968768); mfRange.addIsotope(carb1, 0, 10); mfRange.addIsotope(h1, 0, 10); mfRange.addIsotope(carb2, 5, 10); mfRange.addIsotope(h2, 5, 10); Assert.assertEquals(4, mfRange.getIsotopeCount()); Assert.assertEquals(0, mfRange.getIsotopeCountMin(carb1)); Assert.assertEquals(0, mfRange.getIsotopeCountMin(h1)); Assert.assertEquals(5, mfRange.getIsotopeCountMin(carb2)); Assert.assertEquals(5, mfRange.getIsotopeCountMin(h2)); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testGetIsotopeCountMin_IIsotope2() { 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); mfRange.addIsotope(carb, 5, 10); mfRange.addIsotope(h1, 5, 10); Assert.assertEquals(2, mfRange.getIsotopeCount()); Assert.assertEquals(5, mfRange.getIsotopeCountMin(carb)); Assert.assertEquals(5, mfRange.getIsotopeCountMin(h1)); }
/** * A unit test suite for JUnit. * * @return The test suite */ public void testRemoveIsotope_IIsotope() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); IIsotope carb = builder.newInstance(IIsotope.class, "C"); IIsotope flu = builder.newInstance(IIsotope.class, "F"); IIsotope h1 = builder.newInstance(IIsotope.class, "H"); mfRange.addIsotope(carb, 0, 10); mfRange.addIsotope(flu, 0, 10); mfRange.addIsotope(h1, 0, 10); // remove the Fluorine mfRange.removeIsotope(flu); Assert.assertEquals(2, mfRange.getIsotopeCount()); Assert.assertEquals(0, mfRange.getIsotopeCountMin(carb)); Assert.assertEquals(-1, mfRange.getIsotopeCountMin(flu)); }
Assert.assertEquals(0, mfRange.getIsotopeCountMin(carb)); 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(0, ((MolecularFormulaRange) clone).getIsotopeCountMin(carb)); 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));
Integer atomicNumber = isotope.getAtomicNumber(); final Element element = periodicTable.get(atomicNumber); int min = range.getIsotopeCountMin(isotope); int max = range.getIsotopeCountMax(isotope);
Integer atomicNumber = isotope.getAtomicNumber(); 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"))); }
} else { int occur_old_Max = mfRange.getIsotopeCountMax(isotope); int occur_old_Min = mfRange.getIsotopeCountMin(isotope); if (occur_new > occur_old_Max) { mfRange.removeIsotope(isotope);
mfRange.getIsotopeCountMin(builder.newInstance(IIsotope.class, "C"))); Assert.assertEquals(formula.getIsotopeCount(builder.newInstance(IIsotope.class, "H")), mfRange.getIsotopeCountMin(builder.newInstance(IIsotope.class, "H"))); Assert.assertEquals(formula.getIsotopeCount(builder.newInstance(IIsotope.class, "N")), mfRange.getIsotopeCountMin(builder.newInstance(IIsotope.class, "N"))); Assert.assertEquals(formula.getIsotopeCount(builder.newInstance(IIsotope.class, "O")), mfRange.getIsotopeCountMin(builder.newInstance(IIsotope.class, "O")));
Assert.assertEquals(4, mfRange.getIsotopeCountMin(builder.newInstance(IIsotope.class, "C"))); 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"))); }