Exemple #1
0
    def __init__(self):
        super(H, self).__init__()
        self.add(mb.Particle(name='H'))

        self.add(mb.Port(anchor=self[0]), 'up')
        mb.rotate_around_z(self['up'], np.pi)
        mb.translate(self['up'], np.array([0, 0.07, 0]))
Exemple #2
0
    def benzene_from_parts(self):
        ch = mb.load(get_fn('ch.mol2'))
        ch.name = 'CH'
        mb.translate(ch, -ch[0].pos)
        ch.add(mb.Port(anchor=ch[0], separation=0.07), 'a')
        mb.rotate_around_z(ch['a'], 120.0 * (np.pi / 180.0))

        ch.add(mb.Port(anchor=ch[0], separation=0.07), 'b')
        mb.rotate_around_z(ch['b'], -120.0 * (np.pi / 180.0))
        ch_copy = mb.clone(ch)

        benzene = mb.Compound(name='Benzene')
        benzene.add(ch)
        current = ch

        for _ in range(5):
            ch_new = mb.clone(ch_copy)
            mb.force_overlap(move_this=ch_new,
                             from_positions=ch_new['a'],
                             to_positions=current['b'])
            current = ch_new
            benzene.add(ch_new)

        carbons = [p for p in benzene.particles_by_name('C')]
        benzene.add_bond((carbons[0], carbons[-1]))

        return benzene
Exemple #3
0
    def benzene_from_parts(self):
        ch = mb.load(get_fn('ch.mol2'))
        ch.name = 'CH'
        mb.translate(ch, -ch[0].pos)       
        ch.add(mb.Port(anchor=ch[0], separation=0.07), 'a')
        mb.rotate_around_z(ch['a'], 120.0 * (np.pi/180.0))

        ch.add(mb.Port(anchor=ch[0], separation=0.07), 'b')
        mb.rotate_around_z(ch['b'], -120.0 * (np.pi/180.0))
        ch_copy = mb.clone(ch)

        benzene = mb.Compound(name='Benzene')
        benzene.add(ch)
        current = ch

        for _ in range(5):
            ch_new = mb.clone(ch_copy)
            mb.force_overlap(move_this=ch_new,
                             from_positions=ch_new['a'],
                             to_positions=current['b'])
            current = ch_new
            benzene.add(ch_new)

        carbons = [p for p in benzene.particles_by_name('C')]
        benzene.add_bond((carbons[0],carbons[-1]))

        return benzene
Exemple #4
0
    def __init__(self):
        super(H, self).__init__()
        self.add(mb.Particle(name='H'))

        self.add(mb.Port(anchor=self[0]), 'up')
        mb.spin_z(self['up'], np.pi)
        mb.translate(self['up'], np.array([0, 0.07, 0]))
Exemple #5
0
def build_monolayer(chain_length, n_molecules, **kwargs):
    from mbuild.examples import AlkaneMonolayer
    pattern = mb.Random2DPattern(n_molecules)
    monolayer = AlkaneMonolayer(pattern, tile_x=1, tile_y=1, chain_length=chain_length)
    monolayer.name = 'alkane_n-{}_l-{}'.format(n_molecules, chain_length)
    mb.translate(monolayer, [0, 0, 2])
    return monolayer
Exemple #6
0
def build_monolayer(chain_length,
                    n_molecules,
                    pattern_class,
                    polymer_class=AlkaneMonolayer,
                    surface_class=Betacristobalite,
                    name=None,
                    **kwargs):
    if pattern_class is mb.Random2DPattern:
        if n_molecules in used_random_patterns:
            pattern = used_random_patterns[n_molecules]
        else:
            pattern = pattern_class(n_molecules)
            used_random_patterns[n_molecules] = pattern
    if pattern_class is mb.Grid2DPattern:
        pattern = pattern_class(int(np.sqrt(n_molecules)),
                                int(np.sqrt(n_molecules)))

    # --------------------------------------------------------------- # TJ
    """
    If elif statement to check surface type and create for each monolayer. TJ
    """
    if surface_class is Betacristobalite:
        surface = surface_class()
    elif surface_class is mb.SilicaInterface:
        surface = surface_class(bulk_silica=AmorphousSilica(), thickness=1.2)
    bot = polymer_class(pattern,
                        surface=surface,
                        tile_x=1,
                        tile_y=1,
                        chain_length=chain_length)
    # --------------------------------------------------------------- # TJ
    mb.translate(bot, [0, 0, 2])

    bot_box = bot.boundingbox
    bot_of_bot = bot_box.mins[2]

    bot_rigid = [
        i + 1 for i, a in enumerate(bot.particles())
        if (a.pos[2] < bot_of_bot + 0.2) and a.name == 'Si'
    ]
    n_particles = bot.n_particles
    top_rigid = [i + n_particles for i in bot_rigid]

    top = mb.clone(bot)
    mb.spin_y(top, np.pi)
    top_of_bot = bot_box.maxs[2]
    bot_of_top = top.boundingbox.mins[2]
    mb.translate(top, [0, 0, top_of_bot - bot_of_top + 0.5])

    monolayer = mb.Compound([bot, top])

    if not name:
        name = '{}_n-{}_l-{}-{}-{}'.format(polymer_class.__name__[:3],
                                           n_molecules, chain_length,
                                           surface_class.__name__,
                                           pattern_class.__name__[:4])
    monolayer.name = name
    rigid_groups = {'bot': bot_rigid, 'top': top_rigid}
    return monolayer, rigid_groups
