I needed a simple way to calculate the exact mass for a couple of millions compounds and so decided to give it another try with the CDK.
After googleing a bit I found something what put me in the right direction and worked with the current version of the cdk, so it was rather simple
class ConvertInchi {
  /**
   * converts an inchi code to a molare mass
   * @param inchi
   * @return
   */
  public static double convertInchiToMolareMass(String inchi) {
    IMolecularFormula moleculeFormula = MolecularFormulaManipulator.getMolecularFormula(convertInchiToMolecularFormula(inchi),DefaultChemObjectBuilder.getInstance())
    return MolecularFormulaManipulator.getTotalExactMass(moleculeFormula)
  }
  /**
   *
   * converts an inchi to a molecular formula
   * @param
   inchi
   * @return
   */
  public static String convertInchiToMolecularFormula(String inchi) {
    return inchi.split("/")[1]
  }
}
March
7 years ago
No comments:
Post a Comment