forked from schrodinger/coordgenlibs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketcherMinimizerEZConstrainInteraction.h
93 lines (86 loc) · 3.13 KB
/
sketcherMinimizerEZConstrainInteraction.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* sketcherMinimizerEZConstrainInteraction.h
*
* Created by Nicola Zonta
* Copyright Schrodinger, LLC. All rights reserved.
*
*/
#ifndef sketcherMINIMIZEREZCONSTRAININTERACTION
#define sketcherMINIMIZEREZCONSTRAININTERACTION
#include "sketcherMinimizerInteraction.h"
/* forcefield constrain to avoid EZ inversion */
class sketcherMinimizerEZConstrainInteraction
: public sketcherMinimizerInteraction
{
public:
sketcherMinimizerEZConstrainInteraction(sketcherMinimizerAtom* at1,
sketcherMinimizerAtom* at2,
sketcherMinimizerAtom* at3,
sketcherMinimizerAtom* at4,
bool isZ)
: sketcherMinimizerInteraction(at1, at2)
{
atom3 = at3;
atom4 = at4;
m_isZ = isZ;
m_forceMovement = false;
};
~sketcherMinimizerEZConstrainInteraction() override = default;
/* calculate the energy of the interaction */
void energy(float& e) override
{
if (inversion()) {
e += 5000;
}
};
/* calculate the forces and apply them */
void score(float& totalE, bool = false) override
{
if (!inversion()) {
return;
}
energy(totalE);
sketcherMinimizerPointF projection1 =
sketcherMinimizerMaths::projectPointOnLine(
atom1->coordinates, atom2->coordinates, atom3->coordinates);
sketcherMinimizerPointF projection2 =
sketcherMinimizerMaths::projectPointOnLine(
atom4->coordinates, atom2->coordinates, atom3->coordinates);
sketcherMinimizerAtom* sideAtom = atom1;
sketcherMinimizerAtom* doubleBondAtom = atom2;
sketcherMinimizerPointF projection = projection1;
if (sketcherMinimizerMaths::squaredDistance(atom1->coordinates,
projection1) >
sketcherMinimizerMaths::squaredDistance(atom4->coordinates,
projection2)) {
sideAtom = atom4;
doubleBondAtom = atom3;
projection = projection2;
}
sketcherMinimizerPointF force = projection - sideAtom->coordinates;
if (m_forceMovement) {
sideAtom->coordinates += force;
doubleBondAtom->coordinates -= force;
sideAtom->force = sketcherMinimizerPointF(0, 0);
doubleBondAtom->force = sketcherMinimizerPointF(0, 0);
} else {
force.normalize();
force *= 10;
sideAtom->force += force;
doubleBondAtom->force -= force;
}
};
/* check if the E/Z configuration is inverted */
bool inversion()
{
return sketcherMinimizerMaths::sameSide(
atom1->coordinates, atom4->coordinates, atom2->coordinates,
atom3->coordinates) != m_isZ;
}
sketcherMinimizerAtom* atom3;
sketcherMinimizerAtom* atom4;
float k2;
bool m_isZ;
bool m_forceMovement;
};
#endif // sketcherMINIMIZEREZCONSTRAININTERACTION