Exemple #7
0
    def __init__(self):
        super(CH3, self).__init__()

        mb.load('ch3.pdb', compound=self, relative_to_module=self.__module__)
        mb.translate(self, -self[0].pos)  # Move carbon to origin.

        self.add(mb.Port(anchor=self[0]), 'up')
        mb.translate(self['up'], [0, -0.07, 0])
Exemple #8
0
    def __init__(self):
        super(CH3, self).__init__()

        mb.load('ch3.pdb', compound=self, relative_to_module=self.__module__)
        mb.translate(self, -self[0].pos)  # Move carbon to origin.

        self.add(mb.Port(anchor=self[0]), 'up')
        mb.translate(self['up'], [0, -0.07, 0])
Exemple #9
0
    def __init__(self):
        super(CH3, self).__init__()

        mb.load('ch3.pdb', compound=self, relative_to_module=self.__module__)
        mb.translate(self, -self.C[0])  # Move carbon to origin.

        port = mb.Port(anchor=self.C[0])
        self.add(port, label='up')
        mb.translate(self.up, [0, -0.07, 0])
Exemple #10
0
def build_monolayer(chain_length, n_molecules, **kwargs):
    from mbuild.examples import AlkaneMonolayer
    pattern = mb.Random2DPattern(n_molecules)
    monolayer = AlkaneMonolayer(pattern, tile_x=1, tile_y=1, chain_length=chain_length)
    monolayer.name = 'alkane_n-{}_l-{}'.format(n_molecules, chain_length)
    mb.translate(monolayer, [0, 0, 2])
    box = monolayer.boundingbox
    monolayer.periodicity += np.array([0, 0, 5 * box.lengths[2]])

    return monolayer
Exemple #11
0
    def __init__(self):
        super(C, self).__init__()

        self.add(mb.Particle(name='C'))

        self.add(mb.Port(anchor=self[0]), 'up')
        mb.translate(self['up'], [0, 0.07, 0])

        self.add(mb.Port(anchor=self[0]), 'down')
        mb.translate(self['down'], [0, -0.07, 0])
 def _identify_surface_sites(self, thickness):
     """Label surface sites and add ports above them. """
     for atom in self.particles():
         if len(self.bond_graph.neighbors(atom)) == 1:
             if atom.name == 'O' and atom.pos[2] > thickness:
                 atom.name = 'OS'
                 port = mb.Port(anchor=atom)
                 mb.rotate_around_x(port, np.pi/2)
                 mb.translate(port, atom.pos + np.array([0.0, 0.0, 0.1]))
                 self.add(port, "port_{}".format(len(self.referenced_ports())))
Exemple #13
0
 def _identify_surface_sites(self, thickness):
     """Label surface sites and add ports above them. """
     for atom in self.particles():
         if len(self.bond_graph.neighbors(atom)) == 1:
             if atom.name == 'O' and atom.pos[2] > thickness:
                 atom.name = 'OS'
                 port = mb.Port(anchor=atom)
                 mb.spin_x(port, np.pi / 2)
                 mb.translate(port, np.array([0.0, 0.0, 0.1]))
                 self.add(port,
                          "port_{}".format(len(self.referenced_ports())))
Exemple #14
0
    def __init__(self,
                 infile=DEFAULTS['terB_infile'],
                 down_offset=DEFAULTS['down_offset'],
                 down_anchor=DEFAULTS['down_anchor']):
        super(terB, self).__init__()
        mb.load(infile, compound=self)

        atom_names = [a.name for a in self]
        nterminal = atom_names.index(down_anchor)

        self.add(mb.Port(anchor=self[nterminal]), label='down')
        mb.translate(self['down'], down_offset)
Exemple #15
0
 def __init__(self):
     super(MonoLJ, self).__init__()
     lj_proto = mb.Particle(name='LJ', pos=[0, 0, 0])
     
     pattern = mb.Grid3DPattern(5, 5, 5)
     pattern.scale(5)
     
     for pos in pattern:
         lj_particle = clone(lj_proto)
         mb.translate(lj_particle, pos)
         self.add(lj_particle)
         print(pos)
Exemple #16
0
    def __init__(self):
        super(Ester, self).__init__()

        mb.load('ester.pdb', compound=self, relative_to_module=self.__module__)
        mb.translate(self, -self[0].pos)

        self.add(mb.Port(anchor=self[2]), 'up')
        mb.spin_z(self['up'], np.pi / 2)
        mb.translate_to(self['up'], np.array([0.07, 0, 0]))

        self.add(mb.Port(anchor=self[0]), 'down')
        mb.spin_z(self['down'], np.pi / 2)
        mb.translate(self['down'], np.array([-0.07, 0, 0]))
Exemple #17
0
    def __init__(self,
                 infile=DEFAULTS['terA_infile'],
                 up_offset=DEFAULTS['up_offset'],
                 up_anchor=DEFAULTS['up_anchor']):
        super(terA, self).__init__()

        mb.load(infile, compound=self)

        atom_names = [a.name for a in self]
        cterminal = atom_names.index(up_anchor)

        self.add(mb.Port(anchor=self[cterminal]), label='up')
        mb.translate(self['up'], up_offset)
