# Path: pyDFTutils/ase_utils/symbol.py
# def symnum_to_sym(symbol_number):
#     """
#     symnum-> sym. eg: Fe1-> Fe
#     """
#     try:
#         a=re.search('[A-Za-z]+',symbol_number).group()
#         return a
#     except AttributeError:
#         raise AttributeError('%s is not a good symbol_number'%symbol_number)
# 
# Path: pyDFTutils/vasp/vasp_utils.py
# def get_symdict(filename='POSCAR', atoms=None):
#     """
#     get a symbol_number: index dict.
#     """
#     if filename is None and atoms is not None:
#         syms = atoms.get_chemical_symbols()
#     elif filename is not None and atoms is None:
#         syms = read(filename).get_chemical_symbols()
# 
#     symdict = symbol_number(syms)
#     return symdict


from ase.io import read
from ase.calculators.vasp import VaspDos
from os.path import join
from shutil import copyfile
from scipy import trapz,integrate
from pyDFTutils.ase_utils.symbol import symnum_to_sym
from .vasp_utils import get_symdict
from matplotlib.ticker import FormatStrFormatter
from collections import OrderedDict,Iterable
        from scipy.interpolate import interp1d
import numpy as np
import matplotlib.pyplot as plt
import os
import copy
    line_num=6
    for line in dos_text:
        line_num +=1
        if line_num >= nbands+6:
            break
        e,dos_up,dos_down,idos_up,idos_down=[float(fstr) for fstr in line.split()]
        e_norm=e-efermi
        if e_norm< epmax and e_norm > epmin:
            e_array.append(e_norm)
            dos_up_array.append(dos_up)
            dos_down_array.append(-dos_down)

    plt.gca().xaxis.set_major_formatter(FormatStrFormatter('%.2f'))
    plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.2f'))
    fig=plt.figure()
    tspin_splt=fig.add_subplot(111)
    tspin_splt.axvline(0,color='black')
    tspin_splt.grid(True)
    plt.plot(e_array,dos_up_array,label="Spin up")
    plt.plot(e_array,dos_down_array,label="Spin down")
    plt.legend()
    if output is None:
        plt.show()
    else:
        plt.savefig(output)
    plt.close()

def write_all_sum_dos(output='sum_dos.txt',nospin_output='sum_dos_nospin.txt',eg_polar_output='eg_polor.txt',erange=None):
    mydos=MyVaspDos()
    orbs=mydos.get_orbital_names()

# Path: pyDFTutils/ase_utils/symbol.py
# def symnum_to_sym(symbol_number):
#     """
#     symnum-> sym. eg: Fe1-> Fe
#     """
#     try:
#         a=re.search('[A-Za-z]+',symbol_number).group()
#         return a
#     except AttributeError:
#         raise AttributeError('%s is not a good symbol_number'%symbol_number)
# 
# Path: pyDFTutils/vasp/vasp_utils.py
# def get_symdict(filename='POSCAR', atoms=None):
#     """
#     get a symbol_number: index dict.
#     """
#     if filename is None and atoms is not None:
#         syms = atoms.get_chemical_symbols()
#     elif filename is not None and atoms is None:
#         syms = read(filename).get_chemical_symbols()
# 
#     symdict = symbol_number(syms)
#     return symdict


# Path: pyDFTutils/vasp/vasp_dos.py
from ase.io import read
from ase.calculators.vasp import VaspDos
from os.path import join
from shutil import copyfile
from scipy import trapz,integrate
from pyDFTutils.ase_utils.symbol import symnum_to_sym
from .vasp_utils import get_symdict
from matplotlib.ticker import FormatStrFormatter
from collections import OrderedDict,Iterable
        from scipy.interpolate import interp1d
import numpy as np
import matplotlib.pyplot as plt
import os
import copy

    line_num=6
    for line in dos_text:
        line_num +=1
        if line_num >= nbands+6:
            break
        e,dos_up,dos_down,idos_up,idos_down=[float(fstr) for fstr in line.split()]
        e_norm=e-efermi
        if e_norm< epmax and e_norm > epmin:
            e_array.append(e_norm)
            dos_up_array.append(dos_up)
            dos_down_array.append(-dos_down)

    plt.gca().xaxis.set_major_formatter(FormatStrFormatter('%.2f'))
    plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.2f'))
    fig=plt.figure()
    tspin_splt=fig.add_subplot(111)
    tspin_splt.axvline(0,color='black')
    tspin_splt.grid(True)
    plt.plot(e_array,dos_up_array,label="Spin up")
    plt.plot(e_array,dos_down_array,label="Spin down")
    plt.legend()
    if output is None:
        plt.show()
    else:
        plt.savefig(output)
    plt.close()

def write_all_sum_dos(output='sum_dos.txt',nospin_output='sum_dos_nospin.txt',eg_polar_output='eg_polor.txt',erange=None):
    mydos=MyVaspDos()
    orbs=mydos.get_orbital_names()

    symdict=get_symdict()