Class CircularFragmenter
For every atom in the input molecule, the neighborhood up to a
user-defined radius (number of bonds, also called "height" or "level") is
collected by a breadth-first expansion and returned as an independent
IAtomContainer. All atoms and bonds in the resulting containers are
deep copies of the originals, so modifying them does not
affect the source molecule.
Usage example:
IAtomContainer molecule = ...; // fully configured molecule
CircularFragmenter fragmenter = new CircularFragmenter(3); //radius 3, also the default
List<IAtomContainer> fragments = fragmenter.getCircularFragments(molecule);
The list index of each fragment corresponds to the index of the center atom (also called
"root") in the original atom container. But note that fragments.get(i).contains(mol.getAtom(i))
will produce false because the atoms (and bonds) are copied at fragment extraction.
Each atom in a fragment has the property with key FRAGMENT_ATOM_DEPTH_PROPERTY_KEY
set, which contains the depth (sphere nr. / level / height) of the respective atom in the respective fragment.
0 stands for the center atom. These can, e.g., be used to generate SMILES strings of a fragment with atom-atom-mappings
corresponding to the respective depth of each atom.
Additional configuration options (to the radius) include the saturation of the fragments where bonds were broken (either, per default, with implicit hydrogen atoms or, alternatively, with pseudo atoms to mark the attachment points) and whether stereochemistry annotations should be preserved in the fragments (default: false).
Note that the resulting fragments are not deduplicated! So, if you, e.g., fragment benzene with a radius of 3, you will get six benzene "fragments" as a result, since a radius of three includes the entire molecule, independent of which atom is taken as the center.
Also note that whether you have done an aromaticity perception or not on your input molecule before using this fragmentation routine influences the results, especially when analyzing a whole collection of molecules and deduplicating the fragments afterward.
Scaling: Let n be the number of atoms and r the radius. A single fragment extraction scales with the number of atoms k in the fragment (approx. min(n, 3r)). Extracting all fragments takes O(n·k). For typical small radii, this is effectively linear O(n); for large radii covering the whole molecule, it is O(n2).
- Author:
- Jonas Schaub (jonas.schaub@uni-jena.de | jonas-schaub@gmx.de | JonasSchaub on GitHub)
- Keywords:
- fragment, circular fingerprint, HOSE code, molecular signature, spherical environment
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty key to retrieve the depth (sphere nr. / level / height) of a fragment atom in the respective circular fragment. 0 stands for the center atom. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newCircularFragmenterwith the default radius (= 3 bonds), the default stereochemistry setting (= false, no preservation of stereochemistry), and the default attachment point marking setting (= false, no marking of attachment points; saturation with implicit hydrogen atoms instead).CircularFragmenter(int radius) Creates a newCircularFragmenterwith the given radius, the default stereochemistry setting (= false, no preservation of stereochemistry), and the default attachment point marking setting (= false, no marking of attachment points; saturation with implicit hydrogen atoms instead).CircularFragmenter(int radius, boolean preserveStereo) Creates a newCircularFragmenterwith the given radius and stereochemistry setting and the default attachment point marking setting (= false, no marking of attachment points; saturation with implicit hydrogen atoms instead).CircularFragmenter(int radius, boolean preserveStereo, boolean markAttachments) Creates a newCircularFragmenterwith the given radius, stereochemistry, and attachment point marking setting. -
Method Summary
Modifier and TypeMethodDescriptiongetCircularFragment(IAtom atom) Extracts a single circular fragment centered on the given atom from the molecule the atom is a part of.getCircularFragment(IAtomContainer molecule, IAtom atom) Extracts a single circular fragment centered on the given atom from the given molecule.getCircularFragments(IAtomContainer molecule) Extracts one circular fragment per atom of the input molecule.intReturns the current radius setting for atom environment extraction.booleanReturns the current attachment point marking setting.booleanReturns the current stereochemistry setting.voidsetMarkAttachments(boolean markAttachments) Sets the attachment point marking setting.voidsetPreserveStereo(boolean preserveStereo) Sets the stereochemistry setting.voidsetRadius(int radius) Sets the radius for atom environment extraction.
-
Field Details
-
FRAGMENT_ATOM_DEPTH_PROPERTY_KEY
Property key to retrieve the depth (sphere nr. / level / height) of a fragment atom in the respective circular fragment. 0 stands for the center atom.- See Also:
-
-
Constructor Details
-
CircularFragmenter
public CircularFragmenter()Creates a newCircularFragmenterwith the default radius (= 3 bonds), the default stereochemistry setting (= false, no preservation of stereochemistry), and the default attachment point marking setting (= false, no marking of attachment points; saturation with implicit hydrogen atoms instead). -
CircularFragmenter
public CircularFragmenter(int radius) Creates a newCircularFragmenterwith the given radius, the default stereochemistry setting (= false, no preservation of stereochemistry), and the default attachment point marking setting (= false, no marking of attachment points; saturation with implicit hydrogen atoms instead).- Parameters:
radius- the number of bonds to expand from each center atom; must be >= 0; a radius of 0 produces fragments containing only the respective center atom itself- Throws:
IllegalArgumentException- ifradiusis negative
-
CircularFragmenter
public CircularFragmenter(int radius, boolean preserveStereo) Creates a newCircularFragmenterwith the given radius and stereochemistry setting and the default attachment point marking setting (= false, no marking of attachment points; saturation with implicit hydrogen atoms instead).- Parameters:
radius- the number of bonds to expand from each center atom; must be >= 0; a radius of 0 produces fragments containing only the respective center atom itselfpreserveStereo- whether to preserve stereochemistry annotations during fragmentation- Throws:
IllegalArgumentException- ifradiusis negative
-
CircularFragmenter
public CircularFragmenter(int radius, boolean preserveStereo, boolean markAttachments) Creates a newCircularFragmenterwith the given radius, stereochemistry, and attachment point marking setting.- Parameters:
radius- the number of bonds to expand from each center atom; must be >= 0; a radius of 0 produces fragments containing only the respective center atom itselfpreserveStereo- whether to preserve stereochemistry annotations during fragmentationmarkAttachments- whether to mark attachment points of broken bonds with pseudo atoms- Throws:
IllegalArgumentException- ifradiusis negative
-
-
Method Details
-
getRadius
public int getRadius()Returns the current radius setting for atom environment extraction.- Returns:
- radius in nr. of bonds
-
setRadius
public void setRadius(int radius) Sets the radius for atom environment extraction.- Parameters:
radius- in nr. of bonds; must be >= 0- Throws:
IllegalArgumentException- ifradiusis negative
-
isPreserveStereo
public boolean isPreserveStereo()Returns the current stereochemistry setting.- Returns:
- whether to preserve stereochemistry annotations during fragmentation
-
setPreserveStereo
public void setPreserveStereo(boolean preserveStereo) Sets the stereochemistry setting.- Parameters:
preserveStereo- whether to preserve stereochemistry annotations during fragmentation
-
isMarkAttachments
public boolean isMarkAttachments()Returns the current attachment point marking setting.- Returns:
- whether to mark attachment points of broken bonds with pseudo atoms
-
setMarkAttachments
public void setMarkAttachments(boolean markAttachments) Sets the attachment point marking setting.- Parameters:
markAttachments- whether to mark attachment points of broken bonds with pseudo atoms
-
getCircularFragments
Extracts one circular fragment per atom of the input molecule.The fragment for atom
icontains deep copies of all atoms reachable from atomiwithin at mostgetRadius()bonds, together with all bonds between those atoms.The list index of each fragment corresponds to the index of the center atom in the input atom container.
Note that the resulting fragments are not deduplicated!
- Parameters:
molecule- the input molecule; must not benull; an empty input molecule yields an empty return list; the method does not modify the molecule- Returns:
- a list of
IAtomContainerobjects, one per atom inmolecule, in atom-index order; nevernullbut can be empty if the input molecule is empty - Throws:
NullPointerException- ifmoleculeisnull
-
getCircularFragment
Extracts a single circular fragment centered on the given atom from the molecule the atom is a part of.The same algorithm as in
getCircularFragments(IAtomContainer)is applied, but for only one center atom.This method will only work if the atom has been accessed in the context of an
IAtomContainer, for example:IAtomContainer mol = new AtomContainer(); IAtom atom = new Atom(6); atom.getContainer(); // null mol.add(atom); atom.getContainer(); // still null mol.getAtom(0).getContainer(); // not-null, returns 'mol'- Parameters:
atom- the center atom; must not benulland must be accessed in the context of anIAtomContainer- Returns:
- a deep-copied
IAtomContainerof the circular environment - Throws:
NullPointerException- ifatomisnullIllegalArgumentException- ifatomis not accessed in the context of anIAtomContainer
-
getCircularFragment
Extracts a single circular fragment centered on the given atom from the given molecule.The same algorithm as in
getCircularFragments(IAtomContainer)is applied, but for only one center atom.- Parameters:
molecule- the source molecule; must not benullatom- the center atom; must not benulland must be part ofmolecule- Returns:
- a deep-copied
IAtomContainerof the circular environment - Throws:
NullPointerException- ifmoleculeoratomisnullIllegalArgumentException- ifatomis not part ofmolecule
-