예제 #1
0
    def test_reprreadprint(self):
        """Test read and print of BasisSet"""
        bs = self.basis_set
        test_file_gaussian = 'my_basis_gaussian.gbs.tmp'
        with open(test_file_gaussian, 'w') as f:
            f.write(bs.print('gaussian94'))
        bs1 = BasisSet.read(test_file_gaussian, 'gaussian94')
        self.assertEqual('<BasisSet my_basis_gaussian>', repr(bs1))
        self.assertEqual(bs, bs1)

        test_file_gamess = 'my_basis_gamess.gbs.tmp'
        with open(test_file_gamess, 'w') as f:
            f.write(bs.print('gamess'))
        bs2 = BasisSet.read(test_file_gamess, 'gamess')
        self.assertEqual(bs, bs2)

        test_file_bagel = 'my_basis_bagel.json.tmp'
        with open(test_file_bagel, 'w') as f:
            f.write(bs.print('bagel'))
        #bs3 = BasisSet.read(test_file_bagel, 'bagel')
        #self.assertEqual(bs, bs3)

        test_file_cfour = 'my_basis_cfour.GENBAS.tmp'
        with open(test_file_cfour, 'w') as f:
            f.write(bs.print('cfour'))
        bs4 = BasisSet.read(test_file_cfour, 'cfour')
        self.assertEqual(bs, bs4)

        self.assertRaises(SyntaxError, self.basis_set.print, 'turbomole')

        for tmp_file in glob('*.tmp'):
            os.remove(tmp_file)
예제 #2
0
    def setUp(self):
        bfs = BasisFunction('S', [1, 2], [0.5, 0.5])
        bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3])
        self.h = Basis('H', [bfs, bfp], 'simple')
        bfs = BasisFunction('S', [0.1, 0.4], [0.6, 0.4])
        bfp = BasisFunction('P', [0.1, 0.4, 3], [0.2, 0.3, 0.5])
        self.c = Basis('C', [bfs, bfp], 'simple')

        atoms = OrderedDict([('H', self.h), ('C', self.c)])
        self.basis_set = BasisSet(atoms)
예제 #3
0
    def test_read_basis_set(self):
        """Test reading a basis from a file"""
        tmp_basis_file = 'basis.gbs.tmp1'
        basis_set = BasisSet()
        basis_set['B'] = Basis('B', [BasisFunction('S', [0.2, 0.4], [0.3, 0.7])])
        open(tmp_basis_file, 'w').write(basis_set.print('gamess'))
        self.g.read_basis_set(tmp_basis_file)
        self.assertEqual(basis_set, self.g.basis_set)

        os.remove(tmp_basis_file)
예제 #4
0
    def test_read_basis_set(self):
        """Test reading a basis from a file"""
        tmp_basis_file = 'basis.gbs.tmp1'
        basis_set = BasisSet()
        basis_set['B'] = Basis('B',
                               [BasisFunction('S', [0.2, 0.4], [0.3, 0.7])])
        open(tmp_basis_file, 'w').write(basis_set.print('gamess'))
        self.g.read_basis_set(tmp_basis_file)
        self.assertEqual(basis_set, self.g.basis_set)

        os.remove(tmp_basis_file)
