Repository navigation
Expand file tree
/
Copy pathrun_openfold_benchmark_monomer_wrapper.py
More file actions
262 lines (236 loc) · 9.28 KB
/
Copy pathrun_openfold_benchmark_monomer_wrapper.py
File metadata and controls
262 lines (236 loc) · 9.28 KB
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
import argparse
from argparse import Namespace
import logging
import math
import numpy as np
import pandas as pd
import os
import shutil
import json
from collections import Counter
import re
import glob
import sys
from datetime import date
import itertools
import time
import ml_collections as mlc
from typing import Tuple, List, Mapping, Optional, Sequence, Any, MutableMapping, Union
from scripts.utils import add_data_args
from run_openfold_benchmark_monomer import (
run_msa_mask
)
FeatureDict = MutableMapping[str, np.ndarray]
logger = logging.getLogger('wrapper')
logger.setLevel(logging.INFO)
logger.propagate = False
formatter = logging.Formatter('%(asctime)s - %(filename)s - %(levelname)s : %(message)s')
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
file_handler = logging.FileHandler('./benchmark_monomer.log', mode='w')
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
TRACING_INTERVAL = 50
asterisk_line = '******************************************************************************'
def gen_args(alignment_dir, output_dir_base, openfold_weights_dir, af_weights_dir, template_mmcif_dir, use_templates, use_af_weights, msa_mask_fraction, num_predictions_per_model, overwrite_pred):
base_parser = argparse.ArgumentParser()
base_parser.add_argument(
"--benchmark_method", type=str,
)
base_parser.add_argument(
"--use_templates", type=bool
)
base_parser.add_argument(
"--fasta_file", type=str, default=None,
help="Path to FASTA file, one sequence per file. By default assumes that .fasta file is located in alignment_dir "
)
base_parser.add_argument(
"--template_mmcif_dir", type=str,
help="Directory containing mmCIF files to search for templates"
)
base_parser.add_argument(
"--alignment_dir", type=str, default=None,
help="""Path to alignment directory. If provided, alignment computation
is skipped and database path arguments are ignored."""
)
base_parser.add_argument(
"--output_dir_base", type=str, default=os.getcwd(),
help="""Name of the directory in which to output the prediction""",
)
base_parser.add_argument(
"--model_device", type=str, default="cpu",
help="""Name of the device on which to run the model. Any valid torch
device name is accepted (e.g. "cpu", "cuda:0")"""
)
base_parser.add_argument(
"--config_preset", type=str, default="model_1",
help="""Name of a model config preset defined in openfold/config.py"""
)
base_parser.add_argument(
"--jax_param_path", type=str, default=None,
help="""Path to JAX model parameters. If None, and openfold_checkpoint_path
is also None, parameters are selected automatically according to
the model name from openfold/resources/params"""
)
base_parser.add_argument(
"--openfold_checkpoint_path", type=str, default=None,
help="""Path to OpenFold checkpoint. Can be either a DeepSpeed
checkpoint directory or a .pt file"""
)
base_parser.add_argument(
"--msa_mask_fraction", type=float, default=0.15
)
base_parser.add_argument(
"--num_predictions_per_model", type=int, default=10
)
base_parser.add_argument(
"--save_outputs", action="store_true", default=False,
help="Whether to save all model outputs, including embeddings, etc."
)
base_parser.add_argument(
"--cpus", type=int, default=4,
help="""Number of CPUs with which to run alignment tools"""
)
base_parser.add_argument(
"--preset", type=str, default='full_dbs',
choices=('reduced_dbs', 'full_dbs')
)
base_parser.add_argument(
"--output_postfix", type=str, default=None,
help="""Postfix for output prediction filenames"""
)
base_parser.add_argument(
"--data_random_seed", type=str, default=None
)
base_parser.add_argument(
"--multimer_ri_gap", type=int, default=1,
help="""Residue index offset between multiple sequences, if provided"""
)
base_parser.add_argument(
"--trace_model", action="store_true", default=False,
help="""Whether to convert parts of each model to TorchScript.
Significantly improves runtime at the cost of lengthy
'compilation.' Useful for large batch jobs."""
)
base_parser.add_argument(
"--subtract_plddt", action="store_true", default=False,
help=""""Whether to output (100 - pLDDT) in the B-factor column instead
of the pLDDT itself"""
)
base_parser.add_argument(
"--long_sequence_inference", action="store_true", default=False,
help="""enable options to reduce memory usage at the cost of speed, helps longer sequences fit into GPU memory, see the README for details"""
)
base_parser.add_argument(
"--cif_output", action="store_true", default=False,
help="Output predicted models in ModelCIF format instead of PDB format (default)"
)
base_parser.add_argument(
"--openfold_weights_dir", type=str,
help="Directory in which openfold weights are saved"
)
base_parser.add_argument(
"--af_weights_dir", type=str,
help="Directory in which AF weights are saved"
)
base_parser.add_argument(
"--overwrite_pred", action="store_true", default=False
)
add_data_args(base_parser)
args = base_parser.parse_args()
if use_templates:
if not(use_af_weights):
openfold_checkpoint_path = '%s/finetuning_ptm_2.pt' % openfold_weights_dir
config_preset = 'model_1_ptm'
else:
jax_param_path = '%s/params_model_1_ptm.npz' % af_weights_dir
config_preset = 'model_1_ptm'
else:
if not(use_af_weights):
openfold_checkpoint_path = '%s/finetuning_no_templ_ptm_1.pt' % openfold_weights_dir
config_preset = 'model_3_ptm'
else:
jax_param_path = '%s/params_model_3_ptm.npz' % af_weights_dir
config_preset = 'model_3_ptm'
args.benchmark_method = 'msa_mask'
args.use_templates = use_templates
args.alignment_dir = alignment_dir
args.output_dir_base = output_dir_base
args.template_mmcif_dir = template_mmcif_dir
args.config_preset = config_preset
if not(use_af_weights):
args.openfold_checkpoint_path = openfold_checkpoint_path
else:
args.jax_param_path = jax_param_path
args.model_device = 'cuda:0'
args.msa_mask_fraction = msa_mask_fraction
args.num_predictions_per_model = num_predictions_per_model
args.overwrite_pred = overwrite_pred
if(args.jax_param_path is None and args.openfold_checkpoint_path is None):
args.jax_param_path = os.path.join(
"openfold", "resources", "params",
"params_" + args.config_preset + ".npz"
)
if(args.model_device == "cpu" and torch.cuda.is_available()):
logging.warning(
"""The model is being run on CPU. Consider specifying
--model_device for better performance"""
)
return args
if __name__ == "__main__":
supp_parser = argparse.ArgumentParser()
supp_parser.add_argument(
"--alignment_dir", type=str, required=True,
help="Path to alignment directory"
)
supp_parser.add_argument(
"--output_dir_base", type=str, default=os.getcwd(),
help="Name of the directory in which to output the prediction"
)
supp_parser.add_argument(
"--openfold_weights_dir", type=str,
help="Directory in which openfold weights are saved"
)
supp_parser.add_argument(
"--af_weights_dir", type=str,
help="Directory in which AF weights are saved"
)
supp_parser.add_argument(
"--template_mmcif_dir", type=str,
help="Path to template mmcif dir"
)
supp_parser.add_argument(
"--use_templates", action="store_true", default=False,
help="Whether to use templates for structure prediction"
)
supp_parser.add_argument(
"--use_af_weights", type=bool, default=True,
help="Uses AlphaFold weights if True, otherwise uses OpenFold weights"
)
supp_parser.add_argument(
"--msa_mask_fraction", type=float, default=0.15
)
supp_parser.add_argument(
"--num_predictions_per_model", type=int, default=100
)
supp_parser.add_argument(
"--overwrite_pred", action="store_true", default=False
)
supp_args, _ = supp_parser.parse_known_args()
args = gen_args(
alignment_dir=supp_args.alignment_dir,
output_dir_base=supp_args.output_dir_base,
openfold_weights_dir=supp_args.openfold_weights_dir,
af_weights_dir=supp_args.af_weights_dir,
template_mmcif_dir=supp_args.template_mmcif_dir,
use_templates=supp_args.use_templates,
use_af_weights=supp_args.use_af_weights,
msa_mask_fraction=supp_args.msa_mask_fraction,
num_predictions_per_model=supp_args.num_predictions_per_model,
overwrite_pred=supp_args.overwrite_pred
)
logger.info("RUNNING %s" % args.output_dir_base)
run_msa_mask(args)