Difference between revisions of "Polarpairs"

From PyMOLWiki
Jump to navigation Jump to search
(Created page with "Find polar pairs with the cmd.find_pairs function and return them as a list of atom pairs. It finds (more or less) the same contacts like [[distance|cmd.distance(m...")
 
(2to3)
 
(2 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
for p in pairs:
 
for p in pairs:
 
     dist = cmd.get_distance('(%s`%s)' % p[0], '(%s`%s)' % p[1])
 
     dist = cmd.get_distance('(%s`%s)' % p[0], '(%s`%s)' % p[1])
     print p, 'Distance: %.2f' % (dist)
+
     print(p, 'Distance: %.2f' % (dist))
 
</source>
 
</source>
  
Line 19: Line 19:
 
from pymol import cmd
 
from pymol import cmd
  
def polarpairs(sel1, sel2, cutoff=4.0, angle=63.0, name='', quiet=1):
+
def polarpairs(sel1, sel2, cutoff=4.0, angle=63.0, name='', state=1, quiet=1):
 
     '''
 
     '''
 
ARGUMENTS
 
ARGUMENTS
Line 38: Line 38:
 
     cutoff = float(cutoff)
 
     cutoff = float(cutoff)
 
     quiet = int(quiet)
 
     quiet = int(quiet)
 +
    state = int(state)
 
     if angle == 'default':
 
     if angle == 'default':
 
         angle = cmd.get('h_bond_max_angle', cmd.get_object_list(sel1)[0])
 
         angle = cmd.get('h_bond_max_angle', cmd.get_object_list(sel1)[0])
Line 43: Line 44:
 
     mode = 1 if angle > 0 else 0
 
     mode = 1 if angle > 0 else 0
 
     x = cmd.find_pairs('(%s) and donors' % sel1, '(%s) and acceptors' % sel2,
 
     x = cmd.find_pairs('(%s) and donors' % sel1, '(%s) and acceptors' % sel2,
 +
            state, state,
 
             cutoff=cutoff, mode=mode, angle=angle) + \
 
             cutoff=cutoff, mode=mode, angle=angle) + \
 
         cmd.find_pairs('(%s) and acceptors' % sel1, '(%s) and donors' % sel2,
 
         cmd.find_pairs('(%s) and acceptors' % sel1, '(%s) and donors' % sel2,
 +
            state, state,
 
             cutoff=cutoff, mode=mode, angle=angle)
 
             cutoff=cutoff, mode=mode, angle=angle)
 
     x = sorted(set(x))
 
     x = sorted(set(x))
 
     if not quiet:
 
     if not quiet:
         print 'Settings: cutoff=%.1fangstrom angle=%.1fdegree' % (cutoff, angle)
+
         print('Settings: cutoff=%.1fangstrom angle=%.1fdegree' % (cutoff, angle))
         print 'Found %d polar contacts' % (len(x))
+
         print('Found %d polar contacts' % (len(x)))
 
     if len(name) > 0:
 
     if len(name) > 0:
 
         for p in x:
 
         for p in x:
Line 58: Line 61:
 
</source>
 
</source>
  
 +
[[Category:Plugins]]
 
[[Category:Biochemical_Scripts]]
 
[[Category:Biochemical_Scripts]]

Latest revision as of 14:53, 12 March 2019

Find polar pairs with the cmd.find_pairs function and return them as a list of atom pairs. It finds (more or less) the same contacts like cmd.distance(mode=2).

Example

pairs = polarpairs('chain A', 'chain B')
for p in pairs:
    dist = cmd.get_distance('(%s`%s)' % p[0], '(%s`%s)' % p[1])
    print(p, 'Distance: %.2f' % (dist))

The Script

'''
(c) 2011 Thomas Holder, MPI for Developmental Biology
'''

from pymol import cmd

def polarpairs(sel1, sel2, cutoff=4.0, angle=63.0, name='', state=1, quiet=1):
    '''
ARGUMENTS

    sel1, sel2 = string: atom selections

    cutoff = float: distance cutoff

    angle = float: h-bond angle cutoff in degrees. If angle="default", take
    "h_bond_max_angle" setting. If angle=0, do not detect h-bonding.

    name = string: If given, also create a distance object for visual representation

SEE ALSO

    cmd.find_pairs, cmd.distance
    '''
    cutoff = float(cutoff)
    quiet = int(quiet)
    state = int(state)
    if angle == 'default':
        angle = cmd.get('h_bond_max_angle', cmd.get_object_list(sel1)[0])
    angle = float(angle)
    mode = 1 if angle > 0 else 0
    x = cmd.find_pairs('(%s) and donors' % sel1, '(%s) and acceptors' % sel2,
            state, state,
            cutoff=cutoff, mode=mode, angle=angle) + \
        cmd.find_pairs('(%s) and acceptors' % sel1, '(%s) and donors' % sel2,
            state, state,
            cutoff=cutoff, mode=mode, angle=angle)
    x = sorted(set(x))
    if not quiet:
        print('Settings: cutoff=%.1fangstrom angle=%.1fdegree' % (cutoff, angle))
        print('Found %d polar contacts' % (len(x)))
    if len(name) > 0:
        for p in x:
            cmd.distance(name, '(%s`%s)' % p[0], '(%s`%s)' % p[1])
    return x

cmd.extend('polarpairs', polarpairs)