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 "core/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 : The descrition of the CV that you include here will appear in the further details and examples 33 : section of the manual 34 : 35 : You can (and should) include examples showing how to use your CV as follows: 36 : 37 : ```plumed 38 : # This should be a sample input. 39 : t: TEMPLATE ATOMS=1,2 40 : PRINT ARG=t STRIDE=100 FILE=COLVAR 41 : ``` 42 : 43 : */ 44 : //+ENDPLUMEDOC 45 : 46 : class Template : public Colvar { 47 : bool pbc; 48 : 49 : public: 50 : explicit Template(const ActionOptions&); 51 : // active methods: 52 : void calculate() override; 53 : static void registerKeywords(Keywords& keys); 54 : }; 55 : 56 : PLUMED_REGISTER_ACTION(Template,"TEMPLATE") 57 : 58 2 : void Template::registerKeywords(Keywords& keys) { 59 2 : Colvar::registerKeywords(keys); 60 2 : keys.addFlag("TEMPLATE_DEFAULT_OFF_FLAG",false,"flags that are by default not performed should be specified like this"); 61 2 : keys.add("compulsory","TEMPLATE_COMPULSORY","all compulsory keywords should be added like this with a description here"); 62 2 : keys.add("optional","TEMPLATE_OPTIONAL","all optional keywords that have input should be added like a description here"); 63 2 : keys.add("atoms","ATOMS","the keyword with which you specify what atoms to use should be added like this"); 64 4 : keys.setValueDescription("scalar","a description of the value that is computed by this colvar should be included here"); 65 2 : } 66 : 67 0 : Template::Template(const ActionOptions&ao): 68 : PLUMED_COLVAR_INIT(ao), 69 0 : pbc(true) { 70 : std::vector<AtomNumber> atoms; 71 0 : parseAtomList("ATOMS",atoms); 72 0 : if(atoms.size()!=2) { 73 0 : error("Number of specified atoms should be 2"); 74 : } 75 0 : bool nopbc=!pbc; 76 0 : parseFlag("NOPBC",nopbc); 77 0 : pbc=!nopbc; 78 0 : checkRead(); 79 : 80 0 : log.printf(" between atoms %d %d\n",atoms[0].serial(),atoms[1].serial()); 81 0 : if(pbc) { 82 0 : log.printf(" using periodic boundary conditions\n"); 83 : } else { 84 0 : log.printf(" without periodic boundary conditions\n"); 85 : } 86 : 87 0 : addValueWithDerivatives(); 88 0 : setNotPeriodic(); 89 : 90 0 : requestAtoms(atoms); 91 0 : } 92 : 93 : 94 : // calculator 95 0 : void Template::calculate() { 96 : 97 0 : Vector distance; 98 0 : if(pbc) { 99 0 : distance=pbcDistance(getPosition(0),getPosition(1)); 100 : } else { 101 0 : distance=delta(getPosition(0),getPosition(1)); 102 : } 103 0 : const double value=distance.modulo(); 104 0 : const double invvalue=1.0/value; 105 : 106 0 : setAtomsDerivatives(0,-invvalue*distance); 107 0 : setAtomsDerivatives(1,invvalue*distance); 108 0 : setBoxDerivatives (-invvalue*Tensor(distance,distance)); 109 0 : setValue (value); 110 0 : } 111 : 112 : } 113 : } 114 : 115 : 116 :