Logo Search packages:      
Sourcecode: cdk version File versions  Download package

void org::openscience::cdk::layout::StructureDiagramGenerator::generateCoordinates ( Vector2d  firstBondVector  )  throws java.lang.Exception [inline]

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
Exceptions:
java.lang.Exception if an error occurs

Definition at line 288 of file StructureDiagramGenerator.java.

References org::openscience::cdk::layout::AtomPlacer::allPlaced(), org::openscience::cdk::layout::RingPlacer::checkAndMarkPlaced(), org::openscience::cdk::tools::LoggingTool::debug(), org::openscience::cdk::ringsearch::SSSRFinder::findSSSR(), fixRest(), org::openscience::cdk::interfaces::IAtomContainer::getAtom(), org::openscience::cdk::interfaces::IAtomContainerSet::getAtomContainerCount(), org::openscience::cdk::interfaces::IAtomContainer::getAtomCount(), org::openscience::cdk::interfaces::IAtomContainer::getBondCount(), org::openscience::cdk::layout::AtomPlacer::getInitialLongestChain(), org::openscience::cdk::layout::TemplateHandler::getMappedSubstructures(), getTemplateHandler(), handleAliphatics(), layoutNextRingSystem(), layoutRingSet(), mappedSubstructures, markRingAtoms(), org::openscience::cdk::layout::AtomPlacer::placeLinearChain(), org::openscience::cdk::layout::RingPlacer::placeRingSubstituents(), org::openscience::cdk::interfaces::IChemObject::setFlag(), org::openscience::cdk::layout::RingPlacer::setMolecule(), and org::openscience::cdk::interfaces::IAtom::setPoint2d().