예제 #5
0
    def test_write_input(self):
        """Test writing an input to a basis file"""
        tmp_basis_file = 'basis.gbs.tmp'
        basis_set = BasisSet()
        basis_set['H'] = Basis('H', [BasisFunction('S', [1], [1])])
        basis_set['O'] = Basis(
            'O', [BasisFunction('S', [1], [1]),
                  BasisFunction('S', [2], [1])])
        basis_set['C'] = Basis('C', [
            BasisFunction('S', [1], [1]),
            BasisFunction('SP', [1, 2], [[0.4, 0.6], [0.1, 0.9]])
        ])
        with open(tmp_basis_file, 'w') as f:
            f.write(basis_set.print('gamess'))
        tmp_geom_file = 'geom.xyz.tmp'
        self.formaldehyde_xyz.write(tmp_geom_file)
        tmp_ecp_file = 'ecp.dat.tmp'
        ecp = """\
C-ECP GEN   10  2
    3      ----- d-ul potential     -----
      -10.0000000        1    357.3914469
      -60.2990287        2     64.6477389
      -10.4217834        2     16.0960833
O-ECP NONE"""
        with open(tmp_ecp_file, 'w') as f:
            f.write(ecp)
        tmp_options_file = 'options.dat.tmp'
        options_str = ' $CONTRL\n    SCFTYP=RHF\n $END\n\n $SCF\n    DIRSCF=.TRUE.\n $END\n\n'
        with open(tmp_options_file, 'w') as f:
            f.write(options_str)
        tmp_dat_file = 'dat.tmp'
        vec = ' $VEC\n12 23 31\n33241 32523 11.0\n $END'
        hess = ' $HESS\n32 43 987\n453 443 11.0\n $END'
        data = 'Hey\n' + vec + ' \n random other text\n' + hess + '\n more text\n122\n'
        with open(tmp_dat_file, 'w') as f:
            f.write(data)

        self.g.read(tmp_geom_file, tmp_basis_file, tmp_ecp_file,
                    tmp_options_file, tmp_dat_file)

        tmp_input_file = 'input.inp.tmp'
        self.g.write_input(tmp_input_file)

        os.remove(tmp_geom_file)
        os.remove(tmp_basis_file)
        os.remove(tmp_ecp_file)
        os.remove(tmp_options_file)
        os.remove(tmp_input_file)
        os.remove(tmp_dat_file)
예제 #6
0
    def setUp(self):
        bfs = BasisFunction('S', [1, 2], [0.5, 0.5])
        bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3])
        self.h = Basis('H', [bfs, bfp], 'simple')
        bfs = BasisFunction('S', [0.1, 0.4], [0.6, 0.4])
        bfp = BasisFunction('P', [0.1, 0.4, 3], [0.2, 0.3, 0.5])
        self.c = Basis('C', [bfs, bfp], 'simple')

        atoms = OrderedDict([('H', self.h), ('C', self.c)])
        self.basis_set = BasisSet(atoms)
예제 #7
0
    def test_write_input(self):
        """Test writing an input to a basis file"""
        tmp_basis_file = 'basis.gbs.tmp'
        basis_set = BasisSet()
        basis_set['H'] = Basis('H', [BasisFunction('S', [1], [1])])
        basis_set['O'] = Basis('O', [BasisFunction('S', [1], [1]), BasisFunction('S', [2], [1])])
        basis_set['C'] = Basis('C', [BasisFunction('S', [1], [1]), BasisFunction('SP', [1, 2], [0.4, 0.6], [0.1, 0.9])])
        open(tmp_basis_file, 'w').write(basis_set.print('gamess'))
        tmp_geom_file = 'geom.xyz.tmp'
        self.formaldehyde_xyz.write(tmp_geom_file)
        tmp_ecp_file = 'ecp.dat.tmp'
        ecp = """\
C-ECP GEN   10  2
    3      ----- d-ul potential     -----
      -10.0000000        1    357.3914469
      -60.2990287        2     64.6477389
      -10.4217834        2     16.0960833
O-ECP NONE"""
        open(tmp_ecp_file, 'w').write(ecp)
        tmp_options_file = 'options.dat.tmp'
        options_str = ' $CONTRL\n    SCFTYP=RHF\n $END\n\n $SCF\n    DIRSCF=.TRUE.\n $END\n\n'
        open(tmp_options_file, 'w').write(options_str)
        tmp_dat_file = 'dat.tmp'
        vec = ' $VEC\n12 23 31\n33241 32523 11.0\n $END'
        hess = ' $HESS\n32 43 987\n453 443 11.0\n $END'
        data = 'Hey\n' + vec + ' \n random other text\n' + hess + '\n more text\n122\n'
        open(tmp_dat_file, 'w').write(data)

        self.g.read(tmp_geom_file, tmp_basis_file, tmp_ecp_file, tmp_options_file, tmp_dat_file)

        tmp_input_file = 'input.inp.tmp'
        self.g.write_input(tmp_input_file)

        os.remove(tmp_geom_file)
        os.remove(tmp_basis_file)
        os.remove(tmp_ecp_file)
        os.remove(tmp_options_file)
        os.remove(tmp_input_file)
        os.remove(tmp_dat_file)
