Example #1
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]), '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))

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

        for _ in range(5):
            ch_new = mb.clone(ch)
            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
Example #2
0
    def __init__(self, chain_length):
        super(AlkylSilane, self).__init__()

        self.add(mb.Particle(name='H'))
        self.add(mb.Port(anchor=self[0]), 'oH')
        self['oH'].spin(np.pi, [0, 0, 1])
        self['oH'].translate(np.array([0, 0.097 / 2, 0]))

        self.add(mb.Particle(name='O'))
        self.add(mb.Port(anchor=self[1]), label='Oh')
        self['Oh'].spin(np.pi, [0, 0, 1])
        self['Oh'].translate(np.array([0, 0.097 / 2, 0]))
        mb.force_overlap(self[0], self['oH'], self['Oh'])
        self.add(mb.Port(anchor=self[1]), label='alcohol')
        self['alcohol'].spin(np.pi, [0, 0, 1])
        self['alcohol'].translate(np.array([0, -0.097 / 2, 0]))

        CH2 = mb.lib.moieties.CH2()
        alkane = Polymer(CH2, chain_length, port_labels=['up', 'down'])
        silane = Silane()
        mb.force_overlap(silane, silane['down'], self['alcohol'])
        self.add(silane, 'silane')
        mb.force_overlap(alkane, alkane['down'], silane['up'])
        self.add(alkane, 'alkane')

        # Hoist silane port to AlkylSilane level.
        #self.add(silane['down'], 'down', containment=False)

        #remove a hydrogen to add a port for the second functionalgroup
        self.remove(self['alkane'][3 * chain_length - 1])
        self.add(self.all_ports()[0], 'secondary', containment=False)
        self.add(self.all_ports()[1], 'primary', containment=False)
Example #3
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.
            port.spin(-pi/2, [0, 0, 1])
            # Raise up (or down) the top of the port in the z direction.
            port.spin(-arcsin(pos[2]/radius), [0, 1, 0])
            # Rotate the Port along the z axis.
            port.spin(arctan2(pos[1], pos[0]), [0, 0, 1])
            # Move the Port a bit away from the surface of the Sphere.
            port.translate(pos/radius * port_distance_from_surface)
Example #4
0
 def test_center(self, methane):
     assert np.array_equal(methane.center, np.array([0, 0, 0]))
     for orientation in np.identity(3):
         separation = 0.2
         port = mb.Port(anchor=methane[0], orientation=orientation)
         assert np.allclose(port.center,
                            np.array([0.0, 0.0, 0.0]),
                            atol=1e-15)
         port = mb.Port(anchor=methane[0],
                        orientation=orientation,
                        separation=separation)
         assert np.allclose(port.center,
                            separation * orientation,
                            atol=1e-15)
     np.random.seed(0)
     for orientation in np.random.rand(5, 3):
         port = mb.Port(anchor=methane[0], orientation=orientation)
         assert np.allclose(port.center,
                            np.array([0.0, 0.0, 0.0]),
                            atol=1e-15)
         port = mb.Port(anchor=methane[0],
                        orientation=orientation,
                        separation=separation)
         assert np.allclose(port.center,
                            separation * orientation /
                            np.linalg.norm(orientation),
                            atol=1e-15)
Example #5
0
    def benzene_from_parts(self):
        ch = mb.load(get_fn('ch.mol2'))
        ch.name = 'CH'
        ch.translate(-ch[0].pos)       
        ch.add(mb.Port(anchor=ch[0], separation=0.07), 'a')
        ch['a'].rotate(120.0 * (np.pi/180.0), around=np.asarray([0, 0, 1]))
        ch.add(mb.Port(anchor=ch[0], separation=0.07), 'b')
        ch['b'].rotate(-120.0 * (np.pi/180.0), around=np.asarray([0, 0, 1]))
        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
Example #6
0
    def __init__(self):
        super().__init__(name='mvp')

        n = mb.Particle(name='N')
        c1 = mb.Particle(name='C')
        c2 = mb.Particle(name='C')
        c3 = mb.Particle(name='C')
        c4 = mb.Particle(name='C')
        o41 = mb.Particle(name='O')
        c5 = mb.Particle(name='C')
        c6 = mb.Particle(name='C')

        self.add([n, c1, c2, c3, c4, o41, c5, c6])

        self.add_bond([n, c1])
        self.add_bond([c1, c2])
        self.add_bond([c3, c2])
        self.add_bond([c3, c4])
        self.add_bond([c4, o41])
        self.add_bond([c4, n])
        self.add_bond([n, c5])
        self.add_bond([c5, c6])

        self.add(mb.Port(anchor=c5), 'up')
        self.add(mb.Port(anchor=c6), 'down')
