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 9 : keys.needsAction("CENTER"); keys.needsAction("GROUP"); keys.needsAction("PLANE"); 63 12 : keys.needsAction("MEAN"); keys.needsAction("SUM"); keys.needsAction("COMBINE"); keys.needsAction("CUSTOM"); 64 3 : } 65 : 66 1 : PlaneShortcut::PlaneShortcut(const ActionOptions&ao): 67 : Action(ao), 68 1 : ActionShortcut(ao) 69 : { 70 3 : bool vmean, vsum; parseFlag("VMEAN",vmean); parseFlag("VSUM",vsum); std::string dline; 71 1 : std::string grpstr = getShortcutLabel() + "_grp: GROUP ATOMS="; 72 1 : for(unsigned i=1;; ++i) { 73 18 : std::string atstring; parseNumbered("ATOMS",i,atstring); 74 9 : if( atstring.length()==0 ) break; 75 16 : std::string locstr; parseNumbered("LOCATION",i,locstr); 76 8 : if( locstr.length()==0 ) { 77 8 : std::string num; Tools::convert( i, num ); 78 16 : readInputLine( getShortcutLabel() + "_vatom" + num + ": CENTER ATOMS=" + atstring ); 79 16 : if( i==1 ) grpstr += getShortcutLabel() + "_vatom" + num; else grpstr += "," + getShortcutLabel() + "_vatom" + num; 80 : } else { 81 0 : if( i==1 ) grpstr += locstr; else grpstr += "," + locstr; 82 : } 83 8 : std::string num; Tools::convert( i, num ); 84 16 : dline += " ATOMS" + num + "=" + atstring; 85 8 : } 86 2 : readInputLine( grpstr ); readInputLine( getShortcutLabel() + ": PLANE " + dline + " " + convertInputLineToString() ); 87 1 : if( vmean ) { 88 2 : readInputLine( getShortcutLabel() + "_xs: MEAN ARG=" + getShortcutLabel() + ".x PERIODIC=NO"); 89 2 : readInputLine( getShortcutLabel() + "_ys: MEAN ARG=" + getShortcutLabel() + ".y PERIODIC=NO"); 90 2 : readInputLine( getShortcutLabel() + "_zs: MEAN ARG=" + getShortcutLabel() + ".z PERIODIC=NO"); 91 : // Now calculate the total length of the vector 92 2 : createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vmean", "s" ); 93 : } 94 1 : if( vsum ) { 95 0 : readInputLine( getShortcutLabel() + "_xz: SUM ARG=" + getShortcutLabel() + ".x PERIODIC=NO"); 96 0 : readInputLine( getShortcutLabel() + "_yz: SUM ARG=" + getShortcutLabel() + ".y PERIODIC=NO"); 97 0 : readInputLine( getShortcutLabel() + "_zz: SUM ARG=" + getShortcutLabel() + ".z PERIODIC=NO"); 98 : // Now calculate the total length of the vector 99 0 : createVectorNormInput( getShortcutLabel(), getShortcutLabel() + "_vsum", "z" ); 100 : } 101 1 : } 102 : 103 1 : void PlaneShortcut::createVectorNormInput( const std::string& ilab, const std::string& olab, const std::string& vlab ) { 104 2 : readInputLine( olab + "2: COMBINE ARG=" + ilab + "_x" + vlab + "," + ilab + "_y" + vlab + "," + ilab + "_z" + vlab + " POWERS=2,2,2 PERIODIC=NO"); 105 2 : readInputLine( olab + ": CUSTOM ARG=" + olab + "2 FUNC=sqrt(x) PERIODIC=NO"); 106 1 : } 107 : 108 : } 109 : } 110 : 111 : 112 :