# -*- coding: utf-8 -*-

#  Copyright (C) 2017 The authors of Py-ChemShell
#
#  This file is part of Py-ChemShell.
#
#  Py-ChemShell is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation, either version 3 of the
#  License, or (at your option) any later version.
#
#  Py-ChemShell is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with Py-ChemShell.  If not, see
#  <http://www.gnu.org/licenses/>.

from sys    import modules
from ..base import constants

# all shall begin with a capital letter!

# 1 Ha = 27.21138505(60) eV (see 2010 CODATA)
Ha2eV         = 27.21138505

# 1 Ha = 4.35974434(19)E-18 J (see 2010 CODATA)
Ha2J          = 4.35974434E-18

# 1 eV = 1.602176634E-19 J (CODATA 2018)
eV2J          = 1.602176634E-19

# 1 eV = ~1239.84193 eV*nm/wavelength (CODATA 2015)
eV2nm = lambda x:1239.84193/x

# 1 Ha = 219474.6 reciprocal centimeters (https://cccbdb.nist.gov/hartree.asp)
Ha2wavenumber = 219474.6

# 1 Ha = 2625.49962 kJ/mol (CODATA 2014)
Ha2kJ_mol     = 2625.49962
Ha2kJ_mol     = 2625.499638

kJ_mol2Ha     = 1.0/Ha2kJ_mol
J_mol2Ha      = 0.001/Ha2kJ_mol

# 1 Ha = 627.509469 kcal/mol
# in TCS: Ha2kcal_mol   = 627.511525
Ha2kcal_mol   = 627.509469
kcal_mol2Ha   = 1.0/Ha2kcal_mol

# 1 Ångstrom = 1.889725989 Bohr
#Angstrom2Bohr = 1.889725989
Angstrom2Bohr = 1.88972666351
#Angstrom2Bohr = 1.8897

# 1 Bohr = 5.2917721092(17)E-11 m (see 2010 CODATA)
#Bohr2Angstrom = 0.52917721092
# Tcl-ChemShell: constant `AUTOANG` in src/chemsh/interface_fragment.c
Bohr2Angstrom = 0.52917706


# put them into module 'constants'
for attr in dir():
    if attr[0].isupper():
        setattr(constants, attr, getattr(modules[__name__], attr))


# convert any input unit to a.u. (key means the given one)
unit2au = { 'angstrom': Angstrom2Bohr,
            'Angstrom': Angstrom2Bohr,
            'ang'     : Angstrom2Bohr,
            'Ang'     : Angstrom2Bohr,
            'a.u.'    : 1.0,
            'A.U.'    : 1.0,
            'au'      : 1.0,
            'AU'      : 1.0,
            'bohr'    : 1.0,
            'Bohr'    : 1.0,
            'atomic'  : 1.0,
            'Atomic'  : 1.0,
            'ev'      : 1.0/Ha2eV,
            'eV'      : 1.0/Ha2eV,
            'kcal/mol': kcal_mol2Ha,
            'kJ/mol'  : kJ_mol2Ha,
            'kj/mol'  : kJ_mol2Ha,
            'kcal'    : kcal_mol2Ha,
             None     : Angstrom2Bohr }

# convert a.u. to any wanted unit (key means the requested one)
au2unit = { 'angstrom': Bohr2Angstrom,
            'Angstrom': Bohr2Angstrom,
            'A'       : Bohr2Angstrom,
            'ang'     : Bohr2Angstrom,
            'Ang'     : Bohr2Angstrom,
            'a.u.'    : 1.0,
            'au'      : 1.0,
            'bohr'    : 1.0,
            'atomic'  : 1.0,
            'ev'      : Ha2eV,
            'eV'      : Ha2eV,
            'kcal'    : Ha2kcal_mol,
            'kcal/mol': Ha2kcal_mol,
            'kJ/mol'  : Ha2kJ_mol,
            'kj/mol'  : Ha2kJ_mol,
             None     : Bohr2Angstrom }

unit2fs = { 'fs'          : 1.0,
            'femto'       : 1.0,
            'femtosecond' : 1.0,
            'femtoseconds': 1.0,
            'ps'          : 10.0**3,
            'pico'        : 10.0**3,
            'picosecond'  : 10.0**3,
            'picoseconds' : 10.0**3,
            'ns'          : 10.0**6,
            'nano'        : 10.0**6,
            'nanosecond'  : 10.0**6,
            'nanoseconds' : 10.0**6,
          }


fs2unit = { 'fs'          : 1.0,
            'femto'       : 1.0,
            'femtosecond' : 1.0,
            'femtoseconds': 1.0,
            'ps'          : 10.0**-3,
            'pico'        : 10.0**-3,
            'picosecond'  : 10.0**-3,
            'picoseconds' : 10.0**-3,
            'ns'          : 10.0**-6,
            'nano'        : 10.0**-6,
            'nanosecond'  : 10.0**-6,
            'nanoseconds' : 10.0**-6,
          }



