/** * 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); } } }
/** * Test empty molecular formula range * */ @Test(expected = IllegalArgumentException.class) public void testEmptyMFRange() throws Exception { new MolecularFormulaGenerator(builder, 0, 100, new MolecularFormulaRange()); }
/** * 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; }
/** * Test negative mass */ @Test(expected = IllegalArgumentException.class) public void testNegativeMass() throws Exception { IsotopeFactory ifac = Isotopes.getInstance(); IIsotope c = ifac.getMajorIsotope("C"); MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(c, 0, 100); new MolecularFormulaGenerator(builder, -20, -10, new MolecularFormulaRange()); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testMolecularFormulaRange() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); Assert.assertNotNull(mfRange); }
/** * A unit test suite for JUnit. * * @return The test suite */ @Test public void testGetIsotopeCount() { MolecularFormulaRange mfRange = new MolecularFormulaRange(); Assert.assertEquals(0, mfRange.getIsotopeCount()); }
/** * Test what happens when null isotope is added to MF range. */ @Test(expected=IllegalArgumentException.class) public void testNull() throws Exception { MolecularFormulaRange mfRange = new MolecularFormulaRange(); IIsotope carb = builder.newInstance(IIsotope.class, "C"); IIsotope nul = null; mfRange.addIsotope(carb, 2, 5); mfRange.addIsotope(nul, 3, 7); }
/** * 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); }
/** * 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 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 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()); }
/** * MolecularFormulaGenerator should use full enumeration method when smallest element has large weight */ @Test public void testUseFullEnumerationWhenNoHydrogen() throws Exception { IsotopeFactory ifac = Isotopes.getInstance(); IIsotope c = ifac.getMajorIsotope("C"); IIsotope n = ifac.getMajorIsotope("N"); IIsotope o = ifac.getMajorIsotope("O"); MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(c, 0, 50); mfRange.addIsotope(o, 0, 30); mfRange.addIsotope(n, 0, 10); MolecularFormulaGenerator generator = new MolecularFormulaGenerator(builder, 1023.000, 1023.002, mfRange); Assert.assertTrue("generator implementation should be instance of FullEnumerationFormulaGenerator", generator.formulaGenerator instanceof FullEnumerationFormulaGenerator); }
/** * 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)); }
/** * MolecularFormulaGenerator should use Round Robin when using proper input */ @Test public void testUseRoundRobinWheneverPossible() throws Exception { IsotopeFactory ifac = Isotopes.getInstance(); IIsotope c = ifac.getMajorIsotope("C"); IIsotope h = ifac.getMajorIsotope("H"); IIsotope n = ifac.getMajorIsotope("N"); IIsotope o = ifac.getMajorIsotope("O"); MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(c, 0, 20); mfRange.addIsotope(h, 0, 30); mfRange.addIsotope(o, 0, 15); mfRange.addIsotope(n, 0, 10); MolecularFormulaGenerator generator = new MolecularFormulaGenerator(builder, 230.002, 230.004, mfRange); Assert.assertTrue("generator implementation should be instance of RoundRobinFormulaGenerator", generator.formulaGenerator instanceof RoundRobinFormulaGenerator); }
/** * MolecularFormulaGenerator should use full enumeration method when mass to decompose is too large to encode * it as 32 bit integer with default blowup factor */ @Test public void testUseFullEnumerationWhenExceedIntegerSpace() throws Exception { IsotopeFactory ifac = Isotopes.getInstance(); IIsotope c = ifac.getMajorIsotope("C"); IIsotope h = ifac.getMajorIsotope("H"); IIsotope n = ifac.getMajorIsotope("N"); IIsotope o = ifac.getMajorIsotope("O"); MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(c, 0, 20); mfRange.addIsotope(h, 0, 30); mfRange.addIsotope(o, 0, 15); mfRange.addIsotope(n, 0, 10); MolecularFormulaGenerator generator = new MolecularFormulaGenerator(builder, 1300000, 1300000.1, mfRange); Assert.assertTrue("generator implementation should be instance of FullEnumerationFormulaGenerator", generator.formulaGenerator instanceof FullEnumerationFormulaGenerator); }
/** * Test to find MF=C10000, MW=120000.0 using only carbons. */ @Test public void testCarbons() throws Exception { IsotopeFactory ifac = Isotopes.getInstance(); IIsotope c = ifac.getMajorIsotope("C"); MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(c, 0, 100000); double minMass = 120000.0 - 1; double maxMass = 120000.0 + 1; MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange); IMolecularFormulaSet mfSet = gen.getAllFormulas(); Assert.assertNotNull(mfSet); Assert.assertEquals(1, mfSet.size()); Assert.assertEquals("C10000", MolecularFormulaManipulator .getString(mfSet.getMolecularFormula(0))); }
/** * 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 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 testDefaultValidFalse_SetParam() throws Exception { IRule rule = new ElementRule(); IMolecularFormula formula = new MolecularFormula(); formula.addIsotope(builder.newInstance(IIsotope.class, "C"), 2); formula.addIsotope(builder.newInstance(IIsotope.class, "H"), 6); Object[] params = new Object[1]; MolecularFormulaRange mfRange = new MolecularFormulaRange(); mfRange.addIsotope(builder.newInstance(IIsotope.class, "C"), 1, 2); mfRange.addIsotope(builder.newInstance(IIsotope.class, "H"), 1, 2); params[0] = mfRange; rule.setParameters(params); Assert.assertEquals(0.0, rule.validate(formula), 0.0001); }
/** * 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)); }