Ejemplo n.º 1
0
    def setParams2D(self, type, vertices, center=False):
        """Set the vertices for a given particle type.

        Args:
            type (str): Name of the type to set the shape of
            vertices (list): List of (2D) points specifying the coordinates of the shape
            center (bool): If True, subtract the center of mass of the shape from the vertices before setting them for the shape

        Shapes are specified as a list of 2D coordinates. Edges will
        be made between all adjacent pairs of vertices, including one
        between the last and first vertex.
        """
        itype = hoomd.context.current.system_definition.getParticleData().getTypeByName(type);

        if not len(vertices):
            vertices = [(0, 0)];
            center = False;

        # explicitly turn into a list of tuples
        if center:
            vertices = [(float(p[0]), float(p[1])) for p in utils.center(vertices)];
        else:
            vertices = [(float(p[0]), float(p[1])) for p in vertices];

        # update the neighbor list
        rcutmax = 2*(sqrt(max(x*x + y*y for (x, y) in vertices)) + self.radius*2**(1./6));
        self.r_cut = max(self.r_cut, rcutmax);

        self.vertices[type] = vertices;
        self.cpp_force.setRcut(self.r_cut);
        self.cpp_force.setParams(itype, vertices);
Ejemplo n.º 2
0
    def setParams3D(self, type, vertices, faces, center=False):
        """Set the vertices for a given particle type.

        Args:
            type (str): Name of the type to set the shape of
            vertices (list): List of (3D) points specifying the coordinates of the shape
            faces (list): List of lists of indices specifying which coordinates comprise each face of a shape.
            center (bool): If True, subtract the center of mass of the shape from the vertices before setting them for the shape

        Shapes are specified as a list of coordinates (`vertices`) and
        another list containing one list for each polygonal face
        (`faces`). The elements of each list inside `faces` are
        integer indices specifying which vertex in `vertices` comprise
        the face.
        """
        itype = hoomd.context.current.system_definition.getParticleData(
        ).getTypeByName(type)

        if not len(vertices):
            vertices = [(0, 0, 0)]
            faces = []
            center = False

        # explicitly turn into python lists
        if center:
            vertices = [(float(p[0]), float(p[1]), float(p[2]))
                        for p in utils.center(vertices, faces)]
        else:
            vertices = [(float(p[0]), float(p[1]), float(p[2]))
                        for p in vertices]
        faces = [[int(i) for i in face] for face in faces]

        # update the neighbor list
        rcutmax = 2 * (
            sqrt(max(x * x + y * y + z * z
                     for (x, y, z) in vertices)) + self.radius * 2**(1. / 6))
        self.r_cut = max(self.r_cut, rcutmax)

        self.vertices[type] = vertices
        self.cpp_force.setRcut(self.r_cut)
        self.cpp_force.setParams(itype, vertices, faces)