def test_enabled_complex_nlep(vasp, structure, Specie): from numpy import all, abs, array from pylada.vasp.specie import U, nlep import pylada pylada.vasp_has_nlep = True vasp.species = { 'A': Specie([U(2, 0, 0.5)]), 'B': Specie([U(2, 0, -0.5), nlep(2, 2, -1.0, -3.0)]), 'X': Specie([]) } vasp.ldau = True map = vasp.output_map(vasp=vasp, structure=structure) assert map['LDAU'] == '.TRUE.' assert map['LDAUTYPE'] == '2' assert all( abs(array(map['LDUL1'].split(), dtype='float64') - [0, 0, -1]) < 1e-8) assert all( abs(array(map['LDUU1'].split(), dtype='float64') - [0.5, -0.5, 0]) < 1e-8) assert all( abs(array(map['LDUJ1'].split(), dtype='float64') - [0, 0, 0]) < 1e-8) assert all( abs(array(map['LDUO1'].split(), dtype='float64') - [1, 1, 1]) < 1e-8) assert all( abs(array(map['LDUL2'].split(), dtype='float64') - [-1, 2, -1]) < 1e-8) assert all( abs(array(map['LDUU2'].split(), dtype='float64') - [0, -1.0, 0]) < 1e-8) assert all( abs(array(map['LDUJ2'].split(), dtype='float64') - [0, -3.0, 0]) < 1e-8) assert all( abs(array(map['LDUO2'].split(), dtype='float64') - [1, 3, 1]) < 1e-8)
def test_enabled_complex_U(vasp, Specie, structure): from numpy import all, abs, array from pylada.vasp.specie import U import pylada pylada.vasp_has_nlep = False vasp.species = {'A': Specie([U(2, 0, 0.5)]), 'B': Specie([U(2, 1, 0.6)]), 'X': Specie([])} vasp.ldau = True map = vasp.output_map(vasp=vasp, structure=structure) assert map['LDAU'] == '.TRUE.' assert map['LDAUTYPE'] == '2' assert all(abs(array(map['LDUJ'].split(), dtype='float64')) < 1e-8) assert all(abs(array(map['LDUU'].split(), dtype='float64') - [0.5, 0.6, 0]) < 1e-8) assert all(abs(array(map['LDUL'].split(), dtype='float64') - [0, 1, -1]) < 1e-8)
def test_disabled_nlep(vasp, Specie, structure): from numpy import all, abs, array from pylada.vasp.specie import U, nlep import pylada pylada.vasp_has_nlep = True vasp.species = { 'A': Specie([U(2, 0, 0.5)]), 'B': Specie([U(2, 0, -0.5), nlep(2, 1, -1.0)]), 'X': Specie([]) } vasp.ldau = False assert vasp.ldau == False assert vasp.output_map(vasp=vasp) is None
def test_U_disabled(vasp, structure, Specie): from pylada.vasp.specie import U import pylada pylada.vasp_has_nlep = False vasp.ldau = False vasp.species = {'A': Specie([U(2, 0, 0.5)]), 'B': Specie([]), 'X': Specie([])} assert vasp.ldau == False assert vasp.output_map(vasp=vasp) is None
def test_U(): """ Test U translation. """ from pylada.vasp.specie import U a = U("liechtenstein", 's', -1e0, 1e0) assert a['type'] == 1 and a['l'] == 0 and abs(a['U'] + 1e0) < 1e-8 \ and abs(a['J'] - 1e0) < 1e-8 and a['func'] == 'U' a = U("dudarev", 'p', -0.5, 5e0) assert a['type'] == 2 and a['l'] == 1 and abs(a['U'] + 0.5) < 1e-8 \ and abs(a['J'] - 5e0) < 1e-8 and a['func'] == 'U' a = U("dudarev", 'd') assert a['type'] == 2 and a['l'] == 2 and abs(a['U']) < 1e-8 \ and abs(a['J']) < 1e-8 and a['func'] == 'U' a = U("dudarev", 'f') assert a['type'] == 2 and a['l'] == 3 and abs(a['U']) < 1e-8 \ and abs(a['J']) < 1e-8 and a['func'] == 'U' try: U('shit') except: pass else: raise RuntimeError() try: U(l=4) except: pass else: raise RuntimeError() try: U(type=0) except: pass else: raise RuntimeError()
def load_FERE_species(vasp: Vasp, structure): # See vasp/functional.py: elementName, fileName, max or min oxidation state pseudoDir = '$PSEUDO_DIR' vasp.add_specie = "Sc", pseudoDir + "/Sc_sv", U("dudarev", "d", 3) # FERE vasp.add_specie = "Y", pseudoDir + "/Y_sv", U("dudarev", "d", 3) # FERE # vasp.add_specie = "Ti", pseudoDir + "/Ti_pv", U("dudarev", "d", 4.35) # Wolverton 3+ # vasp.add_specie = "V", pseudoDir + "/V_pv", U("dudarev", "d", 4.9) # Wolverton 2+ # vasp.add_specie = "Cr", pseudoDir + "/Cr_pv", U("dudarev", "d", 3.04) # Wolverton 3+ vasp.add_specie = "Zr", pseudoDir + "/Zr_sv", U("dudarev", "d", 3) # FERE # vasp.add_specie = "Mn", pseudoDir + "/Mn_pv", U("dudarev", "d", 2.98) # Wolverton 2+ # vasp.add_specie = "Mn3p", pseudoDir + "/Mn_pv", U("dudarev", "d", 4.54) # Wolverton 3+ vasp.add_specie = "Fe", pseudoDir + "/Fe_pv", U("dudarev", "d", 3) # FERE vasp.add_specie = "Co", pseudoDir + "/Co_pv", U("dudarev", "d", 3) # Wolverton 2+ vasp.add_specie = "Ni", pseudoDir + "/Ni_pv", U("dudarev", "d", 3) # FERE vasp.add_specie = "Cu", pseudoDir + "/Cu_pv", U("dudarev", "d", 5.0) # FERE vasp.add_specie = "Nb", pseudoDir + "/Nb_pv", U("dudarev", "d", 3.0) # FERE vasp.add_specie = "Ce", pseudoDir + "/Ce", U("dudarev", "f", 3.0) # Wolverton Ceria Paper vasp.add_specie = "Zn", pseudoDir + "/Zn", vasp.add_specie = "Ga", pseudoDir + "/Ga", vasp.add_specie = "O", pseudoDir + "/O" vasp.add_specie = "Al", pseudoDir + "/Al" vasp.add_specie = "H", pseudoDir + "/H" vasp.add_specie = "Nb", pseudoDir + "/Nb_pv" vasp.add_specie = "Ta", pseudoDir + "/Ta_pv" vasp.add_specie = "Hf", pseudoDir + "/Hf_pv" vasp.add_specie = "Sr", pseudoDir + "/Sr_sv" vasp.add_specie = "Si", pseudoDir + "/Si" vasp.add_specie = "Cd", pseudoDir + "/Cd" vasp.add_specie = "Ba", pseudoDir + "/Ba_sv" vasp.add_specie = "Be", pseudoDir + "/Be" vasp.add_specie = "Ba", pseudoDir + "/Ba_sv" vasp.add_specie = "Bi", pseudoDir + "/Bi_d" vasp.add_specie = "Ge", pseudoDir + "/Ge_d" vasp.add_specie = "Se", pseudoDir + "/Se" vasp.add_specie = "Sb", pseudoDir + "/Sb" vasp.add_specie = "Na", pseudoDir + "/Na_pv" vasp.add_specie = "Ca", pseudoDir + "/Ca_pv" vasp.add_specie = "In", pseudoDir + "/In_d" vasp.add_specie = "K", pseudoDir + "/K_sv" vasp.add_specie = "Mg", pseudoDir + "/Mg" vasp.add_specie = "Sn", pseudoDir + "/Sn_d" vasp.add_specie = "Li", pseudoDir + "/Li_sv" vasp.add_specie = "La", pseudoDir + "/La" # TODO Determine U return (vasp)
def test(): from collections import namedtuple from pickle import loads, dumps from pylada.crystal.cppwrappers import Structure from pylada.vasp.incar._params import UParams from pylada.vasp.specie import U, nlep u = 0.25 x, y = u, 0.25 - u structure = Structure([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]]) \ .add_atom(5.000000e-01, 5.000000e-01, 5.000000e-01, "A") \ .add_atom(5.000000e-01, 2.500000e-01, 2.500000e-01, "A") \ .add_atom(2.500000e-01, 5.000000e-01, 2.500000e-01, "A") \ .add_atom(2.500000e-01, 2.500000e-01, 5.000000e-01, "A") \ .add_atom(8.750000e-01, 8.750000e-01, 8.750000e-01, "B") \ .add_atom(1.250000e-01, 1.250000e-01, 1.250000e-01, "B") \ .add_atom( x, x, x, "X") \ .add_atom( x, y, y, "X") \ .add_atom( y, x, y, "X") \ .add_atom( y, y, x, "X") \ .add_atom( -x, -x, -x, "X") \ .add_atom( -x, -y, -y, "X") \ .add_atom( -y, -x, -y, "X") \ .add_atom( -y, -y, -x, "X") Vasp = namedtuple('Vasp', ['species']) Specie = namedtuple('Specie', ['U']) vasp = Vasp({ 'A': Specie([U(2, 0, 0.5)]), 'B': Specie([U(2, 0, -0.5), nlep(2, 1, -1.0)]), 'X': Specie([]) }) a =\ """\ LDAU = .TRUE. LDAUPRINT = 0 LDAUTYPE = 2 LDUL1= 0 -1 0 LDUU1= 5.0000000000e-01 0.0000000000e+00 -5.0000000000e-01 LDUJ1= 0.0000000000e+00 0.0000000000e+00 0.0000000000e+00 LDUO1= 1 1 1 LDUL2= -1 -1 1 LDUU2= 0.0000000000e+00 0.0000000000e+00 -1.0000000000e+00 LDUJ2= 0.0000000000e+00 0.0000000000e+00 0.0000000000e+00 LDUO2= 1 1 2 """ assert a == UParams('off').incar_string(vasp=vasp, structure=structure) vasp = Vasp({ 'A': Specie([U(2, 0, 0.5)]), 'B': Specie([U(2, 0, -0.5), nlep(2, 2, -1.0, -3.0)]), 'X': Specie([]) }) a =\ """\ LDAU = .TRUE. LDAUPRINT = 1 LDAUTYPE = 2 LDUL1= 0 -1 0 LDUU1= 5.0000000000e-01 0.0000000000e+00 -5.0000000000e-01 LDUJ1= 0.0000000000e+00 0.0000000000e+00 0.0000000000e+00 LDUO1= 1 1 1 LDUL2= -1 -1 2 LDUU2= 0.0000000000e+00 0.0000000000e+00 -1.0000000000e+00 LDUJ2= 0.0000000000e+00 0.0000000000e+00 -3.0000000000e+00 LDUO2= 1 1 3 """ assert a == UParams('on').incar_string(vasp=vasp, structure=structure) vasp = Vasp({'A': Specie([]), 'B': Specie([]), 'X': Specie([])}) assert '# no LDA+U/NLEP parameters' == UParams('all').incar_string( vasp=vasp, structure=structure) assert repr(UParams('off')) == "UParams('off')" assert repr(UParams('on')) == "UParams('on')" assert repr(UParams(None)) == "UParams('off')" assert repr(UParams('all')) == "UParams('all')" assert repr(loads(dumps(UParams('off')))) == "UParams('off')" assert repr(loads(dumps(UParams('on')))) == "UParams('on')" assert repr(loads(dumps(UParams(None)))) == "UParams('off')" assert repr(loads(dumps(UParams('all')))) == "UParams('all')"
def test(): from collections import namedtuple from pickle import loads, dumps from numpy import all, abs, array from pylada.crystal import Structure from pylada.vasp import Vasp from pylada.vasp.specie import U, nlep import pylada u = 0.25 x, y = u, 0.25 - u structure = Structure([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]]) \ .add_atom(5.000000e-01, 5.000000e-01, 5.000000e-01, "A") \ .add_atom(5.000000e-01, 2.500000e-01, 2.500000e-01, "A") \ .add_atom(2.500000e-01, 5.000000e-01, 2.500000e-01, "A") \ .add_atom(2.500000e-01, 2.500000e-01, 5.000000e-01, "A") \ .add_atom(8.750000e-01, 8.750000e-01, 8.750000e-01, "B") \ .add_atom(1.250000e-01, 1.250000e-01, 1.250000e-01, "B") \ .add_atom( x, x, x, "X") \ .add_atom( x, y, y, "X") \ .add_atom( y, x, y, "X") \ .add_atom( y, y, x, "X") \ .add_atom( -x, -x, -x, "X") \ .add_atom( -x, -y, -y, "X") \ .add_atom( -y, -x, -y, "X") \ .add_atom( -y, -y, -x, "X") a = Vasp() Specie = namedtuple('Specie', ['U']) a.species = {'A': Specie([]), 'B': Specie([]), 'X': Specie([])} pylada.vasp_has_nlep = False o = a._input['ldau'] d = {'LDAU': o.__class__} assert a.ldau == True assert o.output_map(vasp=a, structure=structure) is None assert eval(repr(o), d)._value == True assert eval(repr(o), d).keyword == 'LDAU' assert loads(dumps(o)).keyword == 'LDAU' assert loads(dumps(o))._value # now disables U. a.species = {'A': Specie([U(2, 0, 0.5)]), 'B': Specie([]), 'X': Specie([])} a.ldau = False assert a.ldau == False print o assert o.output_map(vasp=a) is None # now prints U a.ldau = True map = o.output_map(vasp=a, structure=structure) assert map['LDAU'] == '.TRUE.' assert map['LDAUTYPE'] == '2' assert all(abs(array(map['LDUJ'].split(), dtype='float64')) < 1e-8) assert all( abs(array(map['LDUU'].split(), dtype='float64') - [0.5, 0, 0]) < 1e-8) assert all( abs(array(map['LDUL'].split(), dtype='float64') - [0, -1, -1]) < 1e-8) a.species = { 'A': Specie([U(2, 0, 0.5)]), 'B': Specie([U(2, 1, 0.6)]), 'X': Specie([]) } map = o.output_map(vasp=a, structure=structure) assert map['LDAU'] == '.TRUE.' assert map['LDAUTYPE'] == '2' assert all(abs(array(map['LDUJ'].split(), dtype='float64')) < 1e-8) assert all( abs(array(map['LDUU'].split(), dtype='float64') - [0.5, 0, 0.6]) < 1e-8) assert all( abs(array(map['LDUL'].split(), dtype='float64') - [0, -1, 1]) < 1e-8) # now tries NLEP pylada.vasp_has_nlep = True a.species = { 'A': Specie([U(2, 0, 0.5)]), 'B': Specie([U(2, 0, -0.5), nlep(2, 1, -1.0)]), 'X': Specie([]) } a.ldau = False assert a.ldau == False assert o.output_map(vasp=a) is None a.ldau = True map = o.output_map(vasp=a, structure=structure) assert map['LDAU'] == '.TRUE.' assert map['LDAUTYPE'] == '2' assert all( abs(array(map['LDUL1'].split(), dtype='float64') - [0, -1, 0]) < 1e-8) assert all( abs(array(map['LDUU1'].split(), dtype='float64') - [0.5, 0, -0.5]) < 1e-8) assert all( abs(array(map['LDUJ1'].split(), dtype='float64') - [0, 0, 0]) < 1e-8) assert all( abs(array(map['LDUO1'].split(), dtype='float64') - [1, 1, 1]) < 1e-8) assert all( abs(array(map['LDUL2'].split(), dtype='float64') - [-1, -1, 1]) < 1e-8) assert all( abs(array(map['LDUU2'].split(), dtype='float64') - [0, 0, -1.0]) < 1e-8) assert all( abs(array(map['LDUJ2'].split(), dtype='float64') - [0, 0, 0]) < 1e-8) assert all( abs(array(map['LDUO2'].split(), dtype='float64') - [1, 1, 2]) < 1e-8) a.species = { 'A': Specie([U(2, 0, 0.5)]), 'B': Specie([U(2, 0, -0.5), nlep(2, 2, -1.0, -3.0)]), 'X': Specie([]) } a.ldau = True map = o.output_map(vasp=a, structure=structure) assert map['LDAU'] == '.TRUE.' assert map['LDAUTYPE'] == '2' assert all( abs(array(map['LDUL1'].split(), dtype='float64') - [0, -1, 0]) < 1e-8) assert all( abs(array(map['LDUU1'].split(), dtype='float64') - [0.5, 0, -0.5]) < 1e-8) assert all( abs(array(map['LDUJ1'].split(), dtype='float64') - [0, 0, 0]) < 1e-8) assert all( abs(array(map['LDUO1'].split(), dtype='float64') - [1, 1, 1]) < 1e-8) assert all( abs(array(map['LDUL2'].split(), dtype='float64') - [-1, -1, 2]) < 1e-8) assert all( abs(array(map['LDUU2'].split(), dtype='float64') - [0, 0, -1.0]) < 1e-8) assert all( abs(array(map['LDUJ2'].split(), dtype='float64') - [0, 0, -3.0]) < 1e-8) assert all( abs(array(map['LDUO2'].split(), dtype='float64') - [1, 1, 3]) < 1e-8)
def load_low_FERE_species(vasp: Vasp, structure): pseudoDir = '$PSEUDO_DIR' vasp.add_specie = "Fe", pseudoDir + "/Fe", U("dudarev", "d", 3) # FERE vasp.add_specie = "O", pseudoDir + "/O_s" vasp.add_specie = "Al", pseudoDir + "/Al" return vasp
def load_optimized_U_species(vasp : Vasp, structure): # See vasp/functional.py: elementName, fileName, max or min oxidation state pseudoDir = '$PSEUDO_DIR' vasp.add_specie = "Sc", pseudoDir + "/Sc_sv", U("dudarev", "d", 3) # FERE vasp.add_specie = "Y", pseudoDir + "/Y_sv", U("dudarev", "d", 3) # FERE vasp.add_specie = "Ti", pseudoDir + "/Ti_pv", U("dudarev", "d", 4.35) # Wolverton 3+ vasp.add_specie = "V", pseudoDir + "/V_pv", U("dudarev", "d", 4.9) # Wolverton 2+ vasp.add_specie = "Cr", pseudoDir + "/Cr_pv", U("dudarev", "d", 3.04) # Wolverton 3+ vasp.add_specie = "Zr", pseudoDir + "/Zr_sv", U("dudarev", "d", 3) # FERE vasp.add_specie = "Mn", pseudoDir + "/Mn_pv", U("dudarev", "d", 2.98) # Wolverton 2+ vasp.add_specie = "Mn3p", pseudoDir + "/Mn_pv", U("dudarev", "d", 4.54) # Wolverton 3+ vasp.add_specie = "Mn4p", pseudoDir + "/Mn", U("dudarev", "d", 3.19) # Wolverton 3+ vasp.add_specie = "Fe", pseudoDir + "/Fe_pv", U("dudarev", "d", 4.04) # Wolverton 2+, vasp.add_specie = "Co", pseudoDir + "/Co_pv", U("dudarev", "d", 3.75) # Wolverton 2+ vasp.add_specie = "Ni", pseudoDir + "/Ni_pv", U("dudarev", "d", 4.4) # Wolverton 2+ vasp.add_specie = "Cu", pseudoDir + "/Cu_pv", U("dudarev", "d" , 5.0) # FERE vasp.add_specie = "Nb", pseudoDir + "/Nb_pv", U("dudarev", "d" , 3.0) # FERE vasp.add_specie = "Ce", pseudoDir + "/Ce", U("dudarev", "f" , 3.0) # Wolverton Ceria Paper vasp.add_specie = "Pr", pseudoDir + "/Pr", U("dudarev", "f" , 4.3) # https://doi.org/10.1016/j.actamat.2010.11.041 vasp.add_specie = "Nd", pseudoDir + "/Nd", U("dudarev", "f" , 6.0) # https://doi.org/10.1016/j.actamat.2010.11.041 vasp.add_specie = "Eu", pseudoDir + "/Eu", U("dudarev", "f" , 7.0) # https://doi.org/10.1016/j.actamat.2010.11.041 vasp.add_specie = "Sm", pseudoDir + "/Sm", U("dudarev", "f" , 8.0) # https://doi.org/10.1016/j.actamat.2010.11.041 vasp.add_specie = "Gd", pseudoDir + "/Gd", U("dudarev", "f" , 4.0) # https://doi.org/10.1002/jcc.23618 vasp.add_specie = "Tb", pseudoDir + "/Tb", U("dudarev", "f" , 10.0) # https://doi.org/10.1002/jcc.23618 vasp.add_specie = "Ho", pseudoDir + "/Ho", U("dudarev", "f" , 8.0) # https://doi.org/10.1002/jcc.24272 vasp.add_specie = "Er", pseudoDir + "/Er", U("dudarev", "f" , 8.4) # https://doi.org/10.1002/jcc.24272 vasp.add_specie = "Tm", pseudoDir + "/Tm", U("dudarev", "f" , 9.1) # https://doi.org/10.1002/jcc.24272 vasp.add_specie = "Yb", pseudoDir + "/Yb", U("dudarev", "f" , 6.4) # https://doi.org/10.1002/jcc.24272 vasp.add_specie = "Dy", pseudoDir + "/Dy", U("dudarev", "f" , 10.9) # https://doi.org/10.1002/jcc.23618 vasp.add_specie = "Gd", pseudoDir + "/Gd", U("dudarev", "f" , 4.5) # https://doi.org/10.1002/jcc.23618 vasp.add_specie = "Lu", pseudoDir + "/Lu", U("dudarev", "f" , 9.5) # https://doi.org/10.1002/jcc.24272 vasp.add_specie = "Zn", pseudoDir + "/Zn", vasp.add_specie = "Ga", pseudoDir + "/Ga", vasp.add_specie = "O", pseudoDir + "/O" vasp.add_specie = "S", pseudoDir + "/S" vasp.add_specie = "P", pseudoDir + "/P" vasp.add_specie = "Al", pseudoDir + "/Al" vasp.add_specie = "H", pseudoDir + "/H" vasp.add_specie = "Hf", pseudoDir + "/Hf_pv", U("dudarev", "d", 3) # FERE vasp.add_specie = "Ta", pseudoDir + "/Ta_pv", U("dudarev", "d", 3) # FERE vasp.add_specie = "Sr", pseudoDir + "/Sr_sv" vasp.add_specie = "F", pseudoDir + "/F" vasp.add_specie = "C", pseudoDir + "/C" vasp.add_specie = "Si", pseudoDir + "/Si" vasp.add_specie = "Cd", pseudoDir + "/Cd" vasp.add_specie = "Ba", pseudoDir + "/Ba_sv" vasp.add_specie = "Be", pseudoDir + "/Be" vasp.add_specie = "Ba", pseudoDir + "/Ba_sv" vasp.add_specie = "Bi", pseudoDir + "/Bi_d" vasp.add_specie = "Ge", pseudoDir + "/Ge_d" vasp.add_specie = "Se", pseudoDir + "/Se" vasp.add_specie = "Sb", pseudoDir + "/Sb" vasp.add_specie = "Na", pseudoDir + "/Na_pv" vasp.add_specie = "Ca", pseudoDir + "/Ca_pv" vasp.add_specie = "In", pseudoDir + "/In_d" vasp.add_specie = "K", pseudoDir + "/K_sv" vasp.add_specie = "Mg", pseudoDir + "/Mg" vasp.add_specie = "Sn", pseudoDir + "/Sn_d" vasp.add_specie = "Li", pseudoDir + "/Li_sv" vasp.add_specie = "La", pseudoDir + "/La" # TODO Determine U las = ['Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb','Dy', 'Ho','Er','Tm','Yb','Lu'] for atom in structure: if atom.type in las: vasp.lmaxmix = 6 return(vasp)