Package chemaxon.util

Class MolHandler


  • @PublicAPI
    public class MolHandler
    extends chemaxon.util.MolHandlerBase
    Class for handling molecules for systems based on ChemAxon's programming interface. A MolHandler object contains the structure of a molecule.
    Operations on the object:
    • retrieving the molecule
    • adding and removing Hydrogens
    • replacing bonds in aromatic systems to aromatic bonds
    • calculating molecular weight and formula
    • etc.
    • Field Detail

      • molAlignerSet

        protected boolean molAlignerSet
    • Constructor Detail

      • MolHandler

        public MolHandler()
        Creates an uninitialized MolHandler object.
      • MolHandler

        public MolHandler​(Molecule mol)
        Creates a MolHandler object from a Molecule.
        Parameters:
        mol - a clone of this parameter is stored in the MolHandler object
      • MolHandler

        public MolHandler​(String molecule)
                   throws MolFormatException
        Creates a MolHandler object from a String.
        Parameters:
        molecule - the String must contain a molecule in MDL's Molfile or Compressed Molfile or Smiles format.
        Throws:
        MolFormatException - if the importer encounters a problem
      • MolHandler

        public MolHandler​(String molecule,
                          boolean queryMode)
                   throws MolFormatException
        Creates a MolHandler object from a String.
        Parameters:
        molecule - the String must contain a molecule in MDL's Molfile or Compressed Molfile or Smiles format.
        queryMode - if set to trueSMILES strings are imported as SMARTS. Default is false.
        Throws:
        MolFormatException - if the importer encounters a problem
        Since:
        2.2
      • MolHandler

        public MolHandler​(byte[] molecule)
                   throws MolFormatException
        Creates a MolHandler object from a byte array.
        Parameters:
        molecule - the byte array must contain a molecule in MDL's Molfile or Compressed Molfile or Smiles format.
        Throws:
        MolFormatException - if the importer encounters a problem
      • MolHandler

        public MolHandler​(byte[] molecule,
                          boolean queryMode)
                   throws MolFormatException
        Creates a MolHandler object from a byte array.
        Parameters:
        molecule - the byte array must contain a molecule in MDL's Molfile or Compressed Molfile or Smiles format
        queryMode - if set to trueSMILES strings are imported as SMARTS. Default is false.
        Throws:
        MolFormatException - if the importer encounters a problem since 2.2
    • Method Detail

      • setMolecule

        public void setMolecule​(Molecule molecule)
        Initializes a MolHandler object from a Molecule.
        Parameters:
        molecule - a clone of this parameter is stored in the MolHandler object
      • setMolecule

        public void setMolecule​(String molecule)
                         throws MolFormatException
        Sets the molecule.
        Overrides:
        setMolecule in class chemaxon.util.MolHandlerBase
        Parameters:
        molecule - the molecule to load into this molhandler
        Throws:
        MolFormatException - if the importer encounters a problem
      • setMolecule

        public void setMolecule​(byte[] molecule)
                         throws MolFormatException
        Initializes a MolHandler object from a byte array.
        Parameters:
        molecule - the byte array must contain a molecule in MDL's Molfile or Compressed Molfile or Smiles format.
        Throws:
        MolFormatException - if the importer encounters a problem
      • getAtomCount

        public int getAtomCount()
        Retrieves the number of atoms in the Molecule stored in the MolHandler object.
        Returns:
        the atomcount of the current molecule
      • getHeavyAtomCount

        public int getHeavyAtomCount()
        Retrieves the number of non-hydrogen atoms in the Molecule stored in the MolHandler object.
        Returns:
        the heavyatomcount of the current molecule
      • addHydrogens

        public void addHydrogens()
        Adds explicit H atoms instead of the current implicit ones.
      • addHydrogensToAromaticHeteroAtoms

        public void addHydrogensToAromaticHeteroAtoms()
        Adds the implicit Hydrogen atoms to heteroatoms in aromatic rings. The coordinates of the H atoms set to 0.
      • removeHydrogens

        public void removeHydrogens()
        Removes all hydrogen atoms.
      • removeHydrogensFromCarbons

        public void removeHydrogensFromCarbons()
        Removes Hydrogen atoms attached to Carbon atoms.
      • containsHydrogens

        public boolean containsHydrogens()
        True if the molecule contains explicit Hydrogen atoms, false otherwise.
        Returns:
        if the molecule contains at least one explicit H
      • aromatize

        public void aromatize()
        Converts the bonds in an aromatic system entered using single and double bonds to aromatic bonds.
      • calcMolWeight

        public float calcMolWeight()
        Calculates the molecular weight of the molecule. In the case of query structures 0 is returned.
        Returns:
        the molweight
      • calcMolWeightInDouble

        public double calcMolWeightInDouble()
        Calculates the molecular weight of the molecule. Returns a double value.
        Returns:
        the molweight
      • calcMolFormula

        public String calcMolFormula()
        Calculates the molecular formula of the molecule. The symbols are listed in Hill Order: C is listed first, followed by H, followed by the remaining elements in alphabetical order.
        Returns:
        the formula of the molecule
      • clean

        public void clean​(boolean always,
                          String options)
        Calculates 2D coordinates. The bond length is set to 0.825. The calculation uses the O1 option of cleaning.
        Parameters:
        always - if false then cleaning will only be performed if the present coordinates are different from zero.
        options - specifies the options used for 2D calculation. (E.g.: "O1e")
        See Also:
        MoleculeGraph.clean(int,java.lang.String)
      • toFormat

        public String toFormat​(String format)
        Converts the molecule to the specified text format.
        Parameters:
        format - "mol", "csmol", "smiles", ...
        The documentation of marvin details all the possible formats.
        Returns:
        the export result
      • toBinFormat

        public byte[] toBinFormat​(String format)
        Converts the molecule to the specified binary format.
        Parameters:
        format - "png", "jpeg", "ppm", ...
        The documentation of marvin details all the possible formats.
        Returns:
        the export result
        Since:
        JChem 2.2
      • generateFingerprintInInts

        public int[] generateFingerprintInInts​(int numberOfInts,
                                               int numberOfOnes,
                                               int numberOfBonds)
        Generates chemical hashed fingerprint for the molecule and returns it in int units.
        NOTE: The structure should be standardized (including aromatization) before fingerprint generation.
        Parameters:
        numberOfInts - the length of the binary fingerprint in int (32 bit) units.
        numberOfOnes - the number of bits to switch on for each pattern.
        numberOfBonds - the maximum length of edges in patterns used for generating the fingerprint.
        Returns:
        an int array of the fingerprint
        Since:
        JChem 3.1
        See Also:
        generateFingerprintInBytes(int, int, int)
      • generateFingerprintInBytes

        public byte[] generateFingerprintInBytes​(int numberOfInts,
                                                 int numberOfOnes,
                                                 int numberOfBonds)
        Generates chemical hashed fingerprint for the molecule and returns it in byte units.
        NOTE: The structure should be standardized (including aromatization) before fingerprint generation.
        Parameters:
        numberOfInts - the length of the binary fingerprint in int (32 bit) units.
        numberOfOnes - the number of bits to switch on for each pattern.
        numberOfBonds - the maximum length of edges in patterns used for generating the fingerprint.
        Returns:
        an byte array of the fingerprint
        Since:
        JChem 3.1
        See Also:
        generateFingerprintInInts(int, int, int)
      • getImplicitHCount

        public int getImplicitHCount()
        Counts the number of implicit hydrogens on the molecule
        Returns:
        the number of implicit hydrogens
      • align

        public double align​(Molecule mol,
                            int[] indexes)
                     throws IllegalArgumentException
        Alignes (rotates) a specified molecule realtive to the contained molecule according to the specified atom pairs.
        NOTE: S-groups in the MolHandler contained molecule will be expanded.
        Parameters:
        mol - the molecule to be aligned
        indexes - the atom indexes of the pattern in the order of the atoms of the molecule to be aligned. Negative values are ignored. The size of this array should be at least the number of atoms in the pattern molecule (in case of RgMolecules, the number of non R-group atoms of the root structure). If the size of the array is grater, the excess elements are ignored.
        Returns:
        the error value of the alignment, can be used to try to align multiple hits and choose the best solution.
        Throws:
        IllegalArgumentException - if encountered
      • getQueryMode

        public boolean getQueryMode()
        Gets query mode. SMILES strings are imported as SMARTS if query mode is set.
        Returns:
        query mode
        Since:
        JChem 2.2
      • isPlainH

        public static boolean isPlainH​(MolAtom atom)
        Decides if atom is a plain H atom.
        Parameters:
        atom - MolAtom to decide.
        Returns:
        true if atom is an uncharged, nonisotopic hydrogen.
        Since:
        JChem 3.2