cryo_em Module
The cryo_em module provides tools for generating synthetic 3D density maps from protein structures and ensembles. This is essential for simulating how conformational heterogeneity and resolution limits affect experimental Cryo-EM data.
Overview
Cryo-Electron Microscopy (Cryo-EM) measures the Coulomb potential of a biological sample. In synth-pdb, we simulate this by representing each atom as a Gaussian blob whose width corresponds to the target resolution.
Key Features
- Gaussian Voxelization: Converts atomic coordinates into a 3D grid of density values.
- Ensemble Averaging: Supports
AtomArrayStackto simulate how flexible regions appear blurred in a consensus map. - MRC Export: Saves density maps in the industry-standard MRC/CCP4 format for visualization in ChimeraX or PyMOL.
API Reference
cryo_em
Advanced Cryo-EM Density Map Generation for Synthetic Ensembles.
Classes
CryoEMSimulator
Stateful wrapper for Cryo-EM simulation workflows.
Allows for reproducible generation of density maps from PDB ensembles.
Source code in synth_pdb/cryo_em.py
Functions
simulate(structure)
Generates a density map for the provided structure.
Source code in synth_pdb/cryo_em.py
Functions
generate_density_map(structure, resolution=3.0, grid_spacing=1.0, buffer=5.0)
Generates a 3D density map from an AtomArray or AtomArrayStack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
AtomArray | AtomArrayStack
|
Biotite structure(s) to convert to density. |
required |
resolution
|
float
|
Target resolution in Angstroms (Gaussian sigma ~ res/3). |
3.0
|
grid_spacing
|
float
|
Voxel size in Angstroms (default 1.0A). |
1.0
|
buffer
|
float
|
Extra padding around the protein in Angstroms. |
5.0
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
Tuple of (3D density array, (3,) array of grid origin coordinates). |
SCIENTIFIC NOTE - Resolution vs Sigma:
The relationship between the resolution (R) and the Gaussian sigma (sigma) is often approximated as sigma = R / (2 * sqrt(2 * ln 2)) ~ R / 2.355. However, for simple visual benchmarks, sigma = resolution / 3 is also common. We use the 1/3 rule here for a conservative "sharpness" at the target res.
Source code in synth_pdb/cryo_em.py
save_mrc_file(path, density, origin, spacing=1.0)
Saves a 3D density array to an MRC/CCP4 formatted file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Output filename. |
required |
density
|
ndarray
|
3D numpy array of density values. |
required |
origin
|
ndarray
|
(3,) array of coordinates for the (0,0,0) voxel. |
required |
spacing
|
float
|
Grid spacing in Angstroms. |
1.0
|
EDUCATIONAL NOTE - The MRC Format:
The MRC format is the standard for 3D electron microscopy data. It contains a 1024-byte header followed by the binary density data. Key header fields include: - NX, NY, NZ: Number of voxels in each dimension. - XLEN, YLEN, ZLEN: Physical size of the box in Angstroms. - MAPC, MAPR, MAPS: Mapping of array axes to physical axes (usually 1,2,3).
Source code in synth_pdb/cryo_em.py
Scientific Principles
Resolution vs. Sigma
The relationship between the reported resolution (\(R\)) and the Gaussian standard deviation (\(\sigma\)) used for blurring is:
This conservative "1/3 rule" ensures that the density reflects the structural details appropriate for the target resolution. At 3Å resolution, atoms are clearly separated; at 8Å, only secondary structure elements (like alpha helices) remain visible as "tubes" of density.
Conformational Heterogeneity
When simulating an ensemble (IDPs or flexible loops), the density at each voxel is the average occupancy across all models:
This naturally results in lower, more diffuse density for highly mobile regions, mimicking the "B-factor" or local resolution effects seen in real experiments.
Usage Example
from synth_pdb.generator import PeptideGenerator
from synth_pdb.cryo_em import generate_density_map, save_mrc_file
# 1. Generate an ensemble of decoys
gen = PeptideGenerator("MEELQK")
ensemble = gen.generate_ensemble(n_models=50)
# 2. Generate a 4Å density map
density, origin = generate_density_map(
ensemble,
resolution=4.0,
grid_spacing=1.0
)
# 3. Save to MRC for visualization
save_mrc_file("synthetic_map.mrc", density, origin, spacing=1.0)