SciLifeLab workshop: molecular pattern mining and sub-tomogram averaging

We’ll pick and average spikes in ten SARS-CoV-2 tomograms from EMPIAR-10453. Start with the denoised tomograms and membrane segmentations from Session 2.

Your results may look different from the examples and may appear in a different order or under different numbers. Make selections from the images in your own project.

Add each block from the output named below and leave inherited values in place when they match. Turn on Advanced options to see hidden fields.

Prepared workflows

To use preset blocks, open Workflows on one of these outputs.

  • On Tomograms of Denoising (eval), choose Stockholm 2026 S3 - EMPIAR-10453 MiLoPYP-2. When the import asks for Segmentation, click and choose Segmentation (pre-trained models) from Session 2; the later blocks keep it at auto. Choose the supplied model later in Particle picking (eval).

  • On Particles of Particle picking (eval), choose Stockholm 2026 S3 - EMPIAR-10453 sub-tomogram averaging. Its STA centering block reads the sub-volume alignments from its parent automatically.

Pause at the selection steps described below.

Membrane-aware exploration with MiLoPYP-2

MiLoPYP clusters 3D tomogram patches by appearance. Over three rounds we choose examples of spikes to train a particle picker.

Exploration round 1 — Find candidates near membranes

From Tomograms on Denoising (eval), add MiLoPYP (train). Open Parameters → Pattern mining.

  • Set Input type to 3D only.

  • Set Epochs to 20.

  • Set Bounding box (binned voxels) to 72.

  • Set Interval to perform validation to 10.

  • Set Gaussian filter to 0.

  • Set DoG sizes to 2,5.

  • Set DoG cutoff (std multiplier) to 2.

  • Set DoG diameter (binned voxels) to 20.

  • Set DoG boundary margin (binned voxels) to 0.

  • Enable Surface constrained to sample patches only near a segmented membrane. The direction from the nearest point on the segmented membrane to the patch center sets its orientation.

    • Click next to Segmentation and choose Segmentation (pre-trained models) from Session 2. The blocks after this one take it from here: their Segmentation stays at auto.

    • Keep Use DoG at DoG to center patches on detected peaks.

      • Set Min distance to 5.

      • Keep Max distance at 25.

    • Keep Remove segmentation enabled so the membrane outline stands out in the patches.

  • Enable Save patches.

Open Resources → Split. Turn on Advanced options to show Cluster Template.

  • Keep Threads at 12.

  • Set Cluster Template to NVIDIA A6000 Ada.

Click Run.

From MiLoPYP model on training 1, add MiLoPYP (eval). In Pattern mining, choose both files from this round’s training block.

  • Set Trained model (*.pth) to train/<training-run>/model_last.pth. Open the dated folder for the run that just finished.

  • Set Clusters to 20.

  • Keep Bounding box (binned voxels) at 72 to match the saved patches.

  • Set Z Threshold to 4.

  • Set Read patches to train/3d_patch_info_train.npz.

  • Disable Calculate Metrics.

Click Run and open View → Mapping. Each thumbnail is one patch. Patches with a similar appearance group together.

Round 1 mapping with virion interiors at left, carbon edges at upper right, irregular clumps at lower left, and spikes above curved membranes at lower right.

Many patches with red and orange borders on the left are centered inside virions. The blue patches at upper right show carbon edges, and the yellow-green patches at lower left contain irregular clumps. In the green and teal patches at lower right, a curved membrane often sits just below a central spike.

Switch to View → Clusters. All rows start selected. Click a row to exclude it when most centers fall inside a virion, on carbon, or on bare membrane. Keep rows where a spike usually sits at the patch center just above the membrane, even when a neighboring membrane is visible.

Six example clusters. Rows 5 and 12 are marked Keep, and rows 2, 4, 9, and 19 are marked Exclude.

The figure shows six of the 20 clusters, with six patches from each. The blue number is the cluster ID (numbered from 0 in the full gallery). The black number gives its patch count.

  • Cluster 2 groups patches centered inside a virion or on its membrane.

  • Cluster 4 contains irregular clumps like those at the lower left of the plot. The centers rarely show a recognizable spike.

  • Cluster 5 includes spikes between nearby membranes. Keep this row for round 2. A few centers miss the spike, but the crowded patches give the model harder examples to learn from.

  • Cluster 9 follows the carbon edge along the bottom of the patches. The densities above it vary from patch to patch.

  • Cluster 12 shows spike heads at the patch centers, with the curved virion membrane just below them.

  • Cluster 19 follows the carbon edge across the patch center. A spike elsewhere in a patch does not make the center a useful pick.

