02_compiling.rst 14.6 KB
Newer Older
1
2
3
4
5
.. _compiling-openmm-from-source-code:

Compiling OpenMM from Source Code
#################################

6
7
8
9
10
This chapter describes the procedure for building and installing OpenMM from
source code.  In most cases, it is best to use the pre-built versions installed
with conda.  Sometimes you might need to build from source, though, such as if
you want to modify OpenMM, or if conda does not provide packages compatible with
your environment.
11

12
13
We first describe how to build on Linux or Mac.  We then describe how to build
on Windows, where the process is slightly different.
14

15
16
Compiling on Linux and Mac
**************************
17

18
19
Prerequisites
=============
20

21
Before building OpenMM from source, you will need certain tools.
22

23
24
C++ compiler
------------
25
26

You must have a C++ compiler installed before attempting to build OpenMM from
27
28
29
30
31
source.  All recent versions of clang or gcc should work correctly.  On Linux,
you can install the compiler with your system's standard package manager (such
as apt or yum).  On MacOS, you can get a C++ compiler by installing the Xcode
developer tools from the App Store.  Alternatively you can use a package manager
such as Homebrew to install clang or gcc.
32

33
34
Python
------
35

36
37
38
You will need a 64-bit Python 3.x environment.  We recommend using Miniconda
(https://docs.conda.io/en/latest/miniconda.html), which includes the conda
package manager.
39

40
41
OpenMM Source Code
------------------
42

43
You will also need the OpenMM source code.  To download it:
44

45
46
47
48
#. Browse to https://github.com/openmm/openmm/releases.
#. Find the latest release and click the link to download the source as either
   a .zip or .tar.gz file.
#. Unpack the file.  Note the location where you unpacked the OpenMM source code.
49
50
51

Alternatively, if you want the most recent development version of the code rather
than the version corresponding to a particular release, you can get it from
52
https://github.com/openmm/openmm.  Be aware that the development code is constantly
53
54
55
56
changing, may contain bugs, and should never be used for production work.  If
you want a stable, well tested version of OpenMM, you should download the source
code for the latest release as described above.

57
58
CUDA or OpenCL Support
----------------------
59

60
61
62
If you want to compile OpenMM with support for running on GPUs, you will need
CUDA and/or OpenCL.  MacOS comes with OpenCL built in, so nothing else needs to
be installed.  For Linux, you need an appropriate SDK.
63

64
65
66
67
68
69
The easiest way is to install the most recent CUDA Toolkit from https://developer.nvidia.com/cuda-downloads.
It includes the headers and libraries needed to compile both CUDA and OpenCL
applications.  In addition, it has runtime libraries that are needed for running
CUDA applications.  The runtime components for OpenCL applications are included
with the GPU drivers from NVIDIA, AMD, and Intel, so make sure you have an
up-to-date driver.
70

71
72
Other Required Software
-----------------------
73

74
75
76
77
Several other tools are required to build OpenMM.  The easiest way to install
them is with conda.  The following command will install everything needed to
build OpenMM.
::
78

79
    conda install -c conda-forge cmake make cython swig fftw doxygen numpy
80

81
82
Step 1: Configure with CMake
============================
83

84
85
86
First, create a directory in which to build OpenMM.  Starting from the root
level of the OpenMM source tree (the directory containing the top CMakeLists.txt
file), execute the following commands:
87

88
.. code-block:: none
89

90
91
92
    mkdir build
    cd build
    ccmake ..
93

94
95
96
That is not a typo.  :code:`ccmake` has two c’s.  CCMake is the visual CMake
configuration tool.  Press :code:`c` within the CCMake interface to load the
OpenMM build scripts and begin configuring CMake.
97

98
There are several variables that can be adjusted in the CMake interface:
99

100
101
102
103
104
105
106
107
108
109
110
111
* Set the variable CMAKE_INSTALL_PREFIX to the location where you want to
  install OpenMM.
* Set the variable PYTHON_EXECUTABLE to the Python interpreter you plan to use
  OpenMM with.  Usually this will be detected automatically.
* There are lots of options starting with OPENMM_BUILD that control
  whether to build particular features of OpenMM, such as plugins, API wrappers,
  and documentation.
* Usually the OpenCL library and headers will be detected automatically.  If for
  any reason CMake is unable to find them, set OPENCL_INCLUDE_DIR to point to
  the directory containing the headers (usually /usr/local/cuda/include on Linux)
  and OPENCL_LIBRARY to point to the library (usually /usr/local/cuda/lib64/libOpenCL.so
  on Linux).  
112

113
Configure (press “c”) again.  Adjust any variables that cause an error.
114

115
116
Continue to configure (press “c”) until no starred CMake variables are
displayed, then press “g” to generate the makefiles for building the project.
117

118
119
Step 2: Build and Install
=========================
120

121
Build and install OpenMM with the command::
122

123
    make install
124

125
126
If you are installing to a system area, such as /usr/local/openmm/, you will
need to type::
127

128
    sudo make install
129

130
131
Step 3: Install the Python API
==============================
132

133
Build and install the Python API with the command::
134

135
    make PythonInstall
136

137
138
If you are installing into the system Python, such as /usr/bin/python, you will
need to type:
139
140
::

141
    sudo make PythonInstall
142

143
.. _test-your-build:
144

145
146
Step 4: Test your build
=======================
147

148
149
After OpenMM has been built, you should run the unit tests to make sure it
works.  Enter the command::
150

151
    make test
152

153
You should see a series of test results like this:
154

155
.. code-block:: none
156

157
158
159
160
161
162
163
            Start   1: TestReferenceAndersenThermostat
      1/317 Test   #1: TestReferenceAndersenThermostat .............. Passed  0.26 sec
            Start   2: TestReferenceBrownianIntegrator
      2/317 Test   #2: TestReferenceBrownianIntegrator .............. Passed  0.13 sec
            Start   3: TestReferenceCheckpoints
      3/317 Test   #3: TestReferenceCheckpoints ..................... Passed  0.02 sec
      ... <many other tests> ...
164

165
166
167
:code:`Passed` is good.  :code:`FAILED` is bad.  If any tests fail, you
can run them individually to get more detailed error information.  For example,
::
168

169
    ./TestReferenceLangevinIntegrator
170

171
172
Note that some tests are stochastic, and therefore are expected to fail a small
fraction of the time.  These tests will say so in the error message:
173

174
.. code-block:: none
175

176
177
    exception: Assertion failure at TestReferenceLangevinIntegrator.cpp:129.  Expected 9.97741,
        found 10.7884 (This test is stochastic and may occasionally fail)
178

179
Congratulations! You have successfully built and installed OpenMM from source.
180
181


182
Compiling on Windows
183
184
********************

185
186
Prerequisites
=============
187

188
Before building OpenMM from source, you will need certain tools.
189

190
191
C++ compiler
------------
192

193
194
On Windows systems, use the C++ compiler in Visual Studio 2015 or later.  You
can download a free version of Visual Studio from https://visualstudio.microsoft.com.
195

196
197
Python
------
198

199
200
201
You will need a 64-bit Python 3.x environment.  We recommend using Miniconda
(https://docs.conda.io/en/latest/miniconda.html), which includes the conda
package manager.
202

203
204
CMake
-----
205

206
207
208
CMake is the build system used for OpenMM.  You must install CMake version 3.17
or higher before attempting to build OpenMM from source.  You can get CMake from
http://www.cmake.org/.
209

210
211
OpenMM Source Code
------------------
212

213
You will also need the OpenMM source code.  To download it:
214

215
216
217
218
#. Browse to https://github.com/openmm/openmm/releases.
#. Find the latest release and click the link to download the source as either
   a .zip or .tar.gz file.
#. Unpack the file.  Note the location where you unpacked the OpenMM source code.
219

220
221
222
223
224
225
Alternatively, if you want the most recent development version of the code rather
than the version corresponding to a particular release, you can get it from
https://github.com/openmm/openmm.  Be aware that the development code is constantly
changing, may contain bugs, and should never be used for production work.  If
you want a stable, well tested version of OpenMM, you should download the source
code for the latest release as described above.
226

227
228
CUDA or OpenCL Support
----------------------
229

230
231
232
233
234
235
236
If you want to compile OpenMM with support for running on GPUs, you will need
CUDA and/or OpenCL.  Install the most recent CUDA Toolkit from https://developer.nvidia.com/cuda-downloads.
It includes the headers and libraries needed to compile both CUDA and OpenCL
applications.  In addition, it has runtime libraries that are needed for running
CUDA applications.  The runtime components for OpenCL applications are included
with the GPU drivers from NVIDIA, AMD, and Intel, so make sure you have an
up-to-date driver.
237

238
239
Other Required Software
-----------------------
240

241
242
243
244
Several other tools are required to build OpenMM.  The easiest way to install
them is with conda.  From the Windows Start menu, select "Anaconda Prompt (Miniconda3)".
It will open a command window that is preconfigured for conda.  Enter the
following command to install everything needed to build OpenMM.
245
246
::

247
    conda install -c conda-forge cython swig fftw doxygen numpy
248

249
250
Step 1: Configure with CMake
============================
251

252
253
254
First, create a directory in which to build OpenMM.  In the "Anaconda Prompt"
window opened above, cd to the root level of the OpenMM source tree (the
directory containing the top CMakeLists.txt file).  Execute the following commands:
255

256
.. code-block:: none
257

258
259
260
    mkdir build
    cd build
    "C:\Program Files\CMake\bin\cmake-gui.exe"
261

262
263
264
265
This will launch the CMake GUI configuration tool.  It is critical that you
launch it from the "Anaconda Prompt" window as shown above.  Do *not* launch
it from the Start menu.  If you do, it will not be able to find the tools you
installed with conda.
266

267
268
269
270
271
272
273
#. In the box labeled "Where is the source code" browse to the OpenMM source directory
   (containing the top CMakeLists.txt file).
#. In the box labeled "Where to build the binaries" browse to the build
   directory you just created.
#. Click the "Configure" button at the bottom of the CMake window.
#. Select "Visual Studio 16 2019" from the  list of Generators (or whichever
   version you have installed) and click "Finish".
274

275
There are several variables that can be adjusted in the CMake interface:
276

277
278
279
280
281
282
283
284
285
286
287
288
289
* Set the variable CMAKE_INSTALL_PREFIX to the location where you want to
  install OpenMM.
* Set the variable PYTHON_EXECUTABLE to the Python interpreter you plan to use
  OpenMM with.  Usually this will be detected automatically.
* There are lots of options starting with OPENMM_BUILD that control
  whether to build particular features of OpenMM, such as plugins, API wrappers,
  and documentation.
* Usually the OpenCL library and headers will be detected automatically.  If for
  any reason CMake is unable to find them, set OPENCL_INCLUDE_DIR to point to
  the directory containing the headers (usually
  "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/include", except
  with the correct version number for the toolkit you installed) and
  OPENCL_LIBRARY to point to the library (usually "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4/lib/x64/OpenCL.lib").  
290

291
Press "Configure" again.  Adjust any variables that cause an error.
292

293
294
Continue to press "Configure" until no red CMake variables are displayed, then
press "Generate" to create the Visual Studio project files for building OpenMM.
295

296
297
Step 2: Build and Install
=========================
298

299
300
301
302
303
304
#. Open the file :file:`OpenMM.sln` in your build directory in Visual Studio.
   Note that this file will appear as just :file:`OpenMM` if you have configured
   Explorer to hide file name extensions.
#. Set the configuration type to "Release" (not "Debug") in the toolbar.
#. From the Build menu, select "Build Solution".  This takes some time.
#. In the Solution Explorer, right-click on "INSTALL" and select "Build".
305

306
307
Step 3: Install the Python API
==============================
308

309
In the Solution Explorer, right-click on "PythonInstall" and select "Build".
310

311
312
Step 4: Test your build
=======================
313

314
315
After OpenMM has been built, you should run the unit tests to make sure it
works.  In the Solution Explorer, right-click on "RUN_TESTS" and select "Build".
316
You should see a series of test results like this:
317
318

.. code-block:: none
319
320
321
322
323
324
325
326
327
328

            Start   1: TestReferenceAndersenThermostat
      1/317 Test   #1: TestReferenceAndersenThermostat .............. Passed  0.26 sec
            Start   2: TestReferenceBrownianIntegrator
      2/317 Test   #2: TestReferenceBrownianIntegrator .............. Passed  0.13 sec
            Start   3: TestReferenceCheckpoints
      3/317 Test   #3: TestReferenceCheckpoints ..................... Passed  0.02 sec
      ... <many other tests> ...

:code:`Passed` is good.  :code:`FAILED` is bad.  If any tests fail, you
329
330
can run them individually to get more detailed error information.  Right-click
on a test in the Solution Explorer and select "Debug > Start New Instance".
331

332
333
334
335
Note that some tests are stochastic, and therefore are expected to fail a small
fraction of the time.  These tests will say so in the error message:

.. code-block:: none
336
337
338
339

    exception: Assertion failure at TestReferenceLangevinIntegrator.cpp:129.  Expected 9.97741,
        found 10.7884 (This test is stochastic and may occasionally fail)

340
341
Congratulations! You have successfully built and installed OpenMM from source.

342
343
344
345

Building the Documentation (Optional)
*************************************

346
347
The documentation that you're currently reading, as well as the Developer Guide and API
documentation, can be built through CMake.  To do that, you need to install a few
348
additional tools.  The easiest way is to use :code:`conda` to install them into
349
350
351
your Python environment.  The following command installs everything needed to
build documentation in HTML format.
::
352

353
    conda install -c conda-forge sphinx sphinxcontrib-bibtex breathe jinja2
354

355
356
To build documentation in PDF format, you also must have a functional LaTeX
installation.  It can be obtained from https://www.latex-project.org/get.
357

358
359
If you want to build documentation, make sure that OPENMM_GENERATE_API_DOCS is
set to ON when configuring the build in CMake.
360

361
To build the documentation, use the following build targets.
362

363
* :code:`sphinxhtml`: Build the User Guide and Developer Guide in HTML format.
364

365
* :code:`sphinxpdf`: Build the User Guide and Developer Guide in PDF format.
366

367
* :code:`C++ApiDocs`: Build the C++ API documentation.
368

369
370
371
* :code:`PythonApiDocs`: Build the Python API documentation.  This target
  requires that you have already built the :code:`install` target, such as with
  :code:`make install`.
372

373
374
On Linux or Mac, build a target using the :code:`make` command.  For example,
::
375

376
    make sphinxhtml
377

378
On Windows, right-click on the target in the Solution Explorer and select "Build".
379

380
381
382
After building the documentation, build the :code:`install` target to install
the documentation into the installation directory (the one you specified with
CMAKE_INSTALL_PREFIX).