Skip to content

Commit

Permalink
use mkdir function
Browse files Browse the repository at this point in the history
  • Loading branch information
newville committed Sep 26, 2023
1 parent e47486f commit f991f59
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
14 changes: 6 additions & 8 deletions larch/wxxas/feffit_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from larch.math import index_of
from larch.fitting import group2params, param
from larch.utils.jsonutils import encode4js, decode4js
from larch.utils import fix_varname, fix_filename, gformat
from larch.utils import fix_varname, fix_filename, gformat, mkdir
from larch.io.export_modelresult import export_modelresult
from larch.xafs import feffit_report, feffpath

Expand Down Expand Up @@ -1543,14 +1543,12 @@ def update_start_values(self, params):
def autosave_script(self, text, fname='feffit_script.lar'):
"""autosave model result to user larch folder"""
confdir = os.path.join(site_config.user_larchdir, 'xas_viewer')
mkdir(confdir)
if not os.path.exists(confdir):
try:
os.makedirs(confdir)
except OSError:
title = "Cannot create XAS Viewer folder"
message = [f"Cannot create directory {confdir}"]
ExceptionPopup(self, title, message)
return
title = "Cannot create XAS Viewer folder"
message = [f"Cannot create directory {confdir}"]
ExceptionPopup(self, title, message)
return

if fname is None:
fname = 'feffit_script.lar'
Expand Down
16 changes: 7 additions & 9 deletions larch/wxxas/prepeak_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import lmfit.models as lm_models

from larch import Group, site_config
from larch.utils import uname, gformat
from larch.utils import uname, gformat, mkdir
from larch.math import index_of
from larch.io.export_modelresult import export_modelresult
from larch.io import save_groups, read_groups
Expand Down Expand Up @@ -721,7 +721,7 @@ def build_display(self):

fsopts = dict(digits=2, increment=0.1, min_val=-9999,
max_val=9999, size=(125, -1), with_pin=True)

ppeak_elo = self.add_floatspin('ppeak_elo', value=-13, **fsopts)
ppeak_ehi = self.add_floatspin('ppeak_ehi', value=-3, **fsopts)
ppeak_emin = self.add_floatspin('ppeak_emin', value=-20, **fsopts)
Expand Down Expand Up @@ -1551,14 +1551,12 @@ def update_start_values(self, params):
def autosave_modelresult(self, result, fname=None):
"""autosave model result to user larch folder"""
confdir = os.path.join(site_config.user_larchdir, 'xas_viewer')
mkdir(confdir)
if not os.path.exists(confdir):
try:
os.makedirs(confdir)
except:
title = "Cannot create XAS Viewer folder"
message = [f"Cannot create directory {confdir}"]
ExceptionPopup(self, title, message)
return
title = "Cannot create XAS Viewer folder"
message = [f"Cannot create directory {confdir}"]
ExceptionPopup(self, title, message)
return
if fname is None:
fname = 'autosave_peakfile.modl'
save_groups(os.path.join(confdir, fname), ['#peakfit 1.0', result])
10 changes: 4 additions & 6 deletions larch/xrd/amcsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

from .xrd_tools import generate_hkl, d_from_hkl, twth_from_q, E_from_lambda
from .cif2feff import cif2feffinp
from ..utils import isotime
from ..utils import isotime, mkdir
from ..utils.strutils import version_ge, bytes2str
from ..utils.physical_constants import TAU, ATOM_SYMS
from ..site_config import user_larchdir
Expand Down Expand Up @@ -637,11 +637,9 @@ def save_feffinp(self, absorber, edge=None, cluster_size=8.0, absorber_site=1,
else:
name = f'{absorber:s}_{edge:s}_{min_name:s}_CIF{self.ams_id:06d}'

bfolder = os.path.join(user_larchdir, 'feff6', name)
if not os.path.exists(bfolder):
os.makedirs(bfolder)

filename = os.path.join(bfolder, 'feff.inp')
ffolder = os.path.join(user_larchdir, 'feff', name)
mkdir(ffolder)
filename = os.path.join(ffolder, 'feff.inp')
with open(filename, 'w', encoding=sys.getdefaultencoding()) as fh:
fh.write(feff6text)
return filename
Expand Down

0 comments on commit f991f59

Please sign in to comment.