Skip to content

Commit

Permalink
Separate out layout seeding from continuation.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Jun 5, 2016
1 parent 3ec5fb4 commit 819a7f6
Showing 1 changed file with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,31 @@ private void generateCoordinates(Vector2d firstBondVector, boolean isConnected,
}
}

// initial layout seeding either from a ring system of longest chain
seedLayout();

// Now, do the layout of the rest of the molecule
for (int i = 0; !AtomPlacer.allPlaced(molecule) && i < numAtoms; i++) {
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.
layoutAcyclicParts();
// layout cyclic parts of the molecule which
// are connected to the parts which have already been laid out.
layoutCyclicParts();
}

if (!isSubLayout)
assignStereochem(molecule);

refinePlacement(molecule);
finalizeLayout(molecule);
}

private void seedLayout() throws CDKException {

int numAtoms = this.molecule.getAtomCount();
int numBonds = this.molecule.getBondCount();
// Compute the circuit rank (https://en.wikipedia.org/wiki/Circuit_rank).
// Frerejacque, Bull. Soc. Chim. Fr., 5, 1008 (1939)
final int circuitrank = numBonds - numAtoms + 1;
Expand Down Expand Up @@ -477,23 +502,6 @@ public int compare(IRingSet a, IRingSet b) {
atomPlacer.placeLinearChain(longestChain, new Vector2d(Math.cos(RAD_30), Math.sin(RAD_30)), bondLength);
logger.debug("Placed longest aliphatic chain");
}

// Now, do the layout of the rest of the molecule
for (int i = 0; !AtomPlacer.allPlaced(molecule) && i < numAtoms; i++) {
logger.debug("*** Start of handling the rest of the molecule. ***");
// layout for all acylic parts of the molecule which are
// connected to the parts which have already been laid out.
handleAliphatics();
// layout cyclic parts of the molecule which
// are connected to the parts which have already been laid out.
layoutNextRingSystem();
}

if (!isSubLayout)
assignStereochem(molecule);

refinePlacement(molecule);
finalizeLayout(molecule);
}

private void assignStereochem(IAtomContainer molecule) {
Expand Down Expand Up @@ -1218,7 +1226,7 @@ private boolean isMacroCycle(IRing ring, IRingSet rs) {
*
* @throws CDKException if an error occurs
*/
private void handleAliphatics() throws CDKException {
private void layoutAcyclicParts() throws CDKException {
logger.debug("Start of handleAliphatics");

int safetyCounter = 0;
Expand Down Expand Up @@ -1293,7 +1301,7 @@ private void handleAliphatics() throws CDKException {
*
* @throws CDKException if an error occurs
*/
private void layoutNextRingSystem() throws CDKException {
private void layoutCyclicParts() throws CDKException {
logger.debug("Start of layoutNextRingSystem()");

resetUnplacedRings();
Expand Down

0 comments on commit 819a7f6

Please sign in to comment.