# Path: tilde/core/settings.py
# DB_SCHEMA_VERSION = '5.20'
# SETTINGS_FILE = 'settings.json'
# DEFAULT_SQLITE_DB = 'default.db'
# BASE_DIR = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
# ROOT_DIR = os.path.normpath(BASE_DIR + '/../')
# DATA_DIR = os.path.join(ROOT_DIR, 'data')
# EXAMPLE_DIR = os.path.join(ROOT_DIR, '../tests/data')
# INIT_DATA = os.path.join(DATA_DIR, 'sql/init-data.sql')
# TEST_DBS_FILE = os.path.join(DATA_DIR, 'test_dbs.txt')
# TEST_DBS_REF_FILE = os.path.join(DATA_DIR, 'test_dbs_ref.txt')
# SETTINGS_PATH = DATA_DIR + os.sep + SETTINGS_FILE
# GUI_URL_TPL = 'http://tilde-lab.github.io/berlinium/?http://127.0.0.1:%s' # ?https://db.tilde.pro
# DEFAULT_SETUP = {
# 
#     # General part
#     'debug_regime': False, # TODO
#     'log_dir': os.path.join(DATA_DIR, "logs"), # TODO
#     'skip_unfinished': False,
#     'skip_notenergy': False,
#     'skip_if_path': [],
# 
#     # DB part
#     'db': {
#         'default_sqlite_db': DEFAULT_SQLITE_DB,
#         'engine': 'sqlite', # if sqlite is chosen: further info is not used
#         'host': 'localhost',
#         'port': 5432,
#         'user': 'postgres',
#         'password': '',
#         'dbname': 'tilde'
#     },
# 
#     # Server part
#     'webport': 8070,
#     'title': "Tilde GUI"
# }
# def virtualize_path(item):
# def connect_url(settings, named=None):
# def connect_database(settings, named=None, no_pooling=False, default_actions=True, scoped=False):
# def write_settings(settings):
# def get_hierarchy(settings):
# 
# Path: tilde/core/model.py
# class Pragma(Base):
# class Hierarchy(Base):
# class Hierarchy_group(Base):
# class Hierarchy_value(Base):
# class Topic(UniqueMixin, Base):
# class Grid(Base):
# class Calculation(Base):
# class Metadata(Base):
# class Reference(Base):
# class Codeversion(UniqueMixin, Base):
# class Codefamily(UniqueMixin, Base):
# class Energy(Base):
# class Basis(Base):
# class Recipinteg(Base):
# class Pottype(UniqueMixin, Base):
# class Electrons(Base):
# class Phonons(Base):
# class Spectra(Base):
# class Forces(Base):
# class Structure(Base):
# class Lattice(Base):
# class Atom(Base):
# class Spacegroup(Base):
# class Struct_ratios(Base):
# class Struct_optimisation(Base):
#     def unique_filter(cls, query, cid, topic):
#     def unique_filter(cls, query, content):
#     def unique_filter(cls, query, content):
#     def unique_filter(cls, query, name):
#     ELECTRON = 'ELECTRON'
#     PHONON = 'PHONON'


import sys, os
import time
import set_path
from sqlalchemy import func, and_
from tilde.core.settings import settings, connect_database
from tilde.core import model
#!/usr/bin/env python
"""
Query band gaps for those calculations,
which possess the minimal total energy
of those sharing the same chemical formula
(wrt unit cell), from a Tilde database
"""




starttime = time.time()
db_choice = None

# Path: tilde/core/settings.py
# DB_SCHEMA_VERSION = '5.20'
# SETTINGS_FILE = 'settings.json'
# DEFAULT_SQLITE_DB = 'default.db'
# BASE_DIR = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
# ROOT_DIR = os.path.normpath(BASE_DIR + '/../')
# DATA_DIR = os.path.join(ROOT_DIR, 'data')
# EXAMPLE_DIR = os.path.join(ROOT_DIR, '../tests/data')
# INIT_DATA = os.path.join(DATA_DIR, 'sql/init-data.sql')
# TEST_DBS_FILE = os.path.join(DATA_DIR, 'test_dbs.txt')
# TEST_DBS_REF_FILE = os.path.join(DATA_DIR, 'test_dbs_ref.txt')
# SETTINGS_PATH = DATA_DIR + os.sep + SETTINGS_FILE
# GUI_URL_TPL = 'http://tilde-lab.github.io/berlinium/?http://127.0.0.1:%s' # ?https://db.tilde.pro
# DEFAULT_SETUP = {
# 
#     # General part
#     'debug_regime': False, # TODO
#     'log_dir': os.path.join(DATA_DIR, "logs"), # TODO
#     'skip_unfinished': False,
#     'skip_notenergy': False,
#     'skip_if_path': [],
# 
#     # DB part
#     'db': {
#         'default_sqlite_db': DEFAULT_SQLITE_DB,
#         'engine': 'sqlite', # if sqlite is chosen: further info is not used
#         'host': 'localhost',
#         'port': 5432,
#         'user': 'postgres',
#         'password': '',
#         'dbname': 'tilde'
#     },
# 
#     # Server part
#     'webport': 8070,
#     'title': "Tilde GUI"
# }
# def virtualize_path(item):
# def connect_url(settings, named=None):
# def connect_database(settings, named=None, no_pooling=False, default_actions=True, scoped=False):
# def write_settings(settings):
# def get_hierarchy(settings):
# 
# Path: tilde/core/model.py
# class Pragma(Base):
# class Hierarchy(Base):
# class Hierarchy_group(Base):
# class Hierarchy_value(Base):
# class Topic(UniqueMixin, Base):
# class Grid(Base):
# class Calculation(Base):
# class Metadata(Base):
# class Reference(Base):
# class Codeversion(UniqueMixin, Base):
# class Codefamily(UniqueMixin, Base):
# class Energy(Base):
# class Basis(Base):
# class Recipinteg(Base):
# class Pottype(UniqueMixin, Base):
# class Electrons(Base):
# class Phonons(Base):
# class Spectra(Base):
# class Forces(Base):
# class Structure(Base):
# class Lattice(Base):
# class Atom(Base):
# class Spacegroup(Base):
# class Struct_ratios(Base):
# class Struct_optimisation(Base):
#     def unique_filter(cls, query, cid, topic):
#     def unique_filter(cls, query, content):
#     def unique_filter(cls, query, content):
#     def unique_filter(cls, query, name):
#     ELECTRON = 'ELECTRON'
#     PHONON = 'PHONON'


# Path: tutorials/simple_data_mining/miner_bandgaps.py
import sys, os
import time
import set_path
from sqlalchemy import func, and_
from tilde.core.settings import settings, connect_database
from tilde.core import model

#!/usr/bin/env python
"""
Query band gaps for those calculations,
which possess the minimal total energy
of those sharing the same chemical formula
(wrt unit cell), from a Tilde database
"""




starttime = time.time()
db_choice = None

if settings['db']['engine'] == 'sqlite':