From c2477bfd9956ce0c913708862646185318d1a343 Mon Sep 17 00:00:00 2001 From: rasmusthog Date: Wed, 12 Oct 2022 21:07:22 +0200 Subject: [PATCH 1/2] Update COOP-plotting function --- nafuma/dft/electrons.py | 18 +++++++++--------- nafuma/dft/io.py | 6 +++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/nafuma/dft/electrons.py b/nafuma/dft/electrons.py index 8ea1064..1fd3092 100644 --- a/nafuma/dft/electrons.py +++ b/nafuma/dft/electrons.py @@ -786,12 +786,10 @@ def prettify_dos_plot(fig, ax, options): -def plot_coop(plot_data, options): +def plot_coop(data, options): ''' interactions = list with number of interaction (index + 1 of interactions list from read_coop)''' - required_options = ['plot_kind', 'mode', 'up', 'down', 'collapse', 'interactions', 'flip_xy', 'fill', 'colours', 'palettes'] - default_options = { 'plot_kind': 'COOP', 'mode': 'individual', @@ -806,17 +804,17 @@ def plot_coop(plot_data, options): } - options = update_options(options=options, required_options=required_options, default_options=default_options) + options = aux.update_options(options=options, default_options=default_options) - fig, ax = prepare_plot(options=options) + fig, ax = btp.prepare_plot(options=options) - coopcar, coop_interactions = dft.io.read_coop(plot_data=plot_data, options=options) + coopcar, coop_interactions = dft.io.read_coop(data=data, options=options) if not options['colours']: - colour_cycle = generate_colours(palettes=options['palettes']) + colour_cycle = btp.generate_colours(palettes=options['palettes']) colours = [] for interaction in range(len(coop_interactions)): @@ -894,6 +892,8 @@ def plot_coop(plot_data, options): to_plot = ['mean_down'] + + # Plot all columns as decided above for j, column in enumerate(to_plot): if options['fill']: @@ -912,9 +912,9 @@ def plot_coop(plot_data, options): else: coopcar.plot(x='Energy', y=column, ax=ax, color=colour) - prettify_dos_plot(fig=fig, ax=ax, options=options) + fig, ax = btp.adjust_plot(fig=fig, ax=ax, options=options) - return coopcar + return coopcar, fig, ax diff --git a/nafuma/dft/io.py b/nafuma/dft/io.py index e09de45..23d7d41 100644 --- a/nafuma/dft/io.py +++ b/nafuma/dft/io.py @@ -94,7 +94,8 @@ def read_coop(data={}, options={}): required_options = ['collapse'] default_options = { - 'collapse': False + 'collapse': False, + 'adjust': None, } @@ -128,6 +129,9 @@ def read_coop(data={}, options={}): coopcar.columns = columns + if options['adjust']: + coopcar['Energy'] = coopcar['Energy'] - options['adjust'] + if options['collapse']: From 33012c60354c48cc34b5c03c54e866dfd1f20584 Mon Sep 17 00:00:00 2001 From: rasmusthog Date: Wed, 12 Oct 2022 21:07:44 +0200 Subject: [PATCH 2/2] Allow user to skip read-in of error columns --- nafuma/xrd/refinement.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/nafuma/xrd/refinement.py b/nafuma/xrd/refinement.py index 71b2da9..75ecee2 100644 --- a/nafuma/xrd/refinement.py +++ b/nafuma/xrd/refinement.py @@ -926,24 +926,44 @@ def refine(data: dict, options={}): -def read_results(path): +def read_results(path, options={}): + + default_options = { + 'errors': True + } + + options = aux.update_options(options=options, default_options=default_options) + results = pd.read_csv(path, delim_whitespace=True, index_col=0, header=None) - atoms = int((results.shape[1] - 24) / 10) + if options['errors']: + atoms = int((results.shape[1] - 24) / 10) - headers = [ + headers = [ 'r_wp', 'r_exp', 'r_p', 'r_p_dash', 'r_exp_dash', 'gof', 'vol', 'vol_err', 'mass', 'mass_err', 'wp', 'wp_err', 'a', 'a_err', 'b', 'b_err', 'c', 'c_err', 'alpha', 'alpha_err', 'beta', 'beta_err', 'gamma', 'gamma_err', - ] + ] + + else: + atoms = int((results.shape[1] - 15) / 5) + + headers = [ + 'r_wp', 'r_exp', 'r_p', 'r_p_dash', 'r_exp_dash', 'gof', + 'vol', 'mass', 'wp', + 'a', 'b', 'c', 'alpha', 'beta', 'gamma', + ] labels = ['x', 'y', 'z', 'occ', 'beq'] for i in range(atoms): for label in labels: headers.append(f'atom_{i+1}_{label}') - headers.append(f'atom_{i+1}_{label}_err') + + if options['errors']: + headers.append(f'atom_{i+1}_{label}_err') + results.columns = headers