Class MassCalc

java.lang.Object
com.compomics.util.general.MassCalc

public class MassCalc
extends Object
This class takes care of mass calculation, based on a sequence in IUPAC format.
By default it can handle monoisotopic biochemical element masses and monoisotopic single-letter amino acid masses.
The object can be customized with your own mass lists through the use of a properties file, or by directly passing a HashMap.

Please note: if you decide on your own lists, be sure to follow the following guidelines:
  • An element (key in properties file or HashMap) can be ONE or TWO letters. The first ALWAYS has to be UPPERCASE, the optional second ALWAYS has to be lowercase.
  • A value has to be a parseable number for a properties file, or a Double instance for the HashMap. No other formats are accepted!
Author:
Lennart Martens
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int MONOAA
    Index for the monoisotopic aminoacid masses.
    static int MONOELEMENTS
    Index for the monoisotopic masses of the biochemically relevant elements.
    static int MONONUCLEOTIDES
    Index for the monoisotopic nucleotide masses.
    static int SELFDEFINED
    Value for the self-defined masses.
  • Constructor Summary

    Constructors 
    Constructor Description
    MassCalc()
    Default constructor.
    MassCalc​(int aMassListIdentifier)
    This constructor allows you to specify an identifier to select a element list to use for calculating a mass.
    MassCalc​(int aMassListIdentifier, HashMap aSupplElementList)
    This constructor allows the caller to supplement (or to replace elements in) a built-in elementlist with a HashMap of its own design.
    MassCalc​(String aFilename)
    This constructor allows the caller to use an elementlist of its own making.
    MassCalc​(HashMap aElementList)
    This constructor allows the caller to initialize the elementlist with a HashMap of its own design.
  • Method Summary

    Modifier and Type Method Description
    double calculateMass​(String aFormula)
    This method attempts to calculate the mass of a chemical formula.
    static void main​(String[] args)
    The main method can be used for command-line usage of this class.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • MassCalc

      public MassCalc()
      Default constructor. The mass list to be used defaults to the monoisotopic masses for biochemically relevant elements.
    • MassCalc

      public MassCalc​(int aMassListIdentifier)
      This constructor allows you to specify an identifier to select a element list to use for calculating a mass.
      Please use the finalo vriables on this class as identifiers!
      Parameters:
      aMassListIdentifier - int with the identifier for the elementlist to use.
    • MassCalc

      public MassCalc​(String aFilename)
      This constructor allows the caller to use an elementlist of its own making. Simply passing the filename of the file suffices.
      Parameters:
      aFilename - String with the name of the file to be loaded. NOTE! this file must be located in the classpath and mst be a simple properties file!
    • MassCalc

      public MassCalc​(HashMap aElementList)
      This constructor allows the caller to initialize the elementlist with a HashMap of its own design.
      This HashMap needs be structured in the following way:
      • KEY can be one or two letters, the first has to be uppercase, the second and optional letter has to be lowercase.
      • VALUE must be a Double value
      Parameters:
      aElementList - HashMap with the elementlist to use.
    • MassCalc

      public MassCalc​(int aMassListIdentifier, HashMap aSupplElementList)
      This constructor allows the caller to supplement (or to replace elements in) a built-in elementlist with a HashMap of its own design.
      This HashMap needs be structured in the following way:
      • KEY can be one or two letters, the first has to be uppercase, the second and optional letter has to be lowercase.
      • VALUE must be a Double value
      Parameters:
      aMassListIdentifier - int with the identifier for the built-in elementlist to use.
      aSupplElementList - HashMap with the supplementary elementlist to use.
  • Method Details

    • calculateMass

      public double calculateMass​(String aFormula) throws UnknownElementMassException
      This method attempts to calculate the mass of a chemical formula. It cannot calculate the mass of an element if it is not known to this class (i.e.: if it does not occur in the Properties instance). In that case it will flag an exception.
      Parameters:
      aFormula - String with the chemical formula (or bruto formula) of the compound in question.
      Returns:
      double with the mass of the compound.
      Throws:
      UnknownElementMassException - when one of the composing elements' mass is unknown to the class.
    • main

      public static void main​(String[] args)
      The main method can be used for command-line usage of this class. The parameters should be (a) chemical (or bruto) formula(e) to calculate the mass for.
      Parameters:
      args - String[] at least one chemical formula should be specified, up to as much as you can cramp into a single command-line.