Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Pymol中显示残基之间的距离_Python_Pymol - Fatal编程技术网

Python 如何在Pymol中显示残基之间的距离

Python 如何在Pymol中显示残基之间的距离,python,pymol,Python,Pymol,使用和以下代码: 我可以制作以下图像: 我想做的是用chainC黄色显示所选残基之间的距离 用我的棍子 我想要的chainC的选定剩余物是: [9, 23, 25, 44, 53, 54, 55, 59, 62, 63, 66] Y Y H W R R F F T N V 我该怎么做 让我们使用cmd.iterate获取选择链C和链I中的所有原子,并将坐标和原子名称写入字典,以供以后使用。 然后我们可以计算所有原子之间的所有距离,并将最近的残基和原

使用和以下代码:

我可以制作以下图像:

我想做的是用chainC黄色显示所选残基之间的距离 用我的棍子

我想要的chainC的选定剩余物是:

[9, 23, 25, 44, 53, 54, 55, 59, 62, 63, 66]

Y    Y   H   W  R   R   F    F   T  N    V 
我该怎么做

让我们使用cmd.iterate获取选择链C和链I中的所有原子,并将坐标和原子名称写入字典,以供以后使用。 然后我们可以计算所有原子之间的所有距离,并将最近的残基和原子名称写入两个列表min_c和min_i 在最后一步中,我们只需绘制最近原子与物体之间的距离,即可:
是否要获取从链C中选择的一个原子与从链I中选择的另一个原子之间的最近距离?获得你所选择的所有原子到链I中所有原子的距离比较容易,但答案相当混乱。@MaximilianPeters:最近的一个。
[9, 23, 25, 44, 53, 54, 55, 59, 62, 63, 66]

Y    Y   H   W  R   R   F    F   T  N    V 
from math import sqrt

def closestAtoms(list1=[9, 23, 25, 44, 53, 54, 55, 59, 62, 63, 66], list2=[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]):
    atoms = {}
    atoms2 = {}

    for r in list1:
        command = "chain C and resi %s" % (r)
        coordinates = {'atoms': []}
        cmd.iterate_state(-1, command, 'atoms.append([x, y, z, name])', space=coordinates)
        atoms[r] = coordinates['atoms']

    for i in list2:
        command = "chain I and resi %s" % (i)
        coordinates = {'atoms': []}
        cmd.iterate_state(-1, command, 'atoms.append([x, y, z, name])', space=coordinates)
        atoms2[i] = coordinates['atoms']

    for i in list2:
        min_dist = 10**3
        for c in list1:
            for cc in atoms[c]:
                for ii in atoms2[i]:
                    dist = sqrt((cc[0] - ii[0])**2 + (cc[1] - ii[1])**2 + (cc[2] - ii[2])**2)
                    if dist < min_dist:
                        min_dist = dist
                        min_c = [c, cc[3]]
                        min_i = [i, ii[3]]
        cmd.distance('dist_%s_%s' % (min_c[0], min_i[0]), 'chain C and resi %s and name %s' % (min_c[0], min_c[1]), 'chain I and resi %s and name %s' % (min_i[0], min_i[1]))

cmd.extend("closestAtoms", closestAtoms)