# 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
# 
# 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)


import numpy as np
import os.path
import re
from ase.io import read
from ase.io.vasp import read_vasp
from pyDFTutils.ase_utils.symbol import symbol_number, symnum_to_sym
from ase.atoms import Atoms
            if line.startswith(' magnetization (x)'):
                start = True
                text = ''
            if start:
                text += line
            if line.startswith('tot'):
                start = False
    return text


def check_converge(filename='log'):
    """
    check the log file to see if the calculation is converged.
    If converged, return the number of steps of iteration, else return False.
    """
    nstep = 0
    with open(filename) as myfile:
        for line in myfile:
            l = line
            try:
                nstep = int(line.strip().split()[0])
            except Exception:
                pass
        if l.strip().startswith('writing'):
            return nstep
        else:
            return False


if __name__ == '__main__':

# 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
# 
# 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
import numpy as np
import os.path
import re
from ase.io import read
from ase.io.vasp import read_vasp
from pyDFTutils.ase_utils.symbol import symbol_number, symnum_to_sym
from ase.atoms import Atoms

            if line.startswith(' magnetization (x)'):
                start = True
                text = ''
            if start:
                text += line
            if line.startswith('tot'):
                start = False
    return text


def check_converge(filename='log'):
    """
    check the log file to see if the calculation is converged.
    If converged, return the number of steps of iteration, else return False.
    """
    nstep = 0
    with open(filename) as myfile:
        for line in myfile:
            l = line
            try:
                nstep = int(line.strip().split()[0])
            except Exception:
                pass
        if l.strip().startswith('writing'):
            return nstep
        else:
            return False


if __name__ == '__main__':

    print(symnum_to_sym('1'))