Skip to content

Commit

Permalink
Assign numbers to unlabelled atoms (i.e. hydrogens). Beam will handle…
Browse files Browse the repository at this point in the history
… the correct hydrogen ordering (CDK API makes this difficult).

Signed-off-by: Stephan Beisken <sbeisken@gmail.com>
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Dec 18, 2013
1 parent 5acf0bb commit dfc5a6f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Expand Up @@ -92,6 +92,11 @@ public static long[] getUSmilesNumbers(IAtomContainer container) throws CDKExcep
* charged oxygen atom, start instead at any carbonyl oxygen attached to the
* same neighbour." <p/>
*
* All unlabelled atoms (e.g. hydrogens) are assigned the same label which
* is different but larger then all other labels. The hydrogen
* labelling then needs to be adjusted externally as universal SMILES
* suggests hydrogens should be visited first.
*
* @param aux inchi AuxInfo
* @param container the structure to obtain the numbering of
* @return the numbers string to use
Expand All @@ -102,8 +107,8 @@ static long[] parseUSmilesNumbers(String aux, IAtomContainer container) {
int index;
long[] numbers = new long[container.getAtomCount()];
int[] first = null;
int label = 1;

int label = 1;
if ((index = aux.indexOf("/R:")) >= 0) { // reconnected metal numbers
String[] baseNumbers = aux.substring(index + 8, aux.indexOf('/', index + 8)).split(";");
first = new int[baseNumbers.length];
Expand Down Expand Up @@ -176,6 +181,11 @@ static long[] parseUSmilesNumbers(String aux, IAtomContainer container) {
}
}
}

// assign unlabelled atoms
for (int i = 0; i < numbers.length; i++)
if (numbers[i] == 0)
numbers[i] = label;

return numbers;
}
Expand Down
Expand Up @@ -157,6 +157,12 @@ public void fixedH() throws Exception {
is(new long[]{3, 2, 1}));
}

@Test public void unlabelledHydrogens() throws Exception {
IAtomContainer container = new SmilesParser(SilentChemObjectBuilder.getInstance()).parseSmiles("[H]C([H])([H])[H]");
assertThat(InChINumbersTools.getUSmilesNumbers(container),
is(new long[]{2, 1, 2, 2, 2}));
}

static IAtomContainer mock(int nAtoms) {
IAtomContainer container = Mockito.mock(IAtomContainer.class);
when(container.getAtomCount()).thenReturn(nAtoms);
Expand Down

0 comments on commit dfc5a6f

Please sign in to comment.