All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AlphaBeta.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 "MultiColvar.h"
23 #include "tools/Torsion.h"
24 #include "core/ActionRegister.h"
25 
26 #include <string>
27 #include <cmath>
28 
29 using namespace std;
30 
31 namespace PLMD{
32 namespace multicolvar{
33 
34 //+PLUMEDOC COLVAR ALPHABETA
35 /*
36 Measures a distance including pbc between the instantaneous values of a set of torsional angles and set of reference values.
37 
38 This colvar calculates the following quantity.
39 
40 \f[
41 s = \frac{1}{2} \sum_i \left[ 1 + \cos( \phi_i - \phi_i^{\textrm{Ref}} ) \right]
42 \f]
43 
44 where the \f$\phi_i\f$ values are the instantaneous values for the \ref TORSION angles of interest.
45 The \f$\phi_i^{\textrm{Ref}}\f$ values are the user-specified reference values for the torsional angles.
46 
47 \par Examples
48 
49 The following provides an example of the input for an alpha beta similarity.
50 
51 \verbatim
52 ALPHABETA ...
53 ATOMS1=168,170,172,188 REFERENCE1=3.14
54 ATOMS2=170,172,188,190 REFERENCE2=3.14
55 ATOMS3=188,190,192,230 REFERENCE3=3.14
56 LABEL=ab
57 ... ALPHABETA
58 PRINT ARG=ab FILE=colvar STRIDE=10
59 \endverbatim
60 
61 Because all the reference values are the same we can calculate the same quantity using
62 
63 \verbatim
64 ALPHABETA ...
65 ATOMS1=168,170,172,188 REFERENCE=3.14
66 ATOMS2=170,172,188,190
67 ATOMS3=188,190,192,230
68 LABEL=ab
69 ... ALPHABETA
70 PRINT ARG=ab FILE=colvar STRIDE=10
71 \endverbatim
72 
73 */
74 //+ENDPLUMEDOC
75 
76 class AlphaBeta : public MultiColvar {
77 private:
78  std::vector<double> target;
79 public:
80  static void registerKeywords( Keywords& keys );
81  AlphaBeta(const ActionOptions&);
82  virtual double compute( const unsigned& j );
83  bool isPeriodic(){ return false; }
84  Vector getCentralAtom();
85 };
86 
87 PLUMED_REGISTER_ACTION(AlphaBeta,"ALPHABETA")
88 
89 void AlphaBeta::registerKeywords( Keywords& keys ){
90  MultiColvar::registerKeywords( keys );
91  keys.use("ATOMS");
92  keys.add("numbered","REFERENCE","the reference values for each of the torsional angles. If you use a single REFERENCE value the "
93  "same reference value is used for all torsions");
94  keys.reset_style("REFERENCE","compulsory");
95 }
96 
97 AlphaBeta::AlphaBeta(const ActionOptions&ao):
99 {
100  // Read in the atoms
101  int natoms=4; readAtoms( natoms );
102  // Resize target
103  target.resize( taskList.fullSize() );
104 
105  // Read in reference values
106  unsigned ntarget=0;
107  for(unsigned i=0;i<target.size();++i){
108  if( !parseNumbered( "REFERENCE", i+1, target[i] ) ) break;
109  ntarget++;
110  }
111  if( ntarget==0 ){
112  parse("REFERENCE",target[0]);
113  for(unsigned i=1;i<target.size();++i) target[i]=target[0];
114  } else if( ntarget!=target.size() ){
115  error("found wrong number of REFERENCE values");
116  }
117 
118  // And setup the ActionWithVessel
120  if( getNumberOfVessels()==0 ){
121  std::string fake_input;
122  addVessel( "SUM", fake_input, -1 ); // -1 here means that this value will be named getLabel()
123  readVesselKeywords(); // This makes sure resizing is done
124  }
125 
126  // And check everything has been read in correctly
127  checkRead();
128 }
129 
130 double AlphaBeta::compute( const unsigned& j ){
131  Vector d0,d1,d2;
135 
136  Vector dd0,dd1,dd2;
137  PLMD::Torsion t;
138  double value = t.compute(d0,d1,d2,dd0,dd1,dd2);
139  double svalue = -0.5*sin(value-target[current]);
140  double cvalue = 1.+cos(value-target[current]);
141 
142  dd0 *= svalue;
143  dd1 *= svalue;
144  dd2 *= svalue;
145  value = 0.5*cvalue;
146 
147  addAtomsDerivatives(0,dd0);
148  addAtomsDerivatives(1,dd1-dd0);
149  addAtomsDerivatives(2,dd2-dd1);
150  addAtomsDerivatives(3,-dd2);
151 
152  addBoxDerivatives (-(extProduct(d0,dd0)+extProduct(d1,dd1)+extProduct(d2,dd2)));
153 
154  return value;
155 }
156 
160  return 0.5*( getPosition(1) + getPosition(2) );
161 }
162 
163 }
164 }
Class to compute torsional angles.
Definition: Torsion.h:39
bool parseNumbered(const std::string &key, const int no, T &t)
Parse one numbered keyword as generic type.
Definition: Action.h:300
unsigned current
The numerical index of the task we are curently performing.
std::vector< double > target
Definition: AlphaBeta.cpp:78
double compute(const Vector &v1, const Vector &v2, const Vector &v3) const
Compute the angle between the projections of v1 and v3 on the plane orthogonal to v2...
Definition: Torsion.cpp:30
void readAtoms(int &natoms)
Read in all the keywords that can be used to define atoms.
Definition: MultiColvar.cpp:71
Vector getSeparation(const Vector &vec1, const Vector &vec2) const
Get the separation between a pair of vectors.
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
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 addVessel(const std::string &name, const std::string &input, const int numlab=0, const std::string thislab="")
Add a vessel to the list of vessels.
void readVesselKeywords()
Complete the setup of this object (this routine must be called after construction of ActionWithValue)...
void addCentralAtomDerivatives(const unsigned &iatom, const Tensor &der)
Add derivatives to the central atom position.
Definition: MultiColvar.h:123
bool isPeriodic()
Are the base quantities periodic.
Definition: AlphaBeta.cpp:83
static TensorGeneric< n, n > identity()
return an identity tensor
Definition: Tensor.h:318
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
Definition: Action.h:273
This class holds the keywords and their documentation.
Definition: Keywords.h:36
#define PLUMED_MULTICOLVAR_INIT(ao)
Definition: MultiColvar.h:28
void addBoxDerivatives(const Tensor &)
Add some derivatives to the virial.
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
Provides the keyword ALPHABETA
Definition: AlphaBeta.cpp:76
Vector getCentralAtom()
Get the position of the central atom.
Definition: AlphaBeta.cpp:157
virtual double compute(const unsigned &j)
Actually compute the colvar.
Definition: AlphaBeta.cpp:130
DynamicList< unsigned > taskList
The list of tasks we have to perform.
void addAtomsDerivatives(const int &, const Vector &)
Add some derivatives for an atom.
Definition: MultiColvar.h:113
unsigned getNumberOfVessels() const
Get the number of vessels.
const Vector & getPosition(unsigned) const
Get the position of atom iatom.
Definition: MultiColvar.h:93
TensorGeneric< n, m > extProduct(const VectorGeneric< n > &v1, const VectorGeneric< m > &v2)
Definition: Tensor.h:396
This is the abstract base class to use for creating distributions of colvars and functions thereof...
Definition: MultiColvar.h:39
unsigned fullSize() const
Return the total number of elements in the list.
Definition: DynamicList.h:225