EZ4Fanta commited on
Commit
605e561
·
1 Parent(s): bfadbfb
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -136,11 +136,11 @@ def handle_pdb_id_input(pdb_id):
136
  try:
137
  pdb_id = pdb_id.strip().upper()
138
  pdbl = PDBList()
139
- pdbl.retrieve_pdb_file(pdb_id, pdir=TEMP_DIR, file_format='pdb')
140
- pdb_file_path = os.path.join(TEMP_DIR, f"pdb{pdb_id}.ent")
141
- html_out, dd, structure_dict = load_structure(pdb_file_path)
142
- # 删除文件
143
- os.remove(pdb_file_path)
144
  return html_out, dd, structure_dict
145
  except Exception as e:
146
  error_message = f"<b style='color:red'>获取PDB ID {pdb_id} 失败 {e}</b>"
 
136
  try:
137
  pdb_id = pdb_id.strip().upper()
138
  pdbl = PDBList()
139
+ # 使用 TemporaryDirectory 创建临时文件夹
140
+ with TemporaryDirectory() as temp_dir:
141
+ pdbl.retrieve_pdb_file(pdb_id, pdir=temp_dir, file_format='pdb')
142
+ pdb_file_path = os.path.join(temp_dir, f"pdb{pdb_id}.ent")
143
+ html_out, dd, structure_dict = load_structure(pdb_file_path)
144
  return html_out, dd, structure_dict
145
  except Exception as e:
146
  error_message = f"<b style='color:red'>获取PDB ID {pdb_id} 失败 {e}</b>"