code: private static IMolecularFormula getMolecularFormula(String stringMF, IMolecularFormula formula,
              boolean assumeMajorIsotope) {
  
          if (stringMF.contains(".") || stringMF.contains("(") || stringMF.length() > 0 && stringMF.charAt(0) >= '0' && stringMF.charAt(0) <= '9')
              stringMF = simplifyMolecularFormula(stringMF);
  
          // Extract charge from String when contains []X- format
          Integer charge = null;
          if ((stringMF.contains("[") && stringMF.contains("]")) && (stringMF.contains("+") || stringMF.contains(HYPHEN_STR) || stringMF.contains(MINUS_STR))) {
              charge = extractCharge(stringMF);
              stringMF = cleanMFfromCharge(stringMF);
          }
          if (stringMF.isEmpty())
              return null;
          int len = stringMF.length();
          CharIter iter = new CharIter();
          iter.str = stringMF;
          while (iter.pos < len) {
              if (!parseIsotope(iter, formula, assumeMajorIsotope)) {
                  LoggingToolFactory.createLoggingTool(MolecularFormulaManipulator.class)
                      .error("Could not parse MF: " + iter.str);
                  return null;
              }
          }
  
          if (charge != null) formula.setCharge(charge);
          return formula;
      }
docs: Add to an instance of IMolecularFormula the elements extracts form
  molecular formula string. The string is immediately analyzed and a set of Nodes
  is built based on this analysis. The hydrogens are assumed to be implicit.
  The boolean indicates if the major isotope is to be assumed, or if no
  assumption is to be made.
  
  @param  stringMF           The molecularFormula string
  @param  assumeMajorIsotope If true, it will take the major isotope for each element
  @return                    The filled IMolecularFormula
  @see                       #getMolecularFormula(String, org.openscience.cdk.interfaces.IChemObjectBuilder)
  @see #getMolecularFormula(String, boolean, org.openscience.cdk.interfaces.IChemObjectBuilder)