ReferenceCCMAAlgorithm.h 7.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

/* Portions copyright (c) 2006-2009 Stanford University and Simbios.
 * Contributors: Pande Group
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject
 * to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

25
26
#ifndef __ReferenceCCMAAlgorithm_H__
#define __ReferenceCCMAAlgorithm_H__
27
28

#include "ReferenceConstraintAlgorithm.h"
29
#include <utility>
30
31
32
33
34
#include <vector>
#include <set>

// ---------------------------------------------------------------------------------------

35
class OPENMM_EXPORT ReferenceCCMAAlgorithm : public ReferenceConstraintAlgorithm {
36
37
38
39
40
41
42

   protected:

      int _maximumNumberOfIterations;
      RealOpenMM _tolerance;

      int _numberOfConstraints;
43
44
      std::vector<std::pair<int, int> > _atomIndices;
      std::vector<RealOpenMM> _distance;
45

46
      std::vector<OpenMM::RealVec> _r_ij;
47
48
49
50
      RealOpenMM* _d_ij2;
      RealOpenMM* _distanceTolerance;
      RealOpenMM* _reducedMasses;
      bool _hasInitializedMasses;
51
      std::vector<std::vector<std::pair<int, RealOpenMM> > > _matrix;
52

53
54
55
56
57
   private:

      int applyConstraints(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates,
                       std::vector<OpenMM::RealVec>& atomCoordinatesP, std::vector<RealOpenMM>& inverseMasses, bool constrainingVelocities);
          
58
   public:
59
      class AngleInfo;
60
61
62

      /**---------------------------------------------------------------------------------------

63
         ReferenceCCMAAlgorithm constructor
64
65
66
67
68

         @param numberOfAtoms    number of atoms
         @param numberOfConstraints      number of constraints
         @param atomIndices              atom indices for contraints
         @param distance                 distances for constraints
69
70
         @param masses                   atom masses
         @param angles                   angle force field terms
71
72
73
74
         @param tolerance                constraint tolerance

         --------------------------------------------------------------------------------------- */

75
      ReferenceCCMAAlgorithm( int numberOfAtoms, int numberOfConstraints, const std::vector<std::pair<int, int> >& atomIndices, const std::vector<RealOpenMM>& distance, std::vector<RealOpenMM>& masses, std::vector<AngleInfo>& angles, RealOpenMM tolerance );
76
77
78
79
80
81
82

      /**---------------------------------------------------------------------------------------

         Destructor

         --------------------------------------------------------------------------------------- */

83
       ~ReferenceCCMAAlgorithm( );
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

      /**---------------------------------------------------------------------------------------

         Get number of constraints

         @return number of constraints

         --------------------------------------------------------------------------------------- */

      int getNumberOfConstraints( void ) const;

      /**---------------------------------------------------------------------------------------

         Get maximum number of iterations

         @return maximum number of iterations

         --------------------------------------------------------------------------------------- */

      int getMaximumNumberOfIterations( void ) const;

      /**---------------------------------------------------------------------------------------

         Set maximum number of iterations

         @param maximumNumberOfIterations   new maximum number of iterations

         --------------------------------------------------------------------------------------- */

113
      void setMaximumNumberOfIterations( int maximumNumberOfIterations );
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

      /**---------------------------------------------------------------------------------------

         Get tolerance

         @return tolerance

         --------------------------------------------------------------------------------------- */

      RealOpenMM getTolerance( void ) const;

      /**---------------------------------------------------------------------------------------

         Set tolerance

         @param tolerance new tolerance

         --------------------------------------------------------------------------------------- */

133
      void setTolerance( RealOpenMM tolerance );
134
135
136

      /**---------------------------------------------------------------------------------------

137
         Apply CCMA algorithm
138
139
140
141
142
143

         @param numberOfAtoms    number of atoms
         @param atomCoordinates  atom coordinates
         @param atomCoordinatesP atom coordinates prime
         @param inverseMasses    1/mass

144
145
         @return SimTKOpenMMCommon::DefaultReturn if converge; else
          return SimTKOpenMMCommon::ErrorReturn
146
147
148

         --------------------------------------------------------------------------------------- */

149
150
      int apply( int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates,
                       std::vector<OpenMM::RealVec>& atomCoordinatesP, std::vector<RealOpenMM>& inverseMasses );
151

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
      /**---------------------------------------------------------------------------------------

         Apply constraint algorithm to velocities.

         @param numberOfAtoms    number of atoms
         @param atomCoordinates  atom coordinates
         @param velocities       atom velocities
         @param inverseMasses    1/mass

         @return SimTKOpenMMCommon::DefaultReturn if converge; else
          return SimTKOpenMMCommon::ErrorReturn

         --------------------------------------------------------------------------------------- */

      int applyToVelocities(int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates,
                     std::vector<OpenMM::RealVec>& velocities, std::vector<RealOpenMM>& inverseMasses);

169
170
171
172
173
174
175
176
177
178
179
180
      /**---------------------------------------------------------------------------------------

         Report any violated constraints

         @param numberOfAtoms    number of atoms
         @param atomCoordinates  atom coordinates
         @param message          report

         @return number of violated constraints

         --------------------------------------------------------------------------------------- */

181
      int reportCCMA( int numberOfAtoms, std::vector<OpenMM::RealVec>& atomCoordinates, std::stringstream& message );
182
183
};

184
class ReferenceCCMAAlgorithm::AngleInfo
185
186
187
188
189
190
191
192
193
194
{
public:
    int atom1, atom2, atom3;
    RealOpenMM angle;
    AngleInfo(int atom1, int atom2, int atom3, RealOpenMM angle) :
        atom1(atom1), atom2(atom2), atom3(atom3), angle(angle)
    {
    }
};

195
196
// ---------------------------------------------------------------------------------------

197
#endif // __ReferenceCCMAAlgorithm_H__