-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest3.py
83 lines (65 loc) · 2.55 KB
/
test3.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import json
import os
import sys
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.extend([current_dir, parent_dir])
# Import for protenix
from runner.inference import infer_predict
from runner.msa_search import contain_msa_res, msa_search_update
from src.task import PredictTask
from src.model import (
get_default_runner,
cif_to_pdb,
convert_seq_to_json,
)
def main(device_id: int = 0):
result_dir = "./protenix_test_dir"
# Copy the result from output_temp_dir to result_dir
if not os.path.exists(result_dir):
os.makedirs(result_dir)
task = PredictTask(
seq="MAEVIRSSAFWRSFPIFEEFDSETLCELSGIASYRKWSAGTVIFQRGDQGDYMIVVVSGRIKLSLFTPQGRELMLRQHEAGALFGEMALLDGQPRSADATAVTAAEGYVIGKKDFLALITQRPKTAEAVIRFLCAQLRDTTDRLETIALYDLNARVARFFLATLRQIHGSEMPQSANLRLTLSQTDIASILGASRPKVNRAILSLEESGAIKRADGIICCNVGRLLSIADPEEDLEHHHHHHHH",
task_type="plddt",
)
seeds = [101]
temp_outdir = "./test_protenix"
input_json_temp_dir = os.path.join(temp_outdir, "input_json")
os.makedirs(input_json_temp_dir, exist_ok=True)
output_temp_dir = os.path.join(temp_outdir, "output")
os.makedirs(output_temp_dir, exist_ok=True)
infer_json = os.path.join(input_json_temp_dir, f"input_{task.id}.json")
# save json to temp_dir
with open(infer_json, "w") as f:
json.dump(convert_seq_to_json(task), f)
model = get_default_runner(
seeds=seeds, device=f"cuda:{device_id}", dump_dir=output_temp_dir
)
configs = model.configs
infer_json = msa_search_update(infer_json, input_json_temp_dir)
configs["input_json_path"] = infer_json
if not contain_msa_res(infer_json):
raise RuntimeError(
f"`{infer_json}` has no msa result for `proteinChain`, please add first."
)
infer_predict(model, configs)
# result dump to
protenix_cif_path = os.path.join(
output_temp_dir,
task.id,
f"seed_{configs['seeds'][0]}",
"predictions",
f"{task.id}_seed_{configs['seeds'][0]}_sample_0.cif",
)
protenix_pdb_path = os.path.join(output_temp_dir, f"test_{task.id}.pdb")
print(f"[{task.id}] writing pdb to {protenix_pdb_path}")
cif_to_pdb(protenix_cif_path, protenix_pdb_path)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Run Protenix inference.")
parser.add_argument(
"--device_id", type=int, default=0, help="CUDA device ID to use."
)
args = parser.parse_args()
device_id = args.device_id
main(device_id)