Ejemplo n.º 1
0
    def __init__(self, anchor=None, orientation=None, separation=0):
        super(Port, self).__init__(name='Port', port_particle=True)
        self.anchor = anchor

        up = Compound(name='subport', port_particle=True)
        up.add(
            Particle(name='G',
                     pos=[0.005, 0.0025, -0.0025],
                     port_particle=True), 'middle')
        up.add(
            Particle(name='G',
                     pos=[0.005, 0.0225, -0.0025],
                     port_particle=True), 'top')
        up.add(
            Particle(name='G',
                     pos=[-0.015, -0.0075, -0.0025],
                     port_particle=True), 'left')
        up.add(
            Particle(name='G',
                     pos=[0.005, -0.0175, 0.0075],
                     port_particle=True), 'right')

        down = clone(up)
        down.rotate(np.pi, [0, 0, 1])

        self.add(up, 'up')
        self.add(down, 'down')
        self.used = False

        if orientation is None:
            orientation = [0, 1, 0]

        default_direction = [0, 1, 0]
        if np.array_equal(np.asarray(default_direction),
                          unit_vector(-np.asarray(orientation))):
            self.rotate(np.pi, [1, 0, 0])
        elif np.array_equal(np.asarray(default_direction),
                            unit_vector(np.asarray(orientation))):
            pass
        else:
            normal = np.cross(default_direction, orientation)
            self.rotate(angle(default_direction, orientation), normal)

        if anchor:
            self.translate_to(anchor.pos)

        self.translate(separation * unit_vector(orientation))
Ejemplo n.º 2
0
def from_snapshot(snapshot, scale=1.0):
    """Convert a Snapshot to a Compound.

    Snapshot can be a hoomd.data.Snapshot or a gsd.hoomd.Snapshot.

    Parameters
    ----------
    snapshot : hoomd._hoomd.SnapshotSystemData_float or gsd.hoomd.Snapshot
        Snapshot from which to build the mbuild Compound.
    scale : float, optional, default 1.0
        Value by which to scale the length values

    Returns
    -------
    comp : Compound

    Note
    ----
    GSD and HOOMD snapshots center their boxes on the origin (0,0,0), so the
    compound is shifted by half the box lengths
    """
    comp = Compound()
    bond_array = snapshot.bonds.group
    n_atoms = snapshot.particles.N

    if "SnapshotSystemData_float" in dir(hoomd._hoomd) and isinstance(
        snapshot, hoomd._hoomd.SnapshotSystemData_float
    ):
        # hoomd v2
        box = snapshot.box
        comp.box = Box.from_lengths_tilt_factors(
            lengths=np.array([box.Lx, box.Ly, box.Lz]) * scale,
            tilt_factors=np.array([box.xy, box.xz, box.yz]),
        )
    else:
        # gsd / hoomd v3
        box = snapshot.configuration.box
        comp.box = Box.from_lengths_tilt_factors(
            lengths=box[:3] * scale, tilt_factors=box[3:]
        )

    # GSD and HOOMD snapshots center their boxes on the origin (0,0,0)
    shift = np.array(comp.box.lengths) / 2
    # Add particles
    for i in range(n_atoms):
        name = snapshot.particles.types[snapshot.particles.typeid[i]]
        xyz = snapshot.particles.position[i] * scale + shift
        charge = snapshot.particles.charge[i]

        atom = Particle(name=name, pos=xyz, charge=charge)
        comp.add(atom, label=str(i))

    # Add bonds
    particle_dict = {idx: p for idx, p in enumerate(comp.particles())}
    for i in range(bond_array.shape[0]):
        atom1 = int(bond_array[i][0])
        atom2 = int(bond_array[i][1])
        comp.add_bond([particle_dict[atom1], particle_dict[atom2]])
    return comp
Ejemplo n.º 3
0
    def __init__(self, anchor=None):
        super(Port, self).__init__(name='Port', port_particle=True)
        self.anchor = anchor

        up = Compound(name='subport', port_particle=True)
        up.add(Particle(name='G', pos=[0, 0, 0], port_particle=True), 'middle')
        up.add(Particle(name='G', pos=[0, 0.02, 0], port_particle=True), 'top')
        up.add(Particle(name='G', pos=[-0.02, -0.01, 0], port_particle=True), 'left')
        up.add(Particle(name='G', pos=[0.0, -0.02, 0.01], port_particle=True), 'right')

        down = clone(up)
        rotate_around_z(down, np.pi)

        self.add(up, 'up')
        self.add(down, 'down')
        self.used = False

        if anchor:
            translate_to(self, anchor.pos)
Ejemplo n.º 4
0
    def __init__(self, anchor=None, orientation=None, separation=0):
        super(Port, self).__init__(name="Port", port_particle=True)
        self.anchor = anchor

        default_direction = np.array([0, 1, 0])
        if orientation is None:
            orientation = [0, 1, 0]
        orientation = np.asarray(orientation)

        up = Compound(name="subport", port_particle=True)
        pos = [0.005, 0.0025, -0.0025]
        up.add(Particle(name="G", pos=pos, port_particle=True), "middle")
        pos = [0.005, 0.0225, -0.0025]
        up.add(Particle(name="G", pos=pos, port_particle=True), "top")
        pos = [-0.015, -0.0075, -0.0025]
        up.add(Particle(name="G", pos=pos, port_particle=True), "left")
        pos = [0.005, -0.0175, 0.0075]
        up.add(Particle(name="G", pos=pos, port_particle=True), "right")

        down = clone(up)
        self.add(up, "up")
        self.add(down, "down")
        self.used = False

        if np.allclose(default_direction, unit_vector(-orientation)):
            down.rotate(np.pi, [0, 0, 1])
            self.rotate(np.pi, [0, 0, 1])
        elif np.allclose(default_direction, unit_vector(orientation)):
            down.rotate(np.pi, [0, 0, 1])
        else:
            normal = np.cross(default_direction, orientation)
            self.rotate(angle(default_direction, orientation), normal)
            down.rotate(np.pi, normal)

        if anchor:
            self.translate_to(anchor.pos)

        self.translate(separation * unit_vector(orientation))