def test_as_dict_and_from_dict(self): file_name = os.path.join(test_dir, 'HEADER') header = Header.from_file(file_name) d = header.as_dict() header2 = Header.from_dict(d) self.assertEqual(str(header), str(header2), "Header failed to and from dict test")
def from_dict(cls, xdict): """ Returns Xmu object from dictionary """ header = Header.from_dict(xdict['HEADER']) return cls(header, xdict['TAGS'], xdict['c_atom'], np.array(xdict['xmu']))
def test_get_string(self): cif_file = os.path.join(test_dir, 'CoO19128.cif') h = Header.from_cif_file(cif_file) head = str(h) self.assertEqual(head.splitlines()[3].split()[-1], HeaderTest.header_string.splitlines()[3].split()[-1], "Failed to generate HEADER from structure")
def test_get_string(self): header = Header.from_string(HeaderTest.header_string) struc = header.struct central_atom = 'O' a = FeffAtoms(struc, central_atom) atoms = a.get_string() self.assertEqual(atoms.splitlines()[3].split()[4], central_atom, "failed to create ATOMS string")
def test_init(self): filepath = os.path.join(test_dir, 'HEADER') header = Header.header_string_from_file(filepath) h = header.splitlines() hs = HeaderTest.header_string.splitlines() for i, line in enumerate(h): self.assertEqual(line, hs[i]) self.assertEqual(HeaderTest.header_string.splitlines(), header.splitlines(), "Failed to read HEADER file")
def test_as_dict_and_from_dict(self): file_name = os.path.join(test_dir, 'HEADER') header = Header.from_file(file_name) struct = header.struct atoms = FeffAtoms(struct, 'O') d = atoms.as_dict() atoms2 = FeffAtoms.from_dict(d) self.assertEqual(str(atoms), str(atoms2), "FeffAtoms failed to and from dict test")
def test_as_dict_and_from_dict(self): file_name = os.path.join(test_dir, 'HEADER') header = Header.from_file(file_name) struct = header.struct pot = FeffPot(struct, 'O') d = pot.as_dict() pot2 = FeffPot.from_dict(d) self.assertEqual(str(pot), str(pot2), "FeffPot to and from dict does not match")
def test_as_dict_and_from_dict(self): file_name = os.path.join(test_dir, 'HEADER') header = Header.from_file(file_name) struct = header.struct pot = FeffPot(struct, 'O') d=pot.as_dict() pot2 = FeffPot.from_dict(d) self.assertEqual(str(pot), str(pot2), "FeffPot to and from dict does not match")
def get_header(self, structure, source='', comment=''): """ Creates header string from structure object Args: structure: A pymatgen structure object source: Source identifier used to create structure, can be defined however user wants to organize structures, calculations, etc. example would be Materials Project material ID number. comment: comment to include in header Returns: Header object to be used in feff.inp file from a pymatgen structure """ return Header(structure, source, comment)
def from_file(xmu_dat_file="xmu.dat", feff_inp_file="feff.inp"): """ Get Xmu from file. Args: xmu_dat_file (str): filename and path for xmu.dat feff_inp_file (str): filename and path of feff.inp input file Returns: Xmu object """ data = np.loadtxt(xmu_dat_file) header = Header.from_file(feff_inp_file) parameters = Tags.from_file(feff_inp_file) pots = Potential.pot_string_from_file(feff_inp_file) absorbing_atom = pots.splitlines()[1].split()[2] return Xmu(header, parameters, absorbing_atom, data)
def from_file(filename="xmu.dat", input_filename="feff.inp"): """ Get Xmu from file. Args: filename: filename and path for xmu.dat input_filename: filename and path of feff.inp input file Returns: Xmu object """ data = np.loadtxt(filename) header = Header.from_file(input_filename) parameters = Tags.from_file(input_filename) pots = Potential.pot_string_from_file(input_filename) central_atom = pots.splitlines()[1].split()[2] return Xmu(header, parameters, central_atom, data)
def from_file(xmu_dat_file="xmu.dat", feff_inp_file="feff.inp"): """ Get Xmu from file. Args: xmu_dat_file (str): filename and path for xmu.dat feff_inp_file (str): filename and path of feff.inp input file Returns: Xmu object """ data = np.loadtxt(xmu_dat_file) header = Header.from_file(feff_inp_file) parameters = Tags.from_file(feff_inp_file) pots = Potential.pot_string_from_file(feff_inp_file) # site index (Note: in feff it starts from 1) if "RECIPROCAL" in parameters: absorbing_atom = parameters["TARGET"] # species symbol else: absorbing_atom = pots.splitlines()[1].split()[2] return Xmu(header, parameters, absorbing_atom, data)
def from_file(xmu_dat_file="xmu.dat", feff_inp_file="feff.inp"): """ Get Xmu from file. Args: xmu_dat_file (str): filename and path for xmu.dat feff_inp_file (str): filename and path of feff.inp input file Returns: Xmu object """ data = np.loadtxt(xmu_dat_file) header = Header.from_file(feff_inp_file) parameters = Tags.from_file(feff_inp_file) pots = Potential.pot_string_from_file(feff_inp_file) # site index (Note: in feff it starts from 1) if "RECIPROCAL" in parameters: absorbing_atom = parameters["TARGET"] # species symbol else: absorbing_atom = pots.splitlines()[3].split()[2] return Xmu(header, parameters, absorbing_atom, data)
def from_file(feff_inp_file='feff.inp', ldos_file='ldos'): """" Creates LDos object from raw Feff ldos files by by assuming they are numbered consecutively, i.e. ldos01.dat ldos02.dat... Args: feff_inp_file (str): input file of run to obtain structure ldos_file (str): output ldos file of run to obtain dos info, etc. """ header_str = Header.header_string_from_file(feff_inp_file) header = Header.from_string(header_str) structure = header.struct nsites = structure.num_sites pot_string = Potential.pot_string_from_file(feff_inp_file) dicts = Potential.pot_dict_from_string(pot_string) pot_dict = dicts[0] with zopen(ldos_file + "00.dat", "r") as fobject: f = fobject.readlines() efermi = float(f[0].split()[4]) dos_energies = [] ldos = {} for i in range(1, len(pot_dict) + 1): if len(str(i)) == 1: ldos[i] = np.loadtxt("{}0{}.dat".format(ldos_file, i)) else: ldos[i] = np.loadtxt("{}{}.dat".format(ldos_file, i)) for i in range(0, len(ldos[1])): dos_energies.append(ldos[1][i][0]) all_pdos = [] vorb = {"s": Orbital.s, "p": Orbital.py, "d": Orbital.dxy, "f": Orbital.f0} forb = {"s": 0, "p": 1, "d": 2, "f": 3} dlength = len(ldos[1]) for i in range(nsites): pot_index = pot_dict[structure.species[i].symbol] all_pdos.append(defaultdict(dict)) for k, v in vorb.items(): density = [ldos[pot_index][j][forb[k] + 1] for j in range(dlength)] updos = density downdos = None if downdos: all_pdos[-1][v] = {Spin.up: updos, Spin.down: downdos} else: all_pdos[-1][v] = {Spin.up: updos} pdos = all_pdos vorb2 = {0: Orbital.s, 1: Orbital.py, 2: Orbital.dxy, 3: Orbital.f0} pdoss = {structure[i]: {v: pdos[i][v] for v in vorb2.values()} for i in range(len(pdos))} forb = {"s": 0, "p": 1, "d": 2, "f": 3} tdos = [0] * dlength for i in range(nsites): pot_index = pot_dict[structure.species[i].symbol] for v in forb.values(): density = [ldos[pot_index][j][v + 1] for j in range(dlength)] for j in range(dlength): tdos[j] = tdos[j] + density[j] tdos = {Spin.up: tdos} dos = Dos(efermi, dos_energies, tdos) complete_dos = CompleteDos(structure, dos, pdoss) charge_transfer = LDos.charge_transfer_from_file(feff_inp_file, ldos_file) return LDos(complete_dos, charge_transfer)
def from_file(feff_inp_file="feff.inp", ldos_file="ldos"): """ Creates LDos object from raw Feff ldos files by by assuming they are numbered consecutively, i.e. ldos01.dat ldos02.dat... Args: feff_inp_file (str): input file of run to obtain structure ldos_file (str): output ldos file of run to obtain dos info, etc. """ header_str = Header.header_string_from_file(feff_inp_file) header = Header.from_string(header_str) structure = header.struct nsites = structure.num_sites parameters = Tags.from_file(feff_inp_file) if "RECIPROCAL" in parameters: pot_dict = {} pot_readstart = re.compile(".*iz.*lmaxsc.*xnatph.*xion.*folp.*") pot_readend = re.compile(".*ExternalPot.*switch.*") pot_inp = re.sub(r"feff.inp", r"pot.inp", feff_inp_file) dos_index = 1 begin = 0 with zopen(pot_inp, "r") as potfile: for line in potfile: if len(pot_readend.findall(line)) > 0: break if begin == 1: begin += 1 continue if begin == 2: z_number = int(line.strip().split()[0]) ele_name = Element.from_Z(z_number).name if ele_name not in pot_dict: pot_dict[ele_name] = dos_index else: pot_dict[ele_name] = min(dos_index, pot_dict[ele_name]) dos_index += 1 if len(pot_readstart.findall(line)) > 0: begin = 1 else: pot_string = Potential.pot_string_from_file(feff_inp_file) dicts = Potential.pot_dict_from_string(pot_string) pot_dict = dicts[0] with zopen(ldos_file + "00.dat", "r") as fobject: f = fobject.readlines() efermi = float(f[0].split()[4]) dos_energies = [] ldos = {} for i in range(1, len(pot_dict) + 1): if len(str(i)) == 1: ldos[i] = np.loadtxt(f"{ldos_file}0{i}.dat") else: ldos[i] = np.loadtxt(f"{ldos_file}{i}.dat") for i in range(0, len(ldos[1])): dos_energies.append(ldos[1][i][0]) all_pdos = [] vorb = { "s": Orbital.s, "p": Orbital.py, "d": Orbital.dxy, "f": Orbital.f0 } forb = {"s": 0, "p": 1, "d": 2, "f": 3} dlength = len(ldos[1]) for i in range(nsites): pot_index = pot_dict[structure.species[i].symbol] all_pdos.append(defaultdict(dict)) for k, v in vorb.items(): density = [ ldos[pot_index][j][forb[k] + 1] for j in range(dlength) ] updos = density downdos = None if downdos: all_pdos[-1][v] = {Spin.up: updos, Spin.down: downdos} else: all_pdos[-1][v] = {Spin.up: updos} pdos = all_pdos vorb2 = {0: Orbital.s, 1: Orbital.py, 2: Orbital.dxy, 3: Orbital.f0} pdoss = { structure[i]: {v: pdos[i][v] for v in vorb2.values()} for i in range(len(pdos)) } forb = {"s": 0, "p": 1, "d": 2, "f": 3} tdos = [0] * dlength for i in range(nsites): pot_index = pot_dict[structure.species[i].symbol] for v in forb.values(): density = [ldos[pot_index][j][v + 1] for j in range(dlength)] for j in range(dlength): tdos[j] = tdos[j] + density[j] tdos = {Spin.up: tdos} dos = Dos(efermi, dos_energies, tdos) complete_dos = CompleteDos(structure, dos, pdoss) charge_transfer = LDos.charge_transfer_from_file( feff_inp_file, ldos_file) return LDos(complete_dos, charge_transfer)
def test_from_string(self): header = Header.from_string(HeaderTest.header_string) self.assertEqual(header.struct.composition.reduced_formula, "CoO", "Failed to generate structure from HEADER string")
def from_file(feff_inp_file='feff.inp', ldos_file='ldos'): """" Creates LDos object from raw Feff ldos files by by assuming they are numbered consecutively, i.e. ldos01.dat ldos02.dat... Args: feff_inp_file (str): input file of run to obtain structure ldos_file (str): output ldos file of run to obtain dos info, etc. """ header_str = Header.header_string_from_file(feff_inp_file) header = Header.from_string(header_str) structure = header.struct nsites = structure.num_sites pot_string = Potential.pot_string_from_file(feff_inp_file) dicts = Potential.pot_dict_from_string(pot_string) pot_dict = dicts[0] with zopen(ldos_file + "00.dat", "r") as fobject: f = fobject.readlines() efermi = float(f[0].split()[4]) dos_energies = [] ldos = {} for i in range(1, len(pot_dict) + 1): if len(str(i)) == 1: ldos[i] = np.loadtxt("{}0{}.dat".format(ldos_file, i)) else: ldos[i] = np.loadtxt("{}{}.dat".format(ldos_file, i)) for i in range(0, len(ldos[1])): dos_energies.append(ldos[1][i][0]) all_pdos = [] vorb = { "s": Orbital.s, "p": Orbital.py, "d": Orbital.dxy, "f": Orbital.f0 } forb = {"s": 0, "p": 1, "d": 2, "f": 3} dlength = len(ldos[1]) for i in range(nsites): pot_index = pot_dict[structure.species[i].symbol] all_pdos.append(defaultdict(dict)) for k, v in vorb.items(): density = [ ldos[pot_index][j][forb[k] + 1] for j in range(dlength) ] updos = density downdos = None if downdos: all_pdos[-1][v] = {Spin.up: updos, Spin.down: downdos} else: all_pdos[-1][v] = {Spin.up: updos} pdos = all_pdos vorb2 = {0: Orbital.s, 1: Orbital.py, 2: Orbital.dxy, 3: Orbital.f0} pdoss = { structure[i]: {v: pdos[i][v] for v in vorb2.values()} for i in range(len(pdos)) } forb = {"s": 0, "p": 1, "d": 2, "f": 3} tdos = [0] * dlength for i in range(nsites): pot_index = pot_dict[structure.species[i].symbol] for v in forb.values(): density = [ldos[pot_index][j][v + 1] for j in range(dlength)] for j in range(dlength): tdos[j] = tdos[j] + density[j] tdos = {Spin.up: tdos} dos = Dos(efermi, dos_energies, tdos) complete_dos = CompleteDos(structure, dos, pdoss) charge_transfer = LDos.charge_transfer_from_file( feff_inp_file, ldos_file) return LDos(complete_dos, charge_transfer)