def test2(): lattice = Crystal3DLattice.hexagonal(a=5.0, c=10.0) cell = UnitCell(lattice=lattice, basis=['C', 'C'], coords=[[0, 0, 0], [1 / 2, 1 / 2, 1 / 2]]) print(cell) print(cell.basis)
def test9(): a = np.sqrt(3) * aCC latt = Crystal3DLattice(a=a, b=a, c=2 * r_CC_vdw, alpha=90, beta=90, gamma=120) print(latt) hex_latt = \ Crystal3DLattice.hexagonal(a, 2 * r_CC_vdw) print(hex_latt) assert_equal(latt, hex_latt)
def test9(): a = np.sqrt(3) * aCC latt = Crystal3DLattice(a=a, b=a, c=2 * r_CC_vdw, alpha=90, beta=90, gamma=120) print(latt) hex_latt = \ Crystal3DLattice.hexagonal(a, 2 * r_CC_vdw) print(hex_latt) assert_equal(latt, hex_latt)
def test17(): dlattice = Crystal3DLattice.hexagonal(np.sqrt(3) * aCC, r_CC_vdw) rlattice = dlattice.reciprocal_lattice assert_true(np.allclose(dlattice.volume ** 2, np.linalg.det(dlattice.metric_tensor))) print(dlattice.volume ** 2) print(np.linalg.det(dlattice.metric_tensor)) print(rlattice.volume ** 2) print(np.linalg.det(rlattice.metric_tensor)) assert_true(np.allclose(rlattice.volume ** 2, np.linalg.det(rlattice.metric_tensor))) print(rlattice.metric_tensor) print(rlattice.metric_tensor.T) assert_true(np.allclose(dlattice.volume * rlattice.volume, 1.0)) assert_true(np.allclose(rlattice.metric_tensor * dlattice.metric_tensor.T, np.asmatrix(np.eye(3))))
def test17(): dlattice = Crystal3DLattice.hexagonal(np.sqrt(3) * aCC, r_CC_vdw) rlattice = dlattice.reciprocal_lattice assert_true( np.allclose(dlattice.volume**2, np.linalg.det(dlattice.metric_tensor))) print(dlattice.volume**2) print(np.linalg.det(dlattice.metric_tensor)) print(rlattice.volume**2) print(np.linalg.det(rlattice.metric_tensor)) assert_true( np.allclose(rlattice.volume**2, np.linalg.det(rlattice.metric_tensor))) print(rlattice.metric_tensor) print(rlattice.metric_tensor.T) assert_true(np.allclose(dlattice.volume * rlattice.volume, 1.0)) assert_true( np.allclose(rlattice.metric_tensor * dlattice.metric_tensor.T, np.asmatrix(np.eye(3))))
def test2(): lattice = Crystal3DLattice.hexagonal(a=5.0, c=10.0) cell = UnitCell(lattice=lattice, basis=['C', 'C'], coords=[[0, 0, 0], [1/2, 1/2, 1/2]]) print(cell) print(cell.basis)
def generate_unit_cell(self): """Generate the nanotube unit cell.""" eps = 0.01 e1 = self.element1 e2 = self.element2 N = self.N T = self.T rt = self.rt psi, tau, dpsi, dtau = self.unit_cell_symmetry_params a = compute_dt(self.n, self.m, bond=self.bond) + 2 * self.gutter c = compute_T(self.n, self.m, bond=self.bond, length=True) lattice = Crystal3DLattice.hexagonal(a, c) basis = BasisAtoms() if self.verbose: print('dpsi: {}'.format(dpsi)) print('dtau: {}\n'.format(dtau)) for i in range(N): for j, element in enumerate((e1, e2), start=1): theta = i * psi h = i * tau if j == 2: theta += dpsi h -= dtau x = rt * np.cos(theta) y = rt * np.sin(theta) z = h while z > T - eps: z -= T if z < 0: z += T xs, ys, zs = \ lattice.cartesian_to_fractional([x, y, z]) if self.wrap_coords: xs, ys, zs = \ lattice.wrap_fractional_coordinate([xs, ys, zs]) if self.debug: print('i={}: x, y, z = ({:.6f}, {:.6f}, {:.6f})'.format( i, x, y, z)) print('xs, ys, zs = ({:.6f}, {:.6f}, {:.6f})'.format( xs, ys, zs)) # atom = BasisAtom(element, lattice=lattice, x=x, y=y, z=z) # print('i={}: x, y, z = ({:.6f}, {:.6f}, {:.6f})'.format( # i, x, y, z)) atom = BasisAtom(element, lattice=lattice, xs=xs, ys=ys, zs=zs) atom.rezero() if self.verbose: print('Basis Atom:\n{}'.format(atom)) basis.append(atom) self.unit_cell = UnitCell(lattice=lattice, basis=basis)
def generate_unit_cell(self): """Generate the nanotube unit cell.""" eps = 0.01 e1 = self.element1 e2 = self.element2 N = self.N T = self.T rt = self.rt psi, tau, dpsi, dtau = self.unit_cell_symmetry_params a = compute_dt(self.n, self.m, bond=self.bond) + 2 * self.gutter c = compute_T(self.n, self.m, bond=self.bond, length=True) lattice = Crystal3DLattice.hexagonal(a, c) basis = BasisAtoms() if self.verbose: print('dpsi: {}'.format(dpsi)) print('dtau: {}\n'.format(dtau)) for i in range(N): for j, element in enumerate((e1, e2), start=1): theta = i * psi h = i * tau if j == 2: theta += dpsi h -= dtau x = rt * np.cos(theta) y = rt * np.sin(theta) z = h while z > T - eps: z -= T if z < 0: z += T xs, ys, zs = \ lattice.cartesian_to_fractional([x, y, z]) if self.wrap_coords: xs, ys, zs = \ lattice.wrap_fractional_coordinate([xs, ys, zs]) if self.debug: print('i={}: x, y, z = ({:.6f}, {:.6f}, {:.6f})'.format( i, x, y, z)) print('xs, ys, zs = ({:.6f}, {:.6f}, {:.6f})'.format( xs, ys, zs)) # atom = BasisAtom(element, lattice=lattice, x=x, y=y, z=z) # print('i={}: x, y, z = ({:.6f}, {:.6f}, {:.6f})'.format( # i, x, y, z)) atom = BasisAtom(element, lattice=lattice, xs=xs, ys=ys, zs=zs) atom.rezero() if self.verbose: print('Basis Atom:\n{}'.format(atom)) basis.append(atom) self.unit_cell = UnitCell(lattice=lattice, basis=basis)