-
Notifications
You must be signed in to change notification settings - Fork 0
/
modeller.rb
438 lines (402 loc) · 15.9 KB
/
modeller.rb
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
require "formula"
class Modeller < Formula
desc "Homology or comparative modeling of protein structures"
homepage "https://salilab.org/modeller/"
url "https://salilab.org/modeller/10.6/modeller-10.6-mac.pax.gz" if OS.mac?
sha256 "a29ead80ae3bef09e6532079eb228c2798cf44a49a067b31e826065c2e79761d" if OS.mac?
url "https://salilab.org/modeller/10.6/modeller-10.6.tar.gz" if OS.linux?
sha256 "7b76d2323d63b935e760380f45365411a7efc67d4f8d175c9c0eebc6eeb377e2" if OS.linux?
depends_on "patchelf" => :build if OS.linux?
depends_on "pkg-config" => :build
depends_on "swig" => :build
depends_on "python-setuptools" => :build
depends_on "gettext"
depends_on "glib"
depends_on "[email protected]"
depends_on "ifort-runtime" if Hardware::CPU.intel?
depends_on "[email protected]" => :recommended
# SWIG 4.3 support
patch :DATA
# otherwise python3 setup.py build cannot find pkg-config
env :std
def install
dylib = "dylib" if OS.mac?
dylib = "so" if OS.linux?
modtop = "Library/modeller-#{version}" if OS.mac?
if OS.linux?
mv "bin/modscript", "bin/mod#{version}"
modtop = "."
end
if Hardware::CPU.arm?
exetype = "mac12arm64-gnu"
univ_exetype = "mac10v4"
else
if `uname -m` == "x86_64\n"
exetype = "mac10v4-intel64" if OS.mac?
exetype = "x86_64-intel8" if OS.linux?
else
exetype = "mac10v4-intel"
end
univ_exetype = "mac10v4" if OS.mac?
univ_exetype = "x86_64-intel8" if OS.linux?
end
pyver = Language::Python.major_minor_version "python"
inreplace "#{modtop}/bin/mod#{version}" do |s|
s.gsub! /^(MODINSTALL.*)=.*/, "\\1=#{prefix}"
if OS.linux?
s.gsub! /(EXECUTABLE_TYPE\w+)=.*;/, "\\1=#{exetype};"
s.gsub! /ARCHBINDIR=bin/, "ARCHBINDIR=modbin"
else
s.gsub! /\/bin\/\$\{EXECUTABLE\}/, "/modbin/${EXECUTABLE}"
end
# Find _modeller.so in Python path
s.gsub! /^# run the/, "export PYTHONPATH=#{lib}/python#{pyver}/site-packages\n\n#run the"
end
# Rename Modeller's 'bin' directory to 'modbin', since the contents are
# (mostly) not binaries (and otherwise Homebrew will link them into
# /usr/local/bin). Also, point DYNLIB to a different location (see below)
inreplace "#{modtop}/modlib/libs.lib" do |s|
s.gsub! /^(BIN_MODELLER.*)\/bin/, "\\1/modbin"
s.gsub! /^(DYNLIB.*)\/lib/, "\\1/dynlib"
end
inreplace "#{modtop}/src/swig/setup.py" do |s|
s.gsub! /^exetype =.*$/, "exetype = \"#{exetype}\""
s.gsub! /\/lib\//, "/dynlib/"
end
sover = "13"
bin.install "#{modtop}/bin/mod#{version}"
(prefix/"modbin").install Dir["#{modtop}/bin/*"]
if OS.mac?
# Otherwise the Python 3 _modeller extension uses the
# old location (in /Library)
system "install_name_tool", "-id",
lib/"libmodeller.#{sover}.dylib",
"#{modtop}/lib/#{univ_exetype}/libmodeller.#{sover}.dylib"
lib.install Dir["#{modtop}/lib/#{univ_exetype}/libmodeller.*dylib"]
lib.install "#{modtop}/lib/#{univ_exetype}/libsaxs.dylib"
if Hardware::CPU.arm?
lib.install "#{modtop}/lib/#{univ_exetype}/libquadmath.0.dylib"
end
(prefix/"py2_compat").install "#{modtop}/py2_compat/Python"
(prefix/"py2_compat").install "#{modtop}/py2_compat/site.py"
elsif OS.linux?
lib.install Dir["#{modtop}/lib/#{exetype}/libmodeller.so*"]
lib.install "#{modtop}/lib/#{exetype}/libsaxs.so"
lib.install "#{modtop}/lib/#{exetype}/libpython2.3.so.1.0"
end
doc.install "#{modtop}/ChangeLog"
doc.install "#{modtop}/doc"
doc.install "#{modtop}/examples"
prefix.install "#{modtop}/modlib"
prefix.install "#{modtop}/src"
if OS.linux?
ifort_libs = ["ifcore.so.5", "imf.so", "intlc.so.5", "svml.so"]
elsif OS.mac?
ifort_libs = ["ifcore.dylib", "imf.dylib", "intlc.dylib", "irc.dylib",
"svml.dylib"]
modbins = [prefix/"modbin/mod#{version}_#{univ_exetype}",
"#{modtop}/lib/#{univ_exetype}/_modeller.so",
lib/"libmodeller.#{sover}.dylib",
lib/"libsaxs.dylib"]
dprefix = "/#{modtop}/lib/mac10v4/"
# Get only the native arch for Modeller dylibs to work around
# Homebrew thinking we have broken dependencies (arm64 version links
# to libquadmath; Intel version does not)
if Hardware::CPU.arm?
exargs = ["-extract", "arm64"]
else
exargs = ["-extract", "i386", "-extract", "x86_64"]
end
["modeller.#{sover}", "saxs"].each do |l|
system "lipo", *exargs, "-output", lib/"lib#{l}.dylib.new",
lib/"lib#{l}.dylib"
mv lib/"lib#{l}.dylib.new", lib/"lib#{l}.dylib"
end
modbins.each do |modbin|
# Point Modeller binaries to Homebrew-installed HDF5
hdf_libs = ["hdf5.103", "hdf5_hl.100"]
hdf_libs.each do |dep|
system "install_name_tool", "-change",
"#{dprefix}lib#{dep}.dylib",
Formula["[email protected]"].lib/"lib#{dep}.dylib", modbin
end
# Point Modeller binaries to Homebrew-installed libintl
system "install_name_tool", "-change",
"#{dprefix}libintl.8.dylib",
Formula["gettext"].lib/"libintl.8.dylib", modbin
# Point Modeller binaries to Homebrew-installed glib2
system "install_name_tool", "-change",
"#{dprefix}libglib-2.0.0.dylib",
Formula["glib"].lib/"libglib-2.0.0.dylib", modbin
# Point Modeller binaries to Homebrew-installed ifort runtime libraries
if Hardware::CPU.intel?
ifort_libs.each do |dep|
system "install_name_tool", "-change",
"/#{modtop}/lib/mac10v4/lib#{dep}",
Formula["ifort-runtime"].lib/"lib#{dep}", modbin
end
end
libs = ["modeller.#{sover}", "saxs"]
if Hardware::CPU.arm?
libs << "quadmath.0"
end
libs.each do |dep|
system "install_name_tool", "-change",
"#{dprefix}lib#{dep}.dylib",
lib/"lib#{dep}.dylib", modbin
end
end
# Make py2_compat binary that pulls in bundled Python
cp prefix/"modbin/mod#{version}_#{univ_exetype}",
prefix/"py2_compat/mod#{version}_#{univ_exetype}"
system "install_name_tool", "-change",
"/System/Library/Frameworks/Python.framework/Versions/2.6/Python",
prefix/"py2_compat/Python",
prefix/"py2_compat/mod#{version}_#{univ_exetype}"
system "install_name_tool", "-change",
"/System/Library/Frameworks/Python.framework/Versions/2.7/Python",
prefix/"py2_compat/Python",
prefix/"py2_compat/mod#{version}_#{univ_exetype}"
# install_name_tool invalidates signatures, so resign
# cp && mv is needed to work around a MacOS bug:
# "the codesign_allocate helper tool cannot be found or used"
if Hardware::CPU.arm?
modbins.each do |modbin|
cp modbin, "#{modbin}.new"
mv "#{modbin}.new", modbin
system "codesign", "-f", "-s", "-", modbin
end
modbin = prefix/"py2_compat/mod#{version}_#{univ_exetype}"
cp modbin, "#{modbin}.new"
mv "#{modbin}.new", modbin
system "codesign", "-f", "-s", "-", modbin
end
end
File.open("#{prefix}/modlib/modeller/config.py", "w") do |file|
file.puts "install_dir = r'#{prefix}'"
file.puts "license = r'XXXX'"
end
# Make dynlib directory and symlinks so modXXX --libs works
Dir.mkdir("#{prefix}/dynlib")
if OS.mac?
if Hardware::CPU.arm?
File.symlink(".", "#{prefix}/dynlib/mac12arm64-gnu")
else
["mac10v4-intel64", "mac10v4-intel"].each do |arch|
File.symlink(".", "#{prefix}/dynlib/#{arch}")
end
end
elsif OS.linux?
File.symlink(".", "#{prefix}/dynlib/x86_64-intel8")
end
File.open("#{prefix}/dynlib/README", "w") do |file|
file.puts %Q("mod#{version} --libs" outputs a single directory containing the Modeller
libraries and its HDF5 and Fortran runtime dependencies. Since the Homebrew
package moves things around a little, the regular lib/ directory isn't
suitable for this purpose. This directory contains symlinks to the necessary
libraries.
)
end
["modeller", "saxs"].each do |l|
File.symlink("../lib/lib#{l}.#{dylib}",
"#{prefix}/dynlib/lib#{l}.#{dylib}")
end
if Hardware::CPU.intel?
ifort_libs.each do |l|
File.symlink(Formula["ifort-runtime"].lib/"lib#{l}",
"#{prefix}/dynlib/lib#{l}")
end
end
["hdf5", "hdf5_hl"].each do |l|
File.symlink(Formula["[email protected]"].lib/"lib#{l}.#{dylib}",
"#{prefix}/dynlib/lib#{l}.#{dylib}")
end
if build.with? "[email protected]"
pyver = Language::Python.major_minor_version Formula["[email protected]"].opt_bin/"python3.13"
File.open("modeller.pth", "w") do |file|
file.puts "#{prefix}/modlib"
end
(lib/"python#{pyver}/site-packages").install "modeller.pth"
end
pyver = Language::Python.major_minor_version "python2"
if OS.mac?
(lib/"python#{pyver}/site-packages").install "#{modtop}/lib/#{univ_exetype}/_modeller.so"
elsif OS.linux?
# Most likely we are using the Python 2.5 ABI, not 2.3
(lib/"python#{pyver}/site-packages").install "#{modtop}/lib/#{univ_exetype}/python2.5/_modeller.so"
end
File.symlink("#{prefix}/modlib/modeller",
lib/"python#{pyver}/site-packages/modeller")
if OS.linux?
modbins = [prefix/"modbin/mod#{version}_#{exetype}",
"#{modtop}/lib/#{exetype}/_modeller.so",
lib/"libmodeller.so.#{sover}",
lib/"libsaxs.so",
lib/"python#{pyver}/site-packages/_modeller.so"]
lib1 = Formula["[email protected]"].lib
lib2 = Formula["ifort-runtime"].lib
modbins.each do |modbin|
system "patchelf", "--set-rpath", "#{lib1}:#{lib2}:#{HOMEBREW_PREFIX}/lib", modbin
end
end
# Build Python 3.13 extension from SWIG inputs
if build.with? "[email protected]"
pyver = Language::Python.major_minor_version Formula["[email protected]"].opt_bin/"python3.13"
Dir.chdir("#{prefix}/src/swig/") do
system "swig", "-python", "-keyword", "-nodefaultctor",
"-nodefaultdtor", "-noproxy", "modeller.i"
# Avoid possible confusion between Python 2 and Python 3 site modules
ENV.delete("PYTHONPATH")
system Formula["[email protected]"].opt_bin/"python3.13", "setup.py", "build"
(lib/"python#{pyver}/site-packages").install Dir["build/lib.*/_modeller.*so"]
File.delete("modeller_wrap.c")
rm_rf("build")
end
end
# Add pkg-config support
Dir.mkdir(lib/"pkgconfig")
if OS.mac?
if Hardware::CPU.intel?
pkgconfig_extras = " -lhdf5 -lhdf5_hl -lsaxs -limf -lsvml -lifcore -lirc"
else
pkgconfig_extras = " -lhdf5 -lhdf5_hl -lsaxs"
end
else
pkgconfig_extras = " -Wl,-rpath-link,#{prefix}/dylib/#{exetype}"
end
File.open(lib/"pkgconfig/modeller.pc", "w") do |file|
file.puts %Q(prefix=/usr
exec_prefix=/usr
Name: Modeller
Description: Comparative modeling by satisfaction of spatial restraints
Version: #{version}
Libs: -L#{prefix}/dynlib/#{exetype} -lmodeller#{pkgconfig_extras}
Cflags: -I#{prefix}/src/include -I#{prefix}/src/include/#{exetype}
)
end
end
def post_install
if FileTest.exist?("#{etc}/modeller/license")
lines = File.readlines("#{etc}/modeller/license")
if lines.size >= 1
inreplace "#{prefix}/modlib/modeller/config.py" do |s|
s.gsub! /XXXX/, lines[0].chomp
end
end
end
end
def caveats
unless FileTest.exist?("#{etc}/modeller/license")
<<~EOS
Edit #{prefix}/modlib/modeller/config.py
and replace XXXX with your Modeller license key
(or write your license key into #{etc}/modeller/license before
running "brew install").
EOS
end
end
test do
Language::Python.each_python(build) do |python, _version|
system python, "-c", "import modeller"
end
system "mod#{version}", "--cflags", "--libs"
end
end
__END__
diff -Nur a/Library/modeller-10.6/src/swig/typemaps/fixed-size-arrays.i b/Library/modeller-10.6/src/swig/typemaps/fixed-size-arrays.i
--- a/Library/modeller-10.6/src/swig/typemaps/fixed-size-arrays.i 2024-10-19 04:33:17
+++ b/Library/modeller-10.6/src/swig/typemaps/fixed-size-arrays.i 2024-10-22 10:27:05
@@ -11,16 +11,16 @@
#endif
#ifdef SWIGPYTHON
-%typemap(argout,fragment="t_output_helper") float[ANY] {
+%typemap(argout) float[ANY] {
PyObject *o = python_from_float_array($1, $1_dim0);
- $result = t_output_helper($result, o);
+ $result = SWIG_AppendOutput($result, o);
}
%typemap(in,numinputs=0) float[ANY] {
$1 = malloc(sizeof(float) * $1_dim0);
}
-%typemap(argout,fragment="t_output_helper") int[ANY] {
+%typemap(argout) int[ANY] {
PyObject *o = python_from_int_array($1, $1_dim0);
- $result = t_output_helper($result, o);
+ $result = SWIG_AppendOutput($result, o);
}
%typemap(in,numinputs=0) int[ANY] {
$1 = malloc(sizeof(int) * $1_dim0);
diff -Nur a/Library/modeller-10.6/src/swig/typemaps/python-callbacks.i b/Library/modeller-10.6/src/swig/typemaps/python-callbacks.i
--- a/Library/modeller-10.6/src/swig/typemaps/python-callbacks.i 2024-10-19 04:33:17
+++ b/Library/modeller-10.6/src/swig/typemaps/python-callbacks.i 2024-10-22 10:26:37
@@ -78,9 +78,9 @@
$1 = malloc(arg3 * sizeof(float));
}
-%typemap(argout,fragment="t_output_helper") float dervx[] {
+%typemap(argout) float dervx[] {
PyObject *o = python_from_float_array($1, arg3);
- $result = t_output_helper($result, o);
+ $result = SWIG_AppendOutput($result, o);
}
%apply float dervx[] { float dervy[] };
%apply float dervx[] { float dervz[] };
diff -Nur a/Library/modeller-10.6/src/swig/typemaps/strings.i b/Library/modeller-10.6/src/swig/typemaps/strings.i
--- a/Library/modeller-10.6/src/swig/typemaps/strings.i 2024-10-19 04:33:17
+++ b/Library/modeller-10.6/src/swig/typemaps/strings.i 2024-10-22 10:26:30
@@ -17,17 +17,17 @@
$1 = &temp;
}
#ifdef SWIGPYTHON
-%typemap(argout,fragment="t_output_helper") const char ** {
+%typemap(argout) const char ** {
if (*$1) {
%#if PY_VERSION_HEX < 0x03000000
PyObject *o = PyString_FromString(*$1);
%#else
PyObject *o = PyUnicode_FromString(*$1);
%#endif
- $result = t_output_helper($result, o);
+ $result = SWIG_AppendOutput($result, o);
}
}
-%typemap(argout,fragment="t_output_helper") char ** {
+%typemap(argout) char ** {
if (*$1) {
%#if PY_VERSION_HEX < 0x03000000
PyObject *o = PyString_FromString(*$1);
@@ -35,7 +35,7 @@
PyObject *o = PyUnicode_FromString(*$1);
%#endif
free(*$1);
- $result = t_output_helper($result, o);
+ $result = SWIG_AppendOutput($result, o);
}
}
#endif
diff -Nur a/Library/modeller-10.6/src/swig/typemaps/variable-size-arrays.i b/Library/modeller-10.6/src/swig/typemaps/variable-size-arrays.i
--- a/Library/modeller-10.6/src/swig/typemaps/variable-size-arrays.i 2024-10-19 04:33:17
+++ b/Library/modeller-10.6/src/swig/typemaps/variable-size-arrays.i 2024-10-22 10:26:51
@@ -54,9 +54,9 @@
$1 = NULL;
}
#ifdef SWIGPYTHON
-%typemap(argout,fragment="t_output_helper") (int **OUTVARARRAY, int *N_OUTVARARRAY) {
+%typemap(argout) (int **OUTVARARRAY, int *N_OUTVARARRAY) {
PyObject *o = python_from_int_array(*$1, *$2);
- $result = t_output_helper($result, o);
+ $result = SWIG_AppendOutput($result, o);
}
#endif
%typemap(freearg) (int **OUTVARARRAY, int *N_OUTVARARRAY) {
@@ -68,9 +68,9 @@
$1 = &temp1;
$2 = &temp2;
}
-%typemap(argout,fragment="t_output_helper") (float **OUTVARARRAY, int *N_OUTVARARRAY) {
+%typemap(argout) (float **OUTVARARRAY, int *N_OUTVARARRAY) {
PyObject *o = python_from_float_array(*$1, *$2);
- $result = t_output_helper($result, o);
+ $result = SWIG_AppendOutput($result, o);
}
#endif
%typemap(freearg) (float **OUTVARARRAY, int *N_OUTVARARRAY) {