All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Bridge.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/SwitchingFunction.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 MCOLVAR BRIDGE
35 /*
36 Calculate the number of atoms that bridge two parts of a structure
37 
38 This quantity calculates:
39 
40 \f[
41  f(x) = \sum_{ijk} s_A(r_{ij})s_B(r_{ik})
42 \f]
43 
44 where the sum over \f$i\f$ is over all the ``bridging atoms" and
45 \f$s_A\f$ and \f$s_B\f$ are \ref switchingfunction.
46 
47 \par Examples
48 
49 The following example instructs plumed to calculate the number of water molecules
50 that are bridging betweeen atoms 1-10 and atoms 11-20 and to print the value
51 to a file
52 
53 \verbatim
54 BRIDGE BRIDGING_ATOMS=100-200 GROUPA=1-10 GROUPB=11-20 LABEL=w1
55 PRINT ARG=a1.mean FILE=colvar
56 \endverbatim
57 
58 */
59 //+ENDPLUMEDOC
60 
61 class Bridge : public MultiColvar {
62 private:
63  Vector dij, dik;
66 public:
67  static void registerKeywords( Keywords& keys );
68  Bridge(const ActionOptions&);
69 // active methods:
70  virtual double compute( const unsigned& j );
71 /// Returns the number of coordinates of the field
72  void calculateWeight();
73  bool isPeriodic(){ return false; }
74  Vector getCentralAtom();
75 };
76 
77 PLUMED_REGISTER_ACTION(Bridge,"BRIDGE")
78 
79 void Bridge::registerKeywords( Keywords& keys ){
80  MultiColvar::registerKeywords( keys );
81  keys.use("ATOMS");
82  keys.add("atoms-2","BRIDGING_ATOMS","The list of atoms that can form the bridge between the two interesting parts "
83  "of the structure.");
84  keys.add("atoms-2","GROUPA","The list of atoms that are in the first interesting part of the structure");
85  keys.add("atoms-2","GROUPB","The list of atoms that are in the second interesting part of the structure");
86  keys.add("optional","SWITCH","The parameters of the two \\ref switchingfunction in the above formula");
87  keys.add("optional","SWITCHA","The \\ref switchingfunction on the distance between bridging atoms and the atoms in "
88  "group A");
89  keys.add("optional","SWITCHB","The \\ref switchingfunction on the distance between the bridging atoms and the atoms in "
90  "group B");
91 }
92 
93 Bridge::Bridge(const ActionOptions&ao):
95 {
96  // Read in the atoms
98  readThreeGroups("BRIDGING_ATOMS","GROUPA","GROUPB",false);
99  int natoms=3; readAtoms( natoms );
100  std::string sfinput,errors; parse("SWITCH",sfinput);
101  if( sfinput.length()>0 ){
102  sf1.set(sfinput,errors);
103  if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
104  sf2.set(sfinput,errors);
105  if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
106  } else {
107  parse("SWITCHA",sfinput);
108  if(sfinput.length()>0){
110  sf1.set(sfinput,errors);
111  if( errors.length()!=0 ) error("problem reading SWITCHA keyword : " + errors );
112  sfinput.clear(); parse("SWITCHB",sfinput);
113  if(sfinput.length()==0) error("found SWITCHA keyword without SWITCHB");
114  sf2.set(sfinput,errors);
115  if( errors.length()!=0 ) error("problem reading SWITCHB keyword : " + errors );
116  } else {
117  error("missing definition of switching functions");
118  }
119  }
120  log.printf(" distance between bridging atoms and atoms in GROUPA must be less than %s\n",sf1.description().c_str());
121  log.printf(" distance between bridging atoms and atoms in GROUPB must be less than %s\n",sf2.description().c_str());
122 
123  // And setup the ActionWithVessel
125  if( getNumberOfVessels()!=0 ) error("should not have vessels for this action");
126  std::string fake_input;
127  addVessel( "SUM", fake_input, -1 ); // -1 here means that this value will be named getLabel()
129  // And check everything has been read in correctly
130  checkRead();
131 }
132 
135  double dw, w=sf1.calculate( dij.modulo(), dw );
136  setWeight( w );
137 
138  if( w<getTolerance() ) return;
139  addAtomsDerivativeOfWeight( 1, -dw*dij );
140  addAtomsDerivativeOfWeight( 0, dw*dij );
141  addBoxDerivativesOfWeight( (-dw)*Tensor(dij,dij) );
142 }
143 
144 double Bridge::compute( const unsigned& j ){
146  double dw, w=sf2.calculate( dik.modulo(), dw );
147 
148  // And finish the calculation
149  addAtomsDerivatives( 1, -dw*dik );
150  addAtomsDerivatives( 2, dw*dik );
151  addBoxDerivatives( (-dw)*Tensor(dik,dik) );
152  return w;
153 }
154 
157  return getPosition(1);
158 }
159 
160 }
161 }
void addAtomsDerivativeOfWeight(const unsigned &i, const Vector &wder)
Set the derivative of the weight (used in MEAN and HISTOGRAM)
Definition: MultiColvar.h:118
double calculate(double x, double &df) const
Log & log
Reference to the log stream.
Definition: Action.h:93
void calculateWeight()
Returns the number of coordinates of the field.
Definition: Bridge.cpp:133
virtual double compute(const unsigned &j)
Actually compute the colvar.
Definition: Bridge.cpp:144
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.
double modulo() const
Compute the modulo.
Definition: Vector.h:325
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
Vector getCentralAtom()
Get the position of the central atom.
Definition: Bridge.cpp:155
void set(int nn, int mm, double r_0, double d_0)
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.
Provides the keyword BRIDGE
Definition: Bridge.cpp:61
Small class to compure switching functions in the form In the future we might extend it so as to be s...
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 weightHasDerivatives
Does the weight have derivatives.
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
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Definition: OFile.cpp:82
void setWeight(const double &weight)
Set a weight for this colvar (used in MEAN and HISTOGRAM)
SwitchingFunction sf1
Definition: Bridge.cpp:64
void const char const char int double int double double int int double int double * w
Definition: Matrix.h:42
bool isPeriodic()
Are the base quantities periodic.
Definition: Bridge.cpp:73
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
double getTolerance() const
Return the value of the tolerance.
This is the abstract base class to use for creating distributions of colvars and functions thereof...
Definition: MultiColvar.h:39
void readThreeGroups(const std::string &key1, const std::string &key2, const std::string &key3, const bool &allow2)
Read three groups.
std::string description() const
SwitchingFunction sf2
Definition: Bridge.cpp:65
Tensor3d Tensor
Definition: Tensor.h:425
void addBoxDerivativesOfWeight(const Tensor &vir)