-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsetup.py
451 lines (392 loc) · 16.5 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
#!/usr/bin/env python
package_name = "AlGDock"
from distutils.core import setup, Command, Extension
from distutils.command.build import build
from distutils.command.sdist import sdist
from distutils.command.install_data import install_data
from distutils.command.install import install
from distutils import dir_util
from distutils.filelist import FileList, translate_pattern
import distutils.sysconfig
sysconfig = distutils.sysconfig.get_config_vars()
import os, sys, types
import ctypes, ctypes.util
from glob import glob
class Dummy:
pass
pkginfo = Dummy()
execfile('AlGDock/__pkginfo__.py', pkginfo.__dict__)
execfile('AlGDock/path_tools.py')
from site import USER_BASE as userbase
# Check module dependencies
# Check for Cython
try:
from Cython.Distutils import build_ext
cython_ok = True
except ImportError:
cython_ok = False
if not cython_ok:
print 'AlGDock requires Cython'
raise SystemExit
# Check that we have Scientific 2.6 or higher
try:
from Scientific import __version__ as scientific_version
if scientific_version[-2:] == 'hg':
scientific_version = scientific_version[:-2]
scientific_version = scientific_version.split('.')
scientific_ok = int(scientific_version[0]) >= 2 and \
int(scientific_version[1]) >= 6
except ImportError:
scientific_ok = False
if not scientific_ok:
print "AlGDock needs ScientificPython 2.6 or higher"
raise SystemExit
# Check that we have MMTK 2.6 or higher
try:
from MMTK import __version__ as mmtk_version
mmtk_version = mmtk_version.split('.')
mmtk_ok = int(mmtk_version[0]) >= 2 and \
int(mmtk_version[1]) >= 6
except ImportError:
mmtk_ok = False
if not mmtk_ok:
print "AlGDock requires MMTK version 2.6 or higher"
raise SystemExit
MMTK_source_path = findPath(search_paths['MMTK'])
# Configure compile arguments and include directories
compile_args = ['-fdiagnostics-color=always']
include_dirs = ['Include',
os.path.join(MMTK_source_path,'Include'),
os.path.join(MMTK_source_path,'include', \
'python%d.%d'%sys.version_info[:2],'MMTK')]
from Scientific import N
assert N.package == "NumPy"
compile_args.append("-DNUMPY=1")
import numpy.distutils.misc_util
include_dirs.extend(numpy.distutils.misc_util.get_numpy_include_dirs())
if (int(scientific_version[1]) >= 8 or \
(int(scientific_version[1]) == 7 and int(scientific_version[2]) >= 8)):
netcdf_h = os.path.join(sys.prefix, 'include',
'python%d.%d' % sys.version_info[:2],
'Scientific', 'netcdf.h')
if os.path.exists(netcdf_h):
compile_args.append("-DUSE_NETCDF_H_FROM_SCIENTIFIC=1")
include_dirs.append(os.path.join(sys.prefix, 'include',
'python%d.%d' % sys.version_info[:2]))
userbase_netcdf_h = os.path.join(userbase, 'include',
'python%d.%d' % sys.version_info[:2],
'Scientific', 'netcdf.h')
if os.path.exists(userbase_netcdf_h):
compile_args.append("-DUSE_NETCDF_H_FROM_SCIENTIFIC=1")
include_dirs.append(os.path.join(sys.prefix, 'include',
'python%d.%d' % sys.version_info[:2]))
else:
# Take care of the common problem that netcdf is in /usr/local but
# /usr/local/include is not on $CPATH.
if os.path.exists('/usr/local/include/netcdf.h'):
include_dirs.append('/usr/local/include')
# netcdf is in /opt/local/include/netcdf.h
# include_dirs.append('/opt/local/include')
if ('NETCDF_PREFIX' in os.environ):
include_dirs.append(os.path.join(os.environ['NETCDF_PREFIX'],'include'))
for user_include_path in [
os.path.join(userbase, 'include',
'python%d.%d' % sys.version_info[:2])]:
if os.path.exists(user_include_path):
include_dirs.append(user_include_path)
headers = []
paths = [os.path.join('AlGDock', 'ForceFields', 'Cylinder'),
os.path.join('AlGDock', 'ForceFields', 'Sphere'),
os.path.join('AlGDock', 'ForceFields', 'Grid'),
os.path.join('AlGDock', 'ForceFields', 'OBC'),
os.path.join('AlGDock', 'ForceFields', 'OpenMM'),
os.path.join('AlGDock', 'ForceFields', 'Pose'),
os.path.join('AlGDock', 'ForceFields', 'ElectricField'),
os.path.join('AlGDock', 'Integrators', 'ExternalMC'),
os.path.join('AlGDock', 'Integrators', 'HamiltonianMonteCarlo'),
os.path.join('AlGDock', 'Integrators', 'NUTS'),
os.path.join('AlGDock', 'Integrators', 'SmartDarting'),
os.path.join('AlGDock', 'Integrators', 'VelocityVerlet')]
data_files = []
for dir in paths:
files = []
for f in glob(os.path.join(dir, '*')):
if f[-3:] != '.py' and f[-4:-1] != '.py' and os.path.isfile(f):
files.append(f)
data_files.append((dir, files))
# Customized distutils sources
class ModifiedFileList(FileList):
def findall(self, dir=os.curdir):
from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK
list = []
stack = [dir]
pop = stack.pop
push = stack.append
while stack:
dir = pop()
names = os.listdir(dir)
for name in names:
if dir != os.curdir:
fullname = os.path.join(dir, name)
else:
fullname = name
stat = os.stat(fullname)
mode = stat[ST_MODE]
if S_ISREG(mode):
list.append(fullname)
elif S_ISDIR(mode) and not S_ISLNK(mode):
list.append(fullname)
push(fullname)
self.allfiles = list
class modified_build(build):
def has_sphinx(self):
if sphinx is None:
return False
setup_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.isdir(os.path.join(setup_dir, 'Doc'))
sub_commands = build.sub_commands + [('build_sphinx', has_sphinx)]
class modified_sdist(sdist):
def run (self):
self.filelist = ModifiedFileList()
self.check_metadata()
self.get_file_list()
if self.manifest_only:
return
self.make_distribution()
def make_release_tree (self, base_dir, files):
self.mkpath(base_dir)
dir_util.create_tree(base_dir, files,
verbose=self.verbose, dry_run=self.dry_run)
if hasattr(os, 'link'): # can make hard links on this system
link = 'hard'
msg = "making hard links in %s..." % base_dir
else: # nope, have to copy
link = None
msg = "copying files to %s..." % base_dir
if not files:
self.warn("no files to distribute -- empty manifest?")
else:
self.announce(msg)
for file in files:
if os.path.isfile(file):
dest = os.path.join(base_dir, file)
self.copy_file(file, dest, link=link)
elif os.path.isdir(file):
dir_util.mkpath(os.path.join(base_dir, file))
else:
self.warn("'%s' not a regular file or directory -- skipping"
% file)
# class modified_install(install):
# def run(self):
# setup_dir = os.path.dirname(os.path.abspath(__file__))
# dest_dir = os.path.join(self.install_lib,'AlGDock',sys.platform)
# import glob
# so_FNs = glob.glob(os.path.join(setup_dir, 'AlGDock', 'Integrators', 'CDHMC','*.so.*'))
# for so_FN in so_FNs:
# print 'Copying %s to %s'%(so_FN, dest_dir)
# os.system('cp %s %s'%(so_FN, dest_dir))
# return install.run(self)
class modified_install_data(install_data):
def run(self):
install_cmd = self.get_finalized_command('install')
self.install_dir = getattr(install_cmd, 'install_lib')
return install_data.run(self)
class test(Command):
user_options = []
def initialize_options(self):
self.build_lib = None
def finalize_options(self):
self.set_undefined_options('build',
('build_lib', 'build_lib'))
def run(self):
import sys, subprocess
self.run_command('build_py')
self.run_command('build_ext')
ff = sum((fns for dir, fns in data_files if 'ForceFields' in dir), [])
for fn in ff:
self.copy_file(fn,
os.path.join(self.build_lib, fn),
preserve_mode=False)
# subprocess.call([sys.executable, 'Tests/all_tests.py'],
# env={'PYTHONPATH': self.build_lib,
# 'MMTKDATABASE': 'MMTK/Database'})
cmdclass = {
'build' : modified_build,
'sdist': modified_sdist,
'install_data': modified_install_data,
'build_ext': build_ext,
'test': test
}
# Build the sphinx documentation if Sphinx is available
try:
import sphinx
except ImportError:
sphinx = None
if sphinx:
from sphinx.setup_command import BuildDoc as _BuildDoc
class BuildDoc(_BuildDoc):
def run(self):
# make sure the python path is pointing to the newly built
# code so that the documentation is built on this and not a
# previously installed version
build = self.get_finalized_command('build')
sys.path.insert(0, os.path.abspath(build.build_lib))
ff = sum((fns for dir, fns in data_files if 'ForceFields' in dir),
[])
for fn in ff:
self.copy_file(fn,
os.path.join(build.build_lib, fn),
preserve_mode=False)
try:
sphinx.setup_command.BuildDoc.run(self)
except UnicodeDecodeError:
print >>sys.stderr, "ERROR: unable to build documentation because Sphinx do not handle source path with non-ASCII characters. Please try to move the source package to another location (path with *only* ASCII characters)."
sys.path.pop(0)
cmdclass['build_sphinx'] = BuildDoc
#################################################################
# Check various compiler/library properties
libraries = []
if sysconfig['LIBM'] != '':
libraries.append('m')
macros = []
try:
from Scientific.MPI import world
except ImportError:
world = None
if world is not None:
if type(world) == types.InstanceType:
world = None
if world is not None:
macros.append(('WITH_MPI', None))
if hasattr(ctypes.CDLL(ctypes.util.find_library('m')), 'erfc'):
macros.append(('LIBM_HAS_ERFC', None))
if sys.platform != 'win32':
if ctypes.sizeof(ctypes.c_long) == 8:
macros.append(('_LONG64_', None))
if sys.version_info[0] == 2 and sys.version_info[1] >= 2:
macros.append(('EXTENDED_TYPES', None))
#################################################################
# System-specific optimization options
low_opt = []
if sys.platform != 'win32' and 'gcc' in sysconfig['CC']:
low_opt = ['-O0']
low_opt.append('-g')
high_opt = []
if sys.platform[:5] == 'linux' and 'gcc' in sysconfig['CC']:
high_opt = ['-O3', '-ffast-math', '-fomit-frame-pointer',
'-fkeep-inline-functions']
if sys.platform == 'darwin' and 'gcc' in sysconfig['CC']:
high_opt = ['-O3', '-ffast-math', '-fomit-frame-pointer',
'-fkeep-inline-functions', '-falign-loops=16']
if sys.platform == 'aix4':
high_opt = ['-O4']
if sys.platform == 'odf1V4':
high_opt = ['-O2', '-fp_reorder', '-ansi_alias', '-ansi_args']
high_opt.append('-g')
#################################################################
ext_module_name_and_path = [\
('MMTK_sphere', ['AlGDock/ForceFields/Sphere/MMTK_sphere.pyx']), \
('MMTK_cylinder', \
['AlGDock/ForceFields/Cylinder/MMTK_cylinder.pyx']), \
('MMTK_trilinear_grid', ['AlGDock/ForceFields/Grid/MMTK_trilinear_grid.c']), \
('MMTK_trilinear_one_fourth_grid', \
['AlGDock/ForceFields/Grid/MMTK_trilinear_one_fourth_grid.c']), \
('MMTK_OBC', ['AlGDock/ForceFields/OBC/MMTK_OBC.c', \
'AlGDock/ForceFields/OBC/ObcParameters.cpp', \
'AlGDock/ForceFields/OBC/ObcWrapper.cpp', \
'AlGDock/ForceFields/OBC/ReferenceForce.cpp', \
'AlGDock/ForceFields/OBC/ReferenceObc.cpp']), \
('MMTK_OBC_desolv', ['AlGDock/ForceFields/OBC/MMTK_OBC_desolv.c', \
'AlGDock/ForceFields/OBC/ObcParameters.cpp', \
'AlGDock/ForceFields/OBC/ObcWrapper.cpp', \
'AlGDock/ForceFields/OBC/ReferenceForce.cpp', \
'AlGDock/ForceFields/OBC/ReferenceObc.cpp']), \
('MMTK_pose', ['AlGDock/ForceFields/Pose/MMTK_pose.c', \
'AlGDock/ForceFields/Pose/pose.c', \
os.path.join(MMTK_source_path, 'Src', 'bonded.c'), \
os.path.join(MMTK_source_path, 'Src', 'nonbonded.c'), \
os.path.join(MMTK_source_path, 'Src', 'ewald.c'), \
os.path.join(MMTK_source_path, 'Src', 'sparsefc.c')]), \
('MMTK_electric_field', \
['AlGDock/ForceFields/ElectricField/MMTK_electric_field.c']), \
('MMTK_electric_field_z', \
['AlGDock/ForceFields/ElectricField/MMTK_electric_field_z.c']), \
('NUTS', ['AlGDock/Integrators/NUTS/NUTS.pyx']), \
('SmartDarting', ['AlGDock/Integrators/SmartDarting/SmartDarting.pyx']), \
('BAT', ['Src/BAT.pyx']),
('repX', ['Src/repX.pyx'])]
if False:
# These extension modules are not used in the current code,
# but may be used in the future.
ext_module_name_and_path.extend(\
[('MMTK_trilinear_thresh_grid', \
['AlGDock/ForceFields/Grid/MMTK_trilinear_thresh_grid.pyx']), \
('MMTK_trilinear_transform_grid', \
['AlGDock/ForceFields/Grid/MMTK_trilinear_transform_grid.pyx']), \
('MMTK_BSpline_grid', \
['AlGDock/ForceFields/Grid/MMTK_BSpline_grid.pyx']), \
('MMTK_BSpline_transform_grid', \
['AlGDock/ForceFields/Grid/MMTK_BSpline_transform_grid.pyx'])])
if False:
# These extension modules are obsolete but are kept as references
ext_module_name_and_path.extend(\
[('MMTK_trilinear_grid_cython', \
['AlGDock/ForceFields/Grid/MMTK_trilinear_grid_cython.pyx']),
('MMTK_OpenMM', \
['AlGDock/ForceFields/OpenMM/MMTK_OpenMM.pyx']),
('MMTK_trilinear_one_fourth_grid', \
['AlGDock/ForceFields/Grid/MMTK_trilinear_one_fourth_grid_cython.pyx'])])
# if False:
# These extension modules need to be debugged.
# ext_module_name_and_path.extend(\
# [('MMTK_CatmullRom_grid', ['AlGDock/ForceFields/Grid/MMTK_CatmullRom_grid.pyx']), \
# ('MMTK_CatmullRom_transform_grid', ['AlGDock/ForceFields/Grid/MMTK_CatmullRom_transform_grid.pyx']), \
# ('MMTK_tricubic_grid', ['AlGDock/ForceFields/Grid/MMTK_tricubic_grid.pyx']), \
# ('MMTK_tricubic_transform_grid', ['AlGDock/ForceFields/Grid/MMTK_tricubic_transformgrid.pyx'])])
setup (name = package_name,
version = pkginfo.__version__,
description = "Molecular docking with an adaptive alchemical interaction grid",
long_description=
"""
AlGDock is an Open Source program for molecular docking. In addition to
low-energy poses, AlGDock also provides an estimate of the binding potential
of mean force, or free energy of binding between a (flexible) ligand and
rigid receptor.
""",
author = "David Minh",
author_email = "[email protected]",
url = "TBA",
license = "MIT",
packages = ['AlGDock',
'AlGDock.ForceFields',
'AlGDock.ForceFields.Cylinder',
'AlGDock.ForceFields.Sphere',
'AlGDock.ForceFields.Grid',
'AlGDock.ForceFields.OBC',
'AlGDock.ForceFields.OpenMM',
'AlGDock.ForceFields.Pose',
'AlGDock.ForceFields.ElectricField',
'AlGDock.Integrators',
'AlGDock.Integrators.ExternalMC',
'AlGDock.Integrators.HamiltonianMonteCarlo',
'AlGDock.Integrators.NUTS',
'AlGDock.Integrators.SmartDarting',
'AlGDock.Integrators.VelocityVerlet'],
ext_package = 'AlGDock.'+sys.platform,
ext_modules = [Extension(name, path, \
extra_compile_args = compile_args + high_opt, \
include_dirs = include_dirs, \
define_macros = \
[('SERIAL', None), ('VIRIAL', None), ('MACROSCOPIC', None)] \
+ macros,
libraries=libraries) \
for (name,path) in ext_module_name_and_path]
,
data_files = data_files,
scripts = [],
cmdclass = cmdclass,
command_options = {
'build_sphinx': {
'source_dir' : ('setup.py', 'Doc')}
},
)