Skip to content

Commit

Permalink
Speeds up coordgen
Browse files Browse the repository at this point in the history
When detecting clashes, do a rough binning of atoms. If both
atoms for one bond are above both atoms of the other bond, they
can't be a clash. This saves clash calculations for things that
are obviously not clashes. It has an impact on big structures
that are partially templated. (overall 15% speedup, but 40%
improvement for the worst molecules in the test case.

Also adds a simplistic test that the coordinates generated don't
have crazy bond lengths.
  • Loading branch information
d-b-w committed Sep 30, 2019
1 parent 35def78 commit 30cef9b
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1,590 deletions.
14 changes: 14 additions & 0 deletions CoordgenMinimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,20 @@ bool CoordgenMinimizer::bondsClash(sketcherMinimizerBond* bond,
bond->getEndAtom() == bond2->getEndAtom()) {
return false;
}
auto& start1 = bond->getStartAtom()->coordinates;
auto& start2 = bond2->getStartAtom()->coordinates;
auto& end1 = bond->getEndAtom()->coordinates;
auto& end2 = bond2->getEndAtom()->coordinates;
// coincidence and intersection calculations are expensive. Often bonds
// are nowhere near each other, so skip the remaining work if a bond is
// strictly to the left or right of another bond.
if (max(start1.x(), end1.x()) < min(start2.x(), end2.x()) ||
max(start1.y(), end1.y()) < min(start2.y(), end2.y()) ||
min(start1.x(), end1.x()) > max(start2.x(), end2.x()) ||
min(start1.y(), end1.y()) > max(start2.y(), end2.y())) {
return false;
}

if (sketcherMinimizerMaths::pointsCoincide(
bond->getStartAtom()->coordinates,
bond2->getStartAtom()->coordinates) ||
Expand Down
2 changes: 1 addition & 1 deletion sketcherMinimizerAtom.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class EXPORT_COORDGEN sketcherMinimizerAtom
* stereochemistry */
bool hasNoStereoActiveBonds() const;

sketcherMinimizerPointF getCoordinates() const { return coordinates; }
const sketcherMinimizerPointF& getCoordinates() const { return coordinates; }
int getAtomicNumber() const { return atomicNumber; }

void setAtomicNumber(int number) { atomicNumber = number; }
Expand Down
13 changes: 6 additions & 7 deletions sketcherMinimizerClashInteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class sketcherMinimizerClashInteraction : public sketcherMinimizerInteraction
/* calculate the energy of the clash */
void energy(float& e) override
{
float squaredDistance =
squaredDistance =
sketcherMinimizerMaths::squaredDistancePointSegment(
atom2->coordinates, atom1->coordinates, atom3->coordinates);
if (squaredDistance > restV)
Expand All @@ -49,16 +49,13 @@ class sketcherMinimizerClashInteraction : public sketcherMinimizerInteraction
energy(totalE);
if (skipForce)
return;
if (squaredDistance > restV)
return;

sketcherMinimizerPointF atomP = atom2->coordinates;
sketcherMinimizerPointF bondP1 = atom1->coordinates;
sketcherMinimizerPointF bondP2 = atom3->coordinates;

float squaredDistance =
sketcherMinimizerMaths::squaredDistancePointSegment(atomP, bondP1,
bondP2);
if (squaredDistance > restV)
return;

sketcherMinimizerPointF projection =
sketcherMinimizerMaths::projectPointOnLine(atomP, bondP1, bondP2);
sketcherMinimizerPointF f = atomP - projection;
Expand All @@ -72,6 +69,8 @@ class sketcherMinimizerClashInteraction : public sketcherMinimizerInteraction

float k2;
sketcherMinimizerAtom* atom3;
private:
float squaredDistance;
};

#endif // sketcherMINIMIZERCLASHINTERACTION
Loading

0 comments on commit 30cef9b

Please sign in to comment.