[Chimera-users] Zones to create inspector list of "contacts"

Thomas Goddard goddard at cgl.ucsf.edu
Wed Mar 23 11:37:18 PST 2005

Hi Grant,

  Below is some Python code that will create pseudobonds between all
pairs of selected atoms from different molecules that are within 3 angstroms.
It is quite slow for large sets of selected atoms.  It could be made much
faster but I chose to keep it simple.


# ----------------------------------------------------------------------------
# Check all pairwise distances between selected atoms and connect those
# atom pairs that are close by a pseudobond if the atoms belong to different
# molecules.
# To run this use Tools / Programming / Idle to show the Python shell and
# type
#    >>> execfile('path-to-this-file.py') 
# For large selected sets of atoms this will be slow.

# ----------------------------------------------------------------------------
def connect_close(dist):

    from chimera import selection, distance
    atoms = selection.currentAtoms()
    atom_pairs = []
    n = len(atoms)
    for i1 in range(n):
        a1 = atoms[i1]
        for i2 in range(i1+1, n):
            a2 = atoms[i2]
            if a1.molecule != a2.molecule:
                if distance(a1.xformCoord().xyz, a2.xformCoord().xyz) <= dist:
    print len(atom_pairs), 'atom pairs'

    from chimera import PseudoBondGroup, PseudoBondMgr_mgr, PseudoBond
    pg = PseudoBondMgr_mgr().newPseudoBondGroup('close contacts')
    bonds = []
    for a1, a2 in atom_pairs:
        bonds.append(pg.newPseudoBond(a1, a2))

    import chimera

# ----------------------------------------------------------------------------

More information about the Chimera-users mailing list