biopython解析mmcif文件得到组装体、链、序列、原子坐标、变换矩阵等信息

server/2024/10/15 11:37:54/

使用 Biopython 解析 .mmCIF 文件可以提取出蛋白质结构的相关信息,包括模型(model)、链(chain)、序列、原子坐标以及可能存在的变换矩阵。以下是一个完整的示例代码,展示如何使用 Biopython 的 MMCIFParser 解析 .mmCIF 文件,并提取这些信息。

示例代码

from Bio.PDB import MMCIFParser
from Bio.SeqUtils import seq1
import numpy as np# 解析 mmCIF 文件
def parse_mmcif(file_path):parser = MMCIFParser(QUIET=True)structure = parser.get_structure('structure', file_path)models_data = []for model in structure:model_data = {'model_id': model.id, 'chains': []}for chain in model:chain_data = {'chain_id': chain.id, 'residues': [], 'atoms': []}for residue in chain:if residue.id[0] == ' ':  # 确保是标准残基try:# 提取序列信息,使用 seq1 函数将三字母代码转换为单字母代码seq_residue = seq1(residue.resname)except KeyError:seq_residue = 'X'  # 若不能转换为单字母代码,则用 'X' 表示chain_data['residues'].append(seq_residue)for atom in residue:# 提取原子坐标coord = atom.coordatom_data = {'atom_name': atom.name,'coord': coord}chain_data['atoms'].append(atom_data)model_data['chains'].append(chain_data)models_data.append(model_data)return models_data# 解析变换矩阵
def parse_transformation_matrices(file_path):# 使用 MMCIF2Dict 解析 mmCIF 文件cif_dict = MMCIF2Dict.MMCIF2Dict(file_path)# 提取变换矩阵信息matrices = []# 如果 mmCIF 文件包含变换矩阵,则从 _pdbx_struct_oper_list 中提取if '_pdbx_struct_oper_list.matrix[1][1]' in cif_dict:n_matrices = len(cif_dict['_pdbx_struct_oper_list.matrix[1][1]'])  # 矩阵数量for i in range(n_matrices):# 提取矩阵元素,按行存储matrix = np.array([[float(cif_dict[f'_pdbx_struct_oper_list.matrix[1][1]'][i]),float(cif_dict[f'_pdbx_struct_oper_list.matrix[1][2]'][i]),float(cif_dict[f'_pdbx_struct_oper_list.matrix[1][3]'][i])],[float(cif_dict[f'_pdbx_struct_oper_list.matrix[2][1]'][i]),float(cif_dict[f'_pdbx_struct_oper_list.matrix[2][2]'][i]),float(cif_dict[f'_pdbx_struct_oper_list.matrix[2][3]'][i])],[float(cif_dict[f'_pdbx_struct_oper_list.matrix[3][1]'][i]),float(cif_dict[f'_pdbx_struct_oper_list.matrix[3][2]'][i]),float(cif_dict[f'_pdbx_struct_oper_list.matrix[3][3]'][i])]])# 提取平移向量translation = np.array([float(cif_dict[f'_pdbx_struct_oper_list.vector[1]'][i]),float(cif_dict[f'_pdbx_struct_oper_list.vector[2]'][i]),float(cif_dict[f'_pdbx_struct_oper_list.vector[3]'][i])])matrices.append({'matrix': matrix, 'translation': translation})return matrices# 示例调用
file_path = '/path/to/.cif/file'# 解析结构信息
structure_data = parse_mmcif(file_path)
for model in structure_data:print(f"Model ID: {model['model_id']}")for chain in model['chains']:print(f"  Chain ID: {chain['chain_id']}")print(f"  Sequence: {''.join(chain['residues'])}")for atom in chain['atoms'][:5]:  # 打印前5个原子坐标print(f"    Atom: {atom['atom_name']}, Coord: {atom['coord']}")# 解析变换矩阵信息
transformation_matrices = parse_transformation_matrices(file_path)
for i, matrix in enumerate(transformation_matrices):print(f"Transformation Matrix {i+1}:\n{matrix}")

