Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-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 "Colvar.h" 23 : #include "tools/OpenMP.h" 24 : #include <vector> 25 : #include <string> 26 : 27 : namespace PLMD { 28 : 29 2638 : Colvar::Colvar(const ActionOptions&ao): 30 : Action(ao), 31 : ActionAtomistic(ao), 32 2638 : ActionWithValue(ao) { 33 2638 : } 34 : 35 7654 : void Colvar::registerKeywords( Keywords& keys ) { 36 7654 : Action::registerKeywords( keys ); 37 7654 : ActionWithValue::registerKeywords( keys ); 38 7654 : ActionAtomistic::registerKeywords( keys ); 39 15308 : keys.addFlag("NOPBC",false,"ignore the periodic boundary conditions when calculating distances"); 40 7654 : } 41 : 42 3071 : void Colvar::requestAtoms(const std::vector<AtomNumber> & a) { 43 : // Tell actionAtomistic what atoms we are getting 44 3071 : ActionAtomistic::requestAtoms(a); 45 : // Resize the derivatives of all atoms 46 7647 : for(int i=0; i<getNumberOfComponents(); ++i) { 47 4577 : getPntrToComponent(i)->resizeDerivatives(3*a.size()+9); 48 : } 49 3070 : } 50 : 51 275981 : void Colvar::apply() { 52 275981 : if( !checkForForces() ) { 53 33615 : return ; 54 : } 55 242366 : unsigned ind=0; 56 242366 : if( getNumberOfAtoms()>0 ) { 57 242278 : setForcesOnAtoms( getForcesToApply(), ind ); 58 : } else { 59 88 : setForcesOnCell( getForcesToApply(), ind ); 60 : } 61 : } 62 : 63 584565 : void Colvar::setBoxDerivativesNoPbc( const std::vector<Vector>& pos, std::vector<std::vector<Vector> >& derivs, std::vector<Tensor>& virial ) { 64 584565 : unsigned nat=pos.size(); 65 1381500 : for(unsigned i=0; i<virial.size(); ++i) { 66 796935 : virial[i].zero(); 67 2584276 : for(unsigned j=0; j<nat; j++) { 68 1787341 : virial[i]-=Tensor(pos[j],derivs[i][j]); 69 : } 70 : } 71 584565 : } 72 : 73 112014 : void Colvar::setBoxDerivativesNoPbc(Value* v) { 74 112014 : Tensor virial; 75 : unsigned nat=getNumberOfAtoms(); 76 16529756 : for(unsigned i=0; i<nat; i++) 77 16417742 : virial-=Tensor(getPosition(i), 78 16417742 : Vector(v->getDerivative(3*i+0), 79 : v->getDerivative(3*i+1), 80 32835484 : v->getDerivative(3*i+2))); 81 112014 : setBoxDerivatives(v,virial); 82 112014 : } 83 : }