Ejemplo n.º 1
0
def _read_gf_element(file, index):
    """
    Read the information needed for a given Green's function element form a ``greensf.hdf``
    file

    :param file: filepath or handle to be read
    :param index: integer index of the element to read in (indexing starts at 1)

    :returns: tuple of the information containing the :py:class:`GreensfElement` for the element
              and the datasets and attributes dict produced by the corresponding
              :py:class:`~masci_tools.io.parsers.hdf5.HDF5Reader`
    """
    with HDF5Reader(file) as h5reader:
        gf_element = _read_element_header(h5reader._h5_file, index)
        group_name = _get_greensf_group_name(h5reader._h5_file)

        if gf_element.sphavg:
            recipe = _get_sphavg_recipe(group_name, index, gf_element.contour)
        else:
            recipe = _get_radial_recipe(group_name,
                                        index,
                                        gf_element.contour,
                                        nlo=gf_element.nLO)

        data, attributes = h5reader.read(recipe=recipe)

    return gf_element, data, attributes
Ejemplo n.º 2
0
def create_aiida_bands_data(fleurinp, retrieved):
    """
    Creates :py:class:`aiida.orm.BandsData` object containing the kpoints and eigenvalues
    from the `banddos.hdf` file of the calculation

    :param fleurinp: :py:class:`~aiida_fleur.data.fleurinp.FleurinpData` for the calculation
    :param retrieved: :py:class:`aiida.orm.FolderData` for the bandstructure calculation

    :returns: :py:class:`aiida.orm.BandsData` for the bandstructure calculation

    :raises: ExitCode 300, banddos.hdf file is missing
    :raises: ExitCode 310, banddos.hdf reading failed
    :raises: ExitCode 320, reading kpointsdata from Fleurinp failed
    """
    from masci_tools.io.parsers.hdf5 import HDF5Reader, HDF5TransformationError
    from masci_tools.io.parsers.hdf5.recipes import FleurSimpleBands  #no projections only eigenvalues for now
    from aiida.engine import ExitCode

    try:
        kpoints = fleurinp.get_kpointsdata_ncf(only_used=True)
    except ValueError as exc:
        return ExitCode(
            320,
            message=f'Retrieving kpoints data from fleurinp failed with: {exc}'
        )

    if 'banddos.hdf' in retrieved.list_object_names():
        try:
            with retrieved.open('banddos.hdf', 'rb') as f:
                with HDF5Reader(f) as reader:
                    data, attributes = reader.read(recipe=FleurSimpleBands)
        except (HDF5TransformationError, ValueError) as exc:
            return ExitCode(310,
                            message=f'banddos.hdf reading failed with: {exc}')
    else:
        return ExitCode(300,
                        message='banddos.hdf file not in the retrieved files')

    bands = BandsData()
    bands.set_kpointsdata(kpoints)

    nkpts, nbands = attributes['nkpts'], attributes['nbands']
    eigenvalues = data['eigenvalues_up'].reshape((nkpts, nbands))
    if 'eigenvalues_down' in data:
        eigenvalues_dn = data['eigenvalues_down'].reshape((nkpts, nbands))
        eigenvalues = [eigenvalues, eigenvalues_dn]

    bands.set_bands(eigenvalues, units='eV')

    bands.label = 'output_banddos_wc_bands'
    bands.description = (
        'Contains BandsData for the bandstructure calculation')

    return bands
Ejemplo n.º 3
0
def test_plot_bands_weighted_spinpol_mpl():
    from masci_tools.io.parsers.hdf5 import HDF5Reader
    from masci_tools.io.parsers.hdf5.recipes import FleurBands
    from masci_tools.vis.fleur import plot_fleur_bands

    TEST_BANDDOS_FILE = os.path.join(HDFTEST_DIR, 'banddos_spinpol_bands.hdf')

    with HDF5Reader(TEST_BANDDOS_FILE) as h5reader:
        data, attributes = h5reader.read(recipe=FleurBands)

    gcf().clear()

    plot_fleur_bands(data, attributes, show=False, weight='MT:1d')

    return gcf()
Ejemplo n.º 4
0
def test_plot_spinpol_dos_defaults_mpl():
    from masci_tools.io.parsers.hdf5 import HDF5Reader
    from masci_tools.io.parsers.hdf5.recipes import FleurDOS
    from masci_tools.vis.fleur import plot_fleur_dos

    TEST_BANDDOS_FILE = os.path.join(HDFTEST_DIR, 'banddos_spinpol_dos.hdf')

    with HDF5Reader(TEST_BANDDOS_FILE) as h5reader:
        data, attributes = h5reader.read(recipe=FleurDOS)

    gcf().clear()

    plot_fleur_dos(data, attributes, show=False)

    return gcf()
Ejemplo n.º 5
0
def test_hdf5_reader_jdos(data_regression):
    """
    Tests of the dos recipe (also pass opened file handle)
    """
    from masci_tools.io.parsers.hdf5 import HDF5Reader
    from masci_tools.io.parsers.hdf5.recipes import FleurJDOS

    TEST_BANDDOS_FILE = os.path.join(HDFTEST_DIR, 'banddos_spinpol_dos.hdf')

    with HDF5Reader(TEST_BANDDOS_FILE) as reader:
        data, attrs = reader.read(recipe=FleurJDOS)

    data_regression.check({
        'datasets': convert_to_pystd(data),
        'attributes': convert_to_pystd(attrs)
    })
