Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2014-2019 The plumed team
3 : (see the PEOPLE file at the root of the distribution for a list of names)
4 :
5 : See http://www.plumed.org for more information.
6 :
7 : This file is part of plumed, version 2.
8 :
9 : plumed is free software: you can redistribute it and/or modify
10 : it under the terms of the GNU Lesser General Public License as published by
11 : the Free Software Foundation, either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : plumed is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU Lesser General Public License for more details.
18 :
19 : You should have received a copy of the GNU Lesser General Public License
20 : along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 : #ifndef __PLUMED_reference_ReferenceValuePack_h
23 : #define __PLUMED_reference_ReferenceValuePack_h
24 :
25 : #include "tools/MultiValue.h"
26 :
27 : namespace PLMD {
28 :
29 443170 : class ReferenceValuePack {
30 : friend class MultiDomainRMSD;
31 : friend class OptimalRMSD;
32 : private:
33 : /// Was the virial set
34 : bool boxWasSet;
35 : ///
36 : unsigned numberOfArgs;
37 : ///
38 : bool oind_set;
39 : unsigned oind;
40 : /// Copy of the values that we are adding to
41 : MultiValue& myvals;
42 : /// Ths list of atom indices
43 : std::vector<unsigned>& atom_indices;
44 : /// Are we using pca
45 : bool pca;
46 : /// A vector of vectors to save us some overhead for vector resizes
47 : std::vector<Vector> centeredpos;
48 : ///
49 : std::vector<Vector> displacement;
50 : ///
51 : std::vector<Tensor> rot;
52 : ///
53 : Matrix< std::vector<Vector> > DRotDPos;
54 : public:
55 : ReferenceValuePack( const unsigned& nargs, const unsigned& natoms, MultiValue& vals );
56 : ///
57 : void resize( const unsigned& nargs, const unsigned& natoms );
58 : ///
59 : void clear();
60 : ///
61 : unsigned getNumberOfDerivatives() const ;
62 : ///
63 : unsigned getNumberOfArguments() const ;
64 : ///
65 : unsigned getNumberOfAtoms() const ;
66 : ///
67 : void setAtomIndex( const unsigned& iatom, const unsigned& jindex );
68 : ///
69 : unsigned getAtomIndex( const unsigned& iatom ) const ;
70 : ///
71 : void copyScaledDerivatives( const unsigned& from, const double& scalef, const MultiValue& tvals );
72 : ///
73 : void addArgumentDerivatives( const unsigned& iarg, const double& der );
74 : ///
75 : void setArgumentDerivatives( const unsigned& iarg, const double& der );
76 : ///
77 : void setAtomDerivatives( const unsigned& jder, const Vector& der );
78 : ///
79 : void addAtomDerivatives( const unsigned& iatom, const Vector& der );
80 : ///
81 : void addBoxDerivatives( const Tensor& vir );
82 : ///
83 : bool updateComplete() const ;
84 : ///
85 : void updateDynamicLists();
86 : ///
87 : void scaleAllDerivatives( const double& scalef );
88 : ///
89 : void setValIndex( const unsigned& ind );
90 : ///
91 : void moveDerivatives( const unsigned& from, const unsigned& to );
92 : ///
93 : bool virialWasSet() const ;
94 : ///
95 : Vector getAtomDerivative( const unsigned& iatom ) const ;
96 : ///
97 : double getArgumentDerivative( const unsigned& ival ) const ;
98 : ///
99 : Tensor getBoxDerivatives() const ;
100 : ///
101 : bool calcUsingPCAOption() const ;
102 : ///
103 : void switchOnPCAOption();
104 : ///
105 : std::vector<Vector>& getAtomVector();
106 : ///
107 : std::vector<Vector>& getAtomsDisplacementVector();
108 : };
109 :
110 : inline
111 : unsigned ReferenceValuePack::getNumberOfDerivatives() const {
112 44 : return myvals.getNumberOfDerivatives();
113 : }
114 :
115 : inline
116 : unsigned ReferenceValuePack::getNumberOfArguments() const {
117 172372 : return numberOfArgs;
118 : }
119 :
120 : inline
121 : unsigned ReferenceValuePack::getNumberOfAtoms() const {
122 4197320 : return atom_indices.size();
123 : }
124 :
125 : inline
126 : void ReferenceValuePack::setAtomIndex( const unsigned& iatom, const unsigned& jindex ) {
127 5933736 : plumed_dbg_assert( iatom<atom_indices.size() ); atom_indices[iatom]=jindex;
128 : }
129 :
130 : inline
131 : unsigned ReferenceValuePack::getAtomIndex( const unsigned& iatom ) const {
132 : plumed_dbg_assert( iatom<atom_indices.size() );
133 3577392 : return atom_indices[iatom];
134 : }
135 :
136 : inline
137 : void ReferenceValuePack::addArgumentDerivatives( const unsigned& iarg, const double& der ) {
138 : plumed_dbg_assert( iarg<numberOfArgs && oind_set ); myvals.addDerivative( oind, iarg, der );
139 : }
140 :
141 : inline
142 100468 : void ReferenceValuePack::setArgumentDerivatives( const unsigned& iarg, const double& der ) {
143 100468 : plumed_dbg_assert( iarg<numberOfArgs && oind_set ); myvals.setDerivative( oind, iarg, der );
144 100468 : }
145 :
146 : inline
147 : bool ReferenceValuePack::updateComplete() const {
148 269322 : return myvals.updateComplete();
149 : }
150 :
151 : inline
152 17546199 : void ReferenceValuePack::setAtomDerivatives( const unsigned& jder, const Vector& der ) {
153 : plumed_dbg_assert( oind_set && jder<atom_indices.size() );
154 35092398 : myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 0, der[0] );
155 35092398 : myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 1, der[1] );
156 35092398 : myvals.setDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 2, der[2] );
157 : }
158 :
159 : inline
160 16356460 : void ReferenceValuePack::addAtomDerivatives( const unsigned& jder, const Vector& der ) {
161 : plumed_dbg_assert( oind_set && jder<atom_indices.size() );
162 32712920 : myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 0, der[0] );
163 32712920 : myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 1, der[1] );
164 32712920 : myvals.addDerivative( oind, numberOfArgs + 3*atom_indices[jder] + 2, der[2] );
165 16356460 : }
166 :
167 : inline
168 8268786 : void ReferenceValuePack::addBoxDerivatives( const Tensor& vir ) {
169 : plumed_dbg_assert( oind_set && atom_indices.size()>0 );
170 16537572 : boxWasSet=true; unsigned nbase = myvals.getNumberOfDerivatives() - 9;
171 33075144 : for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) myvals.addDerivative( oind, nbase + 3*i + j, vir(i,j) );
172 8268786 : }
173 :
174 : inline
175 : void ReferenceValuePack::setValIndex( const unsigned& ind ) {
176 255233 : oind=ind; oind_set=true;
177 : }
178 :
179 : inline
180 : bool ReferenceValuePack::virialWasSet() const {
181 176799 : return boxWasSet;
182 : }
183 :
184 : inline
185 17174225 : Vector ReferenceValuePack::getAtomDerivative( const unsigned& iatom ) const {
186 17174225 : Vector tmp; plumed_dbg_assert( oind_set && iatom<atom_indices.size() );
187 51522675 : tmp[0]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 0 );
188 51522675 : tmp[1]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 1 );
189 51522675 : tmp[2]=myvals.getDerivative( oind, numberOfArgs + 3*atom_indices[iatom] + 2 );
190 17174225 : return tmp;
191 : }
192 :
193 : inline
194 : double ReferenceValuePack::getArgumentDerivative( const unsigned& ival ) const {
195 : plumed_dbg_assert( oind_set && ival<numberOfArgs );
196 9542 : return myvals.getDerivative( oind, ival );
197 : }
198 :
199 : inline
200 600 : Tensor ReferenceValuePack::getBoxDerivatives() const {
201 1200 : plumed_dbg_assert( oind_set && boxWasSet ); Tensor tvir; unsigned nbase = myvals.getNumberOfDerivatives() - 9;
202 7800 : for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) tvir(i,j)=myvals.getDerivative( oind, nbase + 3*i + j );
203 600 : return tvir;
204 : }
205 :
206 : inline
207 : bool ReferenceValuePack::calcUsingPCAOption() const {
208 219076 : return pca;
209 : }
210 :
211 : inline
212 : void ReferenceValuePack::switchOnPCAOption() {
213 150 : pca=true;
214 : }
215 :
216 : inline
217 : std::vector<Vector>& ReferenceValuePack::getAtomVector() {
218 17764968 : return myvals.getAtomVector();
219 : }
220 :
221 : inline
222 : std::vector<Vector>& ReferenceValuePack::getAtomsDisplacementVector() {
223 3036 : return displacement;
224 : }
225 :
226 : }
227 :
228 : #endif
|