def test_bad_args(self, h2o):
     with pytest.raises(ValueError):
         mb.fill_box(h2o, n_compounds=10)
     with pytest.raises(ValueError):
         mb.fill_box(h2o, density=1000)
     with pytest.raises(ValueError):
         mb.fill_box(h2o, box=[2, 2, 2])
     with pytest.raises(ValueError):
         mb.fill_box(h2o, n_compounds=10, density=1000, box=[2, 2, 2])
     with pytest.raises(ValueError):
         mb.fill_box(compound=[h2o, h2o], n_compounds=[10], density=1000)
     with pytest.raises(ValueError):
         mb.solvate(solute=h2o,
                    solvent=[h2o],
                    n_solvent=[10, 10],
                    box=[2, 2, 2])
     with pytest.raises(ValueError):
         mb.fill_region(h2o,
                        n_compounds=[10, 10],
                        region=[2, 2, 2, 4, 4, 4])
     with pytest.raises(ValueError):
         mb.fill_box(
             compound=[h2o, h2o],
             n_compounds=[10],
             density=1000,
             fix_orientation=[True, True, True],
         )
Exemple #2
0
    def __init__(self,
                 pore_depth=4,
                 side_dim=3,
                 n_sheets=3,
                 pore_width=1,
                 x_bulk=3,
                 solvent=None,
                 n_solvent=100):

        super(GraphenePoreSolvent, self).__init__()

        pore = GraphenePore(pore_depth=pore_depth,
                            side_dim=side_dim,
                            n_sheets=n_sheets,
                            pore_width=pore_width)

        box = mb.Box(pore.periodicity)
        box.maxs[0] += 2 * x_bulk

        system = mb.solvate(pore, solvent, n_solvent, box=box, overlap=0.2)

        for child in system.children:
            self.add(mb.clone(child))

        self.periodicity = box.maxs
Exemple #3
0
    def test_box_edge(self, h2o, methane):
        system_box = mb.Box(lengths=(1.8, 1.8, 1.8))
        packed = mb.fill_box(compound=h2o,
                             n_compounds=100,
                             box=system_box,
                             edge=0.2)
        edge_sizes = system_box.lengths - packed.boundingbox.lengths
        assert np.allclose(edge_sizes, np.array([0.4]*3), atol=0.1)

        region = mb.fill_region(compound=h2o,
                                n_compounds=100,
                                region=system_box,
                                edge=0.2)
        edge_sizes = system_box.lengths - packed.boundingbox.lengths
        assert np.allclose(edge_sizes, np.array([0.4]*3), atol=0.1)

        sphere = mb.fill_sphere(compound=h2o,
                                n_compounds=100,
                                sphere=[2, 2, 2, 1],
                                edge=0.2)
        assert np.allclose(sphere.boundingbox.mins, np.array([1.2]*3), atol=0.1)
        assert np.allclose(sphere.boundingbox.maxs, np.array([2.8]*3), atol=0.1)

        solvated = mb.solvate(solvent=h2o,
                              solute=methane,
                              n_solvent=100,
                              box=system_box,
                              overlap=0.2)
        edge_sizes = system_box.lengths - solvated.boundingbox.lengths
        assert np.allclose(edge_sizes, np.array([0.4]*3), atol=0.1)
Exemple #4
0
 def test_write_temp_file(self, h2o):
     cwd = os.getcwd() # Must keep track of the temp dir that pytest creates
     filled = mb.fill_box(h2o, n_compounds=10, box=[4, 4, 4], temp_file='temp_file1.pdb')
     region = mb.fill_region(h2o, 10, [2, 2, 2, 4, 4, 4], temp_file='temp_file2.pdb')
     solvated = mb.solvate(filled, h2o, 10, box=[4, 4, 4], temp_file='temp_file3.pdb')
     assert os.path.isfile(os.path.join(cwd, 'temp_file1.pdb'))
     assert os.path.isfile(os.path.join(cwd, 'temp_file2.pdb'))
     assert os.path.isfile(os.path.join(cwd, 'temp_file3.pdb'))
