Ejemplo n.º 1
0
 def __init__(self):
     super(I2, self).__init__()
     
     iodine1= mb.Particle(pos=[0.0, 0.0, 0.0], name='I')
     iodine2= mb.Particle(pos=[0.8, 0.0, 0.0], name='I')
     self.add([iodine2,iodine1])
     self.add_bond((iodine2,iodine1))
 def __init__(self):
     super(OH, self).__init__()
     self.add(mb.Particle(name='O', pos=[0.0, 0.0, 0.0]), label='O')
     self.add(mb.Particle(name='H', pos=[0.0, 0.1, 0.0]), label='H')
     self.add_bond((self['O'], self['H']))
     # add the port to the oxygen atom along the [0,-1, 0] direction
     self.add(mb.Port(anchor=self['O'], orientation=[0, -1, 0], separation=0.075), label='down')
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def __init__(self):
     super(Cl2, self).__init__()
     
     chlorine1= mb.Particle(pos=[0.0, 0.0, 0.0], name='Cl')
     chlorine2= mb.Particle(pos=[0.2, 0.0, 0.0], name='Cl')
     self.add([chlorine2,chlorine1])
     self.add_bond((chlorine2,chlorine1))
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def __init__(self):
     super(O2, self).__init__()
     
     oxygen1= mb.Particle(pos=[0.0, 0.0, 0.0], name='O')
     oxygen2= mb.Particle(pos=[0.15, 0.0, 0.0], name='O')
     self.add([oxygen2,oxygen1])
     self.add_bond((oxygen2,oxygen1))
Ejemplo n.º 7
0
    def __init__(self):
        super(FCl, self).__init__()

        fluorine1 = mb.Particle(pos=[0.0, 0.0, 0.0], name='F')
        chlorine2 = mb.Particle(pos=[0.2, 0.0, 0.0], name='Cl')
        self.add([fluorine1, chlorine2])
        self.add_bond((fluorine1, chlorine2))
Ejemplo n.º 8
0
    def __init__(self):
        super(N2, self).__init__()

        nitrogen1 = mb.Particle(pos=[0.0, 0.0, 0.0], name='N')
        nitrogen2 = mb.Particle(pos=[0.2, 0.0, 0.0], name='N')
        self.add([nitrogen2, nitrogen1])
        self.add_bond((nitrogen2, nitrogen1))
Ejemplo n.º 9
0
    def __init__(self):
        super(H2O, self).__init__()

        self.add(mb.Particle(name="O", pos=[1.0203, 0.7604, 1.2673]))
        self.add(mb.Particle(name="H", pos=[0.9626, 0.8420, 1.2673]))
        self.add(mb.Particle(name="H", pos=[0.9626, 0.6787, 1.2673]))
        self.add_bond((self[0], self[1]))
        self.add_bond((self[0], self[2]))
Ejemplo n.º 10
0
 def __init__(self):
     super(CHF, self).__init__()
     carbon = mb.Particle(name='C', pos=[0.0, 0.0, 0.0])
     hydrogen = mb.Particle(name='H', pos=[0.0, -0.15, 0.0])
     fluorine = mb.Particle(name='F', pos=[0.0, 0.15, 0.0])
     self.add([carbon, hydrogen, fluorine])
     self.add_bond((carbon, hydrogen))
     self.add_bond((carbon, fluorine))
Ejemplo n.º 11
0
    def test_parmed_element_guess(self):
        compound = mb.Particle(name='foobar')
        with pytest.warns(UserWarning):
            _ = compound.to_parmed()

        compound = mb.Particle(name='XXXXXX')
        with pytest.warns(UserWarning):
            _ = compound.to_parmed()
Ejemplo n.º 12
0
 def __init__(self):
     super(Hydroxyl, self).__init__()
     #self.add(mb.Particle(name='_OH'))
     oxygen = mb.Particle(name='O', pos=[0.0, 0.0, 0.0])
     hydrogen = mb.Particle(name='H', pos=[0.0945, 0.0, 0.0])
     self.add((oxygen, hydrogen))
     self.add_bond((oxygen, hydrogen))
     self.add(mb.Port(anchor=oxygen,
                      orientation=[-1, 0, 0],
                      separation=0.075),
              label='up')
