[英]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)
例如:
Atom 1 和 Atom 2,3,4 之間的距離...
Atom 2 和 Atom 3, 4, 5 之間的距離...
對於 PDB 文件中的每個 Atom,依此類推。 我是編碼新手,所以任何實現最終結果的方法都會很棒。
目前我的代碼是:
from Bio.PDB.PDBParser import PDBParser
import Bio.PDB
parser = PDBParser()
structure = parser.get_structure("6gch", "6gch.pdb")
"""This gets the coordinates for all the atoms"""
for model in structure:
for chain in model:
for residue in chain:
for atom in residue:
x = (atom.coord[0])
y = (atom.coord[1])
z = (atom.coord[2])
all_atom_coords = atom.coord
有問題的 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. ]]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.