Ejemplo n.º 6
0
def test_hdf5_reader_bands(data_regression):
    """
    Tests of the bands recipe
    """
    from masci_tools.io.parsers.hdf5 import HDF5Reader
    from masci_tools.io.parsers.hdf5.recipes import FleurBands

    TEST_BANDDOS_FILE = os.path.join(HDFTEST_DIR, 'banddos_bands.hdf')

    with HDF5Reader(TEST_BANDDOS_FILE) as reader:
        data, attrs = reader.read(recipe=FleurBands)

    data_regression.check({
        'datasets': convert_to_pystd(data),
        'attributes': convert_to_pystd(attrs)
    })
Ejemplo n.º 7
0
def test_plot_dos_param_change_by_label_mpl():
    from masci_tools.io.parsers.hdf5 import HDF5Reader
    from masci_tools.io.parsers.hdf5.recipes import FleurDOS
    from masci_tools.vis.fleur import plot_fleur_dos

    TEST_BANDDOS_FILE = os.path.join(HDFTEST_DIR, 'banddos_dos.hdf')

    with HDF5Reader(TEST_BANDDOS_FILE) as h5reader:
        data, attributes = h5reader.read(recipe=FleurDOS)

    gcf().clear()

    plot_fleur_dos(data,
                   attributes,
                   show=False,
                   color={'MT:1_up': 'red'},
                   linewidth={'Total_up': 6})

    return gcf()
Ejemplo n.º 8
0
def create_aiida_dos_data(retrieved):
    """
    Creates :py:class:`aiida.orm.XyData` object containing the standard DOS components
    from the `banddos.hdf` file of the calculation

    :param retrieved: :py:class:`aiida.orm.FolderData` for the DOS calculation

    :returns: :py:class:`aiida.orm.XyData` containing all standard DOS components

    :raises: ExitCode 300, banddos.hdf file is missing
    :raises: ExitCode 310, banddos.hdf reading failed
    """
    from masci_tools.io.parsers.hdf5 import HDF5Reader, HDF5TransformationError
    from masci_tools.io.parsers.hdf5.recipes import FleurDOS  #only standard DOS for now
    from aiida.engine import ExitCode

    if 'banddos.hdf' in retrieved.list_object_names():
        try:
            with retrieved.open('banddos.hdf', 'rb') as f:
                with HDF5Reader(f) as reader:
                    data, attributes = reader.read(recipe=FleurDOS)
        except (HDF5TransformationError, ValueError) as exc:
            return ExitCode(310,
                            message=f'banddos.hdf reading failed with: {exc}')
    else:
        return ExitCode(300,
                        message='banddos.hdf file not in the retrieved files')

    dos = XyData()
    dos.set_x(data['energy_grid'], 'energy', x_units='eV')

    names = [key for key in data if key != 'energy_grid']
    arrays = [entry for key, entry in data.items() if key != 'energy_grid']
    units = ['1/eV'] * len(names)
    dos.set_y(arrays, names, y_units=units)

    dos.label = 'output_banddos_wc_dos'
    dos.description = (
        'Contains XyData for the density of states calculation with total, interstitial, atom and orbital weights'
    )

    return dos
Ejemplo n.º 9
0
def test_plot_bands_characterize_mpl():
    from masci_tools.io.parsers.hdf5 import HDF5Reader
    from masci_tools.io.parsers.hdf5.recipes import FleurBands
    from masci_tools.vis.fleur import plot_fleur_bands_characterize

    TEST_BANDDOS_FILE = os.path.join(HDFTEST_DIR, 'banddos_spinpol_bands.hdf')

    with HDF5Reader(TEST_BANDDOS_FILE) as h5reader:
        data, attributes = h5reader.read(recipe=FleurBands)

    gcf().clear()

    plot_fleur_bands_characterize(
        data,
        attributes, ['MT:1s', 'MT:1p', 'MT:1d', 'MT:1f'],
        ['darkblue', 'darkred', 'darkgreen', 'darkorange'],
        show=False,
        markersize=30,
        only_spin='up')

    return gcf()
Ejemplo n.º 10
0
def test_plot_dos_selection_mpl():
    from masci_tools.io.parsers.hdf5 import HDF5Reader
    from masci_tools.io.parsers.hdf5.recipes import FleurDOS
    from masci_tools.vis.fleur import plot_fleur_dos

    TEST_BANDDOS_FILE = os.path.join(HDFTEST_DIR, 'banddos_dos.hdf')

    with HDF5Reader(TEST_BANDDOS_FILE) as h5reader:
        data, attributes = h5reader.read(recipe=FleurDOS)

    gcf().clear()

    plot_fleur_dos(data,
                   attributes,
                   show=False,
                   show_total=False,
                   show_interstitial=False,
                   show_atoms=1,
                   show_lresolved=2,
                   plot_keys='MT:1p')

    return gcf()