-
Notifications
You must be signed in to change notification settings - Fork 28
/
sketcherMinimizerInteraction.h
71 lines (64 loc) · 1.98 KB
/
sketcherMinimizerInteraction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* sketcherMinimizerInteraction.h
*
* Created by Nicola Zonta on 13/04/2010.
* Copyright Schrodinger, LLC. All rights reserved.
*
*/
#ifndef sketcherMINIMIZERINTERACTION
#define sketcherMINIMIZERINTERACTION
#include "sketcherMinimizerAtom.h"
/* abstract class for force field interactions */
class sketcherMinimizerInteraction
{
public:
sketcherMinimizerInteraction(sketcherMinimizerAtom* at1,
sketcherMinimizerAtom* at2)
{
atom1 = at1;
atom2 = at2;
k = 1.f;
restV = 50;
// minimizationPhase = 0;
};
virtual ~sketcherMinimizerInteraction() = default;
/* return energy associated with it */
virtual void energy(float& e)
{
sketcherMinimizerPointF l = atom1->coordinates - atom2->coordinates;
float dr = sqrt(l.x() * l.x() + l.y() * l.y()) - restV;
e += 0.5f * k * dr * dr;
};
/* calculate and apply forces */
virtual void score(float& totalE, bool = false)
{
sketcherMinimizerPointF l = atom1->coordinates - atom2->coordinates;
if (l.x() > 0 && l.x() < SKETCHER_EPSILON) {
l.setX(SKETCHER_EPSILON);
} else if (l.x() < 0 && l.x() > -SKETCHER_EPSILON) {
l.setX(-SKETCHER_EPSILON);
}
float delta = 0.05f;
float e1 = 0.f;
float e2 = 0.f;
float dx, dy;
atom1->coordinates.rx() += delta;
energy(e1);
atom1->coordinates.rx() -= 2 * delta;
energy(e2);
dx = (e2 - e1) / (2 * delta);
atom1->coordinates.rx() += delta;
dy = dx * l.y() / l.x();
totalE += (e2 + e1) * .5f;
sketcherMinimizerPointF dForce(dx, dy);
atom1->force += dForce;
atom2->force -= dForce;
};
virtual bool isClash() { return false; };
float k;
float restV; // rest value
sketcherMinimizerAtom* atom1;
sketcherMinimizerAtom* atom2;
// int minimizationPhase;
};
#endif // sketcherMINIMIZERINTERACTION