Particle recentering from Relion to Warp

559 views
Skip to first unread message

Juan Carlos De la Concepción

unread,
Sep 25, 2023, 8:07:02 AM9/25/23
to Warp
Hi all,

After extracting subtomograms at high binning in Warp and refining the particles in Relion all the way to Nyquist, I'm trying to recenter the _rlnCoordinates of my particles (i.e. add _rlnOriginX/Y/ZAngst to _rlnCoordinateX/Y/Z, then decrease _rlnOriginX/Y/ZAngst to sub-pixel accuracy -- although I realized that these coordinates are not expressed in the same reference frame) to extract subtomograms at lower binning in Warp. So far, averaging particles re-extracted at lower binning with my text-edited .star files came out as only noise. Not-recentered subtomos gave a reasonable average but I would like them recentered.

tl;dr : Does any of you know how to recenter the particles coming from Relion in a way that Warp can understand?

That would equate with using relion_preprocess --recenter on a .star file without actually extracting subtomograms. (since my tomograms are set up in Warp but not in relion, extraction fails.) I tried `relion_star_handler --center`  but it only acts on _rlnOriginX/Y/ZAngst, not on  _rlnCoordinateX/Y/Z.

Thanks a lot for helping!
JC

Alister Burt

unread,
Sep 25, 2023, 8:35:40 AM9/25/23
to Juan Carlos De la Concepción, Warp
Hi Juan-Carlos,

Absolute position is rlnCoordinateX/Y/Z - (rlnOriginX/Y/Z / pixel size)

You can then add the shifts you need (taking care of the negative sign) 

If you want a quick demo for STAR file manipulation in Python happy to jump on zoom over the next few days

Cheers,

Alister 
Sent from mobile - apologies for brevity

On 25 Sep 2023, at 13:07, Juan Carlos De la Concepción <jcdelaco...@gmail.com> wrote:

Hi all,
--
You received this message because you are subscribed to the Google Groups "Warp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to warp-em+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/warp-em/d4e45899-29e6-4d35-83ba-804b3fa26323n%40googlegroups.com.

Juan Carlos De la Concepción

unread,
Sep 25, 2023, 9:01:25 AM9/25/23
to Warp

Dear Alister,
OK for dividing rlnOriginX/Y/Z by the pixel size to get it in pixels, but 
lines 1013-1022 of https://github.com/3dem/relion/blob/master/src/apps/star_handler.cpp show that rlnOriginX/Y/Z is using rotated X' Y' Z' coordinates compared to rlnCoordinateX/Y/Z :
"
// Project the center-coordinates
Euler_angles2matrix(rot, tilt, psi, A3D, false);
my_projected_center = A3D * my_center;

xoff -= XX(my_projected_center);
yoff -= YY(my_projected_center);

// Set back the new centers
MD.setValue(EMDL_ORIENT_ORIGIN_X_ANGSTROM, xoff*angpix);
MD.setValue(EMDL_ORIENT_ORIGIN_Y_ANGSTROM, yoff*angpix);
"
We actually want to rotate the shifts back in the """world""" X Y Z frame before getting   rlnCoordinateX/Y/Z - (rotated_rlnOriginX/Y/Z / pixel size) ,   but maybe someone has a script ready for that already ?

Thanks!
JC and Olivier

Alister Burt

unread,
Sep 25, 2023, 10:06:35 AM9/25/23
to Juan Carlos De la Concepción, Warp
RELION centers the particle, then rotates it so if you’re only applying a shift you can just update the position

The simplest workflow:

- update rlnCoordinateX/Y/Z to account for the previous shifts and the recentering, remove shifts from the file
- extract new particles in warp

If you have extracted ‘pre-oriented subtomograms’ then you have to worry about rotating the shifts -> generate the rotation matrix from the euler angles, use it to rotate the shifts

Cheers,

Alister

Sent from mobile - apologies for brevity

On 25 Sep 2023, at 14:01, Juan Carlos De la Concepción <jcdelaco...@gmail.com> wrote:



Alister Burt

unread,
Sep 25, 2023, 10:08:08 AM9/25/23
to Juan Carlos De la Concepción, Warp
The code you linked is calculating what the shift should be in a 2D image which is already centered in a certain place -> a different problem which you do need to account for rotations to calculate 

Sent from mobile - apologies for brevity

On 25 Sep 2023, at 14:01, Juan Carlos De la Concepción <jcdelaco...@gmail.com> wrote:



Juan Carlos De la Concepción

unread,
Sep 26, 2023, 6:22:41 AM9/26/23
to Warp
Thanks a lot Alister,

It turned out to be a mistake on the recentering code.  I did not include a minus so I was adding the shifts rather than subtracting them... :/

