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_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 103 : 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 addDerivative( const unsigned&, const unsigned&, const double& );
56 : ///
57 : void addAtomsDerivatives( const unsigned&, const unsigned&, const Vector& );
58 : ///
59 : void addTemporyAtomsDerivatives( const unsigned& jder, const Vector& der );
60 : public:
61 : AtomValuePack( MultiValue& vals, MultiColvarBase const * mcolv );
62 : /// Set the number of atoms
63 : void setNumberOfAtoms( const unsigned& );
64 : /// Set the index for one of the atoms
65 : void setIndex( const unsigned&, const unsigned& );
66 : ///
67 : void setAtomIndex( const unsigned& j, const unsigned& ind );
68 : ///
69 : void setAtom( const unsigned& j, const unsigned& ind );
70 : ///
71 : unsigned setupAtomsFromLinkCells( const std::vector<unsigned>& cind, const Vector& cpos, const LinkCells& linkcells );
72 : ///
73 : unsigned getIndex( const unsigned& j ) const ;
74 : ///
75 : unsigned getNumberOfAtoms() const ;
76 : ///
77 : unsigned getNumberOfDerivatives() const ;
78 : /// Get the position of the ith atom
79 : Vector& getPosition( const unsigned& );
80 : /// Get the absolute index of the ith atom in the list
81 : AtomNumber getAbsoluteIndex( const unsigned& j ) const ;
82 : ///
83 : void setValue( const unsigned&, const double& );
84 : ///
85 : void addValue( const unsigned& ival, const double& vv );
86 : ///
87 : double getValue( const unsigned& ) const ;
88 : ///
89 : void addBoxDerivatives( const unsigned&, const Tensor& );
90 : ///
91 : void addTemporyBoxDerivatives( const Tensor& vir );
92 : ///
93 : void updateUsingIndices();
94 : ///
95 : void updateDynamicList();
96 : ///
97 : void addComDerivatives( const int&, const Vector&, CatomPack& );
98 : ///
99 : MultiValue& getUnderlyingMultiValue();
100 : };
101 :
102 : inline
103 : void AtomValuePack::setNumberOfAtoms( const unsigned& nat ) {
104 230697 : natoms=nat;
105 : }
106 :
107 : inline
108 : unsigned AtomValuePack::getNumberOfAtoms() const {
109 518709333 : 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 ); indices[j]=ind;
120 : }
121 :
122 : inline
123 : void AtomValuePack::setAtomIndex( const unsigned& j, const unsigned& ind ) {
124 1161254 : plumed_dbg_assert( j<natoms ); indices[j]=ind;
125 : }
126 :
127 : inline
128 546978 : void AtomValuePack::setAtom( const unsigned& j, const unsigned& ind ) {
129 1093956 : setAtomIndex( j, ind ); myatoms[j]=mycolv->getPositionOfAtomForLinkCells( ind );
130 546978 : }
131 :
132 : inline
133 : unsigned AtomValuePack::getIndex( const unsigned& j ) const {
134 1638271470 : plumed_dbg_assert( j<natoms ); return indices[j];
135 : }
136 :
137 : inline
138 117937031 : AtomNumber AtomValuePack::getAbsoluteIndex( const unsigned& j ) const {
139 235874062 : plumed_dbg_assert( j<natoms ); unsigned jatom=indices[j];
140 235874062 : if( mycolv->atom_lab[jatom].first>0 ) {
141 0 : unsigned mmc=mycolv->atom_lab[jatom].first - 1;
142 0 : return (mycolv->mybasemulticolvars[mmc])->getAbsoluteIndexOfCentralAtom( mycolv->atom_lab[jatom].second );
143 : }
144 117937031 : return mycolv->getAbsoluteIndex( mycolv->atom_lab[jatom].second );
145 : }
146 :
147 : inline
148 : Vector& AtomValuePack::getPosition( const unsigned& iatom ) {
149 : plumed_dbg_assert( iatom<natoms );
150 136461448 : return myatoms[iatom];
151 : }
152 :
153 : inline
154 : void AtomValuePack::setValue( const unsigned& ival, const double& vv ) {
155 723517 : myvals.setValue( ival, vv );
156 : }
157 :
158 : inline
159 : void AtomValuePack::addValue( const unsigned& ival, const double& vv ) {
160 58086401 : myvals.addValue( ival, vv );
161 : }
162 :
163 : inline
164 : double AtomValuePack::getValue( const unsigned& ival ) const {
165 3389847 : return myvals.get( ival );
166 : }
167 :
168 : inline
169 : void AtomValuePack::addDerivative( const unsigned& ival, const unsigned& jder, const double& der ) {
170 75860460 : myvals.addDerivative( ival, jder, der );
171 : }
172 :
173 : inline
174 105348203 : void AtomValuePack::addAtomsDerivatives( const unsigned& ival, const unsigned& jder, const Vector& der ) {
175 : plumed_dbg_assert( jder<natoms );
176 210696406 : myvals.addDerivative( ival, 3*indices[jder] + 0, der[0] );
177 210696406 : myvals.addDerivative( ival, 3*indices[jder] + 1, der[1] );
178 210696406 : myvals.addDerivative( ival, 3*indices[jder] + 2, der[2] );
179 105348203 : }
180 :
181 : inline
182 4515550 : void AtomValuePack::addTemporyAtomsDerivatives( const unsigned& jder, const Vector& der ) {
183 : plumed_dbg_assert( jder<natoms );
184 9031100 : myvals.addTemporyDerivative( 3*indices[jder] + 0, der[0] );
185 9031100 : myvals.addTemporyDerivative( 3*indices[jder] + 1, der[1] );
186 9031100 : myvals.addTemporyDerivative( 3*indices[jder] + 2, der[2] );
187 4515550 : }
188 :
189 : inline
190 2282641 : void AtomValuePack::addTemporyBoxDerivatives( const Tensor& vir ) {
191 4565282 : unsigned nvir=3*mycolv->getNumberOfAtoms();
192 29674333 : for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) myvals.addTemporyDerivative( nvir + 3*i+j, vir(i,j) );
193 2282641 : }
194 :
195 : inline
196 52910386 : void AtomValuePack::addBoxDerivatives( const unsigned& ival, const Tensor& vir ) {
197 105820772 : unsigned nvir=3*mycolv->getNumberOfAtoms();
198 211641544 : for(unsigned i=0; i<3; ++i) for(unsigned j=0; j<3; ++j) myvals.addDerivative( ival, nvir + 3*i+j, vir(i,j) );
199 52910386 : }
200 :
201 : inline
202 141710 : void AtomValuePack::updateDynamicList() {
203 283420 : if( myvals.updateComplete() ) return;
204 : myvals.updateDynamicList();
205 : }
206 :
207 : inline
208 : MultiValue& AtomValuePack::getUnderlyingMultiValue() {
209 4742070 : return myvals;
210 : }
211 :
212 : }
213 : }
214 : #endif
215 :
|