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 with setMolecule(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 Details

  • Constructor Details

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

    • 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
    • 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 anymore
      Sets 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 anymore
      Returns 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 templates
      Sets 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 anymore
      Gets 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:
    • 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)
      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 with GeometryUtil.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 have
      bond - the bond
      Returns:
      the other atom of the bond