diff --git a/calphy/postprocessing.py b/calphy/postprocessing.py index 71683c2..6d82e3d 100644 --- a/calphy/postprocessing.py +++ b/calphy/postprocessing.py @@ -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 @@ -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: @@ -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') @@ -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']: @@ -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 \ No newline at end of file