代码说明:

  1. 结构解析部分:

    • 使用 MMCIFParser 解析 .mmCIF 文件,遍历每个模型(model)和链(chain),提取残基的序列以及原子的坐标。
    • Bio.SeqUtils 模块中的 seq1 函数,它也可以将三字母的氨基酸代码转换为单字母代码: eq1(residue.resname) 。
    • 通过遍历原子来获取坐标。
  2. 变换矩阵解析部分:

    • 变换矩阵的解析是通过读取文件并根据关键字 _pdbx_struct_oper_list.matrix 提取相关信息。变换矩阵通常以3x3的形式给出。

输出:

  • 会输出模型的 ID、链 ID、序列和部分原子坐标。
  • 如果存在变换矩阵,也会输出每个变换矩阵。

http://www.ppmy.cn/server/123208.html

相关文章

pysim-1

pySim 简介 pySim 是一个 Python 实现的软件套件,旨在帮助您管理蜂窝网络的用户身份卡,即 SIM 卡。许多 Osmocom(开源移动通信)项目都与运行私有/定制蜂窝网络有关,为这些网络提供 SIM 卡是运营这些网络的常见要求。要…

Shp2pb:Shapefile转Protocol Buffers的高效工具

Shp2pb是一个实用工具,专门用于将Shapefile(shp)格式转换为Protocol Buffers(protobuf)文件。这对于以更高效、更紧凑的方式处理地理数据特别有用。以下是关于如何安装和使用Shp2pb工具的详细说明,以及一个…

Hive优化高频面试题

文章目录 一、开启本地模式二、explain分析sql语句三、修改Fetch操作四、开启hive的严格模式五、JVM重用六、分区、分桶以及压缩七、合理设置map和ruduce的数量八、设置并行执行九、CBO优化-成本优化器十、谓词下推十一、小表join大表--使用MapJoin十二、大表join大表--使用SMB…

录屏小白福音!三款神器助你轻松上手

生活工作中,需要借助录屏功能越来越家常便饭了,选择录屏软件时,主要考虑的是软件的易用性、功能以及用户评价等因素。以下是如何进行录屏的步骤,以及推荐的四个录屏软件的使用说明:关于如何录屏的步骤操作,…

基于Springboot农耕知识查询平台JAVA|VUE|SSM计算机毕业设计源代码+数据库+LW文档+开题报告+答辩稿+部署教+代码讲解

源代码数据库LW文档(1万字以上)开题报告答辩稿 部署教程代码讲解代码时间修改教程 一、开发工具、运行环境、开发技术 开发工具 1、操作系统:Window操作系统 2、开发工具:IntelliJ IDEA或者Eclipse 3、数据库存储&#xff1a…

【计算机网络 - 基础问题】每日 3 题(二十八)

✍个人博客:Pandaconda-CSDN博客 📣专栏地址:http://t.csdnimg.cn/fYaBd 📚专栏简介:在这个专栏中,我将会分享 C 面试中常见的面试题给大家~ ❤️如果有收获的话,欢迎点赞👍收藏&…

【React】JSX基础知识

1. JSX的本质 JSX并不是标准的js语法,而是js语法扩展,浏览器本身无法识别,需要进行解析。解析工具:babel 2. JSX使用的4个高频场景 使用引号传递字符串使用js变量函数调用和方法调用使用js对象 function App() {const jsVar …

opencv学习:通过图像透视进行发票识别完整代码流程

概念: 使用OpenCV库实现图像的透视变换处理,以矫正图像中的透视失真。通过本实验,学习者将掌握图像处理的基本操作,包括图像的读取、显示、大小调整、灰度转换、二值化、轮廓检测、轮廓近似以及透视变换。 步骤: 1. …