예제 #8
0
    def test_reprreadprint(self):
        """Test read and print of BasisSet"""
        bs = self.basis_set
        test_file_gaussian = 'my_basis_gaussian.gbs.tmp'
        with open(test_file_gaussian, 'w') as f:
            f.write(bs.print('gaussian94'))
        bs1 = BasisSet.read_file(test_file_gaussian, 'gaussian94')
        self.assertEqual('<BasisSet my_basis_gaussian.gbs>', repr(bs1))
        self.assertEqual(bs, bs1)

        test_file_gamess = 'my_basis_gamess.gbs.tmp'
        with open(test_file_gamess, 'w') as f:
            f.write(bs.print('gamess'))
        bs2 = BasisSet.read_file(test_file_gamess, 'gamess')
        self.assertEqual(bs, bs2)

        test_file_bagel = 'my_basis_bagel.json.tmp'
        with open(test_file_bagel, 'w') as f:
            f.write(bs.print('bagel'))
        bs3 = BasisSet.read_file(test_file_bagel, 'bagel')
        self.assertEqual(bs, bs3)

        test_file_cfour = 'my_basis_cfour.GENBAS.tmp'
        with open(test_file_cfour, 'w') as f:
            f.write(bs.print('cfour'))
        bs4 = BasisSet.read_file(test_file_cfour, 'cfour')
        self.assertEqual(bs, bs4)

        test_file_molpro = 'my_basis_molpro.bas.tmp'
        with open(test_file_molpro, 'w') as f:
            f.write(bs.print('molpro'))
        bs4 = BasisSet.read_file(test_file_molpro, 'molpro')
        self.assertEqual(bs, bs4)

        self.assertRaises(ValueError, self.basis_set.print, 'turbomole')

        for tmp_file in glob('*.tmp'):
            os.remove(tmp_file)
예제 #9
0
 def test_getsetdeleq(self):
     """Test __getitem__, __setitem__, __delitem__, and __eq__"""
     bfs = BasisFunction('S', [0.2, 0.4], [0.3, 0.7])
     b = Basis('B', [bfs])
     self.basis_set['B'] = b
     self.assertEqual(self.c, self.basis_set['C'])
     self.assertEqual(b, self.basis_set['B'])
     del self.basis_set['B']
     self.assertRaises(KeyError, self.basis_set.__getitem__, 'B')
     bfs = BasisFunction('S', [1, 2], [0.5, 0.5])
     bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3])
     h = Basis('H', [bfs, bfp])
     bfs = BasisFunction('S', [0.1, 0.4], [0.6, 0.4])
     bfp = BasisFunction('P', [0.1, 0.4, 3],
                         [[0.2, 0.3, 0.5], [0.1, 0.3, 0.6]])
     c = Basis('C', [bfs, bfp])
     atoms = OrderedDict([('H', h), ('C', c)])
     atoms = OrderedDict([('H', h)])
     basis_set2 = BasisSet(atoms)
     self.assertEqual(basis_set2, self.basis_set)
