def find_jobs_torun(self, max_njobs): """ Find entries whose results have not been yet calculated. Args: select_formulas: """ jobs, got = [], 0 for struct_type, formula, data in self.iter_struct_formula_data(): if got == max_njobs: break if data in ("scheduled", "failed"): continue if data is None: symbols = list(set(species_from_formula(formula))) pseudos = self.table.pseudos_with_symbols(symbols) job = dict2namedtuple(formula=formula, struct_type=struct_type, pseudos=pseudos) self[struct_type][formula] = "scheduled" jobs.append(job) got += 1 # Update the database. if jobs: self.json_write() return jobs
def plot_errors_for_elements(self, ax=None, **kwargs): """ Plot the relative errors associated to the chemical elements. """ dict_list = [] for idx, row in self.iterrows(): rerr = 100 * (row["this"] - row["ae"]) / row["ae"] for symbol in set(species_from_formula(row.formula)): dict_list.append(dict( element=symbol, rerr=rerr, formula=row.formula, struct_type=row.struct_type, )) frame = DataFrame(dict_list) order = sort_symbols_by_Z(set(frame["element"])) #print_frame(frame) import seaborn as sns ax, fig, plt = get_ax_fig_plt(ax=ax) # Draw violinplot #sns.violinplot(x="element", y="rerr", order=order, data=frame, ax=ax, orient="v") # Box plot ax = sns.boxplot(x="element", y="rerr", data=frame, ax=ax, order=order, whis=np.inf, color="c") # Add in points to show each observation sns.stripplot(x="element", y="rerr", data=frame, ax=ax, order=order, jitter=True, size=5, color=".3", linewidth=0) sns.despine(left=True) ax.set_ylabel("Relative error %") ax.grid(True) return fig
def select_bad_guys(self, reltol=0.4): new = self[abs(100 * (self["this"] - self["ae"]) / self["ae"]) > reltol].copy() new["rel_err"] = 100 * (self["this"] - self["ae"]) / self["ae"] new.__class__ = self.__class__ count = Counter() for idx, row in new.iterrows(): for symbol in set(species_from_formula(row.formula)): count[symbol] += 1 return new, count
def plot_errors_for_elements(self, ax=None, **kwargs): """ Plot the relative errors associated to the chemical elements. """ dict_list = [] for idx, row in self.iterrows(): rerr = 100 * (row["this"] - row["ae"]) / row["ae"] for symbol in set(species_from_formula(row.formula)): dict_list.append(dict( element=symbol, rerr=rerr, formula=row.formula, struct_type=row.struct_type, )) frame = DataFrame(dict_list) order = sort_symbols_by_Z(set(frame["element"])) #print_frame(frame) import seaborn as sns ax, fig, plt = get_ax_fig_plt(ax=ax) # Draw violinplot #sns.violinplot(x="element", y="rerr", order=order, data=frame, ax=ax, orient="v") # Box plot ax = sns.boxplot(x="element", y="rerr", data=frame, ax=ax, order=order, whis=np.inf, color="c") # Add in points to show each observation sns.stripplot(x="element", y="rerr", data=frame, ax=ax, order=order, hue='struct_type', # jitter=True, size=5, color=".3", linewidth=0) jitter=0, size=4, color=".3", linewidth=0, palette=sns.color_palette("muted")) sns.despine(left=True) ax.set_ylabel("Relative error %") labels = ax.get_xticklabels() ticks = ax.get_xticks() ticks1 = range(min(ticks), max(ticks)+1, 2) ticks2 = range(min(ticks) + 1, max(ticks)+1, 2) labels1 = [labels[i].get_text() for i in ticks1] labels2 = [labels[i].get_text() for i in ticks2] # ax.tick_params(which='both', direction='out') #ax.set_ylim(-1, 1) ax.set_xticks(ticks1) ax.set_xticklabels(labels1, rotation=90) ax2 = ax.twiny() ax2.set_zorder(-1) ax2.set_xticks(ticks2) ax2.set_xticklabels(labels2, rotation=90) ax2.set_xlim(ax.get_xlim()) ax.grid(True) return fig
def select_symbol(self, symbol): """ Extract the rows whose formula contain the given element symbol. Return new `GbrvCompoundDataFrame`. """ rows = [] for idx, row in self.iterrows(): if symbol not in species_from_formula(row.formula): continue rows.append(row) return self.__class__(rows)
def select_bad_guys(self, reltol=0.4, struct_type=None): """Return new frame with the entries whose relative errors is > reltol.""" new = self[abs(100 * (self["this"] - self["ae"]) / self["ae"]) > reltol].copy() new["rel_err"] = 100 * (self["this"] - self["ae"]) / self["ae"] if struct_type is not None: new = new[new.struct_type == struct_type] new.__class__ = self.__class__ count = Counter() for idx, row in new.iterrows(): for symbol in set(species_from_formula(row.formula)): count[symbol] += 1 new.symbol_counter = count return new
def plot_errors_for_elements(self, ax=None, **kwargs): """ Plot the relative errors associated to the chemical elements. """ dict_list = [] for idx, row in self.iterrows(): rerr = 100 * (row["this"] - row["ae"]) / row["ae"] for symbol in set(species_from_formula(row.formula)): dict_list.append( dict( element=symbol, rerr=rerr, formula=row.formula, struct_type=row.struct_type, )) frame = DataFrame(dict_list) order = sort_symbols_by_Z(set(frame["element"])) #print_frame(frame) import seaborn as sns ax, fig, plt = get_ax_fig_plt(ax=ax) # Draw violinplot #sns.violinplot(x="element", y="rerr", order=order, data=frame, ax=ax, orient="v") # Box plot ax = sns.boxplot(x="element", y="rerr", data=frame, ax=ax, order=order, whis=np.inf, color="c") # Add in points to show each observation sns.stripplot( x="element", y="rerr", data=frame, ax=ax, order=order, hue='struct_type', # jitter=True, size=5, color=".3", linewidth=0) jitter=0, size=4, color=".3", linewidth=0, palette=sns.color_palette("muted")) sns.despine(left=True) ax.set_ylabel("Relative error %") labels = ax.get_xticklabels() ticks = ax.get_xticks() ticks1 = range(min(ticks), max(ticks) + 1, 2) ticks2 = range(min(ticks) + 1, max(ticks) + 1, 2) labels1 = [labels[i].get_text() for i in ticks1] labels2 = [labels[i].get_text() for i in ticks2] # ax.tick_params(which='both', direction='out') #ax.set_ylim(-1, 1) ax.set_xticks(ticks1) ax.set_xticklabels(labels1, rotation=90) ax2 = ax.twiny() ax2.set_zorder(-1) ax2.set_xticks(ticks2) ax2.set_xticklabels(labels2, rotation=90) ax2.set_xlim(ax.get_xlim()) ax.grid(True) return fig
def gbrv_runform(options): """ Run GBRV compound tests given a chemical formula. """ # Extract chemical symbols from formula formula = options.formula symbols = set(species_from_formula(formula)) # Init pseudo table and construct all possible combinations for the given formula. table = DojoTable.from_dir(top=options.pseudo_dir, exts=("psp8", "xml"), exclude_dirs="_*") pseudo_list = table.all_combinations_for_elements(symbols) #print("Removing relativistic pseudos from list") #pseudo_list = [plist for plist in pseudo_list if not any("_r" in p.basename for p in plist)] # This is hard-coded since we GBRV results are PBE-only. # There's a check between xc and pseudo.xc below. xc = "PBE" gbrv_factory = GbrvCompoundsFactory(xc=xc) db = gbrv_factory.db # Consistency check entry = db.match_symbols(symbols) if entry is None: cprint("Cannot find entry for %s! Returning" % str(symbols), "red") return 1 workdir = "GBRVCOMP_" + formula print("Working in:", workdir) flow = GbrvCompoundsFlow(workdir=workdir) accuracy = "high" for pseudos in pseudo_list: if any(xc != p.xc for p in pseudos): raise ValueError("Pseudos with different XC functional") ecut = max(p.hint_for_accuracy(accuracy).ecut for p in pseudos) pawecutdg = max( p.hint_for_accuracy(accuracy).pawecutdg for p in pseudos) if ecut <= 0.0: raise RuntimeError("Pseudos do not have hints") #ecut = ecut_from_pseudos(pseudos, accuracy) print("Adding work for pseudos:", pseudos) print(" formula:", entry.symbol, ", structure:", entry.struct_type, ", ecut:", ecut) work = gbrv_factory.relax_and_eos_work(accuracy, pseudos, entry.symbol, entry.struct_type, ecut=ecut, pawecutdg=None) flow.register_work(work) if options.dry_run: flow.build_and_pickle_dump() return 0 # Run the flow with the scheduler (enable smart_io) flow.use_smartio() return flow.make_scheduler().start()