#  Copyright (C) 2021 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/>.



pbcs = [ 'no'                  ,
         '0D'                  ,
         'cubic'               ,
         'orthorhombic'        ,
         'parallelepiped'      ,
         '3D'                  ,
         'truncated_octahedron',
         'rhombic_dodecahedron',
         '2D'                  , # no periodicity in z
         'x-y_parallelogram'   , # no periodicity in z
         'xy_parallelogram'    , # no periodicity in z
         'hexagonal_prism' ]

def verifyRequestedPBC(pbc, ndimensions):
    '''Verify if the PBC requested by the user is supported in ChemShell'''

    from numpy import char

    pbc = pbc.strip().lower()

    if pbc not in char.lower(pbcs):
        if ndimensions == 0:
            default = 'no'
        if ndimensions == 2:
            default = 'x-y_parallelogram'
        if ndimensions == 3:
            default = 'parallelepiped'
        if pbc:
            print("\n >>> WARNING: We do not yet support periodic boundary condition")
            print("              \"{}\". \"{}\" will be used for".format(pbc, default))
            print("              {} system by default.\n".format(ndimensions))
        return default

    else:
        if ndimensions == 2:
            if pbc != 'x-y_parallelogram':
                print("\n >>> x-y_parallelogram PBC forced for 2D system\n")
                pbc = 'x-y_parallelogram'
        if ndimensions == 0:
            if pbc != 'no':
                print("\n >>> no PBC for non-periodic system\n")
                pbc = 'no'
        return pbc
