Example #1
0
def get_dict_element():
    c.execute('''SELECT id,name,charge,multiplicity,
                        num_atoms,num_elec,symmetry FROM ele_tab''')

    d = defaultdict(dict)

    for i in c.fetchall():
        d[str(i[1])] = {
            "id": str(i[0]),
            "charge": int(i[2]),
            "multiplicity": int(i[3]),
            "num_atoms": int(i[4]),
            "symmetry": str(i[6])
        }

    for ele in d:
        f = get_formula(ele)
        d[ele]["formula"] = f

        for geo in list_geo():

            l = [get_coord(ele, a, geo) for a in f]
            d[ele][geo] = l

    return d
Example #2
0
def get_l_ele(arguments):
    """
    Return the good list of element needed using arguments dict.
    arguments need to have all this key:
        --ele ; --like_toulouse ; --like_applencourt ; --like_run_id
    """
    if "--ele" in arguments and arguments["--ele"]:
        l_ele = "--ele" in arguments and arguments["--ele"]

    elif "--like_toulouse" in arguments and arguments["--like_toulouse"]:
        from src.misc_info import list_toulouse
        l_ele = list_toulouse

    elif "--like_applencourt" in arguments and arguments["--like_applencourt"]:
        from src.misc_info import list_applencourt
        l_ele = list_applencourt

    elif "--like_run_id" in arguments and arguments["--like_run_id"]:
        c.execute("""SELECT name FROM output_tab
                          WHERE run_id = {0}""".format(arguments["--like_run_id"]))

        l_ele = [i[0] for i in c.fetchall()]

    else:
        l_ele = list()

    return l_ele
Example #3
0
def get_l_ele(arguments):
    """
    Return the good list of element needed using arguments dict.
    arguments need to have all this key:
        --ele ; --like_toulouse ; --like_applencourt ; --like_run_id
    """
    if "--ele" in arguments and arguments["--ele"]:
        l_ele = "--ele" in arguments and arguments["--ele"]

    elif "--like_toulouse" in arguments and arguments["--like_toulouse"]:
        from src.misc_info import list_toulouse
        l_ele = list_toulouse

    elif "--like_applencourt" in arguments and arguments["--like_applencourt"]:
        from src.misc_info import list_applencourt
        l_ele = list_applencourt

    elif "--like_run_id" in arguments and arguments["--like_run_id"]:
        c.execute("""SELECT name FROM output_tab
                          WHERE run_id = {0}""".format(
            arguments["--like_run_id"]))

        l_ele = [i[0] for i in c.fetchall()]

    else:
        l_ele = list()

    return l_ele
Example #4
0
    def get_children(self):
        """
        Find all this children of all the elements and
        and add them to l_ele_to_get
        """
        cond = " ".join(cond_sql_or("name", self.l_ele_to_get))

        c.execute("""SELECT name, formula
                                   FROM id_tab
                                  WHERE {where_cond}""".format(where_cond=cond))

        # Uniquify the list
        return list(set([a for _, f in c.fetchall() for a, _ in eval(f)]))
Example #5
0
    def get_children(self):
        """
        Find all this children of all the elements and
        and add them to l_ele_to_get
        """
        cond = " ".join(cond_sql_or("name", self.l_ele_to_get))

        c.execute("""SELECT name, formula
                                   FROM id_tab
                                  WHERE {where_cond}""".format(
            where_cond=cond))

        # Uniquify the list
        return list(set([a for _, f in c.fetchall() for a, _ in eval(f)]))
Example #6
0
def get_enr(cond_filter_ele):
    """
    Return 1 dict:
        * e_nr   Dict of estimated exact no relativist energy  (e_nr[name])
    """
    # -#-#- #
    # S Q L #
    # -#-#- #
    # Get Davidson est. atomics energies
    try:
        run_id_mol = e_nr_name_id_dict[config.get("estimated_exact",
                                                  "method")]
        run_id_atom = e_nr_name_id_dict[config.get("estimated_exact",
                                                   "atomic")]
    except KeyError:
        print "WARNING bad method in cfg"
        print "Will use by default Feller and Chakravorty"
        run_id_mol = e_nr_name_id_dict["Feller"]
        run_id_atom = e_nr_name_id_dict["Chakravorty"]

    cmd_id = cond_sql_or("run_id", [run_id_atom, run_id_mol])

    cmd_where = " AND ".join(cond_filter_ele + cmd_id)
    c.execute("""SELECT name as name_atome,
                          energy as exact_energy
                            FROM simple_energy_tab
                    NATURAL JOIN id_tab
                           WHERE {cmd_where}""".format(cmd_where=cmd_where))

    # -#-#-#- #
    # I n i t #
    # -#-#-#- #
    e_nr = defaultdict()

    # -#-#-#-#-#-#- #
    # F i l l _ i n #
    # -#-#-#-#-#-#- #
    # Put exact energy non relativist for atom and molecule
    for name, exact_energy in c.fetchall():
        e_nr[name] = float(exact_energy)

    return e_nr
