All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
VolumeAround.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 "core/ActionRegister.h"
23 #include "tools/Pbc.h"
24 #include "ActionVolume.h"
25 
26 //+PLUMEDOC MCOLVARF AROUND
27 /*
28 This quantity can be used to calculate functions of the distribution of collective
29 variables for the atoms that lie in a particular, user-specified part of of the cell.
30 
31 Each of the base quantities calculated by a multicolvar can can be assigned to a particular point in three
32 dimensional space. For example, if we have the coordination numbers for all the atoms in the
33 system each coordination number can be assumed to lie on the position of the central atom.
34 Because each base quantity can be assigned to a particular point in space we can calculate functions of the
35 distribution of base quantities in a particular part of the box by using:
36 
37 \f[
38 \overline{s}_{\tau} = \frac{ \sum_i f(s_i) w(x_i,y_i,z_i) }{ \sum_i w(x_i,y_i,z_i) }
39 \f]
40 
41 where the sum is over the collective variables, \f$s_i\f$, each of which can be thought to be at \f$ (x_i,y_i,z_i)\f$.
42 The function \f$ w(x_i,y_i,z_i) \f$ measures whether or not the system is in the subregion of interest. It
43 is equal to:
44 
45 \f[
46 w(x_i,y_i,z_i) = \int_{xl}^{xu} \int_{yl}^{yu} \int_{zl}^{zu} \textrm{d}x\textrm{d}y\textrm{d}z K\left( \frac{x - x_i}{\sigma} \right)K\left( \frac{y - y_i}{\sigma} \right)K\left( \frac{z - z_i}{\sigma} \right)
47 \f]
48 
49 where \f$K\f$ is one of the kernel functions described on \ref histogrambead and \f$\sigma\f$ is a bandwidth parameter.
50 The function \f$(s_i)\f$ can be any of the usual LESS_THAN, MORE_THAN, WITHIN etc that are used in all other multicolvars.
51 
52 When AROUND is used with the \ref DENSITY action the number of atoms in the specified region is calculated
53 
54 \par Examples
55 
56 The following commands tell plumed to calculate the average coordination number for the atoms
57 that have x (in fractional coordinates) within 2.0 nm of the com of mass c1. The final value will be labeled s.mean.
58 \verbatim
59 COM ATOMS=1-100 LABEL=c1
60 COORDINATIONNUMBER SPECIES=1-100 R_0=1.0 LABEL=c
61 AROUND ARG=c ORIGIN=c1 XLOWER=-2.0 XUPPER=2.0 SIGMA=0.1 MEAN LABEL=s
62 \endverbatim
63 
64 */
65 //+ENDPLUMEDOC
66 
67 namespace PLMD {
68 namespace multicolvar {
69 
70 class VolumeAround : public ActionVolume {
71 private:
73  bool dox, doy, doz;
74  double xlow, xhigh;
75  double ylow, yhigh;
76  double zlow, zhigh;
77 public:
78  static void registerKeywords( Keywords& keys );
79  VolumeAround(const ActionOptions& ao);
80  void setupRegion();
82 };
83 
84 PLUMED_REGISTER_ACTION(VolumeAround,"AROUND")
85 
86 void VolumeAround::registerKeywords( Keywords& keys ){
88  keys.add("atoms","ATOM","the atom whose vicinity we are interested in examining");
89  keys.add("compulsory","XLOWER","0.0","the lower boundary in x relative to the x coordinate of the atom (0 indicates use full extent of box).");
90  keys.add("compulsory","XUPPER","0.0","the upper boundary in x relative to the x coordinate of the atom (0 indicates use full extent of box).");
91  keys.add("compulsory","YLOWER","0.0","the lower boundary in y relative to the y coordinate of the atom (0 indicates use full extent of box).");
92  keys.add("compulsory","YUPPER","0.0","the upper boundary in y relative to the y coordinate of the atom (0 indicates use full extent of box).");
93  keys.add("compulsory","ZLOWER","0.0","the lower boundary in z relative to the z coordinate of the atom (0 indicates use full extent of box).");
94  keys.add("compulsory","ZUPPER","0.0","the upper boundary in z relative to the z coordinate of the atom (0 indicates use full extent of box).");
95 }
96 
98 Action(ao),
99 ActionVolume(ao)
100 {
101  std::vector<AtomNumber> atom;
102  parseAtomList("ATOM",atom);
103  if( atom.size()!=1 ) error("should only be one atom specified");
104  log.printf(" boundaries for region are calculated based on positions of atom : %d\n",atom[0].serial() );
105 
106  dox=true; parse("XLOWER",xlow); parse("XUPPER",xhigh);
107  doy=true; parse("YLOWER",ylow); parse("YUPPER",yhigh);
108  doz=true; parse("ZLOWER",zlow); parse("ZUPPER",zhigh);
109  if( xlow==0.0 && xhigh==0.0 ) dox=false;
110  if( ylow==0.0 && yhigh==0.0 ) doy=false;
111  if( zlow==0.0 && zhigh==0.0 ) doz=false;
112  if( !dox && !doy && !doz ) error("no subregion defined use XLOWER, XUPPER, YLOWER, YUPPER, ZLOWER, ZUPPER");
113  log.printf(" boundaries for region (region of interest about atom) : x %f %f, y %f %f, z %f %f \n",xlow,xhigh,ylow,yhigh,zlow,zhigh);
114  checkRead(); requestAtoms(atom);
115 }
116 
118 
119 double VolumeAround::calculateNumberInside( const Vector& cpos, HistogramBead& bead, Vector& derivatives ){
120  // Calculate position of atom wrt to origin
121  Vector fpos=pbcDistance( getPosition(0), cpos );
122 
123  double xcontr, ycontr, zcontr, xder, yder, zder;
124  if( dox ){
125  bead.set( xlow, xhigh, getSigma() );
126  xcontr=bead.calculate( fpos[0], xder );
127  } else {
128  xcontr=1.; xder=0.;
129  }
130  if( doy ){
131  bead.set( ylow, yhigh, getSigma() );
132  ycontr=bead.calculate( fpos[1], yder );
133  } else {
134  ycontr=1.; yder=0.;
135  }
136  if( doz ){
137  bead.set( zlow, zhigh, getSigma() );
138  zcontr=bead.calculate( fpos[2], zder );
139  } else {
140  zcontr=1.; zder=0.;
141  }
142  derivatives[0]=xder*ycontr*zcontr;
143  derivatives[1]=xcontr*yder*zcontr;
144  derivatives[2]=xcontr*ycontr*zder;
145  // Add derivatives wrt to position of origin atom
146  addReferenceAtomDerivatives( 0, -derivatives );
147  // Add virial contribution
148  addBoxDerivatives( -Tensor(fpos,derivatives) );
149  return xcontr*ycontr*zcontr;
150 }
151 
152 }
153 }
Log & log
Reference to the log stream.
Definition: Action.h:93
void addBoxDerivatives(const Tensor &vir)
Add derivatives wrt to the virial.
Definition: ActionVolume.h:177
static void registerKeywords(Keywords &keys)
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
void parseAtomList(const std::string &key, std::vector< AtomNumber > &t)
Parse a list of atoms without a numbered keyword.
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
A class for calculating whether or not values are within a given range using : .
Definition: HistogramBead.h:41
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
Base class for all the input Actions.
Definition: Action.h:60
This is the abstract base class to use for implementing a new way of definining a particular region o...
Definition: ActionVolume.h:43
void set(const std::string &params, const std::string &dd, std::string &errormsg)
Provides the keyword AROUND
HistogramBead bead
The bead for the histogram.
Definition: ActionVolume.h:57
double calculateNumberInside(const Vector &cpos, HistogramBead &bead, Vector &derivatives)
void addReferenceAtomDerivatives(const unsigned &iatom, const Vector &der)
Add derivatinve to one of the reference atoms here.
Definition: ActionVolume.h:165
Vector pbcDistance(const Vector &v1, const Vector &v2) const
Calculate distance between two points.
Definition: ActionVolume.h:131
bool serial
Do all calculations in serial.
Tensor3d Tensor
Definition: Tensor.h:425
static void registerKeywords(Keywords &keys)
std::vector< double > derivatives
Vector of derivatives for the object.
double calculate(double x, double &df) const
VolumeAround(const ActionOptions &ao)
const Vector & getPosition(int iatom)
Get position of atom.
Definition: ActionVolume.h:136
void requestAtoms(const std::vector< AtomNumber > &atoms)
Request the atoms.