-
Notifications
You must be signed in to change notification settings - Fork 23
/
generate.py
executable file
·61 lines (52 loc) · 1.63 KB
/
generate.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
import torch
import torch.nn as nn
import torch.optim as optim
import torch.optim.lr_scheduler as lr_scheduler
from torch.utils.data import DataLoader
import json
import csv
import math, random, sys
import numpy as np
import argparse
import os
from bindgen import *
from tqdm import tqdm
def build_model(args):
if args.att_refine:
model = AttRefineDecoder(args)
elif args.no_target:
model = UncondRefineDecoder(args)
elif args.sequence:
model = SequenceDecoder(args)
else:
model = CondRefineDecoder(args)
return model.cuda()
if __name__ == "__main__":
model_ckpt, _, args = torch.load(sys.argv[1])
model = build_model(args)
model.load_state_dict(model_ckpt)
model.eval()
data = AntibodyComplexDataset(
sys.argv[2],
cdr_type=args.cdr,
L_target=args.L_target,
)
torch.manual_seed(args.seed)
np.random.seed(args.seed)
random.seed(args.seed)
batch_size = 250
num_decode = 1000
topk = sys.argv[3]
print('PDB', 'Native', 'Designed', 'Perplexity')
with torch.no_grad():
for ab in tqdm(data):
new_cdrs, new_ppl = [], []
for _ in range(num_decode // batch_size):
_, epitope, surface = make_batch([ab] * batch_size)
out = model.generate(epitope, surface)
new_cdrs.extend(out.handle)
new_ppl.extend(out.ppl.tolist())
orig_cdr = ab['binder_seq']
new_res = sorted(zip(new_cdrs, new_ppl), key=lambda x:x[1])
for cdr,ppl in new_res[:topk]:
print(ab['pdb'], orig_cdr, cdr, '%.3f' % ppl)