Search in sources :

Example 1 with ExplicitHydrogenRepresentationException

use of de.ipbhalle.metfraglib.exceptions.ExplicitHydrogenRepresentationException in project MetFragRelaunched by ipb-halle.

the class ByteMolecularFormula method initialise.

/**
 * initialise molecular formula by molecular structure
 *
 * @param molecule
 * @throws ExplicitHydrogenRepresentationException
 */
protected void initialise(IMolecularStructure precursorMolecule) throws de.ipbhalle.metfraglib.exceptions.ExplicitHydrogenRepresentationException, de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException {
    this.numberHydrogens = 0;
    java.util.Map<Byte, Short> elementsToCount = new java.util.HashMap<Byte, Short>();
    int numberElementsPresentInPrecursorMolecule = 0;
    for (int i = 0; i < precursorMolecule.getStructureAsIAtomContainer().getAtomCount(); i++) {
        String currentAtomSymbol = this.getAtomSymbol(precursorMolecule.getStructureAsIAtomContainer().getAtom(i));
        byte byteToAtomSymbol = (byte) Constants.ELEMENTS.indexOf(currentAtomSymbol);
        if (byteToAtomSymbol == 0 || byteToAtomSymbol == -1)
            this.containsC = true;
        if (byteToAtomSymbol == -1) {
            throw new de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException(currentAtomSymbol + " not found");
        }
        if (currentAtomSymbol.equals("H"))
            throw new de.ipbhalle.metfraglib.exceptions.ExplicitHydrogenRepresentationException();
        if (elementsToCount.containsKey(byteToAtomSymbol))
            elementsToCount.put(byteToAtomSymbol, (short) (elementsToCount.get(byteToAtomSymbol) + 1));
        else {
            elementsToCount.put(byteToAtomSymbol, (short) 1);
            numberElementsPresentInPrecursorMolecule++;
        }
        this.numberHydrogens += precursorMolecule.getStructureAsIAtomContainer().getAtom(i).getImplicitHydrogenCount();
    }
    java.util.Iterator<Byte> keys = elementsToCount.keySet().iterator();
    int index = 0;
    this.atomsAsIndeces = new byte[numberElementsPresentInPrecursorMolecule];
    this.numberOfAtoms = new short[numberElementsPresentInPrecursorMolecule];
    while (keys.hasNext()) {
        byte atomSymbol = keys.next();
        this.atomsAsIndeces[index] = atomSymbol;
        this.numberOfAtoms[index] = elementsToCount.get(atomSymbol);
        index++;
    }
}
Also used : AtomTypeNotKnownFromInputListException(de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException) ExplicitHydrogenRepresentationException(de.ipbhalle.metfraglib.exceptions.ExplicitHydrogenRepresentationException)

Aggregations

AtomTypeNotKnownFromInputListException (de.ipbhalle.metfraglib.exceptions.AtomTypeNotKnownFromInputListException)1 ExplicitHydrogenRepresentationException (de.ipbhalle.metfraglib.exceptions.ExplicitHydrogenRepresentationException)1