Skip to content

Instantly share code, notes, and snippets.

@alisterburt
alisterburt / napari_projector.py
Created February 28, 2025 17:55
render a projection below a volume in napari
import napari
import mrcfile
import torch
from torch_fourier_slice import project_3d_to_2d
volume = torch.tensor(mrcfile.read("run_class001.mrc")).float()
projection = project_3d_to_2d(volume, rotation_matrices=torch.eye(3))
d, h, w = volume.shape
@alisterburt
alisterburt / recenter_3d.py
Created February 7, 2025 18:19
recenter 3D particles in RELION 3.1+ style STAR files
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "pandas",
# "scipy",
# "starfile",
# "typer",
# "einops",
# "rich",
# ]
@alisterburt
alisterburt / recenter.py
Last active February 6, 2025 22:21
recenter particles r3.1+ for bryce
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "pandas",
# "scipy",
# "starfile",
# "typer",
# "einops",
# ]
# [tool.uv]
@alisterburt
alisterburt / star_merge.py
Created February 4, 2025 19:08
merge simple one loop block star files
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "pandas",
# "starfile",
# "typer",
# ]
# [tool.uv]
# exclude-newer = "2025-01-01T00:00:00Z"
# ///
@alisterburt
alisterburt / dynamo2warp.py
Last active February 4, 2025 18:03
works on per-tomogram table files and takes corresponding tomostar file name as input
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "dynamotable",
# "pandas",
# "scipy",
# "starfile",
# "typer",
# ]
# [tool.uv]
@alisterburt
alisterburt / dynamo2warp.py
Created February 3, 2025 18:15
standalone dynamo to warp particle metadata conversion, to run `uv run dynamo2warp.py`
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "dynamotable",
# "pandas",
# "scipy",
# "starfile",
# "typer",
# ]
# [tool.uv]
@alisterburt
alisterburt / dynamo2warp.py
Created February 3, 2025 18:15
standalone dynamo -> warp particle metadata conversion
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "dynamotable",
# "pandas",
# "scipy",
# "starfile",
# "typer",
# ]
# [tool.uv]
from functools import partial
import napari
from magicgui.widgets import Button, Container
from scipy.spatial.transform import Rotation as R
from skimage import data
viewer = napari.Viewer(ndisplay=3)
blobs = data.binary_blobs(n_dim=3, length=32, volume_fraction=0.1)
viewer.add_image(blobs)
@alisterburt
alisterburt / warp_grid_parse.py
Created November 16, 2024 00:12
parse warp grids in python
from lxml import etree
json_file = "/Users/burta2/data/fakery/MotionAndCTF2D/average/20170629_00021_frameImage_motion.json"
# <GridMovementX Width="1" Height="1" Depth="3" MarginX="0" MarginY="0" MarginZ="0">
# <Node X="0" Y="0" Z="0" Value="-5.1639977" />
# <Node X="0" Y="0" Z="1" Value="0.7089546" />
# <Node X="0" Y="0" Z="2" Value="4.455043" />
# </GridMovementX>
# <GridMovementY Width="1" Height="1" Depth="3" MarginX="0" MarginY="0" MarginZ="0">
@alisterburt
alisterburt / reliondirfinder.py
Last active October 15, 2024 18:41
find relion directories
import os
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path
def find_relion_dirs(root_dir):
"""
Recursively walks through the directory and finds all directories that contain a 'Refine3D' or 'Class3D' subdirectory.
Args: