Package org.openscience.cdk.layout
Class StructureDiagramGenerator
- java.lang.Object
-
- org.openscience.cdk.layout.StructureDiagramGenerator
-
public class StructureDiagramGenerator extends Object
Generates 2D coordinates for a molecule. Basic Usage: If you just want to generate coordinate for a molecule (or reaction) you can use the following one-liner:new StructureDiagramGenerator().generateCoordinates(molecule);
The older versions of the API suggested using the following a set/generate/get idiom but this performs an unnecessary (in most cases) copy.StructureDiagramGenerator sdg = new StructureDiagramGenerator(); sdg.setMolecule(molecule); // cloned! sdg.generateCoordinates(); molecule = sdg.getMolecule();
This idiom only needs to be used when 'fixing' parts of an existing layout withsetMolecule(IAtomContainer, boolean, Set, Set)
- Author:
- steinbeck
- This class is affected by these bug(s):
- 1536561 1788686
- Dictionary pointer(s):
- layoutMolecule in the Blue Obelisk Chemoinformatics Dictionary [blue-obelisk:layoutMolecule]
- Source code:
- main
- Belongs to CDK module:
- sdg
- Keywords:
- Layout, Structure Diagram Generation (SDG), 2D-coordinates, Coordinate generation, 2D
- Created on:
- 2004-02-02
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<IAtomContainer>
LARGEST_FIRST_COMPARATOR
-
Constructor Summary
Constructors Constructor Description StructureDiagramGenerator()
The empty constructor.StructureDiagramGenerator(IAtomContainer molecule)
Creates an instance of this class while assigning a molecule to be layed out.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
generateAlignedCoordinates(IAtomContainer mol, IAtomContainer ref, Pattern pattern)
Generate coordinates aligned to a reference based on the provided pattern.void
generateAlignedCoordinates(IAtomContainer mol, Pattern pattern)
Generate coordinates aligned, the atoms in substructure pattern is used to cache/provide the coordinates.void
generateCoordinates()
The main method of this StructurDiagramGenerator.void
generateCoordinates(javax.vecmath.Vector2d firstBondVector)
The main method of this StructurDiagramGenerator.void
generateCoordinates(IAtomContainer mol)
Convenience method for generating 2D coordinates.void
generateCoordinates(IReaction reaction)
Convenience method to generate 2D coordinates for a reaction.void
generateExperimentalCoordinates()
Deprecated.void
generateExperimentalCoordinates(javax.vecmath.Vector2d firstBondVector)
Deprecated.double
getBondLength()
Returns the bond length used for laying out the molecule.IAtomContainer
getMolecule()
Returns the molecule, usually used after a call of generateCoordinates()IAtom
getOtherBondAtom(IAtom atom, IBond bond)
Returns the other atom of the bond.TemplateHandler
getTemplateHandler()
Deprecated.always null, substructure templates are not used anymoreboolean
getUseTemplates()
Deprecated.always false, substructure templates are not used anymorevoid
setAlignMappedReaction(boolean align)
Set whether reaction reactants should be allignned to their product.void
setBondLength(double bondLength)
Deprecated.void
setMolecule(IAtomContainer molecule)
Assings a molecule to be layed out.void
setMolecule(IAtomContainer mol, boolean clone)
void
setMolecule(IAtomContainer mol, boolean clone, Set<IAtom> afix, Set<IBond> bfix)
Assigns a molecule to be laid out.void
setTemplateHandler(TemplateHandler templateHandler)
Deprecated.substructure templates are no longer used for layout but those provided here will be converted to identity templatesvoid
setUseIdentityTemplates(boolean use)
Set whether identity templates are used.void
setUseTemplates(boolean useTemplates)
Deprecated.always false, substructure templates are not used anymore
-
-
-
Field Detail
-
LARGEST_FIRST_COMPARATOR
public static final Comparator<IAtomContainer> LARGEST_FIRST_COMPARATOR
-
-
Constructor Detail
-
StructureDiagramGenerator
public StructureDiagramGenerator()
The empty constructor.
-
StructureDiagramGenerator
public StructureDiagramGenerator(IAtomContainer molecule)
Creates an instance of this class while assigning a molecule to be layed out.- Parameters:
molecule
- The molecule to be layed out.
-
-
Method Detail
-
generateCoordinates
public final void generateCoordinates(IAtomContainer mol) throws CDKException
Convenience method for generating 2D coordinates.
The method is short-hand for calling:
sdg.setMolecule(mol, false); sdg.generateCoordinates();
- Parameters:
mol
- molecule to layout- Throws:
CDKException
- problem with layout
-
generateAlignedCoordinates
public final void generateAlignedCoordinates(IAtomContainer mol, IAtomContainer ref, Pattern pattern) throws CDKException
Generate coordinates aligned to a reference based on the provided pattern. The pattern is matched against both the input and reference molecules. The reference coordinates are generated and scaled accordingly if needed. The part of the pattern which can be aligned (consistent ring flags) is then copied and fixed in place before laying out the rest of the molecule.
Note: An internal read/write lock is used to ensure consistency in threaded environments.- Parameters:
mol
- moleculeref
- reference molecule (may be null)pattern
- the substructure pattern to match- Throws:
CDKException
- there was a problem generating the layout
-
generateAlignedCoordinates
public final void generateAlignedCoordinates(IAtomContainer mol, Pattern pattern) throws CDKException
Generate coordinates aligned, the atoms in substructure pattern is used to cache/provide the coordinates. If no coordinates are present the substructure from the molecule is generated first and its coordinates cached. If an atom in the- Parameters:
mol
- moleculepattern
- the substructure pattern to match (will be modified)- Throws:
CDKException
- there was a problem generating the layout
-
generateCoordinates
public final void generateCoordinates(IReaction reaction) throws CDKException
Convenience method to generate 2D coordinates for a reaction. If atom-atom maps are present on a reaction, the substructures are automatically aligned.
This feature can be disabled by changing the
setAlignMappedReaction(boolean)
- Parameters:
reaction
- reaction to layout- Throws:
CDKException
- problem with layout
-
setMolecule
public void setMolecule(IAtomContainer mol, boolean clone)
-
setMolecule
public void setMolecule(IAtomContainer mol, boolean clone, Set<IAtom> afix, Set<IBond> bfix)
Assigns a molecule to be laid out. After, setting the molecule call generateCoordinates() to assign 2D coordinates. An optional set of atoms/bonds can be parsed in to allow partial layout, these will be 'fixed' in place. This only applies to non-cloned molecules, and only atoms with coordinates can be fixed.- Parameters:
mol
- the molecule for which coordinates are to be generated.clone
- Should the whole process be performed with a cloned copy?afix
- Atoms that should be fixed in place, coordinates are not changed.bfix
- Bonds that should be fixed in place, they will not be flipped, bent, or streched.
-
setUseTemplates
@Deprecated public void setUseTemplates(boolean useTemplates)
Deprecated.always false, substructure templates are not used anymoreSets whether to use templates or not. Some complicated ring systems like adamantane are only nicely layouted when using templates. This option is by default set true.- Parameters:
useTemplates
- set true to use templates, false otherwise
-
setUseIdentityTemplates
public void setUseIdentityTemplates(boolean use)
Set whether identity templates are used. Identity templates use an exact match are are very fast. They are used for layout of the 'primary' ring system in de facto orientation.- Parameters:
use
- whether to use identity templates
-
getUseTemplates
@Deprecated public boolean getUseTemplates()
Deprecated.always false, substructure templates are not used anymoreReturns whether the use of templates is enabled or disabled.- Returns:
- true, when the use of templates is enables, false otherwise
-
setTemplateHandler
@Deprecated public void setTemplateHandler(TemplateHandler templateHandler)
Deprecated.substructure templates are no longer used for layout but those provided here will be converted to identity templatesSets the templateHandler attribute of the StructureDiagramGenerator object- Parameters:
templateHandler
- The new templateHandler value
-
getTemplateHandler
@Deprecated public TemplateHandler getTemplateHandler()
Deprecated.always null, substructure templates are not used anymoreGets the templateHandler attribute of the StructureDiagramGenerator object- Returns:
- The templateHandler value
-
setMolecule
public void setMolecule(IAtomContainer molecule)
Assings a molecule to be layed out. Call generateCoordinates() to do the actual layout.- Parameters:
molecule
- the molecule for which coordinates are to be generated.
-
setAlignMappedReaction
public void setAlignMappedReaction(boolean align)
Set whether reaction reactants should be allignned to their product.- Parameters:
align
- align setting
-
getMolecule
public IAtomContainer getMolecule()
Returns the molecule, usually used after a call of generateCoordinates()- Returns:
- The molecule with new coordinates (if generateCoordinates() had been called)
-
generateExperimentalCoordinates
@Deprecated public void generateExperimentalCoordinates() throws CDKException
Deprecated.This method uses generateCoordinates, but it removes the hydrogens first, lays out the structure and then adds them again.- Throws:
CDKException
- if an error occurs- See Also:
generateCoordinates(org.openscience.cdk.interfaces.IAtomContainer)
-
generateExperimentalCoordinates
@Deprecated public void generateExperimentalCoordinates(javax.vecmath.Vector2d firstBondVector) throws CDKException
Deprecated.Generates 2D coordinates on the non-hydrogen skeleton, after which coordinates for the hydrogens are calculated.- Parameters:
firstBondVector
- the vector of the first bond to lay out- Throws:
CDKException
- if an error occurs
-
generateCoordinates
public void generateCoordinates(javax.vecmath.Vector2d firstBondVector) throws CDKException
The main method of this StructurDiagramGenerator. Assign a molecule to the StructurDiagramGenerator, call the generateCoordinates() method and get your molecule back.- Parameters:
firstBondVector
- The vector of the first bond to lay out- Throws:
CDKException
- if an error occurs
-
generateCoordinates
public void generateCoordinates() throws CDKException
The main method of this StructurDiagramGenerator. Assign a molecule to the StructurDiagramGenerator, call the generateCoordinates() method and get your molecule back.- Throws:
CDKException
- if an error occurs
-
setBondLength
@Deprecated public void setBondLength(double bondLength)
Deprecated.This method used to set the bond length used for laying out the molecule. Since bond lengths in 2D are are arbitrary, the preferred way to do this is withGeometryUtil.scaleMolecule(IAtomContainer, double)
.IAtomContainer mol = ...; sdg.generateCoordinates(mol); int targetBondLength = 28; double factor = targetBondLength/GeometryUtil.getMedianBondLength(mol); GeometryUtil.scaleMolecule(mol, factor);
- Parameters:
bondLength
- The new bondLength value- Throws:
UnsupportedOperationException
- not supported
-
getBondLength
public double getBondLength()
Returns the bond length used for laying out the molecule.- Returns:
- The current bond length
-
getOtherBondAtom
public IAtom getOtherBondAtom(IAtom atom, IBond bond)
Returns the other atom of the bond. Expects bond to have only two atoms. Returns null if the given atom is not part of the given bond.- Parameters:
atom
- the atom we already havebond
- the bond- Returns:
- the other atom of the bond
-
-