MolecularFormulaManipulator { public static String getString(IMolecularFormula formula, String[] orderElements, boolean setOne) { return getString(formula, orderElements, setOne, true); }  static int getAtomCount(IMolecularFormula formula); static int getElementCount(IMolecularFormula formula, IElement element); static int getElementCount(IMolecularFormula formula, IIsotope isotope); static int getElementCount(IMolecularFormula formula, String symbol); static List<IIsotope> getIsotopes(IMolecularFormula formula, IElement element); static List<IElement> elements(IMolecularFormula formula); static boolean containsElement(IMolecularFormula formula, IElement element); static IMolecularFormula removeElement(IMolecularFormula formula, IElement element); static String getString(IMolecularFormula formula, String[] orderElements,
                                   boolean setOne); static String getString(IMolecularFormula formula, String[] orderElements,
                                   boolean setOne, boolean setMassNumber); static String getString(IMolecularFormula formula); static String getString(IMolecularFormula formula, boolean setOne); static String getString(IMolecularFormula formula, boolean setOne, boolean setMassNumber); static List<IIsotope> putInOrder(String[] orderElements, IMolecularFormula formula); @Deprecated static String getHillString(IMolecularFormula formula); static String getHTML(IMolecularFormula formula); static String getHTML(IMolecularFormula formula, boolean chargeB, boolean isotopeB); static String getHTML(IMolecularFormula formula, String[] orderElements, boolean showCharge, boolean showIsotopes); static IMolecularFormula getMolecularFormula(String stringMF, IChemObjectBuilder builder); static IMolecularFormula getMajorIsotopeMolecularFormula(String stringMF, IChemObjectBuilder builder); static IMolecularFormula getMolecularFormula(String stringMF, IMolecularFormula formula); @Deprecated static double getTotalExactMass(IMolecularFormula formula); static double getTotalMassNumber(IMolecularFormula formula); static double getMass(IMolecularFormula mf, int flav); static double getMass(IMolecularFormula mf); @Deprecated static double getNaturalExactMass(IMolecularFormula formula); @Deprecated static double getMajorIsotopeMass(IMolecularFormula formula); static double getTotalNaturalAbundance(IMolecularFormula formula); static double getDBE(IMolecularFormula formula); static IMolecularFormula getMolecularFormula(IAtomContainer atomContainer); static IMolecularFormula getMolecularFormula(IAtomContainer atomContainer, IMolecularFormula formula); static IAtomContainer getAtomContainer(IMolecularFormula formula); static IAtomContainer getAtomContainer(IMolecularFormula formula, IAtomContainer atomContainer); static IAtomContainer getAtomContainer(String formulaString, IChemObjectBuilder builder); static String[] generateOrderEle(); static boolean compare(IMolecularFormula formula1, IMolecularFormula formula2); static List<IElement> getHeavyElements(IMolecularFormula formula); static String simplifyMolecularFormula(String formula); static boolean adjustProtonation(IMolecularFormula mf, int hcnt); static IMolecularFormula getMostAbundant(IMolecularFormula mf); static IMolecularFormula getMostAbundant(IAtomContainer mol); static final int MolWeight; static final int MolWeightIgnoreSpecified; static final int MonoIsotopic; static final int MostAbundant; static final Comparator<IIsotope> NAT_ABUN_COMP; }
@Test public void testGetString_IMolecularFormula_arrayString_boolean() { IMolecularFormula formula = new MolecularFormula(); formula.addIsotope(builder.newInstance(IIsotope.class, "C"), 2); formula.addIsotope(builder.newInstance(IIsotope.class, "H"), 2); Assert.assertEquals("C2H2", MolecularFormulaManipulator.getString(formula)); String[] newOrder = new String[2]; newOrder[0] = "H"; newOrder[1] = "C"; Assert.assertEquals("H2C2", MolecularFormulaManipulator.getString(formula, newOrder, true)); }
@Test public void testGetString_IMolecularFormula() { IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newInstance(IIsotope.class, "C"), 10); mf1.addIsotope(builder.newInstance(IIsotope.class, "H"), 16); Assert.assertEquals("C10H16", MolecularFormulaManipulator.getString(mf1)); IMolecularFormula mf2 = new MolecularFormula(); mf2.addIsotope(builder.newInstance(IAtom.class, "H"), 16); mf2.addIsotope(builder.newInstance(IAtom.class, "C"), 10); Assert.assertEquals("C10H16", MolecularFormulaManipulator.getString(mf2)); Assert.assertEquals(MolecularFormulaManipulator.getString(mf2), MolecularFormulaManipulator.getString(mf1)); }
@Test public void testBug2276507() { IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); mf1.addIsotope(builder.newInstance(IIsotope.class, "H"), 4); Assert.assertEquals("CH4", MolecularFormulaManipulator.getString(mf1)); }
@Test public void testGetString_IMolecularFormula_boolean() { IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newInstance(IIsotope.class, "C"), 1); mf1.addIsotope(builder.newInstance(IIsotope.class, "H"), 4); Assert.assertEquals("C1H4", MolecularFormulaManipulator.getString(mf1, true)); }
@Test public void testGetString_Isotopes() { IMolecularFormula mf1 = new MolecularFormula(); mf1.addIsotope(builder.newInstance(IIsotope.class, "C", 12), 9); mf1.addIsotope(builder.newInstance(IIsotope.class, "C", 13), 1); mf1.addIsotope(builder.newInstance(IIsotope.class, "H"), 16); Assert.assertEquals("C10H16", MolecularFormulaManipulator.getString(mf1)); }
@Test public void testMassNumberDisplay() throws Exception { IsotopeFactory ifac = Isotopes.getInstance(); IIsotope br81 = ifac.getIsotope("Br", 81); IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); IMolecularFormula mf = bldr.newInstance(IMolecularFormula.class); mf.addIsotope(new Atom("C"), 7); mf.addIsotope(new Atom("O"), 3); mf.addIsotope(new Atom("H"), 3); mf.addIsotope(new Atom("Br"), 1); mf.addIsotope(ifac.getIsotope("Br", 81), 1); assertThat(MolecularFormulaManipulator.getString(mf, false, false), is("C7H3Br2O3")); assertThat(MolecularFormulaManipulator.getString(mf, false, true), is("C7H3Br[81]BrO3")); }
@Test public void testMassNumberDisplayWithDefinedIsotopes() throws Exception { IsotopeFactory ifac = Isotopes.getInstance(); IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); IMolecularFormula mf = bldr.newInstance(IMolecularFormula.class); mf.addIsotope(ifac.getMajorIsotope("C"), 7); mf.addIsotope(ifac.getMajorIsotope("O"), 3); mf.addIsotope(ifac.getMajorIsotope("H"), 3); mf.addIsotope(ifac.getMajorIsotope("Br"), 1); mf.addIsotope(ifac.getIsotope("Br", 81), 1); Isotopes.clearMajorIsotopes(mf); assertThat(MolecularFormulaManipulator.getString(mf, false, false), is("C7H3Br2O3")); assertThat(MolecularFormulaManipulator.getString(mf, false, true), is("C7H3Br[81]BrO3")); }
@Test public void testGetString_IMolecularFormula_Empty() { String stringMF = MolecularFormulaManipulator.getString(new MolecularFormula()); Assert.assertNotNull(stringMF); Assert.assertEquals("", stringMF); }