All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Template.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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 "ActionRegister.h"
24 
25 #include <string>
26 #include <cmath>
27 
28 using namespace std;
29 
30 namespace PLMD{
31 namespace colvar{
32 
33 //+PLUMEDOC COLVAR TEMPLATE
34 /*
35 This file provides a template for if you want to introduce a new CV.
36 
37 <!-----You should add a description of your CV here---->
38 
39 \par Examples
40 
41 <!---You should put an example of how to use your CV here--->
42 
43 */
44 //+ENDPLUMEDOC
45 
46 class Template : public Colvar {
47  bool pbc;
48 
49 public:
50  Template(const ActionOptions&);
51 // active methods:
52  virtual void calculate();
53  static void registerKeywords(Keywords& keys);
54 };
55 
56 PLUMED_REGISTER_ACTION(Template,"TEMPLATE")
57 
58 void Template::registerKeywords(Keywords& keys){
59  Colvar::registerKeywords(keys);
60  keys.addFlag("TEMPLATE_DEFAULT_OFF_FLAG",false,"flags that are by default not performed should be specified like this");
61  keys.addFlag("TEMPLATE_DEFAULT_ON_FLAG",true,"flags that are by default performed should be specified like this");
62  keys.add("compulsory","TEMPLATE_COMPULSORY","all compulsory keywords should be added like this with a description here");
63  keys.add("optional","TEMPLATE_OPTIONAL","all optional keywords that have input should be added like a description here");
64  keys.add("atoms","TEMPLATE_INPUT","the keyword with which you specify what atoms to use should be added like this");
65 }
66 
67 Template::Template(const ActionOptions&ao):
69 pbc(true)
70 {
71  vector<AtomNumber> atoms;
72  parseAtomList("ATOMS",atoms);
73  if(atoms.size()!=2)
74  error("Number of specified atoms should be 2");
75  bool nopbc=!pbc;
76  parseFlag("NOPBC",nopbc);
77  pbc=!nopbc;
78  checkRead();
79 
80  log.printf(" between atoms %d %d\n",atoms[0].serial(),atoms[1].serial());
81  if(pbc) log.printf(" using periodic boundary conditions\n");
82  else log.printf(" without periodic boundary conditions\n");
83 
85 
86  requestAtoms(atoms);
87 }
88 
89 
90 // calculator
92 
93  Vector distance;
94  if(pbc){
95  distance=pbcDistance(getPosition(0),getPosition(1));
96  } else {
97  distance=delta(getPosition(0),getPosition(1));
98  }
99  const double value=distance.modulo();
100  const double invvalue=1.0/value;
101 
102  setAtomsDerivatives(0,-invvalue*distance);
103  setAtomsDerivatives(1,invvalue*distance);
104  setBoxDerivatives (-invvalue*Tensor(distance,distance));
105  setValue (value);
106 }
107 
108 }
109 }
110 
111 
112 
const Vector & getPosition(int) const
Get position of i-th atom.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
Definition: Action.cpp:104
void setNotPeriodic()
Set your default value to have no periodicity.
Log & log
Reference to the log stream.
Definition: Action.h:93
double modulo() const
Compute the modulo.
Definition: Vector.h:325
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
Provides the keyword TEMPLATE
Definition: Template.cpp:46
void setAtomsDerivatives(int, const Vector &)
Definition: Colvar.h:97
void error(const std::string &msg) const
Crash calculation and print documentation.
Definition: Action.cpp:195
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
void parseAtomList(const std::string &key, std::vector< AtomNumber > &t)
Parse a list of atoms without a numbered keyword.
void addValueWithDerivatives()
Add a value with the name label that has derivatives.
void requestAtoms(const std::vector< AtomNumber > &a)
Definition: Colvar.cpp:44
#define PLUMED_COLVAR_INIT(ao)
Definition: Colvar.h:29
void setBoxDerivatives(const Tensor &)
Definition: Colvar.h:102
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Definition: OFile.cpp:82
This is the abstract base class to use for implementing new collective variables, within it there is ...
Definition: Colvar.h:39
VectorGeneric< n > delta(const VectorGeneric< n > &v1, const VectorGeneric< n > &v2)
Definition: Vector.h:262
void setValue(const double &d)
Set the default value (the one without name)
Vector pbcDistance(const Vector &, const Vector &) const
Compute the pbc distance between two positions.
Tensor3d Tensor
Definition: Tensor.h:425
virtual void calculate()
Calculate an Action.
Definition: Template.cpp:91