# Path: pyDFTutils/vasp/vasp_utils.py
# def read_poscar_and_unsort(filename='CONTCAR'):
#     """
#     read poscar and unsort. return the symbols,positions and cell in unsorted order.
#     """
#     atoms = read_vasp(filename)
#     symbols = get_unsorted(atoms.get_chemical_symbols())
#     positions = get_unsorted(atoms.get_positions())
#     cell = atoms.get_cell()
#     return symbols, positions, cell
# 
# Path: pyDFTutils/ase_utils/symbol.py
# def symbol_number(symbols):
#     """
#     symbols can be also atoms. Thus the chemical symbols will be used.
#     Fe Fe Fe O -> {Fe1:0 Fe2:1 Fe3:2 O1:3}
#     """
#     try:
#         symbs=symbols.copy().get_chemical_symbols()
#     except Exception:
#         symbs=symbols
#     symdict={}
#     result=OrderedDict()
#     for i,sym in enumerate(symbs):
#         if sym in symdict:
#             symdict[sym]=symdict[sym]+1
#         else:
#             symdict[sym]=1
#         result[sym+str(symdict[sym])]=i
#     return result


from pyDFTutils.vasp.vasp_utils import read_poscar_and_unsort
from ase.calculators.vasp import Vasp, Vasp2
from ase.dft.kpoints import get_bandpath
from os.path import join
from ase.utils import devnull, basestring
from pyDFTutils.ase_utils.symbol import symbol_number
from shutil import copyfile, move
import ase.calculators.vasp.create_input
import matplotlib.pyplot as plt
import os
import sys
import numpy as np
import tempfile
import ase.io
import socket
def read_OUTCAR_energy(outcar='./OUTCAR'):
    """
    read energy with out entropy from OUTCAR
    """
    [energy_free, energy_zero] = [0, 0]
    if all:
        energy_free = []
        energy_zero = []
    for line in open(outcar, 'r'):
        # Free energy
        if line.lower().startswith('  free  energy   toten'):
            if all:
                energy_free.append(float(line.split()[-2]))
            else:
                energy_free = float(line.split()[-2])
                # Extrapolated zero point energy
        if line.startswith('  energy  without entropy'):
            if all:
                energy_zero.append(float(line.split()[-1]))
            else:
                energy_zero = float(line.split()[-1])
    return energy_free


def read_OUTCAR_charges(poscar=None,
                        outcar='./OUTCAR',
                        orbital=None,
                        symnum=None):
    poscar = os.path.join(os.path.split(outcar)[0], 'POSCAR')
    atoms = read(poscar)

# Path: pyDFTutils/vasp/vasp_utils.py
# def read_poscar_and_unsort(filename='CONTCAR'):
#     """
#     read poscar and unsort. return the symbols,positions and cell in unsorted order.
#     """
#     atoms = read_vasp(filename)
#     symbols = get_unsorted(atoms.get_chemical_symbols())
#     positions = get_unsorted(atoms.get_positions())
#     cell = atoms.get_cell()
#     return symbols, positions, cell
# 
# Path: pyDFTutils/ase_utils/symbol.py
# def symbol_number(symbols):
#     """
#     symbols can be also atoms. Thus the chemical symbols will be used.
#     Fe Fe Fe O -> {Fe1:0 Fe2:1 Fe3:2 O1:3}
#     """
#     try:
#         symbs=symbols.copy().get_chemical_symbols()
#     except Exception:
#         symbs=symbols
#     symdict={}
#     result=OrderedDict()
#     for i,sym in enumerate(symbs):
#         if sym in symdict:
#             symdict[sym]=symdict[sym]+1
#         else:
#             symdict[sym]=1
#         result[sym+str(symdict[sym])]=i
#     return result


# Path: pyDFTutils/vasp/myvasp.py
from pyDFTutils.vasp.vasp_utils import read_poscar_and_unsort
from ase.calculators.vasp import Vasp, Vasp2
from ase.dft.kpoints import get_bandpath
from os.path import join
from ase.utils import devnull, basestring
from pyDFTutils.ase_utils.symbol import symbol_number
from shutil import copyfile, move
import ase.calculators.vasp.create_input
import matplotlib.pyplot as plt
import os
import sys
import numpy as np
import tempfile
import ase.io
import socket

def read_OUTCAR_energy(outcar='./OUTCAR'):
    """
    read energy with out entropy from OUTCAR
    """
    [energy_free, energy_zero] = [0, 0]
    if all:
        energy_free = []
        energy_zero = []
    for line in open(outcar, 'r'):
        # Free energy
        if line.lower().startswith('  free  energy   toten'):
            if all:
                energy_free.append(float(line.split()[-2]))
            else:
                energy_free = float(line.split()[-2])
                # Extrapolated zero point energy
        if line.startswith('  energy  without entropy'):
            if all:
                energy_zero.append(float(line.split()[-1]))
            else:
                energy_zero = float(line.split()[-1])
    return energy_free


def read_OUTCAR_charges(poscar=None,
                        outcar='./OUTCAR',
                        orbital=None,
                        symnum=None):
    poscar = os.path.join(os.path.split(outcar)[0], 'POSCAR')
    atoms = read(poscar)

    sdict = symbol_number(atoms)