public static double getMass(IMolecularFormula mf, int flav) {
        final Isotopes isofact;
        try {
            isofact = Isotopes.getInstance();
        } catch (IOException e) {
            throw new IllegalStateException("Could not load Isotopes!");
        }

        double mass = 0;
        switch (flav & 0xf) {
            case MolWeight:
                for (IIsotope iso : mf.isotopes()) {
                    mass += mf.getIsotopeCount(iso) *
                            getMassOrAvg(isofact, iso);
                }
                break;
            case MolWeightIgnoreSpecified:
                for (IIsotope iso : mf.isotopes()) {
                    mass += mf.getIsotopeCount(iso) *
                            isofact.getNaturalMass(iso.getAtomicNumber());
                }
                break;
            case MonoIsotopic:
                for (IIsotope iso : mf.isotopes()) {
                    mass += mf.getIsotopeCount(iso) *
                            getExactMass(isofact, iso);
                }
                break;
            case MostAbundant:
                IMolecularFormula mamf = getMostAbundant(mf);
                if (mamf != null)
                    mass = getMass(mamf, MonoIsotopic);
                break;
        }
        return mass;
    }
public static double getMass ( IMolecularFormula mf , int flav ) { final Isotopes isofact ; try { isofact = Isotopes . getInstance ( ) ; } catch ( IOException e ) { throw new IllegalStateException ( "Could not load Isotopes!" ) ; } double mass = 0 ; switch ( flav & 0xf ) { case MolWeight : for ( IIsotope iso : mf . isotopes ( ) ) { mass += mf . getIsotopeCount ( iso ) * getMassOrAvg ( isofact , iso ) ; } break ; case MolWeightIgnoreSpecified : for ( IIsotope iso : mf . isotopes ( ) ) { mass += mf . getIsotopeCount ( iso ) * isofact . getNaturalMass ( iso . getAtomicNumber ( ) ) ; } break ; case MonoIsotopic : for ( IIsotope iso : mf . isotopes ( ) ) { mass += mf . getIsotopeCount ( iso ) * getExactMass ( isofact , iso ) ; } break ; case MostAbundant : IMolecularFormula mamf = getMostAbundant ( mf ) ; if ( mamf != null ) mass = getMass ( mamf , MonoIsotopic ) ; break ; } return mass ; }
Calculate the mass of a formula, this function takes an optional
'mass flavour' that switches the computation type. The key distinction
is how specified/unspecified isotopes are handled. A specified isotope
is an atom that has either {@link IAtom#setMassNumber(Integer)}
or {@link IAtom#setExactMass(Double)} set to non-null and non-zero.
<br>
The flavours are:
<br>
<ul>
<li>{@link #MolWeight} (default) - uses the exact mass of each
atom when an isotope is specified, if not specified the average mass
of the element is used.</li>
<li>{@link #MolWeightIgnoreSpecified} - uses the average mass of each
element, ignoring any isotopic/exact mass specification</li>
<li>{@link #MonoIsotopic} - uses the exact mass of each
atom when an isotope is specified, if not specified the major isotope
mass for that element is used.</li>
<li>{@link #MostAbundant} - uses the exact mass of each atom when
specified, if not specified a distribution is calculated and the
most abundant isotope pattern is used.</li>
</ul>

@param mf molecular formula
@param flav flavor
@return the mass of the molecule
@see #getMass(IMolecularFormula, int)
@see #MolWeight
@see #MolWeightIgnoreSpecified
@see #MonoIsotopic
@see #MostAbundant