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]))
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
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
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
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
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]))
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)
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)
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'])
def main(): """A quick test for updating a Compound and traversing its hierarchy. """ # Create a compound and write it to file. brush1 = Brush() brush1.save("brush1.pdb") # Create another compound, rotate it and write it to file. brush2 = Brush() mb.rotate_around_z(brush2, pi/2) brush2.save("brush2.pdb") # Load brush2.pdb into brush1, modifying the atom positions of brush1. brush1.update_coordinates("brush2.pdb") brush1.save("modified_brush1.pdb") # Access the internals of the updated brush1. print(brush1['pmpc']) for mpc in brush1['pmpc']['monomer']: print(mpc)
def test_reload(self): from mbuild.examples.pmpc.brush import Brush from numpy import pi # Create a compound and write it to file. brush1 = Brush() brush1.save("brush1.pdb") # Create another compound, rotate it and write it to file. brush2 = Brush() mb.rotate_around_z(brush2, pi / 2) brush2.save("brush2.pdb") # Load brush2.pdb into brush1, modifying the atom positions of brush1. brush1.update_coordinates("brush2.pdb") brush1.save("modified_brush1.pdb") assert brush1['pmpc'].n_particles == 164 assert brush1['pmpc'].n_bonds == 163 assert len(brush1['pmpc']['monomer']) == 4 assert brush1['pmpc']['monomer'][0].n_particles == 41 assert brush1['pmpc']['monomer'][0].n_bonds == 40
def test_reload(self): from mbuild.examples.pmpc.brush import Brush from numpy import pi # Create a compound and write it to file. brush1 = Brush() brush1.save("brush1.pdb") # Create another compound, rotate it and write it to file. brush2 = Brush() mb.rotate_around_z(brush2, pi/2) brush2.save("brush2.pdb") # Load brush2.pdb into brush1, modifying the atom positions of brush1. brush1.update_coordinates("brush2.pdb") brush1.save("modified_brush1.pdb") assert brush1['pmpc'].n_particles == 164 assert brush1['pmpc'].n_bonds == 163 assert len(brush1['pmpc']['monomer']) == 4 assert brush1['pmpc']['monomer'][0].n_particles == 41 assert brush1['pmpc']['monomer'][0].n_bonds == 40