Exemple #18
0
    def __init__(self):
        super(MonoLJ, self).__init__()
        lj_proto = mb.Particle(name='LJ', pos=[0, 0, 0])
        
        pattern = mb.Grid3DPattern(5, 5, 5)
        pattern.scale(5)
        
        for pos in pattern:
            lj_particle = clone(lj_proto)
            mb.translate(lj_particle, pos)
            self.add(lj_particle)

# -- ==monolj== --
Exemple #19
0
def build_monolayer(chain_length, n_molecules, **kwargs):
    from mbuild.examples import AlkaneMonolayer
    pattern = mb.Random2DPattern(n_molecules)
    monolayer = AlkaneMonolayer(pattern,
                                tile_x=1,
                                tile_y=1,
                                chain_length=chain_length)
    monolayer.name = 'alkane_n-{}_l-{}'.format(n_molecules, chain_length)
    mb.translate(monolayer, [0, 0, 2])
    box = monolayer.boundingbox
    monolayer.periodicity += np.array([0, 0, 5 * box.lengths[2]])

    return monolayer
Exemple #20
0
    def __init__(self):
        super(Ester, self).__init__()

        mb.load('ester.pdb', compound=self, relative_to_module=self.__module__)
        mb.translate(self, -self[0].pos)

        self.add(mb.Port(anchor=self[2]), 'up')
        mb.rotate_around_z(self['up'], np.pi / 2)
        mb.translate_to(self['up'], self[2].pos + np.array([0.07, 0, 0]))

        self.add(mb.Port(anchor=self[0]), 'down')
        mb.rotate_around_z(self['down'], np.pi / 2)
        mb.translate(self['down'], np.array([-0.07, 0, 0]))
Exemple #21
0
    def __init__(self, particle_kind="bead"):
        """Initialize a Bead object.

        Args:
            particle_kind (str): Descriptive name for the Bead.
        """
        super(Bead, self).__init__()

        self.add(mb.Particle(name=particle_kind), particle_kind)

        self.add(mb.Port(anchor=self.labels[particle_kind]), 'up')
        mb.translate(self['up'], np.array([0, 0.7, 0]))

        self.add(mb.Port(anchor=self.labels[particle_kind]), 'down')
        mb.translate(self['down'], np.array([0, -0.7, 0]))
Exemple #22
0
    def __init__(self, particle_kind="bead"):
        """Initialize a Bead object.

        Args:
            particle_kind (str): Descriptive name for the Bead.
        """
        super(Bead, self).__init__()

        self.add(mb.Particle(name=particle_kind), particle_kind)

        self.add(mb.Port(anchor=self.labels[particle_kind]), 'up')
        mb.translate(self['up'], np.array([0, 0.7, 0]))

        self.add(mb.Port(anchor=self.labels[particle_kind]), 'down')
        mb.translate(self['down'], np.array([0, -0.7, 0]))
Exemple #23
0
    def __init__(self, ):
        super(Silane, self).__init__()
        mb.load('silane.pdb', compound=self, relative_to_module=self.__module__)

        # Transform the coordinate system such that the silicon atom is at the
        # origin and the oxygen atoms are on the x axis.
        mb.x_axis_transform(self, new_origin=self[0], point_on_x_axis=self[1])

        # Add bottom port.
        self.add(mb.Port(anchor=self[0]), 'down')
        mb.translate(self['down'], np.array([0, -.07, 0]))

        # Add top port.
        self.add(mb.Port(anchor=self[0]), 'up')
        mb.translate(self['up'], np.array([0, .07, 0]))
    def __init__(self):
        super(Betacristobalite, self).__init__()

        mb.load('beta-cristobalite-expanded.mol2', compound=self,
                relative_to_module=self.__module__)
        self.periodicity = np.array([5.3888, 4.6669, 0.0])

        count = 0
        for particle in self.particles():
            if particle.name.startswith('O') and particle.pos[2] > 1.0:
                count += 1
                port = mb.Port(anchor=particle)
                mb.rotate_around_x(port, np.pi/2)
                mb.translate(port, particle.pos + np.array([0, 0, .1]))
                self.add(port, 'port_{}'.format(count))
Exemple #25
0
    def __init__(self):
        super(TnpBox, self).__init__()

        tnp_proto = Tnp(ball_radius=5, n_chains=5, chain_length=8)

        pattern = mb.Grid3DPattern(3, 3, 3)
        pattern.scale(100)

        rnd = random.Random()
        rnd.seed(1928)

        for pos in pattern:
            tnp = clone(tnp_proto)
            mb.rotate_around_x(tnp, rnd.uniform(0, 2 * pi))
            mb.rotate_around_y(tnp, rnd.uniform(0, 2 * pi))
            mb.rotate_around_z(tnp, rnd.uniform(0, 2 * pi))
            mb.translate(tnp, pos)
            self.add(tnp)
Exemple #26
0
    def __init__(self, c1_pos=None, rotate_random=True):
        super(C10, self).__init__()
        num_particles = 10
        for index in range(num_particles):
            self.add(C(), label='C[$]')

        if c1_pos is not None:
            mb.translate(self['C'][0], c1_pos)

        if rotate_random is True:
            mb.rotate_around_x(self['C'][0], random.uniform(0, 2 * math.pi))
            mb.rotate_around_y(self['C'][0], random.uniform(0, 2 * math.pi))
            mb.rotate_around_z(self['C'][0], random.uniform(0, 2 * math.pi))

        for index in range(num_particles - 1):
            mb.force_overlap(move_this=self['C'][index + 1],
                             from_positions=self['C'][index + 1]['down'],
                             to_positions=self['C'][index]['up'])