Cheers,
JC

Tyler Brittain

unread,
Feb 6, 2025, 8:05:15 PMFeb 6
to Warp
Hi all,

I have a similar issue. I'm trying to shift the box center of my subtomos(based on my Refine3D map) to the edge of my particle and then use the ts_export_particles job in warp to reextract my sub-particles. relion_star_handler --center_X(Y and Z) isn't changing the _rlnCoordinateX(Y or Z). Is there a simple way to do this? The above conversation was not entirely clear to me. I'm fine with just shifting the box center but if possible it would be great to keep the orientations from previous refinements.

Any help is greatly appreciated,

Tyler

Avrin Ghanaeian

unread,
Feb 7, 2025, 11:26:53 AMFeb 7
to Warp

Hi all,

I’m encountering the same issue. I need to shift the box center of my subtomograms (based on my Refine3D map) to the new center of my particle and then use the ts_export_particles job in Warp to re-extract my sub-particles.

Is there any available code or method to adjust the particle centers? The previous conversation on this topic wasn’t entirely clear to me.

I’d appreciate any guidance. Thanks in advance for your help!

Best,
Avrin

Alister Burt

unread,
Feb 7, 2025, 1:29:43 PMFeb 7
to Avrin Ghanaeian, Warp
Hi both,

Here's a script to recenter particles in particle STAR files output by ts_export_particles.
These are RELION 3.1+ style star files (optics groups, shifts in angstroms), you'll have to adapt it for your own needs if your data looks different

To run it, install uv then uv run recenter_3d.py

 Usage: recenter_3d.py [OPTIONS]                                                                                                                                                
                                                                                            
╭─ Options ────────────────────────────────────────────────────────────────────────────────╮
│ *  --input   -i      PATH                    input star file [default: None] [required]  │
│ *  --shift   -s      <FLOAT FLOAT FLOAT>...  shift x, y and z [default: None] [required] │
│ *  --output  -o      PATH                    output star file [default: None] [required] │
│    --help                                    Show this message and exit.                 │
╰──────────────────────────────────────────────────────────────────────────────────────────╯

Example:
uv run recenter_3d.py -i particles_3d.star -s 0 0 0 -o test_3d.star
Reading inline script metadata from `recenter_3d.py`
[10:25:53] particles_3d.star read                                                                             recenter_3d.py:35
           optics table merged                                                                                recenter_3d.py:41
           1258 particles found                                                                               recenter_3d.py:42
           grabbing relevant info...                                                                          recenter_3d.py:45
           got shifts from 'rlnCoordinateX', 'rlnCoordinateY', 'rlnCoordinateZ'                               recenter_3d.py:48
           got pixel spacing from 'rlnImagePixelSize'                                                         recenter_3d.py:51
           got euler angles from 'rlnAngleRot', 'rlnAngleTilt', 'rlnAnglePsi'                                 recenter_3d.py:54
           got shifts from 'rlnOriginXAngst', 'rlnOriginYAngst', 'rlnOriginZAngst'                            recenter_3d.py:58
           converted shifts to angstroms                                                                      recenter_3d.py:66
           applied shifts to particle positions                                                               recenter_3d.py:68
           calculated rotation matrices from euler angles                                                     recenter_3d.py:72
           calculated shifted particle positions                                                              recenter_3d.py:81
           calculated new shifts from shifted particle positions                                              recenter_3d.py:86
           updated shift values in 'rlnOriginXAngst', 'rlnOriginYAngst', 'rlnOriginZAngst'                    recenter_3d.py:89
           Output with updated shifts written to test_3d.star                                                 recenter_3d.py:94

Cheers,

Alister

Tyler Brittain

unread,
Feb 7, 2025, 3:54:05 PMFeb 7
to Warp
Alister,

Thanks for the quick response. Just to be clear, i should run this script which calculates the new shifts in values of rlnOriginXAngst(Y and Z) and then for plugging into ts_export_particles, i will have to take the (rlnCoordinateX - (the newly calculated rlnOriginXAngst/my pixel size)) and that becomes the rlnCoordinateX for the star file used in ts_export_particles job? I'm under the impression that the star file used in ts_export_particles can only have tomostar, rlnCoordinateX(Y and Z).

Best,

Tyler

Alister Burt

unread,
Feb 7, 2025, 4:27:50 PMFeb 7
to Tyler Brittain, Warp
Hi Tyler,

No - you should be able to extract directly from this file. What makes you think it can only have x/y/z?

Cheers,

Alister

Tyler Brittain

unread,
Feb 7, 2025, 4:35:26 PMFeb 7
to Warp
Alister,

