code: private static String cleanMFfromCharge(String formula) {
          if (!(formula.contains("[") && formula.contains("]"))) return formula;
          boolean startBreak = false;
          String finalFormula = "";
          for (int f = 0; f < formula.length(); f++) {
              char thisChar = formula.charAt(f);
              if (thisChar == '[') {
                  // start
                  startBreak = true;
              } else if (thisChar == ']') {
                  break;
              } else if (startBreak) finalFormula += thisChar;
          }
          return finalFormula;
      }
docs: Extract the molecular formula when it is defined with charge. e.g. [O3S]2-.
  
  @param formula  The formula to inspect
  @return         The corrected formula