Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2014-2023 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_multicolvar_AtomValuePack_h
23 : #define __PLUMED_multicolvar_AtomValuePack_h
24 :
25 : #include "tools/MultiValue.h"
26 : #include "MultiColvarBase.h"
27 :
28 : namespace PLMD {
29 :
30 : class LinkCells;
31 :
32 : namespace multicolvar {
33 :
34 : class CatomPack;
35 :
36 449409 : class AtomValuePack {
37 : friend class MultiColvarBase;
38 : friend class LocalAverage;
39 : private:
40 : /// Copy of the values that we are adding to
41 : MultiValue& myvals;
42 : /// Copy of the underlying multicolvar
43 : MultiColvarBase const * mycolv;
44 : /// Number of atoms at the moment
45 : unsigned natoms;
46 : /// Atom indices
47 : std::vector<unsigned>& indices;
48 : /// This is used to sort the atom indices
49 : std::vector<unsigned>& sort_vector;
50 : /// This holds atom positions
51 : std::vector<Vector>& myatoms;
52 : /// This is stuff for link cells
53 : std::vector<unsigned> cells_required;
54 : ///
55 : void addAtomsDerivatives( const unsigned&, const unsigned&, const Vector& );
56 : ///
57 : void addTemporyAtomsDerivatives( const unsigned& jder, const Vector& der );
58 : public:
59 : AtomValuePack( MultiValue& vals, MultiColvarBase const * mcolv );
60 : /// Set the number of atoms
61 : void setNumberOfAtoms( const unsigned& );
62 : /// Set the index for one of the atoms
63 : void setIndex( const unsigned&, const unsigned& );
64 : ///
65 : void setAtomIndex( const unsigned& j, const unsigned& ind );
66 : ///
67 : void setAtom( const unsigned& j, const unsigned& ind );
68 : ///
69 : unsigned setupAtomsFromLinkCells( const std::vector<unsigned>& cind, const Vector& cpos, const LinkCells& linkcells );
70 : ///
71 : unsigned getIndex( const unsigned& j ) const ;
72 : ///
73 : unsigned getNumberOfAtoms() const ;
74 : ///
75 : unsigned getNumberOfDerivatives() const ;
76 : /// Get the position of the ith atom
77 : Vector& getPosition( const unsigned& );
78 : /// Get the absolute index of the ith atom in the list
79 : AtomNumber getAbsoluteIndex( const unsigned& j ) const ;
80 : ///
81 : void setValue( const unsigned&, const double& );
82 : ///
83 : void addValue( const unsigned& ival, const double& vv );
84 : ///
85 : double getValue( const unsigned& ) const ;
86 : ///
87 : void addBoxDerivatives( const unsigned&, const Tensor& );
88 : ///
89 : void addTemporyBoxDerivatives( const Tensor& vir );
90 : ///
91 : void updateUsingIndices();
92 : ///
93 : void updateDynamicList();
94 : ///
95 : void addComDerivatives( const int&, const Vector&, const CatomPack& );
96 : ///
97 : MultiValue& getUnderlyingMultiValue();
98 : ///
99 : void addDerivative( const unsigned&, const unsigned&, const double& );
100 : };
101 :
102 : inline
103 : void AtomValuePack::setNumberOfAtoms( const unsigned& nat ) {
104 230894 : natoms=nat;
105 : }
106 :
107 : inline
108 : unsigned AtomValuePack::getNumberOfAtoms() const {
109 522586204 : return natoms;
110 : }
111 :
112 : inline
113 : unsigned AtomValuePack::getNumberOfDerivatives() const {
114 110 : return myvals.getNumberOfDerivatives();
115 : }
116 :
117 : inline
118 : void AtomValuePack::setIndex( const unsigned& j, const unsigned& ind ) {
119 : plumed_dbg_assert( j<natoms );
120 : indices[j]=ind;
121 : }
122 :
123 : inline
124 : void AtomValuePack::setAtomIndex( const unsigned& j, const unsigned& ind ) {
125 : plumed_dbg_assert( j<natoms );
126 605398 : indices[j]=ind;
127 : }
128 :
129 : inline
130 571749 : void AtomValuePack::setAtom( const unsigned& j, const unsigned& ind ) {
131 : setAtomIndex( j, ind );
132 571749 : myatoms[j]=mycolv->getPositionOfAtomForLinkCells( ind );
133 571749 : }
134 :
135 : inline
136 : unsigned AtomValuePack::getIndex( const unsigned& j ) const {
137 : plumed_dbg_assert( j<natoms );
138 680755930 : return indices[j];
139 : }
140 :
141 : inline
142 117937031 : AtomNumber AtomValuePack::getAbsoluteIndex( const unsigned& j ) const {
143 : plumed_dbg_assert( j<natoms );
144 117937031 : unsigned jatom=indices[j];
145 117937031 : if( mycolv->atom_lab[jatom].first>0 ) {
146 0 : unsigned mmc=mycolv->atom_lab[jatom].first - 1;
147 0 : return (mycolv->mybasemulticolvars[mmc])->getAbsoluteIndexOfCentralAtom( mycolv->atom_lab[jatom].second );
148 : }
149 117937031 : return mycolv->getAbsoluteIndex( mycolv->atom_lab[jatom].second );
150 : }
151 :
152 : inline
153 : Vector& AtomValuePack::getPosition( const unsigned& iatom ) {
154 : plumed_dbg_assert( iatom<natoms );
155 139700760 : return myatoms[iatom];
156 : }
157 :
158 : inline
159 : void AtomValuePack::setValue( const unsigned& ival, const double& vv ) {
160 698503 : myvals.setValue( ival, vv );
161 : }
162 :
163 : inline
164 : void AtomValuePack::addValue( const unsigned& ival, const double& vv ) {
165 63014961 : myvals.addValue( ival, vv );
166 : }
167 :
168 : inline
169 : double AtomValuePack::getValue( const unsigned& ival ) const {
170 3464306 : return myvals.get( ival );
171 : }
172 :
173 : inline
174 : void AtomValuePack::addDerivative( const unsigned& ival, const unsigned& jder, const double& der ) {
175 40573338 : myvals.addDerivative( ival, jder, der );
176 : }
177 :
178 : inline
179 113229875 : void AtomValuePack::addAtomsDerivatives( const unsigned& ival, const unsigned& jder, const Vector& der ) {
180 : plumed_dbg_assert( jder<natoms );
181 113229875 : myvals.addDerivative( ival, 3*indices[jder] + 0, der[0] );
182 113229875 : myvals.addDerivative( ival, 3*indices[jder] + 1, der[1] );
183 113229875 : myvals.addDerivative( ival, 3*indices[jder] + 2, der[2] );
184 113229875 : }
185 :
186 : inline
187 4575750 : void AtomValuePack::addTemporyAtomsDerivatives( const unsigned& jder, const Vector& der ) {
188 : plumed_dbg_assert( jder<natoms );
189 4575750 : myvals.addTemporyDerivative( 3*indices[jder] + 0, der[0] );
190 4575750 : myvals.addTemporyDerivative( 3*indices[jder] + 1, der[1] );
191 4575750 : myvals.addTemporyDerivative( 3*indices[jder] + 2, der[2] );
192 4575750 : }
193 :
194 : inline
195 2314127 : void AtomValuePack::addTemporyBoxDerivatives( const Tensor& vir ) {
196 2314127 : unsigned nvir=3*mycolv->getNumberOfAtoms();
197 9256508 : for(unsigned i=0; i<3; ++i)
198 27769524 : for(unsigned j=0; j<3; ++j) {
199 20827143 : myvals.addTemporyDerivative( nvir + 3*i+j, vir(i,j) );
200 : }
201 2314127 : }
202 :
203 : inline
204 57137170 : void AtomValuePack::addBoxDerivatives( const unsigned& ival, const Tensor& vir ) {
205 57137170 : unsigned nvir=3*mycolv->getNumberOfAtoms();
206 228548680 : for(unsigned i=0; i<3; ++i)
207 685646040 : for(unsigned j=0; j<3; ++j) {
208 514234530 : myvals.addDerivative( ival, nvir + 3*i+j, vir(i,j) );
209 : }
210 57137170 : }
211 :
212 : inline
213 141871 : void AtomValuePack::updateDynamicList() {
214 141871 : if( myvals.updateComplete() ) {
215 : return;
216 : }
217 : myvals.updateDynamicList();
218 : }
219 :
220 : inline
221 : MultiValue& AtomValuePack::getUnderlyingMultiValue() {
222 4809736 : return myvals;
223 : }
224 :
225 : }
226 : }
227 : #endif
228 :
|