-
Notifications
You must be signed in to change notification settings - Fork 28
/
sketcherMinimizerFragment.h
288 lines (235 loc) · 8.42 KB
/
sketcherMinimizerFragment.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
*
*
* Created by Nicola Zonta on 03/05/2010.
* Copyright Schrodinger, LLC. All rights reserved.
*
*/
#ifndef sketcherMINIMIZERFRAGMENT
#define sketcherMINIMIZERFRAGMENT
#include "sketcherMinimizerMaths.h"
#include <cassert>
#include <iostream>
#include <map>
#include <vector>
#include "CoordgenConfig.hpp"
class sketcherMinimizerAtom;
class sketcherMinimizerBond;
class sketcherMinimizerRing;
class sketcherMinimizerFragment;
/*
abstract class for fragment degree of freedom
*/
class CoordgenFragmentDOF
{
public:
CoordgenFragmentDOF(sketcherMinimizerFragment* fragment);
virtual ~CoordgenFragmentDOF();
/* set the current value as the optimal value for this DOF */
void storeCurrentValueAsOptimal();
/* load the optimal value */
void setToOptimalValue();
/* cycle through the various possible values of this DOF */
void changeState();
/* add the given atom to the DoF */
void addAtom(sketcherMinimizerAtom* atom);
/* get the penalty associated with the current state */
virtual float getCurrentPenalty() const;
/* return the number of states */
virtual int numberOfStates() const = 0;
/* return the tier of this DoF. Lower tier DoFs are considered first in the
* minimization */
virtual int tier() const = 0;
/* apply the current DoF value to the atoms coordinates */
virtual void apply() const = 0;
/* return the fragment this DoF refers to */
sketcherMinimizerFragment* getFragment() const;
/* return the current state */
short unsigned int getCurrentState();
/* set the given state as current */
void setState(short unsigned int state);
short unsigned int m_currentState, m_optimalState;
protected:
std::vector<sketcherMinimizerAtom*> m_atoms;
sketcherMinimizerFragment* m_fragment;
};
/*
change the angle of the fragment wrt its parent
*/
class CoordgenRotateFragmentDOF : public CoordgenFragmentDOF
{
public:
CoordgenRotateFragmentDOF(sketcherMinimizerFragment* fragment);
int numberOfStates() const override;
int tier() const override;
void apply() const override;
float getCurrentPenalty() const override;
};
/*
flip the fragment along the bond to its parent
*/
class CoordgenFlipFragmentDOF : public CoordgenFragmentDOF
{
public:
CoordgenFlipFragmentDOF(sketcherMinimizerFragment* fragment);
int numberOfStates() const override;
int tier() const override;
void apply() const override;
float getCurrentPenalty() const override;
};
/*
scale the coordinates of the given atoms
*/
class CoordgenScaleAtomsDOF : public CoordgenFragmentDOF
{
public:
CoordgenScaleAtomsDOF(sketcherMinimizerAtom* pivotAtom);
int numberOfStates() const override;
int tier() const override;
void apply() const override;
float getCurrentPenalty() const override;
private:
sketcherMinimizerAtom* m_pivotAtom;
};
/*
scale the coordinates of the whole fragment
*/
class CoordgenScaleFragmentDOF : public CoordgenFragmentDOF
{
public:
CoordgenScaleFragmentDOF(sketcherMinimizerFragment* fragment);
int numberOfStates() const override;
int tier() const override;
void apply() const override;
float getCurrentPenalty() const override;
};
/*
extend or shorten the bond to the parent fragment
*/
class CoordgenChangeParentBondLengthFragmentDOF : public CoordgenFragmentDOF
{
public:
CoordgenChangeParentBondLengthFragmentDOF(
sketcherMinimizerFragment* fragment);
int numberOfStates() const override;
int tier() const override;
void apply() const override;
float getCurrentPenalty() const override;
};
/*
Invert the direction of a bond (e.g. a substituent to a macrocycle can be
placed towards the inside
of the ring)
*/
class CoordgenInvertBondDOF : public CoordgenFragmentDOF
{
public:
CoordgenInvertBondDOF(sketcherMinimizerAtom* pivotAtom,
sketcherMinimizerAtom* boundAtom);
int numberOfStates() const override;
int tier() const override;
void apply() const override;
float getCurrentPenalty() const override;
private:
sketcherMinimizerAtom* m_pivotAtom;
sketcherMinimizerAtom* m_boundAtom;
};
/* flip a ring fused with another with more than 2 bonds (e.g. ring in a
* macrocycle) */
class CoordgenFlipRingDOF : public CoordgenFragmentDOF
{
public:
CoordgenFlipRingDOF(sketcherMinimizerRing* ring,
const std::vector<sketcherMinimizerAtom*>& fusionAtoms);
int numberOfStates() const override;
int tier() const override;
void apply() const override;
float getCurrentPenalty() const override;
private:
sketcherMinimizerAtom* m_pivotAtom1;
sketcherMinimizerAtom* m_pivotAtom2;
int m_penalty;
};
/* class that represents a rigid molecular fragment */
class EXPORT_COORDGEN sketcherMinimizerFragment
{
public:
sketcherMinimizerFragment();
~sketcherMinimizerFragment();
/* return the total weight of the fragment */
unsigned int totalWeight() const;
/* return the number of double bonds in the fragment */
unsigned int countDoubleBonds() const;
/* return the number of heavy atoms in the fragment */
unsigned int countHeavyAtoms() const;
/* return the number of constrained atoms in the fragment */
unsigned int countConstrainedAtoms() const;
/* return the number of fixed atoms in the fragment */
unsigned int countFixedAtoms() const;
/* add an atom to this fragment */
void addAtom(sketcherMinimizerAtom* atom);
/* add a bond to this fragment */
void addBond(sketcherMinimizerBond* bond);
/* add a ring to this fragment */
void addRing(sketcherMinimizerRing* ring);
/* add a degree of freedom to this fragment */
void addDof(CoordgenFragmentDOF* dof);
/* get all degrees of freedom of this fragment */
const std::vector<CoordgenFragmentDOF*>& getDofs();
/* mark the given bond as interfragment */
void addInterFragmentBond(sketcherMinimizerBond* bond)
{
_interFragmentBonds.push_back(bond);
}
std::vector<sketcherMinimizerAtom*> getAtoms() const { return m_atoms; }
std::vector<sketcherMinimizerBond*> getBonds() const { return m_bonds; }
std::vector<sketcherMinimizerRing*> getRings() const { return m_rings; }
std::vector<sketcherMinimizerAtom*>& atoms() { return m_atoms; }
std::vector<sketcherMinimizerBond*>& bonds() { return m_bonds; }
std::vector<sketcherMinimizerRing*>& rings() { return m_rings; }
/* return the parent fragment */
sketcherMinimizerFragment* getParent() const { return m_parent; }
/* set the given fragment as parent */
void setParent(sketcherMinimizerFragment* parent) { m_parent = parent; }
/* add the given degree of freedom to the given atom which will be modified
* by it */
void addDofToAtom(sketcherMinimizerAtom* atom, CoordgenFragmentDOF* dof)
{
m_dofsForAtom[atom].push_back(dof);
}
/* return the degrees of freedom that would modify the given atom */
std::vector<CoordgenFragmentDOF*>&
getDofsOfAtom(sketcherMinimizerAtom* atom)
{
return m_dofsForAtom[atom];
}
/* set the coordinates of each atom to the template coordinates */
void setAllCoordinatesToTemplate();
/* save coordinates information */
void storeCoordinateInformation();
std::vector<sketcherMinimizerBond*> _interFragmentBonds;
std::vector<sketcherMinimizerFragment*> _children;
std::map<sketcherMinimizerAtom*, sketcherMinimizerPointF> _coordinates;
sketcherMinimizerPointF _bondToParentCoordinatesStart;
sketcherMinimizerPointF _bondToParentCoordinatesEnd;
bool fixed, isTemplated, constrained, constrainedFlip;
bool isChain;
sketcherMinimizerBond* _bondToParent;
float longestChainFromHere;
size_t numberOfChildrenAtoms;
float numberOfChildrenAtomsRank;
/* translate and rotate the fragment and set the resulting coordinates to
* every atom */
void setCoordinates(const sketcherMinimizerPointF& position, float angle);
/* get the dof that refers to flipping this fragment */
CoordgenFragmentDOF* getFlipDof() const { return m_dofs[0]; }
private:
sketcherMinimizerFragment* m_parent;
std::vector<sketcherMinimizerAtom*> m_atoms;
std::vector<sketcherMinimizerBond*> m_bonds;
std::vector<sketcherMinimizerRing*> m_rings;
std::vector<CoordgenFragmentDOF*> m_dofs;
std::map<sketcherMinimizerAtom*, std::vector<CoordgenFragmentDOF*>>
m_dofsForAtom;
};
#endif // sketcherMINIMIZERFRAGMENT