Ejemplo n.º 13
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
Ejemplo n.º 14
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
Ejemplo n.º 15
0
    def __init__(self, nano, n, box, seed=12345):
        super(PatchyBox, self).__init__()

        if type(nano) is not list:
            nano = [nano]
        if type(n) is not list:
            n = [n]

        # Define positions for nanoparticles (use points to speed
        # this up)
        point_rep = mb.Particle(name='point0')
        d_vdw = max([
            max(nano[0].xyz[:, dim]) - min(nano[0].xyz[:, dim])
            for dim in range(3)
        ])
        point_box = mb.fill_box(point_rep,
                                n[0],
                                box,
                                overlap=d_vdw + 0.5,
                                edge=d_vdw / 2 + 0.25,
                                seed=seed)

        for i, (np_proto, np_n) in enumerate(zip(nano[1:], n[1:])):
            point_rep = mb.Particle(name='point{:d}'.format(i + 1))
            d_vdw = max([
                max(np_proto.xyz[:, dim]) - min(np_proto.xyz[:, dim])
                for dim in range(3)
            ])
            point_box = mb.solvate(solute=point_box,
                                   solvent=point_rep,
                                   n_solvent=np_n,
                                   box=box,
                                   overlap=d_vdw + 0.5,
                                   edge=d_vdw / 2 + 0.25,
                                   seed=seed)
        self.periodicity = box.lengths
        random.seed(seed)

        # Replicate the nanoparticle at the defined positions
        for particle in point_box.particles():
            nano_index = int(particle.name.strip('point'))
            nano_clone = mb.clone(nano[nano_index])
            nano_clone.spin(
                random.random() * 2 * np.pi,
                np.array([random.random(),
                          random.random(),
                          random.random()]) - 0.5)
            #mb.translate_to(nano_clone, particle.pos)
            nano_clone.translate_to(particle.pos)
            self.add(nano_clone)
Ejemplo n.º 16
0
 def __init__(self,
              n_beads=10,
              build='linear',
              bead_name='bead',
              spring_distance=1):
     super(BeadSpring, self).__init__()
     prev_bead = mb.Particle(pos=[0.0, 0.0, 0.0], name=bead_name)
     self.add(prev_bead)
     for n in range(1, n_beads):
         current_bead = mb.Particle(pos=[0.0, 0.0, n * spring_distance],
                                    name=bead_name)
         self.add(current_bead)
         self.add_bond((prev_bead, current_bead))
         prev_bead = current_bead
Ejemplo n.º 17
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')
Ejemplo n.º 18
0
    def visualize_qcc_input(self, i, single=True):
        """Visualize the input for pyscf using mbuild.

        Parameters
        ----------
        i : int
            Index of the single or pair input to visualize.
        single : bool, default True
            Whether to visualize a single or pair input.

        Note
        ----
        The visualize functions require mbuild, a visualization backend (py3Dmol
        or nglview), and a jupyter notebook. They are designed only to help
        troubleshoot.
        """
        import mbuild as mb

        if single:
            qcc_input = self.chromophores[i].qcc_input
        else:
            qcc_input = self.qcc_pairs[i][1]
        comp = mb.Compound()
        for line in qcc_input.split(";")[:-1]:
            atom, x, y, z = line.split()
            xyz = np.array([x,y,z], dtype=float)
            # Angstrom -> nm
            xyz /= 10
            comp.add(mb.Particle(name=atom, pos=xyz))
        comp.visualize().show()
