The API Reference

Bragg edge calculation module for crystalline materials.

class neutronbraggedge.braggedge.NewMaterialDict[source]

Type definition for new material dictionary.

name

Material name/symbol.

Type:

str

lattice

Lattice constant in Angstroms.

Type:

float

crystal_structure

Crystal structure type (“BCC” or “FCC”).

Type:

CrystalStructure

name: str
lattice: float
crystal_structure: Literal['BCC', 'FCC']
class neutronbraggedge.braggedge.BraggEdge(material=None, new_material=None, number_of_bragg_edges=10, use_local_metadata_table=True)[source]

Calculate Bragg edges for crystalline materials.

This class retrieves material metadata and calculates Bragg edge positions for neutron diffraction analysis.

Parameters:
material

List of material names.

Type:

list[str]

hkl

Miller indices for each material.

Type:

dict[str, list[list[int]]]

bragg_edges

Bragg edge wavelengths in Angstroms for each material.

Type:

dict[str, list[float]]

d_spacing

Interplanar spacing in Angstroms for each material.

Type:

dict[str, list[float]]

metadata

Material metadata including lattice and crystal structure.

Type:

dict[str, Any]

Examples

Calculate Bragg edges for Iron:

>>> from neutronbraggedge.braggedge import BraggEdge
>>> handler = BraggEdge(material='Fe', number_of_bragg_edges=4)
>>> print(handler.bragg_edges['Fe'])
[4.0538, 2.8664, 2.3404, 2.0269]

Use a custom material:

>>> custom = [{'name': 'MyMat', 'lattice': 3.5, 'crystal_structure': 'FCC'}]
>>> handler = BraggEdge(new_material=custom)

Get Pydantic model result:

>>> result = handler.to_result('Fe')
>>> print(result.model_dump_json())
hkl: dict[str, list[list[int]]] | None = None
metadata: dict[str, Any] | None = None
bragg_edges: dict[str, list[float]] | None = None
d_spacing: dict[str, list[float]] | None = None
lattice: dict[str, float]
crystal_structure: dict[str, Literal['BCC', 'FCC']]
__init__(material=None, new_material=None, number_of_bragg_edges=10, use_local_metadata_table=True)[source]

Initialize BraggEdge calculator.

Parameters:
  • material (str or list[str], optional) – Material name(s) such as ‘Ni’, ‘Fe’. Either material or new_material must be provided.

  • new_material (list[NewMaterialDict], optional) – List of custom material definitions with ‘name’, ‘lattice’, and ‘crystal_structure’ keys.

  • number_of_bragg_edges (int, default 10) – Number of Bragg edges to calculate.

  • use_local_metadata_table (bool, default True) – If True, use local metadata table. If False, fetch from Wikipedia.

Raises:

ValueError – If neither material nor new_material is provided, or if new_material has an invalid format.

Return type:

None

material: list[str]
number_of_bragg_edges: int
use_local_metadata_table: bool
to_result(material)[source]

Convert calculation results to a Pydantic model.

Parameters:

material (str) – Material name to get results for.

Returns:

Pydantic model containing all calculation results.

Return type:

BraggEdgeResult

Raises:

KeyError – If the specified material was not calculated.

Examples

>>> handler = BraggEdge(material='Fe', number_of_bragg_edges=4)
>>> result = handler.to_result('Fe')
>>> print(result.lattice)
2.8664
>>> print(result.model_dump_json(indent=2))
get_experimental_lattice_parameter(experimental_bragg_edge_values=None, experimental_bragg_edge_error=None)[source]

Calculate experimental lattice parameter from Bragg edge values.

Note: This method is not yet implemented. Use the Lattice class directly for experimental lattice parameter calculations.

Parameters:
  • experimental_bragg_edge_values (list[float], optional) – Array of experimental Bragg edge values.

  • experimental_bragg_edge_error (list[float], optional) – Array of errors for the Bragg edge values.

Raises:
  • ValueError – If experimental_bragg_edge_values is not provided, or if experimental_bragg_edge_error length doesn’t match.

  • NotImplementedError – This method is not yet implemented.

Return type:

None

export(filename=None, file_type='csv')[source]

Export calculation results to a file.

Parameters:
  • filename (str, optional) – Output file path.

  • file_type (str, default "csv") – Output format. Only “csv” is currently supported.

Raises:
Return type:

None