如何计算MDtraj中原子对之间的距离?

2024-05-16 00:48:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想计算两个氢原子之间的距离。我想使用MDtraj模块https://mdtraj.org/1.9.4/api/generated/mdtraj.compute_distances.html来实现这一点

但我得到了一个错误: enter image description here

这是密码

coord = md.load('alanine-dipeptide-nowater.pdb')
h1 = np.array([(4.259, 24,471, 0.81), (-0.008, 23.118, -0.407)])

md.compute_distances(coord, h1)

h1是第一个氢原子和第二个氢原子的坐标。 数据文件在这里https://github.com/mahesh27dx/molecular_phys

有人能找出我为什么会犯这个错误吗? 谢谢


Tags: 模块httpsorgapi距离错误h1md
1条回答
网友
1楼 · 发布于 2024-05-16 00:48:07

mdtraj.compute_distances的参数atom_pairs需要一个numpy ndarray,其中每行给出参与相互作用的两个原子的指数(而不是坐标):

>>> import numpy as np
>>> import mdtraj as md

>>> coord = md.load('alanine-dipeptide-nowater.pdb')
>>> h1 = np.array([[7, 17]], dtype=np.int32)
>>> md.compute_distances(coord, h1)
array([[0.46388564]], dtype=float32)

相关问题 更多 >