Skip to content

crystallography

crystallography

apply_atom_site_aniso_symmetry_constraints(atom_site_aniso, name_hm, coord_code, _wyckoff_letter, site_fract)

Apply symmetry constraints to anisotropic ADP tensor components.

Uses the Peterse-Palm probe technique to determine which tensor components are constrained by the site symmetry, then delegates to cryspy's vibration_constraints to enforce them.

Parameters:

Name Type Description Default
atom_site_aniso dict[str, float]

Dictionary with keys 'adp_11''adp_23'. Modified in place.

required
name_hm str

Hermann-Mauguin symbol of the space group.

required
coord_code str | None

IT coordinate system code.

required
_wyckoff_letter str

Wyckoff position letter (unused, reserved).

required
site_fract tuple[float, float, float]

Fractional coordinates of the atom site.

required

Returns:

Type Description
tuple[dict[str, float], tuple[bool, ...]]

The atom_site_aniso dictionary with constrained values, and a 6-tuple of booleans indicating which components remain free for refinement (True = free, False = fixed by symmetry).

Source code in src/easydiffraction/crystallography/crystallography.py
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
def apply_atom_site_aniso_symmetry_constraints(
    atom_site_aniso: dict[str, float],
    name_hm: str,
    coord_code: str | None,
    _wyckoff_letter: str,
    site_fract: tuple[float, float, float],
) -> tuple[dict[str, float], tuple[bool, ...]]:
    """
    Apply symmetry constraints to anisotropic ADP tensor components.

    Uses the Peterse-Palm probe technique to determine which tensor
    components are constrained by the site symmetry, then delegates to
    cryspy's ``vibration_constraints`` to enforce them.

    Parameters
    ----------
    atom_site_aniso : dict[str, float]
        Dictionary with keys ``'adp_11'`` … ``'adp_23'``.  Modified in
        place.
    name_hm : str
        Hermann-Mauguin symbol of the space group.
    coord_code : str | None
        IT coordinate system code.
    _wyckoff_letter : str
        Wyckoff position letter (unused, reserved).
    site_fract : tuple[float, float, float]
        Fractional coordinates of the atom site.

    Returns
    -------
    tuple[dict[str, float], tuple[bool, ...]]
        The *atom_site_aniso* dictionary with constrained values, and a
        6-tuple of booleans indicating which components remain free for
        refinement (``True`` = free, ``False`` = fixed by symmetry).
    """
    all_free = (True, True, True, True, True, True)

    it_number = get_it_number_by_name_hm_short(name_hm)
    if it_number is None:
        log.error(f"Failed to get IT_number for name_H-M '{name_hm}'")
        return atom_site_aniso, all_free

    ops = _get_general_position_ops(it_number, coord_code)
    if ops is None:
        return atom_site_aniso, all_free

    stabiliser = _site_stabilizer_rotations(ops, site_fract)
    if len(stabiliser) <= 1:
        # Identity only — no ADP constraints
        return atom_site_aniso, all_free

    numb = _calc_adp_constraint_number(stabiliser)
    if numb == 0:
        return atom_site_aniso, all_free

    param_i = (
        atom_site_aniso['adp_11'],
        atom_site_aniso['adp_22'],
        atom_site_aniso['adp_33'],
        atom_site_aniso['adp_12'],
        atom_site_aniso['adp_13'],
        atom_site_aniso['adp_23'],
    )
    sigma_i = (0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
    ref_i = (True, True, True, True, True, True)

    param_i, _sigma_i, ref_i, _constr_i = vibration_constraints(
        numb,
        param_i,
        sigma_i,
        ref_i,
    )

    keys = ('adp_11', 'adp_22', 'adp_33', 'adp_12', 'adp_13', 'adp_23')
    atom_site_aniso.update(dict(zip(keys, param_i, strict=False)))

    return atom_site_aniso, ref_i

apply_atom_site_symmetry_constraints(atom_site, name_hm, coord_code, wyckoff_letter)

Apply symmetry constraints to atom site coordinates.

Parameters:

Name Type Description Default
atom_site dict[str, Any]

Dictionary containing atom position data.

required
name_hm str

Hermann-Mauguin symbol of the space group.

required
coord_code int

Coordinate system code.

required
wyckoff_letter str

Wyckoff position letter.

required

Returns:

Type Description
dict[str, Any]

The atom_site dictionary with applied symmetry constraints.

Source code in src/easydiffraction/crystallography/crystallography.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
def apply_atom_site_symmetry_constraints(
    atom_site: dict[str, Any],
    name_hm: str,
    coord_code: int,
    wyckoff_letter: str,
) -> dict[str, Any]:
    """
    Apply symmetry constraints to atom site coordinates.

    Parameters
    ----------
    atom_site : dict[str, Any]
        Dictionary containing atom position data.
    name_hm : str
        Hermann-Mauguin symbol of the space group.
    coord_code : int
        Coordinate system code.
    wyckoff_letter : str
        Wyckoff position letter.

    Returns
    -------
    dict[str, Any]
        The atom_site dictionary with applied symmetry constraints.
    """
    parsed_exprs = _get_wyckoff_exprs(name_hm, coord_code, wyckoff_letter)
    if parsed_exprs is None:
        return atom_site

    _apply_fract_constraints(atom_site, parsed_exprs)
    return atom_site

apply_cell_symmetry_constraints(cell, name_hm)

Apply symmetry constraints to unit cell parameters.

Parameters:

Name Type Description Default
cell dict[str, float]

Dictionary containing lattice parameters.

required
name_hm str

Hermann-Mauguin symbol of the space group.

required

Returns:

Type Description
dict[str, float]

The cell dictionary with applied symmetry constraints.

Source code in src/easydiffraction/crystallography/crystallography.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def apply_cell_symmetry_constraints(
    cell: dict[str, float],
    name_hm: str,
) -> dict[str, float]:
    """
    Apply symmetry constraints to unit cell parameters.

    Parameters
    ----------
    cell : dict[str, float]
        Dictionary containing lattice parameters.
    name_hm : str
        Hermann-Mauguin symbol of the space group.

    Returns
    -------
    dict[str, float]
        The cell dictionary with applied symmetry constraints.
    """
    crystal_system = _crystal_system_from_name_hm(name_hm)
    if crystal_system is None:
        return cell

    if crystal_system == 'cubic':
        a = cell['lattice_a']
        cell['lattice_b'] = a
        cell['lattice_c'] = a
        cell['angle_alpha'] = 90.0
        cell['angle_beta'] = 90.0
        cell['angle_gamma'] = 90.0

    elif crystal_system == 'tetragonal':
        a = cell['lattice_a']
        cell['lattice_b'] = a
        cell['angle_alpha'] = 90.0
        cell['angle_beta'] = 90.0
        cell['angle_gamma'] = 90.0

    elif crystal_system == 'orthorhombic':
        cell['angle_alpha'] = 90.0
        cell['angle_beta'] = 90.0
        cell['angle_gamma'] = 90.0

    elif crystal_system in {'hexagonal', 'trigonal'}:
        a = cell['lattice_a']
        cell['lattice_b'] = a
        cell['angle_alpha'] = 90.0
        cell['angle_beta'] = 90.0
        cell['angle_gamma'] = 120.0

    elif crystal_system == 'monoclinic':
        cell['angle_alpha'] = 90.0
        cell['angle_gamma'] = 90.0

    elif crystal_system == 'triclinic':
        pass  # No constraints to apply

    else:
        error_msg = f'Unknown or unsupported crystal system: {crystal_system}'
        log.error(error_msg)  # TODO: ValueError? Diagnostics?

    return cell

atom_site_symmetry_fixed_flags(name_hm, coord_code, wyckoff_letter)

Return per-axis flags marking coordinates fixed by site symmetry.

Parameters:

Name Type Description Default
name_hm str

Hermann-Mauguin symbol of the space group.

required
coord_code int

Coordinate system code.

required
wyckoff_letter str

Wyckoff position letter.

required

Returns:

Type Description
dict[str, bool]

Mapping 'fract_x' / 'fract_y' / 'fract_z' to True if the axis is fully determined by site symmetry. Returns all False when the Wyckoff position cannot be resolved.

Source code in src/easydiffraction/crystallography/crystallography.py
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
def atom_site_symmetry_fixed_flags(
    name_hm: str,
    coord_code: int,
    wyckoff_letter: str,
) -> dict[str, bool]:
    """
    Return per-axis flags marking coordinates fixed by site symmetry.

    Parameters
    ----------
    name_hm : str
        Hermann-Mauguin symbol of the space group.
    coord_code : int
        Coordinate system code.
    wyckoff_letter : str
        Wyckoff position letter.

    Returns
    -------
    dict[str, bool]
        Mapping ``'fract_x' / 'fract_y' / 'fract_z'`` to ``True`` if the
        axis is fully determined by site symmetry. Returns all ``False``
        when the Wyckoff position cannot be resolved.
    """
    parsed_exprs = _get_wyckoff_exprs(name_hm, coord_code, wyckoff_letter)
    if parsed_exprs is None:
        return {'fract_x': False, 'fract_y': False, 'fract_z': False}
    return _fract_fixed_flags(parsed_exprs)

cell_symmetry_fixed_flags(name_hm)

Return per-key flags indicating which cell parameters are fixed.

Parameters:

Name Type Description Default
name_hm str

Hermann-Mauguin symbol of the space group.

required

Returns:

Type Description
dict[str, bool]

Mapping of cell key to True when the parameter is fixed by symmetry (dependent on another parameter or set to a fixed angle), False when it is independent. Returns all keys False when the space group cannot be resolved.

Source code in src/easydiffraction/crystallography/crystallography.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
def cell_symmetry_fixed_flags(name_hm: str) -> dict[str, bool]:
    """
    Return per-key flags indicating which cell parameters are fixed.

    Parameters
    ----------
    name_hm : str
        Hermann-Mauguin symbol of the space group.

    Returns
    -------
    dict[str, bool]
        Mapping of cell key to ``True`` when the parameter is fixed by
        symmetry (dependent on another parameter or set to a fixed
        angle), ``False`` when it is independent. Returns all keys
        ``False`` when the space group cannot be resolved.
    """
    crystal_system = _crystal_system_from_name_hm(name_hm)
    if crystal_system is None:
        return dict.fromkeys(_CELL_KEYS, False)
    fixed = _cell_fixed_axes(crystal_system)
    return {key: key in fixed for key in _CELL_KEYS}

space_groups

Space group reference data.

Loads a gzipped, packaged pickle with crystallographic space-group information. The file is part of the distribution; user input is not involved.