# Path: orbkit/tools.py
# def read_nist():
#   def rm_brackets(text,rm=['(',')','[',']']):
# def standard_mass(atom):
# def get_atom_symbol(atom):
# def l_deg(l=0,ao=None,cartesian_basis=True):
# def get_cart2sph(l,m):
# def remove_from_list(inlist, value):
# def validate_drv(drv):
# def each_ao_is_normalized(ao_spec):
# def prepare_ao_calc(ao_spec):    
# def is_mo_spec(mo):
# def moveaxis(array, source, target):
# def require(data,dtype='f',requirements='CA'):
# def convert(data,was_vector,N):
# def zeros(shape,name,hdf5_file=None,chunks=True):
# def reshape(data,shape,save_hdf5):
# def print2D(x,format='%+.2f ',start='\t',end=''):
# def pmat(matrix,vmax=lambda x: numpy.max(numpy.abs(x))):
# 
# 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()


import numpy
import ctypes
import time
import os
from ..tools import lquant
from ..display import display
from itertools import chain, combinations_with_replacement
  from numpy import moveaxis
  from orbkit.tools import moveaxis
    else:
      if not self.AO_blocks_2e:
        AOs = [range(self.Norb)]*4
        shells = [range(self.Nshells), range(self.Nshells), range(self.Nshells), range(self.Nshells)]
      else:
        AOs = [numpy.array(sorted(set(chain(*blocks)))) for blocks in zip(*self.AO_blocks_2e)]
    if not shells:
      shells = [sorted(set([self._ao2shell(ao) for ao in aos])) for aos in AOs]

    if max_mem:
      # get memory requirements for AO matrix (j,k,l)
      shape = []
      for shell in shells:
        Norb = numpy.sum(self.basis.shell_dims[shell[0]:shell[-1]+1])
        shape.append(Norb)
      mem_jkl = numpy.prod(shape[1:])*8/1000**2
      # get memory requirements for MO matrix (i,j,k,l)
      if asMO:
        block = self.MO_blocks_2e[0]
        mem_mo = [numpy.prod([len(i) for i in block])*8/1000.**2 for block in self.MO_blocks_2e]
        max_mem -= sum(mem_mo)
      # calculate max_dims (estimate 2*mem_jkl to account for ao2mo)
      max_dims = int(max_mem/(2*mem_jkl))
      if max_dims > shape[0]:
        # only 1 slice required
        max_dims = 0

    if not asMO or not max_dims:

      # calculate whole AO matrix

# Path: orbkit/tools.py
# def read_nist():
#   def rm_brackets(text,rm=['(',')','[',']']):
# def standard_mass(atom):
# def get_atom_symbol(atom):
# def l_deg(l=0,ao=None,cartesian_basis=True):
# def get_cart2sph(l,m):
# def remove_from_list(inlist, value):
# def validate_drv(drv):
# def each_ao_is_normalized(ao_spec):
# def prepare_ao_calc(ao_spec):    
# def is_mo_spec(mo):
# def moveaxis(array, source, target):
# def require(data,dtype='f',requirements='CA'):
# def convert(data,was_vector,N):
# def zeros(shape,name,hdf5_file=None,chunks=True):
# def reshape(data,shape,save_hdf5):
# def print2D(x,format='%+.2f ',start='\t',end=''):
# def pmat(matrix,vmax=lambda x: numpy.max(numpy.abs(x))):
# 
# 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/libcint_interface/ao_integrals.py
import numpy
import ctypes
import time
import os
from ..tools import lquant
from ..display import display
from itertools import chain, combinations_with_replacement
  from numpy import moveaxis
  from orbkit.tools import moveaxis

    else:
      if not self.AO_blocks_2e:
        AOs = [range(self.Norb)]*4
        shells = [range(self.Nshells), range(self.Nshells), range(self.Nshells), range(self.Nshells)]
      else:
        AOs = [numpy.array(sorted(set(chain(*blocks)))) for blocks in zip(*self.AO_blocks_2e)]
    if not shells:
      shells = [sorted(set([self._ao2shell(ao) for ao in aos])) for aos in AOs]

    if max_mem:
      # get memory requirements for AO matrix (j,k,l)
      shape = []
      for shell in shells:
        Norb = numpy.sum(self.basis.shell_dims[shell[0]:shell[-1]+1])
        shape.append(Norb)
      mem_jkl = numpy.prod(shape[1:])*8/1000**2
      # get memory requirements for MO matrix (i,j,k,l)
      if asMO:
        block = self.MO_blocks_2e[0]
        mem_mo = [numpy.prod([len(i) for i in block])*8/1000.**2 for block in self.MO_blocks_2e]
        max_mem -= sum(mem_mo)
      # calculate max_dims (estimate 2*mem_jkl to account for ao2mo)
      max_dims = int(max_mem/(2*mem_jkl))
      if max_dims > shape[0]:
        # only 1 slice required
        max_dims = 0

    if not asMO or not max_dims:

      # calculate whole AO matrix

      display('calculating 2-electron AO matrix for {:4d} shells along first index'.format(len(shells[0])))