PyEMMA icon indicating copy to clipboard operation
PyEMMA copied to clipboard

Add feature: convenient plotting of contactmaps

Open franknoe opened this issue 10 years ago • 0 comments

We just plotted contactmaps using a combination of mdtraj and pyemma. I think this is a useful feature and easy to implement, so why not offer a plotting function for it?

I roughly sketch the code here - but this needs to be rethought and done properly.

def plot_contact_map(topfile, trajfile, difference_to=trajfile2, threshold=5)
    # define featurizer. Perhaps we should optionally give a featurizer to be general
    feat = coor.featurizer()
    pairs = feat.pairs(feat.select_ca())
    feat.add_contacts(pairs)
    # compute mean contact map
    map = coor.load(trajfile, feat)
    mean_map = np.mean(map,axis=0)
    # write the feature vectors back to a contact map
    # I imagine this could be a function on its own, as it might be generally useful.
    top = mdtraj.load(topfile).top
    cmatrix = np.zeros((n_residues,n_residues))
    for i in range(len(pairs)):
        res1 = top.atom(pairs[i,0]).residue.index
        res2 = top.atom(pairs[i,1]).residue.index
        cmatrix[res1,res2] = mean_map[i]
    imshow(cmatrix)
    colorbar()

franknoe avatar Apr 30 '15 13:04 franknoe