<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

__author__ = "<NAME>"

import numpy as np
from phonopy.phonon.band_structure import BandStructure
from phonopy.units import VaspToTHz
from phonopy.structure.cells import get_primitive
from eigenstates_unfolding import EigenstatesUnfolding


class BandStructureUnfolding(BandStructure):
    def __init__(self,
                 paths,
                 dynamical_matrix,
                 unitcell_ideal,
                 primitive_matrix_ideal,
                 density_extractor,
                 is_eigenvectors=False,
                 is_band_connection=False,
                 group_velocity=None,
                 factor=VaspToTHz,
                 star="none",
                 mode="eigenvector",
                 verbose=False):
        """

        Args:
            dynamical_matrix:
                Dynamical matrix for the (disordered) supercell.
            primitive_ideal_wrt_unitcell:
                Primitive cell w.r.t. the unitcell (not the supercell).
        """
        # ._dynamical_matrix must be assigned for calculating DOS
        # using the tetrahedron method.
        self._dynamical_matrix = dynamical_matrix

        # self._cell is used for write_yaml and _shift_point.
        # This must correspond to the "ideal" primitive cell.
        primitive_ideal_wrt_unitcell = (
            get_primitive(unitcell_ideal, primitive_matrix_ideal))
        self._cell = primitive_ideal_wrt_unitcell

        self._factor = factor
        self._is_eigenvectors = is_eigenvectors
        self._is_band_connection = is_band_connection
        if is_band_connection:
            self._is_eigenvectors = True
        self._group_velocity = group_velocity

        self._paths = [np.array(path) for path in paths]
        self._distances = []
        self._distance = 0.
        self._special_point = [0.]
        self._eigenvalues = None
        self._eigenvectors = None
        self._frequencies = None

        self._star = star
        self._mode = mode

        self._eigenstates_unfolding = EigenstatesUnfolding(
            dynamical_matrix,
            unitcell_ideal,
            primitive_matrix_ideal,
            mode=mode,
            star=star,
            verbose=verbose)

        self._density_extractor = density_extractor

        fn_sf_atoms = "spectral_functions_atoms.dat"
        fn_sf_irs   = "spectral_functions_irs.dat"
        with open(fn_sf_atoms, "w") as fatoms, open(fn_sf_irs, "w") as firs:
            self._file_sf_atoms = fatoms
            self._file_sf_irs   = firs

            self._set_band(verbose=verbose)

    def write_hdf5(self):
        import h5py
        with h5py.File('band.hdf5', 'w') as w:
            w.create_dataset('paths', data=self._paths)
            w.create_dataset('distances', data=self._distances)
            w.create_dataset('nqstars', data=self._nqstars)
            w.create_dataset('num_irs', data=self._num_irs)
            w.create_dataset('frequencies', data=self._frequencies)
            w.create_dataset('pr_weights', data=self._pr_weights)
            w.create_dataset('rot_pr_weights', data=self._rot_pr_weights)
            w.create_dataset('pg_symbols', data=self._pg_symbols)
            w.create_dataset('ir_labels', data=self._ir_labels)
            if self._group_velocity is not None:<commit_msg>Modify not to write rot_pr_weights in band.hdf5 because it may be too large<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

__author__ = "<NAME>"

import numpy as np
from phonopy.phonon.band_structure import BandStructure
from phonopy.units import VaspToTHz
from phonopy.structure.cells import get_primitive
from eigenstates_unfolding import EigenstatesUnfolding


class BandStructureUnfolding(BandStructure):
    def __init__(self,
                 paths,
                 dynamical_matrix,
                 unitcell_ideal,
                 primitive_matrix_ideal,
                 density_extractor,
                 is_eigenvectors=False,
                 is_band_connection=False,
                 group_velocity=None,
                 factor=VaspToTHz,
                 star="none",
                 mode="eigenvector",
                 verbose=False):
        """

        Args:
            dynamical_matrix:
                Dynamical matrix for the (disordered) supercell.
            primitive_ideal_wrt_unitcell:
                Primitive cell w.r.t. the unitcell (not the supercell).
        """
        # ._dynamical_matrix must be assigned for calculating DOS
        # using the tetrahedron method.
        self._dynamical_matrix = dynamical_matrix

        # self._cell is used for write_yaml and _shift_point.
        # This must correspond to the "ideal" primitive cell.
        primitive_ideal_wrt_unitcell = (
            get_primitive(unitcell_ideal, primitive_matrix_ideal))
        self._cell = primitive_ideal_wrt_unitcell

        self._factor = factor
        self._is_eigenvectors = is_eigenvectors
        self._is_band_connection = is_band_connection
        if is_band_connection:
            self._is_eigenvectors = True
        self._group_velocity = group_velocity

        self._paths = [np.array(path) for path in paths]
        self._distances = []
        self._distance = 0.
        self._special_point = [0.]
        self._eigenvalues = None
        self._eigenvectors = None
        self._frequencies = None

        self._star = star
        self._mode = mode

        self._eigenstates_unfolding = EigenstatesUnfolding(
            dynamical_matrix,
            unitcell_ideal,
            primitive_matrix_ideal,
            mode=mode,
            star=star,
            verbose=verbose)

        self._density_extractor = density_extractor

        fn_sf_atoms = "spectral_functions_atoms.dat"
        fn_sf_irs   = "spectral_functions_irs.dat"
        with open(fn_sf_atoms, "w") as fatoms, open(fn_sf_irs, "w") as firs:
            self._file_sf_atoms = fatoms
            self._file_sf_irs   = firs

            self._set_band(verbose=verbose)

    def write_hdf5(self):
        import h5py
        with h5py.File('band.hdf5', 'w') as w:
            w.create_dataset('paths', data=self._paths)
            w.create_dataset('distances', data=self._distances)
            w.create_dataset('nqstars', data=self._nqstars)
            w.create_dataset('num_irs', data=self._num_irs)
            w.create_dataset('frequencies', data=self._frequencies)
            w.create_dataset('pr_weights', data=self._pr_weights)
            # w.create_dataset('rot_pr_weights', data=self._rot_pr_weights)
            w.create_dataset('pg_symbols', data=self._pg_symbols)
            w.create_dataset('ir_labels', data=self._ir_labels)
            if self._group_velocity is not None:
{'fraction_non_alphanumeric': 0.07728200641586469, 'fraction_numerical': 0.0021872265966754157, 'mean_word_length': 2.1564657156005524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4432716', 'n_tokens_mistral': 2043, 'n_tokens_neox': 1952, 'n_words': 389}