Interactive session
The SPARX system is activated by typing sparx at the prompt. Should that fail, please change sparx script to executable by typing
- chmod +x ~/EMAN2/bin/sparx
Example of an interactive session:
sparx # create test image a = test_image_3d(1) # display test image display(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. drop_image(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). 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 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.
sparx # generate a test 2-D image and display it. a = test_image() d = EMImage(a) # another possibility display(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:
Major steps of program:
- Generates volume (phantom)
- Create a list of Euler angles
- Calculates 2-D projections of volume for previously generated angles
- 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) info(vol) 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) list_proj=range(nangles) v = recons3d_4nn(stack, list_proj, "c1") # write volume in SPIDER format, chimera will not display volumes in hdf format drop_image(v,"vv.hdf") v = recons3d_wbp(stack, list_proj, "exact", 75) drop_image(v,"aa.hdf") v = recons3d_wbp(stack, list_proj, "general") #v = recons3d_4nn(stack, list_proj, "c1") drop_image(v,"bb.hdf") #s = recons3d_sirt(stack, list_proj, 35, 1.0e-2) #drop_image(s,"sirt.hdf")
Save the file as my_program.py and change it to executable:
- chmod +x my_program.py
The program can be run as:
my_program.py &
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 my_program2.py and change it to executable:
- chmod +x my_program2.py
The program can be run as:
my_program2.py input_stack.hdf output_stack.hdf &
In order to view volumes, use chimera or e2display.py. 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:
#!/bin/sh sxheader.py proj.hdf --params="active" --one sxheader.py proj.hdf --params="xform.align2d" --zero sxali2d.py proj.hdf output_directory --ou=27 --center=0 --maxit=50 sxtransform2d.py proj.hdf ali_proj.hdf sxk_means.py ali_proj.hdf cluster_dir --K=5 --opt_method='SSE'
Save the file as my_project, change it to executable:
- chmod +x my_project
and run it
my_project &
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 my_project.py and change it to executable:
- chmod +x my_project.py
The program can be run as:
my_project.py &
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
To run MPI code, flag MPI has to be added in the command line and mympi installed (currently, it is not part of the distribution). Specifics of submitting an MPI program depend on the queueing system on a given cluster and should be consulted with a cluster manager. However, simple runs can be done on a workstation with multiple CPUs and even on a workstation with a single CPU (in the latter case, there is no gain in performance, as all processes will run on a single CPU):
mpirun -np <number of CPUs> <application_name.py> <parameters, as described in the documentation> --MPI &
Note about BATCH flag that indicates whether the program runs in a background in a silent mode
BATCH flag is stored in ~/sparx/libpy/global_def.py. When it is set to False (which is a default), the output is both displayed on the screen and written to the log file. All applications (programs beginning with sx) set this flag to True, in which case the output is only written to the log file. However, the user may set this flag to True at any moment, even in interactive session, which will switch off output printed to the screen.
- The name of the log file is specified in the global parameter LOGFILE. The user may change it before a running session.
Note about applications
- All applications are stored in the directory ~/sparx/bin/ , but the files contain only parsing of the input parameters and simple calls to actual SPARX code. The code itself is contained in the file ~/sparx/libpy/applications.py. For the large part, the code is quite straightforward and can be easily modified, so one can create additional applications.