config.py 8.44 KB
Newer Older
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
1
2
3
4
import copy
import ml_collections as mlc


5
6
7
8
9
10
11
12
13
def set_inf(c, inf):
    for k, v in c.items():
        if(isinstance(v, mlc.ConfigDict)):
            set_inf(v, inf)
        elif(k == "inf"):
            c[k] = inf


def model_config(name, train=False, low_prec=False):
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
14
    c = copy.deepcopy(config)
15
16
17
18
19
    if(name == "model_1"):
        pass
    elif(name == "model_2"):
        pass
    elif(name == "model_3"):
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
20
21
22
23
24
        c.model.template.enabled = False
    elif(name == "model_4"):
        c.model.template.enabled = False
    elif(name == "model_5"):
        c.model.template.enabled = False
25
26
    elif(name == "model_1_ptm"):
        c.model.heads.tm.enabled = True
27
        c.loss.tm.weight = 0.1
28
29
    elif(name == "model_2_ptm"):
        c.model.heads.tm.enabled = True
30
        c.loss.tm.weight = 0.1
31
32
33
    elif(name == "model_3_ptm"):
        c.model.template.enabled = False
        c.model.heads.tm.enabled = True
34
        c.loss.tm.weight = 0.1
35
36
37
    elif(name == "model_4_ptm"):
        c.model.template.enabled = False
        c.model.heads.tm.enabled = True
38
        c.loss.tm.weight = 0.1
39
40
41
    elif(name == "model_5_ptm"):
        c.model.template.enabled = False
        c.model.heads.tm.enabled = True
42
        c.loss.tm.weight = 0.1
43
44
45
46
    else:
        raise ValueError("Invalid model name")

    if(train):
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
47
        c.globals.blocks_per_ckpt = 1
48
        c.globals.chunk_size = None
49
50
51
52
53
54

    if(low_prec):
        c.globals.eps = 1e-4
        # If we want exact numerical parity with the original, inf can't be
        # a global constant
        set_inf(c, 1e4)
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
55
56
    
    return c
57

Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
58

