-
Notifications
You must be signed in to change notification settings - Fork 0
/
alphafold_install.py
342 lines (220 loc) · 9.87 KB
/
alphafold_install.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
import os
import re
import sys
import requests
import subprocess as sp
from lxml import etree
PYTHON = sys.executable
PATH = os.path.dirname(__file__)
CUDA12 = '12.0'
CUDA11 = '11.0'
ALPHAFOLD_GIT_PATH = 'https://github.com/deepmind/alphafold.git'
ALPHAFOLD_VERSION = 'v2.3.2'
def get_linux_bit():
linux_bit_cmd = sp.Popen(['getconf', 'LONG_BIT'], stdout=sp.PIPE)
linux_bit = linux_bit_cmd.stdout.read().decode().replace('\n','')
return linux_bit
def list_find(lst, pattern):
for s in lst:
if re.search(pattern, s):
return s
return None
def install_make():
try:
sp.run('cmake -h', shell=True, check=True, stdout=sp.PIPE)
cmake_version_cmd = sp.run(['cmake', '--version'], stdout=sp.PIPE)
cmake_version = cmake_version_cmd.stdout.decode().split('\n')[0]
print(f'cmake had been installed: {cmake_version}')
except:
apt_install(packname='cmake')
# check
try:
sp.run(['cmake', '-h'], check=True, stdout=sp.PIPE)
print('cmake installation succeeds\n')
except:
print('cmake installation failure\n')
os.chdir(PATH)
return None
def get_make_url():
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
}
resp = requests.get(url="https://cmake.org/download/", headers=headers)
html_etree = etree.HTML(resp.text.encode('utf-8'))
filename = html_etree.xpath('/html/body/div/div/div/article/div/div/div/div/div/div[2]/div/div[1]/div/table[1]/tbody/tr[2]/td[2]/a/text()')[0]
url = html_etree.xpath('/html/body/div/div/div/article/div/div/div/div/div/div[2]/div/div[1]/div/table[1]/tbody/tr[2]/td[2]/a/@href')[0]
return url, filename
def install_hmmer():
try:
hmmer_cmd = sp.run('jackhmmer -h', shell=True, check=True, stdout=sp.PIPE)
hmmer_version = hmmer_cmd.stdout.decode().split('\n')[1]
print(f'hmmer had been installed: {hmmer_version}')
except:
# install hmmer
print('start to install hmmer')
sp.run(['sudo','apt', 'install', 'hmmer'])
print('installation completed')
# check
try:
sp.run(['jackhmmer', '-h'], check=True, stdout=sp.PIPE)
print('hmmer installation succeeds\n')
except:
print('hmmer installation failure\n')
return None
def install_hhsuite():
try:
hhsuite_cmd = sp.run(['hhblits', '-h'], check=True, stdout=sp.PIPE, stderr=sp.PIPE)
hhsuite_version = hhsuite_cmd.stdout.decode().split('\n')[0][:-1]
print(f'hh-suite had been installed: {hhsuite_version}')
except:
print('start to clone hh-suite')
sp.run(['git', 'clone', 'https://github.com/soedinglab/hh-suite.git'])
print('clone hh-suite complete')
print('start to compile and install')
sp.run(['mkdir', '-p', f'{PATH}/hh-suite/build'])
os.chdir(f'{PATH}/hh-suite/build/')
sp.run(['cmake', '-DCMAKE_INSTALL_PREFIX=/usr/local/', '..'])
sp.run(['make', '-j', '4'])
sp.run(['sudo', 'make', 'install'])
print('hh-suite installation complete ')
try:
sp.run(['hhblits', '-h'], check=True, stdout=sp.PIPE)
print('hh-suite installation succeeds\n')
except:
print('hh-suite installation failure\n')
os.chdir(PATH)
return None
def install_kalign():
try:
kalign_cmd = sp.run(['kalign', '-h'], check=True, stdout=sp.PIPE, stderr=sp.PIPE)
kalign_version = kalign_cmd.stdout.decode().split('\n')[1]
print(f'kalign had been installed: {kalign_version}')
except:
sp.run(['wget', '-O', f'{PATH}/kalign.tar.gz', '-c', 'https://github.com/TimoLassmann/kalign/archive/refs/tags/v3.3.5.tar.gz'])
# unzip
print('start to unzip kalign')
sp.run(['tar', '-zxvf', f'{PATH}/kalign.tar.gz'], stdout=sp.PIPE)
print('decompression complete')
# compile and install
dirname = list_find(os.listdir(PATH), 'kalign-')
print('start to compile and install')
sp.run(['mkdir', '-p', f'{PATH}/{dirname}/build'])
os.chdir(f'{PATH}/{dirname}/build')
sp.run(['cmake', '..'])
sp.run(['make'])
sp.run(['sudo', 'make', 'install'])
try:
sp.run(['kalign', '-h'], check=True, stdout=sp.PIPE)
print('kalign installation succeeds\n')
except:
print('kalign installation failure\n')
os.chdir(PATH)
return None
def install_openmm():
try:
# sudo apt install doxygen, swig
openmm_cmd = sp.run([PYTHON, '-m', 'openmm.testInstallation'], check=True, stdout=sp.PIPE)
openmm_version = openmm_cmd.stdout.decode().split('\n')[1]
print(f'kalign had been installed: {openmm_version}')
except:
sp.run(['wget', '-O', f'{PATH}/openmm.tar.gz', '-c','https://github.com/openmm/openmm/archive/refs/tags/8.0.0.tar.gz'])
# unzip
print('start to unzip openmm')
sp.run(['tar', '-zxvf', f'{PATH}/openmm.tar.gz'], stdout=sp.PIPE)
print('decompression complete')
# install dependency
apt_install('doxygen')
apt_install('swig')
# compile and install
dirname = list_find(os.listdir(PATH), 'openmm-')
print('start to compile and install')
sp.run(['mkdir', '-p', f'{PATH}/{dirname}/build'])
os.chdir(f'{PATH}/{dirname}/build')
sp.run(['cmake', '..'])
sp.run(['make'])
sp.run(['sudo', 'make', 'install'])
sp.run(['sudo', PYTHON, '-m', 'pip', 'install', 'numpy', 'cython'])
sp.run(['sudo', 'make', 'PythonInstall'])
try:
sp.run([PYTHON, '-m', 'openmm.testInstallation'], check=True, stdout=sp.PIPE)
print('openmm installation succeeds\n')
except:
print('openmm installation failure\n')
os.chdir(PATH)
return None
def apt_install(packname):
sp.run(['sudo', 'apt', 'install', packname])
return None
def install_pdbfixer():
print('start to install pdbfixer')
sp.run(['sudo', PYTHON, '-m', 'pip', 'install','git+http://github.com/openmm/pdbfixer.git'])
print('pdbfixer installation complete')
return None
def install_software():
install_lists = [install_make, install_hmmer, install_hhsuite, install_kalign, install_openmm, install_pdbfixer]
for func in install_lists:
func()
return None
def get_cuda_version():
nvidia_cmd = sp.run(
['nvidia-smi', '-q', '-d', 'compute'], check=True, stdout=sp.PIPE)
cuda_version_infos = nvidia_cmd.stdout.decode().split('\n')[5]
cuda_version = cuda_version_infos.split()[-1]
if cuda_version == CUDA12:
return CUDA12
elif cuda_version == CUDA11:
return CUDA11
else:
raise ValueError(f'This cuda version({cuda_version}) is not supported')
def install_packages():
print('start to install python packages')
print('start to upgrade pip')
sp.run([PYTHON, '-m', 'pip', 'install', '--user', '-U', 'pip'])
print('pip upgrade complete')
# read python package info
with open(os.path.join(PATH, 'requirements.txt'), 'r') as rf:
packages_infos = rf.readlines()
for package in packages_infos:
package = package.strip()
# TODO Conflict resolution
print(f'start to install {package}')
sp.run([PYTHON, '-m', 'pip', 'install', '--user', package])
print(f'{package} installation complete')
# install jax
cuda_version = get_cuda_version()
if cuda_version == CUDA12:
print(f'start to install JAX, CUDA version is {CUDA12}')
sp.run(f'{PYTHON} -m pip install --user "jax[cuda12_pip]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html', shell=True)
print(f'JAX installation complete')
elif cuda_version == CUDA11:
print(f'start to install JAX, CUDA version is {CUDA11}')
sp.run(f'{PYTHON} -m pip install --user "jax[cuda11_pip]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html', shell=True)
print(f'JAX installation complete')
else:
raise ValueError(f'This cuda version({cuda_version}) is not supported')
return None
def modify_code():
with open(os.path.join(PATH, 'alphafold/alphafold/relax/amber_minimize.py'), 'r') as amr:
code = amr.read()
new_code = code.replace('from simtk import openmm', 'import openmm')
new_code = new_code.replace('from simtk import unit',
'from openmm import unit')
new_code = new_code.replace('from simtk.openmm import app as openmm_app',
'from openmm import app as openmm_app')
new_code = new_code.replace(
'from simtk.openmm.app.internal.pdbstructure import PdbStructure', 'from openmm.app.internal.pdbstructure import PdbStructure')
with open(os.path.join(PATH, 'alphafold/alphafold/relax/amber_minimize.py'), 'w') as amw:
amw.write(new_code)
return None
def clone_alphafold():
print('start to git clone alphafold')
sp.run(['git', 'clone', ALPHAFOLD_GIT_PATH, '--branch', ALPHAFOLD_VERSION], cwd=PATH)
print('git clone finished')
return None
def main():
functions = [install_software, install_packages, clone_alphafold, modify_code]
for func in functions:
func()
return None
if __name__ == '__main__':
main()