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)]))
Beispiel #2
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)]))
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
Beispiel #4
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_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]
Beispiel #6
0
try:
    from src.docopt import docopt
    from src.SQL_util import cond_sql_or, list_geo, list_ele, dict_raw
    from src.SQL_util import get_xyz, get_g09
except:
    print "File in misc is corupted. Git reset may cure the disease."
    sys.exit(1)

if __name__ == '__main__':

    arguments = docopt(__doc__, version='G2 Api ' + version)

    if arguments["list_geometries"]:

        if arguments["--ele"]:
            str_ = cond_sql_or("id_tab.name", arguments["--ele"])
            str_ = "AND".join(str_)
        else:
            str_ = '(1)'

        print ", ".join(list_geo(str_))

    elif arguments["list_elements"]:

        str_ = cond_sql_or("geo_tab.name", arguments["--geo"])
        str_ = "AND".join(str_)

        l = [x for x in list_ele(str_) if "-" not in x and "+" not in x]

        print ", ".join(l)
Beispiel #7
0
try:
    from src.docopt import docopt
    from src.SQL_util import cond_sql_or, list_geo, list_ele, dict_raw
    from src.SQL_util import get_xyz, get_g09
except:
    print "File in misc is corupted. Git reset may cure the disease."
    sys.exit(1)

if __name__ == '__main__':

    arguments = docopt(__doc__, version='G2 Api ' + version)

    if arguments["list_geometries"]:

        if arguments["--ele"]:
            str_ = cond_sql_or("id_tab.name", arguments["--ele"])
            str_ = "AND".join(str_)
        else:
            str_ = '(1)'

        print ", ".join(list_geo(str_))

    elif arguments["list_elements"]:

        str_ = cond_sql_or("geo_tab.name", arguments["--geo"])
        str_ = "AND".join(str_)

        l = [x for x in list_ele(str_) if "-" not in x and "+" not in x]

        print ", ".join(l)
Beispiel #8
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]