LCOV - code coverage report
Current view: top level - colvar - Template.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 8 35 22.9 %
Date: 2024-10-18 14:00:25 Functions: 1 4 25.0 %

          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 "core/ActionRegister.h"
      24             : 
      25             : namespace PLMD {
      26             : namespace colvar {
      27             : 
      28             : //+PLUMEDOC COLVAR TEMPLATE
      29             : /*
      30             : This file provides a template for if you want to introduce a new CV.
      31             : 
      32             : <!-----You should add a description of your CV here---->
      33             : 
      34             : \par Examples
      35             : 
      36             : <!---You should put an example of how to use your CV here--->
      37             : 
      38             : \plumedfile
      39             : # This should be a sample input.
      40             : t: TEMPLATE ATOMS=1,2
      41             : PRINT ARG=t STRIDE=100 FILE=COLVAR
      42             : \endplumedfile
      43             : <!---You should reference here the other actions used in this example--->
      44             : (see also \ref PRINT)
      45             : 
      46             : */
      47             : //+ENDPLUMEDOC
      48             : 
      49             : class Template : public Colvar {
      50             :   bool pbc;
      51             : 
      52             : public:
      53             :   explicit Template(const ActionOptions&);
      54             : // active methods:
      55             :   void calculate() override;
      56             :   static void registerKeywords(Keywords& keys);
      57             : };
      58             : 
      59             : PLUMED_REGISTER_ACTION(Template,"TEMPLATE")
      60             : 
      61           2 : void Template::registerKeywords(Keywords& keys) {
      62           2 :   Colvar::registerKeywords(keys);
      63           4 :   keys.addFlag("TEMPLATE_DEFAULT_OFF_FLAG",false,"flags that are by default not performed should be specified like this");
      64           4 :   keys.add("compulsory","TEMPLATE_COMPULSORY","all compulsory keywords should be added like this with a description here");
      65           4 :   keys.add("optional","TEMPLATE_OPTIONAL","all optional keywords that have input should be added like a description here");
      66           4 :   keys.add("atoms","ATOMS","the keyword with which you specify what atoms to use should be added like this");
      67           2 :   keys.setValueDescription("a description of the value that is computed by this colvar should be included here");
      68           2 : }
      69             : 
      70           0 : Template::Template(const ActionOptions&ao):
      71             :   PLUMED_COLVAR_INIT(ao),
      72           0 :   pbc(true)
      73             : {
      74             :   std::vector<AtomNumber> atoms;
      75           0 :   parseAtomList("ATOMS",atoms);
      76           0 :   if(atoms.size()!=2)
      77           0 :     error("Number of specified atoms should be 2");
      78           0 :   bool nopbc=!pbc;
      79           0 :   parseFlag("NOPBC",nopbc);
      80           0 :   pbc=!nopbc;
      81           0 :   checkRead();
      82             : 
      83           0 :   log.printf("  between atoms %d %d\n",atoms[0].serial(),atoms[1].serial());
      84           0 :   if(pbc) log.printf("  using periodic boundary conditions\n");
      85           0 :   else    log.printf("  without periodic boundary conditions\n");
      86             : 
      87           0 :   addValueWithDerivatives(); setNotPeriodic();
      88             : 
      89           0 :   requestAtoms(atoms);
      90           0 : }
      91             : 
      92             : 
      93             : // calculator
      94           0 : void Template::calculate() {
      95             : 
      96           0 :   Vector distance;
      97           0 :   if(pbc) {
      98           0 :     distance=pbcDistance(getPosition(0),getPosition(1));
      99             :   } else {
     100           0 :     distance=delta(getPosition(0),getPosition(1));
     101             :   }
     102           0 :   const double value=distance.modulo();
     103           0 :   const double invvalue=1.0/value;
     104             : 
     105           0 :   setAtomsDerivatives(0,-invvalue*distance);
     106           0 :   setAtomsDerivatives(1,invvalue*distance);
     107           0 :   setBoxDerivatives  (-invvalue*Tensor(distance,distance));
     108           0 :   setValue           (value);
     109           0 : }
     110             : 
     111             : }
     112             : }
     113             : 
     114             : 
     115             : 

Generated by: LCOV version 1.16