# Path: pyDFTutils/abipy/input_utils.py
# def find_all_pp(obj, xc, family, label_dict={},pp_path=pp_path):
#     symbols = []
#     if isinstance(obj, collections.Iterable) and (
#             not isinstance(obj, str)) and isinstance(obj[0], str):
#         symbols = obj
#     elif isinstance(obj, str) and os.path.isfile(obj):
#         structure = Structure.as_structure(obj)
#         symbols = set(structure.symbol_set)
#     elif isinstance(obj, Structure):
#         symbols = obj.symbol_set
#     elif isinstance(obj, Atoms):
#         for elem in obj.get_chemical_symbols():
#             if elem not in symbols:
#                 symbols.append(elem)
#     else:
#         raise ValueError(
#             'obj should be one of these: list of chemical symbols| abipy structure file name| abipy structure| ase atoms.'
#         )
#     ppdict = OrderedDict()
#     for elem in symbols:
#         if elem not in ppdict:
#             if elem in label_dict:
#                 label = label_dict
#             else:
#                 label = ''
#             ppdict[elem] = find_pp(elem, xc, family, label,pp_path=pp_path)
#     return list(ppdict.values())
# 
# def set_Hubbard_U(abi_inp, ldau_dict={}, ldau_type=1, unit='eV'):
#     """
#     set DFT+U parameters.
#     """
#     structure = abi_inp.structure
#     symbols = structure.symbol_set
#     luj_params = LdauParams(ldau_type, structure)
#     for symbol in ldau_dict:
#         if symbol in symbols:
#             luj_params.luj_for_symbol(
#                 symbol,
#                 l=ldau_dict[symbol]['L'],
#                 u=ldau_dict[symbol]['U'],
#                 j=ldau_dict[symbol]['J'],
#                 unit=unit)
#     u_vars = luj_params.to_abivars()
#     abi_inp.set_vars(u_vars)
#     return abi_inp
# 
# def set_spinat(abi_inp, magmoms):
#     """
#     set initial spin configuration
#     """
#     sdict = None
#     if len(magmoms) == 0:
#         return abi_inp
#     elif isinstance(magmoms[0], collections.Iterable):
#         if len(magmoms[0]) == 3:
#             sdict = {'spinat': magmoms}
#     else:
#         sdict = {'spinat': [[0, 0, m] for m in magmoms]}
#     if sdict is None:
#         raise ValueError('magmoms should be 1D array or 3d array')
#     abi_inp.set_vars(sdict)
#     return abi_inp
# 
# def to_abi_structure(obj,magmoms=False):
#     ms=None
#     if isinstance(obj, str) and os.path.isfile(obj):
#         structure = Structure.as_structure(obj)
#     elif isinstance(obj, Structure):
#         structure = obj
#     elif isinstance(obj, Atoms):
#         #cell=obj.get_cell()
#         #acell0=np.linalg.norm(cell[0])
#         #acell1=np.linalg.norm(cell[1])
#         #acell2=np.linalg.norm(cell[2])
#         #cell0=cell[0]/acell0
#         #cell1=cell[1]/acell1
#         #cell2=cell[2]/acell2
#         #acell=[acell0, acell1, acell2]
#         #rprim=[cell0, cell1, cell2]
#         #xred=obj.get_scaled_positions()
#         #znucl=list(set(obj.get_atomic_numbers()))
#         #ntypat=len(znucl)
#         #typat=[]
#         #for z in obj.get_atomic_numbers():
#         #    for i,n in enumerate(znucl):
#         #        if z==n:
#         #            typat.append(i)
#         #structure = Structure.from_abivars(acell=acell, rprim=rprim, typat=typat, xred=xred, ntypat=ntypat, znucl=znucl)
#         structure = Structure.from_ase_atoms(obj)
#         if magmoms:
#             ms=obj.get_initial_magnetic_moments()
#     else:
#         raise ValueError(
#             'obj should be one of these:  abipy structure file name| abipy structure| ase atoms.'
#         )
#     if magmoms:
#         return structure,ms
#     else:
#         return structure


import os
import abipy.data as abidata
import abipy.abilab as abilab
import abipy.flowtk as flowapi
from abipy.abilab import AbinitInput
from abipy.abilab import Structure
from ase.units import eV, Ha
from abipy.abio.factories import scf_input, ebands_input, dos_from_gsinput, ioncell_relax_from_gsinput, scf_for_phonons, phonons_from_gsinput, piezo_elastic_inputs_from_gsinput, scf_piezo_elastic_inputs, ebands_from_gsinput
from abipy.abio.inputs import AbinitInput
from flow import myAbinitInput
from pyDFTutils.abipy.input_utils import find_all_pp, set_Hubbard_U, set_spinat, to_abi_structure
    from ase_utils3.cubic_perovskite import gen_primitive

#!/usr/bin/env python

from __future__ import division, print_function, unicode_literals



def build_structure(name, mag='PM'):
    return gen_primitive(name=name, latticeconstant=4, mag_order='PM')


