# 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
    poscar = os.path.join(os.path.split(outcar)[0], 'POSCAR')
    atoms = read(poscar)
    sdict = symbol_number(atoms)
    charges = np.zeros(len(atoms))
    orb_charges = []
    n = 0
    lines = open(outcar, 'r').readlines()
    for line in lines:
        if line.rfind('total charge   ') > -1:
            for m in range(len(atoms)):
                charges[m] = float(lines[n + m + 4].strip().split()[-1])
                orb_charges.append(
                    [float(x) for x in lines[n + m + 4].strip().split()[1:-1]])
        n += 1
    if orbital is None and symnum is None:
        return np.array(charges)
    elif orbital is None and symnum is not None:
        return np.array(charges)[sdict[symnum]]
    elif orbital is not None and symnum is not None:
        return np.array(orb_charges)[sdict[symnum]][orbital]
    else:
        return np.array(orb_charges)[:, orbital]


def read_magnetic_moments(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

    poscar = os.path.join(os.path.split(outcar)[0], 'POSCAR')
    atoms = read(poscar)
    sdict = symbol_number(atoms)
    charges = np.zeros(len(atoms))
    orb_charges = []
    n = 0
    lines = open(outcar, 'r').readlines()
    for line in lines:
        if line.rfind('total charge   ') > -1:
            for m in range(len(atoms)):
                charges[m] = float(lines[n + m + 4].strip().split()[-1])
                orb_charges.append(
                    [float(x) for x in lines[n + m + 4].strip().split()[1:-1]])
        n += 1
    if orbital is None and symnum is None:
        return np.array(charges)
    elif orbital is None and symnum is not None:
        return np.array(charges)[sdict[symnum]]
    elif orbital is not None and symnum is not None:
        return np.array(orb_charges)[sdict[symnum]][orbital]
    else:
        return np.array(orb_charges)[:, orbital]


def read_magnetic_moments(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)