Where the patches fall in the tomogram

Open View → Tomograms. The patches have the same colors here as in Mapping. Red and orange marks fall inside virions. Many green and teal marks lie over spike heads just outside the membrane. The blue mark lies beside the carbon edge at left. Yellow and yellow-green marks overlap irregular clumps farther down the edge.

Tomogram slice with red and orange marks inside virions, green and teal marks around their surfaces, and a blue mark beside the carbon edge.
Exploration round 2 — Inspect the patch centers

From MiLoPYP particles on evaluation 1, add MiLoPYP (train). Open Pattern mining.

  • Set Epochs to 30.

  • Set Bounding box (binned voxels) to 54.

  • Enable Iterate.

    • Set Patch coordinate location to train/interactive_info_parquet.gzip from evaluation 1.

  • Clear Read patches so training extracts new patches at this size.

Click Run. MiLoPYP extracts a 54-voxel box around each center you kept. At 10.632 Å per voxel, that’s 57 nm across, down from 77 nm.

From MiLoPYP model on training 2, add MiLoPYP (eval). Open Pattern mining and use the files from training 2.

  • Set Trained model (*.pth) to train/<training-run>/model_last.pth from training 2.

  • Keep Clusters at 20.

  • Keep Bounding box (binned voxels) at 54.

  • Keep Z Threshold at 4.

  • Set Read patches to train/3d_patch_info_train.npz from training 2.

  • Enable Skip tomogram visualization.

Click Run and open View → Mapping.

Round 2 mapping with spikes above curved membranes in the lower group, closely spaced membranes at right, and clumped densities near the top.

Many patches near the bottom show a spike head just above the membrane. On the right, a second membrane often enters the patch. The irregular clumps near the top rarely show a recognizable spike.

In View → Clusters, follow the center across each row. Keep rows with repeated spike heads, including crowded views. Exclude rows where most centers fall on bare membrane or irregular clumps.

Exploration round 3 — Choose examples for the picker

From MiLoPYP particles on evaluation 2, add MiLoPYP (train). Open Pattern mining.

  • Set Epochs to 50.

  • Set Bounding box (binned voxels) to 36.

  • Keep Surface constrained enabled.

    • Disable Remove segmentation.

  • Keep Iterate enabled.

    • Set Patch coordinate location to train/interactive_info_parquet.gzip from evaluation 2.

  • Clear Read patches so training extracts the smaller patches with Remove segmentation turned off.

Click Run. At 38 nm across, the crop brings individual spike heads into view even when several lie close together.

From MiLoPYP model on training 3, add MiLoPYP (eval). Open Pattern mining and use the files from training 3.

  • Set Trained model (*.pth) to train/<training-run>/model_last.pth from training 3.

  • Keep Clusters at 20.

  • Keep Bounding box (binned voxels) at 36.

  • Set Z Threshold to 3.

  • Set Read patches to train/3d_patch_info_train.npz from training 3.

Click Run and open View → Mapping.

Round 3 mapping with isolated spike heads at left and spikes among neighboring heads and membranes at right.

On the left, many patches show a single spike head at the center. Spike heads are common on the right too, where another spike or a nearby membrane often shares the patch.

Choose the picker’s training examples in View → Clusters. Follow the center across each row. A spike at the edge would teach the picker the wrong position.

Three example rows from the last exploration round. The excluded row has inconsistent centers. Both kept rows have central spike heads, with more neighboring density in the last row.
  • Cluster 0 often has an edge or background at the patch center.

  • Cluster 3 shows a distinct dark spike head at the center.

  • Cluster 18 is more crowded. Keep it because the central head is still recognizable among neighboring spikes.

Compare exploration settings across three rounds

Parameter

Rounds 1 → 2 → 3

What it changes

For your own data

Epochs

20 → 30 → 50

Fewer patches remain after each selection, so later rounds use more passes through the smaller training set.

If the loss is still falling at the last epoch, train longer. Once it levels off, inspect the clusters.

Bounding box (binned voxels)

72 → 54 → 36

Start with a large box so the neighboring structures help identify promising centers. Smaller boxes bring the spike itself into focus in later rounds.

Check that the entire target still fits in the smallest box.

Remove segmentation

On → on → off

The membrane outline helps us spot centers inside virions early. We turn this off in round 3 to judge the spike heads.

Keep this on while the outline of the segmented region helps you judge which patch centers to keep.

Z Threshold

4 → 4 → 3

A stricter cutoff leaves more outliers unassigned before picker training.

If recognizable targets are left unassigned, raise the cutoff and inspect the clusters again.

