-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun_af2_step3.py
95 lines (75 loc) · 2.59 KB
/
run_af2_step3.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
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
#-*- coding:utf-8 -*-
###############################################
#
#
# Run AlphaFold2 step by step
# (https://github.com/deepmind/alphafold)
# Author: Pan Li ([email protected])
# @ Shuimu BioScience
# https://www.shuimubio.com/
#
#
################################################
#
#
# AlphaFold2 Step 3 -- Relax models
# Usage: run_af2_step3.py /path/to/features.pkl /path/to/result_model.pkl /path/to/output.pdb
#
#
import json
import os
import pathlib
import pickle
import random
import shutil
import sys
import time
import gzip
from typing import Dict, Union, Optional
import numpy as np
import argparse
import configparser
os.environ['TF_FORCE_UNIFIED_MEMORY'] = '1'
os.environ['XLA_PYTHON_CLIENT_MEM_FRACTION'] = '4.0'
cur_path = pathlib.Path(__file__).parent.resolve()
ini_config = configparser.ConfigParser(allow_no_value=True)
assert len(ini_config.read(os.path.join(cur_path, 'config.ini'))) > 0, "Read config.ini failed"
sys.path.insert(0, ini_config['ALPHAFOLD2']['alphafold_path'])
from alphafold.common import protein
from alphafold.common import residue_constants
from alphafold.relax import relax
parser = argparse.ArgumentParser(description='AlphaFold2 Step 3 -- Relax models')
parser.add_argument('model_pdb', metavar='model_pdb', type=str, help='The result_model.pdb file generated by AlphaFold2 step 2.')
parser.add_argument('output_pdb_file', metavar='output_pdb_file', type=str, help='The PDB file to save the relaxed models.')
args = parser.parse_args()
if os.path.exists(args.output_pdb_file):
print(f"Info: {args.output_pdb_file} exists, please delete and try again")
exit(0)
######################
## Define the relaxer
######################
RELAX_MAX_ITERATIONS = 0
RELAX_ENERGY_TOLERANCE = 2.39
RELAX_STIFFNESS = 10.0
RELAX_EXCLUDE_RESIDUES = []
RELAX_MAX_OUTER_ITERATIONS = 3
use_gpu_relax=False # It is easy to Minimization failed using GPU
amber_relaxer = relax.AmberRelaxation(
max_iterations=RELAX_MAX_ITERATIONS,
tolerance=RELAX_ENERGY_TOLERANCE,
stiffness=RELAX_STIFFNESS,
exclude_residues=RELAX_EXCLUDE_RESIDUES,
max_outer_iterations=RELAX_MAX_OUTER_ITERATIONS,
use_gpu=use_gpu_relax)
######################
## Define Protein object
######################
pdb_string = open(args.model_pdb).read()
unrelaxed_protein = protein.from_pdb_string(pdb_string)
######################
## Start to relax
######################
print(f"Relax model {args.model_pdb}", flush=True)
relaxed_pdb_str, _, _ = amber_relaxer.process(prot=unrelaxed_protein)
print( relaxed_pdb_str, file=open(args.output_pdb_file, 'w') )