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