Skip to content

Commit

Permalink
HOOH not OHOH.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Oct 7, 2016
1 parent 953e611 commit 2b83fa4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Expand Up @@ -508,7 +508,7 @@ else if (attachBond.getAtom(1) == atom)
hcount++;
xatoms.add(nbr);
} else if (nbr.getAtomicNumber() > 0){
nbrSymbols.add(newSymbol(nbr.getAtomicNumber(), nbr.getImplicitHydrogenCount()));
nbrSymbols.add(newSymbol(nbr.getAtomicNumber(), nbr.getImplicitHydrogenCount(), false));
xatoms.add(nbr);
}
} else {
Expand All @@ -527,7 +527,7 @@ else if (attachBond.getAtom(1) == atom)

// create the symbol
StringBuilder sb = new StringBuilder();
sb.append(newSymbol(attach.getAtomicNumber(), hcount));
sb.append(newSymbol(attach.getAtomicNumber(), hcount, newbonds.size() == 0));
String prev = null;
int count = 0;
Collections.sort(nbrSymbols, new Comparator<String>() {
Expand Down Expand Up @@ -597,16 +597,25 @@ private boolean digitAtEnd(String str) {
return Character.isDigit(str.charAt(str.length()-1));
}

private String newSymbol(int atomnum, int hcount) {
private String newSymbol(int atomnum, int hcount, boolean prefix) {
StringBuilder sb = new StringBuilder();
Elements elem = Elements.ofNumber(atomnum);
if (elem == Elements.Carbon && hcount == 3)
return "Me";
sb.append(elem.symbol());
if (hcount > 0) {
sb.append('H');
if (hcount > 1)
sb.append(hcount);
if (prefix) {
if (hcount > 0) {
sb.append('H');
if (hcount > 1)
sb.append(hcount);
}
sb.append(elem.symbol());
} else {
sb.append(elem.symbol());
if (hcount > 0) {
sb.append('H');
if (hcount > 1)
sb.append(hcount);
}
}
return sb.toString();
}
Expand Down
Expand Up @@ -264,6 +264,14 @@ public void dontOverwriteExistingSgroups() throws Exception {
assertThat(sgroups.get(0).getSubscript(), is("SnCl2"));
}

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

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

0 comments on commit 2b83fa4

Please sign in to comment.