Update moppit.py
Browse files
moppit.py
CHANGED
|
@@ -7,10 +7,6 @@ from models.peptide_classifiers import *
|
|
| 7 |
from utils.parsing import parse_guidance_args
|
| 8 |
args = parse_guidance_args()
|
| 9 |
|
| 10 |
-
import pdb
|
| 11 |
-
import random
|
| 12 |
-
import inspect
|
| 13 |
-
import csv
|
| 14 |
|
| 15 |
# MOO hyper-parameters
|
| 16 |
step_size = 1 / 100
|
|
@@ -29,7 +25,7 @@ tokenizer = AutoTokenizer.from_pretrained("facebook/esm2_t33_650M_UR50D")
|
|
| 29 |
target_sequence = tokenizer(target, return_tensors='pt')['input_ids'].to(device)
|
| 30 |
|
| 31 |
# Load Models
|
| 32 |
-
solver = load_solver('
|
| 33 |
|
| 34 |
score_models = []
|
| 35 |
if 'Hemolysis' in args.objectives:
|
|
@@ -45,21 +41,25 @@ if 'Half-Life' in args.objectives:
|
|
| 45 |
halflife_model = HalfLifeModel(device=device)
|
| 46 |
score_models.append(halflife_model)
|
| 47 |
if 'Affinity' in args.objectives:
|
| 48 |
-
affinity_predictor = load_affinity_predictor('
|
| 49 |
affinity_model = AffinityModel(affinity_predictor, target_sequence)
|
| 50 |
score_models.append(affinity_model)
|
| 51 |
if 'Motif' in args.objectives or 'Specificity' in args.objectives:
|
| 52 |
-
bindevaluator = load_bindevaluator('
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
score_models.append(motif_model)
|
| 55 |
|
| 56 |
-
objective_line = str(args.objectives)[1:-1].replace(' ', '').replace("'", "") + '\n'
|
| 57 |
|
| 58 |
if Path(args.output_file).exists():
|
| 59 |
with open(args.output_file, 'r') as f:
|
| 60 |
lines = f.readlines()
|
| 61 |
|
| 62 |
-
if lines[0] != objective_line:
|
| 63 |
with open(args.output_file, 'w') as f:
|
| 64 |
f.write(objective_line)
|
| 65 |
else:
|
|
@@ -83,7 +83,7 @@ for i in range(args.n_batches):
|
|
| 83 |
verbose=True,
|
| 84 |
time_grid=torch.tensor([0.0, 1.0-1e-3]),
|
| 85 |
score_models=score_models,
|
| 86 |
-
num_objectives=len(score_models) + int(
|
| 87 |
weights=args.weights)
|
| 88 |
|
| 89 |
samples = x_1.tolist()
|
|
@@ -98,8 +98,6 @@ for i in range(args.n_batches):
|
|
| 98 |
else:
|
| 99 |
candidate_scores = s(x_1)
|
| 100 |
|
| 101 |
-
if args.objectives[i] == 'Half-Life':
|
| 102 |
-
candidate_scores = 10 ** (candidate_scores * 2)
|
| 103 |
if args.objectives[i] == 'Affinity':
|
| 104 |
candidate_scores = 10 * candidate_scores
|
| 105 |
|
|
|
|
| 7 |
from utils.parsing import parse_guidance_args
|
| 8 |
args = parse_guidance_args()
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# MOO hyper-parameters
|
| 12 |
step_size = 1 / 100
|
|
|
|
| 25 |
target_sequence = tokenizer(target, return_tensors='pt')['input_ids'].to(device)
|
| 26 |
|
| 27 |
# Load Models
|
| 28 |
+
solver = load_solver('/scratch/pranamlab/tong/checkpoints/MOG-DFM/ckpt/peptide/cnn_epoch200_lr0.0001_embed512_hidden256_loss3.1051.ckpt', vocab_size, device)
|
| 29 |
|
| 30 |
score_models = []
|
| 31 |
if 'Hemolysis' in args.objectives:
|
|
|
|
| 41 |
halflife_model = HalfLifeModel(device=device)
|
| 42 |
score_models.append(halflife_model)
|
| 43 |
if 'Affinity' in args.objectives:
|
| 44 |
+
affinity_predictor = load_affinity_predictor('/scratch/pranamlab/tong/checkpoints/MOG-DFM/classifier_ckpt/binding_affinity_unpooled.pt', device)
|
| 45 |
affinity_model = AffinityModel(affinity_predictor, target_sequence)
|
| 46 |
score_models.append(affinity_model)
|
| 47 |
if 'Motif' in args.objectives or 'Specificity' in args.objectives:
|
| 48 |
+
bindevaluator = load_bindevaluator('/scratch/pranamlab/tong/checkpoints/BindEvaluator/model_path/finetuned_BindEvaluator.ckpt', device)
|
| 49 |
+
if 'Specificity' in args.objectives:
|
| 50 |
+
motif_penalty = True
|
| 51 |
+
else:
|
| 52 |
+
motif_penalty = False
|
| 53 |
+
motif_model = MotifModel(bindevaluator, target_sequence, motifs, penalty=motif_penalty)
|
| 54 |
score_models.append(motif_model)
|
| 55 |
|
| 56 |
+
objective_line = "Binder," + str(args.objectives)[1:-1].replace(' ', '').replace("'", "") + '\n'
|
| 57 |
|
| 58 |
if Path(args.output_file).exists():
|
| 59 |
with open(args.output_file, 'r') as f:
|
| 60 |
lines = f.readlines()
|
| 61 |
|
| 62 |
+
if len(lines) == 0 or lines[0] != objective_line:
|
| 63 |
with open(args.output_file, 'w') as f:
|
| 64 |
f.write(objective_line)
|
| 65 |
else:
|
|
|
|
| 83 |
verbose=True,
|
| 84 |
time_grid=torch.tensor([0.0, 1.0-1e-3]),
|
| 85 |
score_models=score_models,
|
| 86 |
+
num_objectives=len(score_models) + int(motif_penalty),
|
| 87 |
weights=args.weights)
|
| 88 |
|
| 89 |
samples = x_1.tolist()
|
|
|
|
| 98 |
else:
|
| 99 |
candidate_scores = s(x_1)
|
| 100 |
|
|
|
|
|
|
|
| 101 |
if args.objectives[i] == 'Affinity':
|
| 102 |
candidate_scores = 10 * candidate_scores
|
| 103 |
|