From 99a5a128cfcf946bacad62ca66f36b91c34b44fe Mon Sep 17 00:00:00 2001 From: John May Date: Tue, 7 Jun 2016 13:44:15 +0100 Subject: [PATCH] Handle more cases of fixed coordinates. --- .../cdk/layout/StructureDiagramGenerator.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tool/sdg/src/main/java/org/openscience/cdk/layout/StructureDiagramGenerator.java b/tool/sdg/src/main/java/org/openscience/cdk/layout/StructureDiagramGenerator.java index 956246977e6..4982c915ff1 100644 --- a/tool/sdg/src/main/java/org/openscience/cdk/layout/StructureDiagramGenerator.java +++ b/tool/sdg/src/main/java/org/openscience/cdk/layout/StructureDiagramGenerator.java @@ -399,7 +399,8 @@ private void generateCoordinates(Vector2d firstBondVector, boolean isConnected, seedLayout(); // Now, do the layout of the rest of the molecule - for (int i = 0; !AtomPlacer.allPlaced(molecule) && i < numAtoms; i++) { + int iter = 0; + for (; !AtomPlacer.allPlaced(molecule) && iter < numAtoms; iter++) { logger.debug("*** Start of handling the rest of the molecule. ***"); // layout for all acyclic parts of the molecule which are // connected to the parts which have already been laid out. @@ -444,9 +445,15 @@ private void seedLayout() throws CDKException { // Frerejacque, Bull. Soc. Chim. Fr., 5, 1008 (1939) final int circuitrank = numBonds - numAtoms + 1; if (hasFixedPart(molecule)) { + // no seeding needed as the molecule has atoms with coordinates, just calc rings if needed - if (circuitrank > 0) + if (circuitrank > 0) { prepareRingSystems(); + for (IRingSet rset : ringSystems) { + if (rset.getFlag(CDKConstants.ISPLACED)) + ringPlacer.placeRingSubstituents(rset, bondLength); + } + } } else if (circuitrank > 0) { logger.debug("*** Start of handling rings. ***"); prepareRingSystems(); @@ -1336,7 +1343,7 @@ private void layoutAcyclicParts() throws CDKException { private void layoutCyclicParts() throws CDKException { logger.debug("Start of layoutNextRingSystem()"); - // resetUnplacedRings(); + resetUnplacedRings(); IAtomContainer placedAtoms = AtomPlacer.getPlacedAtoms(molecule); logger.debug("Finding attachment bond to already placed part..."); IBond nextRingAttachmentBond = getNextBondWithUnplacedRingAtom(); @@ -1428,15 +1435,21 @@ private void layoutCyclicParts() throws CDKException { if (!ring.getFlag(CDKConstants.ISPLACED)) { partiallyPlacedRing.removeAllElements(); + for (IAtom atom : ring.atoms()) + if (atom.getPoint2d() != null) + atom.setFlag(CDKConstants.ISPLACED, true); AtomPlacer.copyPlaced(partiallyPlacedRing, ring); - if (partiallyPlacedRing.getAtomCount() < ring.getAtomCount()) { + if (partiallyPlacedRing.getAtomCount() > 0 && partiallyPlacedRing.getAtomCount() < ring.getAtomCount()) { ringPlacer.placeConnectedRings(ringset, partiallyPlacedRing, RingPlacer.FUSED, bondLength); ringPlacer.placeConnectedRings(ringset, partiallyPlacedRing, RingPlacer.BRIDGED, bondLength); ringPlacer.placeConnectedRings(ringset, partiallyPlacedRing, RingPlacer.SPIRO, bondLength); } } } + + if (allPlaced(ringset)) + ringPlacer.placeRingSubstituents(ringset, bondLength); } } }