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


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

    if(train):
        c.globals.model.blocks_per_ckpt = 1
        c.globals.chunk_size = None
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
41
42
    
    return c
43

Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
44

45
46
47
48
49
50
51
52
53
54
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)
inf = mlc.FieldReference(1e8, field_type=float)
55

Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
56
config = mlc.ConfigDict({
57
58
59
60
    # 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
61
62
63
64
65
        "c_z": c_z,
        "c_m": c_m,
        "c_t": c_t,
        "c_e": c_e,
        "c_s": c_s,
66
67
68
69
70
        "eps": eps,
        "inf": inf,
    },
    "model": {
        "no_cycles": 4,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        "_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,
85
            "inf": inf,#1e8,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
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
        },
        "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
112
                "blocks_per_ckpt": blocks_per_ckpt,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
113
                "chunk_size": chunk_size,
114
                "inf": inf,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
115
116
117
118
119
120
121
122
123
            },
            "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,
124
                "inf": inf,#1e-9,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
125
            },
126
127
            "inf": inf,
            "eps": eps,#1e-6,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
            "enabled": True,
            "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
149
                "blocks_per_ckpt": blocks_per_ckpt,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
150
                "chunk_size": chunk_size,
151
152
                "inf": inf,#1e9,
                "eps": eps,#1e-10,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
153
            },
154
            "enabled": True,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
        },
        "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
170
            "blocks_per_ckpt": blocks_per_ckpt,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
171
            "chunk_size": chunk_size,
172
173
            "inf": inf,#1e9,
            "eps": eps,#1e-10,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
174
175
176
177
178
179
180
181
182
183
        },
        "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,
184
            "no_blocks": 8,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
185
186
187
188
            "no_transition_layers": 1,
            "no_resnet_blocks": 2,
            "no_angles": 7,
            "trans_scale_factor": 10,
189
190
            "epsilon": eps,#1e-12,
            "inf": inf,#1e5,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
191
192
193
194
195
196
197
198
199
200
201
        },
        "heads": {
            "lddt": {
                "no_bins": 50,
                "c_in": c_s,
                "c_hidden": 128,
            },
            "distogram": {
                "c_z": c_z,
                "no_bins": aux_distogram_bins,
            },
202
            "tm": {
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
203
204
                "c_z": c_z,
                "no_bins": aux_distogram_bins,
205
                "enabled": False,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
            },
            "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
224
225
226
227
228
    "loss": {
        "distogram": {
            "min_bin": 2.3125, 
            "max_bin": 21.6875, 
            "no_bins": 64, 
229
230
            "eps": eps,#1e-6,
            "weight": 0.,#0.3, 
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
231
232
        },
        "experimentally_resolved": {
233
            "eps": eps,#1e-8,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
234
235
236
237
238
239
240
241
242
            "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
243
            },
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
244
245
246
247
            "sidechain": {
                "clamp_distance": 10.,
                "length_scale": 10.,
                "weight": 0.5,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
248
            },
249
            "eps": 1e-4,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
250
251
252
253
254
255
            "weight": 1.0,
        },
        "lddt": {
            "min_resolution": 0.1,
            "max_resolution": 3.0,
            "cutoff": 15.,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
256
            "no_bins": 50,
257
258
            "eps": eps,#1e-10,
            "weight": 0.,#0.01,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
259
260
        },
        "masked_msa": {
261
262
            "eps": eps,#1e-8,
            "weight": 0.,#2.0,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
263
264
265
266
        },
        "supervised_chi": {
            "chi_weight": 0.5,
            "angle_norm_weight": 0.01,
267
268
            "eps": eps,#1e-6,
            "weight": 0.,#1.0,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
269
270
        },
        "violation": {
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
271
272
            "violation_tolerance_factor": 12.0,
            "clash_overlap_tolerance": 1.5,
273
            "eps": eps,#1e-6,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
274
275
            "weight": 0.,
        },
276
277
278
279
280
281
        "tm": {
            "max_bin": 31,
            "no_bins": 64,
            "min_resolution": 0.1,
            "max_resolution": 3.0,
            "eps": eps,#1e-8,
282
            "weight": 0.,
283
        },
284
        "eps": eps,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
285
    },
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
286
})