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:

   # create test image  
   a = test_image_3d(1)   
   #  display test image
   #  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
   drop_image(p, "pop1.hdf")
   # write image to the disk in spider format, it can be viewed using, v2 or web (web is part of SPIDER package).
   drop_image(p, "pop1.spi","s")
   # rotate and shift the image
   q = rtshg(p, 33., 3.8, 2.3)
   # add both images
   z = q + p
   drop_image(z, "pop2.hdf")
   # End session

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.

   # generate a test 2-D image and display it.
   a = test_image()
   d = EMImage(a)
   # another possibility
   #  generate a sphere and display it
   vol = model_circle(23,64,64,64)
   v = EMImage(vol)
   # End session

For more details, see

Example of your own program:

Major steps of program:

  1. Generates volume (phantom)
  2. Create a list of Euler angles
  3. Calculates 2-D projections of volume for previously generated angles
  4. Reconstructs 3-D volume based on 2-D projections obtained using diffrent methods than saved on a disk as ".hdf" files.

Input parameters of program: Euler angles for projection generated using function even_angles(delta,theta_min,theta_max, phi_min,phi_max,method,phiEqpsi)

Output of program: Resonstructed 3-D volume obtained using diffrent reconstructions algorithms and saved as ".hdf" files.

In a text editor, write the program as follows:

#!/bin/env python

# Author: me

from EMAN2  import *
from sparx  import *

from random import randint

vol = test_image_3d(3)   

volft, kb = prep_vol(vol)

angles = even_angles(5.,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])
        proj.write_image(stack, i)

nangles = len(angles)

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

# write volume in SPIDER format, chimera will not display volumes in hdf format

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

v = recons3d_wbp(stack, list_proj, "general")

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


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


Save the file as and change it to executable:

The program can be run as:

Note location of python in your system might be different from that given in the first line of the above program.

The next example is a simple 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)

Save the file as and change it to executable:

The program can be run as:

In order to view volumes, use chimera or 2-D images can be displayed using, 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:

#!/bin/sh proj.hdf --params="active" --one proj.hdf --params="xform.align2d" --zero proj.hdf output_directory --ou=27 --center=0 --maxit=50 proj.hdf ali_proj.hdf ali_proj.hdf cluster_dir --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 *

header("proj.hdf", "active",one=True)

header("proj.hdf", "xform.align2d",zero=True)

ali2d("proj.hdf",  "output_directory", ou=27, center=0,maxit=50)

transform2d("proj.hdf", "ali_proj.hdf")

k_means_main("ali_proj.hdf", "cluster_directory",None,"SSE",5,-1,10,1,"D")

Save the file as 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 MPI code

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

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

Note about applications

HowToUseSparx (last edited 2022-12-15 19:42:25 by Anna)