Esempio n. 1
0
def test7():
    v1 = Vector([1, 0, 0])
    v2 = Vector([0, 1, 0])
    v3 = vec.cross(v1, v2)
    assert_is_instance(v3, Vector)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
    assert_true(np.allclose(v3.p0, v1.p0))
    assert_true(np.allclose(v3.p0, v2.p0))

    v1 = Vector([1, 0, 0], p0=[1, 1, 1])
    v2 = Vector([0, 1, 0], p0=[1, 1, 1])

    v3 = vec.cross(v1, v2)
    assert_is_instance(v3, Vector)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
    assert_true(np.allclose(v3.p0, v1.p0))
    assert_true(np.allclose(v3.p0, v2.p0))

    v1 = Vector([1, 0, 0], p0=[1, 0, 0])
    v2 = Vector([0, 1, 0], p0=[0, 1, 0])

    v3 = vec.cross(v1, v2)
    assert_is_instance(v3, Vector)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
    assert_true(np.allclose(v3.p0, v1.p0))
    assert_false(np.allclose(v3.p0, v2.p0))

    v1 = Vector([1, 2, 3], p0=[1, 0, 0])
    v2 = Vector([4, 5, 6], p0=[0, 1, 0])
    v3 = vec.cross(v1, v2)
    assert_is_instance(v3, Vector)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
    assert_true(np.allclose(v3.p0, v1.p0))
    assert_false(np.allclose(v3.p0, v2.p0))
Esempio n. 2
0
def test7():
    v1 = Vector([1, 0, 0])
    v2 = Vector([0, 1, 0])
    v3 = vec.cross(v1, v2)
    assert_is_instance(v3, Vector)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
    assert_true(np.allclose(v3.p0, v1.p0))
    assert_true(np.allclose(v3.p0, v2.p0))

    v1 = Vector([1, 0, 0], p0=[1, 1, 1])
    v2 = Vector([0, 1, 0], p0=[1, 1, 1])

    v3 = vec.cross(v1, v2)
    assert_is_instance(v3, Vector)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
    assert_true(np.allclose(v3.p0, v1.p0))
    assert_true(np.allclose(v3.p0, v2.p0))

    v1 = Vector([1, 0, 0], p0=[1, 0, 0])
    v2 = Vector([0, 1, 0], p0=[0, 1, 0])

    v3 = vec.cross(v1, v2)
    assert_is_instance(v3, Vector)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
    assert_true(np.allclose(v3.p0, v1.p0))
    assert_false(np.allclose(v3.p0, v2.p0))

    v1 = Vector([1, 2, 3], p0=[1, 0, 0])
    v2 = Vector([4, 5, 6], p0=[0, 1, 0])
    v3 = vec.cross(v1, v2)
    assert_is_instance(v3, Vector)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
    assert_true(np.allclose(v3.p0, v1.p0))
    assert_false(np.allclose(v3.p0, v2.p0))
Esempio n. 3
0
def test5():
    v1 = Vector([1.0, 0.0])
    v2 = Vector([1.0, 1.0])

    v3 = vec.cross(v1, v2)
    assert_equal(v3, np.cross(np.asarray(v1), np.asarray(v2)))

    v1 = Vector([1, 0], p0=[1, 1])
    v2 = Vector([0, 1], p0=[1, 1])

    v3 = vec.cross(v1, v2)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))

    v1 = Vector([1, 0], p0=[1, 0])
    v2 = Vector([0, 1], p0=[0, 1])

    v3 = vec.cross(v1, v2)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
Esempio n. 4
0
def test5():
    v1 = Vector([1.0, 0.0])
    v2 = Vector([1.0, 1.0])

    v3 = vec.cross(v1, v2)
    assert_equal(v3, np.cross(np.asarray(v1), np.asarray(v2)))

    v1 = Vector([1, 0], p0=[1, 1])
    v2 = Vector([0, 1], p0=[1, 1])

    v3 = vec.cross(v1, v2)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))

    v1 = Vector([1, 0], p0=[1, 0])
    v2 = Vector([0, 1], p0=[0, 1])

    v3 = vec.cross(v1, v2)
    assert_true(np.allclose(v3, np.cross(np.asarray(v1), np.asarray(v2))))
Esempio n. 5
0
    def reciprocal_v3(self):
        """Reciprocal :class:`~sknano.core.math.Vector` \
            :math:`\\mathbf{v}_3^{*}`.

        Defined as:

        .. math::

           \\mathbf{v}_3^{*} =
           \\frac{\\mathbf{v}_1\\times\\mathbf{v}_2}
           {|\\mathbf{v}_1\\cdot(\\mathbf{v}_2\\times\\mathbf{v}_3)|}

        """
        with warnings.catch_warnings():
            warnings.filterwarnings('error')
            try:
                return vec.cross(self.v1, self.v2) / self.Vv1v2v3
            except Warning:
                return vec.cross(self.v1, self.v2)
Esempio n. 6
0
    def reciprocal_v3(self):
        """Reciprocal :class:`~sknano.core.math.Vector` \
            :math:`\\mathbf{v}_3^{*}`.

        Defined as:

        .. math::

           \\mathbf{v}_3^{*} =
           \\frac{\\mathbf{v}_1\\times\\mathbf{v}_2}
           {|\\mathbf{v}_1\\cdot(\\mathbf{v}_2\\times\\mathbf{v}_3)|}

        """
        with warnings.catch_warnings():
            warnings.filterwarnings('error')
            try:
                return vec.cross(self.v1, self.v2) / self.Vv1v2v3
            except Warning:
                return vec.cross(self.v1, self.v2)