Example #7
0
File: o.py Project: dubosese/atools
 def __init__(self):
     super(O, self).__init__()
             
     mb.load('o.pdb', compound=self, relative_to_module=self.__module__)
     self.add(mb.Port(anchor=self[0], orientation=[0, 0, 1], 
                      separation=.075), label='up')
     self.add(mb.Port(anchor=self[0], orientation=[0, 0, -1], 
                      separation=.075), label='down')
Example #8
0
 def test_up_down_reverse_orientation_axes(self):
     for vector in [[1, 0, 0], [0, 1, 0], [0, 0, 1]]:
         port1 = mb.Port(orientation=vector)
         port2 = mb.Port(orientation=-np.array(vector))
         assert np.allclose(port1['up'].xyz_with_ports,
                            port2['down'].xyz_with_ports)
         assert np.allclose(port1['down'].xyz_with_ports,
                            port2['up'].xyz_with_ports)
Example #9
0
    def test_port_separation(self, ethane):
        port = mb.Port(anchor=ethane, separation=0.7)
        assert np.allclose(0.7, port.separation, atol=1e-15)

        port_no_anchor = mb.Port()
        with pytest.warns(UserWarning):
            separation = port_no_anchor.separation
        assert separation is None
Example #10
0
    def test_port_separation(self, ethane):
        port = mb.Port(anchor=ethane, separation=0.7)
        assert (np.allclose(0.7, port.separation, atol=1e-15))

        port_no_anchor = mb.Port()
        with warnings.catch_warnings(record=True) as w:
            separation = port_no_anchor.separation
            assert w
            assert (separation is None)
Example #11
0
 def __init__ (self, chain_separation=0.30):
     super(CGMMM, self).__init__()
     middle_bead = mb.Particle(name='_MMM')
     self.add(middle_bead, 'middle_bead')
     
     self.add(mb.Port(anchor=self['middle_bead']), label='up')
     self.add(mb.Port(anchor=self['middle_bead']), label='down')
     mb.Compound.translate(self['up'], [0, chain_separation, 0])
     mb.Compound.translate(self['down'], [0, -(chain_separation), 0])
    def __init__(self):
        super(CH2UA, self).__init__()
        self.add(mb.Particle(name='_CH2'))

        self.add(mb.Port(anchor=self[0], separation=0.075), 'up')

        self.add(
            mb.Port(anchor=self[0], orientation=[0, -1, 0], separation=0.075),
            'down')
Example #13
0
 def __init__(self, filepath, bond_indices):
     super(Monomer, self).__init__()
     mb.load(filepath, compound=self)
     # mb.Compound.translate(self, -self[0].pos)  # center molecule at origin
     # self.add_bond((self[1], self[3]))
     self.add(mb.Port(anchor=self[bond_indices[0]]), label='up')
     self.add(mb.Port(anchor=self[bond_indices[1]]), label='down')
     mb.Compound.translate(self['up'], [bond_length, 0, 0])
     mb.Compound.translate(self['down'], [-bond_length, 0, 0])
Example #14
0
    def __init__(self):
        super(MMM, self).__init__()
        self.add(mb.Particle(name='_MMM'))

        self.add(mb.Port(anchor=self[0], separation=0.18), 'up')

        self.add(
            mb.Port(anchor=self[0], orientation=[0, -1, 0], separation=0.18),
            'down')
Example #15
0
 def test_up_down_reverse_orientation_random(self):
     np.random.seed(84)
     for _ in range(15):
         vector = np.random.random(3) - 0.5
         port1 = mb.Port(orientation=vector)
         port2 = mb.Port(orientation=-vector)
         assert np.allclose(port1['up'].xyz_with_ports,
                            port2['down'].xyz_with_ports)
         assert np.allclose(port1['down'].xyz_with_ports,
                            port2['up'].xyz_with_ports)
Example #16
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])
Example #17
0
    def __init__(self):
        super(Phenyl, self).__init__()

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

        self.add(mb.Port(anchor=self[0], orientation=[0, -1, 0], separation=0.07),
            'down')
        self.add(mb.Port(anchor=self[3], orientation=[0, 1, 0], separation=0.07),
            'up')
Example #18
0
File: peg.py Project: sallai/mbuild
    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])
Example #19
0
    def __init__(self):
        super(CH2, self).__init__()

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

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

        self.add(mb.Port(anchor=self[0]), 'down')
        self['down'].translate([0, -0.07, 0])
