forked from mdtraj/mdtraj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
301 lines (261 loc) · 12.1 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
"""MDTraj: A modern, open library for the analysis of molecular dynamics trajectories
MDTraj is a python library that allows users to manipulate molecular dynamics
(MD) trajectories and perform a variety of analyses, including fast RMSD,
solvent accessible surface area, hydrogen bonding, etc. A highlight of MDTraj
is the wide variety of molecular dynamics trajectory file formats which are
supported, including RCSB pdb, GROMACS xtc, tng, and trr, CHARMM / NAMD dcd, AMBER
binpos, AMBER NetCDF, AMBER mdcrd, TINKER arc and MDTraj HDF5.
"""
from __future__ import print_function, absolute_import
import sys
from glob import glob
DOCLINES = __doc__.split("\n")
from setuptools import setup, Extension, find_packages
sys.path.insert(0, '.')
from basesetup import (write_version_py, build_ext,
StaticLibrary, CompilerDetection, parse_setuppy_commands)
try:
# add an optional --disable-openmp to disable OpenMP support
sys.argv.remove('--disable-openmp')
disable_openmp = True
except ValueError:
disable_openmp = False
##########################
VERSION = "1.9.3"
ISRELEASED = True
__version__ = VERSION
##########################
CLASSIFIERS = """\
Development Status :: 5 - Production/Stable
Intended Audience :: Science/Research
Intended Audience :: Developers
License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
Programming Language :: C
Programming Language :: Python
Programming Language :: Python :: 3
Topic :: Scientific/Engineering :: Bio-Informatics
Topic :: Scientific/Engineering :: Chemistry
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
Operating System :: MacOS
"""
# Global info about compiler
compiler = CompilerDetection(disable_openmp)
compiler.initialize()
extra_cpp_libraries = []
if sys.platform == 'win32':
extra_cpp_libraries.append('Ws2_32')
# For determining if a path is relative (for dtr)
extra_cpp_libraries.append('Shlwapi')
################################################################################
# Declaration of the compiled extension modules (cython + c)
################################################################################
def format_extensions():
compiler_args = compiler.compiler_args_warn
xtc = Extension('mdtraj.formats.xtc',
sources=['mdtraj/formats/xtc/src/xdrfile.c',
'mdtraj/formats/xtc/src/xdr_seek.c',
'mdtraj/formats/xtc/src/xdrfile_xtc.c',
'mdtraj/formats/xtc/xtc.pyx',
],
include_dirs=['mdtraj/formats/xtc/include/',
'mdtraj/formats/xtc/'],
extra_compile_args=compiler_args)
trr = Extension('mdtraj.formats.trr',
sources=['mdtraj/formats/xtc/src/xdrfile.c',
'mdtraj/formats/xtc/src/xdr_seek.c',
'mdtraj/formats/xtc/src/xdrfile_trr.c',
'mdtraj/formats/xtc/trr.pyx'],
include_dirs=['mdtraj/formats/xtc/include/',
'mdtraj/formats/xtc/'],
extra_compile_args=compiler_args)
zlib_include_dirs = []
zlib_library_dirs = []
if sys.platform == 'win32':
# Conda puts the zlib headers in ./Library/... on windows
# If you're not using conda, good luck!
zlib_include_dirs += ["{}/Library/include".format(sys.prefix)]
zlib_library_dirs += ["{}/Library/lib".format(sys.prefix)]
else:
# On linux (and mac(?)) these paths should work for a standard
# install of python+zlib or a conda install of python+zlib
zlib_include_dirs += ["{}/include".format(sys.prefix)]
zlib_library_dirs += ["{}/lib".format(sys.prefix)]
tng = Extension('mdtraj.formats.tng',
sources=glob('mdtraj/formats/tng/src/compression/*.c') +
['mdtraj/formats/tng/src/lib/tng_io.c',
'mdtraj/formats/tng/src/lib/md5.c',
'mdtraj/formats/tng/tng.pyx'],
include_dirs=['mdtraj/formats/tng/include']
+ zlib_include_dirs,
define_macros=[('USE_ZLIB', 1)],
library_dirs=zlib_library_dirs,
libraries=['z'],
)
dcd = Extension('mdtraj.formats.dcd',
sources=['mdtraj/formats/dcd/src/dcdplugin.c',
'mdtraj/formats/dcd/dcd.pyx'],
include_dirs=["mdtraj/formats/dcd/include/",
'mdtraj/formats/dcd/'],
extra_compile_args=compiler_args)
binpos = Extension('mdtraj.formats.binpos',
sources=['mdtraj/formats/binpos/src/binposplugin.c',
'mdtraj/formats/binpos/binpos.pyx'],
include_dirs=['mdtraj/formats/binpos/include/',
'mdtraj/formats/binpos/'],
extra_compile_args=compiler_args)
dtr = Extension('mdtraj.formats.dtr',
sources=['mdtraj/formats/dtr/src/dtrplugin.cxx',
'mdtraj/formats/dtr/dtr.pyx'],
include_dirs=['mdtraj/formats/dtr/include/',
'mdtraj/formats/dtr/'],
define_macros=[('DESRES_READ_TIMESTEP2', 1)],
language='c++',
extra_compile_args=compiler_args,
libraries=extra_cpp_libraries)
return [xtc, trr, tng, dcd, binpos, dtr]
def rmsd_extensions():
compiler_args = (compiler.compiler_args_openmp + compiler.compiler_args_sse2 +
compiler.compiler_args_sse3 + compiler.compiler_args_opt +
compiler.compiler_args_warn)
compiler_libraries = compiler.compiler_libraries_openmp
libtheobald = StaticLibrary(
'mdtraj.core.lib.libtheobald',
sources=[
'mdtraj/rmsd/src/theobald_rmsd.c',
'mdtraj/rmsd/src/center.c'],
include_dirs=[
'mdtraj/rmsd/include'],
export_include=['mdtraj/rmsd/include/theobald_rmsd.h',
'mdtraj/rmsd/include/center.h'],
# don't enable OpenMP
extra_compile_args=(compiler.compiler_args_sse2 +
compiler.compiler_args_sse3 +
compiler.compiler_args_opt))
rmsd = Extension('mdtraj._rmsd',
sources=[
'mdtraj/rmsd/src/theobald_rmsd.c',
'mdtraj/rmsd/src/rotation.c',
'mdtraj/rmsd/src/center.c',
'mdtraj/rmsd/_rmsd.pyx'],
include_dirs=['mdtraj/rmsd/include'],
extra_compile_args=compiler_args,
libraries=compiler_libraries)
lprmsd = Extension('mdtraj._lprmsd',
sources=[
'mdtraj/rmsd/src/theobald_rmsd.c',
'mdtraj/rmsd/src/rotation.c',
'mdtraj/rmsd/src/center.c',
'mdtraj/rmsd/src/fancy_index.cpp',
'mdtraj/rmsd/src/Munkres.cpp',
'mdtraj/rmsd/src/euclidean_permutation.cpp',
'mdtraj/rmsd/_lprmsd.pyx'],
language='c++',
include_dirs=['mdtraj/rmsd/include'],
extra_compile_args=compiler_args,
libraries=compiler_libraries + extra_cpp_libraries)
return rmsd, lprmsd, libtheobald
def geometry_extensions():
compiler.initialize()
compiler_args = (
compiler.compiler_args_openmp +
compiler.compiler_args_sse2 + compiler.compiler_args_sse3 +
compiler.compiler_args_opt + compiler.compiler_args_warn)
define_macros = None
compiler_libraries = compiler.compiler_libraries_openmp + extra_cpp_libraries
return [
Extension('mdtraj.geometry._geometry',
sources=['mdtraj/geometry/src/sasa.cpp',
'mdtraj/geometry/src/dssp.cpp',
'mdtraj/geometry/src/geometry.cpp',
'mdtraj/geometry/src/_geometry.pyx',],
include_dirs=['mdtraj/geometry/include',
'mdtraj/geometry/src/kernels'],
depends=['mdtraj/geometry/src/kernels/anglekernels.h',
'mdtraj/geometry/src/kernels/dihedralkernels.h',
'mdtraj/geometry/src/kernels/distancekernels.h'],
define_macros=define_macros,
extra_compile_args=compiler_args,
libraries=compiler_libraries,
language='c++'),
Extension('mdtraj.geometry.drid',
sources=["mdtraj/geometry/drid.pyx",
"mdtraj/geometry/src/dridkernels.cpp",
"mdtraj/geometry/src/moments.cpp"],
include_dirs=["mdtraj/geometry/include"],
define_macros=define_macros,
extra_compile_args=compiler_args,
libraries=compiler_libraries,
language='c++'),
Extension('mdtraj.geometry.neighbors',
sources=["mdtraj/geometry/neighbors.pyx",
"mdtraj/geometry/src/neighbors.cpp"],
include_dirs=["mdtraj/geometry/include",],
define_macros=define_macros,
extra_compile_args=compiler_args,
libraries=compiler_libraries,
language='c++'),
Extension('mdtraj.geometry.neighborlist',
sources=["mdtraj/geometry/neighborlist.pyx",
"mdtraj/geometry/src/neighborlist.cpp"],
include_dirs=["mdtraj/geometry/include",],
define_macros=define_macros,
extra_compile_args=compiler_args,
libraries=compiler_libraries,
language='c++'),
]
write_version_py(VERSION, ISRELEASED, 'mdtraj/version.py')
metadata = \
dict(name='mdtraj',
author='Robert McGibbon',
author_email='[email protected]',
description=DOCLINES[0],
long_description="\n".join(DOCLINES[2:]),
version=__version__,
license='LGPLv2.1+',
url='http://mdtraj.org',
download_url = "https://github.com/rmcgibbo/mdtraj/releases/latest",
platforms=['Linux', 'Mac OS-X', 'Unix', 'Windows'],
classifiers=CLASSIFIERS.splitlines(),
packages=find_packages(),
cmdclass={'build_ext': build_ext},
install_requires=['numpy>=1.6',
'scipy',
'astor',
'pyparsing',
],
package_data={'mdtraj.formats.pdb': ['data/*'], },
zip_safe=False,
entry_points={'console_scripts':
['mdconvert = mdtraj.scripts.mdconvert:entry_point',
'mdinspect = mdtraj.scripts.mdinspect:entry_point']},
)
if __name__ == '__main__':
# Don't use numpy if we are just - non-build actions are required to succeed
# without NumPy for example when pip is used to install Scipy when
# NumPy is not yet present in the system.
run_build = parse_setuppy_commands()
if run_build:
extensions = format_extensions()
extensions.extend(rmsd_extensions())
extensions.extend(geometry_extensions())
# most extensions use numpy, add headers for it.
try:
import Cython as _c
from Cython.Build import cythonize
if _c.__version__ < '0.29':
raise ImportError("Too old")
except ImportError as e:
print('mdtrajs setup depends on Cython (>=0.29). Install it prior invoking setup.py')
print(e)
sys.exit(1)
try:
import numpy as np
except ImportError:
print('mdtrajs setup depends on NumPy. Install it prior invoking setup.py')
sys.exit(1)
for e in extensions:
e.include_dirs.append(np.get_include())
metadata['ext_modules'] = cythonize(extensions, language_level=sys.version_info[0])
setup(**metadata)