Skip to content

Commit 2d5996f

Browse files
committed
Add some more explanation about what's going on with the counts.
1 parent 7b31b35 commit 2d5996f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

base/standard/src/main/java/org/openscience/cdk/stereo/Stereocenters.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ private boolean verifyTerminalHCount(int v) {
597597

598598
boolean found = false;
599599

600+
// group the 'X' neighbours we care about,
601+
// N=>1, O=>2, S=>3, etc, anything we don't care
602+
// about goes in slot 0
600603
for (int w : g[v]) {
601604
int idx = indexNeighbor(container.getAtom(w));
602605
atoms[idx][counts[idx]++] = w;
@@ -605,26 +608,34 @@ private boolean verifyTerminalHCount(int v) {
605608

606609
if (!found) return true;
607610

611+
// now we have the neighbours group check out one,
612+
// N first, O, then S, etc and check if there is at
613+
// least two terminals atom and the total number of H
614+
// connected to these terminals is >= 1. i.e. -XHm and -XHn, (n+m>0)
608615
for (int i = 1; i < counts.length; i++) {
609616
if (counts[i] < 2) continue;
610617

611618
int terminalCount = 0;
612619
int terminalHCount = 0;
613620

614621
for (int j = 0; j < counts[i]; j++) {
615-
int hCount = 0;
616-
int[] ws = g[atoms[i][j]];
622+
int explHCount = 0;
623+
int[] ws = g[atoms[i][j]];
617624
for (int w : g[atoms[i][j]]) {
618625
IAtom atom = container.getAtom(w);
619626
if (atomicNumber(atom) == 1 && atom.getMassNumber() == null) {
620-
hCount++;
627+
explHCount++;
621628
}
622629
}
623630

624-
// is terminal?
625-
if (ws.length - hCount == 1) {
631+
final int degree = ws.length - explHCount;
632+
if (degree == 1) {
626633
terminalCount++;
627-
terminalHCount += hCount + container.getAtom(atoms[i][j]).getImplicitHydrogenCount();
634+
terminalHCount += explHCount;
635+
IAtom atom = container.getAtom(atoms[i][j]);
636+
Integer implHCount = atom.getImplicitHydrogenCount();
637+
if (implHCount != null)
638+
terminalHCount += implHCount;
628639
}
629640
}
630641

0 commit comments

Comments
 (0)