Skip to content

Commit

Permalink
Merge pull request #153 from ICAMS/process_fixes
Browse files Browse the repository at this point in the history
Process fixes
  • Loading branch information
srmnitc authored Sep 13, 2024
2 parents 057fe3b + bd281e8 commit 870602f
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions calphy/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ def read_report(folder):
data = yaml.safe_load(fin)
return data

def _extract_error(errfile):
error_code = None
if os.path.exists(errfile):
with open(errfile, 'r') as fin:
for line in fin:
if 'calphy.errors' in line:
break
try:
error_code = line.split(':')[0].split('.')[-1]
except:
pass
return error_code

def gather_results(mainfolder):
"""
Gather results from all subfolders in a given folder into a Pandas DataFrame
Expand Down Expand Up @@ -52,6 +65,8 @@ def gather_results(mainfolder):
datadict['free_energy'] = []
datadict['reference_phase'] = []
datadict['error_code'] = []
datadict['composition'] = []
datadict['calculation'] = []

folders = next(os.walk(mainfolder))[1]
for folder in folders:
Expand All @@ -77,6 +92,8 @@ def gather_results(mainfolder):
datadict['temperature'].append(inp['temperature'])
datadict['pressure'].append(inp['pressure'])
datadict['reference_phase'].append(inp['reference_phase'])
datadict['composition'].append(None)
datadict['calculation'].append(folder)

#check output file
outfile = os.path.join(mainfolder, folder, 'report.yaml')
Expand All @@ -88,16 +105,7 @@ def gather_results(mainfolder):
datadict['free_energy'].append(np.NaN)
#check if error file is found
errfile = os.path.join(os.getcwd(), mainfolder, folder+'.sub.err')
if os.path.exists(errfile):
with open(errfile, 'r') as fin:
for line in fin:
if 'calphy.errors' in line:
break
try:
error_code = line.split(':')[0].split('.')[-1]
datadict['error_code'][-1] = error_code
except:
pass
datadict['error_code'][-1] = _extract_error(errfile)
continue;

if mode in ['fe', 'alchemy', 'composition_scaling']:
Expand All @@ -108,13 +116,33 @@ def gather_results(mainfolder):
out = yaml.safe_load(fin)

datadict['free_energy'].append(out['results']['free_energy'])


#add normal composition
el_arr = np.array(out['input']['element'].split(' ')).astype(str)
comp_arr = np.array(out['input']['concentration'].split(' ')).astype(float)
composition = {x:y for x,y in zip(el_arr, comp_arr)}
datadict['composition'][-1] = composition

if mode == 'composition_scaling':
#we need to update composition
compdict = inp['composition_scaling']['output_chemical_composition']
maxatoms = np.sum([val for key, val in compdict.items()])
for key, val in compdict.items():
compdict[key] = val/maxatoms
datadict['composition'][-1] = compdict

#parse extra info
if mode in ['ts', 'tscale']:
datafile = os.path.join(os.getcwd(), folder, 'temperature_sweep.dat')
t, f = np.loadtxt(datafile, unpack=True, usecols=(0,1))
datadict['temperature'][-1] = t
datadict['free_energy'][-1] = f

datafile = os.path.join(os.getcwd(), mainfolder, folder, 'temperature_sweep.dat')
if os.path.exists(datafile):
datadict['status'].append('True')
t, f = np.loadtxt(datafile, unpack=True, usecols=(0,1))
datadict['temperature'][-1] = t
datadict['free_energy'][-1] = f
else:
datadict['status'].append('False')
errfile = os.path.join(os.getcwd(), mainfolder, folder+'.sub.err')
datadict['error_code'][-1] = _extract_error(errfile)

df = pd.DataFrame(data=datadict)
return df

0 comments on commit 870602f

Please sign in to comment.