本示例代码将从一列的pdb id集合中根据结构分子类型、分辨率、结构解析方法,多肽链数目,以及总的氨基酸数目限制筛选出所需要的结构。
1. 安装 biopython
和 requests
:
pip install biopython requests
2. 网站下载并筛选pdb
from Bio.PDB import PDBList, PDBParser
import requests
# 筛选条件
RESOLUTION_THRESHOLD = 3.5 # 分辨率小于3.5Å
MAX_AMINO_ACID_COUNT = 10000 # 总氨基酸数目不超过10000
def get_pdb_metadata(pdb_id):
"""通过 PDB ID 获取结构解析方法、分辨率等信息"""
url = f"https://data.rcsb.org/rest/v1/core/entry/{pdb_id}"
response = requests.get(url)
if response.status_code != 200:
return None
data = response.json()
# 解析分辨率和方法
resolution = data.get("rcsb_entry_info", {}).get("resolution_combined", [None])[0]
method = data.get("exptl", [{}])[0].get("method")
return resolution, method
def count_chains_and_residues(pdb_file):
"""解析 PDB 文件,返回多肽链数目和总氨基酸数目"""
parser = PDBParser(QUIET=True)
structure = parser.get_structure("PDB_structure", pdb_file)
total_residues = 0
chain_count = 0
# for model in structure: 处理所有的模型
for model in structure[0]: # 只处理第一个模型