Translate And Measure

From PyMOLWiki
Revision as of 07:38, 13 June 2005 by Inchoate (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 =3D getIds(moleculeA)
    ids_B =3D getIds(moleculeB)
    for idA in ids_A:
        for idB in idsB:
            d =3D distance(moleculeA, idA, moleculeB, idB)
            if d > cutoff: return "overlap"
    return "no overlap"

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

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