# Path: pyDFTutils/phonon/plotphon.py
# def plot_band_weight(kslist,
#                      ekslist,
#                      wkslist=None,
#                      efermi=0,
#                      yrange=None,
#                      output=None,
#                      style='alpha',
#                      color='blue',
#                      axis=None,
#                      width=2,
#                      xticks=None,
#                      title=None):
#     if axis is None:
#         fig, a = plt.subplots()
#         plt.tight_layout(pad=2.19)
#         plt.axis('tight')
#         plt.gcf().subplots_adjust(left=0.17)
#     else:
#         a = axis
#     if title is not None:
#         a.set_title(title)
# 
#     xmax = max(kslist[0])
#     if yrange is None:
#         yrange = (np.array(ekslist).flatten().min() - 66,
#                   np.array(ekslist).flatten().max() + 66)
# 
#     if wkslist is not None:
#         for i in range(len(kslist)):
#             x = kslist[i]
#             y = ekslist[i]
#             lwidths = np.array(wkslist[i]) * width
#             #lwidths=np.ones(len(x))
#             points = np.array([x, y]).T.reshape(-1, 1, 2)
#             segments = np.concatenate([points[:-1], points[1:]], axis=1)
#             if style == 'width':
#                 lc = LineCollection(segments, linewidths=lwidths, colors=color)
#             elif style == 'alpha':
#                 lc = LineCollection(
#                     segments,
#                     linewidths=[2] * len(x),
#                     colors=[
#                         colorConverter.to_rgba(
#                             color, alpha=np.abs(lwidth / (width + 0.001)))
#                         for lwidth in lwidths
#                     ])
# 
#             a.add_collection(lc)
#     plt.ylabel('Frequency (cm$^{-1}$)')
#     if axis is None:
#         for ks, eks in zip(kslist, ekslist):
#             plt.plot(ks, eks, color='gray', linewidth=0.001)
#         a.set_xlim(0, xmax)
#         a.set_ylim(yrange)
#         if xticks is not None:
#             plt.xticks(xticks[1], xticks[0])
#         for x in xticks[1]:
#             plt.axvline(x, color='gray', linewidth=0.5)
#         if efermi is not None:
#             plt.axhline(linestyle='--', color='black')
#     return a


from ase.lattice.cubic import FaceCenteredCubic
from ase.calculators.emt import EMT
from ase.units import Bohr
from frozenphonon import calculate_phonon
from ase.dft.kpoints import *
from ase.build import bulk
from pyDFTutils.unfolding.phonon_unfolder import phonon_unfolder
from pyDFTutils.phonon.plotphon import plot_band_weight
import numpy as np
import matplotlib.pyplot as plt
#!/usr/bin/env python

#from ase_utils import vesta_view


def kpath():
    #atoms = FaceCenteredCubic(size=(1,1,1), symbol="Cu", pbc=True)
    atoms = bulk('Cu', 'fcc', a=3.61)
    points = get_special_points('fcc', atoms.cell, eps=0.01)
    GXW = [points[k] for k in 'GXWGL']
    kpts, x, X = bandpath(GXW, atoms.cell, 700)
    names = ['$\Gamma$', 'X', 'W', '$\Gamma$', 'L']
    return kpts, x, X, names


def get_phonon_prim(ax=None):
    atoms = bulk('Cu', 'fcc', a=3.61)
    #vesta_view(atoms)
    calc = EMT()
    atoms.set_calculator(calc)
    phonon = calculate_phonon(
        atoms, calc, ndim=np.eye(3) * 3, primitive_matrix=np.diag([1] * 3))
    kpts, x, X, names = kpath()

# Path: pyDFTutils/phonon/plotphon.py
# def plot_band_weight(kslist,
#                      ekslist,
#                      wkslist=None,
#                      efermi=0,
#                      yrange=None,
#                      output=None,
#                      style='alpha',
#                      color='blue',
#                      axis=None,
#                      width=2,
#                      xticks=None,
#                      title=None):
#     if axis is None:
#         fig, a = plt.subplots()
#         plt.tight_layout(pad=2.19)
#         plt.axis('tight')
#         plt.gcf().subplots_adjust(left=0.17)
#     else:
#         a = axis
#     if title is not None:
#         a.set_title(title)
# 
#     xmax = max(kslist[0])
#     if yrange is None:
#         yrange = (np.array(ekslist).flatten().min() - 66,
#                   np.array(ekslist).flatten().max() + 66)
# 
#     if wkslist is not None:
#         for i in range(len(kslist)):
#             x = kslist[i]
#             y = ekslist[i]
#             lwidths = np.array(wkslist[i]) * width
#             #lwidths=np.ones(len(x))
#             points = np.array([x, y]).T.reshape(-1, 1, 2)
#             segments = np.concatenate([points[:-1], points[1:]], axis=1)
#             if style == 'width':
#                 lc = LineCollection(segments, linewidths=lwidths, colors=color)
#             elif style == 'alpha':
#                 lc = LineCollection(
#                     segments,
#                     linewidths=[2] * len(x),
#                     colors=[
#                         colorConverter.to_rgba(
#                             color, alpha=np.abs(lwidth / (width + 0.001)))
#                         for lwidth in lwidths
#                     ])
# 
#             a.add_collection(lc)
#     plt.ylabel('Frequency (cm$^{-1}$)')
#     if axis is None:
#         for ks, eks in zip(kslist, ekslist):
#             plt.plot(ks, eks, color='gray', linewidth=0.001)
#         a.set_xlim(0, xmax)
#         a.set_ylim(yrange)
#         if xticks is not None:
#             plt.xticks(xticks[1], xticks[0])
#         for x in xticks[1]:
#             plt.axvline(x, color='gray', linewidth=0.5)
#         if efermi is not None:
#             plt.axhline(linestyle='--', color='black')
#     return a


# Path: examples/phonon_unfolding/eam_me.py
from ase.lattice.cubic import FaceCenteredCubic
from ase.calculators.emt import EMT
from ase.units import Bohr
from frozenphonon import calculate_phonon
from ase.dft.kpoints import *
from ase.build import bulk
from pyDFTutils.unfolding.phonon_unfolder import phonon_unfolder
from pyDFTutils.phonon.plotphon import plot_band_weight
import numpy as np
import matplotlib.pyplot as plt

#!/usr/bin/env python

#from ase_utils import vesta_view


def kpath():
    #atoms = FaceCenteredCubic(size=(1,1,1), symbol="Cu", pbc=True)
    atoms = bulk('Cu', 'fcc', a=3.61)
    points = get_special_points('fcc', atoms.cell, eps=0.01)
    GXW = [points[k] for k in 'GXWGL']
    kpts, x, X = bandpath(GXW, atoms.cell, 700)
    names = ['$\Gamma$', 'X', 'W', '$\Gamma$', 'L']
    return kpts, x, X, names


def get_phonon_prim(ax=None):
    atoms = bulk('Cu', 'fcc', a=3.61)
    #vesta_view(atoms)
    calc = EMT()
    atoms.set_calculator(calc)
    phonon = calculate_phonon(
        atoms, calc, ndim=np.eye(3) * 3, primitive_matrix=np.diag([1] * 3))
    kpts, x, X, names = kpath()

    phonon.set_qpoints_phonon(kpts, is_eigenvectors=True)