Example #20
0
    def __init__(self):
        super(Ch2, self).__init__()

        mb.load('ch2.pdb', compound=self, relative_to_module=self.__module__)
        carbon = list(self.particles_by_name('C'))[0]
        self.add(mb.Port(anchor=carbon, orientation=[0, 0, 1],
                         separation=.075),
                 label='up')
        self.add(mb.Port(anchor=carbon,
                         orientation=[0, 0, -1],
                         separation=0.075),
                 label='down')
Example #21
0
    def __init__(self):
        super(Silicon, self).__init__()
        self.add(mb.Particle(name='Si'))

        self.add(mb.Port(anchor=self[0], orientation=[0, 0, 1], separation=0.07),
                 label='up')
        self.add(mb.Port(anchor=self[0], orientation=[0, 0, -1], separation=0.07),
                 label='down')
        self.add(mb.Port(anchor=self[0], orientation=[1, 0, 0], separation=0.07),
                 label='right')
        self.add(mb.Port(anchor=self[0], orientation=[-1, 0, 0], separation=0.07),
                 label='left')
Example #22
0
    def __init__(self):
        super(Oxygen, self).__init__()

        self.add(mb.Particle(name='O'))
        up_port = mb.Port(anchor=self[0],
                          orientation=[0, 0, 1],
                          separation=.075)
        down_port = mb.Port(anchor=self[0],
                            orientation=[0, 0, -1],
                            separation=.075)
        self.add(up_port, label='up')
        self.add(down_port, label='down')
Example #23
0
 def sixpoints(self):
     molecule = mb.Compound()
     molecule.add(mb.Particle(name="C", pos=[5, 5, 5]), label="middle")
     molecule.add(mb.Particle(name="C", pos=[6, 5, 5]), label="right")
     molecule.add(mb.Particle(name="C", pos=[4, 5, 5]), label="left")
     molecule.add(mb.Port(anchor=molecule[0]), label="up")
     molecule["up"].translate([0, 1, 0])
     molecule.add(mb.Port(anchor=molecule[0]), label="down")
     molecule["down"].translate([0, -1, 0])
     molecule.add(mb.Particle(name="C", pos=[5, 5, 6]), label="front")
     molecule.add(mb.Particle(name="C", pos=[5, 5, 4]), label="back")
     molecule.generate_bonds("C", "C", 0.9, 1.1)
     return molecule
Example #24
0
 def sixpoints(self):
     molecule = mb.Compound()
     molecule.add(mb.Particle(name='C', pos=[5, 5, 5]), label='middle')
     molecule.add(mb.Particle(name='C', pos=[6, 5, 5]), label='right')
     molecule.add(mb.Particle(name='C', pos=[4, 5, 5]), label='left')
     molecule.add(mb.Port(anchor=molecule[0]), label='up')
     molecule['up'].translate([0, 1, 0])
     molecule.add(mb.Port(anchor=molecule[0]), label='down')
     molecule['down'].translate([0, -1, 0])
     molecule.add(mb.Particle(name='C', pos=[5, 5, 6]), label='front')
     molecule.add(mb.Particle(name='C', pos=[5, 5, 4]), label='back')
     molecule.generate_bonds('C', 'C', 0.9, 1.1)
     return molecule
Example #25
0
File: peg.py Project: daico007/TNP
    def __init__(self):
        super(PegMonomer, self).__init__()

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

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

        self.add(mb.Port(anchor=self[6]), 'down')
        self['down'].translate([0, -0.073, 0]) 
Example #26
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
Example #27
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]))
Example #28
0
    def __init__(self):
        super(C3, self).__init__()
        self.add(mb.Particle(name="C"))

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

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

        self.add(mb.Port(anchor=self[0]), "left")
        self["left"].translate(np.array([0, 0.07, 0]))
        self["left"].spin(-np.pi * 2 / 3, [0, 0, 1])
Example #29
0
    def rigid_ch(self):
        ch = mb.load(get_fn('ch.mol2'))
        ch.name = 'CH'
        ch.label_rigid_bodies()
        ch.translate(-ch[0].pos)    
        ch.add(mb.Port(anchor=ch[0]), 'a')
        ch['a'].translate([0, 0.07, 0]) 
        ch['a'].rotate(120.0 * (np.pi/180.0), around=np.asarray([0, 0, 1]))

        ch.add(mb.Port(anchor=ch[0]), 'b')
        ch['b'].translate([0, 0.07, 0]) 
        ch['b'].rotate(-120.0 * (np.pi/180.0), around=np.asarray([0, 0, 1]))

        return ch
Example #30
0
    def __init__(self):
        super(C3, self).__init__()
        self.add(mb.Particle(name='C'))

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

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

        self.add(mb.Port(anchor=self[0]), 'left')
        self['left'].translate(np.array([0, 0.07, 0]))
        self['left'].spin(-np.pi * 2 / 3, [0, 0, 1])