コード例 #1
0
    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_Ch(self.n, self.m, bond=self.bond)
        b = self.layer_spacing
        c = compute_T(self.n, self.m, bond=self.bond, length=True)
        lattice = Crystal3DLattice.orthorhombic(a, b, c)

        basis = Atoms()
        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 * theta
                z = h

                while z > T - eps:
                    z -= T

                if z < 0:
                    z += T

                xs, ys, zs = \
                    lattice.cartesian_to_fractional([x, 0, z])
                if self.wrap_coords:
                    xs, ys, zs = \
                        lattice.wrap_fractional_coordinate([xs, ys, zs])

                if self.debug:
                    print('i={}: x, z = ({:.6f}, {:.6f})'.format(i, x, z))

                atom = Atom(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)
コード例 #2
0
def test2():
    lattice = Crystal2DLattice.square(a=1.0)
    elements = ['H', 'He', 'B', 'C', 'N', 'O', 'Ar']
    for element in elements:
        xatom = BasisAtom(element, lattice=lattice)
        assert_equal(xatom.element, element)
        assert_equal(xatom.m, xatom.mass)

    xatom = BasisAtom()
    for c in ('x', 'y', 'z'):
        assert_equal(getattr(xatom, c), 0.0)
コード例 #3
0
 def from_pymatgen_structure(cls, structure):
     atoms = BasisAtoms()
     for site in structure.sites:
         atoms.append(BasisAtom(element=site.specie.symbol,
                                x=site.x, y=site.y, z=site.z))
     return cls(lattice=Crystal2DLattice(
                cell_matrix=structure.lattice.matrix), basis=atoms)
コード例 #4
0
ファイル: _xtal_cells.py プロジェクト: haidi-ustc/scikit-nano
    def scaling_matrix(self, value):
        if value is None:
            self._scaling_matrix = np.asmatrix(np.ones(3, dtype=int))
            return

        if not isinstance(value, (int, float, tuple, list, np.ndarray)):
            return

        if isinstance(value, np.ndarray) and \
                ((value.shape == np.ones(3).shape and
                  np.allclose(value, np.ones(3))) or
                 (value.shape == np.eye(3).shape and
                  np.allclose(value, np.eye(3)))):
            self._scaling_matrix = np.asmatrix(value)
            return

        if isinstance(value, numbers.Number):
            value = self.lattice.nd * [int(value)]

        scaling_matrix = np.asmatrix(value, dtype=int)
        # scaling_matrix = np.asmatrix(value)
        if scaling_matrix.shape != self.lattice.matrix.shape:
            scaling_matrix = np.diagflat(scaling_matrix)
        self._scaling_matrix = scaling_matrix

        self.lattice = self.lattice.__class__(cell_matrix=self.scaling_matrix *
                                              self.lattice.matrix)

        tvecs = \
            np.asarray(
                np.asmatrix(supercell_lattice_points(self.scaling_matrix)) *
                self.lattice.matrix)

        basis = self.basis[:]
        self.basis = BasisAtoms()
        for atom in basis:
            for tvec in tvecs:
                xs, ys, zs = \
                    self.lattice.cartesian_to_fractional(atom.r + tvec)
                if self.wrap_coords:
                    xs, ys, zs = \
                        self.lattice.wrap_fractional_coordinate(
                            [xs, ys, zs])
                self.basis.append(
                    BasisAtom(atom.element,
                              lattice=self.lattice,
                              xs=xs,
                              ys=ys,
                              zs=zs))
コード例 #5
0
    def from_pymatgen_structure(cls, structure):
        """Return a `Crystal3DStructure` from a \
            :class:`pymatgen:pymatgen.core.Structure`.

        Parameters
        ----------
        structure : :class:`pymatgen:pymatgen.core.Structure`

        Returns
        -------
        :class:`Crystal3DStructure`

        """
        atoms = BasisAtoms()
        for site in structure.sites:
            atoms.append(BasisAtom(site.specie.symbol,
                                   x=site.x, y=site.y, z=site.z))
        return cls(lattice=Crystal3DLattice(
                   cell_matrix=structure.lattice.matrix), basis=atoms)
コード例 #6
0
def test3():
    lattice = Crystal2DLattice.square(a=1.0)
    atom = BasisAtom('C', lattice=lattice)
    print(atom)
コード例 #7
0
def test1():
    from sknano.core.atoms import Atom
    xatom = BasisAtom()
    assert_is_instance(xatom, (Atom, BasisAtom))