All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Distances.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 "core/ActionRegister.h"
24 
25 #include <string>
26 #include <cmath>
27 
28 using namespace std;
29 
30 namespace PLMD{
31 namespace multicolvar{
32 
33 //+PLUMEDOC MCOLVAR DISTANCES
34 /*
35 Calculate the distances between one or many pairs of atoms. You can then calculate functions of the distribution of
36 distances such as the minimum, the number less than a certain quantity and so on.
37 
38 \par Examples
39 
40 The following input tells plumed to calculate the distances between atoms 3 and 5 and between atoms 1 and 2 and to
41 print the minimum for these two distances.
42 \verbatim
43 DISTANCES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1} LABEL=d1
44 PRINT ARG=d1.min
45 \endverbatim
46 (See also \ref PRINT).
47 
48 The following input tells plumed to calculate the distances between atoms 3 and 5 and between atoms 1 and 2
49 and then to calculate the number of these distances that are less than 0.1 nm. The number of distances
50 less than 0.1nm is then printed to a file.
51 \verbatim
52 DISTANCES ATOMS1=3,5 ATOMS2=1,2 LABEL=d1 LESS_THAN={RATIONAL R_0=0.1}
53 PRINT ARG=d1.lt0.1
54 \endverbatim
55 (See also \ref PRINT \ref switchingfunction).
56 
57 The following input tells plumed to calculate all the distances between atoms 1, 2 and 3 (i.e. the distances between atoms
58 1 and 2, atoms 1 and 3 and atoms 2 and 3). The average of these distances is then calculated.
59 \verbatim
60 DISTANCES GROUP=1-3 AVERAGE LABEL=d1
61 PRINT ARG=d1.average
62 \endverbatim
63 (See also \ref PRINT)
64 
65 The following input tells plumed to calculate all the distances between the atoms in GROUPA and the atoms in GROUPB.
66 In other words the distances between atoms 1 and 2 and the distance between atoms 1 and 3. The number of distances
67 more than 0.1 is then printed to a file.
68 \verbatim
69 DISTANCES GROUPA=1 GROUPB=2,3 MORE_THAN={RATIONAL R_0=0.1}
70 PRINT ARG=d1.gt0.1
71 \endverbatim
72 (See also \ref PRINT \ref switchingfunction)
73 */
74 //+ENDPLUMEDOC
75 
76 
77 class Distances : public MultiColvar {
78 private:
79 public:
80  static void registerKeywords( Keywords& keys );
81  Distances(const ActionOptions&);
82 // active methods:
83  virtual double compute( const unsigned& j );
84 /// Returns the number of coordinates of the field
85  bool isPeriodic(){ return false; }
86  Vector getCentralAtom();
87 };
88 
89 PLUMED_REGISTER_ACTION(Distances,"DISTANCES")
90 
91 void Distances::registerKeywords( Keywords& keys ){
92  MultiColvar::registerKeywords( keys );
93  keys.use("ATOMS");
94  keys.use("MEAN"); keys.use("MIN"); keys.use("LESS_THAN"); keys.use("DHENERGY");
95  keys.use("MORE_THAN"); keys.use("BETWEEN"); keys.use("HISTOGRAM"); keys.use("MOMENTS");
96  keys.add("atoms-1","GROUP","Calculate the distance between each distinct pair of atoms in the group");
97  keys.add("atoms-2","GROUPA","Calculate the distances between all the atoms in GROUPA and all "
98  "the atoms in GROUPB. This must be used in conjuction with GROUPB.");
99  keys.add("atoms-2","GROUPB","Calculate the distances between all the atoms in GROUPA and all the atoms "
100  "in GROUPB. This must be used in conjuction with GROUPA.");
101 }
102 
103 Distances::Distances(const ActionOptions&ao):
105 {
106  // Read in the atoms
107  int natoms=2; readAtoms( natoms );
108  // And setup the ActionWithVessel
110  // And check everything has been read in correctly
111  checkRead();
112 }
113 
114 double Distances::compute( const unsigned& j ){
115  Vector distance;
116  distance=getSeparation( getPosition(0), getPosition(1) );
117  const double value=distance.modulo();
118  const double invvalue=1.0/value;
119 
120  // And finish the calculation
121  addAtomsDerivatives( 0,-invvalue*distance );
122  addAtomsDerivatives( 1, invvalue*distance );
123  addBoxDerivatives( -invvalue*Tensor(distance,distance) );
124  return value;
125 }
126 
130  return 0.5*( getPosition(0) + getPosition(1) );
131 }
132 
133 }
134 }
135 
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
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
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
static TensorGeneric< n, n > identity()
return an identity tensor
Definition: Tensor.h:318
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
void addAtomsDerivatives(const int &, const Vector &)
Add some derivatives for an atom.
Definition: MultiColvar.h:113
const Vector & getPosition(unsigned) const
Get the position of atom iatom.
Definition: MultiColvar.h:93
This is the abstract base class to use for creating distributions of colvars and functions thereof...
Definition: MultiColvar.h:39
Provides the keyword DISTANCES
Definition: Distances.cpp:77
Tensor3d Tensor
Definition: Tensor.h:425
Vector getCentralAtom()
Get the position of the central atom.
Definition: Distances.cpp:127
bool isPeriodic()
Returns the number of coordinates of the field.
Definition: Distances.cpp:85
virtual double compute(const unsigned &j)
Actually compute the colvar.
Definition: Distances.cpp:114