MiLoPYP-2 refinement and particle picking

Refinement trains the picker on your selected patch centers. We’ll start training here and use the workshop model to pick the ten tomograms.

Refinement training and evaluation

From MiLoPYP particles on the last MiLoPYP (eval) block, add Particle picking (train). Open Training/Evaluation.

  • Set Coordinates for training to class labels from MiLoPYP.

  • Set Epochs to 5.

  • Set Validation interval (epochs) to 1.

  • Set Validation debug interval (epochs) to 5.

  • Enable Use masking.

    • Keep Segmentation at auto: it uses the segmentation chosen in the first MiLoPYP (train) block.

    • Keep Mask radius at 25.

  • Set Patch size to 128.

  • Set Patch height to 11.

  • Set Patch size downscaling to 6.

Click Run. The first heatmap is written after epoch 5. If time allows, open View → Tomograms → Heat Map then and check whether the bright peaks line up with spike heads. If you stop earlier, go straight to Evaluation with the supplied model.

From Particles model on Particle picking (train), add Particle picking (eval). Open Training/Evaluation.

After a full refinement training run, choose train/<training-run>/model_last.pth from your Particle picking (train) block. Full training takes longer than we have in this session, so use the supplied model below for evaluation.

  • Set Trained model (*.pth) to /fastrs/bartesaghi/nextpyp/workshop/10453/20261201_052817_model_last.pth.

  • Set Particle radius (A) to 80. The picker records this radius with each output coordinate.

  • Keep Output threshold at 0.85.

  • Keep Use masking enabled.

    • Keep Segmentation at auto.

    • Set Mask radius to 50.

  • Keep Use GPU disabled to run evaluation on CPUs.

  • Set Initial particle orientation(s) to from segmentation(s).

    • Keep Segmentation at auto. Each pick starts with its axis perpendicular to the nearby membrane.

Open Resources → Split and turn on Advanced options.

  • Set Threads to 24 (one job per tomogram).

  • Set Total threads to 240. This cap allows up to ten 24-thread jobs to run at once.

  • Set Cluster Template to Default if it still shows NVIDIA A6000 Ada.

Click Run and open View → Particles.

Tomogram slice showing green pick markers around several virions, including a group of closely spaced virions near the center.
Compare refinement settings

Parameter

This run

What it changes

For your own data

Output threshold

0.85

A peak must reach this score to become a pick.

Raise the threshold if weak background peaks are picked. Lower it if recognizable particles might have peaks below the cutoff.

Mask radius

25 in training, 50 in evaluation

Some segmented membranes have gaps. We can afford to miss a few spikes in training. In evaluation we widen the mask to pick up spikes near those gaps.

Widen the mask if gaps in the segmentation leave visible targets outside the search area.

Sub-tomogram averaging with 3DAVG

We extract a small 3D box around each pick so we can align and average the spikes.

Extract sub-volumes

From Particles on Particle picking (eval), add Sub-volume Extraction. Open Particle extraction.

  • Keep Sub-volume export format at 3davg (do not invert contrast).

  • Set Sub-tomogram size (voxels) to 48.

  • Set Sub-tomogram binning to 5.

  • Disable Use existing reconstruction settings.

    • Set 2D filtering to none.

    • Enable Erase fiducials.

    • Set Radial filtering to fakeSIRT (mimic SIRT reconstruction) for SIRT-like contrast in the extracted boxes.

Click Run. At this binning the 48-voxel box spans 31.9 nm, enough to see the spike and the membrane below it. The workshop example contains 2,821 sub-volumes from ten tomograms.

Session 3 checkpoint

To resume with sub-volumes ready, click Import Blocks, choose Archive, and import /fastrs/bartesaghi/nextpyp/workshop/checkpoints/Session-3-Sub-volumes.nextpyp.tbz. The archive contains the raw-data, pre-processing, denoising, particle picking and sub-volume extraction blocks, so you can start STA iteration 1 from its Sub-volume Extraction block.

STA iteration 1 — Establish the spike axis

