-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix minor issues that I noticed when going through the QE section * Remove the Fermi level align with zero example, which uses bands.show_mpl(), but this doesn't work from the AiiDAlab machines since we don't have X forwarding. * Replace the query demo script by the one from the intro week, which shows off the high-throughput elements more.
- Loading branch information
Showing
3 changed files
with
117 additions
and
56 deletions.
There are no files selected for viewing
Binary file modified
BIN
+91.3 KB
(270%)
docs/pages/2020_BIGMAP/sections/include/images/demo_query.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 81 additions & 31 deletions
112
docs/pages/2020_BIGMAP/sections/include/snippets/demo_query.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,94 @@ | ||
from aiida.orm import Group | ||
from aiida.plugins import DataFactory, CalculationFactory | ||
from IPython.display import Image | ||
from datetime import datetime, timedelta | ||
import numpy as np | ||
from matplotlib import gridspec, pyplot as plt | ||
|
||
PwCalculation = CalculationFactory('quantumespresso.pw') | ||
StructureData = DataFactory('structure') | ||
KpointsData = DataFactory('array.kpoints') | ||
Dict = DataFactory('dict') | ||
UpfData = DataFactory('upf') | ||
|
||
import matplotlib.pyplot as plt | ||
def plot_results(query_res): | ||
""" | ||
:param query_res: The result of an instance of the QueryBuilder | ||
""" | ||
smearing_unit_set,magnetization_unit_set,pseudo_family_set = set(), set(), set() | ||
# Storing results: | ||
results_dict = {} | ||
for pseudo_family, formula, smearing, smearing_units, mag, mag_units in query_res: | ||
if formula not in results_dict: | ||
results_dict[formula] = {} | ||
# Storing the results: | ||
results_dict[formula][pseudo_family] = (smearing, mag) | ||
# Adding to the unit set: | ||
smearing_unit_set.add(smearing_units) | ||
magnetization_unit_set.add(mag_units) | ||
pseudo_family_set.add(pseudo_family) | ||
|
||
qb = QueryBuilder().append( | ||
Group, filters={'label': {'like': 'tutorial_%'}}, tag='group', | ||
project='label' | ||
).append( | ||
PwCalculation, with_group='group', tag='pw' | ||
).append( | ||
StructureData, with_outgoing='pw', | ||
project='extras.formula' | ||
).append( | ||
Dict, with_incoming='pw', filters={'attributes.absolute_magnetization': {'>': 0.0}}, | ||
project='attributes.absolute_magnetization' | ||
) | ||
# Sorting by formula: | ||
sorted_results = sorted(results_dict.items()) | ||
formula_list = next(zip(*sorted_results)) | ||
nr_of_results = len(formula_list) | ||
|
||
results_dict = dict() | ||
formulas = set() | ||
# Checks that I have not more than 3 pseudo families. | ||
# If more are needed, define more colors | ||
#pseudo_list = list(pseudo_family_set) | ||
if len(pseudo_family_set) > 3: | ||
raise Exception('I was expecting 3 or less pseudo families') | ||
|
||
for group_label, formula, abs_magnetization in qb.iterall(): | ||
functional = group_label.split('_')[1].upper() | ||
results_dict.setdefault(functional, {}) | ||
results_dict[functional][formula] = abs_magnetization | ||
formulas.add(formula) | ||
colors = ['b', 'r', 'g'] | ||
|
||
formulas = list(formulas) | ||
# Plotting: | ||
plt.clf() | ||
fig=plt.figure(figsize=(16, 9), facecolor='w', edgecolor=None) | ||
gs = gridspec.GridSpec(2,1, hspace=0.01, left=0.1, right=0.94) | ||
|
||
for functional, results in results_dict.items(): | ||
# Defining barwidth | ||
barwidth = 1. / (len(pseudo_family_set)+1) | ||
offset = [-0.5+(0.5+n)*barwidth for n in range(len(pseudo_family_set))] | ||
# Axing labels with units: | ||
yaxis = ("Smearing energy [{}]".format(smearing_unit_set.pop()), | ||
"Total magnetization [{}]".format(magnetization_unit_set.pop())) | ||
# If more than one unit was specified, I will exit: | ||
if smearing_unit_set: | ||
raise ValueError('Found different units for smearing') | ||
if magnetization_unit_set: | ||
raise ValueError('Found different units for magnetization') | ||
|
||
abs_magnetizations = [results[formula] for formula in formulas] | ||
# Making two plots, the top one for the smearing, the bottom one for the magnetization | ||
for index in range(2): | ||
ax=fig.add_subplot(gs[index]) | ||
for i,pseudo_family in enumerate(pseudo_family_set): | ||
X = np.arange(nr_of_results)+offset[i] | ||
Y = np.array([thisres[1][pseudo_family][index] for thisres in sorted_results]) | ||
ax.bar(X, Y, width=0.2, facecolor=colors[i], edgecolor=colors[i], label=pseudo_family) | ||
ax.set_ylabel(yaxis[index], fontsize=14, labelpad=15*index+5) | ||
ax.set_xlim(-0.5, nr_of_results-0.5) | ||
ax.set_xticks(np.arange(nr_of_results)) | ||
if index == 0: | ||
plt.setp(ax.get_yticklabels()[0], visible=False) | ||
ax.xaxis.tick_top() | ||
ax.legend(loc=3, prop={'size': 18}) | ||
else: | ||
plt.setp(ax.get_yticklabels()[-1], visible=False) | ||
for i in range(0, nr_of_results, 2): | ||
ax.axvspan(i-0.5, i+0.5, facecolor='y', alpha=0.2) | ||
ax.set_xticklabels(list(formula_list),rotation=90, size=14, ha='center') | ||
plt.savefig('demo_query.pdf') | ||
|
||
plt.plot(abs_magnetizations, 's') | ||
plt.xticks(range(len(formulas)), formulas, rotation=90) | ||
plt.ylabel('Magnetization [Bohrmag / cell]') | ||
|
||
plt.legend(results_dict.keys()) | ||
plt.tight_layout() | ||
plt.savefig('demo_query.pdf') | ||
qb = QueryBuilder().append( | ||
Group, filters={'label':{'like':'tutorial_%'}}, project='label', tag='group' | ||
).append( | ||
PwCalculation, tag='calculation', with_group='group' | ||
).append( | ||
StructureData, project=['extras.formula'], tag='structure', with_outgoing='calculation' | ||
).append( | ||
Dict, tag='results', | ||
project=['attributes.energy_smearing', 'attributes.energy_smearing_units', | ||
'attributes.total_magnetization', 'attributes.total_magnetization_units', | ||
], with_incoming='calculation' | ||
) | ||
|
||
plot_results(qb.all()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters