Skip to content

segmentmodel_from_pdb

Module documentation for segmentmodel_from_pdb.

API Reference

residues_within(cutoff, coords1, coords2, sel1, sel2)

Returns lists of index of residues within sel1 and sel2 such that sel1.residue[arr_idx1[i]] is within cutoff of sel2.residue[arr_idx2[i]] for all i

Also returns distance_matrix

Ignores residues that are the same in sel1 and sel2

Source code in mrdna/readers/segmentmodel_from_pdb.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def residues_within( cutoff, coords1, coords2, sel1, sel2 ):
    """
    Returns lists of index of residues within sel1 and sel2 such that
    sel1.residue[arr_idx1[i]] is within cutoff of sel2.residue[arr_idx2[i]] for all i

    Also returns distance_matrix

    Ignores residues that are the same in sel1 and sel2
    """

    assert(len(sel1.atoms) > 0 and len(sel2.atoms) > 0)
    assert(len(sel1.residues) == len(coords1))
    assert(len(sel2.residues) == len(coords2))

    distance_matrix = distance_array( coords1, coords2 )

    ## Ignore comparisons with self
    res_diff = sel1.residues.resindices[:,np.newaxis] - sel2.residues.resindices[np.newaxis,:]
    assert( res_diff.shape == distance_matrix.shape )
    distance_matrix[ res_diff == 0 ] = distance_matrix[ res_diff == 0 ] + 10 *cutoff

    arr_idxs = np.where((distance_matrix < cutoff))
    arr_idx1,arr_idx2 = arr_idxs

    return arr_idx1, arr_idx2, distance_matrix