torchref.maps package

Maps module for torchref.

Provides classes for computing and writing crystallographic electron density maps.

Classes

Map

Base class for 2mFo-DFc and Fcalc maps.

DifferenceMap

Isomorphous difference map from two datasets.

class torchref.maps.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

class torchref.maps.DifferenceMap(data, data_reference, model, gridsize=None, device=None)[source]

Bases: Map

Isomorphous difference map between two datasets.

Scales both datasets to a common reference using DatasetCollection, then computes difference Fourier coefficients: DF * exp(i * phi_calc) where DF = F_data - F_reference.

Parameters:
  • data (ReflectionData) – Reflection data for the perturbed state (e.g., light, derivative).

  • data_reference (ReflectionData) – Reflection data for the reference state (e.g., dark, native).

  • model (ModelFT) – Model for computing phases.

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

__init__(data, data_reference, model, gridsize=None, device=None)[source]
calculate()[source]

Compute the isomorphous difference map.

Returns:

3D real-space difference map tensor.

Return type:

torch.Tensor

Submodules