Skip to content

Instantly share code, notes, and snippets.

@alisterburt
alisterburt / dynamo_activate.sh
Last active October 1, 2020 14:37
Dynamo standalone activation script for shell environment
#!/bin/bash
# Set DYNAMO_ROOT and WORKING_DIR
WORKING_DIR=${PWD}
DYNAMO_ROOT="/opt/dynamo/1.1.514"
# Add CUDA installation to LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
# Activate dynamo in the current shell environment
cd ${DYNAMO_ROOT}
@alisterburt
alisterburt / dipoles2vesicles.m
Created October 1, 2020 14:36
convert dynamo dipoleSet models into oversampled vesicle models
function dipoles2vesicles(catalogue_name, distance_between_particles)
%%% to be run in the folder which holds your catalogue
%%%
%%% catalogue name - name of catalogue containing your dipoleSet models
%%% distance_between_particles - expected distance between particles in px
%%% (output points will be oversampled relative to this value)
%%%
%%% if you want to restart - !rm */*/*/*/*rawVesicle*.omd
p = [catalogue_name,'/tomograms/*/models/*.omd'];
model_files = dir(p);
@alisterburt
alisterburt / relion_star_orientation_distribution.py
Created October 2, 2020 20:53
plot relion euler angle distribution on stereonet
#!/usr/bin/env python
import click
import starfile
import matplotlib.pyplot as plt
import mplstereonet
@click.command()
@click.option('--star_file', '-s', prompt='Input STAR file', type=click.Path(exists=True))
def star_orientation_distribution(star_file):
star = starfile.read(star_file)
@alisterburt
alisterburt / res2fpix.py
Created October 2, 2020 20:55
resolution in angstroms to fourier index
#!/usr/bin/env python
import click
@click.command()
@click.argument('resolution_angstroms', required=False)
@click.argument('angstroms_per_pixel', required=False)
@click.argument('box_size', required=False)
@click.option('-res',
'--resolution_angstroms',
@alisterburt
alisterburt / fpix2res.py
Created October 2, 2020 20:56
fourier index to angstrom resolution
#!/usr/bin/env python
import click
@click.command()
@click.argument('fourier_pixel_extent', required=False)
@click.argument('angstroms_per_pixel', required=False)
@click.argument('box_size', required=False)
@click.option('-fpix',
'--fourier_pixel_extent',
@alisterburt
alisterburt / relion_class_select.py
Created October 2, 2020 21:08
select classes from relion STAR files
#!/usr/bin/env python
import click
import starfile
@click.command()
@click.option('--star_file', prompt='Input STAR file')
@click.option('--class_idx', type=int, prompt='Class number')
def class_select(star_file, class_idx):
star = starfile.read(star_file)
subset = star[star['rlnClassNumber']==class_idx]
@alisterburt
alisterburt / dms2mod.m
Created October 6, 2020 07:52
convert dynamo markers files into imod model files
function dms2mod(markers_dms_file, model_file, image_file)
%%%%% Convert Dynamo markers (.dms files) into IMOD format model files (.mod)
%%%%% Requires MATLAB >= r2019a
%%%%% Requires Dynamo >= 1.1.478
%%%%% Requires IMOD >= 4.10.37
%%% Reading marker file
m = dread(markers_dms_file);
%%% Extract useful objects
markers = m.shapes;
@alisterburt
alisterburt / vll2table.m
Created October 7, 2020 14:01
dynamo vll file to table and table map
function table = vll2table(vll_file)
%%% Convert a vll file into a table and corresponding tomogram table-map file
% Read volume list file
volume_list = ptdb.volumelisttext2object(vll_file).volumes;
% Prepare output filenames
table_file_name = strrep(vll_file, '.vll', '.tbl');
table_map_file_name = strrep(vll_file, '.vll', '_tablemap.doc');
@alisterburt
alisterburt / align_two_3d_vectors.py
Created October 18, 2020 13:31
find rotation matrix to align two normalised vectors in 3d avoiding trig calls
import numpy as np
def align(a, b):
"""
Find r such that r @ a = b when a and b are normalised vectors
:param a: normalised vector of length 3
:param b: normalised vector of length 3
:return: rotation matrix
"""
# cross product to find axis about which rotation should occur
@alisterburt
alisterburt / align_two_3d_vectors_vectorised.py
Last active May 12, 2022 18:30
vectorised version of align_two_3d_vectors.py
def align_vectorised(a: np.ndarray, b: np.ndarray):
"""
Find array of rotation matrices r such that r @ a = b when a and b are arrays of normalised vectors
implementation designed to avoid trig calls
based on https://iquilezles.org/www/articles/noacos/noacos.htm
:param a: normalised vector(s) of length 3
:param b: normalised vector(s) of length 3
:return: rotation matrix
"""
# setup