def make_scf_input(atoms,
                   ecut=26,
                   xc='LDA',
                   is_metal=True,
                   spin_mode='PM',
                   pp_family='gbrv',
                   pp_labels={},
                   ldau_type=0,
                   Hubbard_U_dict={},

# Path: pyDFTutils/abipy/input_utils.py
# def find_all_pp(obj, xc, family, label_dict={},pp_path=pp_path):
#     symbols = []
#     if isinstance(obj, collections.Iterable) and (
#             not isinstance(obj, str)) and isinstance(obj[0], str):
#         symbols = obj
#     elif isinstance(obj, str) and os.path.isfile(obj):
#         structure = Structure.as_structure(obj)
#         symbols = set(structure.symbol_set)
#     elif isinstance(obj, Structure):
#         symbols = obj.symbol_set
#     elif isinstance(obj, Atoms):
#         for elem in obj.get_chemical_symbols():
#             if elem not in symbols:
#                 symbols.append(elem)
#     else:
#         raise ValueError(
#             'obj should be one of these: list of chemical symbols| abipy structure file name| abipy structure| ase atoms.'
#         )
#     ppdict = OrderedDict()
#     for elem in symbols:
#         if elem not in ppdict:
#             if elem in label_dict:
#                 label = label_dict
#             else:
#                 label = ''
#             ppdict[elem] = find_pp(elem, xc, family, label,pp_path=pp_path)
#     return list(ppdict.values())
# 
# def set_Hubbard_U(abi_inp, ldau_dict={}, ldau_type=1, unit='eV'):
#     """
#     set DFT+U parameters.
#     """
#     structure = abi_inp.structure
#     symbols = structure.symbol_set
#     luj_params = LdauParams(ldau_type, structure)
#     for symbol in ldau_dict:
#         if symbol in symbols:
#             luj_params.luj_for_symbol(
#                 symbol,
#                 l=ldau_dict[symbol]['L'],
#                 u=ldau_dict[symbol]['U'],
#                 j=ldau_dict[symbol]['J'],
#                 unit=unit)
#     u_vars = luj_params.to_abivars()
#     abi_inp.set_vars(u_vars)
#     return abi_inp
# 
# def set_spinat(abi_inp, magmoms):
#     """
#     set initial spin configuration
#     """
#     sdict = None
#     if len(magmoms) == 0:
#         return abi_inp
#     elif isinstance(magmoms[0], collections.Iterable):
#         if len(magmoms[0]) == 3:
#             sdict = {'spinat': magmoms}
#     else:
#         sdict = {'spinat': [[0, 0, m] for m in magmoms]}
#     if sdict is None:
#         raise ValueError('magmoms should be 1D array or 3d array')
#     abi_inp.set_vars(sdict)
#     return abi_inp
# 
# def to_abi_structure(obj,magmoms=False):
#     ms=None
#     if isinstance(obj, str) and os.path.isfile(obj):
#         structure = Structure.as_structure(obj)
#     elif isinstance(obj, Structure):
#         structure = obj
#     elif isinstance(obj, Atoms):
#         #cell=obj.get_cell()
#         #acell0=np.linalg.norm(cell[0])
#         #acell1=np.linalg.norm(cell[1])
#         #acell2=np.linalg.norm(cell[2])
#         #cell0=cell[0]/acell0
#         #cell1=cell[1]/acell1
#         #cell2=cell[2]/acell2
#         #acell=[acell0, acell1, acell2]
#         #rprim=[cell0, cell1, cell2]
#         #xred=obj.get_scaled_positions()
#         #znucl=list(set(obj.get_atomic_numbers()))
#         #ntypat=len(znucl)
#         #typat=[]
#         #for z in obj.get_atomic_numbers():
#         #    for i,n in enumerate(znucl):
#         #        if z==n:
#         #            typat.append(i)
#         #structure = Structure.from_abivars(acell=acell, rprim=rprim, typat=typat, xred=xred, ntypat=ntypat, znucl=znucl)
#         structure = Structure.from_ase_atoms(obj)
#         if magmoms:
#             ms=obj.get_initial_magnetic_moments()
#     else:
#         raise ValueError(
#             'obj should be one of these:  abipy structure file name| abipy structure| ase atoms.'
#         )
#     if magmoms:
#         return structure,ms
#     else:
#         return structure


# Path: pyDFTutils/abipy/test.py
import os
import abipy.data as abidata
import abipy.abilab as abilab
import abipy.flowtk as flowapi
from abipy.abilab import AbinitInput
from abipy.abilab import Structure
from ase.units import eV, Ha
from abipy.abio.factories import scf_input, ebands_input, dos_from_gsinput, ioncell_relax_from_gsinput, scf_for_phonons, phonons_from_gsinput, piezo_elastic_inputs_from_gsinput, scf_piezo_elastic_inputs, ebands_from_gsinput
from abipy.abio.inputs import AbinitInput
from flow import myAbinitInput
from pyDFTutils.abipy.input_utils import find_all_pp, set_Hubbard_U, set_spinat, to_abi_structure
    from ase_utils3.cubic_perovskite import gen_primitive


#!/usr/bin/env python

from __future__ import division, print_function, unicode_literals



def build_structure(name, mag='PM'):
    return gen_primitive(name=name, latticeconstant=4, mag_order='PM')


def make_scf_input(atoms,
                   ecut=26,
                   xc='LDA',
                   is_metal=True,
                   spin_mode='PM',
                   pp_family='gbrv',
                   pp_labels={},
                   ldau_type=0,
                   Hubbard_U_dict={},

                   **kwargs):