Hey :)

In response to an earlier question regarding coloring objects according to
per residue RMSD, I wrote a small routine to color according to atom RMSD,
after an alignment. Maybe it'll be of any use to someone...

The script performs an alignment and then gets the corresponding atoms, for
which the RMSDs are calculated. These are written to the b-factor fields of
the atoms in both objects and the structures are colored.

Any improvements are welcomed.

Enjoy,

Tsjerk


###

import numpy

from pymol import cmd


def rmsd2b(selection1, selection2, cycles=5, scheme="rainbow"):

    """

    Align structures and write pairwise RMSDs to b-factor fields


    Author: Tsjerk A. Wassenaar

    """


    cmd.align(selection1,selection2,cycles=int(cycles))


    # I would like to have a better way for this...

    # Find the element in the session list that corresponds to the object
_align1

    # which is an object generated by cmd.align (likewise for _align2)

    # The list contains a number of things. The fifth element is the list
of

    # IDs of atoms that are aligned to those in the other structure.

    aln1 = [i for i in cmd.get_session()["names"] if i and i[0] ==
"_align1"][0][5][0][1]

    aln2 = [i for i in cmd.get_session()["names"] if i and i[0] ==
"_align2"][0][5][0][1]


    m1 = numpy.array(cmd.get_model(selection1).get_coord_list())

    m2 = numpy.array(cmd.get_model(selection2).get_coord_list())


    # RMSD per atom in the alignment

    d = numpy.sqrt( ((m1[aln1,:]-m2[aln2,:])**2).sum(axis=1) )


    b1 = numpy.zeros(m1.shape[0])

    b2 = numpy.zeros(m2.shape[0])


    b1[aln1] = d

    b2[aln2] = d


    b1 = b1.tolist()

    b2 = b2.tolist()


    cmd.alter(selection1,"b=b1.pop(0)",space=locals())

    cmd.alter(selection2,"b=b2.pop(0)",space=locals())


    cmd.spectrum("b",scheme, "(%s) or (%s)"%(selection1, selection2))



cmd.extend("rmsd2b",rmsd2b)



-- 
Tsjerk A. Wassenaar, Ph.D.
------------------------------------------------------------------------------
Slashdot TV.  Videos for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to