Material database module.¶
This module provides access to the material database.
The material database is a collection of material records. Each record describes a material and contains the following fields:
name: material name type: material type, either ‘crystal’ or ‘amorphous’ density: material density in g/cm^3 atoms: list of atoms in the material. Each atom is described by a dictionary with the following fields:
symbol: atom symbol x: x coordinate of the atom in the unit cell y: y coordinate of the atom in the unit cell z: z coordinate of the atom in the unit cell occ: occupancy of the atom in the unit cell repeat: number of atoms in the unit cell
The material database is stored in a YAML file. The file contains a list of material records. The user can add new records to the database by editing a copy of the YAML material database file.
To get a copy of the material database file, use the copy_db()
method.
- Example:
>>> from escape.scattering.mdb import copy_db >>> copy_db()
The copy of the material database file is stored in the current working directory.
In order to compile the new material database, the user should create an instance of the new material database using
mdb()
method. This method will look for the YAML material database file in the current working directory and will
compile the material database from the YAML file. The compiled material database is stored in the current working
directory and is used by default. If the local MDB file is not found, the method will look for the MDB file in the
specific folder of the package.
- escape.scattering.mdb.mdb(mdbdir: Optional[str] = None) mdb_obj ¶
Create a material database object.
- Args:
mdbdir (str | None): Path to the directory with the material database file
- Returns:
mdb_obj: Material database object
- escape.scattering.mdb.copy_db(overwrite: bool = False) None ¶
Copy the material database file to the current working directory.
- Args:
overwrite (bool): Whether to overwrite existing files
- escape.scattering.mdb.neutrons(wavelength: float, units: str = 'angstrom', name: str = 'Neutron source') source_obj ¶
Create a neutron source object.
- Args:
wavelength (float): Wavelength of the neutron radiation units (str): Units of the wavelength, ‘angstrom’ or ‘nm’ name (str): Name of the source
- Returns:
source_obj: Neutron source object
- escape.scattering.mdb.xrays(wavelength: float, units: str = 'angstrom', name: str = 'X-ray source') source_obj ¶
Create an X-ray source object.
- Args:
wavelength (float): Wavelength of the X-ray radiation units (str): Units of the wavelength, ‘angstrom’ or ‘nm’ name (str): Name of the source
- Returns:
source_obj: X-ray source object
- class escape.scattering.mdb.mdb_obj¶
This object represents a material database.
- ABSORPTION_WAVELENGTH = 1.798¶
- DATADIR = 'mdb'¶
- ELEMENTSDBFN = 'elements.db'¶
- MATERIALSDBFN = 'materials.db'¶
- MATERIALSYAMLFN = 'materials.yaml'¶
- add(rec)¶
Add a material record to the database.
- Args:
rec (dict): Material record dictionary
- Raises:
MdbError: If record is invalid or missing required fields
- amorph_density(amorph)¶
- amorphs¶
Returns list of amorphous materials names in the database.
- Returns:
list: List of amorphous material names as strings
- compile_elements_db(datadir, dbfn)¶
Compile the elements database from the data files in the given directory.
- Args:
datadir: Path to the directory with the data files dbfn: Name of the elements database file
- compile_materials_db(datadir, mdbfn)¶
Compile the materials database from the data files in the given directory.
- Args:
datadir: Path to the directory with the data files mdbfn: Name of the materials database file
- Raises:
MdbError: If compilation fails
- classmethod copy_db(overwrite=False)¶
Copy the material database file to the current working directory.
- Args:
overwrite: If True, overwrite existing file
- Raises:
MdbError: If file exists and overwrite=False
- crystal_density(crystal)¶
- crystals¶
Returns list of crystal materials names in the database.
- Returns:
list: List of crystal material names as strings
- load_elements_db(dbrelpath, escdir)¶
- load_materials_db(datadir, dbfn, escdir)¶
- parse_element(symbol)¶
- sf(element, src, Q=None)¶
- class escape.scattering.mdb.source_obj¶
This object represents a source of radiation.
- type¶
Returns type of the source.
- Returns:
str: Source type (‘xrays’, ‘neutrons’ or ‘unknown’)
- units¶
Returns units of the source.
- Returns:
str: Units value
- wavelength¶
Returns wavelength of the source.
- Returns:
double: Wavelength value
- exception escape.scattering.mdb.MdbError¶