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 : #include "AtomValuePack.h" 23 : #include "CatomPack.h" 24 : #include "tools/LinkCells.h" 25 : 26 : namespace PLMD { 27 : namespace multicolvar { 28 : 29 447981 : AtomValuePack::AtomValuePack( MultiValue& vals, MultiColvarBase const * mcolv ): 30 447981 : myvals(vals), 31 447981 : mycolv(mcolv), 32 447981 : natoms(0), 33 447981 : indices( vals.getIndices() ), 34 447981 : sort_vector( vals.getSortIndices() ), 35 447981 : myatoms( vals.getAtomVector() ) 36 : { 37 447981 : if( indices.size()!=mcolv->getNumberOfAtoms() ) { 38 23855 : indices.resize( mcolv->getNumberOfAtoms() ); 39 23855 : sort_vector.resize( mcolv->getNumberOfAtoms() ); 40 23855 : myatoms.resize( mcolv->getNumberOfAtoms() ); 41 : } 42 447981 : } 43 : 44 220567 : unsigned AtomValuePack::setupAtomsFromLinkCells( const std::vector<unsigned>& cind, const Vector& cpos, const LinkCells& linkcells ) { 45 220567 : if( cells_required.size()!=linkcells.getNumberOfCells() ) cells_required.resize( linkcells.getNumberOfCells() ); 46 : // Build the list of cells that we need 47 220567 : unsigned ncells_required=0; linkcells.addRequiredCells( linkcells.findMyCell( cpos ), ncells_required, cells_required ); 48 : // Now build the list of atoms we need 49 480950 : natoms=cind.size(); for(unsigned i=0; i<natoms; ++i) indices[i]=cind[i]; 50 220567 : linkcells.retrieveAtomsInCells( ncells_required, cells_required, natoms, indices ); 51 : // linkcells.retrieveNeighboringAtoms( cpos, natoms, indices ); 52 404317627 : for(unsigned i=0; i<natoms; ++i) myatoms[i]=mycolv->getPositionOfAtomForLinkCells( indices[i] ) - cpos; 53 220567 : if( mycolv->usesPbc() ) mycolv->applyPbc( myatoms, natoms ); 54 220567 : return natoms; 55 : } 56 : 57 516269 : void AtomValuePack::updateUsingIndices() { 58 516269 : if( myvals.updateComplete() ) return; 59 : 60 : unsigned jactive=0; 61 402779418 : for(unsigned i=0; i<natoms; ++i) { 62 402464745 : unsigned base=3*indices[i]; 63 402464745 : if( myvals.isActive( base ) ) { sort_vector[jactive]=indices[i]; jactive++; } 64 : } 65 314673 : std::sort( sort_vector.begin(), sort_vector.begin()+jactive ); 66 : 67 314673 : myvals.emptyActiveMembers(); 68 4413720 : for(unsigned i=0; i<jactive; ++i) { 69 4099047 : unsigned base=3*sort_vector[i]; // indices[i]; 70 4099047 : myvals.putIndexInActiveArray( base ); 71 4099047 : myvals.putIndexInActiveArray( base + 1 ); 72 4099047 : myvals.putIndexInActiveArray( base + 2 ); 73 : } 74 314673 : unsigned nvir=3*mycolv->getNumberOfAtoms(); 75 314673 : if( myvals.isActive( nvir ) ) { 76 2060650 : for(unsigned i=0; i<9; ++i) myvals.putIndexInActiveArray( nvir + i ); 77 : } 78 314673 : myvals.completeUpdate(); 79 : } 80 : 81 905762 : void AtomValuePack::addComDerivatives( const int& ind, const Vector& der, const CatomPack& catom_der ) { 82 905762 : if( ind<0 ) { 83 104392 : for(unsigned ider=0; ider<catom_der.getNumberOfAtomsWithDerivatives(); ++ider) { 84 54660 : unsigned jder=3*catom_der.getIndex(ider); 85 54660 : myvals.addTemporyDerivative( jder+0, catom_der.getDerivative(ider,0,der) ); 86 54660 : myvals.addTemporyDerivative( jder+1, catom_der.getDerivative(ider,1,der) ); 87 54660 : myvals.addTemporyDerivative( jder+2, catom_der.getDerivative(ider,2,der) ); 88 : } 89 : } else { 90 1716988 : for(unsigned ider=0; ider<catom_der.getNumberOfAtomsWithDerivatives(); ++ider) { 91 860958 : unsigned jder=3*catom_der.getIndex(ider); 92 860958 : myvals.addDerivative( ind, jder+0, catom_der.getDerivative(ider,0,der) ); 93 860958 : myvals.addDerivative( ind, jder+1, catom_der.getDerivative(ider,1,der) ); 94 860958 : myvals.addDerivative( ind, jder+2, catom_der.getDerivative(ider,2,der) ); 95 : } 96 : } 97 905762 : } 98 : 99 : } 100 : }