Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-2018 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.org for more information.
6 :
7 : This file is part of plumed, version 2.
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 "MultiColvarBase.h"
23 : #include "AtomValuePack.h"
24 : #include "tools/NeighborList.h"
25 : #include "core/ActionRegister.h"
26 : #include "tools/SwitchingFunction.h"
27 :
28 : #include <string>
29 : #include <cmath>
30 :
31 : using namespace std;
32 :
33 : namespace PLMD {
34 : namespace multicolvar {
35 :
36 : //+PLUMEDOC MCOLVAR COORDINATIONNUMBER
37 : /*
38 : Calculate the coordination numbers of atoms so that you can then calculate functions of the distribution of
39 : coordination numbers such as the minimum, the number less than a certain quantity and so on.
40 :
41 : To make the calculation of coordination numbers differentiable the following function is used:
42 :
43 : \f[
44 : s = \frac{ 1 - \left(\frac{r-d_0}{r_0}\right)^n } { 1 - \left(\frac{r-d_0}{r_0}\right)^m }
45 : \f]
46 :
47 : \par Examples
48 :
49 : The following input tells plumed to calculate the coordination numbers of atoms 1-100 with themselves.
50 : The minimum coordination number is then calculated.
51 : \verbatim
52 : COORDINATIONNUMBER SPECIES=1-100 R_0=1.0 MIN={BETA=0.1}
53 : \endverbatim
54 :
55 : The following input tells plumed to calculate how many atoms from 1-100 are within 3.0 of each of the atoms
56 : from 101-110. In the first 101 is the central atom, in the second 102 is the central atom and so on. The
57 : number of coordination numbers more than 6 is then computed.
58 : \verbatim
59 : COORDINATIONNUMBER SPECIESA=101-110 SPECIESB=1-100 R_0=3.0 MORE_THAN={RATIONAL R_0=6.0 NN=6 MM=12 D_0=0}
60 : \endverbatim
61 :
62 : */
63 : //+ENDPLUMEDOC
64 :
65 :
66 76 : class CoordinationNumbers : public MultiColvarBase {
67 : private:
68 : // double nl_cut;
69 : double rcut2;
70 : SwitchingFunction switchingFunction;
71 : public:
72 : static void registerKeywords( Keywords& keys );
73 : explicit CoordinationNumbers(const ActionOptions&);
74 : // active methods:
75 : virtual double compute( const unsigned& tindex, AtomValuePack& myatoms ) const ;
76 : /// Returns the number of coordinates of the field
77 643 : bool isPeriodic() { return false; }
78 : };
79 :
80 2561 : PLUMED_REGISTER_ACTION(CoordinationNumbers,"COORDINATIONNUMBER")
81 :
82 39 : void CoordinationNumbers::registerKeywords( Keywords& keys ) {
83 39 : MultiColvarBase::registerKeywords( keys );
84 39 : keys.use("SPECIES"); keys.use("SPECIESA"); keys.use("SPECIESB");
85 39 : keys.add("compulsory","NN","6","The n parameter of the switching function ");
86 39 : keys.add("compulsory","MM","0","The m parameter of the switching function; 0 implies 2*NN");
87 39 : keys.add("compulsory","D_0","0.0","The d_0 parameter of the switching function");
88 39 : keys.add("compulsory","R_0","The r_0 parameter of the switching function");
89 : keys.add("optional","SWITCH","This keyword is used if you want to employ an alternative to the continuous swiching function defined above. "
90 : "The following provides information on the \\ref switchingfunction that are available. "
91 39 : "When this keyword is present you no longer need the NN, MM, D_0 and R_0 keywords.");
92 : // Use actionWithDistributionKeywords
93 39 : keys.use("MEAN"); keys.use("MORE_THAN"); keys.use("LESS_THAN"); keys.use("MAX");
94 39 : keys.use("MIN"); keys.use("BETWEEN"); keys.use("HISTOGRAM"); keys.use("MOMENTS");
95 39 : keys.use("ALT_MIN"); keys.use("LOWEST"); keys.use("HIGHEST");
96 39 : }
97 :
98 38 : CoordinationNumbers::CoordinationNumbers(const ActionOptions&ao):
99 : Action(ao),
100 38 : MultiColvarBase(ao)
101 : {
102 : // Read in the switching function
103 76 : std::string sw, errors; parse("SWITCH",sw);
104 38 : if(sw.length()>0) {
105 38 : switchingFunction.set(sw,errors);
106 38 : if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
107 : } else {
108 0 : double r_0=-1.0, d_0; int nn, mm;
109 0 : parse("NN",nn); parse("MM",mm);
110 0 : parse("R_0",r_0); parse("D_0",d_0);
111 0 : if( r_0<0.0 ) error("you must set a value for R_0");
112 0 : switchingFunction.set(nn,mm,r_0,d_0);
113 : }
114 38 : log.printf(" coordination of central atom and those within %s\n",( switchingFunction.description() ).c_str() );
115 : // Set the link cell cutoff
116 38 : setLinkCellCutoff( switchingFunction.get_dmax() );
117 38 : rcut2 = switchingFunction.get_dmax()*switchingFunction.get_dmax();
118 :
119 : // And setup the ActionWithVessel
120 76 : std::vector<AtomNumber> all_atoms; setupMultiColvarBase( all_atoms ); checkRead();
121 38 : }
122 :
123 33095 : double CoordinationNumbers::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
124 : // Calculate the coordination number
125 : double dfunc, d2, sw;
126 3761710 : for(unsigned i=1; i<myatoms.getNumberOfAtoms(); ++i) {
127 3728521 : Vector& distance=myatoms.getPosition(i);
128 17715416 : if ( (d2=distance[0]*distance[0])<rcut2 &&
129 12196553 : (d2+=distance[1]*distance[1])<rcut2 &&
130 15701530 : (d2+=distance[2]*distance[2])<rcut2 &&
131 2576772 : d2>epsilon ) {
132 :
133 2576780 : sw = switchingFunction.calculateSqr( d2, dfunc );
134 2576725 : accumulateSymmetryFunction( 1, i, sw, (dfunc)*distance, (-dfunc)*Tensor(distance,distance), myatoms );
135 : }
136 : }
137 :
138 33201 : return myatoms.getValue(1);
139 : }
140 :
141 : }
142 2523 : }
143 :
|