Ejemplo n.º 19
0
def offmol_to_compound(off_mol: "Molecule") -> "mb.Compound":
    """Covert an OpenFF Molecule into an mBuild Compound.

    Examples
    --------

    .. code-block:: pycon

        >>> from openff.toolkit.topology import Molecule
        >>> from openff.interchange.components.mbuild import offmol_to_compound
        >>> mol = Molecule.from_smiles("CCO")
        >>> compound = offmol_to_compound(mol)
        >>> type(compound), compound.n_particles, compound.n_bonds
        (<class 'mbuild.compound.Compound'>, 9, 8)

    """
    if not off_mol.has_unique_atom_names:
        off_mol.generate_unique_atom_names()

    if off_mol.n_conformers == 0:
        off_mol.generate_conformers(n_conformers=1)

    comp = mb.Compound()
    comp.name = off_mol.name

    for a in off_mol.atoms:
        atom_comp = mb.Particle(name=a.element.symbol)
        comp.add(atom_comp, label=a.name)

    for b in off_mol.bonds:
        comp.add_bond((comp[b.atom1_index], comp[b.atom2_index]))

    comp.xyz = off_mol.conformers[0].value_in_unit(unit.nanometer)

    return comp
Ejemplo n.º 20
0
    def __init__(self):
        super(H, self).__init__()
        self.add(mb.Particle(name="H"))

        self.add(mb.Port(anchor=self[0]), "up")
        self["up"].spin(np.pi, [0, 0, 1])
        self["up"].translate(np.array([0, 0.07, 0]))
Ejemplo n.º 21
0
Archivo: h.py Proyecto: sallai/mbuild
    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]))
Ejemplo n.º 22
0
            def __init__ (self, radius, bead_diameter):
                super(Core, self).__init__()
                
                core_bead = mb.Particle(name='_CGN')

                # calculate n number of core particles from ratio of core total SA and single bead SA
                n_core_particles = (int)((4*np.pi*(radius**2))/(4*np.pi*(bead_diameter/2)**2))
                
                # arrange beads into a sphere pattern and add it to the compound
                core_pattern = mb.SpherePattern(n_core_particles)
                core_pattern.scale(radius)

                core_formation = core_pattern.apply(core_bead)
                self.add(core_formation)
                
                self.generate_bonds(name_a='_CGN', name_b='_CGN', dmin=bead_diameter*2-0.4, dmax=bead_diameter*2+0.3)

                print('Core beads added.')

                # apply ports to each bead in core_formation
                for i, pos in enumerate(core_pattern.points):
                    port = mb.Port(anchor=core_formation[i], orientation=pos, separation=radius/5)
                    self.add(port, label='port[$]')

                print('Ports added to core')
Ejemplo n.º 23
0
def test_assert_bonds():
    ff = Forcefield(name='trappe-ua')

    derponium = mb.Compound()
    at1 = mb.Particle(name='H')
    at2 = mb.Particle(name='O')
    at3 = mb.Particle(name='_CH4')

    derponium.add([at1, at2, at3])
    derponium.add_bond((at1, at2))
    derponium.add_bond((at2, at3))

    with pytest.raises(Exception):
        ff.apply(derponium)
    thing = ff.apply(derponium, assert_bond_params=False, assert_angle_params=False)
    assert any(b.type is None for b in thing.bonds)
Ejemplo n.º 24
0
    def __init__(self):
        super(IN, self).__init__(
            pos=[0, 0,
                 0], name='bb')  #Initizlize an instance of abstract class

        bead = mb.Particle(pos=[0.0, 0.0, 0.0], name='IN')
        self.add(bead)
