Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-2017 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 "MultiColvarShortcuts.h" 23 : #include "core/ActionShortcut.h" 24 : #include "core/ActionRegister.h" 25 : #include "tools/Pbc.h" 26 : 27 : #include <string> 28 : #include <cmath> 29 : 30 : //+PLUMEDOC MCOLVAR PLANES 31 : /* 32 : Calculate the components of the normal to the plane containing three atoms 33 : 34 : \par Examples 35 : 36 : */ 37 : //+ENDPLUMEDOC 38 : 39 : namespace PLMD { 40 : namespace multicolvar { 41 : 42 : class PlaneShortcut : public ActionShortcut { 43 : private: 44 : void createVectorNormInput( const std::string& ilab, const std::string& olab, const std::string& vlab ); 45 : public: 46 : static void registerKeywords( Keywords& keys ); 47 : PlaneShortcut(const ActionOptions&); 48 : }; 49 : 50 : PLUMED_REGISTER_ACTION(PlaneShortcut,"PLANES") 51 : 52 3 : void PlaneShortcut::registerKeywords( Keywords& keys ) { 53 3 : ActionShortcut::registerKeywords( keys ); 54 3 : MultiColvarShortcuts::shortcutKeywords( keys ); 55 6 : keys.add("numbered","ATOMS","the sets of atoms that you would like to calculate the planes for"); 56 6 : keys.add("numbered","LOCATION","the location at which the CV is assumed to be in space"); 57 6 : keys.reset_style("LOCATION","atoms"); 58 6 : keys.addFlag("VMEAN",false,"calculate the norm of the mean vector."); 59 6 : keys.addOutputComponent("_vmean","VMEAN","the norm of the mean vector"); 60 6 : keys.addFlag("VSUM",false,"calculate the norm of the sum of all the vectors"); 61 6 : keys.addOutputComponent("_vsum","VSUM","the norm of the mean vector"); 62 3 : keys.needsAction("CENTER"); 63 3 : keys.needsAction("GROUP"); 64 3 : keys.needsAction("PLANE"); 65 3 : keys.needsAction("MEAN"); 66 3 : keys.needsAction("SUM"); 67 3 : keys.needsAction("COMBINE"); 68 3 : keys.needsAction("CUSTOM"); 69 3 : } 70 : 71 1 : PlaneShortcut::PlaneShortcut(const ActionOptions&ao): 72 : Action(ao), 73 1 : ActionShortcut(ao) { 74 : bool vmean, vsum; 75 1 : parseFlag("VMEAN",vmean); 76 2 : parseFlag("VSUM",vsum); 77 : std::string dline; 78 1 : std::string grpstr = getShortcutLabel() + "_grp: GROUP ATOMS="; 79 1 : for(unsigned i=1;; ++i) { 80 : std::string atstring; 81 18 : parseNumbered("ATOMS",i,atstring); 82 9 : if( atstring.length()==0 ) { 83 : break; 84 : } 85 : std::string locstr; 86 16 : parseNumbered("LOCATION",i,locstr); 87 8 : if( locstr.length()==0 ) { 88 : std::string num; 89 8 : Tools::convert( i, num ); 90 16 : readInputLine( getShortcutLabel() + "_vatom" + num + ": CENTER ATOMS=" + atstring ); 91 8 : if( i==1 ) { 92 2 : grpstr += getShortcutLabel() + "_vatom" + num; 93 : } else { 94 14 : grpstr += "," + getShortcutLabel() + "_vatom" + num; 95 : } 96 : } else { 97 0 : if( i==1 ) { 98 : grpstr += locstr; 99 : } else { 100 0 : grpstr += "," + locstr; 101 : } 102 : } 103 : std::string num; 104 8 : Tools::convert( i, num ); 105 16 : dline += " ATOMS" + num + "=" + atstring; 106 8 : } 107 1 : readInputLine( grpstr ); 108 2 : readInputLine( getShortcutLabel() + ": PLANE " + dline + " " + convertInputLineToString() ); 109 1 : if( vmean ) { 110 2 : readInputLine( getShortcutLabel() + "_xs: MEAN ARG=" + getShortcutLabel() + ".x PERIODIC=NO"); 111 2 : readInputLine( getShortcutLabel() + "_ys: MEAN ARG=" + getShortcutLabel() + ".y PERIODIC=NO"); 112 2 : readInputLine( getShortcutLabel() + "_zs: MEAN ARG=" + getShortcutLabel() + ".z PERIODIC=NO"); 113 : // Now calculate the total length of the vector 114 2 : createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vmean", "s" ); 115 : } 116 1 : if( vsum ) { 117 0 : readInputLine( getShortcutLabel() + "_xz: SUM ARG=" + getShortcutLabel() + ".x PERIODIC=NO"); 118 0 : readInputLine( getShortcutLabel() + "_yz: SUM ARG=" + getShortcutLabel() + ".y PERIODIC=NO"); 119 0 : readInputLine( getShortcutLabel() + "_zz: SUM ARG=" + getShortcutLabel() + ".z PERIODIC=NO"); 120 : // Now calculate the total length of the vector 121 0 : createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vsum", "z" ); 122 : } 123 1 : } 124 : 125 1 : void PlaneShortcut::createVectorNormInput( const std::string& ilab, const std::string& olab, const std::string& vlab ) { 126 2 : readInputLine( olab + "2: COMBINE ARG=" + ilab + "_x" + vlab + "," + ilab + "_y" + vlab + "," + ilab + "_z" + vlab + " POWERS=2,2,2 PERIODIC=NO"); 127 2 : readInputLine( olab + ": CUSTOM ARG=" + olab + "2 FUNC=sqrt(x) PERIODIC=NO"); 128 1 : } 129 : 130 : } 131 : } 132 : 133 : 134 :