Skip to content

Commit 9e7cb8f

Browse files
committed
Watch out for ambiguity, we cannot collapse "N" "iPr" to "NiPr" as it is ambiguous with "Ni", "Pr".
1 parent 6cfa36a commit 9e7cb8f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

app/depict/src/main/java/org/openscience/cdk/depict/Abbreviations.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

app/depict/src/test/java/org/openscience/cdk/depict/AbbreviationsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)