Exemple #27
0
    def __init__(self):
        super(Betacristobalite, self).__init__()

        mb.load('beta-cristobalite-expanded.mol2',
                compound=self,
                relative_to_module=self.__module__)
        self.periodicity = np.array([5.3888, 4.6669, 0.0])

        count = 0
        for particle in self.particles():
            if particle.name.startswith('O') and particle.pos[2] > 1.0:
                count += 1
                port = mb.Port(anchor=particle)
                mb.spin_x(port, np.pi / 2)
                mb.translate(port, np.array([0, 0, .1]))
                self.add(port, 'port_{}'.format(count))
                particle.name = 'O'  # Strip numbers required in .mol2 files.
            elif particle.name.startswith('Si'):
                particle.name = 'Si'
Exemple #28
0
    def __init__(self):
        super(Initiator, self).__init__()

        # Look for data file in same directory as this python module.
        mb.load('initiator.pdb', compound=self, relative_to_module=self.__module__)

        # Transform the coordinate system such that the two carbon atoms
        # that are part of the backbone are on the y axis, C_1 at the origin.
        mb.y_axis_transform(self, new_origin=self[0], point_on_y_axis=self[21])

        # Add bottom port
        self.add(mb.Port(anchor=self[0]), 'down')
        # Place the port.
        mb.translate(self['down'], self[0].pos + np.array([0.0, -0.07, 0.0]))

        # Add top port.
        self.add(mb.Port(anchor=self[21]), 'up')
        # Place the port.
        mb.translate(self['up'], self[21].pos + np.array([0.0, 0.07, 0.0]))
Exemple #29
0
    def __init__(self):
        super(Initiator, self).__init__()

        # Look for data file in same directory as this python module.
        mb.load('initiator.pdb',
                compound=self,
                relative_to_module=self.__module__)

        # Transform the coordinate system such that the two carbon atoms
        # that are part of the backbone are on the y axis, C_1 at the origin.
        mb.y_axis_transform(self, new_origin=self[0], point_on_y_axis=self[21])

        # Add bottom port
        self.add(mb.Port(anchor=self[0]), 'down')
        # Place the port.
        mb.translate(self['down'], np.array([0.0, -0.07, 0.0]))

        # Add top port.
        self.add(mb.Port(anchor=self[21]), 'up')
        # Place the port.
        mb.translate(self['up'], np.array([0.0, 0.07, 0.0]))
    def __init__(self, surface_roughness=1.0):
        super(AmorphousSilica, self).__init__()

        if surface_roughness == 1.0:
            # TODO: description of how this surface was generated/citation
            mb.load('amorphous_silica_sr1.0.pdb', compound=self,
                    relative_to_module=self.__module__)
            self.periodicity = np.array([5.4366, 4.7082, 0.0])
        else:
            raise ValueError('Amorphous silica input file with surface '
                             'roughness of {0:.1f} does not exist. If you have '
                             'this structure, please submit a pull request to'
                             'add it! '.format(surface_roughness))
        count = 0
        for particle in self.particles():
            if particle.name == 'OB':
                count += 1
                port = mb.Port(anchor=particle)
                mb.rotate_around_x(port, np.pi/2)
                mb.translate(port, particle.pos + np.array([0, 0, .1]))
                self.add(port, 'port_{}'.format(count))
Exemple #31
0
def build_monolayer(chain_length, n_molecules, pattern_class, **kwargs):
    from mbuild.examples import AlkaneMonolayer
    if pattern_class is mb.Random2DPattern:
        if n_molecules in used_random_patterns:
            pattern = used_random_patterns[n_molecules]
        else:
            pattern = pattern_class(n_molecules)
        pattern_name = 'rand'
    if pattern_class is mb.Grid2DPattern:
        pattern = pattern_class(int(np.sqrt(n_molecules)),
                                int(np.sqrt(n_molecules)))
        pattern_name = 'grid'

    bot = AlkaneMonolayer(pattern,
                          tile_x=1,
                          tile_y=1,
                          chain_length=chain_length)
    mb.translate(bot, [0, 0, 2])

    bot_box = bot.boundingbox
    bot_of_bot = bot_box.mins[2]

    bot_rigid = [
        i + 1 for i, a in enumerate(bot.particles())
        if (a.pos[2] < bot_of_bot + 0.05) and a.name == 'Si'
    ]
    n_particles = bot.n_particles
    top_rigid = [i + n_particles for i in bot_rigid]

    top = mb.clone(bot)
    mb.spin_y(top, np.pi)
    top_of_bot = bot_box.maxs[2]
    bot_of_top = top.boundingbox.mins[2]
    mb.translate(top, [0, 0, top_of_bot - bot_of_top + 0.5])

    monolayer = mb.Compound([bot, top])
    monolayer.name = 'alkane_n-{}_l-{}-{}'.format(n_molecules, chain_length,
                                                  pattern_name)
    rigid_groups = {'bot': bot_rigid, 'top': top_rigid}
    return monolayer, rigid_groups