예제 #10
0
class TestBasisSet(unittest.TestCase):
    """Test the BasisSet class"""
    def setUp(self):
        bfs = BasisFunction('S', [1, 2], [0.5, 0.5])
        bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3])
        self.h = Basis('H', [bfs, bfp], 'simple')
        bfs = BasisFunction('S', [0.1, 0.4], [0.6, 0.4])
        bfp = BasisFunction('P', [0.1, 0.4, 3], [0.2, 0.3, 0.5])
        self.c = Basis('C', [bfs, bfp], 'simple')

        atoms = OrderedDict([('H', self.h), ('C', self.c)])
        self.basis_set = BasisSet(atoms)

    def test_getsetdeleq(self):
        """Test __getitem__, __setitem__, __delitem__, and __eq__"""
        bfs = BasisFunction('S', [0.2, 0.4], [0.3, 0.7])
        b = Basis('B', [bfs])
        self.basis_set['B'] = b
        self.assertEqual(self.c, self.basis_set['C'])
        self.assertEqual(b, self.basis_set['B'])
        del self.basis_set['B']
        self.assertRaises(KeyError, self.basis_set.__getitem__, 'B')
        bfs = BasisFunction('S', [1, 2], [0.5, 0.5])
        bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3])
        h = Basis('H', [bfs, bfp])
        bfs = BasisFunction('S', [0.1, 0.4], [0.6, 0.4])
        bfp = BasisFunction('P', [0.1, 0.4, 3],
                            [[0.2, 0.3, 0.5], [0.1, 0.3, 0.6]])
        c = Basis('C', [bfs, bfp])
        atoms = OrderedDict([('H', h), ('C', c)])
        atoms = OrderedDict([('H', h)])
        basis_set2 = BasisSet(atoms)
        self.assertEqual(basis_set2, self.basis_set)

    def test_iter(self):
        bs_it = iter(self.basis_set)
        self.assertEqual(self.h, next(bs_it))
        self.assertEqual(self.c, next(bs_it))

    def test_check_basis_set(self):
        """Test check_basis_set"""
        self.assertRaises(SyntaxError, BasisSet.check_basis_set, ({'H': 1}))
        self.assertRaises(SyntaxError, BasisSet.check_basis_set,
                          (OrderedDict([('H', 1)])))

    def test_change_basis_set(self):
        """Test change_basis_set"""
        atoms = OrderedDict([('C', Basis('C',
                                         [BasisFunction('S', [1], [1])]))])
        self.basis_set.change_basis_set(atoms)
        bad_bs = OrderedDict([('H', 1)])
        self.assertRaises(SyntaxError, self.basis_set.change_basis_set,
                          (bad_bs, ))

    def test_reprreadprint(self):
        """Test read and print of BasisSet"""
        bs = self.basis_set
        test_file_gaussian = 'my_basis_gaussian.gbs.tmp'
        with open(test_file_gaussian, 'w') as f:
            f.write(bs.print('gaussian94'))
        bs1 = BasisSet.read(test_file_gaussian, 'gaussian94')
        self.assertEqual('<BasisSet my_basis_gaussian>', repr(bs1))
        self.assertEqual(bs, bs1)

        test_file_gamess = 'my_basis_gamess.gbs.tmp'
        with open(test_file_gamess, 'w') as f:
            f.write(bs.print('gamess'))
        bs2 = BasisSet.read(test_file_gamess, 'gamess')
        self.assertEqual(bs, bs2)

        test_file_bagel = 'my_basis_bagel.json.tmp'
        with open(test_file_bagel, 'w') as f:
            f.write(bs.print('bagel'))
        bs3 = BasisSet.read(test_file_bagel, 'bagel')
        self.assertEqual(bs, bs3)

        test_file_cfour = 'my_basis_cfour.GENBAS.tmp'
        with open(test_file_cfour, 'w') as f:
            f.write(bs.print('cfour'))
        bs4 = BasisSet.read(test_file_cfour, 'cfour')
        self.assertEqual(bs, bs4)

        test_file_molpro = 'def2-svp.molpro'
        bs5 = BasisSet.read(test_file_molpro, 'molpro')
        self.assertEqual(len(bs5['O']), 6)

        self.assertRaises(SyntaxError, self.basis_set.print, 'turbomole')

        for tmp_file in glob('*.tmp'):
            os.remove(tmp_file)

    def test_values(self):
        """Test values"""
        vals = [[
            np.array([[1.0, 0.5], [2.0, 0.5]]),
            np.array([[0.01, 0.3], [0.2, 0.4], [1.0, 0.3]])
        ],
                [
                    np.array([[0.1, 0.6], [0.4, 0.4]]),
                    np.array([[0.1, 0.2], [0.4, 0.3], [3.0, 0.5]])
                ]]
        self.assertEqual(vals[0][0][0][1], self.basis_set.values()[0][0][0][1])
        self.assertEqual(vals[0][1][1][0], self.basis_set.values()[0][1][1][0])
