Exemplo n.º 1
0
    def seperate_with(self, targetItem, type, value):
        """ [Bioperate] to seperate two items in opposite direction: (rel)ative distance is move EACH item in a distance under system unit; (abs)olute distance is the time of current distance of two items, e.g.: item+=unit_orientation_vector*rel; item+=orientation_vector*abs.

        Args:
            targetItem (Item): Atom|Molecule
            type (str): rel|abs
            value (Float): distance
        """
        # orientation vector
        if all(self.position == targetItem.position):
            raise ValueError(_("两个atom完全重叠, 无法计算方向矢量"))
        oriVec = targetItem.position - self.position

        distance = np.linalg.norm(oriVec)

        uniVec = oriVec / distance

        if type == 'relative' or type == 'rel':

            distance = distance * (value - 1) / 2

            self.move(*-uniVec * distance)
            targetItem.move(*+uniVec * distance)

        if type == 'abusolute' or type == 'abs':
            self.move(*-uniVec * value)
            targetItem.move(*+uniVec * value)
        return self
Exemplo n.º 2
0
    def rotate_orth(self, theta, x, y, z, xAxis, yAxis, zAxis):
        """围绕在(x,y,z)点的x/y/z轴旋转theta

        Args:
            theta (deg): 旋转角
            x (float): 旋转参考点
            y (float): 旋转参考点
            z (float): 旋转参考点
            xAxis (bool): 旋转轴指向
            yAxis (bool): 旋转轴指向
            zAxis (bool): 旋转轴指向

        Raises:
            SyntaxError: 只能有一个方向被设置成True来代表旋转轴指向
        """

        if (xAxis, yAxis, zAxis) == (1, 0, 0) or\
           (xAxis, yAxis, zAxis) == (0, 1, 0) or\
           (xAxis, yAxis, zAxis) == (0, 0, 1):

            self.rotate(theta, xAxis, yAxis, zAxis, x, y, z)
        else:
            raise SyntaxError(
                _('为了指定空间中(x,y,z)的旋转轴的朝向, 需要将方向设定为1. 如: 旋转轴指向x方向则xAxis=1, yAxis=zAxis=0'
                  ))
        return self
Exemplo n.º 3
0
    def __getitem__(self, label):

        if isinstance(label, str):
            for item in self:
                if item.label == label:
                    return item

        elif isinstance(label, int):
            return self.container[label]

        elif isinstance(label, slice):
            raise TypeError(_('暂不支持切片调用'))
Exemplo n.º 4
0
    def add_neighbors(self, *atoms):
        """添加键接的Atom. TODO: 将键接Atom和临近Atom区分开

        Raises:
            TypeError: 添加了错误种类的对象而不是Atom
        """
        for atom in atoms:
            if isinstance(atom, Atom):
                if atom not in self:
                    self._neighbors.append(atom)
                if self not in atom:
                    atom._neighbors.append(self)

            else:
                raise TypeError(_('相邻的atom应该是 ATOM类 而不是 %s' % (type(atom))))
Exemplo n.º 5
0
    def add_items(self, *items):
        """向Molecule中添加item

        Raises:
            TypeError: 如果不是Atom或者Molecule则报错
        """
        for item in items:
            if item.itemType == 'Molecule' or item.itemType == 'Atom':
                item.parent = self.label
                self.container.append(item)

            else:
                raise TypeError(_('传入的类型错误'))

        self.update()
Exemplo n.º 6
0
    def rotate_orth(self, theta, x, y, z, xAxis, yAxis, zAxis):
        """ 围绕(x,y,z)点的x/y/z轴旋转theta角

        Raises:        self.x = pos[0]
        self.y = pos[1]
        self.z = pos[2]
            SyntaxError: [description]
        """

        if (xAxis, yAxis, zAxis) == (1, 0, 0) or\
           (xAxis, yAxis, zAxis) == (0, 1, 0) or\
           (xAxis, yAxis, zAxis) == (0, 0, 1):

            self.rotate(theta, xAxis, yAxis, zAxis, x, y, z)
        else:
            raise SyntaxError(
                _('为了指定空间中(x,y,z)的旋转轴的朝向, 需要将方向设定为1. 如: 旋转轴指向x方向则xAxis=1, yAxis=zAxis=0'
                  ))
Exemplo n.º 7
0
    def seperate_with(self, targetItem, type, value):
        if all(self.position == targetItem.position):
            raise ValueError(_("两个atom完全重叠, 无法计算方向矢量"))
        oriVec = targetItem.position - self.position

        distance = np.linalg.norm(oriVec)

        uniVec = oriVec / distance

        if type == 'relative' or type == 'rel':

            distance = distance * (value - 1) / 2

            self.move(*-uniVec * distance)
            targetItem.move(*+uniVec * distance)

        if type == 'abusolute' or type == 'abs':
            self.move(*-uniVec * value)
            targetItem.move(*+uniVec * value)
        return self