Skip to content

Commit

Permalink
wip: cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
maurov committed Oct 13, 2023
1 parent f2a418d commit 9ea47b1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
32 changes: 16 additions & 16 deletions larch/xrd/struct2xas.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,14 @@ def read_structure(self, file):
file = os.path.basename(self.file)
split_file = os.path.splitext(file)
self.file_name = split_file[0]
ext = split_file[1]
self.file_ext = split_file[1]
else:
self.file_name, self.file_ext = None, None
errmsg = f"{self.file} not found"
logger.error(errmsg)
raise FileNotFoundError(errmsg)

if ext == ".cif":
if self.file_ext == ".cif":
self.is_cif = True
self.xyz = None
self.molecules = None
Expand All @@ -247,7 +248,7 @@ def read_structure(self, file):
self.struct = Structure.from_file(self.file)
#self.struct = self.cif.get_structures()[0] #: NOT WORKING!
logger.debug("structure created from a CIF file")
elif ext == ".xyz":
elif self.file_ext == ".xyz":
self.is_xyz = True
self.cif = None
self.xyz = XYZ.from_file(self.file)
Expand All @@ -256,7 +257,7 @@ def read_structure(self, file):
self.nframes = len(self.molecules)
self.struct = xyz2struct(self.mol)
logger.debug("structure created from a XYZ file")
elif ext == ".mpjson":
elif self.file_ext == ".mpjson":
self.is_xyz = False
self.is_cif = True
self.molecules = None
Expand Down Expand Up @@ -310,9 +311,12 @@ def _get_atom_sites(self):
raise KeyError(errmsg)
try:
atom_lists.append(cf["_atom_site_symmetry_multiplicity"])
atom_lists.append(cf["_atom_site_Wyckoff_symbol"])
except KeyError:
atom_lists.append(["?"] * natoms)

try:
atom_lists.append(cf["_atom_site_Wyckoff_symbol"])
except KeyError:
atom_lists.append(["?"] * natoms)

atom_sites = []
Expand Down Expand Up @@ -793,6 +797,7 @@ def make_input_fdmnes(self, radius=7, parent_path=None,
"""
replacements = {}
replacements.update(**kwargs)
replacements["version"] = __version__

if template is None:
template = os.path.join(
Expand All @@ -810,6 +815,7 @@ def make_input_fdmnes(self, radius=7, parent_path=None,
absorber = ""
crystal = ""
occupancy = ""
comment = f"input structure: {self.file_name}{self.file_ext}\ncreation date: {_get_timestamp()}"

if self.is_cif:
try:
Expand Down Expand Up @@ -883,10 +889,6 @@ def make_input_fdmnes(self, radius=7, parent_path=None,
# absorber = f"{absorber}"
# replacements["absorber"] = f"Z_absorber\n{round(Element(elem).Z)}"

comment = (
f"cif file name: {self.file_name}\ncreation date:{_get_timestamp()}"
)

if self.is_xyz:
replacements["crystal"] = "molecule"

Expand All @@ -913,10 +915,6 @@ def make_input_fdmnes(self, radius=7, parent_path=None,
f"{lat.alpha:12.8f} {lat.beta:12.8f} {lat.gamma:12.8f}"
)

comment = (
f"xyz file name: {self.file_name}\ncreation date:{_get_timestamp()}"
)

replacements["sites"] = sites
replacements["radius"] = radius
replacements["method"] = method
Expand All @@ -942,7 +940,7 @@ def make_input_fdmnes(self, radius=7, parent_path=None,

def make_input_feff(self, radius=7, parent_path=None,
template=None, feff_comment="*", edge="K",
sig2=None, debye=None):
sig2=None, debye=None, **kwargs):
"""
Create a FEFF input from a template.
Expand Down Expand Up @@ -974,6 +972,9 @@ def make_input_feff(self, radius=7, parent_path=None,
None -> writes FEFF input to disk
directory structure: {parent_path}/feff/{self.file_name}/{self.abs_atom}/frame{self.frame}/site{self.abs_site}/
"""
replacements = {}
replacements.update(**kwargs)
replacements["version"] = __version__

if parent_path is None:
parent_path = self.folders['feff']
Expand All @@ -998,7 +999,6 @@ def make_input_feff(self, radius=7, parent_path=None,
use_debye = ""
temperature, debye_temperature = debye[0], debye[1]

replacements = {}
feff_comment = f"{feff_comment}"
edge = f"{edge}"
radius = f"{radius}"
Expand Down Expand Up @@ -1095,7 +1095,7 @@ def make_input_feff(self, radius=7, parent_path=None,
f"{at[i][0][0]:10.6f} {at[i][0][1]:10.6f} {at[i][0][2]:10.6f} {ipot[choice]} {choice:>5} {at[i][3]:10.5f} *{at[i][4]}"
)

title = f"TITLE {self.file_name}\nTITLE {_get_timestamp()}\nTITLE site {self.abs_site}"
title = f"TITLE {self.file_name}{self.file_ext}\nTITLE {_get_timestamp()}\nTITLE site {self.abs_site}"

replacements["feff_comment"] = feff_comment
replacements["edge"] = edge
Expand Down
3 changes: 1 addition & 2 deletions larch/xrd/templates/fdmnes.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
! FDMNES input file generated by Struct2XAS
! FDMNES input file generated by Struct2XAS version {version}

header

comment
{comment}

filout

job

range
Expand Down
2 changes: 1 addition & 1 deletion larch/xrd/templates/feff_exafs.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* FEFF8* input file generated by Struct2XAS
* FEFF8* input file generated by Struct2XAS version {version}

{title}

Expand Down

0 comments on commit 9ea47b1

Please sign in to comment.