<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""EMSL Api.

Usage:
  EMSL_api.py list_basis  [--basis=<basis_name>...]
                          [--atom=<atom_name>...]
                          [--db_path=<db_path>]
                          [--average_mo_number]
  EMSL_api.py list_atoms  --basis=<basis_name>
                          [--db_path=<db_path>]
  EMSL_api.py get_basis_data --basis=<basis_name>
                             [--atom=<atom_name>...]
                             [--db_path=<db_path>]
                             [(--save [--path=<path>])]
                             [--check=<format>]
  EMSL_api.py list_formats
  EMSL_api.py create_db      --db_path=<db_path>
                             --format=<format>
                             [--no-contraction]
  EMSL_api.py (-h | --help)
  EMSL_api.py --version

Options:
  -h --help         Show this screen.
  --version         Show version.
  --no-contraction  Basis functions are not contracted

<db_path> is the path to the SQLite3 file containing the Basis sets.
By default is $EMSL_API_ROOT/db/Gausian_uk.db

Example of use:
    ./EMSL_api.py list_basis --atom Al --atom U
    ./EMSL_api.py list_basis --atom S --basis 'cc-pV*' --average_mo_number
    ./EMSL_api.py list_atoms --basis ANO-RCC
    ./EMSL_api.py get_basis_data --basis 3-21++G*
