<commit_before># Copyright (c) 2015, <NAME>
# All rights reserved.
#
# This file is part of the yambopy project
#
from yambopy import *
from yambopy.plot  import *
import os

class YamboBSEAbsorptionSpectra(YamboSaveDB):
    """
    Create a file with information about the excitons from Yambo files
    """
    def __init__(self,job_string,path='.'):
        """
        Parameters:
            job_string - the job_string used for yambo. yambo -J <job_string>
            path       - the folder where the yambo run was made
        """

        #look for the save folder
        self.save=path+'/SAVE'
        if not os.path.isdir(self.save):
            raise ValueError('SAVE folder not found in %s'%self.save)

        YamboSaveDB.__init__(self,save=self.save)

        self.job_string = job_string
        self.data = {"excitons":[],
                     "lattice": self.lat,
                     "atypes": self.atomic_numbers,
                     "atoms": self.atomic_positions}

        self.atoms = None
        self.excitons = None
 
        #use YamboOut to read the absorption spectra
        self.path = path

        #try to find o-* files in path, if not use path/job_string
        paths = [path, "%s/%s"%(path,job_string)]
        for path in paths:
            y = YamboOut(path)
            absorptionspectra = y.get_data(('eps','diago'))
            #if we read the files then continue
            if absorptionspectra != {}:
                break

        #trap the errors here
        if absorptionspectra == {}:
            raise ValueError('Could not find the o-*diago*eps files in %s. Make sure you diagonalized the BSE hamiltonian in yambo.'%paths)

        #we just use one of them
        key = list(absorptionspectra)[0]
        for key,value in absorptionspectra[key].items():
            self.data[key] = value

    def get_excitons(self,min_intensity=0.1,max_energy=4,Degen_Step=0.0):
        """ 
        Obtain the excitons using ypp
        Parameters:
            min_intensity - Only plot excitons with intensity larger than this value (default: 0.1)
            max_energy    - Only plot excitons with energy below this value (default: 4 eV)
            Degen_Step    - Only plot excitons whose energy is different by more that this value (default: 0.0)
        """
        filename = "%s/o-%s.exc_E_sorted"%(self.path,self.job_string)
        if not os.path.isfile(filename):
            os.system("cd %s; ypp -e s -J %s"%(self.path,self.job_string))
        self.excitons = np.loadtxt(filename)

        #filter with energy
        self.excitons = self.excitons[self.excitons[:,0]<max_energy]

        #filter with intensity
        self.excitons = self.excitons[self.excitons[:,1]>min_intensity]

        #filter with degen
        if Degen_Step:

            #create a list with differences in energy
            new_excitons = []
            prev_exc = 0
            for exc in self.excitons:
                e,i,index = exc
                #if the energy of this exciton is too diferent then we add it to the list
                print e
                if abs(e-prev_exc)<Degen_Step:
                    new_excitons[-1][1] += i
                    continue
                new_excitons.append([e,i,index])
                intensity = 0
                prev_exc = e
            self.excitons = np.array(new_excitons)
<commit_msg>Read energies and indexes in the get_excitons of the YamboBSEAbsorptionSpectra class<commit_after># Copyright (c) 2015, <NAME>
# All rights reserved.
#
# This file is part of the yambopy project
#
from yambopy import *
from yambopy.plot  import *
import os

class YamboBSEAbsorptionSpectra(YamboSaveDB):
    """
    Create a file with information about the excitons from Yambo files
    """
    def __init__(self,job_string,path='.'):
        """
        Parameters:
            job_string - the job_string used for yambo. yambo -J <job_string>
            path       - the folder where the yambo run was made
        """

        #look for the save folder
        self.save=path+'/SAVE'
        if not os.path.isdir(self.save):
            raise ValueError('SAVE folder not found in %s'%self.save)

        YamboSaveDB.__init__(self,save=self.save)

        self.job_string = job_string
        self.data = {"excitons":[],
                     "lattice": self.lat,
                     "atypes": self.atomic_numbers,
                     "atoms": self.atomic_positions}

        self.atoms = None
        self.excitons = None
 
        #use YamboOut to read the absorption spectra
        self.path = path

        #try to find o-* files in path, if not use path/job_string
        paths = [path, "%s/%s"%(path,job_string)]
        for p in paths:
            y = YamboOut(p,save_folder=path)
            absorptionspectra = y.get_data(('eps','diago'))
            #if we read the files then continue
            if absorptionspectra != {}:
                break

        #trap the errors here
        if absorptionspectra == {}:
            raise ValueError('Could not find the o-*diago*eps files in %s. Make sure you diagonalized the BSE hamiltonian in yambo.'%paths)

        #we just use one of them
        key = list(absorptionspectra)[0]
        for key,value in absorptionspectra[key].items():
            self.data[key] = value

    def get_excitons(self,min_intensity=0.1,max_energy=4,Degen_Step=0.0):
        """ 
        Obtain the excitons using ypp
        Parameters:
            min_intensity - Only plot excitons with intensity larger than this value (default: 0.1)
            max_energy    - Only plot excitons with energy below this value (default: 4 eV)
            Degen_Step    - Only plot excitons whose energy is different by more that this value (default: 0.0)
        """
        filename = "%s/o-%s.exc_E_sorted"%(self.path,self.job_string)
        if not os.path.isfile(filename):
            os.system("cd %s; ypp -e s -J %s"%(self.path,self.job_string))
        self.excitons = np.loadtxt(filename)

        #filter with energy
        self.excitons = self.excitons[self.excitons[:,0]<max_energy]

        #filter with intensity
        self.excitons = self.excitons[self.excitons[:,1]>min_intensity]

        #filter with degen
        if Degen_Step:

            #create a list with differences in energy
            new_excitons = []
            prev_exc = 0
            for exc in self.excitons:
                e,i,index = exc
                #if the energy of this exciton is too diferent then we add it to the list
                print e
                if abs(e-prev_exc)<Degen_Step:
                    new_excitons[-1][1] += i
                    continue
                new_excitons.append([e,i,index])
                intensity = 0
                prev_exc = e
            self.excitons = np.array(new_excitons)

        #create dictionary with excitons 
        excitons = self.data["excitons"]
        for e,intensity,i in self.excitons:
            exciton = {"energy": e,
                       "intensity": intensity,
                       "index": i}
            excitons.append(exciton)
{'fraction_non_alphanumeric': 0.09274873524451939, 'fraction_numerical': 0.005902192242833052, 'mean_word_length': 1.891913856156034, 'pattern_counts': {'":': 11, '<': 11, '<?xml version=': 0, '>': 9, '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': '3918744', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2058, 'n_words': 608}