计算氨基酸残基之间的键角和二面角

在蛋白质结构中,不同的角度由特定的原子位置决定。常见的原子类型包括氨基酸主链中的 Cα(α 碳)、C(羰基碳)、N(氮原子)和 O(氧原子)。为了更加清晰,下面给出几种常见角度的定义及其对应的原子类型:

  1. 计算氨基酸残基之间的键角和二面角_第1张图片

使用具体原子的坐标计算键角和二面角

1. 计算 N−Cα−C 的键角

import torch

def compute_bond_angle(N, C_alpha, C):
    # 向量N到C_alpha 和 C_alpha到C
    N_to_C_alpha = N - C_alpha
    C_alpha_to_C = C - C_alpha
    
    # 计算点积和模长
    dot_product = torch.sum(N_to_C_alpha * C_alpha_to_C, dim=-1)
    norm_N_to_C_alpha = torch.norm(N_to_C_alpha, dim=-1)
    norm_C_alpha_to_C = torch.norm(C_alpha_to_C, dim=-1)
    
    # 计算cosθ
    cos_theta = dot_product / (norm_N_to_C_alpha * norm_C_alpha_to_C + 1e-8)
    
    # 计算角度
    angle = torch.acos(torch.clamp(cos_theta, -1.0, 1.0))  # 使用clamp避免浮点误差
    return angle

# 假设N, C_alpha, C三个原子的坐标
N = torch.tensor([1.0, 2.0, 3.0])
C_alpha = torch.tensor([4.0, 5.0, 6.0])
C = torch.tensor([7.0, 8.0, 9.0])

# 计算N-Cα-C的键角
angle = compute_bond_angle(N, C_alpha, C)
print(f"N-Cα-C 键角: {angle.item()} radians")

2. 计算 Phi (ϕ) 二面角:Cn−1−Nn−Cαn​−Cn​**

import torch

def compute_dihedral_angle(N, C_alpha, C, N_next):
    # 计算向量
    N_to_C_alpha = N - C_alpha
    C_alpha_to_C = C_alpha - C
    C_to_N_next = C - N_next
    
    # 计算叉积
    N_cross_C_alpha = torch.cross(N_to_C_alpha, C_alpha_to_C)
    C_alpha_cross_N_next = torch.cross(C_alpha_to_C, C_to_N_next)
    
    # 计算叉积的模长
    norm_N_cross_C_alpha = torch.norm(N_cross_C_alpha, dim=-1)
    norm_C_alpha_cross_N_next = torch.norm(C_alpha_cross_N_next, dim=-1)
    
    # 计算点积和cosθ
    cos_theta = torch.sum(N_cross_C_alpha * C_alpha_cross_N_next, dim=-1) / (norm_N_cross_C_alpha * norm_C_alpha_cross_N_next + 1e-8)
    
    # 计算正负角度 (sinθ)
    sin_theta = torch.sum(C_alpha_to_C * torch.cross(N_cross_C_alpha, C_alpha_cross_N_next), dim=-1) / (torch.norm(C_alpha_to_C, dim=-1) + 1e-8)
    
    # 计算二面角
    angle = torch.atan2(sin_theta, cos_theta)
    return angle

# 假设N, C_alpha, C, N_next四个原子的坐标
N = torch.tensor([100.837, 118.981, 122.447])
C_alpha = torch.tensor([100.672, 119.677, 121.174])
C = torch.tensor([100.221, 118.721, 120.080])
N_next = torch.tensor([100.704, 117.479, 120.116])

# 计算Psi二面角
psi_angle = compute_dihedral_angle(N, C_alpha, C, N_next)
print(f"Psi 二面角: {psi_angle.item()} radians")

3. 计算 Psi (ψ) 二面角:Nn−Cαn−Cn−Nn+1​**

import torch

def compute_dihedral_angle(C_prev, N, C_alpha, C):
    # 计算向量
    C_prev_to_N = C_prev - N
    N_to_C_alpha = N - C_alpha
    C_alpha_to_C = C_alpha - C
    
    # 计算叉积
    C_prev_cross_N = torch.cross(C_prev_to_N, N_to_C_alpha)
    N_cross_C_alpha = torch.cross(N_to_C_alpha, C_alpha_to_C)
    
    # 计算叉积的模长
    norm_C_prev_cross_N = torch.norm(C_prev_cross_N, dim=-1)
    norm_N_cross_C_alpha = torch.norm(N_cross_C_alpha, dim=-1)
    
    # 计算点积和cosθ
    cos_theta = torch.sum(C_prev_cross_N * N_cross_C_alpha, dim=-1) / (norm_C_prev_cross_N * norm_N_cross_C_alpha + 1e-8)
    
    # 计算正负角度 (sinθ)
    sin_theta = torch.sum(N_to_C_alpha * torch.cross(C_prev_cross_N, N_cross_C_alpha), dim=-1) / (torch.norm(N_to_C_alpha, dim=-1) + 1e-8)
    
    # 计算二面角
    angle = torch.atan2(sin_theta, cos_theta)
    return angle

# 假设C_prev, N, C_alpha, C四个原子的坐标
C_prev = torch.tensor([109.476, 118.921, 129.929])
N = torch.tensor([109.941, 119.373, 127.573])
C_alpha = torch.tensor([109.557, 119.596, 126.186])
C = torch.tensor([108.904, 118.357, 125.586])

# 计算Phi二面角
phi_angle = compute_dihedral_angle(C_prev, N, C_alpha, C)
print(f"Phi 二面角: {phi_angle.item()} radians")

关键原子的定义

  • N:氨基酸的氮原子,位于肽键的氨基末端。
  • :氨基酸的α碳原子,是每个氨基酸的主链中枢原子。
  • C:羰基碳原子,位于肽键的羧基末端。
  • O:氧原子,一般用于计算氢键和空间结构相关的参数。

这些角度用于描述蛋白质主链的旋转、折叠和总体构象,是蛋白质结构预测和分子动力学模拟中的重要几何特征。

你可能感兴趣的:(pytorch,深度学习,python)