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 449463 : AtomValuePack::AtomValuePack( MultiValue& vals, MultiColvarBase const * mcolv ): 30 449463 : myvals(vals), 31 449463 : mycolv(mcolv), 32 449463 : natoms(0), 33 449463 : indices( vals.getIndices() ), 34 449463 : sort_vector( vals.getSortIndices() ), 35 449463 : myatoms( vals.getAtomVector() ) { 36 449463 : if( indices.size()!=mcolv->getNumberOfAtoms() ) { 37 23864 : indices.resize( mcolv->getNumberOfAtoms() ); 38 23864 : sort_vector.resize( mcolv->getNumberOfAtoms() ); 39 23864 : myatoms.resize( mcolv->getNumberOfAtoms() ); 40 : } 41 449463 : } 42 : 43 222049 : unsigned AtomValuePack::setupAtomsFromLinkCells( const std::vector<unsigned>& cind, const Vector& cpos, const LinkCells& linkcells ) { 44 222049 : if( cells_required.size()!=linkcells.getNumberOfCells() ) { 45 218659 : cells_required.resize( linkcells.getNumberOfCells() ); 46 : } 47 : // Build the list of cells that we need 48 222049 : unsigned ncells_required=0; 49 222049 : linkcells.addRequiredCells( linkcells.findMyCell( cpos ), ncells_required, cells_required ); 50 : // Now build the list of atoms we need 51 222049 : natoms=cind.size(); 52 483914 : for(unsigned i=0; i<natoms; ++i) { 53 261865 : indices[i]=cind[i]; 54 : } 55 222049 : linkcells.retrieveAtomsInCells( ncells_required, cells_required, natoms, indices ); 56 : // linkcells.retrieveNeighboringAtoms( cpos, natoms, indices ); 57 401982235 : for(unsigned i=0; i<natoms; ++i) { 58 401760186 : myatoms[i]=mycolv->getPositionOfAtomForLinkCells( indices[i] ) - cpos; 59 : } 60 222049 : if( mycolv->usesPbc() ) { 61 222049 : mycolv->applyPbc( myatoms, natoms ); 62 : } 63 222049 : return natoms; 64 : } 65 : 66 520523 : void AtomValuePack::updateUsingIndices() { 67 520523 : if( myvals.updateComplete() ) { 68 204368 : return; 69 : } 70 : 71 : unsigned jactive=0; 72 400639874 : for(unsigned i=0; i<natoms; ++i) { 73 400323719 : unsigned base=3*indices[i]; 74 400323719 : if( myvals.isActive( base ) ) { 75 4130161 : sort_vector[jactive]=indices[i]; 76 4130161 : jactive++; 77 : } 78 : } 79 316155 : std::sort( sort_vector.begin(), sort_vector.begin()+jactive ); 80 : 81 316155 : myvals.emptyActiveMembers(); 82 4446316 : for(unsigned i=0; i<jactive; ++i) { 83 4130161 : unsigned base=3*sort_vector[i]; // indices[i]; 84 4130161 : myvals.putIndexInActiveArray( base ); 85 4130161 : myvals.putIndexInActiveArray( base + 1 ); 86 4130161 : myvals.putIndexInActiveArray( base + 2 ); 87 : } 88 316155 : unsigned nvir=3*mycolv->getNumberOfAtoms(); 89 316155 : if( myvals.isActive( nvir ) ) { 90 2074510 : for(unsigned i=0; i<9; ++i) { 91 1867059 : myvals.putIndexInActiveArray( nvir + i ); 92 : } 93 : } 94 316155 : myvals.completeUpdate(); 95 : } 96 : 97 980606 : void AtomValuePack::addComDerivatives( const int& ind, const Vector& der, const CatomPack& catom_der ) { 98 980606 : if( ind<0 ) { 99 109936 : for(unsigned ider=0; ider<catom_der.getNumberOfAtomsWithDerivatives(); ++ider) { 100 57432 : unsigned jder=3*catom_der.getIndex(ider); 101 57432 : myvals.addTemporyDerivative( jder+0, catom_der.getDerivative(ider,0,der) ); 102 57432 : myvals.addTemporyDerivative( jder+1, catom_der.getDerivative(ider,1,der) ); 103 57432 : myvals.addTemporyDerivative( jder+2, catom_der.getDerivative(ider,2,der) ); 104 : } 105 : } else { 106 1861132 : for(unsigned ider=0; ider<catom_der.getNumberOfAtomsWithDerivatives(); ++ider) { 107 933030 : unsigned jder=3*catom_der.getIndex(ider); 108 933030 : myvals.addDerivative( ind, jder+0, catom_der.getDerivative(ider,0,der) ); 109 933030 : myvals.addDerivative( ind, jder+1, catom_der.getDerivative(ider,1,der) ); 110 933030 : myvals.addDerivative( ind, jder+2, catom_der.getDerivative(ider,2,der) ); 111 : } 112 : } 113 980606 : } 114 : 115 : } 116 : }