# 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/common.py
# def write_cif(filename, structure, comment=None):
#     try:
#         file = open(filename, 'w')
#         file.write(generate_cif(structure, comment))
#         file.close()
#     except IOError: return False
#     else: return True
# 
# def num2name(target, rules, mapping):
#     return mapping[rules['cid']][int(target)] if rules['enumerated'] else target
# 
# Path: tilde/core/symmetry.py
# class SymmetryFinder:
#     accuracy = 1e-04
# 
#     def __init__(self, accuracy=None):
#         self.error = None
#         self.accuracy=accuracy if accuracy else SymmetryFinder.accuracy
#         self.angle_tolerance = -1
# 
#     def get_spacegroup(self, tilde_obj):
#         try:
#             symmetry = spg.get_spacegroup(tilde_obj['structures'][-1], symprec=self.accuracy, angle_tolerance=self.angle_tolerance)
#         except Exception as ex:
#             self.error = 'Symmetry finder error: %s' % ex
#         else:
#             try:
#                 self.sg, self.ng = symmetry.split()
#                 self.ng = int(self.ng.strip("()"))
#             except (ValueError, IndexError, AttributeError):
#                 self.ng = 0
#                 self.error = 'Symmetry finder error (probably, coinciding atoms)'
# 
#     def refine_cell(self, tilde_obj):
#         '''
#         NB only used for perovskite_tilting app
#         '''
#         try: lattice, positions, numbers = spg.refine_cell(tilde_obj['structures'][-1], symprec=self.accuracy, angle_tolerance=self.angle_tolerance)
#         except Exception as ex:
#             self.error = 'Symmetry finder error: %s' % ex
#         else:
#             self.refinedcell = Atoms(numbers=numbers, cell=lattice, scaled_positions=positions, pbc=tilde_obj['structures'][-1].get_pbc())
#             self.refinedcell.periodicity = sum(self.refinedcell.get_pbc())
#             self.refinedcell.dims = abs(det(tilde_obj['structures'][-1].cell))
# 
# Path: tilde/core/api.py
# API = TildeAPI


import os, sys
import time
import logging
import argparse
import chk_tilde_install
from numpy import nan
from numpy.linalg import det
from tilde.core.settings import settings, connect_database, DATA_DIR, SETTINGS_PATH, DB_SCHEMA_VERSION
from tilde.core.common import write_cif, num2name
from tilde.core.symmetry import SymmetryFinder
from tilde.core.api import API
from ase.geometry import cell_to_cellpar
#!/usr/bin/env python
'''
Entry junction

Tilde is a general-purpose materials informatics framework
for intelligent organizers of the first-principles modeling data.
More info: https://tilde.pro

Author: Evgeny Blokhin
'''






logging.basicConfig(level=logging.INFO)
starttime = time.time()

# 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/common.py
# def write_cif(filename, structure, comment=None):
#     try:
#         file = open(filename, 'w')
#         file.write(generate_cif(structure, comment))
#         file.close()
#     except IOError: return False
#     else: return True
# 
# def num2name(target, rules, mapping):
#     return mapping[rules['cid']][int(target)] if rules['enumerated'] else target
# 
# Path: tilde/core/symmetry.py
# class SymmetryFinder:
#     accuracy = 1e-04
# 
#     def __init__(self, accuracy=None):
#         self.error = None
#         self.accuracy=accuracy if accuracy else SymmetryFinder.accuracy
#         self.angle_tolerance = -1
# 
#     def get_spacegroup(self, tilde_obj):
#         try:
#             symmetry = spg.get_spacegroup(tilde_obj['structures'][-1], symprec=self.accuracy, angle_tolerance=self.angle_tolerance)
#         except Exception as ex:
#             self.error = 'Symmetry finder error: %s' % ex
#         else:
#             try:
#                 self.sg, self.ng = symmetry.split()
#                 self.ng = int(self.ng.strip("()"))
#             except (ValueError, IndexError, AttributeError):
#                 self.ng = 0
#                 self.error = 'Symmetry finder error (probably, coinciding atoms)'
# 
#     def refine_cell(self, tilde_obj):
#         '''
#         NB only used for perovskite_tilting app
#         '''
#         try: lattice, positions, numbers = spg.refine_cell(tilde_obj['structures'][-1], symprec=self.accuracy, angle_tolerance=self.angle_tolerance)
#         except Exception as ex:
#             self.error = 'Symmetry finder error: %s' % ex
#         else:
#             self.refinedcell = Atoms(numbers=numbers, cell=lattice, scaled_positions=positions, pbc=tilde_obj['structures'][-1].get_pbc())
#             self.refinedcell.periodicity = sum(self.refinedcell.get_pbc())
#             self.refinedcell.dims = abs(det(tilde_obj['structures'][-1].cell))
# 
# Path: tilde/core/api.py
# API = TildeAPI


# Path: utils/entry.py
import os, sys
import time
import logging
import argparse
import chk_tilde_install
from numpy import nan
from numpy.linalg import det
from tilde.core.settings import settings, connect_database, DATA_DIR, SETTINGS_PATH, DB_SCHEMA_VERSION
from tilde.core.common import write_cif, num2name
from tilde.core.symmetry import SymmetryFinder
from tilde.core.api import API
from ase.geometry import cell_to_cellpar

#!/usr/bin/env python
'''
Entry junction

Tilde is a general-purpose materials informatics framework
for intelligent organizers of the first-principles modeling data.
More info: https://tilde.pro

Author: Evgeny Blokhin
'''






logging.basicConfig(level=logging.INFO)
starttime = time.time()

work = API()