#  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

# ChemShell parameters #

# ChemShell system
STRLEN   = 256
BLANCSTR = " "*STRLEN

# Chemical fragments
NTYPES   = 4
MAXCONN  = 14

# accuracy
SMALL = 1.0E-10
MEDIUM = 1.0E-7
LARGE = 1.0E-4

# end of ChemShell parameters #


# collection of the above parameters
dbuff = dict(zip(dir(), [ getattr(modules[__name__], attr) for attr in dir() if attr.isupper() ]))

class _Constants:
    '''Container of constants'''

    class ConstError(TypeError):
        pass

    def __init__(self, **kwargs):
        '''Initialise'''
        for key, val in kwargs.items():
            setattr(self, key, val)

    def __setattr__(self, name, value):
        # YL: Python 3.x has removed __dict__.has_key()
        if name in self.__dict__:
            # TODO: use standard ChemShell errors
            raise self.ConstError("The constant consts.%s is immutable!"%name)
        self.__dict__[name] = value


# redirecting the current module to a '_Constants' instance which is initialised with dbuff
# here __name__ is 'consts'
modules[__name__] = _Constants(**dbuff)



