예제 #1
0
 def test_fill_region_incorrect_type(self, ethane):
     box1 = {"a": 1}
     with pytest.raises(ValueError, match=r"expected a list of type:"):
         mb.fill_region(compound=[ethane],
                        n_compounds=[2],
                        region=box1,
                        bounds=None)
예제 #2
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],
         )
예제 #3
0
 def test_fill_region_multiple(self, ethane, h2o):
     filled = mb.fill_region(compound=[ethane, h2o], n_compounds=[2, 2],
                             region=[[2, 2, 2, 4, 4, 4], [4, 2, 2, 6, 4, 4]])
     assert filled.n_particles == 2 * 8 + 2 * 3
     assert filled.n_bonds == 2 * 7 + 2 * 2
     assert np.max(filled.xyz[:16, 0]) < 4
     assert np.min(filled.xyz[16:, 0]) > 4
예제 #4
0
 def test_fill_region_box(self, h2o):
     mybox = mb.Box([4, 4, 4])
     filled = mb.fill_region(h2o, n_compounds=50, region=mybox)
     assert filled.n_particles == 50 * 3
     assert filled.n_bonds == 50 * 2
     assert np.min(filled.xyz[:,0]) >= 0
     assert np.max(filled.xyz[:,2]) <= 4
예제 #5
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)
예제 #6
0
 def test_fill_region_multiple(self, ethane, h2o):
     filled = mb.fill_region(compound=[ethane, h2o], n_compounds=[2, 2],
                             region=[[2, 2, 2, 4, 4, 4], [4, 2, 2, 6, 4, 4]])
     assert filled.n_particles == 2 * 8 + 2 * 3
     assert filled.n_bonds == 2 * 7 + 2 * 2
     assert np.max(filled.xyz[:16, 0]) < 4
     assert np.min(filled.xyz[16:, 0]) > 4
예제 #7
0
 def test_fill_region_box(self, h2o):
     mybox = mb.Box([4, 4, 4])
     filled = mb.fill_region(h2o, n_compounds=50, region=mybox)
     assert filled.n_particles == 50 * 3
     assert filled.n_bonds == 50 * 2
     assert np.min(filled.xyz[:, 0]) >= 0
     assert np.max(filled.xyz[:, 2]) <= 4
예제 #8
0
 def test_fill_region(self, h2o):
     filled = mb.fill_region(h2o, n_compounds=50,
                             region=[3, 2, 2, 4, 4, 3])
     assert filled.n_particles == 50 * 3
     assert filled.n_bonds == 50 * 2
     assert np.min(filled.xyz[:,0]) >= 3
     assert np.max(filled.xyz[:,2]) <= 3
예제 #9
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'))
예제 #10
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'))
예제 #11
0
 def test_fill_region_multiple_types(self, ethane, h2o):
     box1 = mb.Box(mins=[2, 2, 2], maxs=[4, 4, 4])
     box2 = [4, 2, 2, 6, 4, 4]
     filled = mb.fill_region(compound=[ethane, h2o], n_compounds=[2, 2],
                             region=[box1, box2])
     assert filled.n_particles == 2 * 8 + 2 * 3
     assert filled.n_bonds == 2 * 7 + 2 * 2
     assert np.max(filled.xyz[:16, 0]) < 4
     assert np.min(filled.xyz[16:, 0]) > 4
예제 #12
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])
예제 #13
0
 def test_fill_region_multiple_types(self, ethane, h2o):
     box1 = mb.Box(mins=[2, 2, 2], maxs=[4, 4, 4])
     box2 = [4, 2, 2, 6, 4, 4]
     filled = mb.fill_region(compound=[ethane, h2o], n_compounds=[2, 2],
                             region=[box1, box2])
     assert filled.n_particles == 2 * 8 + 2 * 3
     assert filled.n_bonds == 2 * 7 + 2 * 2
     assert np.max(filled.xyz[:16, 0]) < 4
     assert np.min(filled.xyz[16:, 0]) > 4
예제 #14
0
 def test_fill_region_box(self, h2o):
     mybox = Box(lengths=[4, 4, 4], angles=[90.0, 90.0, 90.0])
     filled = mb.fill_region(h2o,
                             n_compounds=50,
                             region=mybox,
                             bounds=[[0, 0, 0, 4, 4, 4]])
     assert filled.n_particles == 50 * 3
     assert filled.n_bonds == 50 * 2
     assert np.min(filled.xyz[:, 0]) >= 0
     assert np.max(filled.xyz[:, 2]) <= 4
예제 #15
0
 def test_fill_region(self, h2o):
     filled = mb.fill_region(h2o, n_compounds=50, region=[3, 2, 2, 5, 5, 5])
     assert filled.n_particles == 50 * 3
     assert filled.n_bonds == 50 * 2
     assert np.min(filled.xyz[:, 0]) >= 3
     assert np.min(filled.xyz[:, 1]) >= 2
     assert np.min(filled.xyz[:, 2]) >= 2
     assert np.max(filled.xyz[:, 0]) <= 5
     assert np.max(filled.xyz[:, 1]) <= 5
     assert np.max(filled.xyz[:, 2]) <= 5
예제 #16
0
 def test_fill_region_multiple(self, ethane, h2o):
     box1 = mb.Box(lengths=[2, 2, 2], angles=[90.0, 90.0, 90.0])
     box2 = mb.Box(lengths=[2, 2, 2], angles=[90.0, 90.0, 90.0])
     filled = mb.fill_region(
         compound=[ethane, h2o],
         n_compounds=[2, 2],
         region=[box1, box2],
         bounds=[[2, 2, 2, 4, 4, 4], [4, 2, 2, 6, 4, 4]],
     )
     assert filled.n_particles == 2 * 8 + 2 * 3
     assert filled.n_bonds == 2 * 7 + 2 * 2
     assert np.max(filled.xyz[:16, 0]) < 4
     assert np.min(filled.xyz[16:, 0]) > 4
예제 #17
0
 def test_fill_region(self, h2o):
     filled = mb.fill_region(
         h2o,
         n_compounds=50,
         region=Box(lengths=[2, 3, 3], angles=[90.0, 90.0, 90.0]),
         bounds=[[3, 2, 2, 5, 5, 5]],
     )
     assert filled.n_particles == 50 * 3
     assert filled.n_bonds == 50 * 2
     assert np.min(filled.xyz[:, 0]) >= 3
     assert np.min(filled.xyz[:, 1]) >= 2
     assert np.min(filled.xyz[:, 2]) >= 2
     assert np.max(filled.xyz[:, 0]) <= 5
     assert np.max(filled.xyz[:, 1]) <= 5
     assert np.max(filled.xyz[:, 2]) <= 5
예제 #18
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 = 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)
예제 #19
0
 def test_box_no_bound(self, ethane):
     box1 = Box(lengths=[2, 2, 2], angles=[90.0, 90.0, 90.0])
     mb.fill_region(compound=[ethane],
                    n_compounds=[2],
                    region=box1,
                    bounds=None)