Two suggestions:

If you know that residues will always contain one and only one of a
given atom type, then you can just use "count_atoms"

For example:

number=cmd.count_atoms("name ca")

Alternatively, you can have PyMOL create a dictionary of all residues:

import pymol
pymol.stored.dict = {}
iterate (all),stored.dict[(segi,chain,resn,resi)]=1
number= len(pymol.stored.dict)

Your cmd.get_model() approach is fine too.  Note that you don't need to
define a selection before using it...

number= len(cmd.get_model("name ca").atom)


Cheers,
Warren

--
mailto:war...@delanoscientific.com
Warren L. DeLano, Ph.D.
Principal Scientist
DeLano Scientific LLC
Voice (650)-346-1154 
Fax   (650)-593-4020

> -----Original Message-----
> From: pymol-users-ad...@lists.sourceforge.net [mailto:pymol-users-
> ad...@lists.sourceforge.net] On Behalf Of Cameron Mura
> Sent: Wednesday, June 25, 2003 3:39 PM
> To: PyMOL-users@lists.sourceforge.net
> Subject: [PyMOL] extracting number of residues
> 
> Hello,
> I'm wondering what's the easiest way to extract the number of residues
> from a PyMOL molecular object?? I need to be able to do this in an
> automated way for a python script I'm writing. I guess a roundabout
way
> would be to define a selection (say "X_ca") from an object ("X"), and
> then use something like this to extract the number of atoms in the
X_ca
> object:
> 
>       calphas = cmd.get_model("X_ca");
>       num_residues = length(calphas.atom);
> 
> But, this seems unneccesary? I thought I could load in the chempy
> "models" module and then use its "get_residues()" function, but the
> command fails as follows:
> 
> ###
> models.get_residues("all")
> PyMOL>models.get_residues("all")
> Traceback (most recent call last):
>    File "modules/pymol/parser.py", line 251, in parse
>      exec(com2[nest]+"\n",pymol_names,pymol_names)
>    File "<string>", line 1, in ?
> AttributeError: 'module' object has no attribute 'get_residues'
> ###
> 
> So, I'm wondering what I'm missing...is there an easy way to do this?
> 
> Thanks anyone,
>       Cameron
> 
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email is sponsored by: INetU
> Attention Web Developers & Consultants: Become An INetU Hosting
Partner.
> Refer Dedicated Servers. We Manage Them. You Get 10% Monthly
Commission!
> INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
> _______________________________________________
> PyMOL-users mailing list
> PyMOL-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pymol-users


Reply via email to