59
60
61
62
63
64
65
66
67
c_z = mlc.FieldReference(128, field_type=int)
c_m = mlc.FieldReference(256, field_type=int)
c_t = mlc.FieldReference(64, field_type=int)
c_e = mlc.FieldReference(64, field_type=int)
c_s = mlc.FieldReference(384, field_type=int)
blocks_per_ckpt = mlc.FieldReference(None, field_type=int)
chunk_size = mlc.FieldReference(4, field_type=int)
aux_distogram_bins = mlc.FieldReference(64, field_type=int)
eps = mlc.FieldReference(1e-8, field_type=float)
68

Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
69
config = mlc.ConfigDict({
70
71
72
73
    # Recurring FieldReferences that can be changed globally here
    "globals": {
        "blocks_per_ckpt": blocks_per_ckpt,
        "chunk_size": chunk_size,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
74
75
76
77
78
        "c_z": c_z,
        "c_m": c_m,
        "c_t": c_t,
        "c_e": c_e,
        "c_s": c_s,
79
80
81
82
        "eps": eps,
    },
    "model": {
        "no_cycles": 4,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
        "_mask_trans": False,
        "input_embedder": {
            "tf_dim": 22,
            "msa_dim": 49,
            "c_z": c_z,
            "c_m": c_m,
            "relpos_k": 32,
        },
        "recycling_embedder": {
            "c_z": c_z,
            "c_m": c_m, 
            "min_bin": 3.25,
            "max_bin": 20.75,
            "no_bins": 15,
97
            "inf": 1e8,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
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
        },
        "template": {
            "distogram": {
                "min_bin": 3.25,
                "max_bin": 50.75,
                "no_bins": 39,
            },
            "template_angle_embedder": {
                # DISCREPANCY: c_in is supposed to be 51.
                "c_in": 57,
                "c_out": c_m,
            },
            "template_pair_embedder": {
                "c_in": 88,
                "c_out": c_t,
            },
            "template_pair_stack": {
                "c_t": c_t, 
                # DISCREPANCY: c_hidden_tri_att here is given in the supplement
                # as 64. In the code, it's 16.
                "c_hidden_tri_att": 16, 
                "c_hidden_tri_mul": 64,
                "no_blocks": 2, 
                "no_heads": 4, 
                "pair_transition_n": 2, 
                "dropout_rate": 0.25,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
124
                "blocks_per_ckpt": blocks_per_ckpt,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
125
                "chunk_size": chunk_size,
126
                "inf": 1e5,#1e9,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
127
128
129
130
131
132
133
134
135
            },
            "template_pointwise_attention": {
                "c_t": c_t, 
                "c_z": c_z, 
                # DISCREPANCY: c_hidden here is given in the supplement as 64.
                # It's actually 16.
                "c_hidden": 16, 
                "no_heads": 4,
                "chunk_size": chunk_size,
136
                "inf": 1e5,#1e9,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
137
            },
138
            "inf": 1e5,#1e9,
139
            "eps": eps,#1e-6,
140
            "enabled": True,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
            "embed_angles": True,
        },
        "extra_msa": {
            "extra_msa_embedder": {
                "c_in": 25,
                "c_out": c_e,
            },
            "extra_msa_stack": {
                "c_m": c_e,
                "c_z": c_z,
                "c_hidden_msa_att": 8,
                "c_hidden_opm": 32,
                "c_hidden_mul": 128,
                "c_hidden_pair_att": 32,
                "no_heads_msa": 8,
                "no_heads_pair": 4,
                "no_blocks": 4,
                "transition_n": 4,
                "msa_dropout": 0.15,
                "pair_dropout": 0.25,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
161
                "blocks_per_ckpt": blocks_per_ckpt,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
162
                "chunk_size": chunk_size,
163
                "inf": 1e5,#1e9,
164
                "eps": eps,#1e-10,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
165
            },
166
            "enabled": True,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
        },
        "evoformer_stack": {
            "c_m": c_m,
            "c_z": c_z,
            "c_hidden_msa_att": 32,
            "c_hidden_opm": 32,
            "c_hidden_mul": 128,
            "c_hidden_pair_att": 32,
            "c_s": c_s,
            "no_heads_msa": 8,
            "no_heads_pair": 4,
            "no_blocks": 48,
            "transition_n": 4,
            "msa_dropout": 0.15,
            "pair_dropout": 0.25,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
182
            "blocks_per_ckpt": blocks_per_ckpt,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
183
            "chunk_size": chunk_size,
184
            "inf": 1e5,#1e9,
185
            "eps": eps,#1e-10,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
186
187
188
189
190
191
192
193
194
195
        },
        "structure_module": {
            "c_s": c_s, 
            "c_z": c_z,
            "c_ipa": 16,
            "c_resnet": 128,
            "no_heads_ipa": 12,
            "no_qk_points": 4,
            "no_v_points": 8,
            "dropout_rate": 0.1,
196
            "no_blocks": 8,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
197
198
199
200
            "no_transition_layers": 1,
            "no_resnet_blocks": 2,
            "no_angles": 7,
            "trans_scale_factor": 10,
201
            "epsilon": eps,#1e-12,
202
            "inf": 1e5,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
203
204
205
206
207
208
209
210
211
212
213
        },
        "heads": {
            "lddt": {
                "no_bins": 50,
                "c_in": c_s,
                "c_hidden": 128,
            },
            "distogram": {
                "c_z": c_z,
                "no_bins": aux_distogram_bins,
            },
214
            "tm": {
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
215
216
                "c_z": c_z,
                "no_bins": aux_distogram_bins,
217
                "enabled": False,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
            },
            "masked_msa": {
                "c_m": c_m,
                "c_out": 23,
            },
            "experimentally_resolved": {
                "c_s": c_s,
                "c_out": 37,
            },
        },
    },
    "relax": {
        "max_iterations": 0, # no max
        "tolerance": 2.39,
        "stiffness": 10.0,
        "max_outer_iterations": 20,
        "exclude_residues": [],
    },
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
236
237
238
239
240
    "loss": {
        "distogram": {
            "min_bin": 2.3125, 
            "max_bin": 21.6875, 
            "no_bins": 64, 
241
            "eps": eps,#1e-6,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
242
            "weight": 0.3, 
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
243
244
        },
        "experimentally_resolved": {
245
            "eps": eps,#1e-8,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
246
247
248
249
250
251
252
253
254
            "min_resolution": 0.1,
            "max_resolution": 3.0,
            "weight": 0.,
        },
        "fape": {
            "backbone": { 
                "clamp_distance": 10.,
                "loss_unit_distance": 10.,
                "weight": 0.5,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
255
            },
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
256
257
258
259
            "sidechain": {
                "clamp_distance": 10.,
                "length_scale": 10.,
                "weight": 0.5,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
260
            },
261
            "eps": 1e-4,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
262
263
264
265
266
267
            "weight": 1.0,
        },
        "lddt": {
            "min_resolution": 0.1,
            "max_resolution": 3.0,
            "cutoff": 15.,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
268
            "no_bins": 50,
269
            "eps": eps,#1e-10,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
270
            "weight": 0.01,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
271
272
        },
        "masked_msa": {
273
            "eps": eps,#1e-8,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
274
            "weight": 2.0,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
275
276
277
278
        },
        "supervised_chi": {
            "chi_weight": 0.5,
            "angle_norm_weight": 0.01,
279
            "eps": eps,#1e-6,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
280
            "weight": 1.0,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
281
282
        },
        "violation": {
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
283
284
            "violation_tolerance_factor": 12.0,
            "clash_overlap_tolerance": 1.5,
285
            "eps": eps,#1e-6,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
286
287
            "weight": 0.,
        },
288
289
290
291
292
293
        "tm": {
            "max_bin": 31,
            "no_bins": 64,
            "min_resolution": 0.1,
            "max_resolution": 3.0,
            "eps": eps,#1e-8,
294
            "weight": 0.,
295
        },
296
        "eps": eps,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
297
    },
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
298
})