def db_get(self, table_name): """ Get a table from the database Return a dict[run_id][ele] = Value TableName is eather e_tab _ae_tab """ l = { cond_sql_or(k, v) for k, v in (["ele_name", self.l_element_whe_want], ["run_id", self.l_run_id]) } sql_cmd_where = " AND ".join(l) cursor = c_row.execute("""SELECT * FROM {0} WHERE {1} """.format(table_name, sql_cmd_where)) from src.object import Energie d = defaultdict(dict) for r in cursor: e = r["energy"] err = r["err"] if r["err"] else 0 d[r["run_id"]][r["ele_name"]] = Energie(e, err) return d
def get_zpe_aeexp(cond_filter_ele): """ Return 2 dict: * zpe_exp Dict of zpe experimental (zpe_exp[name]) * ae_exp Dict of atomization experimental energis (ae_ext[name]) """ # -#-#- # # S Q L # # -#-#- # try: zpe_ae_user = config.get("ZPE_AE", "value") except KeyError: print "WARNING bad ZPE AE type" raise if zpe_ae_user == "recomended": cond = ['basis_id=(1)'] else: method_id = ae_zpe_exp_dict[zpe_ae_user] cond = ['(basis_id=1)', '(method_id=%d)' % (method_id)] cond_filter = cond_filter_ele + cond cmd_where = " AND ".join(cond_filter) cursor = c_row.execute("""SELECT name, formula, zpe, kcal, min(kcal_err) as kcal_err FROM id_tab NATURAL JOIN zpe_tab NATURAL JOIN atomization_tab WHERE {cmd_where} GROUP BY name""".format(cmd_where=cmd_where)) # -#-#-#- # # I n i t # # -#-#-#- # ae_exp = defaultdict() zpe_exp = defaultdict() # -#-#-#-#-#-#- # # F i l l _ i n # # -#-#-#-#-#-#- # for r in cursor: zpe = r['zpe'] * 4.55633e-06 energy = r['kcal'] * 0.00159362 energy_err = r['kcal_err'] * 0.00159362 if r['kcal_err'] else 0. ae_exp[r['name']] = v_un(energy, energy_err) zpe_exp[r['name']] = zpe return [ae_exp, zpe_exp]
def db_list_element(self, run_id): """ Get the element listed in a run_id """ sql_cmd_where = cond_sql_or("run_id", [run_id]) cursor = c_row.execute("""SELECT ele_name FROM run_tab_ele WHERE {0} """.format(sql_cmd_where)) l_ele = {i[0] for i in cursor} str_ = "No element in run_id: {0}" assert (l_ele), str_.format(run_id) return l_ele
def l_element(self): """ Get the element from the databse """ l = { cond_sql_or(k, v) for k, v in (["ele_name", self.l_element_whe_want], ["run_id", self.l_run_id]) } sql_cmd_where = " AND ".join(l) cursor = c_row.execute("""SELECT DISTINCT ele_name FROM run_tab_ele WHERE {0} """.format(sql_cmd_where)) return {i[0] for i in cursor.fetchall()}
def d_run_info(self): "Return a dict in adecation with d_arguments" d_arg2db = self.d_arg_to_db d_arg2value = self.d_arguments l = d_arg2db.viewkeys() & d_arg2value.viewkeys() if l: l_cond_filter = [ cond_sql_or(table_name=d_arg2db[k], l_value=d_arg2value[k]) for k in l ] else: l_cond_filter = ["(1)"] sql_cmd_where = " AND ".join(l_cond_filter) # -#-#- # # S Q L # # -#-#- # cursor = c_row.execute("""SELECT run_id, method, basis, geo, comments FROM run_tab_expended WHERE {0} """.format(sql_cmd_where)) RunInfo = namedtuple('RunInfo', 'run_id, method, basis, geo, comments') d_run_info = dict() for emp in map(RunInfo._make, cursor.fetchall()): d_run_info[emp.run_id] = emp assert d_run_info, "No run_id with: {0}".format(sql_cmd_where) return d_run_info
def d_run_info(self): "Return a dict in adecation with d_arguments" d_arg2db = self.d_arg_to_db d_arg2value = self.d_arguments l = d_arg2db.viewkeys() & d_arg2value.viewkeys() if l: l_cond_filter = [cond_sql_or(table_name=d_arg2db[k], l_value=d_arg2value[k]) for k in l] else: l_cond_filter = ["(1)"] sql_cmd_where = " AND ".join(l_cond_filter) # -#-#- # # S Q L # # -#-#- # cursor = c_row.execute("""SELECT run_id, method, basis, geo, comments FROM run_tab_expended WHERE {0} """.format(sql_cmd_where)) RunInfo = namedtuple('RunInfo', 'run_id, method, basis, geo, comments') d_run_info = dict() for emp in map(RunInfo._make, cursor.fetchall()): d_run_info[emp.run_id] = emp assert d_run_info, "No run_id with: {0}".format(sql_cmd_where) return d_run_info
def get_ecal_runinfo_finfo(cmd_where, cipsi_type): """ Return 3 dict: * e_cal Dict of energies theorical / calculated (e_cal[run_id][name]) * run_info Dict of the geo,basis,method,comments (run_info[run_id]) * f_info Dict of formula (run_id[name]) """ # -#-#- # # S Q L # # -#-#- # cursor = c_row.execute("""SELECT formula, num_atoms, run_id, method_name method, basis_name basis, geo_name geo, comments, output_tab.name ele, s_energy, c_energy, c_pt2, q_energy, q_err FROM output_tab INNER JOIN id_tab ON output_tab.name = id_tab.name WHERE {0}""".format(cmd_where.replace("name", "ele"))) # -#-#-#- # # I n i t # # -#-#-#- # e_cal = defaultdict(dict) run_info = defaultdict() f_info = defaultdict() # -#-#-#-#-#-#- # # F i l l _ i n # # -#-#-#-#-#-#- # num_formula = namedtuple('num_formula', ['num_atoms', 'formula']) for r in cursor: # Energy if r['s_energy']: value = float(r['s_energy']) if r['c_energy']: if cipsi_type == "var": value = float(r['c_energy']) elif cipsi_type == "pt2": value = float(r['c_pt2']) elif cipsi_type == "var+pt2": value = float(r['c_energy']) + float(r['c_pt2']) if r['q_energy']: value = v_un(float(r['q_energy']), float(r['q_err'])) e_cal[r['run_id']][r['ele']] = value # Info run_info[r['run_id']] = [r['method'], r['basis'], r['geo'], r['comments']] if not r['ele'] in f_info: f_info[r['ele']] = num_formula(r['num_atoms'], eval(r['formula'])) return [e_cal, run_info, f_info]
def get_ecal_runinfo_finfo(cmd_where, cipsi_type): """ Return 3 dict: * e_cal Dict of energies theorical / calculated (e_cal[run_id][name]) * run_info Dict of the geo,basis,method,comments (run_info[run_id]) * f_info Dict of formula (run_id[name]) """ # -#-#- # # S Q L # # -#-#- # cursor = c_row.execute("""SELECT formula, num_atoms, run_id, method_name method, basis_name basis, geo_name geo, comments, output_tab.name ele, s_energy, c_energy, c_pt2, q_energy, q_err FROM output_tab INNER JOIN id_tab ON output_tab.name = id_tab.name WHERE {0}""".format(cmd_where.replace("name", "ele"))) # -#-#-#- # # I n i t # # -#-#-#- # e_cal = defaultdict(dict) run_info = defaultdict() f_info = defaultdict() # -#-#-#-#-#-#- # # F i l l _ i n # # -#-#-#-#-#-#- # num_formula = namedtuple('num_formula', ['num_atoms', 'formula']) for r in cursor: # Energy if r['s_energy']: value = float(r['s_energy']) if r['c_energy']: if cipsi_type == "var": value = float(r['c_energy']) elif cipsi_type == "pt2": value = float(r['c_pt2']) elif cipsi_type == "var+pt2": value = float(r['c_energy']) + float(r['c_pt2']) if r['q_energy']: value = v_un(float(r['q_energy']), float(r['q_err'])) e_cal[r['run_id']][r['ele']] = value # Info run_info[r['run_id']] = [ r['method'], r['basis'], r['geo'], r['comments'] ] if not r['ele'] in f_info: f_info[r['ele']] = num_formula(r['num_atoms'], eval(r['formula'])) return [e_cal, run_info, f_info]