Exemple #32
0
    def __init__(self, box=[1, 1, 1]):
        super(Epoxy_A_10_B_20_C10_2_Blend, self).__init__()

        if len(box) is not 3:
            raise ValueError('box shape should be 3. You passed in {}'.format(
                len(box)))

        num_a = 10
        num_b = 20
        num_c10 = 2

        for index in range(0, num_a):
            self.add(A(), label='A[$]')
            x = random.uniform(-box[0] / 2, box[0] / 2)
            y = random.uniform(-box[1] / 2, box[1] / 2)
            z = random.uniform(-box[2] / 2, box[2] / 2)
            mb.translate(self['A'][-1], [x, y, z])

        for index in range(0, num_b):
            self.add(B(), label='B[$]')
            x = random.uniform(-box[0] / 2, box[0] / 2)
            y = random.uniform(-box[1] / 2, box[1] / 2)
            z = random.uniform(-box[2] / 2, box[2] / 2)
            mb.translate(self['B'][-1], [x, y, z])

        for index in range(0, num_c10):
            self.add(C10(), label='C10[$]')
            x = random.uniform(-box[0] / 2, box[0] / 2)
            y = random.uniform(-box[1] / 2, box[1] / 2)
            z = random.uniform(-box[2] / 2, box[2] / 2)
            mb.translate(self['C10'][-1], [x, y, z])
Exemple #33
0
    def __init__(self, surface_roughness=1.0):
        super(AmorphousSilica, self).__init__()

        if surface_roughness == 1.0:
            # TODO: description of how this surface was generated/citation
            mb.load('amorphous_silica_sr1.0.pdb',
                    compound=self,
                    relative_to_module=self.__module__)
            self.periodicity = np.array([5.4366, 4.7082, 0.0])
        else:
            raise ValueError(
                'Amorphous silica input file with surface '
                'roughness of {0:.1f} does not exist. If you have '
                'this structure, please submit a pull request to'
                'add it! '.format(surface_roughness))
        count = 0
        for particle in self.particles():
            if particle.name == 'OB':
                count += 1
                port = mb.Port(anchor=particle)
                mb.spin_x(port, np.pi / 2)
                mb.translate(port, np.array([0, 0, .1]))
                self.add(port, 'port_{}'.format(count))
Exemple #34
0
    def __init__(self, n=65, radius=1, port_distance_from_surface=.07):
        """Initialize a Sphere object.

        Args:
            n (int): Number of points used to construct the Sphere.
            radius (float): Radius of the Sphere.
            port_distance_from_surface (float): Distance of Ports from Sphere.
        """
        super(Sphere, self).__init__()
        particle = mb.Particle(name='np')
        particle.add(mb.Port(anchor=particle), label='out')

        # Generate 65 points on the surface of a unit sphere.
        pattern = mb.SpherePattern(n)
        # Magnify the unit sphere by the provided radius.
        pattern.scale(radius)

        particles = pattern.apply(particle,
                                  orientation='normal',
                                  compound_port='out')
        self.add(particles, label='np_[$]')

        # Create particles and Ports at pattern positions.
        for i, pos in enumerate(pattern.points):
            particle = mb.Particle(name="np", pos=pos)
            self.add(particle, "np_{}".format(i))
            port = mb.Port(anchor=particle)
            self.add(port, "port_{}".format(i))

            # Make the top of the port point toward the positive x axis.
            mb.spin_z(port, -pi / 2)
            # Raise up (or down) the top of the port in the z direction.
            mb.spin_y(port, -arcsin(pos[2] / radius))
            # Rotate the Port along the z axis.
            mb.spin_z(port, arctan2(pos[1], pos[0]))
            # Move the Port a bit away from the surface of the Sphere.
            mb.translate(port, pos / radius * port_distance_from_surface)
Exemple #35
0
    def __init__(self, alpha=0):
        super(MPC, self).__init__()

        # Look for data file in same directory as this python module.
        mb.load('mpc.pdb', compound=self, relative_to_module=self.__module__)

        # Transform the coordinate system of mpc such that the two carbon atoms
        # that are part of the backbone are on the y axis, c_backbone at the origin.
        C_top = self[37]
        # this can be achieved with the following alternative syntax:
        # C_top = self.labels["atom[37]"]
        # C_top = self.labels["atom"][37]
        C_bottom = self[1]

        mb.y_axis_transform(self, new_origin=C_top, point_on_y_axis=C_bottom)

        # Add top port.
        self.add(mb.Port(anchor=C_top), label='up')
        mb.translate(self['up'], C_top.pos - (C_top.pos - C_bottom.pos)*1.50)

        # Add bottom port
        self.add(mb.Port(anchor=C_bottom), 'down')
        mb.rotate_around_y(self['down'], alpha)
        mb.translate(self['down'], C_bottom.pos - (C_bottom.pos - C_top.pos)*1.50)
