torchref.maps.map module

Base Map class for crystallographic electron density map computation.

Supports 2mFo-DFc and Fcalc map types. Computes maps via FFT of map coefficients placed on a reciprocal-space grid.

FFT convention: ρ(r) = sum_h F(h) * exp(-2πi h·r) This corresponds to torch.fft.fftn (forward DFT with exp(-2πi) kernel). Hermitian symmetry F(-h) = F*(h) is enforced by place_on_grid to ensure a real-valued map.

class torchref.maps.map.Map(data, model, gridsize=None, map_type='2mFo-DFc', device=None)[source]

Bases: DeviceMixin

Crystallographic electron density map.

Parameters:
  • data (ReflectionData) – Observed reflection data with amplitudes, hkl, cell, and spacegroup.

  • model (ModelFT) – Model for computing Fcalc (structure factors).

  • gridsize (tuple of int, optional) – Grid dimensions (nx, ny, nz). If None, determined automatically from cell parameters and resolution.

  • map_type (str, optional) – Type of map to compute. One of "2mFo-DFc" or "Fcalc". Default is "2mFo-DFc".

VALID_MAP_TYPES = ('2mFo-DFc', 'Fcalc')
__init__(data, model, gridsize=None, map_type='2mFo-DFc', device=None)[source]
reset_cache()[source]

Invalidate the cached map tensor; recomputed on next access.

property map_data: Tensor | None

The computed 3D real-space map, or None if not yet calculated.

calculate()[source]

Compute the electron density map.

Returns:

3D real-space map tensor.

Return type:

torch.Tensor

write(filepath)[source]

Write the map to a CCP4 file.

Automatically computes the map if it hasn’t been calculated yet.

Parameters:

filepath (str) – Output CCP4 map file path.

Returns:

1 on success.

Return type:

int