Package chemaxon.util
Class MolHandler
java.lang.Object
chemaxon.util.MolHandler
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:
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
FieldsModifier and TypeFieldDescriptionprotected Moleculeprotected MolAlignerprotected booleanprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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.MolHandler(Molecule mol) 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 TypeMethodDescriptionvoidAdds explicit H atoms instead of the current implicit ones.voidDeprecated, for removal: This API element is subject to removal in a future version.doubleAlignes (rotates) a specified molecule realtive to the contained molecule according to the specified atom pairs.voidConverts the bonds in an aromatic system entered using single and double bonds to aromatic bonds.voidaromatize(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.floatCalculates the molecular weight of the molecule.doubleCalculates the molecular weight of the molecule.voidCalculates 2D coordinates.booleanTrue 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 inbyteunits.int[]generateFingerprintInInts(int numberOfInts, int numberOfOnes, int numberOfBonds) Generates chemical hashed fingerprint for the molecule and returns it inintunits.intRetrieves the number of atoms in the Molecule stored in the MolHandler object.intRetrieves the number of non-hydrogen atoms in the Molecule stored in the MolHandler object.intCounts the number of implicit hydrogens on the moleculeRetrieves the Molecule from the MolHandler object.booleanGets query mode.static booleanDecides if atom is a plain H atom.voidRemoves all hydrogen atoms.voidRemoves Hydrogen atoms attached to Carbon atoms.voidsetMolecule(byte[] molecule) Initializes a MolHandler object from a byte array.voidsetMolecule(Molecule molecule) Initializes a MolHandler object from a Molecule.voidsetMolecule(String molecule) Sets the molecule.voidsetQueryMode(boolean q) Sets query mode.byte[]toBinFormat(String format) Converts the molecule to the specified binary format.Converts the molecule to the specified text format.
-
Field Details
-
mol
-
queryMode
protected boolean queryMode -
molAligner
-
molAlignerSet
protected boolean molAlignerSet
-
-
Constructor Details
-
MolHandler
public MolHandler()Creates an uninitialized MolHandler object. -
MolHandler
Creates a MolHandler object from a Molecule.- Parameters:
mol- this molecule is stored directly
-
MolHandler
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
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 totrueSMILES strings are imported as SMARTS. Default isfalse.- Throws:
MolFormatException- if the importer encounters a problem- Since:
- 2.2
-
MolHandler
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
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 formatqueryMode- if set totrueSMILES strings are imported as SMARTS. Default isfalse.- Throws:
MolFormatException- if the importer encounters a problem since 2.2
-
-
Method Details
-
setMolecule
Initializes a MolHandler object from a Molecule.- Parameters:
molecule- this parameter is stored in the MolHandler object
-
setMolecule
Sets the molecule.- Parameters:
molecule- the molecule to load into this molhandler- Throws:
MolFormatException- if the importer encounters a problem
-
setMolecule
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
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:-
MoleculeGraph.AROM_GENERAL- Chemaxon aromatization -
MoleculeGraph.AROM_BASIC- Daylight aromatization (modified Huckel rule)
-
- See Also:
-
calcMolWeight
Calculates the molecular weight of the molecule.- Returns:
- molweight as float
- Throws:
PluginException- if molecule check inElementalAnalyserPluginfailed
-
calcMolWeightInDouble
Calculates the molecular weight of the molecule.- Returns:
- molweight as double
- Throws:
PluginException- if molecule check inElementalAnalyserPluginfailed
-
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:
- molecule formula
- Throws:
PluginException- if molecule check inElementalAnalyserPluginfailed
-
clean
Calculates 2D coordinates. The bond length is set to 0.825. The calculation uses theO1option of cleaning.- Parameters:
always- iffalsethen 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
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
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 inintunits.
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 inbyteunits.
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
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 alignedindexes- 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
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
-