Package chemaxon.util

Class MolHandler

java.lang.Object
chemaxon.util.MolHandler

@PublicApi public class MolHandler extends Object
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 Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Molecule
     
    protected MolAligner
     
    protected boolean
     
    protected boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an uninitialized MolHandler object.
    MolHandler(byte[] molecule)
    Creates a MolHandler object from a byte array.
    MolHandler(byte[] molecule, boolean queryMode)
    Creates a MolHandler object from a byte array.
    Creates a MolHandler object from a Molecule.
    MolHandler(String molecule)
    Creates a MolHandler object from a String.
    MolHandler(String molecule, boolean queryMode)
    Creates a MolHandler object from a String.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds explicit H atoms instead of the current implicit ones.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    double
    align(Molecule mol, int[] indexes)
    Alignes (rotates) a specified molecule realtive to the contained molecule according to the specified atom pairs.
    void
    Converts the bonds in an aromatic system entered using single and double bonds to aromatic bonds.
    void
    aromatize(int method)
    Converts the bonds in an aromatic system entered using single and double bonds to aromatic bonds.
    Calculates the molecular formula of the molecule.
    float
    Calculates the molecular weight of the molecule.
    double
    Calculates the molecular weight of the molecule.
    void
    clean(boolean always, String options)
    Calculates 2D coordinates.
    boolean
    True if the molecule contains explicit Hydrogen atoms, false otherwise.
    byte[]
    generateFingerprintInBytes(int numberOfInts, int numberOfOnes, int numberOfBonds)
    Generates chemical hashed fingerprint for the molecule and returns it in byte units.
    int[]
    generateFingerprintInInts(int numberOfInts, int numberOfOnes, int numberOfBonds)
    Generates chemical hashed fingerprint for the molecule and returns it in int units.
    int
    Retrieves the number of atoms in the Molecule stored in the MolHandler object.
    int
    Retrieves the number of non-hydrogen atoms in the Molecule stored in the MolHandler object.
    int
    Counts the number of implicit hydrogens on the molecule
    Retrieves the Molecule from the MolHandler object.
    boolean
    Gets query mode.
    static boolean
    Decides if atom is a plain H atom.
    void
    Removes all hydrogen atoms.
    void
    Removes Hydrogen atoms attached to Carbon atoms.
    void
    setMolecule(byte[] molecule)
    Initializes a MolHandler object from a byte array.
    void
    Initializes a MolHandler object from a Molecule.
    void
    setMolecule(String molecule)
    Sets the molecule.
    void
    setQueryMode(boolean q)
    Sets query mode.
    byte[]
    Converts the molecule to the specified binary format.
    toFormat(String format)
    Converts the molecule to the specified text format.

    Methods inherited from class java.lang.Object

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

    • mol

      protected Molecule mol
    • queryMode

      protected boolean queryMode
    • molAligner

      protected MolAligner molAligner
    • molAlignerSet

      protected boolean molAlignerSet
  • Constructor Details

    • MolHandler

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

      public MolHandler(Molecule mol)
      Creates a MolHandler object from a Molecule.
      Parameters:
      mol - this molecule is stored directly
    • 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 Details

    • setMolecule

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

      public void setMolecule(String molecule) throws MolFormatException
      Sets the molecule.
      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
    • getMolecule

      public Molecule getMolecule()
      Retrieves the Molecule from the MolHandler object.
    • setQueryMode

      public void setQueryMode(boolean q)
      Sets query mode. SMILES strings are imported as SMARTS if query mode is set.
      Parameters:
      q - query mode
      Since:
      JChem 2.2
    • 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

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void addHydrogensToAromaticHeteroAtoms()
      Deprecated, for removal: This API element is subject to removal in a future version.
      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.
    • aromatize

      public void aromatize(int method)
      Converts the bonds in an aromatic system entered using single and double bonds to aromatic bonds. since 2.3
      Parameters:
      method - specifies the algorithm for aromatization. Possible values:
      See Also:
    • calcMolWeight

      public float calcMolWeight() throws PluginException
      Calculates the molecular weight of the molecule.
      Returns:
      molweight as float
      Throws:
      PluginException - if molecule check in ElementalAnalyserPlugin failed
    • calcMolWeightInDouble

      public double calcMolWeightInDouble() throws PluginException
      Calculates the molecular weight of the molecule.
      Returns:
      molweight as double
      Throws:
      PluginException - if molecule check in ElementalAnalyserPlugin failed
    • calcMolFormula

      public String calcMolFormula() throws PluginException
      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:
      molecule formula
      Throws:
      PluginException - if molecule check in ElementalAnalyserPlugin failed
    • 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:
    • 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

      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:
    • 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