LCOV - code coverage report
Current view: top level - core - Colvar.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 36 36 100.0 %
Date: 2025-03-25 09:33:27 Functions: 6 7 85.7 %

          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        2188 : Colvar::Colvar(const ActionOptions&ao):
      30             :   Action(ao),
      31             :   ActionAtomistic(ao),
      32        2188 :   ActionWithValue(ao) {
      33        2188 : }
      34             : 
      35        6379 : void Colvar::registerKeywords( Keywords& keys ) {
      36        6379 :   Action::registerKeywords( keys );
      37        6379 :   ActionWithValue::registerKeywords( keys );
      38        6379 :   ActionAtomistic::registerKeywords( keys );
      39        6379 :   keys.addFlag("NOPBC",false,"ignore the periodic boundary conditions when calculating distances");
      40        6379 : }
      41             : 
      42        2621 : void Colvar::requestAtoms(const std::vector<AtomNumber> & a) {
      43             : // Tell actionAtomistic what atoms we are getting
      44        2621 :   ActionAtomistic::requestAtoms(a);
      45             : // Resize the derivatives of all atoms
      46        6743 :   for(int i=0; i<getNumberOfComponents(); ++i) {
      47        4123 :     getPntrToComponent(i)->resizeDerivatives(3*a.size()+9);
      48             :   }
      49        2620 : }
      50             : 
      51      145629 : void Colvar::apply() {
      52      145629 :   if( !checkForForces() ) {
      53       33545 :     return ;
      54             :   }
      55      112084 :   unsigned ind=0;
      56      112084 :   if( getNumberOfAtoms()>0 ) {
      57      111996 :     setForcesOnAtoms( getForcesToApply(), ind );
      58             :   } else {
      59          88 :     setForcesOnCell( getForcesToApply(), ind );
      60             :   }
      61             : }
      62             : 
      63      454275 : void Colvar::setBoxDerivativesNoPbc( const std::vector<Vector>& pos, std::vector<std::vector<Vector> >& derivs, std::vector<Tensor>& virial ) {
      64      454275 :   unsigned nat=pos.size();
      65     1120920 :   for(unsigned i=0; i<virial.size(); ++i) {
      66      666645 :     virial[i].zero();
      67     2190746 :     for(unsigned j=0; j<nat; j++) {
      68     1524101 :       virial[i]-=Tensor(pos[j],derivs[i][j]);
      69             :     }
      70             :   }
      71      454275 : }
      72             : 
      73      112016 : void Colvar::setBoxDerivativesNoPbc(Value* v) {
      74      112016 :   Tensor virial;
      75             :   unsigned nat=getNumberOfAtoms();
      76    16530004 :   for(unsigned i=0; i<nat; i++)
      77    16417988 :     virial-=Tensor(getPosition(i),
      78    16417988 :                    Vector(v->getDerivative(3*i+0),
      79             :                           v->getDerivative(3*i+1),
      80    32835976 :                           v->getDerivative(3*i+2)));
      81      112016 :   setBoxDerivatives(v,virial);
      82      112016 : }
      83             : }

Generated by: LCOV version 1.16