From Particles on Sub-volume Extraction, add STA centering. Open Parameters → Sub-volume averaging.

  • Click auto next to Alignments from sub-volume averaging (*.txt) so it shows Parent’s output (auto). It uses the extraction block’s frealign/*_original_volumes.txt.

  • Keep Centering iterations at 0.

  • Set Translation tolerance (binned voxels) to 16.

  • Set Mask radius (binned voxels) to 20,20,24.

  • Set Mask apodization (binned voxels) to 0.

  • Set Low-pass filter (cutoff, decay) to 0.2,0.05.

Open Resources → Split. Turn on Advanced options for Total threads.

  • Set Threads to 120.

  • Set Total threads to 0. STA centering, classification, and refinement each use one job for all particles.

Click Run and open View → Centering. With zero centering iterations, the average shows the spikes in their starting poses. We found that shifting the picks gave a poorer average for this dataset.

From Particles on STA centering, add STA classification. Open Sub-volume averaging.

  • Keep Classes at 10.

Click Run and open View → Classification → Reconstruction.

Ten class averages from iteration 1, with example inclusions and reference class 4

In these 3DAVG views, the spike and membrane appear bright. Each tile shows projections across the top and central slices below. Both rows show the same three orientations, with a top view on the left and two side views to its right.

  • Click a class to exclude it if the side views show mostly membrane or neighboring density.

  • Right-click an included class where the spike axis is clear and the membrane is less prominent than the spike, then choose Set as reference.

The green check marks and blue Ref badge identify the four included classes. Membrane density dominates several excluded side views in the bottom row.

From Particles on classification, add STA refinement. Open Sub-volume averaging.

  • Set C symmetry order to 36.

  • Set Out-of-plane rotation tolerance (degrees) to 20.

Click Run and open View → Aligned classes → Reconstruction. The aligned classes start included. Click a tile to exclude it if its spike still tilts away from the others.

Side projections before and after refinement of classes 2, 3, 4, and 5. Class 4 is the reference.

Some classes have tilted spikes. C36 averages the reference over 36 rotations about its axis. Refinement then rotates each class average to line up with that axis.

Each column pairs a side projection from Classification (top) with the same class in Aligned classes (bottom). Class 2 becomes more upright. Even the reference, class 4, looks smoother after averaging about its axis with C36.

From Particles on refinement, add STA alignment. Open Sub-volume averaging.

  • Set C symmetry order to 1.

Particle alignment runs one job per tilt series. Open Resources → Split.

  • Set Threads to 24.

  • Set Total threads to 240.

Click Run. Open View → Reconstruction to see the reference made from the selected class averages.

Round 1 reference with a circular outline in the top view and a broad head in both side views

This block aligns individual particles to that reference with C1.

STA iteration 2 — Use threefold symmetry for the class reference

From Particles on the first alignment, add STA classification.

  • Keep Classes at 10.

  • Set Mask radius (binned voxels) to 18,18,22.

Open Resources → Split.

  • Set Threads to 120.

  • Set Total threads to 0.

Click Run. In Classification, exclude classes dominated by surrounding density, then right-click a retained class and choose Set as reference.

Ten class averages from iteration 2, with example inclusions and reference class 6

The tighter mask cuts out more neighboring density.

From round 2 onward, the number at the lower left of each tile is its distance from the previous reference. Smaller means a closer match. Choose a reference with a clear spike axis in both side views, even if another class has a smaller distance.

From the classifier’s Particles output, add STA refinement.

  • Set C symmetry order to 3.

Click Run. In Aligned classes, exclude any average whose spike still tilts away from the others.

Side projections before and after refinement of classes 2, 5, and 6. Class 6 is the reference.

We now use C3 for the upright class reference.

From refinement’s Particles output, add STA alignment.

  • Set C symmetry order to 1.

Open Resources → Split.

  • Set Threads to 24.

  • Set Total threads to 240.

Click Run and open View → Reconstruction.

Round 2 reference with a broad head that narrows toward its base

The broad head tapers toward the stalk in both side views. Its darker center is clearest in the central slices.

STA iteration 3 — Tighten the mask and widen the search

From Particles on the second alignment, add STA classification.

  • Set Apply offset (binned voxels) to 4. In these data this moves the sampling center along the surface normal toward the spike head.

  • Keep Classes at 10.

  • Set Mask radius (binned voxels) to 16,16,20.

  • Set Low-pass filter (cutoff, decay) to 0.25,0.05.

Open Resources → Split.

  • Set Threads to 120.

  • Set Total threads to 0.

Click Run and choose the classes and reference in Classification.

Ten class averages from iteration 3, with example inclusions and reference class 9

The tighter mask covers the head, and the 0.25 cutoff preserves more detail within it.

From the classifier’s Particles output, add STA refinement.

  • Set C symmetry order to 3.

  • Set Out-of-plane rotation tolerance (degrees) to 30.

  • Set Translation tolerance (binned voxels) to 24.

Click Run and open Aligned classes. The class maps already include the shift toward the head. Keep the aligned classes you want combined into the particle alignment reference.

Side projections before and after refinement of classes 5, 7, and 9. Class 9 is the reference.

The tighter mask concentrates the alignment on the head. The wider search gives tilted or off-center class averages more room to line up with the reference. The next block uses the same limits for individual particles. At this sampling, 24 voxels is about 16 nm.

From refinement’s Particles output, add STA alignment.

  • Set C symmetry order to 1.

  • Keep Out-of-plane rotation tolerance (degrees) at 30.

  • Keep Translation tolerance (binned voxels) at 24.

Open Resources → Split.

  • Set Threads to 24.

  • Set Total threads to 240.

Click Run and open View → Reconstruction.

Round 3 reference with a roughly triangular outline in the top view of the central slice

In the lower-left slice, the top view of the C3 reference now has a roughly triangular outline.

STA iteration 4 — Compare references across all four rounds

From Particles on the third alignment, add STA classification.

  • Set Apply offset (binned voxels) to 0. This round starts from the poses aligned to the shifted round 3 reference. Zero applies no additional shift.

  • Keep Classes at 10.

  • Set Mask radius (binned voxels) to 14,14,20.

  • Set Low-pass filter (cutoff, decay) to 0.3,0.05.

Open Resources → Split.

  • Set Threads to 120.

  • Set Total threads to 0.

Click Run. In Classification, look for a distinct head and stalk in the side views. Include the spike classes and choose Set as reference on one of them.

Ten class averages from iteration 4, with example inclusions and reference class 5

From the classifier’s Particles output, add STA refinement.

  • Set C symmetry order to 3.

  • Keep Out-of-plane rotation tolerance (degrees) at 30.

  • Keep Translation tolerance (binned voxels) at 24.

Click Run and open Aligned classes. Keep the averages that line up for the final reference.

Side projections before and after refinement of classes 5, 7, and 9. Class 5 is the reference.

From refinement’s Particles output, add STA alignment.

  • Set C symmetry order to 1.

  • Keep Out-of-plane rotation tolerance (degrees) at 30.

  • Keep Translation tolerance (binned voxels) at 24.

Open Resources → Split.

  • Set Threads to 24.

  • Set Total threads to 240.

Click Run and open View → Reconstruction.

Round 4 reference with three lobes in the top view and a broad head above a narrow stalk in the side views

Once the reference appears, compare the head and stalk across all four rounds while the particle search runs.

Alignment references from rounds 1 to 4 with a side projection above a top projection in each column
  • Each column shows a side view above a top view.

  • The stalk is clearer by round 4.

  • In the top views, the nearly circular head in round 1 reflects C36. The three lobes in round 4 are visible in a reference built with C3.

  • Particle alignment uses C1 throughout.

Compare STA settings across four rounds

Parameter

Rounds 1 → 2 → 3 → 4

What it changes

For your own data

C symmetry order in STA refinement

36 → 3 → 3 → 3

C36 establishes an upright axis. We then use C3 because the spike is a known trimer.

Use C1 if the symmetry is unknown. A symmetric reference can reinforce its own pattern even in a C1 particle search.

Mask radius (binned voxels)

20,20,24 → 18,18,22 → 16,16,20 → 14,14,20

The first Z radius reaches the edge of the 48-voxel box. Later masks narrow around the spike head.

Inspect all three views for clipping. If the box itself cuts through the target, extract a larger box.

Low-pass filter (cutoff, decay)

0.2,0.05 → 0.2,0.05 → 0.25,0.05 → 0.3,0.05

Cutoff and decay are fractions of Nyquist. At 6.645 Å/voxel, cutoffs of 0.2, 0.25, and 0.3 correspond to nominal spacings of 66, 53, and 44 Å.

Raise the cutoff once several classes show consistent detail.

Optional Calculate reconstruction

Go back to the fourth STA classification and add Calculate reconstruction from its Particles output. This uses the orientations and shifts from round 3 for the classes you select in round 4.

Open Sample.

  • Set Molecular weight (kDa) to 450.

  • Set Particle radius (A) to 100. Here it sets the approximate size of the particle for display.

  • Set Particle symmetry to C3.

Open Particle extraction.

  • Set Box size (pixels) to 48.

  • Set Image binning to 5.

Open Resources → Split and turn on Advanced options.

  • Set Threads to 24.

  • Set Total threads to 240.

If time permits, click Run. The three classes in the example contribute 515 of the 2,821 picks. To postpone filtering on your own data, keep all classes selected in the classifier.

Session 4 uses a separate HIV-1 Gag dataset.

Applying this to your own data

If a cluster still mixes your target with background, another exploration round can help separate the two before picker training. See Iteration 3 → Evaluation in the MiLoPYP-2 exploration guide.

For further alignment options, see the 3DAVG guide.