Aretomo3 alignments into EMAN2

24 views
Skip to first unread message

Molly Gravett

unread,
Oct 7, 2025, 6:30:24 AM (14 days ago) Oct 7
to EMAN2
Hello,

I am writing a script to convert my aretomo3 imod-style .xf file and .tlt file into a json to do an EMAN2 reconstruction with the --load flag. I have kind of used a combination of Alistair Burt's emanjson2imodxf and tomoguide's aretomo3torelion5. But I am noticing some discrepancies between how imod and eman2 reconstruct and I was wondering if you could help. 

This is my code:

def readxf(xf_file, tlt_file):
    # EMAN translates then rotates, IMOD rotates then translates
    # R(x+dx, y+dy) = R(x, y) + R(dx, dy)
    # IMOD (dx, dy) is the rotated EMAN (dx, dy)
    xf_array = np.loadtxt(xf_file) #load imod xf file
    tlt_array = np.loadtxt(tlt_file) #load imod tlt file
    A11 = xf_array[:,0] #column 1 in xf 0,0 of 2D rot matrix
    A12 = xf_array[:,1] #column 2 in xf 0,1 of 2D rot matrix
    A21 = xf_array[:,2] #column 3 in xf 1,0 of 2D rot matrix
    A22 = xf_array[:,3] #column 4 in xf 1,1 of 2D rot matrix
    dx_imod = xf_array[:,4] #column 5 in xf, shift in x
    dy_imod = xf_array[:,5] #column 6 in xf shift in y
    rotation_matrices = np.zeros([len(A11),3,3]) #make empty array to put xf file data into 3x3 transformation matrices
    rotation_matrices[:, 0, 0] = A11
    rotation_matrices[:, 0, 1] = A12
    rotation_matrices[:, 1, 0] = A21
    rotation_matrices[:, 1, 1] = A22
    rotation_matrices[:, 0, 2] = dx_imod
    rotation_matrices[:, 1, 2] = dy_imod
    rotation_matrices[:, 2, 2] = [1.0]*len(A11)
    T_inv = np.linalg.inv(rotation_matrices) #invert matrices to find shift in eman
    dx_eman = T_inv[:,0,2]
    dy_eman = T_inv[:,1,2]
    z_rot = np.degrees(np.arctan2(A12,A11))#find refined tilt axis in degrees
    y_tilt = tlt_array #list of tilt angles from tlt
    x_tilt = [0.0]*len(A11) #xtilt is 0
    return dx_eman, dy_eman, z_rot, y_tilt, x_tilt

def imodxf2emanjson(xf_file, tlt_file): #tomoguide for aretomo to relion
    Path('info').mkdir(parents=True, exist_ok=True) #make directory in eman style structure
    json_name = f'info/{tomo_name}_info.json' #name of json
    tomo_json = js_open_dict(json_name) #open empty json
    dx, dy, z_rot, y_tilt, x_tilt = readxf(xf_file, tlt_file) #get data from xf file
    json = np.stack((dx, dy, z_rot, y_tilt, x_tilt), axis=-1) #xf data in correct format
    tomo_json['apix_unbin'] = '2.21' #pixel size angstroms
    tomo_json['tlt_file']="tiltseries/tomo01.mrc.hdf" #tilt series path
    tomo_json['tlt_params'] = json #write xf data to json tlt_params

When I use the tilt axis calculated from the xf file (-90.17) my tomogram is a 180 degree rotation about z away from the imod reconstruction. I noticed that in the documentation it says imod stores the tilt axis with the opposite sign (90.17) which would be 180 degrees away, but when I reconstruct with this the z seems to be flipped (more like 180 about y and 90 about z). I have attached screenshots for reference (slice number is the z slice).

Many thanks,
Molly
tomo_90.17_slice40.png
imod_slice251.png
tomo_-90.17_slice460.png
imod_slice460.png
tomo_90.17_slice251.png
tomo_-90.17_slice251.png

Steve Ludtke

unread,
Oct 7, 2025, 6:53:40 AM (13 days ago) Oct 7
to em...@googlegroups.com
It can be quite challenging to get this sort of geometry sorted out properly. The first question, which I can't tell from your screenshots, is whether you are looking at a 180 degree rotation or a mirroring?  The second question is whether the data you're working with was saved on the microscope in MRC format or another format (and what type of detector it is)?

--
--
----------------------------------------------------------------------------------------------
You received this message because you are subscribed to the Google
Groups "EMAN2" group.
To post to this group, send email to em...@googlegroups.com
To unsubscribe from this group, send email to eman2+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/eman2

---
You received this message because you are subscribed to the Google Groups "EMAN2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eman2+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/eman2/c594f190-cf73-4473-b43c-c60e977f8aadn%40googlegroups.com.
<tomo_90.17_slice40.png><imod_slice251.png><tomo_-90.17_slice460.png><imod_slice460.png><tomo_90.17_slice251.png><tomo_-90.17_slice251.png>

Molly Gravett

unread,
Oct 7, 2025, 8:25:31 AM (13 days ago) Oct 7
to em...@googlegroups.com
Hi Steve,

So the tomo_-90.17 is a 180 degree rotation difference from the imod. The tomo_90.17 is a mirror of the imod (the ice chunk is at slice 460 in the imod and slice 40 in the tomo_90.17). We save our data in tiff format at the microscope and we have a K2 detector. 

Thanks!
Molly

You received this message because you are subscribed to a topic in the Google Groups "EMAN2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/eman2/g20A9_q97UA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to eman2+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/eman2/4FF51CDF-A141-44C1-A1E5-8A174B142798%40gmail.com.

Steve Ludtke

unread,
Oct 7, 2025, 8:42:16 AM (13 days ago) Oct 7
to em...@googlegroups.com
Ok, if you're going to rotate the tilt axis by 180 degrees, that will, indeed cause a mirroring. If you need to do that to get the reconstruction in the orientation you want you should also multiply the tilt angle by -1. I think that should clear up the flip and the orientation. I think the orientation refinement in e2tomogram should clean up any remaining issues with out of plane tilts...

On Oct 7, 2025, at 5:30 AM, Molly Gravett <moll...@gmail.com> wrote:

Molly Gravett

unread,
Oct 7, 2025, 11:53:40 AM (13 days ago) Oct 7
to em...@googlegroups.com
It's worked! Amazing thank you!

You received this message because you are subscribed to a topic in the Google Groups "EMAN2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/eman2/g20A9_q97UA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to eman2+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/eman2/76BC9067-051A-4201-869F-0BBFC7A10421%40gmail.com.

Steve Ludtke

unread,
Oct 7, 2025, 6:31:42 PM (13 days ago) Oct 7
to em...@googlegroups.com
Great, but, I'd also point out that if you're doing CTF corrected subtomogram averaging using this strategy, that flipping the axis like this isn't arbitrary. If you use the wrong axis you will invert the direction of the defocus gradient and make the CTF correction inaccurate. Doing the CTF correction requires an additional step (see the tutorial) but could result in an inconsistency. If it does cause an inconsistency it indicates that IMOD would presumably have the same problem if trying to do CTF correction there.

Molly Gravett

unread,
Oct 16, 2025, 10:53:37 AM (4 days ago) Oct 16
to EMAN2
Hi Steve,

Thank you for this. I have input the defocus values from aretomo3 into the json, so I assume that these match the axis, but I will run a handedness check. In case anyone else would like to use the conversion script I have uploaded it onto github.


Thanks!
Molly

Reply all
Reply to author
Forward
0 new messages