# 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
        #subplot_number=int(str(len(xs))+'1'+str(i+1))
        nplot=len(xs)
        if i==0:
            axes.append(plt.subplot(nplot,1,i+1))
        else:
            axes.append(plt.subplot(nplot,1,i+1,sharex=axes[0]))
        ys=yss[i]
        label=labels[i]
        for y in ys:
            plt.xlabel('Energy (eV)')
            plt.ylabel('%s'%label)
            axes[i].plot(x,y)
            axes[i]
            plt.xlim(xmin,xmax)
            try:
                plt.ylim(ymin[i],ymax[i])
                plt.yticks(np.arange(ymin[i],ymax[i],(ymax[i]-ymin[i])/3.0))
            except Exception:
                plt.ylim(ymin,ymax)
                plt.yticks(np.arange(ymin,ymax,(ymax-ymin)/3.0))
    plt.legend()
    plt.show()

def plot_all_ldos(filename='DOSCAR',ispin=2,ymin=-2.0,ymax=2.0,xmin=-15.0,xmax=5.0,element_types=None, has_f=False):
    """
    plot the local dos of all atoms.
    """
    symdict=get_symdict()

    if element_types is not None:

# 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

        #subplot_number=int(str(len(xs))+'1'+str(i+1))
        nplot=len(xs)
        if i==0:
            axes.append(plt.subplot(nplot,1,i+1))
        else:
            axes.append(plt.subplot(nplot,1,i+1,sharex=axes[0]))
        ys=yss[i]
        label=labels[i]
        for y in ys:
            plt.xlabel('Energy (eV)')
            plt.ylabel('%s'%label)
            axes[i].plot(x,y)
            axes[i]
            plt.xlim(xmin,xmax)
            try:
                plt.ylim(ymin[i],ymax[i])
                plt.yticks(np.arange(ymin[i],ymax[i],(ymax[i]-ymin[i])/3.0))
            except Exception:
                plt.ylim(ymin,ymax)
                plt.yticks(np.arange(ymin,ymax,(ymax-ymin)/3.0))
    plt.legend()
    plt.show()

def plot_all_ldos(filename='DOSCAR',ispin=2,ymin=-2.0,ymax=2.0,xmin=-15.0,xmax=5.0,element_types=None, has_f=False):
    """
    plot the local dos of all atoms.
    """
    symdict=get_symdict()

    if element_types is not None:

        atom_nums=[x for x in list(symdict.keys()) if symnum_to_sym(x) in element_types]