@@ -382,7 +382,8 @@ public void placeLinearChain(IAtomContainer atomContainer, Vector2d initialBondV
382382 nextAtom .setFlag (CDKConstants .ISPLACED , true );
383383 boolean trans = false ;
384384
385- if (prevBond != null && isColinear (atom , molecule .getConnectedBondsList (atom ))) {
385+ if (prevBond != null &&
386+ isColinear (atom , molecule .getConnectedBondsList (atom ))) {
386387
387388 int atomicNumber = atom .getAtomicNumber ();
388389 int charge = atom .getFormalCharge ();
@@ -418,6 +419,20 @@ public void placeLinearChain(IAtomContainer atomContainer, Vector2d initialBondV
418419 }
419420 }
420421
422+ private boolean isTerminalD4 (IAtom atom ) {
423+ List <IBond > bonds = molecule .getConnectedBondsList (atom );
424+ if (bonds .size () != 4 )
425+ return false ;
426+ int nonD1 = 0 ;
427+ for (IBond bond : bonds ) {
428+ if (molecule .getConnectedBondsCount (bond .getOther (atom )) != 1 ) {
429+ if (++nonD1 > 1 )
430+ return false ;
431+ }
432+ }
433+ return true ;
434+ }
435+
421436 /**
422437 * Returns the next bond vector needed for drawing an extended linear chain of
423438 * atoms. It assumes an angle of 120 deg for a nice chain layout and
@@ -449,7 +464,13 @@ public Vector2d getNextBondVector(IAtom atom, IAtom previousAtom, Point2d distan
449464
450465 double angle = GeometryUtil .getAngle (previousAtom .getPoint2d ().x - atom .getPoint2d ().x ,
451466 previousAtom .getPoint2d ().y - atom .getPoint2d ().y );
452- double addAngle = Math .toRadians (120 );
467+ double addAngle ;
468+
469+ if (isTerminalD4 (atom ))
470+ addAngle = Math .toRadians (45 );
471+ else
472+ addAngle = Math .toRadians (120 );
473+
453474 if (!trans ) addAngle = Math .toRadians (60 );
454475 if (isColinear (atom , molecule .getConnectedBondsList (atom ))) addAngle = Math .toRadians (180 );
455476
0 commit comments