File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/java/org/openscience/cdk/depict
test/java/org/openscience/cdk/depict Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -448,6 +448,7 @@ else if (attachBond.getEnd().equals(atom))
448448 return newSgroups ;
449449
450450 // now collapse
451+ collapse :
451452 for (IAtom attach : mol .atoms ()) {
452453 if (usedAtoms .contains (attach ))
453454 continue ;
@@ -470,8 +471,16 @@ else if (attachBond.getEnd().equals(atom))
470471 for (Sgroup sgroup : sgroupAdjs .get (attach )) {
471472 if (containsChargeChar (sgroup .getSubscript ()))
472473 continue ;
473- xbonds .addAll (sgroup .getBonds ());
474+ if (sgroup .getBonds ().size () != 1 )
475+ continue ;
476+ IBond xbond = sgroup .getBonds ().iterator ().next ();
477+ xbonds .add (xbond );
474478 xatoms .addAll (sgroup .getAtoms ());
479+ if (attach .getSymbol ().length () == 1 &&
480+ Character .isLowerCase (sgroup .getSubscript ().charAt (0 ))) {
481+ if (Elements .ofString (attach .getSymbol () + sgroup .getSubscript ().charAt (0 )) != Elements .Unknown )
482+ continue collapse ;
483+ }
475484 nbrSymbols .add (sgroup .getSubscript ());
476485 todelete .add (sgroup );
477486 }
Original file line number Diff line number Diff line change @@ -294,6 +294,17 @@ public void dontOverwriteExistingSgroups() throws Exception {
294294 assertThat (sgroups .get (0 ).getSubscript (), is ("Pd(dppf)Cl2" ));
295295 }
296296
297+ // Don't generate NiPr
298+ @ Test public void avoidAmbiguity () throws Exception {
299+ String smi = "C1CCCCC1=NC(C)C" ;
300+ Abbreviations factory = new Abbreviations ();
301+ factory .add ("*C(C)C iPr" );
302+ IAtomContainer mol = smi (smi );
303+ List <Sgroup > sgroups = factory .generate (mol );
304+ assertThat (sgroups .size (), is (1 ));
305+ assertThat (sgroups .get (0 ).getSubscript (), is ("iPr" ));
306+ }
307+
297308 @ Test
298309 public void loadFromFile () throws Exception {
299310 Abbreviations factory = new Abbreviations ();
You can’t perform that action at this time.
0 commit comments