Hi Cun Zhuang, I think what you need to do is adding one line in the end of mathexpr.py:
cmd.extend("SelectByExpr",Select) then you can type in command line SelectByExpr x>5 see the following page for more explanation: http://www.pymolwiki.org/index.php/Simple_Scripting hongbo On 12/13/2010 11:00 AM, Tsjerk Wassenaar 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<apzc2...@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 >> > > > ------------------------------------------------------------------------------ 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