Exemple #36
0
    def create_layer(self, lipid_indices=None, flip_orientation=False):
        """Create a monolayer of lipids.

        Parameters
        ----------
        lipid_indices : list, optional, default=None
            A list of indices associated with each lipid in the layer.
        flip_orientation : bool, optional, default=False
            Flip the orientation of the layer with respect to the z-dimension.

        """
        layer = mb.Compound()
        if not lipid_indices:
            lipid_indices = list(range(self.n_lipids_per_layer))
            shuffle(lipid_indices)

        for n_type, n_of_lipid_type in enumerate(
                self.number_of_each_lipid_per_layer):
            current_type = self.lipids[n_type][0]
            for n_this_type, n_this_lipid_type in enumerate(
                    range(n_of_lipid_type)):
                lipids_placed = n_type + n_this_type
                new_lipid = clone(current_type)
                random_index = lipid_indices[lipids_placed]
                position = self.pattern[random_index]

                # Zero and space in z-direction
                particles = list(new_lipid.particles())
                ref_atom = self.ref_atoms[n_type]
                mb.translate(new_lipid,
                             -particles[ref_atom].pos + self.spacing)

                # Move to point on pattern
                if flip_orientation == True:
                    # TODO: Function for this?
                    # E.g., rotate_around_x_keep_com(compound, bool(3))
                    center = new_lipid.center
                    center[2] = 0.0
                    mb.translate(new_lipid, -center)
                    mb.rotate_around_x(new_lipid, np.pi)
                    mb.translate(new_lipid, center)
                mb.translate(new_lipid, position)
                layer.add(new_lipid)
        return layer, lipid_indices
Exemple #37
0
    def __init__(self):
        super(PegMonomer, self).__init__()

        mb.load('peg_monomer.pdb', compound=self, relative_to_module=self.__module__)
        mb.translate(self, -self[0].pos)

        self.add(mb.Port(anchor=self[0]), 'down')
        mb.translate(self['down'], [0, -0.07, 0])

        self.add(mb.Port(anchor=self[6]), 'up')
        mb.translate(self['up'], [0, 0.073, 0])
    def __init__(self):
        super(PegMonomer, self).__init__()

        mb.load('peg_monomer.pdb', compound=self, relative_to_module=self.__module__)
        mb.translate(self, -self.C[0])

        self.add(mb.Port(anchor=self.C[0]), 'down')
        mb.translate(self.down, [0, -0.07, 0])


        self.add(mb.Port(anchor=self.O[0]), 'up')
        mb.translate(self.up, [0, 0.364, 0])
Exemple #39
0
    def rigid_ch(self):
        ch = mb.load(get_fn('ch.mol2'))
        ch.name = 'CH'
        ch.label_rigid_bodies()
        mb.translate(ch, -ch[0].pos)
        ch.add(mb.Port(anchor=ch[0]), 'a')
        mb.translate(ch['a'], [0, 0.07, 0])
        mb.rotate_around_z(ch['a'], 120.0 * (np.pi / 180.0))

        ch.add(mb.Port(anchor=ch[0]), 'b')
        mb.translate(ch['b'], [0, 0.07, 0])
        mb.rotate_around_z(ch['b'], -120.0 * (np.pi / 180.0))
        return ch
Exemple #40
0
    def rigid_ch(self):
        ch = mb.load(get_fn('ch.mol2'))
        ch.name = 'CH'
        ch.label_rigid_bodies()
        mb.translate(ch, -ch[0].pos)    
        ch.add(mb.Port(anchor=ch[0]), 'a')
        mb.translate(ch['a'], [0, 0.07, 0]) 
        mb.rotate_around_z(ch['a'], 120.0 * (np.pi/180.0))

        ch.add(mb.Port(anchor=ch[0]), 'b')
        mb.translate(ch['b'], [0, 0.07, 0]) 
        mb.rotate_around_z(ch['b'], -120.0 * (np.pi/180.0))
        return ch
Exemple #41
0
    def create_layer(self, lipid_indices=None, flip_orientation=False):
        """Create a monolayer of lipids.

        Parameters
        ----------
        lipid_indices : list, optional, default=None
            A list of indices associated with each lipid in the layer.
        flip_orientation : bool, optional, default=False
            Flip the orientation of the layer with respect to the z-dimension.

        """
        layer = mb.Compound()
        if not lipid_indices:
            lipid_indices = list(range(self.n_lipids_per_layer))
            shuffle(lipid_indices)

        for n_type, n_of_lipid_type in enumerate(self.number_of_each_lipid_per_layer):
            current_type = self.lipids[n_type][0]
            for n_this_type, n_this_lipid_type in enumerate(range(n_of_lipid_type)):
                lipids_placed = n_type + n_this_type
                new_lipid = clone(current_type)
                random_index = lipid_indices[lipids_placed]
                position = self.pattern[random_index]

                # Zero and space in z-direction
                particles = list(new_lipid.particles())
                ref_atom = self.ref_atoms[n_type]
                mb.translate(new_lipid, -particles[ref_atom].pos + self.spacing)

                # Move to point on pattern
                if flip_orientation == True:
                    # TODO: Function for this?
                    # E.g., rotate_around_x_keep_com(compound, bool(3))
                    center = new_lipid.center
                    center[2] = 0.0
                    mb.translate(new_lipid, -center)
                    mb.rotate_around_x(new_lipid, np.pi)
                    mb.translate(new_lipid, center)
                mb.translate(new_lipid, position)
                layer.add(new_lipid)
        return layer, lipid_indices
Exemple #42
0
    def __init__(self):
        super(C3, self).__init__()
        self.add(mb.Particle(name='C'))

        self.add(mb.Port(anchor=self[0]), 'up')
        mb.translate(self['up'], np.array([0, 0.07, 0]))

        self.add(mb.Port(anchor=self[0]), 'down')
        mb.translate(self['down'], np.array([0, 0.07, 0]))
        mb.rotate_around_z(self['down'], np.pi * 2/3)

        self.add(mb.Port(anchor=self[0]), 'left')
        mb.translate(self['left'], np.array([0, 0.07, 0]))
        mb.rotate_around_z(self['left'], -np.pi * 2/3)
