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 : 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 34 : orientation of a vector, $\mathbf{n}$. The perpendicular distance between this vector and the position of some third atom is then computed using: 35 : 36 : $$ 37 : x_j = |\mathbf{r}_{j}| \sin (\theta_j) 38 : $$ 39 : 40 : 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$ 41 : 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. 42 : 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. 43 : 44 : The following input can be used to calculate the number of atoms that have indices greater than 3 and less than 101 that 45 : 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. 46 : 47 : ```plumed 48 : d1: INPLANEDISTANCES VECTORSTART=1 VECTOREND=2 GROUP=3-100 LESS_THAN={RATIONAL D_0=0.2 R_0=0.1} 49 : PRINT ARG=d1.lessthan FILE=colvar 50 : ``` 51 : 52 : 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. 53 : 54 : */ 55 : //+ENDPLUMEDOC 56 : 57 : namespace PLMD { 58 : namespace multicolvar { 59 : 60 : class InPlaneDistances : public ActionShortcut { 61 : public: 62 : explicit InPlaneDistances(const ActionOptions&); 63 : static void registerKeywords( Keywords& keys ); 64 : }; 65 : 66 : PLUMED_REGISTER_ACTION(InPlaneDistances,"INPLANEDISTANCES") 67 : 68 3 : void InPlaneDistances::registerKeywords( Keywords& keys ) { 69 3 : ActionShortcut::registerKeywords( keys ); 70 3 : keys.add("atoms","GROUP","calculate distance for each distinct set of three atoms in the group"); 71 3 : keys.add("atoms","VECTORSTART","The first atom position that is used to define the normal to the plane of interest"); 72 3 : keys.add("atoms","VECTOREND","The second atom position that is used to defin the normal to the plane of interest"); 73 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"); 74 3 : MultiColvarShortcuts::shortcutKeywords( keys ); 75 3 : keys.needsAction("DISTANCE"); 76 3 : keys.needsAction("ANGLE"); 77 3 : } 78 : 79 1 : InPlaneDistances::InPlaneDistances(const ActionOptions&ao): 80 : Action(ao), 81 1 : ActionShortcut(ao) { 82 : std::vector<std::string> str_atomsA; 83 1 : parseVector("VECTORSTART",str_atomsA); 84 1 : Tools::interpretRanges( str_atomsA ); 85 : std::vector<std::string> str_atomsB; 86 1 : parseVector("VECTOREND",str_atomsB); 87 1 : Tools::interpretRanges( str_atomsB ); 88 : std::vector<std::string> str_atomsC; 89 1 : parseVector("GROUP",str_atomsC); 90 1 : Tools::interpretRanges( str_atomsC ); 91 1 : unsigned n=1; 92 1 : std::string dinput= getShortcutLabel() + "_dis: DISTANCE", ainput = getShortcutLabel() + "_ang: ANGLE"; 93 2 : for(unsigned i=0; i<str_atomsA.size(); ++i ) { 94 2 : for(unsigned j=0; j<str_atomsB.size(); ++j ) { 95 9 : for(unsigned k=0; k<str_atomsC.size(); ++k) { 96 : std::string str_n; 97 8 : Tools::convert( n, str_n ); 98 8 : n++; 99 16 : dinput += " ATOMS" + str_n + "=" + str_atomsA[j] + "," + str_atomsC[k]; 100 16 : ainput += " ATOMS" + str_n + "=" + str_atomsB[j] + "," + str_atomsA[i] + "," + str_atomsC[k]; 101 : } 102 : } 103 : } 104 1 : readInputLine( dinput ); 105 1 : readInputLine( ainput ); 106 2 : readInputLine( getShortcutLabel() + ": CUSTOM PERIODIC=NO FUNC=x*sin(y) ARG=" + getShortcutLabel() + "_dis," + getShortcutLabel() + "_ang"); 107 2 : MultiColvarShortcuts::expandFunctions( getShortcutLabel(), getShortcutLabel(), "", this ); 108 1 : } 109 : 110 : } 111 : }