예제 #11
0
class TestBasisSet(unittest.TestCase):
    """Test the BasisSet class"""
    def setUp(self):
        bfs = BasisFunction('S', [1, 2], [0.5, 0.5])
        bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3])
        self.h = Basis('H', [bfs, bfp], 'simple')
        bfs = BasisFunction('S', [0.1, 0.4], [0.6, 0.4])
        bfp = BasisFunction('P', [0.1, 0.4, 3], [0.2, 0.3, 0.5])
        self.c = Basis('C', [bfs, bfp], 'simple')

        atoms = OrderedDict([('H', self.h), ('C', self.c)])
        self.basis_set = BasisSet(atoms)

    def test_getsetdeleq(self):
        """Test __getitem__, __setitem__, __delitem__, and __eq__"""
        bfs = BasisFunction('S', [0.2, 0.4], [0.3, 0.7])
        b = Basis('B', [bfs])
        self.basis_set['B'] = b
        self.assertEqual(self.c, self.basis_set['C'])
        self.assertEqual(b, self.basis_set['B'])
        del self.basis_set['B']
        self.assertRaises(KeyError, self.basis_set.__getitem__, 'B')
        bfs = BasisFunction('S', [1, 2], [0.5, 0.5])
        bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3])
        h = Basis('H', [bfs, bfp])
        bfs = BasisFunction('S', [0.1, 0.4], [0.6, 0.4])
        bfp = BasisFunction('P', [0.1, 0.4, 3], [0.2, 0.3, 0.5], [0.1, 0.3, 0.6])
        c = Basis('C', [bfs, bfp])
        atoms = OrderedDict([('H', h), ('C', c)])
        atoms = OrderedDict([('H', h)])
        basis_set2 = BasisSet(atoms)
        self.assertEqual(basis_set2, self.basis_set)

    def test_iter(self):
        bs_it = iter(self.basis_set)
        self.assertEqual(self.h, next(bs_it))
        self.assertEqual(self.c, next(bs_it))

    def test_check_basis_set(self):
        """Test check_basis_set"""
        self.assertRaises(SyntaxError, BasisSet.check_basis_set, ({'H': 1}))
        self.assertRaises(SyntaxError, BasisSet.check_basis_set, (OrderedDict([('H', 1)])))

    def test_change_basis_set(self):
        """Test change_basis_set"""
        atoms = OrderedDict([('C', Basis('C', [BasisFunction('S', [1], [1])]))])
        self.basis_set.change_basis_set(atoms)
        bad_bs = OrderedDict([('H', 1)])
        self.assertRaises(SyntaxError, self.basis_set.change_basis_set, (bad_bs,))

    def test_reprreadprint(self):
        """Test read and print of BasisSet"""
        bs = self.basis_set
        test_file_gaussian = 'my_basis_gaussian.gbs.tmp'
        with open(test_file_gaussian, 'w') as f:
            f.write(bs.print('gaussian94'))
        bs1 = BasisSet.read(test_file_gaussian, 'gaussian94')
        self.assertEqual('<BasisSet my_basis_gaussian>', repr(bs1))
        self.assertEqual(bs, bs1)

        test_file_gamess = 'my_basis_gamess.gbs.tmp'
        with open(test_file_gamess, 'w') as f:
            f.write(bs.print('gamess'))
        bs2 = BasisSet.read(test_file_gamess, 'gamess')
        self.assertEqual(bs, bs2)

        test_file_bagel = 'my_basis_bagel.json.tmp'
        with open(test_file_bagel, 'w') as f:
            f.write(bs.print('bagel'))
        #bs3 = BasisSet.read(test_file_bagel, 'bagel')
        #self.assertEqual(bs, bs3)

        test_file_cfour = 'my_basis_cfour.GENBAS.tmp'
        with open(test_file_cfour, 'w') as f:
            f.write(bs.print('cfour'))
        bs4 = BasisSet.read(test_file_cfour, 'cfour')
        self.assertEqual(bs, bs4)

        self.assertRaises(SyntaxError, self.basis_set.print, 'turbomole')

        for tmp_file in glob('*.tmp'):
            os.remove(tmp_file)

    def test_values(self):
        """Test values"""
        vals = [[np.array([[1.0, 0.5], [2.0, 0.5]]),
                 np.array([[0.01, 0.3], [0.2, 0.4], [1.0, 0.3]])],
                [np.array([[0.1, 0.6], [0.4, 0.4]]),
                 np.array([[0.1, 0.2], [0.4, 0.3], [3.0, 0.5]])]]
        self.assertEqual(vals[0][0][0][1], self.basis_set.values()[0][0][0][1])
        self.assertEqual(vals[0][1][1][0], self.basis_set.values()[0][1][1][0])