When i extract with the rest of the metadata (_rlnOriginXAngst) present in the star file the export job crashes. Usually with an error like this "Value cannot be null. (Parameter 'second')"

Best,

Tyler

Alister Burt

unread,
Feb 7, 2025, 4:44:10 PMFeb 7
to Tyler Brittain, Warp
Hi Tyler,

I can't reproduce, the following extracts successfully

WarpTools ts_export_particles \
--settings warp_tiltseries.settings \
--input_star relion/Refine3D/job004/run_it002_data.star \
--coords_angpix 4 \
--output_star relion/test_with_shifts.star \
--output_processing particle_export_with_shifts \
--output_angpix 4 \
--box 96 \
--diameter 130 \
--relative_output_paths \
--2d

Tyler Brittain

unread,
Feb 7, 2025, 6:51:23 PMFeb 7
to Warp
Alister,

Thank you, it is working now and the shifts look good. I'm running all of my stuff on a cluster and to run any of the MCore jobs i had to create a separate conda environment and install warp in that environment. I just ran the ts_export_particles job in that environment and now it is working with the star file with all metadata present. I'm not sure why ts_export_particles was working ok with just tomostar, X, Y, and Z before.

Thanks again for all your help!

Tyler

Kewei Gu

unread,
Oct 10, 2025, 7:23:52 AM (8 days ago) Oct 10
to Warp

Hi Alister,

Thank you again for your clear explanation on using relion_star_handler to reset particle positions.

I now have another related question:

Is there a way to move the box center to a specific, fixed position in the refined reference map (for example, to recenter all particles so that a chosen structural feature ends up at the box center)?

I’d appreciate any guidance you could share on how best to approach this

Best regards

Kewei Gu

Alister Burt

unread,
Oct 10, 2025, 10:22:09 AM (8 days ago) Oct 10
to Kewei Gu, Warp
Hi Kewei,

You can do this on M species using MTools rotate_species and shift_species



For RELION star files I always do this with Python scripts, because there are so many variants of STAR files these days I always end up having to modify them each time I use them…

This script recenters but the function can both recenter and reorient


Cheers and good luck,

Alister

Sent from mobile - apologies for brevity

On Oct 10, 2025, at 04:23, Kewei Gu <frootl...@gmail.com> wrote:



Kewei Gu

unread,
Oct 13, 2025, 8:06:25 AM (5 days ago) Oct 13
to Warp

Hi Alister,

Sorry for the delayed reply, and thank you so much for sharing your script!

I tried it out, and it worked perfectly — it really did move the box center exactly to the position I wanted. I truly appreciate your help.

I have two small questions if you don’t mind:

  1. In RELION there seem to be multiple commands like --center and --recenter.

    My understanding is that both are used to shift the subtomogram center to a specific position.

    Is that correct? If so, could you please explain the difference between them?

  2. Since I’m still new to structural biology and not very familiar with the code, I’d like to confirm my understanding:

    Does your script (and the --center operation in RELION) calculate each subtomo’s new position in the tomogram by combining both the Euler angles and the translational offsets?

    In contrast, if I only use

    rlnCoordinateX/Y/Z - (rlnOriginX/Y/Z / pixel size),

    that would simply shift the subtomo’s center in tomogram space without taking its orientation into account — is that right?

    I’m also wondering whether rlnOriginX/Y/Z are defined purely in tomogram coordinates, meaning that without Euler angles they can only adjust the position but not fully describe where each subtomo sits in 3D space.

Thank you again for your time and for being so generous in sharing your experience — I really learned a lot from your message.

Sorry if I’ve asked too many questions and taken up your time; I truly appreciate your patience.

Best wishes,

Kewei Gu

Alister Burt

unread,
Oct 13, 2025, 9:50:01 AM (5 days ago) Oct 13
to Kewei Gu, Warp
Hi Kewei,

Asking questions is how we learn! 

1. I’m not sure
2. Yes your intuition is perfect, more concretely

- you have a shift vector defined in the coordinate system of your reference
- you have the position and orientation (the pose) of each particle within the tomogram
- you calculate the new pose of each particle in the tomogram based on this information

Any errors in initial particle poses will propagate 

Cheers,

Alister

Sent from mobile - apologies for brevity

Alister Burt

unread,
Oct 13, 2025, 9:51:06 AM (5 days ago) Oct 13
to Kewei Gu, Warp
Oh and yes, origin* RELION cols are shifts

Sent from mobile - apologies for brevity

Kewei Gu

unread,
Oct 13, 2025, 12:15:06 PM (5 days ago) Oct 13
to Warp
Thank you so much!
Reply all
Reply to author
Forward
0 new messages