Exemple #5
0
 def test_write_temp_file(self, h2o):
     cwd = os.getcwd() # Must keep track of the temp dir that pytest creates
     filled = mb.fill_box(h2o, n_compounds=10, box=[4, 4, 4], temp_file='temp_file1.pdb')
     region = mb.fill_region(h2o, 10, [2, 2, 2, 4, 4, 4], temp_file='temp_file2.pdb')
     solvated = mb.solvate(filled, h2o, 10, box=[4, 4, 4], temp_file='temp_file3.pdb')
     assert os.path.isfile(os.path.join(cwd, 'temp_file1.pdb'))
     assert os.path.isfile(os.path.join(cwd, 'temp_file2.pdb'))
     assert os.path.isfile(os.path.join(cwd, 'temp_file3.pdb'))
Exemple #6
0
 def test_bad_args(self, h2o):
     with pytest.raises(ValueError):
         mb.fill_box(h2o, n_compounds=10)
     with pytest.raises(ValueError):
         mb.fill_box(h2o, density=1000)
     with pytest.raises(ValueError):
         mb.fill_box(h2o, box=[2, 2, 2])
     with pytest.raises(ValueError):
         mb.fill_box(h2o, n_compounds=10, density=1000, box=[2, 2, 2])
     with pytest.raises(ValueError):
         mb.fill_box(compound=[h2o, h2o], n_compounds=[10], density=1000)
     with pytest.raises(ValueError):
         mb.solvate(solute=h2o, solvent=[h2o], n_solvent=[10, 10], box=[2, 2, 2])
     with pytest.raises(ValueError):
         mb.fill_region(h2o, n_compounds=[10, 10], region=[2, 2, 2, 4, 4, 4])
     with pytest.raises(ValueError):
         mb.fill_box(compound=[h2o, h2o], n_compounds=[10], density=1000,
                     fix_orientation=[True, True, True])
    def __init__(self,
                 solv,
                 n_solvent,
                 length=3,
                 radius=None,
                 chirality="armchair",
                 n=None,
                 m=None,
                 superPacked=False):
        super(SWCNT_solvated, self).__init__(length,
                                             radius=radius,
                                             chirality=chirality,
                                             n=n,
                                             m=m)

        #Quick method packs molecules into smaller box but with a higher density
        if superPacked:
            minimums = (self.r * np.cos(.75 * np.pi),
                        self.r * np.cos(.25 * np.pi), 0)
            maximums = (self.r * np.cos(.25 * np.pi),
                        self.r * np.cos(.75 * np.pi), length)
            box = mb.Box(mins=minimums, maxs=maximums)

            mb.solvate(self, solv, n_solvent, box=box)

        #Slow method carves out cyilnder of molecules from box of proper
        #density molecules silghtly larger than the nanotube
        else:

            s = mb.Compound(name="Temp")

            box = mb.Box(mins=(-self.r, -self.r, 0),
                         maxs=(self.r, self.r, length))
            print(box)

            s = mb.solvate(s, solv, n_solvent, box)

            for child in s:
                if child.pos[0] < self.r - .1 and child.pos[
                        1] < self.r - .1 and child.name != "Temp":
                    self.add(mb.clone(child))

            del s
