-
Notifications
You must be signed in to change notification settings - Fork 24
/
setup.py
executable file
·304 lines (259 loc) · 8.92 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
# ======================================================================
# Atomistica - Interatomic potential library and molecular dynamics code
# https://github.com/Atomistica/atomistica
#
# Copyright (2005-2015) Lars Pastewka <[email protected]> and others
# See the AUTHORS file in the top-level Atomistica directory.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ======================================================================
from __future__ import absolute_import, print_function
import glob
import os
import sys
import re
sys.path += [ 'src/python', 'tools' ]
import numpy as np
from numpy.distutils.core import setup, Extension
import versioneer
from meta import scanallmeta
from listclasses import get_module_list
from gen_factory import write_factory_f90, write_factory_c
from gen_factory import write_coulomb_factory_f90, write_coulomb_factory_c
###
cwd = os.getcwd()
srcdir = '%s/src' % cwd
###
#
# Module configuration
#
inc_dirs = [ ]
lib_dirs = [ ]
# atomisticalib is a dependency, build below by the setup command
libs = [ 'atomisticalib' ]
extra_link_args = [ ]
###
#
# LAPACK configuration from numpy
#
for k, v in np.__config__.__dict__.items():
if re.match('lapack_.*_info', k):
if v:
print("* Using LAPACK information from '%s' dictionary in " \
"numpy.__config__" % k)
try:
print(" library_dirs = '%s'" % v['library_dirs'])
lib_dirs += v['library_dirs']
except:
print(" No 'library_dirs' entry found.")
try:
print(" libraries = '%s'" % v['libraries'])
libs += v['libraries']
except:
print(" No 'libraries' entry found.")
try:
print(" extra_link_args = '%s'" % v['extra_link_args'])
extra_link_args += v['extra_link_args']
except:
print(" No 'extra_link_args' entry found.")
# We use whichever lapack_*_info comes first, hopefully there is
# just one.
break
###
#
# Build list of source files
#
lib_srcs = [ ]
mod_srcs = [ ]
# MDCORE support modules
lib_srcs += [ 'build/versioninfo.f90',
]
lib_srcs += [ ('%s/support/' % srcdir)+i for i in
[ 'c_f.f90',
'error.f90',
'System.f90',
'MPI_context.f90',
'Units.f90',
'PeriodicTable.f90',
'c_linearalgebra.cpp',
'f_linearalgebra.f90',
'f_ptrdict.f90',
'c_ptrdict.c',
'io.f90',
'f_logging.f90',
'c_logging.c',
'timer.f90',
'tls.f90',
'misc.f90',
'data.f90',
'simple_spline.f90',
'nonuniform_spline.f90',
'cutoff.f90',
'histogram1d.f90',
'supplib.f90',
'atomistica.f90',
]
]
lib_srcs += [ ('%s/python/f90/' % srcdir)+i for i in
[ 'python_particles.f90',
'python_neighbors.f90',
'particles_wrap.f90',
'neighbors_wrap.f90',
'python_helper.f90',
]
]
lib_srcs += [ ('%s/special/' % srcdir)+i for i in
[ 'table2d.f90',
'table3d.f90',
'table4d.f90',
'anderson_mixer.f90',
'extrapolation.f90'
]
]
lib_srcs += [ ('%s/core/' % srcdir)+i for i in
[ 'filter.f90',
]
]
# Generate versioninfo
os.system('sh src/gen_versioninfo.sh src build Python')
# Other stuff
mod_srcs += [ '%s/python/c/py_f.c' % (srcdir),
'%s/python/c/particles.c' % (srcdir),
'%s/python/c/neighbors.c' % (srcdir),
'%s/python/c/coulomb.c' % (srcdir),
'%s/python/c/coulomb_callback.c' % (srcdir),
'%s/python/c/potential.c' % (srcdir),
'%s/python/c/analysis.c' % (srcdir),
'%s/python/c/atomisticamodule.c' % (srcdir),
]
###
#
# C and Fortran compile flags
#
inc_dirs += [ np.get_include(),
'build',
'src',
'src/support',
'src/potentials',
'src/notb',
'src/notb/dense',
]
lib_macros = [ ( 'NO_BIND_C_OPTIONAL', None ),
( 'PYTHON', None ),
]
###
#
# Scan all metadata and get list of potentials
#
#print 'Scanning f90 metadata in directory {0}...'.format(srcdir)
metadata = scanallmeta(['{0}/{1}'.format(srcdir, x) for x in
['notb', 'potentials', 'potentials_nonfree']])
#print 'Writing factories...'
# Coulomb modules
mods1, fns1 = get_module_list(metadata, 'coulomb',
include_list = inc_dirs)
if sys.version_info >= (3,0):
lib_srcs += fns1
else:
lib_srcs += [ fn.encode('ascii') for fn in fns1 ]
print('* Found the following Coulomb modules:')
for f90name, f90type, name, features, methods in mods1:
print(' {0}'.format(name))
# Write coulomb factory
write_coulomb_factory_f90(mods1, 'coulomb', 'build/coulomb_factory_f90.f90')
write_coulomb_factory_c(mods1, 'coulomb',
'%s/python/c/coulomb_factory.template.c' \
% (srcdir),
'build/coulomb_factory_c.c',
'%s/python/c/coulomb_factory.template.h' \
% (srcdir),
'build/coulomb_factory_c.h')
lib_srcs += [ '%s/python/f90/coulomb_dispatch.f90' % (srcdir),
'build/coulomb_factory_f90.f90',
'build/coulomb_factory_c.c',
]
# Potential modules
mods2, fns2 = get_module_list(metadata, 'potentials',
include_list = inc_dirs)
if sys.version_info >= (3,0):
lib_srcs += fns2
else:
lib_srcs += [ fn.encode('ascii') for fn in fns2 ]
print('* Found the following potential modules:')
for f90name, f90type, name, features, methods in mods2:
print(' {0}'.format(name))
write_factory_f90(mods2, 'potential', 'build/potentials_factory_f90.f90')
write_factory_c(mods2, 'potential',
'%s/python/c/factory.template.c' % srcdir,
'build/potentials_factory_c.c',
'%s/python/c/factory.template.h' % srcdir,
'build/potentials_factory_c.h')
lib_srcs += [ 'build/potentials_factory_f90.f90',
'build/potentials_factory_c.c',
]
f = open('build/have.inc', 'w')
print('#ifndef __HAVE_INC', file=f)
print('#define __HAVE_INC', file=f)
for classabbrev, classname, classtype, classfeatures, methods in mods1:
print('#define HAVE_%s' % (classabbrev.upper()), file=f)
for classabbrev, classname, classtype, classfeatures, methods in mods2:
print('#define HAVE_%s' % (classabbrev.upper()), file=f)
print('#endif', file=f)
f.close()
###
scripts = glob.glob('src/python/tools/*.py')
###
setup(
name = 'atomistica',
version = versioneer.get_version(),
cmdclass = versioneer.get_cmdclass(),
description = 'Atomistica is a library of interatomic potentials that is compatible with ASE and LAMMPS',
maintainer = 'Lars Pastewka',
maintainer_email = '[email protected]',
url = 'https://github.com/Atomistica/atomistica',
download_url = 'https://github.com/Atomistica/atomistica/tarball/'+versioneer.get_version(),
license = 'GPLv3',
packages = [
'atomistica'
],
package_dir = {
'atomistica': 'src/python/atomistica'
},
libraries = [
( 'atomisticalib', dict(
sources = lib_srcs,
include_dirs = inc_dirs,
macros = lib_macros,
extra_compiler_args = [ '-fPIC', '-DHAVE_LAPACK' ],
)
)
],
ext_modules = [
Extension(
'_atomistica',
mod_srcs,
include_dirs = inc_dirs,
library_dirs = lib_dirs,
libraries = libs,
extra_compile_args = [ '-fPIC', '-DHAVE_LAPACK' ],
extra_link_args = extra_link_args,
)
],
scripts = scripts,
setup_requires = [],
install_requires = [
'ase>=3.15.0',
'numpy>=1.11.0'
]
)