Material Libraries – pyne.material_library

This module contains the Material Library class, which is used to represent collections of nuclear materials throughout PyNE.

All functionality may be found in the material_library package:

from pyne import material_library

Material Libraries provide a way of assembling a collection of Materials – pyne.material objects, including the reading and writing of those collections in various formats. They behave in a dictionary-like way in which the key is a string that is generally a semantically meaningful name, and the value is a Materials – pyne.material object. MaterialLibrary contains mainly a dictionary like object referencing a list of Materials – pyne.material by the a string name key.

The MaterialLibrary class is presented below. For more information please refer to Materials.

HDF5 File Structure

When using the write_hdf5 method to write a material library in a group named my_mat_lib (the user shall provide the name for this group in argument datapath), the default structure for the HDF5 file is: .. verbatim:

/material_library/
/----------------/my_mat_lib/
                 /----------/composition
                 /----------/nuclidelist
                 /----------/composition_metadata

Where, /material_library and /material_library/my_mat_lib are HDF5 groups.

Previous HDF5 File Structure

If the datapath or /material_library exist as a dataset in the file, then the old writing method will be used.

Old data structure looks like: .. verbatim:

/my_mat_lib/
/----------/nucpath
/my_mat_lib_metadata
/nuclidelist

my_mat_lib (the datapath – default material) is a HDF5 dataset containing the array of material compositions, nucpath is a attribute containing the path to the nuclide list (attached to the datapath). my_mat_lib_metadata is a dataset containing an array of metadata of the materials. nuclidelist is a dataset containing the list of nuclides composition the materials.

from_hdf5() will detect the structure (old or new) of the file.

MaterialLibrary Class

class pyne.material_library.MaterialLibrary(lib=None, datapath='/materials', nucpath='/nucid')

The material library is a collection of unique keys mapped to Material objects.

clear(self)
dump_json()

Dumps the material to a JSON object.

Returns
valjsoncpp.Value

An object-type JSON value.

from_hdf5()

Loads data from an HDF5 file into this material library. Parameters ———- file : str

A path to an HDF5 file.

datapathstr, optional

The path in the hierarchy to the data table in an HDF5 file. The path in the hierarchy to the nuclide array in an HDF5 file.

protocolint, optional

Specifies the protocol to use to read in the data. Different protocols are used to represent different internal structures in the HDF5 file.

from_json()

Initialize a Material object from a JSON file.

Parameters
filenamestr

Path to text file that contains the data to read in.

get(self, key, default=None)
items(self)
keys(self)
load_json()

Loads a JSON instance into this Material.

Parameters
jsonjsoncpp.Value

An object-type JSON value.

merge()

Merge a material library into this material library. Parameters ———- mat_library : MaterialLibrary

Material Library to merge

pop(self, key, default=<object object at 0x7fb1fff76050>)

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem(self)

as a 2-tuple; but raise KeyError if D is empty.

remove_material()

Remove a Material from this material library. Parameters ———- mat_name : str Name of the material be removed from this material library

setdefault(self, key, default=None)
update(\*args, \*\*kwds)

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values(self)
write_hdf5()

Writes this material library to an HDF5 file. Parameters ———- filename : str

A path to an HDF5 file.

datapathstr, optional

The path in the hierarchy to the data table in an HDF5 file.

write_json()

Writes the material to a JSON file.

Parameters
filenamestr

Path to text file to write the data to. If the file already exists, it will be overwritten.

MaterialLibrary Read/Write Functions

A key functionality of the MaterialLibrary class is the ability to read and write material libraries in different formats.




MaterialLibrary Modification Functions

Functions are provided to ensure robust behavior when working with changes to MaterialLibrary collections.