Referenced by org::openscience::cdk::applications::jchempaint::action::CopyPasteAction::actionPerformed(), org::openscience::cdk::applications::swing::MoleculeListViewer::addStructure(), org::openscience::cdk::applications::FileConvertor::convert(), and org::openscience::cdk::applications::jchempaint::applet::JChemPaintAbstractApplet::loadModelFromSmiles().

      {
            int safetyCounter = 0;
            /*
             *  if molecule contains only one Atom, don't fail, simply
             *  set coordinates to simplest: 0,0. See bug #780545
             */
            logger.debug("Entry point of generateCoordinates()");
            logger.debug("We have a molecules with " + molecule.getAtomCount() + " atoms.");
            if (molecule.getAtomCount() == 1)
            {
                  molecule.getAtom(0).setPoint2d(new Point2d(0, 0));
                  return;
            }
            if (!ConnectivityChecker.isConnected(molecule))
            {
                  logger.debug("Molecule is not connected. Throwing exception.");
                  throw new CDKException(disconnectedMessage);
            } else
            {
                  logger.debug("Molecule is connected.");
            }

            /*
             *  compute the minimum number of rings as
             *  given by Frerejacque, Bull. Soc. Chim. Fr., 5, 1008 (1939)
             */
            int nrOfEdges = molecule.getBondCount();
            //Vector2d ringSystemVector = null;
            //Vector2d newRingSystemVector = null;
            this.firstBondVector = firstBondVector;
            boolean templateMapped = false;
            double angle;

            /*
             *  First we check if we can map any templates with predefined coordinates
             *  Those are stored as MDL molfiles in data/templates
             */
            if (useTemplates && (System.getProperty("java.version").indexOf("1.3.") == -1))
            {
                  logger.debug("Initializing TemplateHandler");
                  logger.debug("TemplateHander initialized");
                  logger.debug("Now starting Template Detection in Molecule...");
                  mappedSubstructures = getTemplateHandler().getMappedSubstructures(molecule);
                  templateMapped = mappedSubstructures.getAtomContainerCount() > 0;
                  logger.debug("Template Detection finished");
                  logger.debug("Number of found templates: " + mappedSubstructures.getAtomContainerCount());
            }
                                                
            int expectedRingCount = nrOfEdges - molecule.getAtomCount() + 1;
            if (expectedRingCount > 0)
            {
                  logger.debug("*** Start of handling rings. ***");
                  /*
                   *  Get the smallest set of smallest rings on this molecule
                   */
                                                                        SSSRFinder sssrf = new SSSRFinder(molecule);

                  sssr = sssrf.findSSSR();
                  if (sssr.getAtomContainerCount() < 1)
                  {
                        return;
                  }
                                                                        
                  /*
                   * Order the rings because SSSRFinder.findSSSR() returns rings in an
                   * undeterministic order.
                   */
                  AtomContainerSetManipulator.sort(sssr);
                                                                        
                  /*
                   *  Mark all the atoms from the ring system as "ISINRING"
                   */
                  markRingAtoms(sssr);
                  /*
                   *  Give a handle of our molecule to the ringPlacer
                   */
                  ringPlacer.setMolecule(molecule);
                  ringPlacer.checkAndMarkPlaced(sssr);
                  /*
                   *  Partition the smallest set of smallest rings into disconnected ring system.
                   *  The RingPartioner returns a Vector containing RingSets. Each of the RingSets contains
                   *  rings that are connected to each other either as bridged ringsystems, fused rings or
                   *  via spiro connections.
                   */
                  ringSystems = RingPartitioner.partitionRings(sssr);
                                                                        
                  /*
                   *  We got our ring systems now
                   */
                                                                        
                  /*
                   *  Do the layout for the first connected ring system ...
                   */
                  int largest = 0;
                  int largestSize = ((IRingSet) ringSystems.get(0)).getAtomContainerCount();
                  logger.debug("We have " + ringSystems.size() + " ring system(s).");
                  for (int f = 0; f < ringSystems.size(); f++)
                  {
                        logger.debug("RingSet " + f + " has size " + ((IRingSet) ringSystems.get(f)).getAtomContainerCount());
                        if (((IRingSet) ringSystems.get(f)).getAtomContainerCount() > largestSize)
                        {
                              largestSize = ((IRingSet) ringSystems.get(f)).getAtomContainerCount();
                              largest = f;
                        }
                  }
                  logger.debug("Largest RingSystem is at RingSet collection's position " + largest);
                  logger.debug("Size of Largest RingSystem: " + largestSize);

                  layoutRingSet(firstBondVector, (IRingSet) ringSystems.get(largest));
                  logger.debug("First RingSet placed");
                  /*
                   *  and do the placement of all the directly connected atoms of this ringsystem
                   */
                  ringPlacer.placeRingSubstituents((IRingSet) ringSystems.get(largest), bondLength);

            } else
            {
                  
                  logger.debug("*** Start of handling purely aliphatic molecules. ***");
                  /*
                   *  We are here because there are no rings in the molecule
                   *  so we get the longest chain in the molecule and placed in
                   *  on a horizontal axis
                   */
                  logger.debug("Searching initialLongestChain for this purely aliphatic molecule");
                  IAtomContainer longestChain = atomPlacer.getInitialLongestChain(molecule);
                  logger.debug("Found linear chain of length " + longestChain.getAtomCount());
                  logger.debug("Setting coordinated of first atom to 0,0");
                  longestChain.getAtom(0).setPoint2d(new Point2d(0, 0));
                  longestChain.getAtom(0).setFlag(CDKConstants.ISPLACED, true);

                  /*
                   *  place the first bond such that the whole chain will be horizontally
                   *  alligned on the x axis
                   */
                  angle = Math.toRadians(-30);
                  logger.debug("Attempting to place the first bond such that the whole chain will be horizontally alligned on the x axis");
                  if (firstBondVector != null)
                        atomPlacer.placeLinearChain(longestChain, firstBondVector, bondLength);
                  else
                        atomPlacer.placeLinearChain(longestChain, new Vector2d(Math.cos(angle), Math.sin(angle)), bondLength);
                  logger.debug("Placed longest aliphatic chain");
            }

            /*
             *  Now, do the layout of the rest of the molecule
             */
            do
            {
                  safetyCounter++;
                  logger.debug("*** Start of handling the rest of the molecule. ***");
                  /*
                   *  do layout for all aliphatic parts of the molecule which are
                   *  connected to the parts which have already been laid out.
                   */
                  handleAliphatics();
                  /*
                   *  do layout for the next ring aliphatic parts of the molecule which are
                   *  connected to the parts which have already been laid out.
                   */
                  layoutNextRingSystem();
            } while (!atomPlacer.allPlaced(molecule) && safetyCounter <= molecule.getAtomCount());

            fixRest();
            new OverlapResolver().resolveOverlap(molecule, sssr);
      }


Generated by  Doxygen 1.6.0   Back to index