biopython提取.cif文件的变换矩阵

蛋白质符合体结构中包含旋转矩阵和平移向量信息。要从 .mmCIF 文件中提取变换矩阵,可以解析文件中存储的 struct_oper 列表。.mmCIF 文件通常包含变换矩阵用于描述不同生物学组装、对称操作等。变换矩阵的信息通常存储在 _pdbx_struct_oper_list 标签下,例如 _pdbx_struct_oper_list.matrix[1][1] 对应矩阵的某个元素。

下面是一个解析 .mmCIF 文件中变换矩阵的代码示例:

from Bio.PDB import MMCIF2Dict
import numpy as np

# 解析变换矩阵
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/8p0j.cif'

# 解析变换矩阵信息
transformation_matrices = parse_transformation_matrices(file_path)

# 打印解析的变换矩阵和平移向量
for i, transform in enumerate(transformation_matrices):
    print(f"Transformation Matrix {i+1}:\n{transform['matrix']}")
    print(f"Translation Vector {i+1}:\n{transform['translation']}")

解析步骤说明:

  1. 使用 MMCIF2Dict

    • MMCIF2Dict 是 Biopython 的一个功能,它会将 .mmCIF 文件解析成一个字典。字典中的键是 .mmCIF 标签,值是对应的内容。
    • .mmCIF 文件中,变换矩阵通常以 _pdbx_struct_oper_list.matrix[n][m]_pdbx_struct_oper_list.vector[n] 的形式出现,分别表示矩阵的元素和平移向量。
  2. 提取变换矩阵和平移向量

    • 每个矩阵是一个 3x3 的矩阵,元素通过不同的标签(如 _pdbx_struct_oper_list.matrix[1][1])来获取。
    • 平移向量通过 _pdbx_struct_oper_list.vector[n] 获取。

输出结果及解释:

Transformation Matrix 1:
[[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]
Translation Vector 1:
[0. 0. 0.]

提取出的变换矩阵为单位矩阵(Transformation Matrix 1: [[1. 0. 0.], [0. 1. 0.], [0. 0. 1.]])且平移向量(Translation Vector 1: [0. 0. 0.])为零,表示此情况下并没有对坐标进行任何变换。因此,单体的坐标就是复合体中的坐标。

解释:

  • 单位矩阵[[1. 0. 0.], [0. 1. 0.], [0. 0. 1.]])是一个不对坐标进行旋转或缩放的矩阵,意味着坐标保持不变。
  • 平移向量[0. 0. 0.])表示没有任何位移发生,因此原点保持不变。

因此,单体的坐标不会因为这组变换矩阵而改变,复合体中的单体坐标和单体自身的坐标一致。这种情况下,复合体可能只是一个由多个单体构成的集合,且这些单体的相对位置没有通过任何变换(旋转、平移)发生变化。

相关推荐
互联网杂货铺10 分钟前
面试干货|自动化测试中常见面试题
自动化测试·软件测试·python·测试工具·面试·职场和发展·测试用例
NLP工程化1 小时前
Python 中的 Kombu 类库
python·celery·kombu
司职在下1 小时前
YAML配置文件的格式
python
rhythmcc1 小时前
【Django5】django的helloworld
python·django
右恩1 小时前
三十种编程语言庆祝【国庆节】!!!
python·dash
chusheng18401 小时前
Python 中的 HTTP 编程入门,如何使用 Requests 请求网络
网络·python·http
IOT.FIVE.NO.12 小时前
Python PDF转图片自定义输出
开发语言·python
光仔December2 小时前
【Python从入门到进阶】65、Pandas如何批量拆分与合并Excel文件
python·excel·pandas·openpyxl·xlsxwriter
hakesashou2 小时前
python是什么语言写的
python
TuringSnowy2 小时前
SparkSQL和Spark常用语句
python·spark