Example #7
0
def get_enr(cond_filter_ele):
    """
    Return 1 dict:
        * e_nr   Dict of estimated exact no relativist energy  (e_nr[name])
    """
    # -#-#- #
    # S Q L #
    # -#-#- #
    # Get Davidson est. atomics energies
    try:
        run_id_mol = e_nr_name_id_dict[config.get("estimated_exact", "method")]
        run_id_atom = e_nr_name_id_dict[config.get("estimated_exact",
                                                   "atomic")]
    except KeyError:
        print "WARNING bad method in cfg"
        print "Will use by default Feller and Chakravorty"
        run_id_mol = e_nr_name_id_dict["Feller"]
        run_id_atom = e_nr_name_id_dict["Chakravorty"]

    cmd_id = cond_sql_or("run_id", [run_id_atom, run_id_mol])

    cmd_where = " AND ".join(cond_filter_ele + cmd_id)
    c.execute("""SELECT name as name_atome,
                          energy as exact_energy
                            FROM simple_energy_tab
                    NATURAL JOIN id_tab
                           WHERE {cmd_where}""".format(cmd_where=cmd_where))

    # -#-#-#- #
    # I n i t #
    # -#-#-#- #
    e_nr = defaultdict()

    # -#-#-#-#-#-#- #
    # F i l l _ i n #
    # -#-#-#-#-#-#- #
    # Put exact energy non relativist for atom and molecule
    for name, exact_energy in c.fetchall():
        e_nr[name] = float(exact_energy)

    return e_nr
def get_dict_element():
    c.execute('''SELECT id,name,charge,multiplicity,
                        num_atoms,num_elec,symmetry FROM ele_tab''')

    d = defaultdict(dict)

    for i in c.fetchall():
        d[str(i[1])] = {"id": str(i[0]),
                        "charge": int(i[2]),
                        "multiplicity": int(i[3]),
                        "num_atoms": int(i[4]),
                        "symmetry": str(i[6])}

    for ele in d:
            f = get_formula(ele)
            d[ele]["formula"] = f

            for geo in list_geo():

                l = [get_coord(ele, a, geo) for a in f]
                d[ele][geo] = l

    return d
Example #9
0
def get_cmd(arguments, l_ele_obj, need_all):
    """
    Create the cmd string who will be executed by the db
    """
    d = {"run_id": "--run_id",
         "geo": "--geo",
         "basis": "--basis",
         "method": "--method",
         "comments": "--comments"}

    cond_filter = []
    for k, v in d.items():
        try:
            cond_filter += cond_sql_or(k, arguments[v])
        except KeyError:
            pass

    l_ele_to_get = l_ele_obj.l_ele_to_get

    # We need to find the run_id who containt ALL the ele is needed
    if l_ele_to_get:
        cond_filter_ele = cond_sql_or("name",
                                      l_ele_to_get) if need_all else ["(1)"]
    else:
        cond_filter_ele = []

    # Maybe we dont need to filter
    # Else just simplify the expresion :
    #   geo basis method -> run_id
    if not any((cond_filter, cond_filter_ele)):
        cmd_where = "(1)"
    else:
        cmd_where_tmp = " AND ".join(cond_filter + cond_filter_ele)

        # Select all the run_id where all the condition is good
        if l_ele_to_get and need_all:
            cmd_having = "count(name) = {0}".format(len(l_ele_to_get))
        else:
            cmd_having = "(1)"

        c.execute("""SELECT run_id
                     FROM (SELECT run_id,
                                    name,
                             method_name method,
                              basis_name basis,
                             geo_name geo
                           FROM output_tab
                           WHERE {0})
                     GROUP BY run_id
                     HAVING {1}""".format(cmd_where_tmp, cmd_having))

        l_run_id = [i[0] for i in c.fetchall()]

        if not l_run_id:
            print "Not run for you'r imput sorry"
            sys.exit()
        else:
            # Now only the run_id count. It containt all the information
            cond_filter = ["run_id in (" + ",".join(map(str, l_run_id)) + ")"]

            cmd_where = " AND ".join(cond_filter + cond_filter_ele)

    return [cond_filter_ele, cmd_where]
Example #10
0
def get_cmd(arguments, l_ele_obj, need_all):
    """
    Create the cmd string who will be executed by the db
    """
    d = {
        "run_id": "--run_id",
        "geo": "--geo",
        "basis": "--basis",
        "method": "--method",
        "comments": "--comments"
    }

    cond_filter = []
    for k, v in d.items():
        try:
            cond_filter += cond_sql_or(k, arguments[v])
        except KeyError:
            pass

    l_ele_to_get = l_ele_obj.l_ele_to_get

    # We need to find the run_id who containt ALL the ele is needed
    if l_ele_to_get:
        cond_filter_ele = cond_sql_or("name",
                                      l_ele_to_get) if need_all else ["(1)"]
    else:
        cond_filter_ele = []

    # Maybe we dont need to filter
    # Else just simplify the expresion :
    #   geo basis method -> run_id
    if not any((cond_filter, cond_filter_ele)):
        cmd_where = "(1)"
    else:
        cmd_where_tmp = " AND ".join(cond_filter + cond_filter_ele)

        # Select all the run_id where all the condition is good
        if l_ele_to_get and need_all:
            cmd_having = "count(name) = {0}".format(len(l_ele_to_get))
        else:
            cmd_having = "(1)"

        c.execute("""SELECT run_id
                     FROM (SELECT run_id,
                                    name,
                             method_name method,
                              basis_name basis,
                             geo_name geo
                           FROM output_tab
                           WHERE {0})
                     GROUP BY run_id
                     HAVING {1}""".format(cmd_where_tmp, cmd_having))

        l_run_id = [i[0] for i in c.fetchall()]

        if not l_run_id:
            print "Not run for you'r imput sorry"
            sys.exit()
        else:
            # Now only the run_id count. It containt all the information
            cond_filter = ["run_id in (" + ",".join(map(str, l_run_id)) + ")"]

            cmd_where = " AND ".join(cond_filter + cond_filter_ele)

    return [cond_filter_ele, cmd_where]