Hi Adam,
Here's an alternative script... The command is pplanes (peptide-planes):
run triangles.py
pplanes selection[, color[, alpha[, state[, name]]]]
Hope it helps,
Tsjerk
On Thu, Aug 25, 2011 at 5:34 PM, H. Adam Steinberg <a...@steinbergs.us> wrote:
> Hi all,
> Can anyone help me with a problem that I am having trying to run a python
> script?
> I am trying to run the bbPlane script from the PyMOLWiki
> <http://www.pymolwiki.org/index.php/BbPlane>
> I have copied the script from the web page, to a plain text document, saved
> it as "bbPlane.py" but when I run it I get:
> ------------
> PyMOL>run bbPlane.py
> Traceback (most recent call last):
> File "/Volumes/Port
> 3/software/MacPyMOL.app/pymol/modules/pymol/parser.py", line 332, in parse
> File "/Volumes/Port
> 3/software/MacPyMOL.app/pymol/modules/pymol/parsing.py", line 455, in
> run_file
> File "bbPlane.py", line 14
>
> ^
> SyntaxError: invalid syntax
> -------------
> script is here:
>
> #
> # -- bbPlane.py - draws a CGO plane across the backbone atoms of
> # neighboring amino acids
> #
> # Author: Jason Vertrees, 06/2010
> # Modified by Thomas Holder, 06/2010
> # Modified by Blaine Bell, 08/2011
> # Copyright (C) Schrodinger
> # Open Source License: MIT
> #
> from pymol.cgo import * # get constants
> from pymol import cmd, stored
> from chempy import cpv
>
> def bbPlane(objSel='(all)', color='white', transp=0.0):
> """
> DESCRIPTION
>
> Draws a plane across the backbone for a selection
>
> ARGUMENTS
>
> objSel = string: protein object or selection {default: (all)}
>
> color = string: color name or number {default: white}
>
> transp = float: transparency component (0.0--1.0) {default: 0.0}
>
> NOTES
>
> You need to pass in an object or selection with at least two
> amino acids. The plane spans CA_i, O_i, N-H_(i+1), and CA_(i+1)
> """
> # format input
> transp = float(transp)
> stored.AAs = []
> coords = dict()
>
> # need hydrogens on peptide nitrogen
> cmd.h_add('(%s) and n. N' % objSel)
>
> # get the list of residue ids
> for obj in cmd.get_object_list(objSel):
> sel = obj + " and (" + objSel + ")"
> for a in cmd.get_model(sel + " and n. CA").atom:
> key = '/%s/%s/%s/%s' % (obj,a.segi,a.chain,a.resi)
> stored.AAs.append(key)
> coords[key] = [a.coord,None,None]
> for a in cmd.get_model(sel + " and n. O").atom:
> key = '/%s/%s/%s/%s' % (obj,a.segi,a.chain,a.resi)
> if key in coords:
> coords[key][1] = a.coord
> for a in cmd.get_model("(hydro or n. CD) and nbr. (" + sel + " and
> n. N)").atom:
> key = '/%s/%s/%s/%s' % (obj,a.segi,a.chain,a.resi)
> if key in coords:
> coords[key][2] = a.coord
>
> # need at least two amino acids
> if len(stored.AAs) <= 1:
> print "ERROR: Please provide at least two amino acids, the
> alpha-carbon on the 2nd is needed."
> return
>
> # prepare the cgo
> obj = [
> BEGIN, TRIANGLES,
> COLOR,
> ]
> obj.extend(cmd.get_color_tuple(color))
>
> for res in range(0, len(stored.AAs)-1):
> curIdx, nextIdx = str(stored.AAs[res]), str(stored.AAs[res+1])
>
> # populate the position array
> pos = [coords[curIdx][0], coords[curIdx][1], coords[nextIdx][2],
> coords[nextIdx][0]]
>
> # if the data are incomplete for any residues, ignore
> if None in pos:
> print 'peptide bond %s -> %s incomplete' % (curIdx, nextIdx)
> continue
>
> if cpv.distance(pos[0], pos[3]) > 4.0:
> print '%s and %s not adjacent' % (curIdx, nextIdx)
> continue
>
> # need to order vertices to generate correct triangles for plane
> # modified/added by B.Bell 8/18/2011
> sumpos = cpv.add(pos[0], cpv.add(pos[1], cpv.add(pos[2], pos[3])))
> centerpos = [ sumpos[0]/4., sumpos[1]/4., sumpos[2]/4. ]
> angles = [ [ 0., 0 ] ]
> s00 = cpv.sub(pos[0], centerpos)
> for i in range(1,4):
> s = cpv.sub(pos[i], centerpos)
> ang = cpv.get_angle(s00, s)
> angles.append( [ ang, i] )
> def sortfirst(a, b):
> return cmp(a[0], b[0])
> angles.sort(sortfirst)
> verts = map(lambda x: x[1], angles)
> vorder = [ verts[0], verts[1], verts[2],
> verts[1], verts[3], verts[2] ]
> # fill in the vertex data for the triangles;
> for i in vorder:
> obj.append(VERTEX)
> obj.extend(pos[i])
>
> # finish the CGO
> obj.append(END)
>
> # update the UI
> newName = cmd.get_unused_name("backbonePlane")
> cmd.load_cgo(obj, newName)
> cmd.set("cgo_transparency", transp, newName)
>
>
> cmd.extend("bbPlane", bbPlane)
>
> artforscience
> H. Adam Steinberg
> Artist, Scientist, Developmental Editor
> www.artforscience.com
> 7904 Bowman Rd
> Lodi, WI 53555
> 608/729-5944
>
> ------------------------------------------------------------------------------
> EMC VNX: the world's simplest storage, starting under $10K
> The only unified storage solution that offers unified management
> Up to 160% more powerful than alternatives and 25% more efficient.
> Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
> _______________________________________________
> 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
from pymol import cmd
from pymol.cgo import *
def vsub(a,b): return [i-j for i,j in zip(a,b)]
def oprod(a,b): return [a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
def normal(a,b,c): return oprod(vsub(b,a),vsub(c,a))
def cgo_n(a,b,c): return [NORMAL]+list(normal(a,b,c))
def cgo_v(a): return [VERTEX]+list(a)
def cgo_t(a,b,c): return cgo_n(a,b,c)+cgo_v(a)+cgo_v(b)+cgo_v(c)
def cgo_c(a): return [COLOR]+list(a)
def cgo_tri(a,b,c,col=[1,1,1]): return cgo_c(col)+cgo_t(a,b,c)
def cgo_rect(a,b,c,d,col=[1,1,1]): return cgo_tri(a,c,b,col)+cgo_tri(a,d,c,col)
def cgo_triangles(x,col=[1,1,1],alpha=1.0):
b = [BEGIN, TRIANGLES, ALPHA, alpha]
if type(col[0]) in (list,tuple):
return b+[k for i,j in zip(x,col) for k in cgo_tri(i[0],i[1],i[2],j)]+[END]
else:
return b+[k for i in x for k in cgo_tri(i[0],i[1],i[2],col)]+[END]
def cgo_rectangles(x,col=[1,1,1],alpha=1.0):
b = [BEGIN, TRIANGLES, ALPHA, alpha]
if type(col[0]) in (list,tuple):
return b+[k for i,j in zip(x,col) for k in cgo_rect(i[0],i[1],i[2],i[3],j)]+[END]
else:
return b+[k for i in x for k in cgo_rect(i[0],i[1],i[2],i[3],col)]+[END]
def pplanes(selection="all",color=[1,1,1],alpha=1.0,state=1,name="pplanes"):
xa = [i.coord for i in cmd.get_model(selection+' and n. ca',state=state).atom]
xo = [i.coord for i in cmd.get_model(selection+' and n. o',state=state).atom]
xh = [i.coord for i in cmd.get_model(selection+' and (n. h or (r. pro and n. cd))',state=state).atom]
pl = cgo_rectangles(zip(xa,xo,xa[1:],xh[1:]),color,alpha)
cmd.load_cgo(pl,state=state,name=name)
def pplanes1(selection="all",color=[1,1,1],alpha=1.0,state=1,name="pplanes"):
xa = [i.coord for i in cmd.get_model(selection+' and n. ca',state=state).atom]
xo = [i.coord for i in cmd.get_model(selection+' and n. o',state=state).atom]
xh = [i.coord for i in cmd.get_model(selection+' and (n. h or (r. pro and n. cd))',state=state).atom]
pl = cgo_rectangles(zip(xa,xo,xa[1:],xh),color,alpha)
cmd.load_cgo(pl,state=1,name=name)
cmd.extend("pplanes",pplanes)
------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management
Up to 160% more powerful than alternatives and 25% more efficient.
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
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