4

With the this PDB file and the following PyMOL code:

cd /Users/foo/Desktop/
reinitialize
load pdp_4gg6CD1_I.pdb
as cartoon 
select chainI, chain I
select chainC, chain C 
select chainD, chain D 
show sticks, chainI
spectrum count, cyan_red, chainI
color yellow, chain C

I can make this image:

enter image description here

What I want to do is to show the distance between the selected residues in chainC (yellow) with chainI (stick).

The selected residues of chainC that I want is this:

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

Y    Y   H   W  R   R   F    F   T  N    V 

How can I do that?

neversaint
  • 60,904
  • 137
  • 310
  • 477
  • Do you want to get the closest distance between one atom in your selection from chain C and another atom from chain I? Getting the distance of all atoms your selection to all atoms in chain I is easier but but the answer is quite messy. – Maximilian Peters Jun 25 '16 at 17:27
  • @MaximilianPeters: Closest one. – neversaint Jun 29 '16 at 01:19

1 Answers1

3
  • Let's use cmd.iterate to get all the atoms in a selection (chain C and chain I) and write the coordinates and atom name to dictionaries for later use.
  • Then we can calculate all the distances between all atoms and write the closest residues and atom names to two lists (min_c and min_i)
  • In the last step we only have to draw the distance objects between the closest atoms and we are done :)

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)
Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99