"""

version = "0.3.0"

import sys
import os

from src.docopt import docopt
from src.EMSL_dump import EMSL_dump
from src.EMSL_local import EMSL_local, checkSQLite3

if __name__ == '__main__':

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

    # ___
    #  |  ._  o _|_
    # _|_ | | |  |_
    #

    if arguments["--db_path"]:
        db_path = arguments["--db_path"]
    else:
        db_path = os.path.dirname(__file__) + "/db/Gamess-us.db"

    # Check the db
    try:
        if not(arguments['create_db']):
            db_path, db_path_changed = checkSQLite3(db_path)
    except:
        raise

    #  _     _     _    ______           _
    # | |   (_)   | |   | ___ \         (_)
    # | |    _ ___| |_  | |_/ / __ _ ___ _ ___
    # | |   | / __| __| | ___ \/ _` / __| / __|
    # | |___| \__ \ |_  | |_/ / (_| \__ \ \__ \
    # \_____/_|___/\__| \____/ \__,_|___/_|___/

    if arguments["list_basis"]:
        e = EMSL_local(db_path=db_path)

        elts = arguments["--atom"]

        amn = arguments["--average_mo_number"]

        l = e.get_list_basis_available(elts,
                                       arguments["--basis"],
                                       average_mo_number=amn)

        if amn:
            for name, des, avg in l:
                print "- '{}' ({}) || {:<50}".format(name, avg, des)
        else:
            for name, des in l:
                print "- {} || {:<50}".format(name, des)

    #  _     _     _     _____ _                           _
    # | |   (_)   | |   |  ___| |                         | |
    # | |    _ ___| |_  | |__ | | ___ _ __ ___   ___ _ __ | |_ ___
    # | |   | / __| __| |  __|| |/ _ \ '_ ` _ \ / _ \ '_ \| __/ __|
    # | |___| \__ \ |_  | |___| |  __/ | | | | |  __/ | | | |_\__ \
    # \_____/_|___/\__| \____/|_|\___|_| |_| |_|\___|_| |_|\__|___/
    if arguments["list_atoms"]:
        e = EMSL_local(db_path=db_path)

        basis_name = arguments["--basis"]
        l = e.get_list_element_available(basis_name)
        print ", ".join(l)

    # ______           _           _       _
    # | ___ \         (_)         | |     | |
    # | |_/ / __ _ ___ _ ___    __| | __ _| |_ __ _
    # | ___ \/ _` / __| / __|  / _` |/ _` | __/ _` |
    # | |_/ / (_| \__ \ \__ \ | (_| | (_| | || (_| |
    # \____/ \__,_|___/_|___/  \__,_|\__,_|\__\__,_|
    if arguments["get_basis_data"]:
        e = EMSL_local(db_path=db_path)
        basis_name = arguments["--basis"][0]
        elts = arguments["--atom"]

        l_atom_basis = e.get_basis(basis_name, elts, arguments["--check"])
        # Add separation between atoms, and a empty last line
        str_ = "\n\n".join(l_atom_basis) + "\n"

        if arguments["--save"]:

            if arguments["--path"]:
                path = arguments["--path"]
            else:
                path = "_".join([basis_name, ".".join(elts)])
                path = "/tmp/" + path + ".bs"

            with open(path, 'w') as f:
                f.write(str_ + "\n")
            print path
        else:
            print str_

    #  _     _     _      __                           _
    # | |   (_)   | |    / _|                         | |
    # | |    _ ___| |_  | |_ ___  _ __ _ __ ___   __ _| |_ ___
    # | |   | / __| __| |  _/ _ \| '__| '_ ` _ \ / _` | __/ __|
    # | |___| \__ \ |_  | || (_) | |  | | | | | | (_| | |_\__ \
    # \_____/_|___/\__| |_| \___/|_|  |_| |_| |_|\__,_|\__|___/
    if arguments["list_formats"]:
        e = EMSL_dump()
        for i in e.get_list_format():
            print i

    #  _____                _             _ _
    # /  __ \              | |           | | |
    # | /  \/_ __ ___  __ _| |_ ___    __| | |__
    # | |   | '__/ _ \/ _` | __/ _ \  / _` | '_ \
    # | \__/\ | |  __/ (_| | ||  __/ | (_| | |_) |
    #  \____/_|  \___|\__,_|\__\___|  \__,_|_.__/
    if arguments["create_db"]:
        db_path = arguments["--db_path"]
        format = arguments["--format"]

        format_dict = EMSL_dump().get_list_format()
        if format not in format_dict:
            print "Format %s doesn't exist. Run list_formats to get the list of formats." % (format)
            sys.exit(1)
        contraction = not arguments["--no-contraction"]

        e = EMSL_dump(
            db_path=db_path,
            format=format_dict[format],
            contraction=contraction)
        e.new_db()

    #  _
    # /  |  _   _. ._  o ._   _
    # \_ | (/_ (_| | | | | | (_|
    #                         _|

    # Clean up on exit
    if not(arguments['create_db']) and db_path_changed:
        os.system("rm -f /dev/shm/%d.db" % (os.getpid()))
<commit_msg>Add standar list_basis format aka - 'name' (mo) || des<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""EMSL Api.

Usage:
  EMSL_api.py list_basis  [--basis=<basis_name>...]
                          [--atom=<atom_name>...]
                          [--db_path=<db_path>]
                          [--average_mo_number]
  EMSL_api.py list_atoms  --basis=<basis_name>
                          [--db_path=<db_path>]
  EMSL_api.py get_basis_data --basis=<basis_name>
                             [--atom=<atom_name>...]
                             [--db_path=<db_path>]
                             [(--save [--path=<path>])]
                             [--check=<format>]
  EMSL_api.py list_formats
  EMSL_api.py create_db      --db_path=<db_path>
                             --format=<format>
                             [--no-contraction]
  EMSL_api.py (-h | --help)
  EMSL_api.py --version

Options:
  -h --help         Show this screen.
  --version         Show version.
  --no-contraction  Basis functions are not contracted

<db_path> is the path to the SQLite3 file containing the Basis sets.
By default is $EMSL_API_ROOT/db/Gausian_uk.db

Example of use:
    ./EMSL_api.py list_basis --atom Al --atom U
    ./EMSL_api.py list_basis --atom S --basis 'cc-pV*' --average_mo_number
    ./EMSL_api.py list_atoms --basis ANO-RCC
    ./EMSL_api.py get_basis_data --basis 3-21++G*
"""

version = "0.3.0"

import sys
import os

from src.docopt import docopt
from src.EMSL_dump import EMSL_dump
from src.EMSL_local import EMSL_local, checkSQLite3

