def test_create_representation_bond(self): with self.assertRaisesRegexp(ValueError, r'atomics.*only representable as.*Cannot create'): Molecule.from_z_matrix('O', create_representation=True) mol = Molecule.from_z_matrix('H\nH 1 0.9', create_representation=True) self.assertEqual(len(mol.internal_representations), 1) self.assertEqual(len(mol.internal_representations[0]), 1)
def test_zmat(self): self.assertEqual( Molecule([Atom("O", [0.0, 0.0, 0.0])]), Molecule.from_z_matrix(""" O """ ) ) self.assertEqual( Molecule([ Atom("O", [0.0, 0.0, 0.0]), Atom("O", [0.0, 0.0, 1.0]) ]), Molecule.from_z_matrix(""" O1 O2 O1 1.0 """ ) ) self.assertEqual( Molecule([ Atom("O", [0.0, 0.0, 0.0]), Atom("H", [0.0, 0.0, 1.0]), Atom("H", [0.0, -1.0, 0.0]) ]), Molecule.from_z_matrix(""" O H1 O 1.0 H2 O 1.0 H1 90 """ ) )
def test_future_errors(self): with self.assertRaisesRegexp(ValueError, r'Ambiguous atom identifier in z-matrix'): Molecule.from_z_matrix(""" O H O 1.0 H H 1.0 O 3.7 """)
def test_create_representation_bond(self): with self.assertRaisesRegexp( ValueError, r'atomics.*only representable as.*Cannot create'): Molecule.from_z_matrix('O', create_representation=True) mol = Molecule.from_z_matrix('H\nH 1 0.9', create_representation=True) self.assertEqual(len(mol.internal_representations), 1) self.assertEqual(len(mol.internal_representations[0]), 1)
def test_errors_18(self): with self.assertRaisesRegexp(IndexError, r"z-matrix index '0' is out of range"): Molecule.from_z_matrix(''' O H 1 0.93 C 2 1.23 1 104.5 B 2 1.35 1 89.5 0 84.3 ''', create_representation=True)
def test_errors_19(self): with self.assertRaisesRegexp(InvalidZMatrixException, r'atom indices in z-matrix line'): Molecule.from_z_matrix(''' O H 1 0.93 C 2 1.23 1 104.5 B 2 1.35 1 89.5 1 84.3 ''', create_representation=True)
def test_future_errors(self): with self.assertRaisesRegexp(ValueError, r'Ambiguous atom identifier in z-matrix'): Molecule.from_z_matrix( """ O H O 1.0 H H 1.0 O 3.7 """ )
def test_errors_11(self): with self.assertRaisesRegexp(ValueError, r'Ambiguous atom identifier in z-matrix'): Molecule.from_z_matrix(""" O H O 1.0 H O -1.0 H 37 O2 H 1.5 O 150 H 25 """)
def test_errors_11(self): with self.assertRaisesRegexp(ValueError, r'Ambiguous atom identifier in z-matrix'): Molecule.from_z_matrix( """ O H O 1.0 H O -1.0 H 37 O2 H 1.5 O 150 H 25 """ )
def test_misc(self): # getitem self.assertEqual(Molecule.from_z_matrix("O")[0].symbol, "O") # contains mol = Molecule.from_z_matrix("O") self.assertIn(mol[0], mol) self.assertNotIn(Atom("H", 0, 0, 0), mol) # less than self.assertLess(mol, Molecule("O 0.0 0.0 1.0"))
def test_displace(self): mol = Molecule.from_z_matrix('H') mol.displace(Vector(1., -1., 0.)) self.assertEqual(mol, Molecule("H 1 -1 0")) mol = Molecule.from_z_matrix('H\nH 1 0.9') mol.displace(Vector(1., 0., 0., 1., 0., 0.)) self.assertEqual(mol, Molecule("H 1 0 0.0\nH 1 0 0.9 ")) with self.assertRaisesRegexp(ValueError, 'dimension mismatch'): mol.displace(Vector(1., 0., 0.)) with self.assertRaises(TypeError): mol.displace(Matrix(1., 0., 0.))
def test_bond_length_2(self): mol = Molecule.from_z_matrix('H\nO 1 0.9', create_representation=True) mol.recenter() # 'randomize' the position in xyz space to avoid miniscule displacement amounts mol.rotate(Vector(1,2,1), 32.*Degrees) coord = mol.internal_representation[0] assert_has_valid_b_tensor(coord, 2)
def test_bond_length_2(self): mol = Molecule.from_z_matrix('H\nO 1 0.9', create_representation=True) mol.recenter() # 'randomize' the position in xyz space to avoid miniscule displacement amounts mol.rotate(Vector(1, 2, 1), 32. * Degrees) coord = mol.internal_representation[0] assert_has_valid_b_tensor(coord, 2)
def test_2_torsions_4_dry_run(self): mol = Molecule.from_z_matrix(''' O H 1 0.93 C 2 1.23 1 104.5 B 3 1.35 2 89.5 1 83.2 O 4 1.25 3 89.5 2 -23.2 ''', create_representation=True) mol.recenter() order = 4 coord = mol.internal_representation[5] natoms = mol.natoms btens = coord.parent_representation.b_tensor() analytic_tensor = Tensor(shape=(3 * natoms, ) * order) for cartcoords in product(coord.variables, repeat=order): analytic_tensor[tuple( c.index for c in cartcoords)] = btens[(coord, ) + cartcoords] coord = mol.internal_representation[8] natoms = mol.natoms btens = coord.parent_representation.b_tensor() analytic_tensor = Tensor(shape=(3 * natoms, ) * order) for cartcoords in product(coord.variables, repeat=order): analytic_tensor[tuple( c.index for c in cartcoords)] = btens[(coord, ) + cartcoords]
def test_create_representation_tors_2(self): mol = Molecule.from_z_matrix(""" H O 1 1.0 O 2 1.0 1 90 H 3 1.0 2 90 1 -90 """, create_representation=True ) self.assertEqual(mol.internal_representations[0].coords[5].value_with_units.in_units(AngularUnit.default), (-90.*Degrees).in_units(AngularUnit.default))
def test_bond_length_7_dry_run(self): self.setUp() order = 7 mol = Molecule.from_z_matrix('H\nO 1 0.9', create_representation=True) mol.recenter() coord = mol.internal_representation[0] natoms = mol.natoms btens = coord.parent_representation.b_tensor() analytic_tensor = Tensor(shape=(3*natoms,)*order) for cartcoords in product(coord.variables, repeat=order): analytic_tensor[tuple(c.index for c in cartcoords)] = btens[(coord,) + cartcoords]
def test_bond_length_7_dry_run(self): self.setUp() order = 7 mol = Molecule.from_z_matrix('H\nO 1 0.9', create_representation=True) mol.recenter() coord = mol.internal_representation[0] natoms = mol.natoms btens = coord.parent_representation.b_tensor() analytic_tensor = Tensor(shape=(3 * natoms, ) * order) for cartcoords in product(coord.variables, repeat=order): analytic_tensor[tuple( c.index for c in cartcoords)] = btens[(coord, ) + cartcoords]
def test_create_representation_tors_2(self): mol = Molecule.from_z_matrix(""" H O 1 1.0 O 2 1.0 1 90 H 3 1.0 2 90 1 -90 """, create_representation=True) self.assertEqual( mol.internal_representations[0].coords[5].value_with_units. in_units(AngularUnit.default), (-90. * Degrees).in_units(AngularUnit.default))
def test_create_rep_hooh(self): mol = Molecule.from_z_matrix(""" H O 1 0.963242 O 2 1.449863 1 100.120071 H 3 0.963242 2 100.120071 1 -67.344079 """, create_representation=True) rep = mol.internal_representation deg_to_def = Degrees.to(AngularUnit.default) self.assertAlmostEqual( rep[5].value_with_units.in_units(AngularUnit.default), -67.344079 * deg_to_def)
def test_create_representation_ang(self): mol = Molecule.from_z_matrix(""" O H1 O 1.0 H2 O 1.0 H1 90 """, create_representation=True ) self.assertEqual(len(mol.internal_representations), 1) self.assertEqual(len(mol.internal_representations[0]), 3) self.assertEqual( mol.internal_representations[0].coords[2].value_with_units.in_units(AngularUnit.default), (90.*Degrees).in_units(AngularUnit.default) )
def test_create_rep_hooh(self): mol = Molecule.from_z_matrix(""" H O 1 0.963242 O 2 1.449863 1 100.120071 H 3 0.963242 2 100.120071 1 -67.344079 """, create_representation=True ) rep = mol.internal_representation deg_to_def = Degrees.to(AngularUnit.default) self.assertAlmostEqual( rep[5].value_with_units.in_units(AngularUnit.default), -67.344079 * deg_to_def)
def test_create_representation_ang(self): mol = Molecule.from_z_matrix(""" O H1 O 1.0 H2 O 1.0 H1 90 """, create_representation=True) self.assertEqual(len(mol.internal_representations), 1) self.assertEqual(len(mol.internal_representations[0]), 3) self.assertEqual( mol.internal_representations[0].coords[2].value_with_units. in_units(AngularUnit.default), (90. * Degrees).in_units(AngularUnit.default))
def setUpForValue(self, val, randomize_cartesian_space=True): self.mol = Molecule.from_z_matrix(''' O H 1 0.93 C 2 1.23 1 104.5 B 3 1.35 2 89.5 1 ''' + str(val), create_representation=True) self.mol.recenter() if randomize_cartesian_space: # 'randomize' the position in xyz space to avoid miniscule displacement amounts self.mol.rotate(Vector(0,0,1), 32 * Degrees.to(Radians)) self.mol.rotate(Vector(0,1,0), 32 * Degrees.to(Radians)) self.mol.rotate(Vector(1,0,0), 32 * Degrees.to(Radians)) self.coord = self.mol.internal_representation[5]
def setUpForValue(self, val, randomize_cartesian_space=True): self.mol = Molecule.from_z_matrix(''' O H 1 0.93 C 2 1.23 1 104.5 B 3 1.35 2 89.5 1 ''' + str(val), create_representation=True) self.mol.recenter() if randomize_cartesian_space: # 'randomize' the position in xyz space to avoid miniscule displacement amounts self.mol.rotate(Vector(0, 0, 1), 32 * Degrees.to(Radians)) self.mol.rotate(Vector(0, 1, 0), 32 * Degrees.to(Radians)) self.mol.rotate(Vector(1, 0, 0), 32 * Degrees.to(Radians)) self.coord = self.mol.internal_representation[5]
def test_zmat(self): self.assertEqual( Molecule([Atom("O", [0.0, 0.0, 0.0])]), Molecule.from_z_matrix(""" O """)) self.assertEqual( Molecule([Atom("O", [0.0, 0.0, 0.0]), Atom("O", [0.0, 0.0, 1.0])]), Molecule.from_z_matrix(""" O1 O2 O1 1.0 """)) self.assertEqual( Molecule([ Atom("O", [0.0, 0.0, 0.0]), Atom("H", [0.0, 0.0, 1.0]), Atom("H", [0.0, -1.0, 0.0]) ]), Molecule.from_z_matrix(""" O H1 O 1.0 H2 O 1.0 H1 90 """))
def test_2_torsions_4_dry_run(self): mol = Molecule.from_z_matrix(''' O H 1 0.93 C 2 1.23 1 104.5 B 3 1.35 2 89.5 1 83.2 O 4 1.25 3 89.5 2 -23.2 ''', create_representation=True) mol.recenter() order = 4 coord = mol.internal_representation[5] natoms = mol.natoms btens = coord.parent_representation.b_tensor() analytic_tensor = Tensor(shape=(3*natoms,)*order) for cartcoords in product(coord.variables, repeat=order): analytic_tensor[tuple(c.index for c in cartcoords)] = btens[(coord,) + cartcoords] coord = mol.internal_representation[8] natoms = mol.natoms btens = coord.parent_representation.b_tensor() analytic_tensor = Tensor(shape=(3*natoms,)*order) for cartcoords in product(coord.variables, repeat=order): analytic_tensor[tuple(c.index for c in cartcoords)] = btens[(coord,) + cartcoords]
def _generated(self, aval): mol = Molecule.from_z_matrix('H\nO 1 1.0\nH 2 1.0 1 ' + str(aval), create_representation=True) coord = mol.internal_representation[2] self.assertHasValidBVector(coord)
def test_bond_angle(self): mol = Molecule.from_z_matrix('H\nO 1 1.0\nH 2 1.0 1 90', create_representation=True) coord = mol.internal_representation[2] self.assertHasValidBVector(coord)
def test_bond_length(self): mol = Molecule.from_z_matrix('H\nO 1 1.0', create_representation=True) coord = mol.internal_representation[0] self.assertHasValidBVector(coord)
def test_bond_length_6(self): mol = Molecule.from_z_matrix('H\nO 1 0.9', create_representation=True) mol.recenter() coord = mol.internal_representation[0] assert_has_valid_b_tensor(coord, 6)