Tsjerk, 你好 (ni hao)
Thank you for your reply. Nice work! So cute codes. I like it.

But when the selection by "id %s"%",".join([str(i) for i in ids]) too long,
it returns "Segmentation fault" error,and quit. Is it a bug?

I use pymol 1.2r2 under Debian Sid.

The error it returns:

PyMOL>run mathexpr.py
Selector-Error: Word too long. Truncated:
Selector-Error: 17,19,.....(long list,about 400 numbers)
Segmentation fault


On Mon, Dec 13, 2010 at 6:00 PM, Tsjerk Wassenaar <tsjerkw@gmail.com> wrote:
Ni Hao Cun Zhang

The real 'problem' is that Pymol does not allow selection based on
coordinates. Probably this should be on the wish list (and easy to
implement). Expressions are allowed, for instance selecting based on
b-factor or occupancy.

In your script, you can use some shortcuts. Maybe something like:

def cselect(selection="all",expression=lambda (x,y,z): True):
   return [i.id for i in cmd.get_model(selection).atom if expression(i.coord)]

The expression can be a predefined function, or a lambda function,
like here. You could then say:

ids = cselect("n. ca",lambda (x,y,z): x<10 and y>5)
cmd.show("spheres","id %s"%",".join([str(i) for i in ids]))

Hope it helps :)

Cheers,

Tsjerk



On Mon, Dec 13, 2010 at 9:44 AM, Cun Zhang <apzc2529@gmail.com> wrote:
> Hi,all
>
> I haven't found any pymol script supports using math expression to select
> atoms,
> so I spend several hours to write one function to do it.
>
> I write a script(mathexpr.py) containing this function, then run
> mathexpr.py,
> function 'Select' now can be called. Can anybody tell me how to combine this
> function into pymol,
> or 'select' command,  so it can be called like 'select x>5'.
> Hope it useful for you.
>
> Thank you!
>
> Yours,
> Cun Zhang
>
>
> def Select(expr='x>5',sel='all'):
>    """
>   A function which supports selection by math expressions.
>    example:
>          x=Select('x>5 and y<2','name C')
>    """
>     ATOMS=cmd.get_model(sel)
>     vec,index=ATOMS.get_coord_list(),cmd.identify(sel)
>     command='[index[vec.index([x,y,z])] for x,y,z in vec if '+expr+']'
>     ID=eval(command) #list type
>     return ID
>
> --
> ========================================
> Cun Zhang
> Ph.D. Candidate
> LNM,Institute of Mechanics
> Chinese Academy of Sciences
> Beijing, 100190, China
> Tel:86-10-82544204
> http://www.edwardpku.com/cun
> ========================================
>
> ------------------------------------------------------------------------------
> Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
> new data types, scalar functions, improved concurrency, built-in packages,
> OCI, SQL*Plus, data movement tools, best practices and more.
> http://p.sf.net/sfu/oracle-sfdev2dev
> _______________________________________________
> 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
>



--
Tsjerk A. Wassenaar, Ph.D.

post-doctoral researcher
Molecular Dynamics Group
* Groningen Institute for Biomolecular Research and Biotechnology
* Zernike Institute for Advanced Materials
University of Groningen
The Netherlands



--
========================================
Cun Zhang
Ph.D. Candidate
LNM,Institute of Mechanics
Chinese Academy of Sciences
Beijing, 100190, China
Tel:86-10-82544204
http://www.edwardpku.com/cun
========================================