All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Coordination.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 "CoordinationBase.h"
23 #include "tools/SwitchingFunction.h"
24 #include "ActionRegister.h"
25 
26 #include <string>
27 
28 using namespace std;
29 
30 namespace PLMD{
31 namespace colvar{
32 
33 //+PLUMEDOC COLVAR COORDINATION
34 /*
35 Calculate coordination numbers.
36 
37 This keyword can be used to calculate the number of contacts between two groups of atoms
38 and is defined as
39 \f[
40 \sum_{i\in A} \sum_{i\in B} s_{ij}
41 \f]
42 where \f$s_{ij}\f$ is 1 if the contact between atoms \f$i\f$ and \f$j\f$ is formed,
43 zero otherwise.
44 In practise, \f$s_{ij}\f$ is replaced with a switching function to make it differentiable.
45 The default switching function is:
46 \f[
47 s_{ij} = \frac{ 1 - \left(\frac{{\bf r}_{ij}-d_0}{r_0}\right)^n } { 1 - \left(\frac{{\bf r}_{ij}-d_0}{r_0}\right)^m }
48 \f]
49 but it can be changed using the optional SWITCH option.
50 
51 To make your calculation faster you can use a neighbor list, which makes it that only a
52 relevant subset of the pairwise distance are calculated at every step.
53 
54 \par Examples
55 
56 The following example instructs plumed to calculate the total coordination number of the atoms in group 1-10 with the atoms in group 20-100. For atoms 1-10 coordination numbers are calculated that count the number of atoms from the second group that are within 0.3 nm of the central atom. A neighbour list is used to make this calculation faster, this neighbour list is updated every 100 steps.
57 \verbatim
58 COORDINATION GROUPA=1-10 GROUPB=20-100 R_0=0.3 NLIST NL_CUTOFF=0.5 NL_STRIDE=100
59 \endverbatim
60 
61 */
62 //+ENDPLUMEDOC
63 
66 
67 public:
69 // active methods:
70  static void registerKeywords( Keywords& keys );
71  virtual double pairing(double distance,double&dfunc,unsigned i,unsigned j)const;
72 };
73 
74 PLUMED_REGISTER_ACTION(Coordination,"COORDINATION")
75 
76 void Coordination::registerKeywords( Keywords& keys ){
77  CoordinationBase::registerKeywords(keys);
78  keys.add("compulsory","NN","6","The n parameter of the switching function ");
79  keys.add("compulsory","MM","12","The m parameter of the switching function ");
80  keys.add("compulsory","D_0","0.0","The d_0 parameter of the switching function");
81  keys.add("compulsory","R_0","The r_0 parameter of the switching function");
82  keys.add("optional","SWITCH","This keyword is used if you want to employ an alternative to the continuous swiching function defined above. "
83  "The following provides information on the \\ref switchingfunction that are available. "
84  "When this keyword is present you no longer need the NN, MM, D_0 and R_0 keywords.");
85 }
86 
87 Coordination::Coordination(const ActionOptions&ao):
88 Action(ao),
90 {
91 
92  string sw,errors;
93  parse("SWITCH",sw);
94  if(sw.length()>0){
95  switchingFunction.set(sw,errors);
96  if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
97  } else {
98  int nn=6;
99  int mm=12;
100  double d0=0.0;
101  double r0=0.0;
102  parse("R_0",r0);
103  if(r0<=0.0) error("R_0 should be explicitly specified and positive");
104  parse("D_0",d0);
105  parse("NN",nn);
106  parse("MM",mm);
107  switchingFunction.set(nn,mm,r0,d0);
108  }
109 
110  checkRead();
111 
112  log<<" contacts are counted with cutoff "<<switchingFunction.description()<<"\n";
113 }
114 
115 double Coordination::pairing(double distance,double&dfunc,unsigned i,unsigned j)const{
116  (void) i; // avoid warnings
117  (void) j; // avoid warnings
118  return switchingFunction.calculate(distance,dfunc);
119 }
120 
121 }
122 
123 }
double calculate(double x, double &df) const
Log & log
Reference to the log stream.
Definition: Action.h:93
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
SwitchingFunction switchingFunction
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
Small class to compure switching functions in the form In the future we might extend it so as to be s...
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
Definition: Action.h:273
Provides the keyword COORDINATION
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
virtual double pairing(double distance, double &dfunc, unsigned i, unsigned j) const
Base class for all the input Actions.
Definition: Action.h:60
std::string description() const