Skip to content

Commit 0eb16f8

Browse files
committed
Additional tweaks for: [Co@OH8](N=[N+]=[N-])(N=[N+]=[N-])(N=[N+]=[N-])([N]1=CC=CC=C1)1[NH2]CC[NH2]1
1 parent a895a09 commit 0eb16f8

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tool/sdg/src/main/java/org/openscience/cdk/layout/NonplanarBonds.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ private boolean snapBondToPosition(IAtom beg, IBond bond, Point2d tP) {
258258
dest.normalize();
259259

260260
// close enough, give it a little bump to be perfect
261-
if (curr.dot(dest) >= 0.97) {
261+
double dot = curr.dot(dest);
262+
if (dot >= 0.97) {
262263
rotate(end.getPoint2d(), bP, cos, sin);
263264
return true;
264265
}
@@ -289,12 +290,18 @@ private boolean snapBondToPosition(IAtom beg, IBond bond, Point2d tP) {
289290
curr.normalize();
290291

291292
// did we get close?
292-
boolean okay = curr.dot(dest) >= 0.97;
293+
double newdot = curr.dot(dest);
294+
boolean okay = newdot >= 0.97;
293295

294296
// hard snap to expected position
295297
if (okay) {
296298
theta = Math.atan2(curr.y, curr.x) - Math.atan2(dest.y, dest.x);
297299
rotate(end.getPoint2d(), bP, Math.cos(theta), Math.sin(theta));
300+
} else if (newdot < dot) {
301+
// reflect it back
302+
GeometryUtil.reflect(visit.keySet(),
303+
reflectBond.getBegin().getPoint2d(),
304+
reflectBond.getEnd().getPoint2d());
298305
}
299306

300307
return okay;
@@ -523,7 +530,7 @@ else if (rnums.get(3).equals(rnums.get(0)))
523530
if (bonds.size() == 5) {
524531

525532
// check for trans- pairing which we can't lay out at the moment
526-
if (rnums.get(0).equals(rnums.get(4)))
533+
if (rnums.get(0) != 0 && rnums.get(0).equals(rnums.get(4)))
527534
return SPIRO_REJECT;
528535

529536
// rotate such that there is a spiro (or no rings) in position 1/2 in the plane, these are laid out
@@ -557,9 +564,9 @@ else if (rnums.get(3) != 0 && rnums.get(3).equals(rnums.get(2)) ||
557564
if (bonds.size() == 6) {
558565

559566
// check for trans- pairings which we can't lay out at the moment
560-
if (rnums.get(0).equals(rnums.get(5)) ||
561-
rnums.get(1).equals(rnums.get(3)) ||
562-
rnums.get(2).equals(rnums.get(4)))
567+
if (rnums.get(0) != 0 && rnums.get(0).equals(rnums.get(5)) ||
568+
rnums.get(1) != 0 && rnums.get(1).equals(rnums.get(3)) ||
569+
rnums.get(2) != 0 && rnums.get(2).equals(rnums.get(4)))
563570
return SPIRO_REJECT;
564571

565572
// rotate such that there is a spiro (or no rings) in position 2/3 in the plane, these are laid out

0 commit comments

Comments
 (0)