Skip to content

Commit

Permalink
Spotted in previous commit - we should add H to extended tetrahedral …
Browse files Browse the repository at this point in the history
…also.
  • Loading branch information
johnmay committed Jun 17, 2017
1 parent 1dc567b commit 253820a
Showing 1 changed file with 29 additions and 12 deletions.
Expand Up @@ -444,6 +444,13 @@ public static int countExplicitHydrogens(IAtomContainer atomContainer, IAtom ato
return hCount;
}

private static final void replaceAtom(IAtom[] atoms, IAtom org, IAtom rep) {
for (int i = 0; i < atoms.length; i++) {
if (atoms[i].equals(org))
atoms[i] = rep;
}
}

/**
* Adds explicit hydrogens (without coordinates) to the IAtomContainer,
* equaling the number of set implicit hydrogens.
Expand Down Expand Up @@ -483,28 +490,38 @@ public static void convertImplicitToExplicitHydrogens(IAtomContainer atomContain
for (IBond bond : newBonds)
atomContainer.addBond(bond);

// update tetrahedral elements with an implicit part
// update stereo elements with an implicit part
List<IStereoElement> stereos = new ArrayList<>();
for (IStereoElement stereo : atomContainer.stereoElements()) {
if (stereo instanceof ITetrahedralChirality) {
ITetrahedralChirality tc = (ITetrahedralChirality) stereo;

IAtom focus = tc.getChiralAtom();
IAtom[] neighbors = tc.getLigands();
IAtom hydrogen = hNeighbor.get(focus);
IAtom focus = tc.getFocus();
IAtom[] carriers = tc.getCarriers().toArray(new IAtom[4]);
IAtom hydrogen = hNeighbor.get(focus);

// in sulfoxide - the implicit part of the tetrahedral centre
// is a lone pair

if (hydrogen != null) {
for (int i = 0; i < 4; i++) {
if (neighbors[i] == focus) {
neighbors[i] = hydrogen;
break;
}
}
// neighbors is a copy so need to create a new stereocenter
stereos.add(new TetrahedralChirality(focus, neighbors, tc.getStereo()));
replaceAtom(carriers, focus, hydrogen);
stereos.add(new TetrahedralChirality(focus, carriers, tc.getStereo()));
} else {
stereos.add(stereo);
}
} else if (stereo instanceof ExtendedTetrahedral) {
ExtendedTetrahedral tc = (ExtendedTetrahedral) stereo;

IAtom focus = tc.getFocus();
IAtom[] carriers = tc.getCarriers().toArray(new IAtom[4]);
IAtom hydrogen = hNeighbor.get(focus);

// in sulfoxide - the implicit part of the tetrahedral centre
// is a lone pair

if (hydrogen != null) {
replaceAtom(carriers, focus, hydrogen);
stereos.add(new TetrahedralChirality(focus, carriers, tc.getConfig()));
} else {
stereos.add(stereo);
}
Expand Down

0 comments on commit 253820a

Please sign in to comment.