Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2015-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 "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 XYDISTANCES
34 : /*
35 : Calculate distance between a pair of atoms neglecting the z-component.
36 : You can then calculate functions of the distribution of
37 : values such as the minimum, the number less than a certain quantity and so on.
38 :
39 : \par Examples
40 :
41 : The following input tells plumed to calculate the projection of the length of the vector connecting atom 3
42 : to atom 5 projected in the xy-plane and the projection of the length of the vector
43 : the vector connecting atom 1 to atom 2 in the xy-plane. The minimum of these two quantities is then
44 : printed
45 : \verbatim
46 : XYDISTANCES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1} LABEL=d1
47 : PRINT ARG=d1.min
48 : \endverbatim
49 : (See also \ref PRINT).
50 :
51 : */
52 : //+ENDPLUMEDOC
53 :
54 : //+PLUMEDOC MCOLVAR XZDISTANCES
55 : /*
56 : Calculate distance between a pair of atoms neglecting the y-component.
57 : You can then calculate functions of the distribution of
58 : values such as the minimum, the number less than a certain quantity and so on.
59 :
60 : \par Examples
61 :
62 : The following input tells plumed to calculate the projection of the length of the vector connecting atom 3
63 : to atom 5 projected in the xz-plane and the projection of the length of the vector
64 : the vector connecting atom 1 to atom 2 in the xz-plane. The minimum of these two quantities is then
65 : printed
66 : \verbatim
67 : XZDISTANCES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1} LABEL=d1
68 : PRINT ARG=d1.min
69 : \endverbatim
70 : (See also \ref PRINT).
71 :
72 : */
73 : //+ENDPLUMEDOC
74 :
75 : //+PLUMEDOC MCOLVAR YZDISTANCES
76 : /*
77 : Calculate distance between a pair of atoms neglecting the x-component.
78 : You can then calculate functions of the distribution of
79 : values such as the minimum, the number less than a certain quantity and so on.
80 :
81 : \par Examples
82 :
83 : The following input tells plumed to calculate the projection of the length of the vector connecting atom 3
84 : to atom 5 in the yz-plane and the projection of the length of the vector
85 : the vector connecting atom 1 to atom 2 in the yz-plane. The minimum of these two quantities is then
86 : printed
87 : \verbatim
88 : YZDISTANCES ATOMS1=3,5 ATOMS2=1,2 MIN={BETA=0.1} LABEL=d1
89 : PRINT ARG=d1.min
90 : \endverbatim
91 : (See also \ref PRINT).
92 :
93 : */
94 : //+ENDPLUMEDOC
95 :
96 :
97 0 : class XYDistances : public MultiColvar {
98 : private:
99 : unsigned myc1, myc2;
100 : public:
101 : static void registerKeywords( Keywords& keys );
102 : explicit XYDistances(const ActionOptions&);
103 : // active methods:
104 : virtual double compute( const unsigned& tindex, AtomValuePack& myatoms ) const ;
105 : /// Returns the number of coordinates of the field
106 0 : bool isPeriodic() { return false; }
107 : };
108 :
109 2523 : PLUMED_REGISTER_ACTION(XYDistances,"XYDISTANCES")
110 2523 : PLUMED_REGISTER_ACTION(XYDistances,"XZDISTANCES")
111 2523 : PLUMED_REGISTER_ACTION(XYDistances,"YZDISTANCES")
112 :
113 3 : void XYDistances::registerKeywords( Keywords& keys ) {
114 3 : MultiColvar::registerKeywords( keys );
115 3 : keys.use("ATOMS"); keys.use("MAX"); keys.use("ALT_MIN");
116 3 : keys.use("MEAN"); keys.use("MIN"); keys.use("LESS_THAN");
117 3 : keys.use("LOWEST"); keys.use("HIGHEST");
118 3 : keys.use("MORE_THAN"); keys.use("BETWEEN"); keys.use("HISTOGRAM"); keys.use("MOMENTS");
119 3 : keys.add("atoms-1","GROUP","Calculate the distance between each distinct pair of atoms in the group");
120 : keys.add("atoms-2","GROUPA","Calculate the distances between all the atoms in GROUPA and all "
121 3 : "the atoms in GROUPB. This must be used in conjuction with GROUPB.");
122 : keys.add("atoms-2","GROUPB","Calculate the distances between all the atoms in GROUPA and all the atoms "
123 3 : "in GROUPB. This must be used in conjuction with GROUPA.");
124 3 : }
125 :
126 0 : XYDistances::XYDistances(const ActionOptions&ao):
127 0 : PLUMED_MULTICOLVAR_INIT(ao)
128 : {
129 0 : if( getName().find("XY")!=std::string::npos) {
130 0 : myc1=0; myc2=1;
131 0 : } else if( getName().find("XZ")!=std::string::npos) {
132 0 : myc1=0; myc2=2;
133 0 : } else if( getName().find("YZ")!=std::string::npos) {
134 0 : myc1=1; myc2=2;
135 0 : } else plumed_error();
136 :
137 : // Read in the atoms
138 0 : std::vector<AtomNumber> all_atoms;
139 0 : readTwoGroups( "GROUP", "GROUPA", "GROUPB", all_atoms );
140 0 : int natoms=2; readAtoms( natoms, all_atoms );
141 : // And check everything has been read in correctly
142 0 : checkRead();
143 0 : }
144 :
145 0 : double XYDistances::compute( const unsigned& tindex, AtomValuePack& myatoms ) const {
146 0 : Vector distance;
147 0 : distance=getSeparation( myatoms.getPosition(0), myatoms.getPosition(1) );
148 0 : const double value=sqrt(distance[myc1]*distance[myc1] + distance[myc2]*distance[myc2] );
149 0 : const double invvalue=1.0/value;
150 :
151 0 : Vector myvec; myvec.zero();
152 : // And finish the calculation
153 0 : myvec[myc1]=+invvalue*distance[myc1]; myvec[myc2]=+invvalue*distance[myc2]; addAtomDerivatives( 1, 1, myvec, myatoms );
154 0 : myvec[myc1]=-invvalue*distance[myc1]; myvec[myc2]=-invvalue*distance[myc2]; addAtomDerivatives( 1, 0, myvec, myatoms );
155 0 : myatoms.addBoxDerivatives( 1, Tensor(distance,myvec) );
156 0 : return value;
157 : }
158 :
159 : }
160 2523 : }
161 :
|