Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2015-2023 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 "core/ActionShortcut.h" 23 : #include "core/ActionRegister.h" 24 : #include "MultiColvarShortcuts.h" 25 : 26 : #include <string> 27 : #include <cmath> 28 : 29 : //+PLUMEDOC MCOLVAR INPLANEDISTANCES 30 : /* 31 : Calculate distances in the plane perpendicular to an axis 32 : 33 : __As you can see if you expand the inputs below, you can achieve what this shortcut action does by using [DISTANCE](DISTANCE.md) and [ANGLE](ANGLE.md) together with [CUSTOM](CUSTOM.md), 34 : [BETWEEN](BETWEEN.md), [LESS_THAN](LESS_THAN.md), [SUM](SUM.md) and [MEAN](MEAN.md). We strongly encourage you to use these actions instead as using them will provide 35 : you with a clearer understanding of the equations you are using.__ 36 : 37 : Each quantity calculated in this CV uses the positions of two atoms, this indices of which are specified using the VECTORSTART and VECTOREND keywords, to specify the 38 : orientation of a vector, $\mathbf{n}$. The perpendicular distance between this vector and the position of some third atom is then computed using: 39 : 40 : $$ 41 : x_j = |\mathbf{r}_{j}| \sin (\theta_j) 42 : $$ 43 : 44 : where $\mathbf{r}_j$ is the distance between one of the two atoms that define the vector $\mathbf{n}$ and a third atom (atom $j$) and where $\theta_j$ 45 : is the angle between the vector \f$\mathbf{n}\f$ and the vector $\mathbf{r}_{j}$. The $x_j$ values for each of the atoms specified using the GROUP keyword are calculated. 46 : Keywords such as MORE_THAN and LESS_THAN can then be used to calculate the number of these quantities that are more or less than a given cutoff. 47 : 48 : The following input can be used to calculate the number of atoms that have indices greater than 3 and less than 101 that 49 : are within a cylinder with a radius of 0.3 nm that has its long axis aligned with the vector connecting atoms 1 and 2. 50 : 51 : ```plumed 52 : d1: INPLANEDISTANCES VECTORSTART=1 VECTOREND=2 GROUP=3-100 LESS_THAN={RATIONAL D_0=0.2 R_0=0.1} 53 : PRINT ARG=d1.lessthan FILE=colvar 54 : ``` 55 : 56 : Notice that the INPLANEDISTANCES is a shortcut. The syntax that is described in the expanded version of the input above provides much more flexibility for designing new CVs. 57 : 58 : */ 59 : //+ENDPLUMEDOC 60 : 61 : namespace PLMD { 62 : namespace multicolvar { 63 : 64 : class InPlaneDistances : public ActionShortcut { 65 : public: 66 : explicit InPlaneDistances(const ActionOptions&); 67 : static void registerKeywords( Keywords& keys ); 68 : }; 69 : 70 : PLUMED_REGISTER_ACTION(InPlaneDistances,"INPLANEDISTANCES") 71 : 72 3 : void InPlaneDistances::registerKeywords( Keywords& keys ) { 73 3 : ActionShortcut::registerKeywords( keys ); 74 3 : keys.add("atoms","GROUP","calculate distance for each distinct set of three atoms in the group"); 75 3 : keys.add("atoms","VECTORSTART","The first atom position that is used to define the normal to the plane of interest"); 76 3 : keys.add("atoms","VECTOREND","The second atom position that is used to defin the normal to the plane of interest"); 77 6 : keys.setValueDescription("vector","the INPLANEDISTANCE between each of the atoms specified using the GROUP keyword and atom A in the plane perpendicular to the vector connecting the atoms specified using VECTORSTART and VECTOREND"); 78 3 : MultiColvarShortcuts::shortcutKeywords( keys ); 79 3 : keys.needsAction("DISTANCE"); 80 3 : keys.needsAction("ANGLE"); 81 3 : keys.setDeprecated("DISTANCE"); 82 3 : } 83 : 84 1 : InPlaneDistances::InPlaneDistances(const ActionOptions&ao): 85 : Action(ao), 86 1 : ActionShortcut(ao) { 87 : std::vector<std::string> str_atomsA; 88 1 : parseVector("VECTORSTART",str_atomsA); 89 1 : Tools::interpretRanges( str_atomsA ); 90 : std::vector<std::string> str_atomsB; 91 1 : parseVector("VECTOREND",str_atomsB); 92 1 : Tools::interpretRanges( str_atomsB ); 93 : std::vector<std::string> str_atomsC; 94 1 : parseVector("GROUP",str_atomsC); 95 1 : Tools::interpretRanges( str_atomsC ); 96 1 : unsigned n=1; 97 1 : std::string dinput= getShortcutLabel() + "_dis: DISTANCE", ainput = getShortcutLabel() + "_ang: ANGLE"; 98 2 : for(unsigned i=0; i<str_atomsA.size(); ++i ) { 99 2 : for(unsigned j=0; j<str_atomsB.size(); ++j ) { 100 9 : for(unsigned k=0; k<str_atomsC.size(); ++k) { 101 : std::string str_n; 102 8 : Tools::convert( n, str_n ); 103 8 : n++; 104 16 : dinput += " ATOMS" + str_n + "=" + str_atomsA[j] + "," + str_atomsC[k]; 105 16 : ainput += " ATOMS" + str_n + "=" + str_atomsB[j] + "," + str_atomsA[i] + "," + str_atomsC[k]; 106 : } 107 : } 108 : } 109 1 : readInputLine( dinput ); 110 1 : readInputLine( ainput ); 111 2 : readInputLine( getShortcutLabel() + ": CUSTOM PERIODIC=NO FUNC=x*sin(y) ARG=" + getShortcutLabel() + "_dis," + getShortcutLabel() + "_ang"); 112 2 : MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel(), "", this ); 113 1 : } 114 : 115 : } 116 : }