def test_primitive_cell_for_triclinic_lattice(self): with self.assertRaises(ValueError): PrimitiveCell.for_triclinic_lattice(-1, -2, -3, 0.5, 0.6, 0.7) with self.assertRaises(ValueError): PrimitiveCell.for_triclinic_lattice(1, 2, 3, 0, np.pi, np.pi) with self.assertRaises(ValueError): PrimitiveCell.for_triclinic_lattice(1, 2, 3, 0.1, 0.2, 0.8) with self.assertRaises(ValueError): # angles too big PrimitiveCell.for_triclinic_lattice(1, 2, 3, 2.1, 2.1, 2.1) cosa = np.cos(self.alpha) cosb = np.cos(self.beta) sinb = np.sin(self.beta) cosg = np.cos(self.gamma) sing = np.sin(self.gamma) p1 = (self.a, 0, 0) p2 = (self.b * cosg, self.b * sing, 0) p3 = (self.c * cosb, self.c * (cosa - cosb * cosg) / sing, self.c * np.sqrt(sinb**2 - ((cosa - cosb * cosg) / sing)**2)) pc = PrimitiveCell.for_triclinic_lattice(self.a, self.b, self.c, self.alpha, self.beta, self.gamma) self.assertIsInstance(pc, PrimitiveCell) self.assertEqual(pc.bravais_lattice, BravaisLattice.TRICLINIC) assert_array_equal(pc.p1, p1) assert_array_equal(pc.p2, p2) assert_array_equal(pc.p3, p3)
def test_primitive_cell_for_triclinic_lattice(self): with self.assertRaises(ValueError): PrimitiveCell.for_triclinic_lattice(-1, -2, -3, 0.5, 0.6, 0.7) with self.assertRaises(ValueError): PrimitiveCell.for_triclinic_lattice(1, 2, 3, 0, np.pi, np.pi) with self.assertRaises(ValueError): PrimitiveCell.for_triclinic_lattice(1, 2, 3, 0.1, 0.2, 0.8) with self.assertRaises(ValueError): # angles too big PrimitiveCell.for_triclinic_lattice(1, 2, 3, 2.1, 2.1, 2.1) cosa = np.cos(self.alpha) cosb = np.cos(self.beta) sinb = np.sin(self.beta) cosg = np.cos(self.gamma) sing = np.sin(self.gamma) p1 = (self.a, 0, 0) p2 = (self.b*cosg, self.b*sing, 0) p3 = (self.c*cosb, self.c*(cosa-cosb*cosg) / sing, self.c*np.sqrt(sinb**2 - ((cosa-cosb*cosg) / sing)**2)) pc = PrimitiveCell.for_triclinic_lattice( self.a, self.b, self.c, self.alpha, self.beta, self.gamma) self.assertIsInstance(pc, PrimitiveCell) self.assertEqual(pc.bravais_lattice, BravaisLattice.TRICLINIC) assert_array_equal(pc.p1, p1) assert_array_equal(pc.p2, p2) assert_array_equal(pc.p3, p3)
def make_triclinic_lattice(name, hs, angles, size, origin=(0, 0, 0)): """Create and return a 3D triclinic lattice. Parameters ---------- name : str hs : float[3] lattice spacings in each axis direction angles : float[3] angles between the (conventional) unit cell edges (in radians) size : int[3] Number of lattice nodes in each axis direction. origin : float[3], default value = (0, 0, 0) lattice origin Returns ------- lattice : Lattice A reference to a Lattice object. """ pc = PrimitiveCell.for_triclinic_lattice( hs[0], hs[1], hs[2], angles[0], angles[1], angles[2]) return Lattice(name, pc, size, origin)
def test_cell_volume(self): pc = PrimitiveCell.for_triclinic_lattice(1, 1, 1, np.pi / 2, np.pi / 2, np.pi / 2) self.assertAlmostEqual(pc.volume, 1)
def test_cell_volume(self): pc = PrimitiveCell.for_triclinic_lattice(1, 1, 1, np.pi/2, np.pi/2, np.pi/2) self.assertAlmostEqual(pc.volume, 1)