示例#1
0
def test_matlib_delete():
    water = Material()
    water.from_atom_frac({10000000: 2.0, 80000000: 1.0})
    water.metadata["name"] = "Aqua sera."

    pubr3 = Material(
        {
            "Br": 0.500617,
            "Pu-238": 0.000250,
            "Pu-239": 0.466923,
            "Pu-240": 0.029963,
            "Pu-241": 0.001998,
            "Pu-242": 0.000250,
        },
        density=6.75,
        metadata={
            "name": "Plutonium Bromide"
        },
    ).expand_elements()

    lib = {"pubr3": pubr3, "aqua": water}
    matlib = MaterialLibrary(lib)

    # test delete methods
    matlib.remove_material("pubr3")

    assert len(matlib) == 1

    del matlib["aqua"]

    assert len(matlib) == 0
示例#2
0
def make_matslib(fname):
    """Make a pyne.material.MaterialLibrary. First makes elements, then
    materials from compendium.

    Parameters
    ----------
    fname : str
        Path to materials compendium.

    Returns
    -------
    matslib : pyne.material.MaterialLibrary
        All the materials you could want, in a handy MaterialLibrary instance.
    """
    matslib = MaterialLibrary(make_elements())
    matsdict = grab_materials_compendium(fname)
    matslib.update(matsdict)
    return matslib
示例#3
0
def test_matlib_hdf5_nuc_data():
    matlib = MaterialLibrary()
    matlib.from_hdf5(nuc_data, "/materials")
    matlib.write_hdf5("matlib_test.h5")
    mat_lib_load_test = MaterialLibrary("matlib_test.h5")
    os.remove("matlib_test.h5")
    for key in matlib:
        assert_mat_almost_equal(matlib[key], mat_lib_load_test[key])
示例#4
0
def setup():
    global MATS, O2HLS
    o2benchurl = 'https://github.com/pyne/data/raw/master/' + H5NAME
    if not os.path.exists(H5NAME):
        sys.stderr.write("\nDownloading " + o2benchurl + ": ")
        sys.stderr.flush()
        urlretrieve(o2benchurl, H5NAME)
        sys.stderr.write("done.\n")
        sys.stderr.flush()
    MATS = MaterialLibrary(H5NAME)
    with open('o2hls.json', 'r') as f:
        O2HLS = json.load(f)
    O2HLS = {int(nuc): v for nuc, v in O2HLS.items()}
示例#5
0
def test_matlib_json():
    filename = "matlib.json"
    water = Material()
    water.from_atom_frac({10000000: 2.0, 80000000: 1.0})
    water.metadata["name"] = "Aqua sera."
    lib = {"leu": Material(leu), "nucvec": nucvec, "aqua": water}
    wmatlib = MaterialLibrary(lib)
    wmatlib.write_json(filename)

    rmatlib = MaterialLibrary()
    rmatlib.from_json(filename)
    assert_equal(set(wmatlib), set(rmatlib))
    for key in rmatlib:
        assert_mat_almost_equal(wmatlib[key], rmatlib[key])
    os.remove(filename)
示例#6
0
def test_against_nuc_data():
    nuc_data = pyne_conf.NUC_DATA_PATH
    if not os.path.isfile(nuc_data):
        raise RuntimeError(
            "Tests require nuc_data.h5. Please run nuc_data_make.")
    obs_matslib = MaterialLibrary(nuc_data)
    gasoline = Material(
        {
            "H": 0.157000,
            "C": 0.843000,
        },
        density=0.721,
        metadata={
            "name": "Gasoline"
        },
    ).expand_elements()

    pubr3 = Material(
        {
            "Br": 0.500617,
            "Pu-238": 0.000250,
            "Pu-239": 0.466923,
            "Pu-240": 0.029963,
            "Pu-241": 0.001998,
            "Pu-242": 0.000250,
        },
        density=6.75,
        metadata={
            "name": "Plutonium Bromide"
        },
    ).expand_elements()

    obs_gasoline = obs_matslib["Gasoline"]
    # remove empty elements
    assert_equal(
        {(x, val)
         for x, val in set(obs_gasoline.comp.items()) if val > 0},
        set(gasoline.comp.items()),
    )
    assert_equal(obs_gasoline.density, gasoline.density)
    assert_equal(obs_gasoline.metadata["name"], gasoline.metadata["name"])

    obs_pubr3 = obs_matslib["Plutonium Bromide"]
    # remove empty elements
    assert_equal(
        {(x, val)
         for x, val in set(obs_pubr3.comp.items()) if val > 0},
        set(pubr3.comp.items()),
    )
    assert_equal(obs_pubr3.density, pubr3.density)
    assert_equal(obs_pubr3.metadata["name"], pubr3.metadata["name"])
