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 forSegmentation, 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 typeto 3D only.Set
Epochsto 20.Set
Bounding box (binned voxels)to 72.Set
Interval to perform validationto 10.Set
Gaussian filterto 0.Set
DoG sizesto 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 constrainedto 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
Segmentationand choose Segmentation (pre-trained models) from Session 2. The blocks after this one take it from here: theirSegmentationstays at auto.Keep
Use DoGat DoG to center patches on detected peaks.Set
Min distanceto 5.Keep
Max distanceat 25.
Keep
Remove segmentationenabled so the membrane outline stands out in the patches.
Enable
Save patches.
Open Resources → Split. Turn on Advanced options to show Cluster Template.
Keep
Threadsat 12.Set
Cluster Templateto 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)totrain/<training-run>/model_last.pth. Open the dated folder for the run that just finished.Set
Clustersto 20.Keep
Bounding box (binned voxels)at 72 to match the saved patches.Set
Z Thresholdto 4.Set
Read patchestotrain/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.
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.
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.
Exploration round 2 — Inspect the patch centers
From MiLoPYP particles on evaluation 1, add MiLoPYP (train). Open Pattern mining.
Set
Epochsto 30.Set
Bounding box (binned voxels)to 54.Enable
Iterate.Set
Patch coordinate locationtotrain/interactive_info_parquet.gzipfrom evaluation 1.
Clear
Read patchesso 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)totrain/<training-run>/model_last.pthfrom training 2.Keep
Clustersat 20.Keep
Bounding box (binned voxels)at 54.Keep
Z Thresholdat 4.Set
Read patchestotrain/3d_patch_info_train.npzfrom training 2.Enable
Skip tomogram visualization.
Click Run and open View → Mapping.
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
Epochsto 50.Set
Bounding box (binned voxels)to 36.Keep
Surface constrainedenabled.Disable
Remove segmentation.
Keep
Iterateenabled.Set
Patch coordinate locationtotrain/interactive_info_parquet.gzipfrom evaluation 2.
Clear
Read patchesso training extracts the smaller patches withRemove segmentationturned 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)totrain/<training-run>/model_last.pthfrom training 3.Keep
Clustersat 20.Keep
Bounding box (binned voxels)at 36.Set
Z Thresholdto 3.Set
Read patchestotrain/3d_patch_info_train.npzfrom training 3.
Click Run and open View → Mapping.
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.
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 |
|---|---|---|---|
|
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. |
|
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. |
|
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. |
|
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 trainingto class labels from MiLoPYP.Set
Epochsto 5.Set
Validation interval (epochs)to 1.Set
Validation debug interval (epochs)to 5.Enable
Use masking.Keep
Segmentationat auto: it uses the segmentation chosen in the first MiLoPYP (train) block.Keep
Mask radiusat 25.
Set
Patch sizeto 128.Set
Patch heightto 11.Set
Patch size downscalingto 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 thresholdat 0.85.Keep
Use maskingenabled.Keep
Segmentationat auto.Set
Mask radiusto 50.
Keep
Use GPUdisabled to run evaluation on CPUs.Set
Initial particle orientation(s)to from segmentation(s).Keep
Segmentationat auto. Each pick starts with its axis perpendicular to the nearby membrane.
Open Resources → Split and turn on Advanced options.
Set
Threadsto 24 (one job per tomogram).Set
Total threadsto 240. This cap allows up to ten 24-thread jobs to run at once.Set
Cluster Templateto Default if it still shows NVIDIA A6000 Ada.
Click Run and open View → Particles.
Compare refinement settings
Parameter |
This run |
What it changes |
For your own data |
|---|---|---|---|
|
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. |
|
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 formatat 3davg (do not invert contrast).Set
Sub-tomogram size (voxels)to 48.Set
Sub-tomogram binningto 5.Disable
Use existing reconstruction settings.Set
2D filteringto none.Enable
Erase fiducials.Set
Radial filteringto 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’sfrealign/*_original_volumes.txt.Keep
Centering iterationsat 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
Threadsto 120.Set
Total threadsto 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
Classesat 10.
Click Run and open View → Classification → Reconstruction.
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 orderto 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.
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 orderto 1.
Particle alignment runs one job per tilt series. Open Resources → Split.
Set
Threadsto 24.Set
Total threadsto 240.
Click Run. Open View → Reconstruction to see the reference made from the selected class averages.
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
Classesat 10.Set
Mask radius (binned voxels)to 18,18,22.
Open Resources → Split.
Set
Threadsto 120.Set
Total threadsto 0.
Click Run. In Classification, exclude classes dominated by surrounding density, then right-click a retained class and choose Set as reference.
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 orderto 3.
Click Run. In Aligned classes, exclude any average whose spike still tilts away from the others.
We now use C3 for the upright class reference.
From refinement’s Particles output, add STA alignment.
Set
C symmetry orderto 1.
Open Resources → Split.
Set
Threadsto 24.Set
Total threadsto 240.
Click Run and open View → Reconstruction.
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
Classesat 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
Threadsto 120.Set
Total threadsto 0.
Click Run and choose the classes and reference in Classification.
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 orderto 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.
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 orderto 1.Keep
Out-of-plane rotation tolerance (degrees)at 30.Keep
Translation tolerance (binned voxels)at 24.
Open Resources → Split.
Set
Threadsto 24.Set
Total threadsto 240.
Click Run and open View → Reconstruction.
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
Classesat 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
Threadsto 120.Set
Total threadsto 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.
From the classifier’s Particles output, add STA refinement.
Set
C symmetry orderto 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.
From refinement’s Particles output, add STA alignment.
Set
C symmetry orderto 1.Keep
Out-of-plane rotation tolerance (degrees)at 30.Keep
Translation tolerance (binned voxels)at 24.
Open Resources → Split.
Set
Threadsto 24.Set
Total threadsto 240.
Click Run and open View → Reconstruction.
Once the reference appears, compare the head and stalk across all four rounds while the particle search runs.
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 |
|---|---|---|---|
|
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. |
|
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. |
|
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 symmetryto C3.
Open Particle extraction.
Set
Box size (pixels)to 48.Set
Image binningto 5.
Open Resources → Split and turn on Advanced options.
Set
Threadsto 24.Set
Total threadsto 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.