if __name__ == '__main__':

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

    # ___
    #  |  ._  o _|_
    # _|_ | | |  |_
    #

    if arguments["--db_path"]:
        db_path = arguments["--db_path"]
    else:
        db_path = os.path.dirname(__file__) + "/db/Gamess-us.db"

    # Check the db
    try:
        if not(arguments['create_db']):
            db_path, db_path_changed = checkSQLite3(db_path)
    except:
        raise

    #  _     _     _    ______           _
    # | |   (_)   | |   | ___ \         (_)
    # | |    _ ___| |_  | |_/ / __ _ ___ _ ___
    # | |   | / __| __| | ___ \/ _` / __| / __|
    # | |___| \__ \ |_  | |_/ / (_| \__ \ \__ \
    # \_____/_|___/\__| \____/ \__,_|___/_|___/

    if arguments["list_basis"]:
        e = EMSL_local(db_path=db_path)

        elts = arguments["--atom"]

        amn = arguments["--average_mo_number"]

        l = e.get_list_basis_available(elts,
                                       arguments["--basis"],
                                       average_mo_number=amn)

        if amn:
            for name, des, avg in l:
                print "- '{}' ({}) || {:<50}".format(name, avg, des)
        else:
            for name, des in l:
                print "- '{}' || {:<50}".format(name, des)

    #  _     _     _     _____ _                           _
    # | |   (_)   | |   |  ___| |                         | |
    # | |    _ ___| |_  | |__ | | ___ _ __ ___   ___ _ __ | |_ ___
    # | |   | / __| __| |  __|| |/ _ \ '_ ` _ \ / _ \ '_ \| __/ __|
    # | |___| \__ \ |_  | |___| |  __/ | | | | |  __/ | | | |_\__ \
    # \_____/_|___/\__| \____/|_|\___|_| |_| |_|\___|_| |_|\__|___/
    if arguments["list_atoms"]:
        e = EMSL_local(db_path=db_path)

        basis_name = arguments["--basis"]
        l = e.get_list_element_available(basis_name)
        print ", ".join(l)

    # ______           _           _       _
    # | ___ \         (_)         | |     | |
    # | |_/ / __ _ ___ _ ___    __| | __ _| |_ __ _
    # | ___ \/ _` / __| / __|  / _` |/ _` | __/ _` |
    # | |_/ / (_| \__ \ \__ \ | (_| | (_| | || (_| |
    # \____/ \__,_|___/_|___/  \__,_|\__,_|\__\__,_|
    if arguments["get_basis_data"]:
        e = EMSL_local(db_path=db_path)
        basis_name = arguments["--basis"][0]
        elts = arguments["--atom"]

        l_atom_basis = e.get_basis(basis_name, elts, arguments["--check"])
        # Add separation between atoms, and a empty last line
        str_ = "\n\n".join(l_atom_basis) + "\n"

        if arguments["--save"]:

            if arguments["--path"]:
                path = arguments["--path"]
            else:
                path = "_".join([basis_name, ".".join(elts)])
                path = "/tmp/" + path + ".bs"

            with open(path, 'w') as f:
                f.write(str_ + "\n")
            print path
        else:
            print str_

    #  _     _     _      __                           _
    # | |   (_)   | |    / _|                         | |
    # | |    _ ___| |_  | |_ ___  _ __ _ __ ___   __ _| |_ ___
    # | |   | / __| __| |  _/ _ \| '__| '_ ` _ \ / _` | __/ __|
    # | |___| \__ \ |_  | || (_) | |  | | | | | | (_| | |_\__ \
    # \_____/_|___/\__| |_| \___/|_|  |_| |_| |_|\__,_|\__|___/
    if arguments["list_formats"]:
        e = EMSL_dump()
        for i in e.get_list_format():
            print i

    #  _____                _             _ _
    # /  __ \              | |           | | |
    # | /  \/_ __ ___  __ _| |_ ___    __| | |__
    # | |   | '__/ _ \/ _` | __/ _ \  / _` | '_ \
    # | \__/\ | |  __/ (_| | ||  __/ | (_| | |_) |
    #  \____/_|  \___|\__,_|\__\___|  \__,_|_.__/
    if arguments["create_db"]:
        db_path = arguments["--db_path"]
        format = arguments["--format"]

        format_dict = EMSL_dump().get_list_format()
        if format not in format_dict:
            print "Format %s doesn't exist. Run list_formats to get the list of formats." % (format)
            sys.exit(1)
        contraction = not arguments["--no-contraction"]

        e = EMSL_dump(
            db_path=db_path,
            format=format_dict[format],
            contraction=contraction)
        e.new_db()

    #  _
    # /  |  _   _. ._  o ._   _
    # \_ | (/_ (_| | | | | | (_|
    #                         _|

    # Clean up on exit
    if not(arguments['create_db']) and db_path_changed:
        os.system("rm -f /dev/shm/%d.db" % (os.getpid()))

{'fraction_non_alphanumeric': 0.17034937046610524, 'fraction_numerical': 0.0026682231301592596, 'mean_word_length': 1.3158910986676964, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2296307', 'n_tokens_mistral': 4521, 'n_tokens_neox': 4284, 'n_words': 591}