如何计算 PDB 文件中所有原子之间的距离并从中创建距离矩阵

How to calculate the distance between all atoms in a PDB file and create a distance matrix from that

我想计算 pdb 文件中所有原子之间的距离,然后根据 PDB 的结果创建一个距离矩阵。

我目前拥有所有的 x、y 和 z 坐标,但我正在努力为所有原子做这个距离计算。

距离 = sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)

例如:

原子 1 和原子 2 ,3 ,4 之间的距离...

原子 2 与原子 3、4、5 之间的距离...

对于 PDB 文件中的每个 Atom,依此类推。我是编码新手,所以任何实现最终结果的方法都会很棒。

有问题的 pdb 文件 - https://files.rcsb.org/download/6GCH.pdb

考虑到您的代码,您可以:

x_y_z_ = list()
...
         for atom in residue:
            x = (atom.coord[0]) 
            y = (atom.coord[1])
            z = (atom.coord[2])
            x_y_z_.append([x,y,z])
...
x_y_z_ = np.array(x_y_z_)
print( pairwise_distances(x_y_z_,x_y_z_) )

他们使用来自 sklearn 的 pairwise_distances,例如:

from sklearn.metrics import pairwise_distances
import numpy as np

x_y_z_ = np.array([[120,130,123],
    [655,123,666],
    [111,444,333],
    [520,876,222]])

print( pairwise_distances(x_y_z_,x_y_z_) )

out:

[[  0.         762.31423967 377.8584391  852.24233643]
[762.31423967   0.         714.04901793 884.51681725]
[377.8584391  714.04901793   0.         605.1660929 ]
[852.24233643 884.51681725 605.1660929    0.        ]]