[chimera-dev] Trajectory and MD Movie GUI

Alex alex.tek.fr at gmail.com
Wed Apr 17 07:32:58 PDT 2013


Hi Eric,

Thank you very much for the hint. It works fine.

I was able to add frames after the creation of the MovieDialog as well. I had to subclass MovieDialog to add a method updateFrames, to be called when the molecule has new coordSets, as I think it's not possible currently :

from Movie.gui import MovieDialog
from Trajectory import Ensemble

class MyMovieDialog(MovieDialog):
    def __init__(self, ensemble, **kw):
        MovieDialog.__init__(self, ensemble, **kw)

    def updateFrames(self):
	# inspired from MovieDialog.addTrajFile method
        ensembleSize = len(self.ensemble)
        self.endFrame = ensembleSize
        self.triggers.activateTrigger(self.MORE_FRAMES, ensembleSize)

class MolEnsemble:
    def __init__(self, mol):
        self.molecule = mol
        self.name = "MolEnsemble"
        self.startFrame = 1
        self.endFrame = len(mol.coordSets)

    def __len__(self):
        return len(self.molecule.coordSets)

ensemble = MolEnsemble(chimera.openModels.list()[0])
movieDialog = MyMovieDialog(ensemble, externalEnsemble=True)


# Get a numpy array containing coordinates from my lib
# [[x0,y0,z0], [x1,y1,z1], ...]
pos = extLib.getCoords()

cs = ensemble.molecule.newCoordSet(len(ensemble)+1)
chimera.fillCoordSet(cs, ensemble.molecule.atoms, pos)

movieDialog.updateFrames()
movieDialog.LoadFrame(len(ensemble))

Best regards,
Alex

---------
Alex Tek, Phd
Department of Cell and Molecular Biology
BMC Box 596
SE-751 24 Uppsala
Sweden

alex.tek at icm.uu.se

Le 16 avr. 2013 à 19:56, Eric Pettersen a écrit :

> On Apr 15, 2013, at 8:50 AM, Alex wrote:
> 
>> Dear all,
>> 
>> I'm developing a plugin and would like to add frames to a model on the fly and being able to use the trajectory (MD Movie) GUI to navigate among the frames.
>> Unfortunately, I can't find a way to instanciate the dialog MovieDialog (Movie/gui.py) with a model already opened.
>> It seems that I have to use an Ensemble object (Trajectory/__init.py__) but its constructor requires another ensemble, and the Ensemble objects seem to be created inside MovieDialog's constructor.
>> 
>> I'm rather confused right now and would appreciate some help on the matter.
> 
> Hi Alex,
> 	I didn't originally write that code and if I were to rewrite it from scratch it wouldn't be quite so obscure, but nonetheless what you want to do isn't hard, given the right knowhow.  You need to construct an ensemble object to hand off to the MovieDialog constructor.  Just declare a class that inherits from nothing and has the following:
> 
> molecule attr:  your Molecule instance
> startFrame attr:  1
> endFrame attr:  the number of frames you have
> name attr:  name you want shown in the title bar
> __len__ func:  returns the number of frames
> 
> In addition, specify externalEnsemble=True in the keywords to the MovieDialog constructor.
> 	I'm assuming that all the "frames added on the fly" have already been added when you bring up the MovieDialog.  If some will be added later, that's more complicated (but doable I think).  Anyway, if you have more questions feel free to ask.
> 
> --Eric
> 
> 
>                         Eric Pettersen
>                         UCSF Computer Graphics Lab
>                         http://www.cgl.ucsf.edu
> 
> 





More information about the Chimera-dev mailing list