Class AtomContainerManipulator
java.lang.Object
org.openscience.cdk.tools.manipulator.AtomContainerManipulator
- Direct Known Subclasses:
ExtAtomContainerManipulator, SMSDNormalizer
Class with convenience methods that provide methods to manipulate
AtomContainer's. For example:
AtomContainerManipulator.replaceAtomByAtom(container, atom1, atom2);will replace the Atom in the AtomContainer, but in all the ElectronContainer's it participates too.
- Author:
- Egon Willighagen
- Created on:
- 2003-08-07
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intFor use withgetMass(IAtomContainer).static final intFor use withgetMass(IAtomContainer).static final intFor use withgetMass(IAtomContainer).static final intFor use withgetMass(IAtomContainer).static final Comparator<IIsotope> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IAtomContaineranonymise(IAtomContainer src) Anonymise the provided container to single-bonded carbon atoms.static voidclearAtomConfigurations(IAtomContainer container) This method will reset all atom configuration to UNSET.static voidconvertImplicitToExplicitHydrogens(IAtomContainer atomContainer) Adds explicit hydrogens (without coordinates) to the IAtomContainer, equaling the number of set implicit hydrogens.static voidcopy(IAtomContainer dest, IAtomContainer source, Collection<IAtom> atoms) Copy atoms in the collection from a 'source' molecule to the provideddestination.static voidcopy(IAtomContainer dest, IAtomContainer source, Predicate<IAtom> atomFilter) Copy selected atoms from a 'source' molecule to the provideddestination.static voidcopy(IAtomContainer dest, IAtomContainer source, Predicate<IAtom> atomFilter, Predicate<IBond> bondFilter) Copy selected atoms/bonds from a 'source' molecule to the provideddestination.static IAtomContainerCopy the input container and suppress any explicit hydrogens.static intcountExplicitHydrogens(IAtomContainer atomContainer, IAtom atom) Count explicit hydrogens.static intcountHydrogens(IAtomContainer atomContainer, IAtom atom) static IAtomContainerDeprecated.static IAtomContainerextractSubstructure(IAtomContainer atomContainer, int... atomIndices) Deprecated.useextractSubstructure(IAtomContainer, Collection)insteadstatic IAtomContainerextractSubstructure(IAtomContainer source, Collection<IAtom> atoms) Extract a substructure from a 'source' molecule to the provideddestination based on the collection of atoms.getAllIDs(IAtomContainer mol) static IAtom[]getAtomArray(List<IAtom> list) Constructs an array of Atom objects from a List of Atom objects.static IAtom[]getAtomArray(IAtomContainer container) Constructs an array of Atom objects from an AtomContainer.static IAtomgetAtomById(IAtomContainer ac, String id) Returns an atom in an atomcontainer identified by idstatic IBond[]getBondArray(List<IBond> list) Constructs an array of Atom objects from a List of Atom objects.static IBond[]getBondArray(IAtomContainer container) Constructs an array of Bond objects from an AtomContainer.static doublegetBondOrderSum(IAtomContainer container, IAtom atom) Returns the sum of the bond order equivalents for a given IAtom.static IElectronContainer[]Constructs an array of Atom objects from a List of Atom objects.static IElectronContainer[]getElectronContainerArray(IAtomContainer container) Constructs an array of Bond objects from an AtomContainer.getHeavyAtoms(IAtomContainer container) Returns a set of nodes excluding all the hydrogens.static intgetImplicitHydrogenCount(IAtomContainer container) Counts the number of implicit hydrogens on the provided IAtomContainer.static IAtomContainergetIntersection(IAtomContainer container1, IAtomContainer container2) Compares this AtomContainer with another given AtomContainer and returns the Intersection between them.static doublegetMass(IAtomContainer mol) Calculate the mass of a molecule, this function takes an optional 'mass flavour' that switches the computation type.static doublegetMass(IAtomContainer mol, int flav) Calculate the mass of a molecule, this function takes an optional 'mass flavour' that switches the computation type.static IBond.OrdergetMaximumBondOrder(IAtomContainer container) static doubleDeprecated.static doubleDeprecated.static intgetSingleBondEquivalentSum(IAtomContainer container) Returns the sum of bond orders, where a single bond counts as one single bond equivalent, a double as two, etc.static doublegetTotalCharge(IAtomContainer atomContainer) Get the summed charge of all atoms in an AtomContainerstatic doubleDeprecated.usesgetMass(IAtomContainer, int)andMonoIsotopicstatic intgetTotalFormalCharge(IAtomContainer atomContainer) Get the total formal charge on a molecule.static intgetTotalHydrogenCount(IAtomContainer container) Counts the number of hydrogens on the provided IAtomContainer.static doublegetTotalNaturalAbundance(IAtomContainer atomContainer) Get the summed natural abundance of all atoms in an AtomContainerstatic intgetTotalNegativeFormalCharge(IAtomContainer atomContainer) Get the total formal negative charge on a molecule.static intgetTotalPositiveFormalCharge(IAtomContainer atomContainer) Get the total positive formal charge on a molecule.static voidnormalizeHydrogens(IAtomContainer container, HydrogenState state) Normalize the state in which hydrogens are represented/store in the provided molecule.static voidpercieveAtomTypesAndConfigureAtoms(IAtomContainer container) Convenience method to perceive atom types for allIAtoms in theIAtomContainer, using theCDKAtomTypeMatcher.static voidConvenience method to perceive atom types for allIAtoms in theIAtomContainer, using theCDKAtomTypeMatcher.static IAtomContainerCreate an copy of theorgstructure with explicit hydrogens removed.static IAtomContainerDeprecated.suppressHydrogens(IAtomContainer)will now not removed bridging hydrogens by defaultstatic IAtomContainerremoveNonChiralHydrogens(IAtomContainer container) Produces an AtomContainer without explicit non stereo-relevant Hs but with H count from one with Hs.static booleanreplaceAtomByAtom(IAtomContainer container, IAtom oldAtom, IAtom newAtom) Substitute one atom in a container for another adjusting bonds, single electrons, lone pairs, and stereochemistry as required.static voidsetAtomProperties(IAtomContainer container, Object propKey, Object propVal) Sets a property on allAtoms in the given container.static IAtomContainerAssignsIChemObject.SINGLE_OR_DOUBLEflags to the bonds of a container.static IAtomContainerskeleton(IAtomContainer src) Create a skeleton copy of the provided structure.static IAtomContainersuppressHydrogens(IAtomContainer container) Suppress any explicit hydrogens in the provided container.static voidunregisterAtomListeners(IAtomContainer container) A method to remove AtomListeners.static voidA method to remove ElectronContainerListeners.
-
Field Details
-
MolWeight
public static final int MolWeightFor use withgetMass(IAtomContainer). This option uses the mass stored on atoms (IIsotope.getExactMass()) or the average mass of the element when unspecified.- See Also:
-
MolWeightIgnoreSpecified
public static final int MolWeightIgnoreSpecifiedFor use withgetMass(IAtomContainer). This option ignores the mass stored on atoms (IIsotope.getExactMass()) and uses the average mass of each element. This option is primarily provided for backwards compatibility.- See Also:
-
MonoIsotopic
public static final int MonoIsotopicFor use withgetMass(IAtomContainer). This option uses the mass stored on atomsIIsotope.getExactMass()or the mass of the major isotope when this is not specified.- See Also:
-
MostAbundant
public static final int MostAbundantFor use withgetMass(IAtomContainer). This option uses the mass stored on atomsIIsotope.getExactMass()and then calculates a distribution for any unspecified atoms and uses the most abundant distribution. For example C6Br6 would have three 79Br and 81Br because their abundance is 51 and 49%.- See Also:
-
NAT_ABUN_COMP
-
-
Constructor Details
-
AtomContainerManipulator
public AtomContainerManipulator()
-
-
Method Details
-
extractSubstructure
@Deprecated public static IAtomContainer extractSubstructure(IAtomContainer atomContainer, int... atomIndices) throws CloneNotSupportedException Deprecated.useextractSubstructure(IAtomContainer, Collection)insteadExtract a substructure from an atom container, in the form of a new cloned atom container with only the atoms with indices in atomIndices and bonds that connect these atoms. Note that this may result in a disconnected atom container.- Parameters:
atomContainer- the source container to extract fromatomIndices- the indices of the substructure- Returns:
- a cloned atom container with a substructure of the source
- Throws:
CloneNotSupportedException- not thrown any longer, kept to retain compatability
-
copy
public static void copy(IAtomContainer dest, IAtomContainer source, Predicate<IAtom> atomFilter, Predicate<IBond> bondFilter) Copy selected atoms/bonds from a 'source' molecule to the provideddestination. For consistency the bond filter is only checked if both atoms of a bond pass the atom filter. i.e. you can't add a bond with atoms that would not be copied.- Parameters:
dest- the destination moleculesource- the source moleculeatomFilter- the atom filter indicates which atoms to copybondFilter- the bond filter indicates which bonds to copy
-
copy
Copy selected atoms from a 'source' molecule to the provideddestination.- Parameters:
dest- the destination moleculesource- the source moleculeatomFilter- the atom filter indicates which atoms to copy- See Also:
-
copy
Copy atoms in the collection from a 'source' molecule to the provideddestination. For performance aSetof 'atoms' is preferred.- Parameters:
dest- the destination moleculesource- the source moleculeatoms- the atom collection indicates which atoms to copy- See Also:
-
extractSubstructure
Extract a substructure from a 'source' molecule to the provideddestination based on the collection of atoms. For performance aSetofatomsis preferred.- Parameters:
source- the source moleculeatoms- the atom collection indicates which atoms to copy- Returns:
- the extracted molecule
- See Also:
-
getAtomById
Returns an atom in an atomcontainer identified by id- Parameters:
ac- The AtomContainer to search inid- The id to search for- Returns:
- An atom having id id
- Throws:
CDKException- There is no such atom
-
replaceAtomByAtom
Substitute one atom in a container for another adjusting bonds, single electrons, lone pairs, and stereochemistry as required.- Parameters:
container- the container to replace the atom ofoldAtom- the atom to replacenewAtom- the atom to insert- Returns:
- whether replacement was made
-
getTotalCharge
Get the summed charge of all atoms in an AtomContainer- Parameters:
atomContainer- The IAtomContainer to manipulate- Returns:
- The summed charges of all atoms in this AtomContainer.
-
getMass
Calculate the mass of a molecule, 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 eitherIIsotope.setMassNumber(Integer)orIIsotope.setExactMass(Double)set to non-null and non-zero.
The flavours are:
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.MolWeightIgnoreSpecified- uses the average mass of each element, ignoring any isotopic/exact mass specificationMonoIsotopic- uses the exact mass of each atom when an isotope is specified, if not specified the major isotope mass for that element is used.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.
- Parameters:
mol- molecule to compute mass forflav- flavor- Returns:
- the mass of the molecule
- See Also:
-
getMass
Calculate the mass of a molecule, 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 eitherIIsotope.setMassNumber(Integer)orIIsotope.setExactMass(Double)set to non-null and non-zero.
The flavours are:
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.MolWeightIgnoreSpecified- uses the average mass of each element, ignoring any isotopic/exact mass specificationMonoIsotopic- uses the exact mass of each atom when an isotope is specified, if not specified the major isotope mass for that element is used.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.
- Parameters:
mol- molecule to compute mass for- Returns:
- the mass of the molecule
- See Also:
-
getTotalExactMass
Deprecated.usesgetMass(IAtomContainer, int)andMonoIsotopic -
getNaturalExactMass
Deprecated. -
getMolecularWeight
Deprecated. -
getTotalNaturalAbundance
Get the summed natural abundance of all atoms in an AtomContainer- Parameters:
atomContainer- The IAtomContainer to manipulate- Returns:
- The summed natural abundance of all atoms in this AtomContainer.
-
getTotalFormalCharge
Get the total formal charge on a molecule.- Parameters:
atomContainer- the atom container to consider- Returns:
- The summed formal charges of all atoms in this AtomContainer.
-
getTotalNegativeFormalCharge
Get the total formal negative charge on a molecule.- Parameters:
atomContainer- the atom container to consider- Returns:
- The summed negative formal charges of all atoms in this AtomContainer.
-
getTotalPositiveFormalCharge
Get the total positive formal charge on a molecule.- Parameters:
atomContainer- the atom container to consider- Returns:
- The summed positive formal charges of all atoms in this AtomContainer.
-
getTotalHydrogenCount
Counts the number of hydrogens on the provided IAtomContainer. As this method will sum all implicit hydrogens on each atom it is important to ensure the atoms have already been perceived (and thus have an implicit hydrogen count) (see.percieveAtomTypesAndConfigureAtoms(IAtomContainer)).- Parameters:
container- the container to count the hydrogens on- Returns:
- the total number of hydrogens
- Throws:
IllegalArgumentException- if the provided container was null- See Also:
-
getImplicitHydrogenCount
Counts the number of implicit hydrogens on the provided IAtomContainer. As this method will sum all implicit hydrogens on each atom it is important to ensure the atoms have already been perceived (and thus have an implicit hydrogen count) (see.percieveAtomTypesAndConfigureAtoms(IAtomContainer)).- Parameters:
container- the container to count the implicit hydrogens on- Returns:
- the total number of implicit hydrogens
- Throws:
IllegalArgumentException- if the provided container was null- See Also:
-
countExplicitHydrogens
Count explicit hydrogens.- Parameters:
atomContainer- the atom container to consider- Returns:
- The number of explicit hydrogens on the given IAtom.
- Throws:
IllegalArgumentException- if either the container or atom were null
-
convertImplicitToExplicitHydrogens
Adds explicit hydrogens (without coordinates) to the IAtomContainer, equaling the number of set implicit hydrogens.- Parameters:
atomContainer- the atom container to consider- See Also:
- Keywords:
- hydrogens, adding
-
normalizeHydrogens
Normalize the state in which hydrogens are represented/store in the provided molecule. Hydrogens can either be stored as a count on the atom (IAtom.getImplicitHydrogenCount()or as an explicitIAtomobject with atomic number 1. This function is used to safely and correctly convert between these two representations with different presets for common use-case (e.g. hydrogens on all stereochemistry).- Parameters:
container- the molecule to normalizestate- the state to convert to
-
countHydrogens
- Returns:
- The summed implicit + explicit hydrogens of the given IAtom.
-
getAllIDs
-
removeNonChiralHydrogens
Produces an AtomContainer without explicit non stereo-relevant Hs but with H count from one with Hs. The new molecule is a deep copy.- Parameters:
container- The AtomContainer from which to remove the hydrogens- Returns:
- The molecule without non stereo-relevant Hs.
- See Also:
- Keywords:
- hydrogens, removal
-
suppressHydrogens
Suppress any explicit hydrogens in the provided container. Only hydrogens that can be represented as a hydrogen count value on the atom are suppressed. The container is updated and no elements are copied, please use eithercopyAndSuppressedHydrogens(IAtomContainer)if you would to preserve the old instance.- Parameters:
container- the container from which to remove hydrogens- Returns:
- the input for convenience
- See Also:
-
copyAndSuppressedHydrogens
Copy the input container and suppress any explicit hydrogens. Only hydrogens that can be represented as a hydrogen count value on the atom are suppressed. If a copy is not needed please usesuppressHydrogens(IAtomContainer).- Parameters:
org- the container from which to remove hydrogens- Returns:
- a copy of the input with suppressed hydrogens
- See Also:
-
removeHydrogens
Create an copy of theorgstructure with explicit hydrogens removed. Stereochemistry is updated but up and down bonds in a depiction may need to be recalculated (see. StructureDiagramGenerator).- Parameters:
org- The AtomContainer from which to remove the hydrogens- Returns:
- The molecule without hydrogens.
- See Also:
- Keywords:
- hydrogens, removal, suppress
-
removeHydrogensPreserveMultiplyBonded
Deprecated.suppressHydrogens(IAtomContainer)will now not removed bridging hydrogens by defaultProduces an AtomContainer without explicit Hs but with H count from one with Hs. Hs bonded to more than one heavy atom are preserved. The new molecule is a deep copy.- Returns:
- The mol without Hs.
- See Also:
- Keywords:
- hydrogens, removal
-
setAtomProperties
Sets a property on allAtoms in the given container. -
unregisterElectronContainerListeners
A method to remove ElectronContainerListeners. ElectronContainerListeners are used to detect changes in ElectronContainers (like bonds) and to notifiy registered Listeners in the event of a change. If an object looses interest in such changes, it should unregister with this AtomContainer in order to improve performance of this class. -
unregisterAtomListeners
A method to remove AtomListeners. AtomListeners are used to detect changes in Atom objects within this AtomContainer and to notifiy registered Listeners in the event of a change. If an object looses interest in such changes, it should unregister with this AtomContainer in order to improve performance of this class. -
getIntersection
Compares this AtomContainer with another given AtomContainer and returns the Intersection between them.Important Note : This is not the maximum common substructure.
- Parameters:
container1- an AtomContainer objectcontainer2- an AtomContainer object- Returns:
- An AtomContainer containing the intersection between container1 and container2
-
getAtomArray
Constructs an array of Atom objects from an AtomContainer.- Parameters:
container- The original AtomContainer.- Returns:
- The array of Atom objects.
-
getAtomArray
-
getBondArray
Constructs an array of Bond objects from an AtomContainer.- Parameters:
container- The original AtomContainer.- Returns:
- The array of Bond objects.
-
getBondArray
-
getElectronContainerArray
Constructs an array of Bond objects from an AtomContainer.- Parameters:
container- The original AtomContainer.- Returns:
- The array of Bond objects.
-
getElectronContainerArray
Constructs an array of Atom objects from a List of Atom objects.- Parameters:
list- The original List.- Returns:
- The array of Atom objects.
-
percieveAtomTypesAndConfigureAtoms
Convenience method to perceive atom types for allIAtoms in theIAtomContainer, using theCDKAtomTypeMatcher. If the matcher finds a matching atom type, theIAtomwill be configured to have the same properties as theIAtomType. If no matching atom type is found, no configuration is performed.
This method overwrites existing values.- Parameters:
container- the container whose atom types are to be perceived- Throws:
CDKException- See Also:
-
percieveAtomTypesAndConfigureUnsetProperties
public static void percieveAtomTypesAndConfigureUnsetProperties(IAtomContainer container) throws CDKException Convenience method to perceive atom types for allIAtoms in theIAtomContainer, using theCDKAtomTypeMatcher. If the matcher finds a matching atom type, theIAtomwill be configured to have the same properties as theIAtomType. If no matching atom type is found, no configuration is performed.
This method only setsnullvalues.- Parameters:
container- the container whose atom types are to be perceived- Throws:
CDKException- See Also:
-
clearAtomConfigurations
This method will reset all atom configuration to UNSET.
This method is the reverse ofpercieveAtomTypesAndConfigureAtoms(org.openscience.cdk.interfaces.IAtomContainer)and after a call to this method all atoms will be "unconfigured".
Note that it is not a complete reversal ofpercieveAtomTypesAndConfigureAtoms(org.openscience.cdk.interfaces.IAtomContainer)since the atomic symbol of the atoms remains unchanged. Also, all the flags that were set by the configuration method (such as IS_HYDROGENBOND_ACCEPTOR or ISAROMATIC) will be set to False.- Parameters:
container- The molecule whose atoms are to be unconfigured- See Also:
-
getSingleBondEquivalentSum
Returns the sum of bond orders, where a single bond counts as one single bond equivalent, a double as two, etc. -
getMaximumBondOrder
-
getHeavyAtoms
Returns a set of nodes excluding all the hydrogens.- Returns:
- The heavyAtoms value
- Keywords:
- hydrogens, removal
-
createAllCarbonAllSingleNonAromaticBondAtomContainer
public static IAtomContainer createAllCarbonAllSingleNonAromaticBondAtomContainer(IAtomContainer atomContainer) throws CloneNotSupportedException Deprecated.not all attributes are removed producing unexpected results, useanonymise(IAtomContainer)Generates a cloned atomcontainer with all atoms being carbon, all bonds being single non-aromatic- Parameters:
atomContainer- The input atomcontainer- Returns:
- The new atomcontainer
- Throws:
CloneNotSupportedException- The atomcontainer cannot be cloned
-
anonymise
Anonymise the provided container to single-bonded carbon atoms. No information other then the connectivity from the original container is retrained.- Parameters:
src- an atom container- Returns:
- anonymised container
-
skeleton
Create a skeleton copy of the provided structure. The skeleton copy is similar to an anonymous copy (anonymise(IAtomContainer)) except that atom elements are preserved. All bonds are converted to single bonds and a 'clean' atom is created for the input elements. The 'clean' atom has unset charge, mass, and hydrogen count.- Parameters:
src- input structure- Returns:
- the skeleton copy
-
getBondOrderSum
Returns the sum of the bond order equivalents for a given IAtom. It considers single bonds as 1.0, double bonds as 2.0, triple bonds as 3.0, and quadruple bonds as 4.0.- Parameters:
atom- The atom for which to calculate the bond order sum- Returns:
- The number of bond order equivalents for this atom
-
setSingleOrDoubleFlags
AssignsIChemObject.SINGLE_OR_DOUBLEflags to the bonds of a container. The single or double flag indicates uncertainty of bond order and in this case is assigned to all aromatic bonds (and atoms) which occur in rings. If any such bonds are found the flag is also set on the container.SmilesParser parser = new SmilesParser(...); parser.setPreservingAromaticity(true); IAtomContainer biphenyl = parser.parseSmiles("c1cccc(c1)c1ccccc1"); AtomContainerManipulator.setSingleOrDoubleFlags(biphenyl);- Parameters:
ac- container to which the flags are assigned- Returns:
- the input for convenience
-
anonymise(IAtomContainer)