Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2012-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 "core/ActionSetup.h" 23 : #include "core/ActionRegister.h" 24 : #include "core/PlumedMain.h" 25 : #include "tools/Exception.h" 26 : 27 : namespace PLMD { 28 : namespace setup { 29 : 30 : //+PLUMEDOC GENERIC LOAD 31 : /* 32 : Loads a library, possibly defining new actions. 33 : 34 : It is available only 35 : on systems allowing for dynamic loading. It can also be fed with a cpp file, 36 : in which case the file is compiled first. 37 : 38 : \par Examples 39 : 40 : If you have a shared object named extensions.so and want to 41 : use the functions implemented within it within PLUMED you can 42 : load it with the following syntax 43 : 44 : \plumedfile 45 : LOAD FILE=extensions.so 46 : \endplumedfile 47 : 48 : As a more practical example, imagine that you want to make a 49 : small change to one collective variable that is already implemented 50 : in PLUMED, say \ref DISTANCE . Copy the file `src/colvar/Distance.cpp` 51 : into your work directory, rename it as `Distance2.cpp` 52 : and edit it as you wish. It might be better 53 : to also replace any occurrence of the string DISTANCE within the file 54 : with DISTANCE2, so that both old and new implementation will be available 55 : with different names. Then you can compile it into a shared object using 56 : \verbatim 57 : > plumed mklib Distance2.cpp 58 : \endverbatim 59 : This will generate a file `Distance2.so` (or `Distance2.dylib` on a mac) 60 : that can be loaded. 61 : Now you can use your new implementation with the following input 62 : \plumedfile 63 : # load the new library 64 : LOAD FILE=Distance2.so 65 : # compute standard distance 66 : d: DISTANCE ATOMS=1,10 67 : # compute modified distance 68 : d2: DISTANCE2 ATOMS=1,10 69 : # print them on a file 70 : PRINT ARG=d,d2 FILE=compare-them 71 : \endplumedfile 72 : 73 : You can even skip the initial step and directly feed PLUMED 74 : with the `Distance2.cpp` file: it will be compiled on the fly. 75 : \plumedfile 76 : # load the new definition 77 : # this is a cpp file so it will be compiled 78 : LOAD FILE=Distance2.cpp 79 : # compute standard distance 80 : d: DISTANCE ATOMS=1,10 81 : # compute modified distance 82 : d2: DISTANCE2 ATOMS=1,10 83 : # print them on a file 84 : PRINT ARG=d,d2 FILE=compare-them 85 : \endplumedfile 86 : 87 : This will allow to make quick tests while developing your own 88 : variables. Of course, after your implementation is ready you might 89 : want to add it to the PLUMED source tree and recompile 90 : the whole PLUMED. 91 : 92 : 93 : */ 94 : //+ENDPLUMEDOC 95 : 96 : class Load : 97 : public virtual ActionSetup 98 : { 99 : public: 100 : static void registerKeywords( Keywords& keys ); 101 : explicit Load(const ActionOptions&ao); 102 : }; 103 : 104 10422 : PLUMED_REGISTER_ACTION(Load,"LOAD") 105 : 106 3 : void Load::registerKeywords( Keywords& keys ) { 107 3 : ActionSetup::registerKeywords(keys); 108 6 : keys.add("compulsory","FILE","file to be loaded"); 109 3 : } 110 : 111 2 : Load::Load(const ActionOptions&ao): 112 : Action(ao), 113 2 : ActionSetup(ao) 114 : { 115 : std::string f; 116 3 : parse("FILE",f); 117 2 : checkRead(); 118 2 : plumed.load(f); 119 2 : } 120 : 121 : } 122 : } 123 :