Ejemplo n.º 25
0
    def _create_crosslinks(self):
        """Creates the crosslinks between monolayer chains. """
        crosslinks = self.crosslink_graph.edges()
        pos = nx.get_node_attributes(self.crosslink_graph, 'pos')
        attachment = nx.get_node_attributes(self.crosslink_graph,
                                            'surface_bound')
        for crosslink in crosslinks:
            atom1 = crosslink[0]
            atom2 = crosslink[1]
            loc1 = deepcopy(atom1.pos)
            loc2 = deepcopy(atom2.pos)
            for i in range(2):
                if loc1[i] - loc2[i] > self.periodicity[i] / 2:
                    loc1[i] -= self.periodicity[i]
                elif loc1[i] - loc2[i] < -self.periodicity[i] / 2:
                    loc1[i] += self.periodicity[i]
            # Add an oxygen atom midway between the two silicon atoms
            midpoint = (loc1 + loc2) / 2
            oxygen = mb.Particle(name='O', pos=midpoint)
            self.add(oxygen, 'crosslink_oxygen[$]')
            self.add_bond((atom1, oxygen))
            self.add_bond((atom2, oxygen))

        # Add hydroxyls to dangling bonds of silane silicons
        for node in self.crosslink_graph.nodes():
            neighbors = len(self.bond_graph.neighbors(node))
            if neighbors == 2:
                self._add_hydroxyls(node, 2)
            elif neighbors == 3:
                self._add_hydroxyls(node, 1)
Ejemplo n.º 26
0
    def __init__(self):
        super(H, self).__init__()
        self.add(mb.Particle(name='H'))

        self.add(mb.Port(anchor=self[0]), 'down')
        self['down'].spin(np.pi, [0, 0, 1])
        self['down'].translate(np.array([0, 0.07, 0]))
Ejemplo n.º 27
0
    def __init__(self):
        super(Methane, self).__init__()
        carbon = mb.Particle(name='C')
        self.add(carbon)

        hydrogen = mb.Particle(name='H', pos=[0.1, 0, -0.07])
        self.add(hydrogen)

        self.add_bond((self[0], self[1]))

        self.add(mb.Particle(name='H', pos=[-0.1, 0, -0.07]))
        self.add(mb.Particle(name='H', pos=[0, 0.1, 0.07]))
        self.add(mb.Particle(name='H', pos=[0, -0.1, 0.07]))

        self.add_bond((self[0], self[2]))
        self.add_bond((self[0], self[3]))
        self.add_bond((self[0], self[4]))
Ejemplo n.º 28
0
    def __init__(self):
        super(Methane, self).__init__()
        carbon = mb.Particle(name="C")
        self.add(carbon, label="C[$]")

        hydrogen = mb.Particle(name="H", pos=[0.1, 0, -0.07])
        self.add(hydrogen, label="HC[$]")

        self.add_bond((self[0], self["HC"][0]))

        self.add(mb.Particle(name="H", pos=[-0.1, 0, -0.07]), label="HC[$]")
        self.add(mb.Particle(name="H", pos=[0, 0.1, 0.07]), label="HC[$]")
        self.add(mb.Particle(name="H", pos=[0, -0.1, 0.07]), label="HC[$]")

        self.add_bond((self[0], self["HC"][1]))
        self.add_bond((self[0], self["HC"][2]))
        self.add_bond((self[0], self["HC"][3]))
Ejemplo n.º 29
0
    def __init__(self):
        super(Methane, self).__init__()
        carbon = mb.Particle(name="C", element="C")
        self.add(carbon)

        hydrogen = mb.Particle(name="H", pos=[0.1, 0, -0.07], element="H")
        self.add(hydrogen)

        self.add_bond((self[0], self[1]))

        self.add(mb.Particle(name="H", pos=[-0.1, 0, -0.07], element="H"))
        self.add(mb.Particle(name="H", pos=[0, 0.1, 0.07], element="H"))
        self.add(mb.Particle(name="H", pos=[0, -0.1, 0.07], element="H"))

        self.add_bond((self[0], self[2]))
        self.add_bond((self[0], self[3]))
        self.add_bond((self[0], self[4]))
Ejemplo n.º 30
0
 def test_single_particle(self):
     part = mb.Particle(name='A')
     assert part.n_particles == 1
     assert len(list(part.particles())) == 1
     assert part.xyz.shape == (1, 3)
     assert part.root == part
     assert len(list(part.ancestors())) == 0
     assert next(part.particles_by_name('A')) == part