Skip to content

Commit

Permalink
Allow contractions like SnCl2.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Oct 5, 2016
1 parent 91a92e4 commit aaae48e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.openscience.cdk.depict;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Multimap;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.config.Elements;
Expand Down Expand Up @@ -494,6 +495,7 @@ else if (attachBond.getAtom(1) == atom)
nbrSymbols.add(sgroup.getSubscript());
todelete.add(sgroup);
}
int numSGrpNbrs = nbrSymbols.size();
for (IBond bond : mol.getConnectedBondsList(attach)) {
if (!xbonds.contains(bond)) {
IAtom nbr = bond.getConnectedAtom(attach);
Expand All @@ -515,7 +517,12 @@ else if (attachBond.getAtom(1) == atom)
}
}

if (newbonds.size() < 1 || newbonds.size() > 3 || nbrSymbols.isEmpty())
// reject if no symbols
// reject if no bonds (<1), except if all symbols are identical... (HashSet.size==1)
// reject if more that 2 bonds
if (nbrSymbols.isEmpty() ||
newbonds.size() < 1 && (new HashSet<>(nbrSymbols).size() != 1) ||
newbonds.size() > 2)
continue;

// create the symbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getSubscript(), is("EDCI·HCl"));
}

@Test public void SnCl2() throws Exception {
Abbreviations factory = new Abbreviations();
IAtomContainer mol = smi("Cl[Sn]Cl");
List<Sgroup> sgroups = factory.generate(mol);
assertThat(sgroups.size(), is(1));
assertThat(sgroups.get(0).getSubscript(), is("SnCl2"));
}

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

0 comments on commit aaae48e

Please sign in to comment.