IsotopePatternGenerator { public IsotopePattern getIsotopes(IMolecularFormula molFor) { if (builder == null) { try { isoFactory = Isotopes.getInstance(); builder = molFor.getBuilder(); } catch (Exception e) { e.printStackTrace(); } } String mf = MolecularFormulaManipulator.getString(molFor, true); IMolecularFormula molecularFormula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula(mf, builder); IsotopePattern abundance_Mass = null; for (IIsotope isos : molecularFormula.isotopes()) { String elementSymbol = isos.getSymbol(); int atomCount = molecularFormula.getIsotopeCount(isos); List<IsotopeContainer> additional = new ArrayList<>(); for (IIsotope isotope : isoFactory.getIsotopes(elementSymbol)) { double mass = isotope.getExactMass(); double abundance = isotope.getNaturalAbundance(); if (abundance <= 0.000000001) continue; IsotopeContainer container = new IsotopeContainer(mass, abundance); if (storeFormula) container.setFormula(asFormula(isotope)); additional.add(container); } for (int i = 0; i < atomCount; i++) abundance_Mass = calculateAbundanceAndMass(abundance_Mass, additional); } IsotopePattern isoP = IsotopePatternManipulator.sortAndNormalizedByIntensity(abundance_Mass); isoP = cleanAbundance(isoP, minIntensity); IsotopePattern isoPattern = IsotopePatternManipulator.sortByMass(isoP); return isoPattern; } IsotopePatternGenerator();  IsotopePatternGenerator(double minIntensity); IsotopePatternGenerator setMinIntensity(double minIntensity); IsotopePatternGenerator setMinResolution(double resolution); IsotopePatternGenerator setStoreFormulas(boolean storeFormula); IsotopePattern getIsotopes(IMolecularFormula molFor);  }
@Test public void testGetIsotopes_IMolecularFormula() { IMolecularFormula molFor = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C41H79N8O3P1", builder); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(.1); IsotopePattern isos = isotopeGe.getIsotopes(molFor); Assert.assertEquals(2, isos.getNumberOfIsotopes(), 0.001); }
@Test public void testGetIsotopes_IMolecularFormula_withoutONE() { IMolecularFormula molFor = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C41H79N8O3P", builder); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(.01); IsotopePattern isos = isotopeGe.getIsotopes(molFor); Assert.assertEquals(6, isos.getNumberOfIsotopes(), 0.001); }
@Test public void testGetIsotopes1() { IMolecularFormula molFor = new MolecularFormula(); molFor.addIsotope(builder.newInstance(IIsotope.class, "Br")); molFor.addIsotope(builder.newInstance(IIsotope.class, "Br")); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(.1); IsotopePattern isoPattern = isotopeGe.getIsotopes(molFor); Assert.assertEquals(3, isoPattern.getNumberOfIsotopes()); }
@Test public void testCalculateIsotopesAllBromine() { double[] massResults = {157.836669, 159.834630, 161.832580}; double[] abundResults = {.512, 1.00, .487}; IMolecularFormula molFor = new MolecularFormula(); molFor.addIsotope(builder.newInstance(IIsotope.class, "Br")); molFor.addIsotope(builder.newInstance(IIsotope.class, "Br")); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(.1); IsotopePattern isoPattern = isotopeGe.getIsotopes(molFor); Assert.assertEquals(3, isoPattern.getNumberOfIsotopes()); Assert.assertEquals(massResults[0], isoPattern.getIsotope(0).getMass(), 0.01); Assert.assertEquals(massResults[1], isoPattern.getIsotope(1).getMass(), 0.01); Assert.assertEquals(massResults[2], isoPattern.getIsotope(2).getMass(), 0.01); Assert.assertEquals(abundResults[0], isoPattern.getIsotope(0).getIntensity(), 0.01); Assert.assertEquals(abundResults[1], isoPattern.getIsotope(1).getIntensity(), 0.01); Assert.assertEquals(abundResults[2], isoPattern.getIsotope(2).getIntensity(), 0.01); }
@Test public void testCalculateIsotopesIodemethylidyne() { double[] massResults = {138.904480, 139.907839}; double[] abundResults = {1.00, .011}; IMolecularFormula molFor = new MolecularFormula(); molFor.addIsotope(builder.newInstance(IIsotope.class, "C")); molFor.addIsotope(builder.newInstance(IIsotope.class, "I")); Assert.assertEquals(2, molFor.getIsotopeCount()); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(.01); IsotopePattern isoPattern = isotopeGe.getIsotopes(molFor); Assert.assertEquals(2, isoPattern.getNumberOfIsotopes()); Assert.assertEquals(massResults[0], isoPattern.getIsotope(0).getMass(), 0.01); Assert.assertEquals(massResults[1], isoPattern.getIsotope(1).getMass(), 0.01); Assert.assertEquals(abundResults[0], isoPattern.getIsotope(0).getIntensity(), 0.01); Assert.assertEquals(abundResults[1], isoPattern.getIsotope(1).getIntensity(), 0.01); }
@Test public void testCalculateIsotopesnCarbono() { double[] massResults = {120.000000, 121.003360, 122.006709}; double[] abundResults = {1.00, .108, 0.005}; IMolecularFormula molFor = new MolecularFormula(); molFor.addIsotope(builder.newInstance(IIsotope.class, "C"), 10); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(0.0010); IsotopePattern isoPattern = isotopeGe.getIsotopes(molFor); Assert.assertEquals(3, isoPattern.getNumberOfIsotopes()); Assert.assertEquals(massResults[0], isoPattern.getIsotope(0).getMass(), 0.01); Assert.assertEquals(massResults[1], isoPattern.getIsotope(1).getMass(), 0.01); Assert.assertEquals(massResults[2], isoPattern.getIsotope(2).getMass(), 0.01); Assert.assertEquals(abundResults[0], isoPattern.getIsotope(0).getIntensity(), 0.01); Assert.assertEquals(abundResults[1], isoPattern.getIsotope(1).getIntensity(), 0.01); Assert.assertEquals(abundResults[2], isoPattern.getIsotope(2).getIntensity(), 0.01); }
@Test public void testCalculateIsotopesOrthinine() { double[] massResults = {133.097720, 134.094750, 134.101079, 134.103990, 135.101959, 135.104430}; double[] abundResults = {1.00, .006, .054, 0.002, 0.004, 0.001}; IMolecularFormula molFor = new MolecularFormula(); molFor.addIsotope(builder.newInstance(IIsotope.class, "C"), 5); molFor.addIsotope(builder.newInstance(IIsotope.class, "H"), 13); molFor.addIsotope(builder.newInstance(IIsotope.class, "N"), 2); molFor.addIsotope(builder.newInstance(IIsotope.class, "O"), 2); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(0.0010); IsotopePattern isoPattern = isotopeGe.getIsotopes(molFor); Assert.assertEquals(6, isoPattern.getNumberOfIsotopes()); Assert.assertEquals(massResults[0], isoPattern.getIsotope(0).getMass(), 0.01); Assert.assertEquals(massResults[1], isoPattern.getIsotope(1).getMass(), 0.01); Assert.assertEquals(massResults[2], isoPattern.getIsotope(2).getMass(), 0.01); Assert.assertEquals(massResults[3], isoPattern.getIsotope(3).getMass(), 0.01); Assert.assertEquals(massResults[4], isoPattern.getIsotope(4).getMass(), 0.01); Assert.assertEquals(massResults[5], isoPattern.getIsotope(5).getMass(), 0.01); Assert.assertEquals(abundResults[0], isoPattern.getIsotope(0).getIntensity(), 0.01); Assert.assertEquals(abundResults[1], isoPattern.getIsotope(1).getIntensity(), 0.01); Assert.assertEquals(abundResults[2], isoPattern.getIsotope(2).getIntensity(), 0.01); Assert.assertEquals(abundResults[3], isoPattern.getIsotope(3).getIntensity(), 0.01); Assert.assertEquals(abundResults[4], isoPattern.getIsotope(4).getIntensity(), 0.01); Assert.assertEquals(abundResults[5], isoPattern.getIsotope(5).getIntensity(), 0.01); }
@Test public void testCalculateIsotopesMn() { IMolecularFormula molFor = new MolecularFormula(); molFor.addIsotope(builder.newInstance(IIsotope.class, "Mn"), 1); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(0.001); IsotopePattern isoPattern = isotopeGe.getIsotopes(molFor); Assert.assertEquals(1, isoPattern.getNumberOfIsotopes()); }
@Test public void testCalculateIsotopesC10000() { IMolecularFormula molFor = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C10000", builder); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(.1); IsotopePattern isos = isotopeGe.getIsotopes(molFor); Assert.assertEquals(44, isos.getNumberOfIsotopes()); for (int i = 0; i < isos.getNumberOfIsotopes(); i++) Assert.assertTrue(isos.getIsotope(i).getMass() > 120085); }
@Test public void testGeneratorSavesState() { IsotopePatternGenerator isogen = new IsotopePatternGenerator(.1); IMolecularFormula mf1 = MolecularFormulaManipulator.getMolecularFormula("C6H12O6", builder); IsotopePattern ip1 = isogen.getIsotopes(mf1); Assert.assertEquals(1, ip1.getNumberOfIsotopes()); IMolecularFormula mf2 = MolecularFormulaManipulator.getMolecularFormula("C6H12O6", builder); IsotopePattern ip2 = isogen.getIsotopes(mf2); Assert.assertEquals(1, ip2.getNumberOfIsotopes()); }
@Test public void testGetIsotopes_IMolecularFormula_Charged() { IsotopePatternGenerator isogen = new IsotopePatternGenerator(.1); IMolecularFormula mfPositive = MolecularFormulaManipulator.getMolecularFormula("C6H11O6Na", builder); mfPositive.setCharge(1); IsotopePattern ip1 = isogen.getIsotopes(mfPositive); Assert.assertEquals(1, ip1.getNumberOfIsotopes()); isogen = new IsotopePatternGenerator(.1); IMolecularFormula mfNeutral = MolecularFormulaManipulator.getMolecularFormula("C6H12O6Na", builder); mfNeutral.setCharge(0); IsotopePattern ip2 = isogen.getIsotopes(mfNeutral); Assert.assertEquals(1, ip2.getNumberOfIsotopes()); Assert.assertNotEquals(ip1.getIsotope(0).getMass(), ip2.getIsotope(0).getMass()); }
@Test public void testGetIsotopes_IMolecularFormula_deprotonate() { IsotopePatternGenerator isogen = new IsotopePatternGenerator(.1); IMolecularFormula mf1 = MolecularFormulaManipulator.getMolecularFormula("C6H12O6", builder); MolecularFormulaManipulator.adjustProtonation(mf1, -1); IsotopePattern ip1 = isogen.getIsotopes(mf1); Assert.assertEquals(1, ip1.getNumberOfIsotopes()); isogen = new IsotopePatternGenerator(.1); IMolecularFormula mf2 = MolecularFormulaManipulator.getMolecularFormula("C6H11O6", builder); IsotopePattern ip2 = isogen.getIsotopes(mf2); Assert.assertEquals(1, ip2.getNumberOfIsotopes()); Assert.assertEquals(ip1.getIsotope(0).getMass(), ip2.getIsotope(0).getMass(), 0.001); }