Exemple #43
0
    def __init__(self):
        super(C3, self).__init__()
        self.add(mb.Particle(name='C'))

        self.add(mb.Port(anchor=self[0]), 'up')
        mb.translate(self['up'], np.array([0, 0.07, 0]))

        self.add(mb.Port(anchor=self[0]), 'down')
        mb.translate(self['down'], np.array([0, 0.07, 0]))
        mb.spin_z(self['down'], np.pi * 2 / 3)

        self.add(mb.Port(anchor=self[0]), 'left')
        mb.translate(self['left'], np.array([0, 0.07, 0]))
        mb.spin_z(self['left'], -np.pi * 2 / 3)
Exemple #44
0
    def populate(self, compound_dict=None, x=1, y=1, z=1):
        """Expand lattice and create compound from lattice.

        populate will expand lattice based on user input. The user must also
        pass in a dictionary that contains the keys that exist in the
        basis_dict. The corresponding Compound will be the full lattice
        returned to the user.

        If no dictionary is passed to the user, Dummy Compounds will be used.

        Parameters
        ----------
        x : int, optional, default=1
            How many iterations in the x direction.
        y : int, optional, default=1
            How many iterations in the y direction.
        z : int, optional, default=1
            How many iterations in the z direction.
        compound_dict : dictionary, optional, default=None
            Link between basis_dict and Compounds.

        Exceptions Raised
        -----------------
        ValueError : incorrect x,y, or z values.
        TypeError : incorrect type for basis vector

        Call Restrictions
        -----------------
        Called after constructor by user.
        """
        error_dict = {0:'X', 1:'Y', 2:'Z'}

        # padded for Compound compatibility
        cell_edges = [edge[0] for edge in zip_longest(self.lattice_spacings, range(3), fillvalue=0.0)]

        for replication_amount in x, y, z:
            if replication_amount is None:
                raise ValueError('Attempt to replicate None times. '
                                 'None is not an acceptable replication amount, '
                                 '1 is the default.')

        for replication_amount, index in zip([x, y, z], range(3)):
            if replication_amount < 1:
                raise ValueError('Incorrect populate value: {} : {} is < 1. '
                                 .format(error_dict[index], replication_amount))

        if self.dimension == 2:
            if z > 1:
                raise ValueError('Attempting to replicate in Z. '
                                 'A non-default value for Z is being '
                                 'passed. 1 is the default value, not {}.'
                                 .format(z))
        elif self.dimension == 1:
            if (y > 1) or (z > 1):
                raise ValueError('Attempting to replicate in Y or Z. '
                                 'A non-default value for Y or Z is being '
                                 'passed. 1 is the default value.')
        else:
            pass

        if ((isinstance(compound_dict, dict)) or (compound_dict is None)):
            pass
        else:
            raise TypeError('Compound dictionary is not of type dict. '
                            '{} was passed.'.format(type(compound_dict)))

        cell = defaultdict(list)
        [a, b, c] = cell_edges
        for key, locations in self.basis_atoms.items():
            for coords in range(len(locations)):
                for replication in it.product(range(x), range(y), range(z)):
                    tmpx = (locations[coords][0] + replication[0]) * a

                    try:
                        tmpy = (locations[coords][1] + replication[1]) * b
                    except IndexError:
                        tmpy = 0.0

                    try:
                        tmpz = (locations[coords][2] + replication[2]) * c
                    except IndexError:
                        tmpz = 0.0

                    tmp_tuple = tuple((tmpx, tmpy, tmpz))
                    cell[key].append(((tmp_tuple)))

        ret_lattice = mb.Compound()
        if compound_dict is None:
            for key_id, all_pos in cell.items():
                particle = mb.Particle(name=key_id, pos=[0, 0, 0])
                for pos in all_pos:
                    particle_to_add = mb.clone(particle)
                    mb.translate(particle_to_add, list(pos))
                    ret_lattice.add(particle_to_add)
        else:
            for key_id, all_pos in cell.items():
                if isinstance(compound_dict[key_id], mb.Compound):
                    compound_to_move = compound_dict[key_id]
                    for pos in all_pos:
                        tmp_comp = mb.clone(compound_to_move)
                        mb.translate(tmp_comp, list(pos))
                        ret_lattice.add(tmp_comp)
                else:
                    err_type = type(compound_dict.get(key_id))
                    raise TypeError('Invalid type in provided Compound dictionary. '
                              'For key {}, type: {} was provided, '
                              'not mbuild.Compound.'.format(key_id, err_type))
        return ret_lattice
Exemple #45
0
import mbuild as mb
import numpy as np
import pdb
from Prototypes import *

system = ISIS()
mb.translate(system, -system[0].pos)

# Make sure the tilt angle is zero
mb.z_axis_transform(system,
                    point_on_z_axis=system.children[1],
                    point_on_zx_plane=system.children[9])

# If this thing is pointing in the negative z-direction, invert the z-coordiantes so it points positive z
for i in range(len(system.children)):
    system.children[i].pos[2] = np.abs(system.children[i].pos[2])
    system.children[i].pos[1] = np.abs(system.children[i].pos[1])
    system.children[i].pos[0] = np.abs(system.children[i].pos[0])

