# Path: orbkit/display.py
# def display(string):
#   '''Prints :literal:`string` to the terminal output and to the .oklog file.'''
#   global log_fid
#   if not options.quiet:
#     print(string)
#   if not options.no_log:
#     if log_fid is None:
#       if options.outputname is None or options.outputname == '':
#         return
#       else:
#         log_fid = '%s.oklog' % options.outputname.split('@')[0]
#     if not is_initiated:
#       init_display(log_fid)
#     f = open(log_fid, 'a')
#     f.write('%s\n' % string)
#     f.close()
# 
# Path: orbkit/options.py
# def get_options():
# def init_parser():
#   def default_if_called(option, opt, value, parser, default=1e4):
# def raise_error(string,error=IOError):
# def print_message(string):
# def check_options(error=raise_error,display=print_message,
#                   interactive=False,info=True,check_io=True):
#   def check_mo(attr):
# def check_if_exists(fid, what='',error=IOError,display=sys.stdout.write,
#                 interactive=False):
# def check_grid_output_compatibilty(error=raise_error): 


import gzip
import numpy
import os
import re
from orbkit.display import display
from orbkit.tools import *
from orbkit import options
  from .tar import is_tar_file, get_file_from_tar
  from io import TextIOWrapper
def descriptor_from_file(filename, index=0, ci_descriptor=False):

  if is_tar_file(filename):
    fname, _ = get_file_from_tar(filename, index=index, ci_descriptor=ci_descriptor)
  elif os.path.splitext(filename)[1] == '.gz':
    fname = gzip.open(filename, 'rt')
  else:
    fname = open(filename, 'r')
  return fname

def basissize(types, cart_spher):
  assert cart_spher in ['cartesian', 'pure'], 'Must specify eigther cartesian or pure spherical harmonics'
  size = 0
  for i in range(len(types)):
    l = spdfg_to_l[types[i]]
    if cart_spher == 'cartesian':
      size += (l+1)*(l+2)/2
    else:
      size += 2*l+1
  return size

def spin_check(spin,restricted,has_alpha,has_beta):
  '''Check if `spin` keyword is valid.
  '''
  if spin is not None:
    if restricted:
      raise IOError('The keyword `spin` is only supported for unrestricted calculations.')    
    if spin != 'alpha' and spin != 'beta':
      raise IOError('`spin=%s` is not a valid option' % spin)
    elif spin == 'alpha' and has_alpha:

# Path: orbkit/display.py
# def display(string):
#   '''Prints :literal:`string` to the terminal output and to the .oklog file.'''
#   global log_fid
#   if not options.quiet:
#     print(string)
#   if not options.no_log:
#     if log_fid is None:
#       if options.outputname is None or options.outputname == '':
#         return
#       else:
#         log_fid = '%s.oklog' % options.outputname.split('@')[0]
#     if not is_initiated:
#       init_display(log_fid)
#     f = open(log_fid, 'a')
#     f.write('%s\n' % string)
#     f.close()
# 
# Path: orbkit/options.py
# def get_options():
# def init_parser():
#   def default_if_called(option, opt, value, parser, default=1e4):
# def raise_error(string,error=IOError):
# def print_message(string):
# def check_options(error=raise_error,display=print_message,
#                   interactive=False,info=True,check_io=True):
#   def check_mo(attr):
# def check_if_exists(fid, what='',error=IOError,display=sys.stdout.write,
#                 interactive=False):
# def check_grid_output_compatibilty(error=raise_error): 


# Path: orbkit/read/tools.py
import gzip
import numpy
import os
import re
from orbkit.display import display
from orbkit.tools import *
from orbkit import options
  from .tar import is_tar_file, get_file_from_tar
  from io import TextIOWrapper

def descriptor_from_file(filename, index=0, ci_descriptor=False):

  if is_tar_file(filename):
    fname, _ = get_file_from_tar(filename, index=index, ci_descriptor=ci_descriptor)
  elif os.path.splitext(filename)[1] == '.gz':
    fname = gzip.open(filename, 'rt')
  else:
    fname = open(filename, 'r')
  return fname

def basissize(types, cart_spher):
  assert cart_spher in ['cartesian', 'pure'], 'Must specify eigther cartesian or pure spherical harmonics'
  size = 0
  for i in range(len(types)):
    l = spdfg_to_l[types[i]]
    if cart_spher == 'cartesian':
      size += (l+1)*(l+2)/2
    else:
      size += 2*l+1
  return size

def spin_check(spin,restricted,has_alpha,has_beta):
  '''Check if `spin` keyword is valid.
  '''
  if spin is not None:
    if restricted:
      raise IOError('The keyword `spin` is only supported for unrestricted calculations.')    
    if spin != 'alpha' and spin != 'beta':
      raise IOError('`spin=%s` is not a valid option' % spin)
    elif spin == 'alpha' and has_alpha:

      display('Reading only molecular orbitals of spin alpha.')