示例#7
0
文件: partisn.py 项目: opotowsky/pyne
def _get_material_lib(hdf5, data_hdf5path, **kwargs):
    """Read material properties from the loaded dagmc geometry.
    """

    # If a set of nuc_names is provided, then collapse elements
    if 'nuc_names' in kwargs:
        nuc_names = kwargs['nuc_names']
        collapse = True
        # set of exception nuclides for collapse_elements
        mat_except = set(nuc_names.keys())
    else:
        collapse = False

    # collapse isotopes into elements (if required)
    mats = MaterialLibrary(hdf5, datapath=data_hdf5path)

    mats_collapsed = {}
    unique_names = {}

    for mat_name in mats:
        mat_name = mat_name.decode('utf-8')
        fluka_name = mats[mat_name].metadata['fluka_name']
        if sys.version_info[0] > 2:
            unique_names[mat_name] = str(fluka_name.encode(), 'utf-8')
        else:
            unique_names[mat_name] = fluka_name.decode('utf-8')

        if collapse:
            mats_collapsed[fluka_name] = mats[mat_name].collapse_elements(
                mat_except)
        else:
            mats_collapsed[fluka_name] = mats[mat_name]

    # convert mass fraction to atom density in units [at/b-cm]
    mat_lib = {}
    for mat_name in mats_collapsed:
        comp = mats_collapsed[mat_name]
        atom_dens_dict = comp.to_atom_dens()
        comp_list = {}
        for nucid, dens in atom_dens_dict.items():
            # convert from [at/cc] to [at/b-cm]
            comp_list[nucid] = dens * 10.**-24
        mat_lib[mat_name] = comp_list

    return mat_lib, unique_names
示例#8
0
def test_matlib_query():
    water = Material()
    water.from_atom_frac({10000000: 2.0, 80000000: 1.0})
    water.metadata["name"] = "Aqua sera."
    mat_nucvec = Material(nucvec)
    mat_nucvec.metadata["name"] = "nucvec"
    lib = {"nucvec": nucvec, "aqua": water}
    matlib = MaterialLibrary(lib)

    matlib_aqua = matlib["aqua"]
    assert_mat_almost_equal(water, matlib_aqua)

    matlib_nucvec = matlib["nucvec"]
    assert_mat_almost_equal(mat_nucvec, matlib_nucvec)

    mat_leu = Material(leu)
    mat_leu.metadata["name"] = "leu"
    matlib["leu"] = mat_leu
    matlib_leu = matlib["leu"]
    assert_mat_almost_equal(mat_leu, matlib_leu)
示例#9
0
def test_hdf5_overwrite():
    filename = "matlib.h5"
    if filename in os.listdir("."):
        os.remove(filename)
    water = Material()
    water.from_atom_frac({10000000: 2.0, 80000000: 1.0})
    water.metadata["name"] = "Aqua sera."
    lib = {"aqua": water}
    wmatlib = MaterialLibrary(lib)
    wmatlib.write_hdf5(filename, "/mats1")

    lib = {"leu": Material(leu)}
    umatlib = MaterialLibrary(lib)
    # test error raise if path already exists
    assert_raises(RuntimeError, umatlib.write_hdf5, filename, "/mats1", False)

    # test overwriting
    umatlib.write_hdf5(filename, "/mats1", h5_overwrite=True)
    rmatlib = MaterialLibrary()
    rmatlib.from_hdf5(filename, "/mats1")

    # Round trip!
    assert_equal(set(umatlib), set(rmatlib))
    for key in rmatlib:
        assert_mat_almost_equal(umatlib[key], rmatlib[key])
    os.remove(filename)
示例#10
0
def test_matlib_hdf5():
    filename = "matlib.h5"
    if filename in os.listdir("."):
        os.remove(filename)
    water = Material()
    water.from_atom_frac({10000000: 2.0, 80000000: 1.0})
    water.metadata["name"] = "Aqua sera."
    lib = {"leu": Material(leu), "nucvec": nucvec, "aqua": water}
    wmatlib = MaterialLibrary(lib)
    wmatlib.write_hdf5(filename, "/mats1")
    rmatlib = MaterialLibrary()
    rmatlib.from_hdf5(filename, "/mats1")
    os.remove(filename)
    # Round trip!
    rmatlib.write_hdf5(filename, "/mats1")
    wmatlib = MaterialLibrary(filename, "/mats1")
    assert_equal(set(wmatlib), set(rmatlib))
    for key in rmatlib:
        assert_mat_almost_equal(wmatlib[key], rmatlib[key])
    os.remove(filename)
示例#11
0
#!/usr/bin/env python3

from pyne.material import Material
from pyne.material_library import MaterialLibrary

mat_lib = MaterialLibrary()

# Create a pyne material for copper
copper = Material({'Cu': 1})
copper = copper.expand_elements()

# Add to material library
mat_lib["copper"] = copper

# Create a pyne material for copper
air = Material({'N': 0.784431, 'O': 0.210748, 'Ar': 0.004821})
air = air.expand_elements()

# Add to material library
mat_lib["air"] = air

#graveyard = Material();
#mat_lib["graveyard"] = graveyard

#vacuum = Material();
#mat_lib["vacuum"] = vacuum

mat_lib.write_hdf5("material_library.h5", "/materials", "/nucid")