Esempio n. 7
0
    def compute_POAVs(self):
        """Compute `POAV1`, `POAV2`, `POAVR`."""
        super().update_attrs()

        POAV_classes = {'POAV1': POAV1, 'POAV2': POAV2, 'POAVR': POAVR}

        for atom in self:
            # the central atom must have 3 bonds for POAV analysis.
            if atom.bonds.Nbonds == 3:
                for POAV_name, POAV_class in list(POAV_classes.items()):
                    setattr(atom, POAV_name, POAV_class(atom.bonds))

        for atom in self:
            # the central atom must have 3 bonds for POAV analysis.
            if atom.bonds.Nbonds == 3:
                for POAV_name in ('POAV1', 'POAV2', 'POAVR'):
                    POAV = getattr(atom, POAV_name)
                    sigma_pi_angles = []
                    pyramidalization_angles = []
                    misalignment_angles = []
                    for bond, NN in zip(atom.bonds, atom.NN):
                        # first compute the pyramidalization angle
                        sigma_pi_angle = vec.angle(POAV.Vpi, bond.vector)
                        if sigma_pi_angle < np.pi / 2:
                            sigma_pi_angle = np.pi - sigma_pi_angle
                        sigma_pi_angles.append(sigma_pi_angle)
                        pyramidalization_angles.append(sigma_pi_angle -
                                                       np.pi / 2)

                        # the bonded atom must have a POAV to compute the
                        # misalignment angles
                        if getattr(NN, POAV_name) is not None:
                            NN_POAV = getattr(NN, POAV_name)
                            # compute vector that is orthogonal to the plane
                            # defined by the bond vector and the POAV of the
                            # center atom.
                            nvec = vec.cross(bond.vector, POAV.Vpi)

                            # the misalignment angle is the angle between the
                            # nearest neighbor's POAV and the plane defined by
                            # the bond vector and the POAV of the center atom,
                            # which is pi/2 minus the angle between
                            # the NN POAV and the normal vector to the plane
                            # computed above.
                            misalignment_angles.append(
                                np.abs(np.pi / 2 -
                                       vec.angle(NN_POAV.Vpi, nvec)))
                        else:
                            misalignment_angles.append(np.nan)

                    POAV.pyramidalization_angles = pyramidalization_angles
                    POAV.misalignment_angles = misalignment_angles
                    POAV.sigma_pi_angles = sigma_pi_angles
Esempio n. 8
0
    def compute_POAVs(self):
        """Compute `POAV1`, `POAV2`, `POAVR`."""
        super().update_attrs()

        POAV_classes = {'POAV1': POAV1, 'POAV2': POAV2, 'POAVR': POAVR}

        for atom in self:
            # the central atom must have 3 bonds for POAV analysis.
            if atom.bonds.Nbonds == 3:
                for POAV_name, POAV_class in list(POAV_classes.items()):
                    setattr(atom, POAV_name, POAV_class(atom.bonds))

        for atom in self:
            # the central atom must have 3 bonds for POAV analysis.
            if atom.bonds.Nbonds == 3:
                for POAV_name in ('POAV1', 'POAV2', 'POAVR'):
                    POAV = getattr(atom, POAV_name)
                    sigma_pi_angles = []
                    pyramidalization_angles = []
                    misalignment_angles = []
                    for bond, NN in zip(atom.bonds, atom.NN):
                        # first compute the pyramidalization angle
                        sigma_pi_angle = vec.angle(POAV.Vpi, bond.vector)
                        if sigma_pi_angle < np.pi / 2:
                            sigma_pi_angle = np.pi - sigma_pi_angle
                        sigma_pi_angles.append(sigma_pi_angle)
                        pyramidalization_angles.append(
                            sigma_pi_angle - np.pi / 2)

                        # the bonded atom must have a POAV to compute the
                        # misalignment angles
                        if getattr(NN, POAV_name) is not None:
                            NN_POAV = getattr(NN, POAV_name)
                            # compute vector that is orthogonal to the plane
                            # defined by the bond vector and the POAV of the
                            # center atom.
                            nvec = vec.cross(bond.vector, POAV.Vpi)

                            # the misalignment angle is the angle between the
                            # nearest neighbor's POAV and the plane defined by
                            # the bond vector and the POAV of the center atom,
                            # which is pi/2 minus the angle between
                            # the NN POAV and the normal vector to the plane
                            # computed above.
                            misalignment_angles.append(np.abs(
                                np.pi / 2 - vec.angle(NN_POAV.Vpi, nvec)))
                        else:
                            misalignment_angles.append(np.nan)

                    POAV.pyramidalization_angles = pyramidalization_angles
                    POAV.misalignment_angles = misalignment_angles
                    POAV.sigma_pi_angles = sigma_pi_angles
Esempio n. 9
0
def test8():
    assert_true(np.allclose(vec.cross(e1, e2), e3))
    assert_equal(vec.cross(e1, e2), e3)

    assert_true(np.allclose(vec.cross(e1, e3), -e2))
    assert_equal(vec.cross(e1, e3), -e2)

    assert_true(np.allclose(vec.cross(e2, e3), e1))
    assert_equal(vec.cross(e2, e3), e1)
Esempio n. 10
0
def test8():
    assert_true(np.allclose(vec.cross(e1, e2), e3))
    assert_equal(vec.cross(e1, e2), e3)

    assert_true(np.allclose(vec.cross(e1, e3), -e2))
    assert_equal(vec.cross(e1, e3), -e2)

    assert_true(np.allclose(vec.cross(e2, e3), e1))
    assert_equal(vec.cross(e2, e3), e1)