Skip to content

Commit

Permalink
Do not align atoms if their geometry doesn't match, for now this mean…
Browse files Browse the repository at this point in the history
…s (collinear vs bent).
  • Loading branch information
johnmay committed Oct 18, 2018
1 parent c464d4f commit 922672c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -940,15 +940,14 @@ public int compare(Integer a, Integer b) {
* -C=[N+]=N
* -N=[N+]=N
*/
boolean isColinear(IAtom atom, List<IBond> bonds) {
if (bonds.size() != 2)
return false;

static boolean isColinear(IAtom atom, Iterable<IBond> bonds) {
int numSgl = atom.getImplicitHydrogenCount() == null ? 0 : atom.getImplicitHydrogenCount();
int numDbl = 0;
int numTpl = 0;
int count = 0;

for (IBond bond : bonds) {
++count;
switch (bond.getOrder()) {
case SINGLE:
numSgl++;
Expand All @@ -966,6 +965,9 @@ boolean isColinear(IAtom atom, List<IBond> bonds) {
}
}

if (count != 2)
return false;

switch (atom.getAtomicNumber()) {
case 6:
case 7:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ public final void generateCoordinates(final IReaction reaction) throws CDKExcept
afix.clear();
bfix.clear();

boolean aggresive = false;

if (largest != null && largest.getAtomCount() > 1) {

int idx = largest.getAtom(0).getProperty(CDKConstants.ATOM_ATOM_MAPPING);
Expand All @@ -246,13 +248,22 @@ public final void generateCoordinates(final IReaction reaction) throws CDKExcept
idx = atom.getProperty(CDKConstants.ATOM_ATOM_MAPPING);
final IAtom src = reference.get(idx);
if (src == null) continue;
if (!aggresive) {
// no way to get the container of 'src' without
// lots of refactoring, instead we just use the
// new API points - first checking these will not
// fail
if (src.getContainer() != null
&& atom.getContainer() != null
&& AtomPlacer.isColinear(src, src.bonds())
!= AtomPlacer.isColinear(atom, atom.bonds()))
continue;
}
atom.setPoint2d(new Point2d(src.getPoint2d()));
afix.put(atom, src);
}
}

boolean aggresive = false;

if (!afix.isEmpty()) {
if (aggresive) {
for (IBond bond : mol.bonds()) {
Expand Down

0 comments on commit 922672c

Please sign in to comment.