/** * 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; }
if ((mfRange == null) || (mfRange.getIsotopeCount() == 0)) { throw (new IllegalArgumentException( "The MolecularFormulaRange parameter must be non-null and must contain at least one isotope"));
/** * 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)); }
/** * 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)); }
mfRange.addIsotope(h1, 4, 10); Assert.assertEquals(3, mfRange.getIsotopeCount()); Assert.assertEquals(0, mfRange.getIsotopeCountMin(carb)); Assert.assertEquals(2, mfRange.getIsotopeCountMin(flu)); Assert.assertEquals(mfRange.getIsotopeCount(), ((MolecularFormulaRange) clone).getIsotopeCount()); Assert.assertEquals(3, ((MolecularFormulaRange) clone).getIsotopeCount()); Assert.assertEquals(3, ((MolecularFormulaRange) clone).getIsotopeCount()); Assert.assertEquals(0, ((MolecularFormulaRange) clone).getIsotopeCountMin(carb)); Assert.assertEquals(2, ((MolecularFormulaRange) clone).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)); }
if (mfRange.getIsotopeCount() <= 2) return true;
Element elements[] = new Element[range.getIsotopeCount()]; int k = 0;
/** * 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. Only test whether the * MolecularFormula are correctly cloned. * * @return The test suite */ @Test public void testClone() throws Exception { MolecularFormulaRange mfRange = new MolecularFormulaRange(); Object clone = mfRange.clone(); Assert.assertTrue(clone instanceof MolecularFormulaRange); Assert.assertEquals(mfRange.getIsotopeCount(), ((MolecularFormulaRange) clone).getIsotopeCount()); }
if (mf.getIsotopeCount() != mfRange.getIsotopeCount()) { for (IIsotope isotope : mfRange.isotopes()) { if (!mf.contains(isotope)) {
/** * 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)); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testGetIsotopeCount() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); Assert.assertEquals(0, mfRange.getIsotopeCount()); }
/** * 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"))); }
/** * 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 */ @Test public void testAddIsotope_IIsotope_int_int() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(builder.newInstance(IIsotope.class, "C"), 0, 10); mfRange.addIsotope(builder.newInstance(IIsotope.class, "H"), 0, 10); Assert.assertEquals(2, mfRange.getIsotopeCount()); }
/** * 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"))); }
/** * 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 testAddIsotope2() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(builder.newInstance(IIsotope.class, "C"), 0, 10); mfRange.addIsotope(builder.newInstance(IIsotope.class, "H"), 0, 10); IIsotope hy = builder.newInstance(IIsotope.class, "C"); hy.setNaturalAbundance(2.00342342); mfRange.addIsotope(hy, 0, 10); Assert.assertEquals(3, mfRange.getIsotopeCount()); }
Assert.assertEquals(4, mfRange.getIsotopeCount()); Assert.assertEquals(formula.getIsotopeCount(builder.newInstance(IIsotope.class, "C")), mfRange.getIsotopeCountMin(builder.newInstance(IIsotope.class, "C")));