def test_decontracted(self): """ Test decontracting of basis """ # Check that s and p are split upon decontraction self.assertEqual(len(self.basis.decontracted()), 11) # Check that decontraction removes duplicates basis2 = Basis('C', [self.bfs, self.bfp, self.bfsp, self.bfs, self.bfp, self.bfsp]) self.assertEqual(self.basis.decontracted(), basis2.decontracted())
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_decontracted(self): """ Test decontracting of basis """ # Check that s and p are split upon decontraction self.assertEqual(len(self.basis.decontracted()), 11) # Check that decontraction removes duplicates basis2 = Basis( 'C', [self.bfs, self.bfp, self.bfsp, self.bfs, self.bfp, self.bfsp]) self.assertEqual(self.basis.decontracted(), basis2.decontracted())
def test_lengetsetdeleq(self): """Test __len__, __getitem__ and __setitem__, __delitem__, __eq__""" self.assertEqual(3, len(self.basis)) bf = BasisFunction('F', [4, 9], [0.1, 0.9]) self.basis[0] = bf self.assertEqual(bf, self.basis[0]) self.assertRaises(SyntaxError, self.basis.__setitem__, 0, 1) del self.basis[2] self.assertRaises(IndexError, self.basis.__getitem__, 2) basis = Basis('C', [self.bfsp]) basis2 = Basis('C', [self.bfsp]) self.assertEqual(basis, basis2)
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)
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_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_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)
class TestBasis(unittest.TestCase): """Tests a basis, which contains BasisFunctions""" def setUp(self): self.bfs = BasisFunction('S', [1, 2], [0.5, 0.5]) self.bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3]) self.bfsp = BasisFunction('SP', [0.1, 0.4, 3], [0.2, 0.3, 0.5], [0.1, 0.3, 0.6]) self.basis = Basis('C', [self.bfs, self.bfp, self.bfsp]) def test_lengetsetdeleq(self): """Test __len__, __getitem__ and __setitem__, __delitem__, __eq__""" self.assertEqual(3, len(self.basis)) bf = BasisFunction('F', [4, 9], [0.1, 0.9]) self.basis[0] = bf self.assertEqual(bf, self.basis[0]) self.assertRaises(SyntaxError, self.basis.__setitem__, 0, 1) del self.basis[2] self.assertRaises(IndexError, self.basis.__getitem__, 2) basis = Basis('C', [self.bfsp]) basis2 = Basis('C', [self.bfsp]) self.assertEqual(basis, basis2) def test_reprstrprint(self): """Test print""" c_gamess = '''C S 2 1 1.0000000 0.5000000 2 2.0000000 0.5000000 P 3 1 0.0100000 0.3000000 2 0.2000000 0.4000000 3 1.0000000 0.3000000 SP 3 1 0.1000000 0.2000000 0.1000000 2 0.4000000 0.3000000 0.3000000 3 3.0000000 0.5000000 0.6000000 ''' c_gaussian94 = '''C 0 S 2 1.0000000 0.5000000 2.0000000 0.5000000 P 3 0.0100000 0.3000000 0.2000000 0.4000000 1.0000000 0.3000000 SP 3 0.1000000 0.2000000 0.1000000 0.4000000 0.3000000 0.3000000 3.0000000 0.5000000 0.6000000 ''' self.assertEqual('<Basis C 3>', repr(self.basis)) self.assertEqual(c_gaussian94, str(self.basis)) self.assertEqual(c_gamess, self.basis.print('gamess'))
def setUp(self): self.bfs = BasisFunction('S', [1, 2], [0.5, 0.5]) self.bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3]) self.bfsp = BasisFunction('SP', [0.1, 0.4, 3], [[0.2, 0.3, 0.5], [0.1, 0.3, 0.6]]) self.basis = Basis('C', [self.bfs, self.bfp, self.bfsp])
class TestBasis(unittest.TestCase): """Tests a basis, which contains BasisFunctions""" def setUp(self): self.bfs = BasisFunction('S', [1, 2], [0.5, 0.5]) self.bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3]) self.bfsp = BasisFunction('SP', [0.1, 0.4, 3], [[0.2, 0.3, 0.5], [0.1, 0.3, 0.6]]) self.basis = Basis('C', [self.bfs, self.bfp, self.bfsp]) def test_lengetsetdeleq(self): """Test __len__, __getitem__ and __setitem__, __delitem__, __eq__""" self.assertEqual(3, len(self.basis)) bf = BasisFunction('F', [4, 9], [0.1, 0.9]) self.basis[0] = bf self.assertEqual(bf, self.basis[0]) self.assertRaises(SyntaxError, self.basis.__setitem__, 0, 1) del self.basis[2] self.assertRaises(IndexError, self.basis.__getitem__, 2) basis = Basis('C', [self.bfsp]) basis2 = Basis('C', [self.bfsp]) self.assertEqual(basis, basis2) def test_reprstrprint(self): """Test print""" c_gamess = '''C S 2 1 1.0000000 0.5000000 2 2.0000000 0.5000000 P 3 1 0.0100000 0.3000000 2 0.2000000 0.4000000 3 1.0000000 0.3000000 SP 3 1 0.1000000 0.2000000 0.1000000 2 0.4000000 0.3000000 0.3000000 3 3.0000000 0.5000000 0.6000000 ''' c_gaussian94 = '''C 0 S 2 1.0000000 0.5000000 2.0000000 0.5000000 P 3 0.0100000 0.3000000 0.2000000 0.4000000 1.0000000 0.3000000 SP 3 0.1000000 0.2000000 0.1000000 0.4000000 0.3000000 0.3000000 3.0000000 0.5000000 0.6000000 ''' self.assertEqual('<Basis C 3>', repr(self.basis)) self.assertEqual(c_gaussian94, str(self.basis)) self.assertEqual(c_gamess, self.basis.print('gamess')) def test_decontracted(self): """ Test decontracting of basis """ # Check that s and p are split upon decontraction self.assertEqual(len(self.basis.decontracted()), 11) # Check that decontraction removes duplicates basis2 = Basis( 'C', [self.bfs, self.bfp, self.bfsp, self.bfs, self.bfp, self.bfsp]) self.assertEqual(self.basis.decontracted(), basis2.decontracted())
def setUp(self): self.bfs = BasisFunction('S', [1, 2], [0.5, 0.5]) self.bfp = BasisFunction('P', [0.01, 0.2, 1], [0.3, 0.4, 0.3]) self.bfsp = BasisFunction('SP', [0.1, 0.4, 3], [0.2, 0.3, 0.5], [0.1, 0.3, 0.6]) self.basis = Basis('C', [self.bfs, self.bfp, self.bfsp])