mb.z_axis_transform(system,
                    point_on_z_axis=system.children[1],
                    point_on_zx_plane=system.children[3])
#mb.spin_x(system, theta=(3.14)*(3/8)) #guessin between 1/2 and 1/4
mb.spin_x(system, theta=(3 / 8) * 3.14)

system.save('Prototypes/new_ISIS.gro', overwrite=True)
Exemple #46
0
 def __init__(self):
     super(alc12, self).__init__()
     mb.load(os.getcwd() + '/Prototypes/alc12.pdb', compound=self)
     mb.translate(self, -self[-1].pos)
Exemple #47
0
 def __init__(self):
     super(C16OH,self).__init__()
     mb.load('C16OH.pdb', compound=self)
     mb.translate(self, -self[-2].pos)
Exemple #48
0
    def populate(self, compound_dict=None, x=None, y=None, z=None):
        """Expand lattice and create compound from lattice.

        populate will expand lattice based on user input. The user must also
        pass in a dictionary that contains the keys that exist in the
        basis_dict. The corresponding Compound will be the full lattice
        returned to the user.

        If no dictionary is passed to the user, Dummy Compounds will be used.

        Parameters
        ----------
        x : int, optional, default=None
            How many iterations in the x direction.
        y : int, optional, default=None
            How many iterations in the y direction.
        z : int, optional, default=None
            How many iterations in the z direction.
        compound_dict : dictionary, optional, default=None
            Link between basis_dict and Compounds.

        Exceptions Raised
        -----------------
        ValueError : incorrect x,y, or z values.
        TypeError : incorrect type for basis vector

        Call Restrictions
        -----------------
        Called after constructor by user.
        """
        if self.dimension == 3:
            a = self.lattice_spacings[0]
            b = self.lattice_spacings[1]
            c = self.lattice_spacings[2]
            if x is None:
                x = 1
            if y is None:
                y = 1
            if z is None:
                z = 1
            if x < 1 or y < 1 or z < 1:
                raise ValueError('Incorrect populate value: X, Y, or Z is < 1.'
                                 ' Cannot replicate unit cell less than 1')
        elif self.dimension == 2:
            a = self.lattice_spacings[0]
            b = self.lattice_spacings[1]
            if x is None:
                x = 1
            if y is None:
                y = 1
            if z is None:
                pass
            else:
                raise ValueError('Z is defined although dimension is 2D')
            if x < 1 or y < 1:
                raise ValueError('Incorrect populate value: X or Y is < 1. '
                                 ' Cannot replicate unit cell less than 1')
        elif self.dimension == 1:
            a = self.lattice_spacings[0]
            if x is None:
                x = 1
            if y is None:
                pass
            else:
                raise ValueError('Y is defined although dimension is 1D')
            if z is None:
                pass
            if z is not None:
                raise ValueError('Z is defined although dimension is 2D')
            if x < 1:
                raise ValueError('Incorrect populate value: X < 1. '
                                 ' Cannot replicate unit cell less than 1')
        else:
            raise ValueError('Dimension not defined.')

        cell = defaultdict(list)
        for key, val in self.basis_vectors.items():
            for val_item in range(len(val)):
                if self.dimension == 3:
                    for i in range(x):
                        for j in range(y):
                            for k in range(z):
                                tmpx = (val[val_item][0] + i) * a
                                tmpy = (val[val_item][1] + j) * b
                                tmpz = (val[val_item][2] + k) * c
                                tmp_tuple = tuple((tmpx, tmpy, tmpz))
                                cell[key].append(((tmp_tuple)))
                elif self.dimension == 2:
                    for i in range(x):
                        for j in range(y):
                            tmpx = (val[val_item][0] + i) * a
                            tmpy = (val[val_item][1] + j) * b
                            tmp_tuple = tuple((tmpx, tmpy))
                            cell[key].append(((tmp_tuple)))
                else:
                    for i in range(x):
                        tmpx = (val[val_item][0] + i) * a
                        tmp_tuple = tuple((tmpx))
                        cell[key].append(((tmp_tuple)))

        ret_lattice = mb.Compound()
        if compound_dict is None:
            for key_id, all_pos in cell.items():
                particle = mb.Particle(name=key_id, pos=[0, 0, 0])
                for pos in all_pos:
                    particle_to_add = mb.clone(particle)
                    mb.translate(particle_to_add, list(pos))
                    ret_lattice.add(particle_to_add)
        else:
            for key_id, all_pos in cell.items():
                if isinstance(compound_dict[key_id], mb.Compound):
                    compound_to_move = compound_dict[key_id]
                    for pos in all_pos:
                        tmp_comp = mb.clone(compound_to_move)
                        mb.translate(tmp_comp, list(pos))
                        ret_lattice.add(tmp_comp)
                else:
                    err_type = type(compound_dict.get(key_id))
                    TypeError('Invalid type in provided Compound Dictionary. '
                              'For key {}, type: {} was provided, '
                              'not Compound.'.format(key_id, err_type))
        return ret_lattice
    def __init__(self):
        super(EtBen, self).__init__()

        mb.load('/Users/jonestj1/ethylbenzene.pdb', compound=self)
        mb.translate(self, -self.atoms[0])