#
# Author: Qiming Sun <osirpt.sun@gmail.com>
#

import unittest
import numpy
from pyscf import gto
from pyscf import scf
from pyscf.symm import addons

mol = gto.Mole()
mol.build(
    verbose = 0,
    atom = [
    ["O" , (0. , 0.     , 0.)],
    [1   , (0. , -0.757 , 0.587)],
    [1   , (0. , 0.757  , 0.587)] ],
    basis = 'cc-pvdz',
    symmetry = 1,
)

mf = scf.RHF(mol)
mf.scf()


class KnowValues(unittest.TestCase):
    def test_label_orb_symm(self):
        l = addons.label_orb_symm(mol, mol.irrep_name, mol.symm_orb, mf.mo_coeff)
        lab0 = ['A1', 'A1', 'B1', 'A1', 'B2', 'A1', 'B1', 'B1',
                'A1', 'A1', 'B2', 'B1', 'A1', 'A2', 'B2', 'A1',
                'B1', 'B1', 'A1', 'B2', 'A2', 'A1', 'A1', 'B1']
        self.assertEqual(l, lab0)

    def test_symmetrize_orb(self):
        c = addons.symmetrize_orb(mol, mf.mo_coeff)
        self.assertTrue(numpy.allclose(c, mf.mo_coeff))
        numpy.random.seed(1)
        c = addons.symmetrize_orb(mol,
                                  numpy.random.random((mf.mo_coeff.shape)))
        self.assertAlmostEqual(numpy.linalg.norm(c), 10.148003411042838)

    def test_route(self):
        orbsym = [0, 3, 0, 2, 5, 6]
        res = addons.route(7, 3, orbsym)
        self.assertEqual(res, [0, 3, 4])


if __name__ == "__main__":
    print("Full Tests for symm.addons")
    unittest.main()


#
# Author: Qiming Sun <osirpt.sun@gmail.com>
#

import unittest
import numpy
from pyscf import gto
from pyscf import scf
from pyscf.symm import addons

mol = gto.Mole()
mol.build(
    verbose = 0,
    atom = [
    ["O" , (0. , 0.     , 0.)],
    [1   , (0. , -0.757 , 0.587)],
    [1   , (0. , 0.757  , 0.587)] ],
    basis = 'cc-pvdz',
    symmetry = 1,
)

mf = scf.RHF(mol)
mf.scf()


class KnowValues(unittest.TestCase):
    def test_label_orb_symm(self):
        l = addons.label_orb_symm(mol, mol.irrep_name, mol.symm_orb, mf.mo_coeff)
        lab0 = ['A1', 'A1', 'B1', 'A1', 'B2', 'A1', 'B1', 'B1',
                'A1', 'A1', 'B2', 'B1', 'A1', 'A2', 'B2', 'A1',
                'B1', 'B1', 'A1', 'B2', 'A2', 'A1', 'A1', 'B1']
        self.assertEqual(l, lab0)

    def test_symmetrize_orb(self):
        c = addons.symmetrize_orb(mol, mf.mo_coeff)
        self.assertTrue(numpy.allclose(c, mf.mo_coeff))
        numpy.random.seed(1)
        c = addons.symmetrize_orb(mol,
                                  numpy.random.random((mf.mo_coeff.shape)))
        self.assertAlmostEqual(numpy.linalg.norm(c), 10.148003411042838)

    def test_symmetrize_space(self):
        from pyscf import gto, symm, scf
        mol = gto.M(atom = 'C  0  0  0; H  1  1  1; H -1 -1  1; H  1 -1 -1; H -1  1 -1',
                    basis = 'sto3g', verbose=0)
        mf = scf.RHF(mol).run()
        mol.build(0, 0, symmetry='D2')
        mo = symm.symmetrize_space(mol, mf.mo_coeff)
        irreps = symm.label_orb_symm(mol, mol.irrep_name, mol.symm_orb, mo)
        self.assertEqual(irreps, ['A','A','A','B1','B1','B2','B2','B3','B3'])

    def test_route(self):
        orbsym = [0, 3, 0, 2, 5, 6]
        res = addons.route(7, 3, orbsym)
        self.assertEqual(res, [0, 3, 4])


if __name__ == "__main__":
    print("Full Tests for symm.addons")
    unittest.main()


Test for symm.symmetrize_space