Skip to content

Commit

Permalink
Cleanup feff.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Jul 24, 2020
1 parent e23301f commit ef37cd2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
32 changes: 13 additions & 19 deletions pymatgen/io/feff/inputs.py
Expand Up @@ -243,8 +243,8 @@ def from_string(header_str):
h = Header(struct, source, comment2)

return h
else:
return "Header not generated by pymatgen, cannot return header object"

raise ValueError("Header not generated by pymatgen, cannot return header object")

def __str__(self):
"""
Expand Down Expand Up @@ -356,7 +356,7 @@ def atoms_string_from_file(filename):
find_atoms = line.find("ATOMS")
if find_atoms >= 0:
coords = 1
if coords == 1 and not ("END" in line):
if coords == 1 and "END" not in line:
atoms_str.append(line.replace("\r", ""))

return ''.join(atoms_str)
Expand Down Expand Up @@ -524,8 +524,8 @@ def get_string(self, sort_keys=False, pretty=False):
lines.append([k, self._stringify_val(self[k])])
if pretty:
return tabulate(lines)
else:
return str_delimited(lines, None, " ")

return str_delimited(lines, None, " ")

@staticmethod
def _stringify_val(val):
Expand All @@ -534,8 +534,8 @@ def _stringify_val(val):
"""
if isinstance(val, list):
return " ".join([str(i) for i in val])
else:
return str(val)

return str(val)

def __str__(self):
return self.get_string()
Expand Down Expand Up @@ -580,7 +580,7 @@ def from_file(filename="feff.inp"):
else:
params[key] = val
if ieels >= 0:
if i >= ieels and i <= ieels_max:
if ieels <= i <= ieels_max:
if i == ieels + 1:
if int(line.split()[1]) == 1:
ieels_max -= 1
Expand Down Expand Up @@ -618,8 +618,7 @@ def proc_val(key, val):
def smart_int_or_float(numstr):
if numstr.find(".") != -1 or numstr.lower().find("e") != -1:
return float(numstr)
else:
return int(numstr)
return int(numstr)

try:
if key.lower() == 'cif':
Expand All @@ -641,10 +640,7 @@ def smart_int_or_float(numstr):
if key in boolean_type_keys:
m = re.search(r"^\W+([TtFf])", val)
if m:
if m.group(1) == "T" or m.group(1) == "t":
return True
else:
return False
return m.group(1) in ["T", "t"]
raise ValueError(key + " should be a boolean type!")

if key in float_type_keys:
Expand Down Expand Up @@ -696,8 +692,7 @@ def __add__(self, other):
for k, v in other.items():
if k in self and v != self[k]:
raise ValueError("Tags have conflicting values!")
else:
params[k] = v
params[k] = v
return Tags(params)


Expand Down Expand Up @@ -925,7 +920,6 @@ def get_absorbing_atom_symbol_index(absorbing_atom, structure):
"""
if isinstance(absorbing_atom, str):
return absorbing_atom, structure.indices_from_symbol(absorbing_atom)[0]
elif isinstance(absorbing_atom, int):
if isinstance(absorbing_atom, int):
return str(structure[absorbing_atom].specie), absorbing_atom
else:
raise ValueError("absorbing_atom must be either specie symbol or site index")
raise ValueError("absorbing_atom must be either specie symbol or site index")
2 changes: 1 addition & 1 deletion pymatgen/io/feff/outputs.py
Expand Up @@ -361,7 +361,7 @@ def e_fermi(self):
"""
Returns the fermi level in eV.
"""
return (self.energies[0] - self.relative_energies[0])
return self.energies[0] - self.relative_energies[0]

@property
def source(self):
Expand Down
14 changes: 8 additions & 6 deletions pymatgen/io/feff/sets.py
Expand Up @@ -10,18 +10,18 @@
runs.
"""

import sys
import os
import abc
from copy import deepcopy
import logging
import os
import sys
from copy import deepcopy

from monty.serialization import loadfn
import numpy as np
from monty.json import MSONable
from monty.os.path import zpath
from monty.serialization import loadfn

from pymatgen.io.feff.inputs import Atoms, Tags, Potential, Header
import numpy as np

__author__ = "Kiran Mathew"
__credits__ = "Alan Dozier, Anubhav Jain, Shyue Ping Ong"
Expand Down Expand Up @@ -168,7 +168,7 @@ def __init__(self, absorbing_atom, structure, radius, config_dict,
del self.config_dict["_del"]
# k-space feff only for small systems. The hardcoded system size in
# feff is around 14 atoms.
self.small_system = True if (len(self.structure) < 14 and 'EXAFS' not in self.config_dict) else False
self.small_system = len(self.structure) < 14 and 'EXAFS' not in self.config_dict

def header(self, source='', comment=''):
"""
Expand Down Expand Up @@ -300,6 +300,8 @@ def from_directory(input_dir):
config_dict=CONFIG, edge=sub_d["parameters"]["EDGE"],
nkpts=1000, user_tag_settings=sub_d["parameters"])

raise ValueError("Bad input directory.")


class MPXANESSet(FEFFDictSet):
"""
Expand Down

0 comments on commit ef37cd2

Please sign in to comment.