The API Reference
Bragg edge calculation module for crystalline materials.
- class neutronbraggedge.braggedge.NewMaterialDict[source]
Type definition for new material dictionary.
- crystal_structure
Crystal structure type (“BCC” or “FCC”).
- Type:
CrystalStructure
- 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:
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())
- __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
- 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:
- 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:
- Raises:
OSError – If no filename is provided.
NotImplementedError – If an unsupported file type is requested.
- Return type:
None