/** * 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)); }
/** * 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; }
MolecularFormulaRange mfRange = new MolecularFormulaRange(); if (!mfRange.contains(isotope)) { 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) { mfRange.removeIsotope(isotope); mfRange.addIsotope(isotope, occur_old_Min, occur_new); } else if (occur_new < occur_old_Min) { mfRange.removeIsotope(isotope); mfRange.addIsotope(isotope, occur_new, occur_old_Max); if (mf.getIsotopeCount() != mfRange.getIsotopeCount()) { for (IIsotope isotope : mfRange.isotopes()) { if (!mf.contains(isotope)) { int occurMax = mfRange.getIsotopeCountMax(isotope); mfRange.addIsotope(isotope, 0, occurMax);
/** * Checks a set of Nodes for the maximal occurrence of the isotope in the * MolecularFormulaExpand from a particular isotope. It returns -1 if the Isotope * does not exist. * * @param isotope The IIsotope to look for * @return The occurrence of this isotope in this IMolecularFormula */ public int getIsotopeCountMax(IIsotope isotope) { return !contains(isotope) ? -1 : isotopesMax.get(getIsotope(isotope)); }
/** * 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; }
/** * Get the isotope instance given an IIsotope. The instance is those * that has the isotope with the same symbol, natural abundance and * exact mass. * * @param isotope The IIsotope for looking for * @return The IIsotope instance * @see #isotopes */ private IIsotope getIsotope(IIsotope isotope) { for (Iterator<IIsotope> it = isotopes().iterator(); it.hasNext();) { IIsotope thisIsotope = it.next(); if (isTheSame(isotope, thisIsotope)) return thisIsotope; } return null; }
/** * Initiate the MolecularFormulaExpand with the maximum and minimum occurrence of the Elements. * In this case all elements of the periodic table are loaded. */ private void ensureDefaultOccurElements(IChemObjectBuilder builder) { if (mfRange == null) { String[] elements = new String[]{"C", "H", "O", "N", "Si", "P", "S", "F", "Cl", "Br", "I", "Sn", "B", "Pb", "Tl", "Ba", "In", "Pd", "Pt", "Os", "Ag", "Zr", "Se", "Zn", "Cu", "Ni", "Co", "Fe", "Cr", "Ti", "Ca", "K", "Al", "Mg", "Na", "Ce", "Hg", "Au", "Ir", "Re", "W", "Ta", "Hf", "Lu", "Yb", "Tm", "Er", "Ho", "Dy", "Tb", "Gd", "Eu", "Sm", "Pm", "Nd", "Pr", "La", "Cs", "Xe", "Te", "Sb", "Cd", "Rh", "Ru", "Tc", "Mo", "Nb", "Y", "Sr", "Rb", "Kr", "As", "Ge", "Ga", "Mn", "V", "Sc", "Ar", "Ne", "Be", "Li", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu"}; mfRange = new MolecularFormulaRange(); for (int i = 0; i < elements.length; i++) mfRange.addIsotope(builder.newInstance(IIsotope.class, elements[i]), 0, 50); } } }
/** * 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"))); }
Iterator<IIsotope> itEle = formulaRange.isotopes().iterator(); 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; while (itEle.hasNext()) { IIsotope isotope = itEle.next(); if (!formulaRange.contains(isotope)) { flagCorrect = false; break;
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testIsotopes() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(builder.newInstance(IIsotope.class, "C"), 0, 10); mfRange.addIsotope(builder.newInstance(IIsotope.class, "F"), 0, 10); Iterator<IIsotope> istoIter = mfRange.isotopes().iterator(); int counter = 0; while (istoIter.hasNext()) { istoIter.next(); counter++; } Assert.assertEquals(2, counter); }
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) { boundsarray[i] = max - min;
if (mfRange.getIsotopeCount() <= 2) return true; for (IIsotope i : mfRange.isotopes()) { smallestMass = Math.min(smallestMass, i.getExactMass());
/** * 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; }
/** * 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; }
/** * 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()); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testContains_IIsotope() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); IIsotope carb = builder.newInstance(IIsotope.class, "C"); IIsotope cl = builder.newInstance(IIsotope.class, "Cl"); IIsotope h1 = builder.newInstance(IIsotope.class, "H"); IIsotope h2 = builder.newInstance(IIsotope.class, "H"); h2.setExactMass(2.0004); mfRange.addIsotope(carb, 0, 10); mfRange.addIsotope(h1, 0, 10); Assert.assertTrue(mfRange.contains(carb)); Assert.assertFalse(mfRange.contains(cl)); Assert.assertTrue(mfRange.contains(h1)); Assert.assertFalse(mfRange.contains(h2)); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testGetIsotopeCount() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); Assert.assertEquals(0, mfRange.getIsotopeCount()); }
Assert.assertEquals(4, mfRange.getIsotopeCount()); Assert.assertEquals(formula.getIsotopeCount(builder.newInstance(IIsotope.class, "C")), 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.getIsotopeCount()); Assert.assertEquals(formula.getIsotopeCount(builder.newInstance(IIsotope.class, "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")));