peakml.chemistry
Class MolecularFormula

java.lang.Object
  extended by peakml.chemistry.MolecularFormula

public class MolecularFormula
extends java.lang.Object

Implementation of a container keeping track of the atom counts for a molecular formula. Several convenience methods are provided, including a string parser, validity checks and molecular formula math (subtraction and addition of other molecular formulae to this molecular formula).


Nested Class Summary
static class MolecularFormula.SubFormula
           
 
Constructor Summary
MolecularFormula()
          Constructs an empty formula.
MolecularFormula(MolecularFormula formula)
          Copy-constructor, which copies the complete contents of the given instance.
MolecularFormula(java.lang.String formula)
          Constructs a new class with the given formula by calling Init(String,String).
MolecularFormula(java.lang.String iontype, java.lang.String formula)
           
 
Method Summary
 boolean equals(java.lang.Object other)
           
 int getCharge()
          Returns the charge on the molecule.
 double getMass(Mass masstype)
          Calculates the mass for this molecular formula.
 double getMassVariance()
          Calculates the mass-variance of the molecule.
 int getNrAtoms()
          Counts the total amount of atoms in the molecule, without taking an atom type into account.
 int getNrAtoms(int atomid)
           
 int getNrAtoms(int atomid, int subformulaindex)
           
 java.util.Vector<MolecularFormula.SubFormula> getSubFormulas()
           
 boolean isValid()
          Validity check for molecular formulae.
static void main(java.lang.String[] args)
           
 void setNrAtoms(int atomid, int count)
           
 void setNrAtoms(int atomid, int count, int subformulaindex)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MolecularFormula

public MolecularFormula()
Constructs an empty formula. The Init(String,String) function can be used to initialize a real molecular formula.


MolecularFormula

public MolecularFormula(java.lang.String formula)
Constructs a new class with the given formula by calling Init(String,String).

Parameters:
formula - The molecular formula to initialize to.

MolecularFormula

public MolecularFormula(java.lang.String iontype,
                        java.lang.String formula)

MolecularFormula

public MolecularFormula(MolecularFormula formula)
Copy-constructor, which copies the complete contents of the given instance.

Parameters:
formula - The molecular formula instance to copy.
Method Detail

getSubFormulas

public java.util.Vector<MolecularFormula.SubFormula> getSubFormulas()

getCharge

public int getCharge()
Returns the charge on the molecule. A positive value corresponds to a positive charge and visa-versa. A value bigger than 1 means there are multiple charges on the molecule.

Returns:
The charge on the molecule.

getNrAtoms

public int getNrAtoms()
Counts the total amount of atoms in the molecule, without taking an atom type into account.

Returns:
The total number of atoms in the molecular formula.

getNrAtoms

public int getNrAtoms(int atomid)

getNrAtoms

public int getNrAtoms(int atomid,
                      int subformulaindex)

setNrAtoms

public void setNrAtoms(int atomid,
                       int count)

setNrAtoms

public void setNrAtoms(int atomid,
                       int count,
                       int subformulaindex)

getMass

public double getMass(Mass masstype)
Calculates the mass for this molecular formula. The parameter masstype indicates whether the molecular mass or the monoisotopic mass should be calculated.

Parameters:
masstype - Indicates whether to use molecular or monoisotopic weight.

getMassVariance

public double getMassVariance()
Calculates the mass-variance of the molecule.

Returns:
The mass variance for the molecule.

isValid

public boolean isValid()
Validity check for molecular formulae.

Returns:
Returns true when the molecule conforms to all the validity checks.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

main

public static void main(java.lang.String[] args)