-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdock.py
More file actions
189 lines (152 loc) · 7.16 KB
/
dock.py
File metadata and controls
189 lines (152 loc) · 7.16 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import os
import glob
import subprocess
import sys
LIGANDS_DIR = "ligantes_sdf"
PROTEINS_DIR = "proteinas_pdb"
OUTPUT_DIR = "resultados_docagem"
VINA_EXECUTABLE = "/usr/bin/vina"
OBABEL_EXECUTABLE = "/usr/bin/obabel"
PYTHONSH_EXECUTABLE = "//home/giovanna/Documentos/autodock/MGLToolsPckgs/bin/pythonsh"
PREPARE_RECEPTOR_SCRIPT = "/home/giovanna/Documentos/autodock/MGLToolsPckgs/MGLToolsPckgs/AutoDockTools/Utilities24/prepare_receptor4.py"
PROTEINS_CONFIG = {
"claudin": {
"receptor_pdb": "CLN12PROTONADA.pdb",
"center_x": -26, "center_y": 7, "center_z": 11,
"size_x": 24, "size_y": 25, "size_z": 23
},
"Stard8": {
"receptor_pdb": "STARD8PROTONADA.pdb",
"center_x": 0, "center_y": 0, "center_z": 14,
"size_x": 21, "size_y": 31, "size_z": 20
},
"TAOK1": {
"receptor_pdb": "TAOK1PROTONADA.pdb",
"center_x": -29, "center_y": 3, "center_z": 25,
"size_x": 21, "size_y": 34, "size_z": 20
}
}
VINA_EXHAUSTIVENESS = 20
VINA_NUM_MODES = 10
VINA_CPU = 4
def prepare_receptor(pdb_file_path, output_dir):
base_name = os.path.basename(pdb_file_path).replace(".pdb", "")
pdbqt_file = os.path.join(output_dir, f"{base_name}.pdbqt")
print(f" Preparando Receptor {base_name} -> {os.path.basename(pdbqt_file)}")
if os.path.exists(pdbqt_file):
print(" -> Receptor PDBQT já existe. Pulando.")
return pdbqt_file
command = [
PYTHONSH_EXECUTABLE,
PREPARE_RECEPTOR_SCRIPT,
"-r", pdb_file_path,
"-o", pdbqt_file,
"-A", "checkhydrogens",
"-U", "nphs_lps_waters"
]
try:
subprocess.run(command, check=True, capture_output=True, text=True)
print(" -> Preparação do receptor concluída com sucesso.")
return pdbqt_file
except FileNotFoundError:
print(f"ERRO: O executável '{PYTHONSH_EXECUTABLE}' ou o script '{PREPARE_RECEPTOR_SCRIPT}' não foi encontrado.")
print("Verifique os caminhos na seção de configurações.")
sys.exit(1)
except subprocess.CalledProcessError as e:
print(f" ERRO ao preparar o receptor {base_name}:")
print(e.stderr)
return None
def prepare_ligand(sdf_file, output_dir):
base_name = os.path.basename(sdf_file).replace(".sdf", "")
pdbqt_file = os.path.join(output_dir, f"{base_name}.pdbqt")
print(f" Preparando Ligante {base_name} -> {os.path.basename(pdbqt_file)}")
if os.path.exists(pdbqt_file):
print(" -> Ligante PDBQT já existe. Pulando.")
return pdbqt_file
command = [OBABEL_EXECUTABLE, "-isdf", sdf_file, "-opdbqt", "-O", pdbqt_file, "--gen3d", "-p", "7.4", "--partialcharge", "gasteiger"]
try:
subprocess.run(command, check=True, capture_output=True, text=True)
print(" -> Preparação do ligante concluída com sucesso.")
return pdbqt_file
except subprocess.CalledProcessError as e:
print(f" ERRO ao preparar o ligante {base_name}: {e.stderr}")
return None
def run_vina_docking(ligand_pdbqt, receptor_pdbqt, protein_name, protein_info, output_base_dir):
ligand_base_name = os.path.basename(ligand_pdbqt).replace(".pdbqt", "")
protein_output_dir = os.path.join(output_base_dir, protein_name)
os.makedirs(protein_output_dir, exist_ok=True)
output_file = os.path.join(protein_output_dir, f"{ligand_base_name}_vs_{protein_name}_out.pdbqt")
log_file = os.path.join(protein_output_dir, f"{ligand_base_name}_vs_{protein_name}_log.txt")
print(f" -> Docando com {protein_name}...")
if os.path.exists(log_file):
print(" -> Resultado já existe. Pulando.")
return
command = [
VINA_EXECUTABLE, "--receptor", receptor_pdbqt, "--ligand", ligand_pdbqt,
"--out", output_file,
"--center_x", str(protein_info["center_x"]), "--center_y", str(protein_info["center_y"]),
"--center_z", str(protein_info["center_z"]), "--size_x", str(protein_info["size_x"]),
"--size_y", str(protein_info["size_y"]), "--size_z", str(protein_info["size_z"]),
"--exhaustiveness", str(VINA_EXHAUSTIVENESS), "--num_modes", str(VINA_NUM_MODES),
"--cpu", str(VINA_CPU)
]
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
with open(log_file, 'w') as f:
f.write(result.stdout)
print(f" -> Docagem com {protein_name} concluída com sucesso.")
except subprocess.CalledProcessError as e:
print(f" ERRO na docagem de {ligand_base_name} com {protein_name}:")
print(" -> Tentando com a sintaxe antiga do Vina (adicionando --log)...")
command_antiga = command + ["--log", log_file]
try:
subprocess.run(command_antiga, check=True, capture_output=True, text=True)
print(f" -> Docagem com a sintaxe antiga funcionou!")
except subprocess.CalledProcessError as e2:
print(f" -> Tentativa com a sintaxe antiga também falhou. Erro original:")
print(e.stderr)
def main():
print("Iniciando o script de docagem em lote.")
prepared_ligands_dir = os.path.join(OUTPUT_DIR, "ligantes_preparados_pdbqt")
prepared_receptors_dir = os.path.join(OUTPUT_DIR, "receptores_preparados_pdbqt")
os.makedirs(prepared_ligands_dir, exist_ok=True)
os.makedirs(prepared_receptors_dir, exist_ok=True)
print("\n--- Preparando Receptores ---")
prepared_receptors_paths = {}
for protein_name, info in PROTEINS_CONFIG.items():
pdb_path = os.path.join(PROTEINS_DIR, info["receptor_pdb"])
if not os.path.exists(pdb_path):
print(f"ERRO: Arquivo da proteína não encontrado: {pdb_path}")
continue
prepared_path = prepare_receptor(pdb_path, prepared_receptors_dir)
if prepared_path:
prepared_receptors_paths[protein_name] = prepared_path
if not prepared_receptors_paths:
print("ERRO: Nenhuma proteína pôde ser preparada. Encerrando o script.")
return
print("--- Preparação de Receptores Concluída ---\n")
sdf_files = glob.glob(os.path.join(LIGANDS_DIR, '*.sdf'))
if not sdf_files:
print(f"ERRO: Nenhum arquivo .sdf encontrado em '{LIGANDS_DIR}'.")
return
total_ligands = len(sdf_files)
print(f"Encontrados {total_ligands} ligantes para processar.")
for i, sdf_file in enumerate(sdf_files):
print("-" * 60)
print(f"Processando ligante {i+1}/{total_ligands}: {os.path.basename(sdf_file)}")
prepared_ligand_path = prepare_ligand(sdf_file, prepared_ligands_dir)
if prepared_ligand_path:
for protein_name, receptor_pdbqt_path in prepared_receptors_paths.items():
run_vina_docking(
prepared_ligand_path,
receptor_pdbqt_path,
protein_name,
PROTEINS_CONFIG[protein_name],
OUTPUT_DIR
)
else:
print(f"Pulando docagem para {os.path.basename(sdf_file)} devido a erro na preparação.")
print("-" * 60)
print("Script de docagem concluído!")
if __name__ == "__main__":
main()