Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-2020 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 "Colvar.h" 23 : #include "ActionRegister.h" 24 : 25 : #include <string> 26 : #include <cmath> 27 : 28 : using namespace std; 29 : 30 : namespace PLMD { 31 : namespace colvar { 32 : 33 : //+PLUMEDOC COLVAR TEMPLATE 34 : /* 35 : This file provides a template for if you want to introduce a new CV. 36 : 37 : <!-----You should add a description of your CV here----> 38 : 39 : \par Examples 40 : 41 : <!---You should put an example of how to use your CV here---> 42 : 43 : \plumedfile 44 : # This should be a sample input. 45 : t: TEMPLATE ATOMS=1,2 46 : PRINT ARG=t STRIDE=100 FILE=COLVAR 47 : \endplumedfile 48 : <!---You should reference here the other actions used in this example---> 49 : (see also \ref PRINT) 50 : 51 : */ 52 : //+ENDPLUMEDOC 53 : 54 0 : class Template : public Colvar { 55 : bool pbc; 56 : 57 : public: 58 : explicit Template(const ActionOptions&); 59 : // active methods: 60 : virtual void calculate(); 61 : static void registerKeywords(Keywords& keys); 62 : }; 63 : 64 7356 : PLUMED_REGISTER_ACTION(Template,"TEMPLATE") 65 : 66 1 : void Template::registerKeywords(Keywords& keys) { 67 1 : Colvar::registerKeywords(keys); 68 3 : keys.addFlag("TEMPLATE_DEFAULT_OFF_FLAG",false,"flags that are by default not performed should be specified like this"); 69 3 : keys.addFlag("TEMPLATE_DEFAULT_ON_FLAG",true,"flags that are by default performed should be specified like this"); 70 4 : keys.add("compulsory","TEMPLATE_COMPULSORY","all compulsory keywords should be added like this with a description here"); 71 4 : keys.add("optional","TEMPLATE_OPTIONAL","all optional keywords that have input should be added like a description here"); 72 4 : keys.add("atoms","ATOMS","the keyword with which you specify what atoms to use should be added like this"); 73 1 : } 74 : 75 0 : Template::Template(const ActionOptions&ao): 76 : PLUMED_COLVAR_INIT(ao), 77 0 : pbc(true) 78 : { 79 : vector<AtomNumber> atoms; 80 0 : parseAtomList("ATOMS",atoms); 81 0 : if(atoms.size()!=2) 82 0 : error("Number of specified atoms should be 2"); 83 0 : bool nopbc=!pbc; 84 0 : parseFlag("NOPBC",nopbc); 85 0 : pbc=!nopbc; 86 0 : checkRead(); 87 : 88 0 : log.printf(" between atoms %d %d\n",atoms[0].serial(),atoms[1].serial()); 89 0 : if(pbc) log.printf(" using periodic boundary conditions\n"); 90 0 : else log.printf(" without periodic boundary conditions\n"); 91 : 92 0 : addValueWithDerivatives(); setNotPeriodic(); 93 : 94 0 : requestAtoms(atoms); 95 0 : } 96 : 97 : 98 : // calculator 99 0 : void Template::calculate() { 100 : 101 0 : Vector distance; 102 0 : if(pbc) { 103 0 : distance=pbcDistance(getPosition(0),getPosition(1)); 104 : } else { 105 0 : distance=delta(getPosition(0),getPosition(1)); 106 : } 107 0 : const double value=distance.modulo(); 108 0 : const double invvalue=1.0/value; 109 : 110 0 : setAtomsDerivatives(0,-invvalue*distance); 111 0 : setAtomsDerivatives(1,invvalue*distance); 112 0 : setBoxDerivatives (-invvalue*Tensor(distance,distance)); 113 0 : setValue (value); 114 0 : } 115 : 116 : } 117 5517 : } 118 : 119 : 120 :