Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2016-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 "CubicHarmonicBase.h"
23 : #include "tools/SwitchingFunction.h"
24 :
25 : #include <string>
26 : #include <cmath>
27 :
28 : using namespace std;
29 :
30 : namespace PLMD {
31 : namespace crystallization {
32 :
33 8 : void CubicHarmonicBase::registerKeywords( Keywords& keys ) {
34 8 : multicolvar::MultiColvarBase::registerKeywords( keys );
35 8 : keys.use("SPECIES"); keys.use("SPECIESA"); keys.use("SPECIESB");
36 8 : keys.add("compulsory","NN","6","The n parameter of the switching function ");
37 8 : keys.add("compulsory","MM","0","The m parameter of the switching function; 0 implies 2*NN");
38 8 : keys.add("compulsory","D_0","0.0","The d_0 parameter of the switching function");
39 8 : keys.add("compulsory","R_0","The r_0 parameter of the switching function");
40 : keys.add("optional","SWITCH","This keyword is used if you want to employ an alternative to the continuous swiching function defined above. "
41 : "The following provides information on the \\ref switchingfunction that are available. "
42 8 : "When this keyword is present you no longer need the NN, MM, D_0 and R_0 keywords.");
43 8 : keys.add("compulsory","PHI","0.0","The Euler rotational angle phi");
44 8 : keys.add("compulsory","THETA","0.0","The Euler rotational angle theta");
45 8 : keys.add("compulsory","PSI","0.0","The Euler rotational angle psi");
46 : // Use actionWithDistributionKeywords
47 8 : keys.use("MEAN"); keys.use("MORE_THAN"); keys.use("LESS_THAN"); keys.use("MAX");
48 8 : keys.use("MIN"); keys.use("BETWEEN"); keys.use("HISTOGRAM"); keys.use("MOMENTS");
49 8 : keys.use("ALT_MIN"); keys.use("LOWEST"); keys.use("HIGHEST");
50 8 : }
51 :
52 5 : CubicHarmonicBase::CubicHarmonicBase(const ActionOptions&ao):
53 : Action(ao),
54 5 : MultiColvarBase(ao)
55 : {
56 : // Read in the switching function
57 10 : std::string sw, errors; parse("SWITCH",sw);
58 5 : if(sw.length()>0) {
59 5 : switchingFunction.set(sw,errors);
60 5 : if( errors.length()!=0 ) error("problem reading SWITCH keyword : " + errors );
61 : } else {
62 0 : double r_0=-1.0, d_0; int nn, mm;
63 0 : parse("NN",nn); parse("MM",mm);
64 0 : parse("R_0",r_0); parse("D_0",d_0);
65 0 : if( r_0<0.0 ) error("you must set a value for R_0");
66 0 : switchingFunction.set(nn,mm,r_0,d_0);
67 : }
68 :
69 5 : double phi, theta, psi; parse("PHI",phi); parse("THETA",theta); parse("PSI",psi);
70 5 : log.printf(" creating rotation matrix with Euler angles phi=%f, theta=%f and psi=%f\n",phi,theta,psi);
71 : // Calculate the rotation matrix http://mathworld.wolfram.com/EulerAngles.html
72 5 : rotationmatrix[0][0]=cos(psi)*cos(phi)-cos(theta)*sin(phi)*sin(psi);
73 5 : rotationmatrix[0][1]=cos(psi)*sin(phi)+cos(theta)*cos(phi)*sin(psi);
74 5 : rotationmatrix[0][2]=sin(psi)*sin(theta);
75 :
76 5 : rotationmatrix[1][0]=-sin(psi)*cos(phi)-cos(theta)*sin(phi)*cos(psi);
77 5 : rotationmatrix[1][1]=-sin(psi)*sin(phi)+cos(theta)*cos(phi)*cos(psi);
78 5 : rotationmatrix[1][2]=cos(psi)*sin(theta);
79 :
80 5 : rotationmatrix[2][0]=sin(theta)*sin(phi);
81 5 : rotationmatrix[2][1]=-sin(theta)*cos(phi);
82 5 : rotationmatrix[2][2]=cos(theta);
83 :
84 :
85 5 : log.printf(" measure crystallinity around central atom. Includes those atoms within %s\n",( switchingFunction.description() ).c_str() );
86 : // Set the link cell cutoff
87 5 : rcut2 = switchingFunction.get_dmax()*switchingFunction.get_dmax();
88 5 : setLinkCellCutoff( switchingFunction.get_dmax() );
89 : // And setup the ActionWithVessel
90 10 : std::vector<AtomNumber> all_atoms; setupMultiColvarBase( all_atoms );
91 5 : }
92 :
93 26109 : double CubicHarmonicBase::compute( const unsigned& tindex, multicolvar::AtomValuePack& myatoms ) const {
94 26109 : double dfunc; Vector rotatedis;
95 :
96 : // Calculate the coordination number
97 26110 : Vector myder, rotateder, fder; unsigned nat=myatoms.getNumberOfAtoms();
98 :
99 : double d2;
100 2510221 : for(unsigned i=1; i<nat; ++i) {
101 2484110 : Vector& distance=myatoms.getPosition(i);
102 :
103 10372774 : if ( (d2=distance[0]*distance[0])<rcut2 &&
104 4322236 : (d2+=distance[1]*distance[1])<rcut2 &&
105 6697063 : (d2+=distance[2]*distance[2])<rcut2 &&
106 328246 : d2>epsilon ) {
107 :
108 328284 : double sw = switchingFunction.calculateSqr( d2, dfunc );
109 :
110 328247 : rotatedis[0]=rotationmatrix[0][0]*distance[0]
111 328291 : +rotationmatrix[0][1]*distance[1]
112 328294 : +rotationmatrix[0][2]*distance[2];
113 328287 : rotatedis[1]=rotationmatrix[1][0]*distance[0]
114 328282 : +rotationmatrix[1][1]*distance[1]
115 328275 : +rotationmatrix[1][2]*distance[2];
116 328266 : rotatedis[2]=rotationmatrix[2][0]*distance[0]
117 328276 : +rotationmatrix[2][1]*distance[1]
118 328270 : +rotationmatrix[2][2]*distance[2];
119 :
120 328255 : double tmp = calculateCubicHarmonic( rotatedis, d2, rotateder );
121 :
122 328301 : myder[0]=rotationmatrix[0][0]*rotateder[0]
123 328302 : +rotationmatrix[1][0]*rotateder[1]
124 328298 : +rotationmatrix[2][0]*rotateder[2];
125 328287 : myder[1]=rotationmatrix[0][1]*rotateder[0]
126 328296 : +rotationmatrix[1][1]*rotateder[1]
127 328294 : +rotationmatrix[2][1]*rotateder[2];
128 328284 : myder[2]=rotationmatrix[0][2]*rotateder[0]
129 328295 : +rotationmatrix[1][2]*rotateder[1]
130 328294 : +rotationmatrix[2][2]*rotateder[2];
131 :
132 328288 : fder = (+dfunc)*tmp*distance + sw*myder;
133 :
134 328281 : accumulateSymmetryFunction( 1, i, sw*tmp, fder, Tensor(distance,-fder), myatoms );
135 328303 : accumulateSymmetryFunction( -1, i, sw, (+dfunc)*distance, (-dfunc)*Tensor(distance,distance), myatoms );
136 : }
137 : }
138 : // values -> der of... value [0], weight[1], x coord [2], y, z... [more magic]
139 26111 : updateActiveAtoms( myatoms ); myatoms.getUnderlyingMultiValue().quotientRule( 1, 1 );
140 26111 : return myatoms.getValue(1); // this is equivalent to getting an "atomic" CV
141 : }
142 :
143 : }
144 2523 : }
145 :
|