Exemple #8
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)
    def test_box_edge(self, h2o, methane):
        system_box = mb.Box(lengths=(1.8, 1.8, 1.8))
        packed = mb.fill_box(compound=h2o,
                             n_compounds=100,
                             box=system_box,
                             edge=0.2)
        edge_sizes = np.subtract(system_box.lengths,
                                 packed.get_boundingbox().lengths)
        assert np.allclose(edge_sizes, np.array([0.4] * 3), atol=0.1)

        region = mb.fill_region(
            compound=h2o,
            n_compounds=100,
            region=system_box,
            edge=0.2,
            bounds=[system_box],
        )
        edge_sizes = np.subtract(system_box.lengths,
                                 packed.get_boundingbox().lengths)
        assert np.allclose(edge_sizes, np.array([0.4] * 3), atol=0.1)

        edge = 0.2
        bounds = [2, 2, 2, 1]
        sphere = mb.fill_sphere(compound=h2o,
                                n_compounds=100,
                                sphere=bounds,
                                edge=edge)
        target_diameter = (bounds[3] - edge) * 2
        assert np.allclose(sphere.maxs - sphere.mins,
                           np.array([target_diameter] * 3),
                           atol=0.1)

        solvated = mb.solvate(
            solvent=h2o,
            solute=methane,
            n_solvent=100,
            box=system_box,
            overlap=0.2,
        )
        edge_sizes = np.subtract(system_box.lengths,
                                 solvated.get_boundingbox().lengths)
        assert np.allclose(edge_sizes, np.array([0.4] * 3), atol=0.1)
 def test_solvate_multiple(self, methane, ethane, h2o):
     init_box = mb.fill_box(methane, 2, box=[4, 4, 4])
     solvated = mb.solvate(init_box, [ethane, h2o], [20, 20], box=[4, 4, 4])
     assert solvated.n_particles == 2 * 5 + 20 * 8 + 20 * 3
     assert len(solvated.children) == 41
 def test_solvate(self, ethane, h2o):
     n_solvent = 100
     solvated = mb.solvate(ethane, h2o, n_solvent=n_solvent, box=[4, 4, 4])
     assert solvated.n_particles == 8 + n_solvent * 3
     assert solvated.n_bonds == 7 + n_solvent * 2
     assert ethane.parent == None
Exemple #12
0
 def test_solvate_multiple(self, methane, ethane, h2o):
     init_box = mb.fill_box(methane, 2, box=[4, 4, 4])
     solvated = mb.solvate(init_box, [ethane, h2o], [20, 20], box=[4, 4, 4])
     assert solvated.n_particles == 2*5 + 20*8 + 20*3
     assert len(solvated.children) == 41
Exemple #13
0
 def test_solvate(self, ethane, h2o):
     n_solvent = 100
     solvated = mb.solvate(ethane, h2o, n_solvent=n_solvent, box=[4, 4, 4])
     assert solvated.n_particles == 8 + n_solvent * 3
     assert solvated.n_bonds == 7 + n_solvent * 2
Exemple #14
0
 def test_solvate(self, ethane, h2o):
     solvated = mb.solvate(ethane, h2o, n_solvent=100, box=[4, 4, 4])
     assert solvated.n_particles == 8 + 100 * 3
     assert solvated.n_bonds == 7 + 100 * 2
Exemple #15
0
# Bilayer needs to be shifted to fit inside the box for gromacs (can't have any negative coordinates)
mb.translate(system, [
    np.abs(systembox.mins[0]),
    np.abs(systembox.mins[1]),
    np.abs(systembox.mins[2])
])

# Shrink the x and y dimensions of the box to prevent packmol from shoving atoms in weird locations
cross_area = (n_x * spacing - 1) * (n_y * spacing - 1)
leaflet_water_z = n_solvent_per_layer * 2.66602458e-2 / cross_area
# Redefine the box to account for shifted coordinates and add extra space in z-direcction
smallbox = mb.Box(
    mins=[0, 0, systembox.mins[2] - leaflet_water_z],
    maxs=[n_x * spacing, n_y * spacing, systembox.maxs[2] + leaflet_water_z])
# The solvate box will have a reduced cross-sectional area to prevent waters in strange locations
solvatebox = mb.Box(
    mins=[0.5, 0.5, smallbox.mins[2]],
    maxs=[smallbox.maxs[0] - 0.5, smallbox.maxs[1] - 0.5, smallbox.maxs[2]])

# Solvate system
system = mb.solvate(system, H2O(), 2 * n_solvent_per_layer, solvatebox)

# Bilayer needs to be shifted to fit inside the box for gromacs (can't have any negative coordinates)
mb.translate(system, [
    np.abs(smallbox.mins[0]),
    np.abs(smallbox.mins[1]),
    np.abs(smallbox.mins[2])
])

system.save('mbuild_bilayer.gro', box=smallbox, overwrite=True)
Exemple #16
0
def main():
    """Solvate an ethane molecule in a Box of water. """
    ethane = Ethane()
    water = H2O()
    return mb.solvate(ethane, water, 500, box=[2, 2, 2])