1\page Installation Installation
2
3In this page you can learn how to
4\link ConfiguringPlumed configure\endlink,
5\link CompilingPlumed compile\endlink,
6and \link InstallingPlumed install\endlink
7PLUMED.
8For those of you who are impatient, the following might do the job:
9\verbatim
10> ./configure --prefix=/usr/local
11> make -j 4
12> make doc # this is optional and requires proper doxygen version installed
13> make install
14\endverbatim
15Notice that `make install` is not strictly necessary  as plumed can be used from the compilation
16directory. This is very useful so as to quickly test the implementation of new features.
17However, we strongly recommend to perform a full install.
18
19Once the above is completed the `plumed` executable should be in your execution path
20and you will be able to use PLUMED to analyze
21existing trajectories or play with the Lennard-Jones code that is included.
22However, because PLUMED is mostly used to bias on the fly simulations
23performed with serious molecular dynamics packages,
24you can find instructions about how to
25\link Patching patch \endlink
26your favorite MD code so that it can be combined with PLUMED below.
27Again, if you are impatient, something like this will do the job:
28\verbatim
29> cd /md/root/dir
30> plumed patch -p
31\endverbatim
32Then compile your MD code.
33For some MD codes these instructions are insufficient.
34It is thus recommended that you read the instructions
35at the end of this page.
36Notice that MD codes could in principle be "PLUMED ready"
37in their official distribution. If your favorite MD code is available "PLUMED ready"
38you will have to compile PLUMED first, then (optionally) install it, then check the MD codes' manual to
39discover how to link it.
40
41\section SupportedCompilers Supported compilers
42
43As of PLUMED 2.4, we require a compiler that supports C++11. The following compilers
44(or later versions) should be sufficient:
45
46- gcc 4.8.1
47- clang 3.3
48- intel 15
49
50Notice that the `./configure` script verifies that your compiler supports C++11.
51Some compilers do not declare full support, but implement anyway a number of C++11 features
52sufficient to compile PLUMED (this is the case for instance of intel 15 compiler).
53In case you see a warning about C++11 support during `./configure`
54please make sure that PLUMED compiles correctly and, if possible, execute the regtests
55(using `make regtest`). Notice that we regularly test a number of compilers on travis-ci,
56and at least those compilers are guaranteed to be able to compile PLUMED correctly.
57
58\section ConfiguringPlumed Configuring PLUMED
59
60The `./configure` command
61just generates a Makefile.conf file and a sourceme.sh file.
62In PLUMED 2.0 these files were prepared and stored in the
63directory configurations/. The new ones generated by ./configure
64are similar to the old ones but are not completely compatible.
65In particular, some of the -D options have been changed in version 2.2,
66and several new variables so as  to specify the installation directories have been added. For this reason,
67you now should run `./configure` again.
68Anyway, it should be easy to enforce a similar setup with autoconf by passing
69the proper arguments on the command line.
70If you have problems on your architecture, please
71report them to the mailing list.
72
73Useful command line options for ./configure can be found by typing
74\verbatim
75> ./configure --help
76\endverbatim
77PLUMED is made up of modules. Some of them are on by default, some others aren't.
78Since version 2.3, the activation of modules should be made during configuration using the `--enable-modules`
79option (see \ref mymodules).
80
81Notice that some of the methods within PLUMED depend on external
82libraries which are looked for by configure. You can typically
83avoid looking for a library using the "disable" syntax, e.g.
84\verbatim
85> ./configure --disable-mpi --disable-xdrfile
86\endverbatim
87
88Notice that when MPI search is enabled (by default) compilers
89such as "mpic++" and "mpicxx" are searched for first. On the other hand,
90if MPI search is disabled ("./configure --disable-mpi") non-mpi
91compilers are searched for. Notice that only a few of the
92possible compiler name are searched. Thus, compilers such as
93"g++-mp-4.8" should be explicitly requested with the CXX option.
94
95You can better control which compiler is used by setting the
96variables CXX and CC. E.g., to use Intel compilers use the following command:
97\verbatim
98> ./configure CXX=icpc CC=icc
99\endverbatim
100Notice that we are using icpc in this example, which is not an MPI compiler as a
101result MPI will not be enabled. Also consider that this is different with respect
102to what some other configure script does in that variables such as MPICXX are
103completely ignored here. In case you work on a machine where CXX is
104set to a serial compiler and MPICXX to a MPI compiler, to
105compile with MPI you should use
106\verbatim
107> ./configure CXX="$MPICXX"
108\endverbatim
109
110\warning
111This procedure could be somehow confusing since many other programs behave in a different way.
112The flag `--enable-mpi` is perfectly valid but is not needed here.
113Autoconf will check if a code containing MPI calls can be compiled,
114and if so it will enable it. `--disable-mpi` could be used if you are
115using a compiler that supports MPI but you don't want PLUMED to  be compiled
116with MPI support. Thus the correct way to enable MPI is to pass
117to ./configure  the name of a C++ compiler that implements MPI using the CXX option.
118In this way, MPI library is treated similarly to all the other libraries
119that PLUMED tries to link by default.
120
121To tune the compilation options you can use the CXXFLAGS variable:
122\verbatim
123> ./configure CXXFLAGS=-O3
124\endverbatim
125
126If you are implementing new functionality and want to build with debug flags
127in place so as to do some checking you can use
128\verbatim
129> ./configure --enable-debug
130\endverbatim
131This will perform some extra check during execution (possibly slowing down PLUMED)
132and write full symbol tables in the executable (making the final executable  much larger).
133
134The main goal of the automatic configure is to find the libraries.
135When they are stored in unconventional places it is thus sensible to tell autoconf where
136to look! To do this there are some environment variable that can be used to instruct the linker
137which directories it should search for libraries inside. These variables are compiler dependent,
138but could have been set by the system administrator so that libraries are found
139without any extra flag. Our suggested procedure is to
140first try to configure without any additional flags and to then check the log so as to see whether
141or not the libraries were properly detected.
142
143If a library is not found during configuration, you can try to use options to modify the
144search path.
145For example if your xdrfile libraries is in /opt/local (this is where MacPorts put it)
146and configure is not able to find it you can try
147\verbatim
148> ./configure LDFLAGS=-L/opt/local/lib CPPFLAGS=-I/opt/local/include
149\endverbatim
150Notice that PLUMED will first try to link a routine from say xdrfile
151without any additional flag, and then in case of failure will retry adding
152"-lxdrfile" to the LIBS options.
153If also this does not work, the xdrfile library will be
154disabled and some features will not be available.
155This procedure allows you to use libraries
156with custom names. So, if
157your xdrfile library is called /opt/local/lib/libmyxdrfile.so you can
158link it with
159\verbatim
160> ./configure LDFLAGS=-L/opt/local/lib CPPFLAGS=-I/opt/local/include LIBS=-lmyxdrfile
161\endverbatim
162In this example, the linker will directly try to link `/opt/local/lib/libmyxdrfile.so`.
163This rule is true for all the libraries, so that you will always be able to link
164a specific version of a library by specifying it using the LIBS variable.
165
166Since version 2.3.2, the search for the library functions passing to the linker a flag with the standard library name (in the xdrfile example,
167it would be `-lxdrfile`) can be skipped by using the option `--disable-libsearch`.
168Notice that in this manner only libraries that are explicitly passed using the `LIBS` option will be linked. For instance
169\verbatim
170> ./configure --disable-libsearch LIBS=-lxdrfile
171\endverbatim
172will make sure that only xdrfile is linked and, for instance, BLAS and LAPACK libraries are not.
173This might be useful when installing PLUMED within package managers such as MacPorts to
174make sure that only desired libraries are linked and thus to avoid to introduce spurious
175dependencies. The only exception to this rule is `-ldl`, which is anyway a system library on Linux.
176
177\warning On OSX it is common practice to hard code the full path
178to libraries in the libraries themselves. This means that, after having linked
179a shared library, that specific shared library will be searched in the same
180place (we do the same for the `libplumed.dylib` library, which has an install name hard coded).
181On the other hand, on Linux it is common practice not to hard code the full path.
182This means that if you use the `LDFLAGS` option to specify the path
183to the libraries you want to link to PLUMED (e.g. `./configure LDFLAGS="-L/path"`)
184these libraries might not be found later.
185The visible symptom is that `src/lib/plumed-shared` will not be linked correctly.
186Although the file 'src/lib/plumed-shared' is not necessary, being
187able to produce it means that it will be possible to link PLUMED dynamically
188with MD codes later.
189The easiest solution is to hard code the library search path in this way:
190\verbatim
191> ./configure LDFLAGS="-L/path -Wl,-rpath,/path"
192\endverbatim
193Notice that as of PLUMED v2.4 it is possible to use the configure option `--enable-rpath`
194to automatically hard code the path defined in `LIBRARY_PATH`:
195\verbatim
196> ./configure LIBRARY_PATH=/path --enable-rpath
197\endverbatim
198In this way, the search path used at link time (`LIBRARY_PATH`) and the one saved in the `libplumed.so`
199library will be consistent by construction.
200In a typical environment configured using module framework (http://modules.sourceforge.net),
201`LIBRARY_PATH` will be a variable containing the path to all the modules loaded at compilation
202time.
203
204PLUMED needs BLAS and LAPACK. These are treated slightly different from
205other libraries. The search is done in the usual way (i.e., first
206look for them without any link flag, then add "-lblas" and "-llapack", respectively).
207As such  if you want to use a specific version of BLAS or LAPACK
208you can make them available to configure by using
209\verbatim
210> ./configure LDFLAGS=-L/path/to/blas/lib LIBS=-lnameoflib
211\endverbatim
212If the functions of these libraries are not found, the compiler
213looks for a version with a final underscore added.
214Finally, since BLAS and LAPACK are compulsory in PLUMED,
215you can use a internal version of these libraries that comes as part of PLUMED.
216If all else fails the internal version of BLAS and LAPACK are the ones that will be
217used by PLUMED.
218If you wish to disable any search for external libraries
219(e.g. because the system libraries have problems) this can be done with
220\verbatim
221> ./configure --disable-external-blas
222\endverbatim
223Notice that you can also disable external LAPACK only, that is use internal LAPACK with external BLAS
224using
225\verbatim
226> ./configure --disable-external-lapack
227\endverbatim
228Since typically it is the BLAS library that can be heavily optimized, this configuration
229should not provide significant slowing down and could be used on systems where
230native LAPACK libraries have problems.
231
232
233As a final resort, you can also edit the resulting Makefile.conf file.
234Notable variables in this file include:
235- DYNAMIC_LIB : these are the libraries needed to compile the PLUMED
236library (e.g. -L/path/to/xdrfile -lxdrfile etc). Notice that for the
237PLUMED shared library to be compiled properly these should be dynamic
238libraries. Also notice that PLUMED preferentially requires BLAS and LAPACK library;
239see \ref BlasAndLapack for further info. Notice that the variables
240that you supply with `configure LIBS=something` will end up in this
241variable. This is a bit misleading but is required to keep the configuration
242files compatible with PLUMED 2.0.
243- LIBS : these are the libraries needed when patching an MD code; typically only "-ldl" (needed to have functions for dynamic loading).
244- CPPFLAGS : add here definition needed to enable specific optional functions;
245e.g. use -D__PLUMED_HAS_XDRFILE to enable the xdrfile library
246- SOEXT : this gives the extension for shared libraries in your system, typically
247"so" on UNIX, "dylib" on mac; If your system does not support dynamic libraries or, for some other reason, you would like a static executable you can
248just set this variable to a blank ("SOEXT=").
249
250\subsection BlasAndLapack BLAS and LAPACK
251
252We tried to keep PLUMED as independent as possible from external libraries and as such those features
253that require external libraries are optional. However, to have a properly working version
254of plumed PLUMED you need BLAS and LAPACK libraries.  We would strongly recommend you download these libraries and
255install them separately so as to have the most efficient possible implementations of the functions contained within
256them.  However, if you cannot install BLAS and LAPACK, you can use the internal ones.
257Since version 2.1, PLUMED uses a configure script to detect libraries. In case system LAPACK or BLAS
258are not found on your system, PLUMED will use the internal replacement.
259
260We have had a number of emails (and have struggled ourselves) with ensuring that PLUMED
261can link BLAS and LAPACK.  The following describes some of the pitfalls that you can fall
262into and a set of sensible steps by which you can check whether or not you have set up the configuration
263correctly.
264
265Notice first of all that the DYNAMIC_LIB variable in the Makefile.conf
266should contain the flag necessary to load the BLAS and LAPACK libraries.  Typically this will be
267-llapack -lblas, in some case followed by -lgfortran.  Full path specification with -L may be necessary
268and on some machines the BLAS and LAPACK libraries may not be called -llapack and -lblas.
269Everything will depend on your system configuration.
270
271Some simple to fix further problems include:
272- If the linker complains and suggests recompiling LAPACK with -fPIC, it means that you have static LAPACK libraries. Either install dynamic LAPACK libraries
273or switch to static compilation of PLUMED by stopping to set the SOEXT variable
274in the configuration file.
275- If the linker complains about other missing functions (typically starting with
276  "for_" prefix) then you should also link some Fortran libraries. PLUMED
277  is written in C++ and often C++ linkers do not include Fortran libraries by default.
278  These libraries are required for LAPACK and BLAS to work. Please check the documentation of your compiler.
279- If the linker complains that dsyevr_ cannot be found, try adding
280  -DF77_NO_UNDERSCORE to CPPFLAGS
281  Notice that "./configure" should automatically try this solution.
282
283\subsection installation-vmdplugins VMD trajectory plugins
284
285PLUMED source code already includes a few selected VMD molfile plugins so as to read a small number
286of additional trajectory formats (e.g., dcd, gromacs files, pdb, and amber files).
287If you configure PLUMED with the full set of VMD plugins you will be able to read
288many more trajectory formats, basically all of those supported by VMD.
289To this aim,
290you need to download the SOURCE of VMD, which contains
291a plugins directory. Adapt build.sh and compile it. At
292the end, you should get the molfile plugins compiled as a static
293library `libmolfile_plugin.a`. Locate said file and `libmolfile_plugin.h`,
294they should be in a directory called `/pathtovmdplugins/ARCH/molfile`
295(e.g. `/pathtovmdplugins/MACOSXX86_64/molfile`). Also locate file `molfile_plugin.h`,
296which should be in `/pathtovmdplugins/include`.
297Then customize the configure command with something along the lines of:
298
299\verbatim
300> ./configure LDFLAGS="-L/pathtovmdplugins/ARCH/molfile" CPPFLAGS="-I/pathtovmdplugins/include -I/pathtovmdplugins/ARCH/molfile"
301\endverbatim
302
303Notice that it might be necessary to add to `LDFLAGS` the path to your TCL interpreter, e.g.
304
305\verbatim
306> ./configure LDFLAGS="-ltcl8.5 -L/mypathtotcl -L/pathtovmdplugins/ARCH/molfile" \
307            CPPFLAGS="-I/pathtovmdplugins/include -I/pathtovmdplugins/ARCH/molfile"
308\endverbatim
309
310Then, rebuild plumed.
311
312\subsection additional-modules Additional Modules
313
314PLUMED includes some additional modules that by default are not compiled, but can be enabled during configuration.
315You can use the option `--enable-modules` to activate some of them, e.g.
316
317\verbatim
318> ./configure --enable-modules=module1name+module2name
319\endverbatim
320
321For more information on modules see \ref mymodules.
322
323\section CompilingPlumed Compiling PLUMED
324
325Once configured, PLUMED can be compiled using the following command:
326\verbatim
327> make -j 4
328\endverbatim
329This will compile the entire code and produce a number of files
330in the 'src/lib' directory, including the executable
331'src/lib/plumed'. When shared libraries are enabled,
332a shared libraries called 'src/lib/libKernel.so' should also be present.
333Notice that the extension could be '.dylib' on a Mac.
334
335In case you want to run PLUMED *without installing it* (i.e. from the compilation
336directory), you can use the file 'sourceme.sh' that has been created by
337the configure script in the main PLUMED directory.
338This file can be "sourced" (presently only working for bash shell)
339if you want to use PLUMED *before installing it* (i.e. from the compilation
340directory). It is a good idea to source it now, so that you can play with the just compiled
341PLUMED:
342\verbatim
343> source sourceme.sh
344\endverbatim
345
346Now
347a "plumed" executable should be in your path. Try to type
348\verbatim
349> plumed -h
350\endverbatim
351
352\warning If you are cross compiling, the plumed executable
353will not work. As a consequence, you won't be able to run regtests
354or compile the manual. This is not a problem.
355
356You can also check if PLUMED is correctly compiled by performing our regression tests.
357Be warned that some of them fail because of the different numerical accuracy on different machines.
358As of version 2.4, in order to test the `plumed` executable that you just compiled
359(prior to installing it) you can use the following command
360\verbatim
361> make check
362\endverbatim
363On the other hand, in order to test the `plumed` executable that you just installed (see \ref InstallingPlumed)
364you should type
365\verbatim
366> make installcheck
367\endverbatim
368In addition, similarly to previous versions of PLUMED, you can test the `plumed` executable
369that is in your current path with
370\verbatim
371> cd regtest
372> make
373\endverbatim
374You can check the exact version they will use by using the command
375\verbatim
376> which plumed
377\endverbatim
378Thus, you can easily run the test suite using a different version of PLUMED
379(maybe an earlier version that you already installed), just making sure that it can be
380found in the path. Clearly, if you test a given
381version of PLUMED with a test suite from a different version you can expect two
382possible kinds of innocuous errors:
383- If `plumed` executable is older than the test suite, the tests might fail since they rely on
384  some feature introduced in PLUMED in a newer version.
385- If `plumed` executable is newer than the test suite, the tests might fail since some
386  non-backward compatible change was made in PLUMED. We try to keep the number
387  of non-backward compatible changes small, but as you can see in the \ref ChangeLog there
388  are typically a few of them at every new major release.
389
390\attention
391Even though we regularly perform tests on [Travis-CI](http://travis-ci.org/plumed/plumed2),
392it is possible that aggressive optimization or even architecture dependent features
393trigger bugs that did not show up on travis. So please always perform the regtests when you install
394PLUMED.
395
396Notice that the compiled executable, which now sits in 'src/lib/plumed', relies
397on other resource files present in the compilation directory.
398This directory should thus stay in the correct place. One should thus not
399rename or delete it. In fact the path to the PLUMED root directory is
400hard coded in the plumed executable as can be verified using
401\verbatim
402> plumed info --root
403\endverbatim
404In case you try to use the plumed executable without the compilation
405directory in place (e.g. you move away the src/lib/plumed static executable
406and delete or rename the compilation directory) PLUMED will
407not work correctly and will give you an
408error message
409\verbatim
410> plumed help
411ERROR: I cannot find /xxx/yyy/patches directory
412\endverbatim
413You can force plumed to run anyway by using the option --standalone-executable:
414\verbatim
415> plumed --standalone-executable help
416\endverbatim
417Many features will not be available if you run in this way. However,
418this is currently the only way to use the PLUMED static executable on Windows.
419
420\section InstallingPlumed Installing PLUMED
421
422It is strongly suggested to
423install PLUMED in a predefined location.
424This is done using
425\verbatim
426> make install
427\endverbatim
428This will allow you to remove the original compilation directory,
429or to recompile a different PLUMED version in the same place.
430
431To install PLUMED one should first decide the location:
432\verbatim
433> ./configure --prefix=$HOME/opt
434> make
435> make install
436\endverbatim
437As of PLUMED 2.5 you cannot anymore change the location during install.
438If you didn't specify the `--prefix` option during configure PLUMED will be installed in /usr/local.
439The install command should be executed with root permissions (e.g. "sudo make install")
440if you want to install PLUMED on a system directory.
441
442Notice that upon installation PLUMED might need to relink a library.
443This was always true until version 2.1, but in version 2.2 libraries should
444only be relinked if one changes the install prefix during when typing `make install`.
445If root user does not have access to compilers, "sudo -E make install" might solve
446the issue.
447
448Upon install, the executable is copied to $prefix/bin, libraries to $prefix/lib,
449include files to $prefix/include, and
450documentation to $prefix/shared/doc/plumed. Additionally, a directory
451$prefix/lib/plumed is created containing several other files, including
452patch files, object files (for static patches), etc.
453Notice also that these path can be further customized using standard autoconf
454directories (e.g. `./configure --bindir=/usr/bin64`).
455
456One should then set the environment properly. We suggest to do it using
457the module framework (http://modules.sourceforge.net). An ad hoc generated
458module file for PLUMED can be found in $prefix/lib/plumed/src/lib/modulefile
459Just edit it as you wish and put it in your modulefile directory.
460This will also allow you to install multiple PLUMED versions on your machine and to
461switch among them. If you do not want to use modules, you can
462still have a look at the modulefile we did so as to know which
463environment variables should be set for PLUMED to work correctly.
464
465If the environment is properly configured one should be able to do
466the following things:
467- use the "plumed" executable from the command line. This is also possible before installing.
468- link against the PLUMED library using the "-lplumed" flag for the linker. This allows
469  one to use PLUMED library in general purpose programs
470- use PLUMED internal functionality (C++ classes) including
471  header files such as "#include <plumed/tools/Vector.h>". This is useful as it may be expedient to
472  exploit the PLUMED library in general purpose programs
473
474As a final note, if you want to install several PLUMED versions without using modules then you
475should provide a different suffix and/or prefix at configure time:
476\verbatim
477> ./configure prefix=$HOME/opt --program-suffix=_2.2 --program-prefix=mpi-
478> make install
479\endverbatim
480This will install a plumed executable named "mpi-plumed_2.2". All the other files will be renamed similarly,
481e.g. the PLUMED library will be loaded with "-lmpi-plumed_2.2" and the PLUMED header files
482will be included with "#include <mpi-plumed_2.2/tools/Vector.h>".
483Notice that you can also use arbitrary scripts to edit the name of the executable
484with the option --program-transform-name=PROGRAM
485(see <a href="http://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Transformation-Examples.html#Transformation-Examples"> autoconf documentation </a> for more info).
486These options are useful if you
487do not want to set up modules, but we believe that using modules as described above is more flexible.
488
489\section Patching Patching your MD code
490
491A growing number of MD codes can use PLUMED without any modification.
492If you are using one of these codes, refer to its manual to know how to activate PLUMED.
493In case your MD code is not supporting PLUMED already, you should modify it.
494We provide scripts to adjust some of the most popular MD codes
495so as to provide PLUMED support.
496At the present times we support patching the following list of codes:
497
498@CODESL@
499
500In the section \subpage CodeSpecificNotes you can find information specific for each MD code.
501
502To patch your MD code, you should have already installed PLUMED properly.
503This is necessary as you need to have the command "plumed" in your execution
504path.  As described above this executable will be in your paths if plumed was
505installed or if you have run sourceme.sh
506
507Once you have a compiled and working version of plumed, follow these steps to add it to
508an MD code
509- Configure and compile your MD engine (look for the instructions in its documentation).
510- Test if the MD code is working properly.
511- Go to the root directory for the source code of the MD engine.
512- Patch with PLUMED using:
513\verbatim
514> plumed patch -p
515\endverbatim
516The script will interactively ask which MD engine you are patching.
517- Once you have patched recompile the MD code (if dependencies are set up properly in the MD engine,
518  only modified files will be recompiled)
519
520There are different options available when patching. You can check all of them using
521\verbatim
522> plumed patch --help
523\endverbatim
524Particularly interesting options include:
525- --static just link PLUMED as a collection of object files. This is only suggested if for external reasons you
526  absolutely need a static executable. Notice that with this setting it is often more complicated to configure
527  properly the MD code, since all the libraries that PLUMED depends on should be properly specified. The `./configure` script
528  does its best in this sense, but sometime it cannot solve the problem. Additionally, this patching mode has been reported
529  not to work properly on OSX.
530- --shared (default) allows you to link PLUMED as a shared library. As a result when PLUMED is updated, there will be no need to recompile the MD code.
531  This is way better than --static since the libraries that PLUMED depends on should be automatically linked.
532  Notice that if you later remove the directory where PLUMED is installed also the MD code will not run anymore.
533- --runtime allows you to choose the location of the PLUMED library at runtime by setting the variable PLUMED_KERNEL.
534  This is probably the most flexible option, and we encourage system administrators to use this option when installing
535  PLUMED on shared facilities. Indeed, using this setting it will be possible to update separately the PLUMED library
536  and the MD code, leaving to the user the possibility to combine different versions at will.
537  We also recommend to use the provided modulefile (see above) to properly set the runtime environment.
538
539Notice that with PLUMED version <2.5 there was no possibility to link PLUMED as a static library (something like 'libplumed.a').
540However, starting with PLUMED 2.5, the `./configure` script will try to set up the system so that a `libplumed.a` file is produced.
541Patching an MD code with `--static` with try to link against this static library.
542Creation of the `libplumed.a` library can be avoided with `./configure --disable-static-archive`.
543
544If your MD code is not supported, you may want to implement an interface for
545it. Refer to the <a href="../../developer-doc/html/index.html"> developer
546manual </a>.
547
548\section CrossCompiling Cross compiling
549
550If you are compiling an executable from a different machine, then
551`plumed` executable will not be available in the compilation environment.
552This means that you won't be able to perform regtests on the machine
553nor to compile the manual.
554You can try to run the regtests on the computing nodes, but this might require some tweak
555since often machines where people do cross compiling have architectures with limited capabilities
556on the compute nodes. Also notice that many of the `plumed` options (e.g. patch) are implemented
557as shell scripts launched from within the `plumed` executable. If the compute nodes have some limitation
558(e.g. they do not allow to fork new processes) these options will not work. Anyway, the PLUMED library
559in combination with an MD software should work if both PLUMED and the MD software have been properly compiled.
560
561Also notice that it will not be possible
562to use the command `plumed patch` on the machine where you are compiling.
563You should thus use `plumed-patch` instead of `plumed patch` (notice that it should be written as a single word).
564
565Try e.g.:
566\verbatim
567> plumed-patch --help
568\endverbatim
569This script provides a "shell only" implementation of `plumed patch` that will skip the launch of the `plumed` executable.
570
571Notice that other command line tools will be available in the directory `prefix/lib/progname/`. If configuring with
572default values this would be `/usr/local/lib/plumed/plumed-*`. These files are not included in the execution path (prefix/bin)
573to avoid clashes, but can be executed also when plumed is cross compiled and the main plumed executable cannot be
574launched.
575
576\section Installation-macports Installing PLUMED with MacPorts
577
578If you are using a Mac, notice that you can take advantage of a MacPorts package.
579Installing a working plumed should be as easy as:
580- Install [MacPorts](https://www.macports.org/)
581- Type `sudo port install plumed`
582
583Notice that plumed comes with many variants that can be inspected with the command
584
585    > sudo port info plumed
586
587Plumed uses variants to support different compilers.
588For instance, you can install plumed with mpich using
589
590    > sudo port install plumed +mpich
591
592Using more recent clang instead of native compilers is recommended so as to
593take advantage of openMP
594
595    > sudo port install plumed +mpich +clang50
596
597Notice that support for c++11 with gcc compilers is someway problematic within MacPorts
598due to impossibility to use the system c++ library. For this reason, only clang compilers are supported
599(see also [this discussion](https://github.com/macports/macports-ports/pull/1252)).
600
601Variants can be also used to compile with debug flags (`+debug`), to pick a linear algebra library
602(e.g. `+openblas`) and to enable all optional modules (`+allmodules`).
603Notice that the default variant installed with `sudo port install plumed` is shipped as a compiled
604binary, which is significantly faster to install.
605
606In addition, we provide a developer version (typically: a later version not yet considered as stable)
607under the subport `plumed-devel` that can be installed with
608
609    > sudo port install plumed-devel
610
611`plumed-devel` also supports the same variants as `plumed` in order to customize the compilation.
612`plumed-devel` and `plumed` cannot be installed at the same time.
613
614It is also possible to install a plumed-patched version of gromacs.
615For instance, you can use the following command to install
616gromacs patched with plumed with clang-5.0 compiler and mpich:
617
618    > sudo port install plumed +mpich +clang50
619    > sudo port install gromacs-plumed +mpich +clang50
620
621In case you want to combine gromacs with the unstable version of plumed, use this instead:
622
623    > sudo port install plumed-devel +mpich +clang50
624    > sudo port install gromacs-plumed +mpich +clang50
625
626Notice that gromacs should be compiled using the same compiler
627variant as plumed (in this example `+mpich +clang50`). In case this is not
628true, compilation will fail.
629
630Also notice that gromacs is patched with plumed in runtime mode
631but that the path of libplumedKernel.dylib in the MacPorts tree
632is hard coded. As a consequence:
633
634- If gromacs is run with `PLUMED_KERNEL` environment variable unset (or set to empty),
635  then the MacPorts plumed is used.
636
637- If gromacs is run with `PLUMED_KERNEL` environment variable pointing to another instance
638  of the plumed library, the other instance is used.
639
640This is especially useful if you are developing PLUMED since you will be able to install
641gromacs once for all and combine it with your working version of PLUMED.
642
643\section Installation-conda Installing PLUMED with conda
644
645If you use the conda package manager you can install a pre-compiled PLUMED binary using the following command:
646\verbatim
647> conda install -c conda-forge plumed
648\endverbatim
649Similarly, the python wrappers can be installed with
650\verbatim
651> conda install -c conda-forge py-plumed
652\endverbatim
653
654These packages are part of [conda-forge](https://anaconda.org/conda-forge) and as such should be binary compatible
655with other codes from the same distribution. Notice that it should also be possible to combine the installed
656plumed kernel with an MD code compiled outside of conda (or within a different conda environment)
657if plumed is linked in runtime mode.
658The only variable that you need to set in order to access to the installed plumed kernel is
659`PLUMED_KERNEL` (e.g., `export PLUMED_KERNEL=/conda/prefix/lib/libplumedKernel.so`).
660
661Notice that binaries are only available for Linux and MacOS and that they have a limited number of features.
662In particular, they do not support MPI and do not include optional modules.
663However, they can be used to quickly install a working PLUMED version without the need to have a compiler.
664
665Notice that there are additional conda packages on the [plumed](https://anaconda.org/plumed/plumed) channel.
666Those packages are for testing only.
667
668\section installingonacluster Installing PLUMED on a cluster
669
670If you are installing PLUMED on a cluster and you want several users to take advantage of it
671consider the following suggestions.
672
673First of all, we highly recommend using the module file that PLUMED provides to set up the environment.
674Just edit it as necessary to make it suitable for your environment.
675
676Notice that PLUMED can take advantage of many additional features if specific libraries are available upon
677compiling it.
678If someone uses gromacs, install libxdrfile first and check if PLUMED `./configure` is detecting it.
679PLUMED will be able to write trr/xtc file, simplifying analysis.
680
681Try to patch all MD codes with the `--runtime` option. This will allow independent update of PLUMED and MD codes.
682  Users will be able to combine any of the installed gromacs/amber/etc versions with any of the installed PLUMED versions.
683Notice that it is sometime claimed that statically linked codes are faster. In our experience, this is not true.
684In case you absolutely need a static executable, be ready to face non trivial linking issues. PLUMED is written in C++,
685thus required the appropriate C++ library to be linked, and might require additional libraries (e.g. libxdrfile).
686
687Sometime we make small fixes on the patches. For this reason, keep track of which version of PLUMED you used
688to patch each of the MD code. Perhaps you can call the MD code modules with names such as `gromacs/4.6.7p1`,
689`gromacs/4.6.7p2` and write somewhere in the module file which version of PLUMED you used. Alternatively, call them
690something like `gromacs/4.6.7p2.2.0`. In this way, when we report a bug on the mailing list, users will know if the version
691they are using is affected by it.
692
693Usually it is not necessary to install both a MPI and a non-MPI PLUMED version. PLUMED library only calls MPI functions
694when the MD code is compiled with MPI. PLUMED executable calls MPI functions only when it is invoked without `--no-mpi`.
695In many machines it is thus sufficient to run the plumed executable on the login node as
696\verbatim
697> plumed --no-mpi
698\endverbatim
699even though PLUMED was compiled with MPI and the login node does not support MPI.
700The only case where you might need two different PLUMED installation for compute
701and login node is when you are cross compiling.
702
703PLUMED needs to be well optimized to run efficiently.
704If you need a single PLUMED binary to run efficiency on machines with different levels of hardware (e.g.: some
705of your workstations support AVX and some do not), with intel compiler you can use something like
706\verbatim
707> ./configure CXX=mpicxx CXXFLAGS="-O3 -axSSE2,AVX"
708\endverbatim
709It will take more time to compile but it will allow you to use a single module. Otherwise, you should install two
710PLUMED version with different optimization levels.
711
712Using modules, it is not necessary to make the PLUMED module explicitly dependent on the used library. Imagine a
713scenario where you first installed a module `libxdrfile`, then load it while you compile PLUMED. If you
714provide the following option to configure `--enable-rpath`, the PLUMED executable and
715library will remember where libxdrfile is, without the need to load libxdrfile module at runtime.
716Notice that this trick often does not work for fundamental libraries such as C++ and MPI library. As a consequence,
717usually the PLUMED module should load the compiler and MPI modules.
718
719\attention
720In case you found out how to compile PLUMED on some fancy architecture please share your tricks! You can
721either post it in your blog, send it to the mailing list, or ask as to update this paragraph in the manual, we will
722be happy to do so.
723
724\section installingpython Installing Python wrappers
725
726As of PLUMED 2.5 it is possible to use the PLUMED library through Python wrappers. Notice that this is not something for end users but rather for developers. The interface is very similar to the one used in MD codes linked with PLUMED.
727
728There are two ways to install Python wrappers.
729
730\subsection installingpython-inside Installing Python wrappers within PLUMED
731
732If `./configure` finds a `python` executable that also has the `cython` module available, Python wrappers will be installed within `/prefix/lib/plumed/python`. In order to access them, you should add this directory to the environment variable `PYTHONPATH`. Notice that if your python interpreter has a different name you might have to pass it to `./configure` with `PYTHON_BIN=python3.6`. The whole thing would then be:
733
734````
735./configure PYTHON_BIN=python3.6 --prefix=$HOME/opt
736make && make install
737export PYTHONPATH="$HOME/opt/lib/plumed/python:$PYTHONPATH"
738python3.6
739>>> import plumed
740````
741
742Notice that in this manner you will have to commit to a specific python version **before** installing PLUMED.
743
744\subsection installingpython-outside Installing Python wrappers outside PLUMED
745
746If you use multiple python versions, you might find it easier to install the Python wrappers separately from PLUMED. The simplest way is to do it with `pip`:
747
748````
749pip3.6 install --user plumed
750````
751
752Here the `--user` flag allows you to install the packages on your home. Notice that you don't even need to download PLUMED in order to install the wrappers, but you will need PLUMED in order to use them. You can tell the wrappers where PLUMED is by setting the `PLUMED_KERNEL` environment variable:
753
754````
755export PLUMED_KERNEL=$HOME/opt/lib/libplumedKernel.so
756python3.6
757>>> import plumed
758````
759
760Notice that by installing the wrappers in this manner you will download those that are packaged on [Pypi](https://pypi.org/project/plumed/).
761If you want to install using pip the development version of the wrappers you should download the PLUMED repository and use
762the following commands:
763
764````
765pip3.6 install --user cython # cython is required in this case
766cd plumed2/python
767make pip
768pip3.6 install --user .
769````
770
771If you want to install the development version it is recommended to use a virtualenv so that it will not interfere with the released packages.
772
773\section installinghints Other hints
774
775We here collect a list of suggestions that might be useful on particular
776machines.
777
778- On Blue Gene Q (likely on AIX) the prelinking made with `ld -r` is not
779  working properly. There is no easy way to detect this at configure time.
780  If during `make` you receive an error in the form
781\verbatim
782ld: TOC section size exceeds 64k
783\endverbatim
784  please configure plumed again with the following flag
785\verbatim
786> ./configure --disable-ld-r
787\endverbatim
788- On Cray machines, you might have to set the following environment variable
789  before configuring and building both PLUMED and the MD code that you want
790  to patch with PLUMED (kindly reported by Marco De La Pierre):
791\verbatim
792> export CRAYPE_LINK_TYPE=dynamic
793\endverbatim
794- Intel MPI seems to require the flags `-lmpi_mt -mt_mpi` for compiling and linking and the flag `-DMPICH_IGNORE_CXX_SEEK` for compiling
795  (kindly reported by Abhishek Acharya).
796  You might want to try to configure using
797\verbatim
798> ./configure LDFLAGS=-lmpi_mt CXXFLAGS="-DMPICH_IGNORE_CXX_SEEK -mt_mpi" STATIC_LIBS=-mt_mpi
799\endverbatim
800  Adding libraries to `STATIC_LIBS` uses them for all the linking steps, whereas those in `LIBS` are only used when linking the PLUMED kernel library.
801  See more at [this thread](https://groups.google.com/d/msgid/plumed-users/CAB1aw3y0m%3D5qwzsZY4ZB-aBevsL5iuS%3DmQuSWK_cw527zCMqzg%40mail.gmail.com?utm_medium=email&utm_source=footer).
802
803\page CodeSpecificNotes Code specific notes
804
805Here you can find instructions that are specific for patching each of the supported MD codes.
806Notice that MD codes with native PLUMED support are not listed here.
807
808@CODES@
809
810