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