Interactive session

The SPARX system is activated by typing sparx at the prompt. Should that fail, please change sparx script to executable by typing

Example of an interactive session:

   cd ~/sparx/test
   sparx
   # read input volume, which is included in the cvs distribution
   a = getImage("model001.tcp")  
   #  print current statistics of the volume
   info(a)
   #  Calculate 2-D projection [phi, theta, psi, sx, sy]
   p = prg(a, [12,23,-55,-2.3,4.1])
   # write image to the disk in hdf format, it can be viewed using e2display.py.
   dropImage(p, "pop1.hdf")
   # write image to the disk in spider format, it can be viewed using e2display.py, v2 or web (web is part of SPIDER package).
   dropImage(p, "pop1.spi","s")
   # rotate and shift the image
   q = rtshg (p, 33., 3.8, 2.3)
   # add both images
   z = q + p
   dropImage(z, "pop2.hdf")
   # End session
   Quit

Build-in graphic (courtesy EMAN2):

sparx provides limited graphics capabilties accessible from command line. This is written by David Woolford and Steve Ludtke within EMAN2.

   cd ~/sparx/test
   sparx
   # generate a test 2-D image and display it.
   a = test_image()
   d = EMImage(a)
   #  generate a sphere and display it
   vol = model_circle(23,64,64,64)
   v = EMImage(vol)
   # End session
   Quit

For more details, see http://blake.bcm.edu/emanwiki/e2display.

Example of your own program:

In a text editor, write the program as follows:

#!/bin/env python

# Author: me

from EMAN2  import *
from sparx  import *

from random import randint
#  the test volume should be in the directory ~/sparx/test

vol=getImage("~/sparx/test/model001.tcp")
info(vol)

volft,kb=prep_vol(vol)

angles=even_angles(1.,90.,90.1,0.,179.9,'P')#,'Minus')

print  angles
nangles = len(angles)

stack = "proj.hdf"

for i in xrange(nangles):
        s2x = randint(-1,1)
        s2y = randint(-1,1)
        print  i, angles[i][0], angles[i][1], angles[i][2], -s2x, -s2y
        proj=prgs(volft, kb, [angles[i][0], angles[i][1], angles[i][2], -s2x, -s2y])
        # Set all parameters for the new 2D image
        # three angles and two shifts
        proj.set_attr_dict({'phi':angles[i][0], 'theta':angles[i][1], 'psi':angles[i][2], 's2x':s2x, 's2y':s2y, 'mirror':0.})
        #proj.set_attr_dict({'phi':0, 'theta':0, 'psi':0, 's2x':0, 's2y':0, 'mirror':0.})
        # CTF parameters, if defocus zero, they are undetermined
        proj.set_attr_dict({'defocus':0.0, 'amp_contrast':0.1, 'voltage':200, 'Cs':2.0, 'pixel':2.2})
        # flags describing the status of the image (1 = true, 0 = false)
        proj.set_attr_dict({'active':1, 'ctf_applied':0})
        proj.write_image(stack, i)


nangles = len(angles)
list_proj=range(nangles)

v = recons3d_4nn(stack, list_proj, "c1")

# write volume in SPIDER format, chimera will not display volumes in hdf format
dropImage(v,"vv.spi","s")


v = recons3d_wbp(stack, list_proj, "exact", 75)

dropImage(v,"aa.spi","s")
v = recons3d_wbp(stack, list_proj, "general")

#v = recons3d_4nn(stack, list_proj, "c1")

dropImage(v,"bb.spi","s")

#s = recons3d_sirt(stack, list_proj, 35, 1.0e-2)

#dropImage(s,"sirt.spi")

Save the file as my_program.py and change it to executable:

The program can be run as:

The next example is a simple interactive program that can be called with parameters provided in the command line.

#!/bin/env python
#

from EMAN2  import *
from sparx  import *
from sys import argv

nima = EMUtil.get_image_count(argv[1])

for i in xrange(nima):
        a = filt_btwo( get_im(argv[1],i), 0.02,0.1,0.5)
        a.write_image(argv[2], i)

If this program is saved as my_program2.py, it is run as:

In order to view volumes, use chimera. 2-D images can be displayed using e2display.py, which comes from EMAN2 and is part of the package.

Using SPARX applications that perform selected single particle tasks:

All available applications are listed in KeywordToc. They can be executed either as line commands (see documentation for details) or as functions in your own SPARX program. In practice, it means that longer single particle projects can be assembled as a sequence of steps using one of two possible methods:

1. Sequence of command line calls

In a text editor, type in all application calls in a proper sequence and with proper parameters:

#
sxali2d_c.py proj.hdf output_directory --ou=27 --c=0
sxtransform2d.py proj.hdf ali_proj.hdf
sxk_means.py ali_proj.hdf cluster_dir 'None' --K=5 --opt_method='SSE'

Save the file as my_project, change it to executable:

and run it

2. SPARX program

In a text editor, write the program as follows:

#!/bin/env python

# Author: me

# My project on my complex

from EMAN2  import *
from sparx  import *

ali2d_c("proj.hdf",  "output_directory", 27, 0)
transform2d("proj.hdf", "ali_proj.hdf")
K_means("ali_proj.hdf", "cluster_dir", "None", "SSE", 5)

Save the file as my_project.py and change it to executable:

The program can be run as:

The advantage of writing your project as a SPARX program is that main steps can be mixed with your own pieces of SPARX code that do additional processing not provided by the system.

Note about global settings and MPI code

mpirun -np <number of CPUs> <application_name.py>  <parameters, as described in the documentation> &

Note about BATCH flag that indicates whether the program runs in a background in a silent mode

Note about applications

HowToUseSparx (last edited 2008-03-03 18:41:34 by penczek)