EMAN2 Programming Quickstart

This page contains some example sessions to get you started using EMAN2 from Python. This is not aimed at mainstream users, but is for those wanting to move into programming in EMAN2.

Here is a sample EMAN2 session:

python
>>> from EMAN2 import *
>>> a=test_image()
>>> display(a)              # Use the middle mouse on the image for controls, right mouse to pan
>>> b=[test_image(),test_image(1),test_image(2)]
>>> display(b)              # Again, middle and right mouse
>>> a*=-1
>>> display(a)
>>> c=a.process("filter.lowpass.gauss",{"sigma":.125})        # use 'e2help.py processor [-v]' or from python 'dump_processors()'
>>> display(c)
>>> c=a.copy()              # Note, memory management is automatic, this will delete the old c
>>> c.process_inplace("filter.lowpass.gauss",{"sigma":.125})  # equivalent to above
>>> display(c)              # Note that this blocks !  See below for nonblocking example
>>> print a.cmp("dot",c,{"negative":0,"normalize":1})         # e2help.py cmp [-v] or dump_cmps()
>>> d=c.do_fft()
>>> e=d.calc_radial_dist(64,0.0,1.0,1)                        # radial power spectrum
>>> print e
>>> plot(e)                 # Note that this is a static image, not an interactive plot

If you want to do interactive GUI programming, such as writing a program like 'e2boxer.py --gui' for example, you need to use a PyQT4 event loop. Right now there is a very primitive prompt you can use for this. This will be improved in future:

e2.py
>>> a=[test_image(i) for i in range(3)]
>>> b=EMImage(a)
>>> a[1]*=-1

Now, how does this second example differ from the first. The difference is that it's running within a GUI event loop. So, when you issue the 'b=EMImage(a)' command, an image display window opens, but you immediately get another python prompt. When you then do a[1]*=-1, the change is immediately displayed.

Here are some good links into the documentation: