Tsjerk,

This will only provide a minor speedup, but the alter* and iterate* commands do 
take a "space" argument with a dictionary to use in lieu of PyMOL globals().

my_dict = {'L':[]}

cmd.iterate_state(1, 'all', 'L.append( (x,y,z) )', space=my_dict)

print len(my_dict['L'])

etc.

Cheers,
Warren


> -----Original Message-----
> From: Tsjerk Wassenaar [mailto:[email protected]]
> Sent: Tuesday, September 29, 2009 7:40 AM
> To: Warren DeLano
> Subject: Re: [PyMOL] Iterate Script Over States
> 
> Hi Warren (e.a.),
> 
> First, as a side note, your first post had 'for state in
> cmd.count_states():' whereas it seems it should read 'for state in
> range(cmd.count_states()):'.
> 
> I find myself doing something similar to Sean now, accumulating
> coordinates over different frames for each of the atoms. The question
> is how to do that fastest. At this moment I'm doing the following,
> which is painstakingly slow (but it works :)). Aside from that it has
> a nasty hack adding to globals(), as cmd.alter executes in its own
> scope.
> 
> class AtomVar:
>     sum = None
>     ssq = None
>     N   = None
>     cov = None
>     var = None
> 
>     def __init__( self ):
>         self.sum = [ 0,0,0 ]       #  x,  y,  z
>         self.ssq = [ 0,0,0,0,0,0 ] # xx, yy, zz, xy, xz, yz
>         self.N   = 0
> 
>     def inc( self, x ):
>         self.sum = [ self.sum[i] + x[i] for i in range(3) ]
>         squares  = [ x[0]*x[0], x[1]*x[1], x[2]*x[2], x[0]*x[1],
> x[0]*x[2], x[1]*x[2] ]
>         self.ssq = [ self.ssq[i] + squares[i] for i in range(6) ]
>         self.N = self.N + 1
> 
>     def purge( self ):
>         s = self.sum
>         squares = [ s[0]*s[0], s[1]*s[1], s[2]*s[2], s[0]*s[1],
> s[0]*s[2], s[1]*s[2] ]
>         self.cov = [ (squares[i] - self.ssq[i]/self.N)/self.N for i in
> range(6) ]
>         self.var = self.cov[0] + self.cov[1] + self.cov[2]
> 
> def molVar( sele="all" ):
>     model = cmd.get_model( sele )
>     globals()["M"] = {}
>     for i in model.atom:
>         M[ i.id ] = AtomVar()
>     for state in range(cmd.count_states()):
>         cmd.iterate_state( state, sele, "M[ ID ].inc( (x,y,z) )" )
>     for i in M.keys():
>         M[ i ].purge()
>     cmd.alter( sele, "b = M[ ID ].var" )
> 
> Any suggestions are welcome :)
> 
> Cheers,
> 
> Tsjerk
> 
> 
> On Mon, Sep 28, 2009 at 9:05 PM, Warren DeLano <[email protected]> wrote:
> > Sean,
> >
> >
> >
> > Yes, that is an alternate route.  cmd.get_model is likely slower than
> > cmd.iterate_state, but should work regardless.
> >
> >
> >
> > Cheers
> >
> > Warren
> >
> >
> >
> > ________________________________
> >
> > From: Sean Law [mailto:[email protected]]
> > Sent: Monday, September 28, 2009 11:58 AM
> > To: [email protected]
> > Subject: Re: [PyMOL] Iterate Script Over States
> >
> >
> >
> > I think I figured it out (though, it wasn't documented).  What I needed
> was
> > to use:
> >
> > cmd.get_model(selection, STATE)
> >
> > I think that's the correct usage?  What I needed was to loop through a
> > selection and then to calculate the sugar pucker information.  However,
> not
> > all atoms from the selection are required for the calculation so some
> > pre-parsing of the residue is needed.  It appears that I can specify the
> > state to obtain atom objects from via the get_model command.  I hope
> that is
> > right?
> >
> > Sean
> >
> > ________________________________
> >
> > Create a cool, new character for your Windows Live(tm) Messenger. Check it
> out
> >
> > ------------------------------------------------------------------------
> ------
> > Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
> > is the only developer event you need to attend this year. Jumpstart your
> > developing skills, take BlackBerry mobile applications to market and
> stay
> > ahead of the curve. Join us from November 9&#45;12, 2009. Register
> now&#33;
> > http://p.sf.net/sfu/devconf
> > _______________________________________________
> > PyMOL-users mailing list ([email protected])
> > Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
> > Archives: http://www.mail-archive.com/[email protected]
> >
> 
> 
> 
> --
> Tsjerk A. Wassenaar, Ph.D.
> Junior UD (post-doc)
> Biomolecular NMR, Bijvoet Center
> Utrecht University
> Padualaan 8
> 3584 CH Utrecht
> The Netherlands
> P: +31-30-2539931
> F: +31-30-2537623
> 
> 
> 



------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
PyMOL-users mailing list ([email protected])
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/[email protected]

Reply via email to