Difference between revisions of "Translate And Measure"

From PyMOLWiki
Jump to navigation Jump to search
 
m (removed the '3D' after all '=3D' - not sure why they were there!)
Line 6: Line 6:
 
4 Angstrom after translating by 1 along X.
 
4 Angstrom after translating by 1 along X.
  
Of course, this could be improved to report exactly /which/ atoms were
+
Of course, this could be improved to report exactly ''which'' atoms were
 
overlapping, or to make distance objects (using cmd.distance) to show them.
 
overlapping, or to make distance objects (using cmd.distance) to show them.
  
Line 15: Line 15:
  
 
def checkDistances(moleculeA, moleculeB, cutoff):
 
def checkDistances(moleculeA, moleculeB, cutoff):
     ids_A =3D getIds(moleculeA)
+
     ids_A = getIds(moleculeA)
     ids_B =3D getIds(moleculeB)
+
     ids_B = getIds(moleculeB)
 
     for idA in ids_A:
 
     for idA in ids_A:
 
         for idB in idsB:
 
         for idB in idsB:
             d =3D distance(moleculeA, idA, moleculeB, idB)
+
             d = distance(moleculeA, idA, moleculeB, idB)
 
             if d > cutoff: return "overlap"
 
             if d > cutoff: return "overlap"
 
     return "no overlap"
 
     return "no overlap"
  
 
def distance(a, idA, b, idB):
 
def distance(a, idA, b, idB):
     atomA =3D "%s and id %s" % (a, idA)
+
     atomA = "%s and id %s" % (a, idA)
     atomB =3D "%s and id %s" % (b, idB)
+
     atomB = "%s and id %s" % (b, idB)
 
     return cmd.get_distance(atomA, atomB)
 
     return cmd.get_distance(atomA, atomB)
  
 
def getIds(selection):
 
def getIds(selection):
     my_dict =3D { 'my_list' : [] }
+
     my_dict = { 'my_list' : [] }
     cmd.iterate(selection, "my_list.append(ID)", space=3Dmy_dict)
+
     cmd.iterate(selection, "my_list.append(ID)", space=my_dict)
 
     return my_dict['my_list']
 
     return my_dict['my_list']
 
</source>
 
</source>

Revision as of 08:06, 8 October 2005

To use, you would call it like :

print translateAndMeasure("molA", "molB", [1,0,0], 4)

which would print "overlap" if any of the atoms in molA or molB were within 4 Angstrom after translating by 1 along X.

Of course, this could be improved to report exactly which atoms were overlapping, or to make distance objects (using cmd.distance) to show them.

def translateAndMeasure(selection, other, translationVector, cutoff):
    cmd.translate(translationVector, selection)
    return checkDistances(selection, other, cutoff)

def checkDistances(moleculeA, moleculeB, cutoff):
    ids_A = getIds(moleculeA)
    ids_B = getIds(moleculeB)
    for idA in ids_A:
        for idB in idsB:
            d = distance(moleculeA, idA, moleculeB, idB)
            if d > cutoff: return "overlap"
    return "no overlap"

def distance(a, idA, b, idB):
    atomA = "%s and id %s" % (a, idA)
    atomB = "%s and id %s" % (b, idB)
    return cmd.get_distance(atomA, atomB)

def getIds(selection):
    my_dict = { 'my_list' : [] }
    cmd.iterate(selection, "my_list.append(ID)", space=my_dict)
    return my_dict['my_list']