Skip to content

Commit

Permalink
Watch out for ambiguity, we cannot collapse "N" "iPr" to "NiPr" as it…
Browse files Browse the repository at this point in the history
… is ambiguous with "Ni", "Pr".
  • Loading branch information
johnmay committed Dec 3, 2018
1 parent 6cfa36a commit 9e7cb8f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ else if (attachBond.getEnd().equals(atom))
return newSgroups;

// now collapse
collapse:
for (IAtom attach : mol.atoms()) {
if (usedAtoms.contains(attach))
continue;
Expand All @@ -470,8 +471,16 @@ else if (attachBond.getEnd().equals(atom))
for (Sgroup sgroup : sgroupAdjs.get(attach)) {
if (containsChargeChar(sgroup.getSubscript()))
continue;
xbonds.addAll(sgroup.getBonds());
if (sgroup.getBonds().size() != 1)
continue;
IBond xbond = sgroup.getBonds().iterator().next();
xbonds.add(xbond);
xatoms.addAll(sgroup.getAtoms());
if (attach.getSymbol().length() == 1 &&
Character.isLowerCase(sgroup.getSubscript().charAt(0))) {
if (Elements.ofString(attach.getSymbol() + sgroup.getSubscript().charAt(0)) != Elements.Unknown)
continue collapse;
}
nbrSymbols.add(sgroup.getSubscript());
todelete.add(sgroup);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getSubscript(), is("Pd(dppf)Cl2"));
}

// Don't generate NiPr
@Test public void avoidAmbiguity() throws Exception {
String smi = "C1CCCCC1=NC(C)C";
Abbreviations factory = new Abbreviations();
factory.add("*C(C)C iPr");
IAtomContainer mol = smi(smi);
List<Sgroup> sgroups = factory.generate(mol);
assertThat(sgroups.size(), is(1));
assertThat(sgroups.get(0).getSubscript(), is("iPr"));
}

@Test
public void loadFromFile() throws Exception {
Abbreviations factory = new Abbreviations();
Expand Down

0 comments on commit 9e7cb8f

Please sign in to comment.