Ejemplo n.º 1
0
 def test_mismatch_boxes(self, methane_oplsaa, box):
     with pytest.raises(ValueError, match=r"requires 1 simulation"):
         system = mc.System(
             [box, box], [methane_oplsaa], mols_to_add=[[10], [0]]
         )
         moves = mc.Moves("nvt", [methane_oplsaa])
         mc.run(system, moves, 300.0, "equilibration", 500)
     with pytest.raises(ValueError, match=r"requires 2 simulation"):
         system = mc.System([box], [methane_oplsaa], mols_to_add=[[10]])
         moves = mc.Moves("gemc", [methane_oplsaa])
         mc.run(system, moves, 300.0, "equilibration", 500)
Ejemplo n.º 2
0
    def test_corrupt_topologies(self, methane_oplsaa, box):
        with pytest.raises(TypeError, match=r"corrupted"):
            system = mc.System([box], [methane_oplsaa], mols_to_add=[[10]])
            moves = mc.Moves("nvt", [methane_oplsaa])

            system._species_topologies = methane_oplsaa
            mc.run(system, moves, 300.0, "equilibration", 500)

        with pytest.raises(TypeError, match=r"corrupted"):
            system = mc.System([box], [methane_oplsaa], mols_to_add=[[10]])
            moves = mc.Moves("nvt", [methane_oplsaa])

            system.species_topologies[0] = 1
            mc.run(system, moves, 300.0, "equilibration", 500)
Ejemplo n.º 3
0
    def test_corrupt_natoms(self, methane_oplsaa, box):
        with pytest.raises(ValueError, match=r"corrupted"):
            system = mc.System([box], [methane_oplsaa], mols_to_add=[[10]])
            moves = mc.Moves("nvt", [methane_oplsaa])

            system.mols_in_boxes[0][0] = 10
            mc.run(system, moves, 300.0, "equilibration", 500)
Ejemplo n.º 4
0
def run_nvt_mixture():
    # Use mbuild to create molecules
    methane = mbuild.load("C", smiles=True)
    propane = mbuild.load("CCC", smiles=True)

    # Create an empty mbuild.Box
    box = mbuild.Box(lengths=[3.0, 3.0, 3.0])

    # Load forcefields
    oplsaa = foyer.forcefields.load_OPLSAA()

    # Use foyer to apply forcefields
    typed_methane = oplsaa.apply(methane)
    typed_propane = oplsaa.apply(propane)

    # Create box and species list
    box_list = [box]
    species_list = [typed_methane, typed_propane]

    # Use Cassandra to insert some initial number of species
    mols_to_add = [[100, 50]]

    system = mc.System(box_list, species_list, mols_to_add=mols_to_add)
    moves = mc.Moves("nvt", species_list)

    mc.run(
        system=system,
        moves=moves,
        run_type="equilibration",
        run_length=10000,
        temperature=200.0,
    )
Ejemplo n.º 5
0
    def test_restricted_gemc_npt(self, methane_oplsaa):
        moves = mc.Moves("gemc_npt", [methane_oplsaa])
        moves.add_restricted_insertions([methane_oplsaa],
                                        [[None], ["slitpore"]], [[None], [3]])

        assert moves._restricted_type == [[None], ["slitpore"]]
        assert moves._restricted_value == [[None], [3]]
Ejemplo n.º 6
0
    def test_ensemble_gcmc(self, methane_oplsaa):
        moves = mc.Moves("gcmc", [methane_oplsaa])
        assert moves.ensemble == "gcmc"
        assert moves.prob_translate == 0.25
        assert moves.prob_rotate == 0.25
        assert moves.prob_regrow == 0.30
        assert moves.prob_volume == 0.0
        assert moves.prob_angle == 0.0
        assert moves.prob_dihedral == 0.0
        assert moves.prob_insert == 0.1
        assert moves.prob_swap == 0.0

        # Per box attributes
        assert len(moves.max_translate) == 1
        assert len(moves.max_rotate) == 1
        assert len(moves.max_volume) == 1
        assert len(moves.prob_swap_from_box) == 1
        assert moves.prob_swap_from_box[0] == 1.0
        assert moves.max_volume[0] == 0.0
        # Per species-per-box
        assert len(moves.max_translate[0]) == 1
        assert len(moves.max_rotate[0]) == 1
        # Per species attributes
        assert len(moves.sp_insertable) == 1
        assert len(moves.sp_prob_swap) == 1
        assert len(moves.sp_prob_regrow) == 1

        # Should be insertable and regrow-able
        assert moves.sp_insertable[0] == True
        assert moves.sp_prob_regrow[0] == 1.0
Ejemplo n.º 7
0
    def test_restricted_gemc(self, methane_oplsaa, typ, value):
        moves = mc.Moves("gemc", [methane_oplsaa])
        moves.add_restricted_insertions([methane_oplsaa], [[None], [typ]],
                                        [[None], [value]])

        assert moves._restricted_type == [[None], [typ]]
        assert moves._restricted_value == [[None], [value]]
Ejemplo n.º 8
0
    def test_single_site_gemc(self, methane_trappe):

        moves = mc.Moves("gemc", [methane_trappe])
        assert moves.ensemble == "gemc"
        assert moves.prob_rotate == 0.0
        assert moves.prob_regrow == 0.0
        assert moves.prob_translate == pytest.approx(0.88)
        assert moves.prob_volume == 0.02
        assert moves.prob_angle == 0.0
        assert moves.prob_dihedral == 0.0
        assert moves.prob_insert == 0.0
        assert moves.prob_swap == 0.1

        # Per box attributes
        assert len(moves.max_translate) == 2
        assert len(moves.max_rotate) == 2
        assert len(moves.max_volume) == 1
        assert len(moves.prob_swap_from_box) == 2
        assert moves.prob_swap_from_box[0] == 0.5
        assert moves.prob_swap_from_box[1] == 0.5
        assert moves.max_volume[0] == 500.0
        # Per species-per-box
        assert len(moves.max_translate[0]) == 1
        assert len(moves.max_translate[1]) == 1
        assert len(moves.max_rotate[0]) == 1
        assert len(moves.max_rotate[1]) == 1
        # Per species attributes
        assert len(moves.sp_insertable) == 1
        assert len(moves.sp_prob_swap) == 1
        assert len(moves.sp_prob_regrow) == 1

        # Should be insertable and NOT regrow-able
        assert moves.sp_insertable[0] == True
        assert moves.sp_prob_regrow[0] == 0.0
Ejemplo n.º 9
0
 def test_invalid_species_list(self, methane_oplsaa):
     with pytest.raises(
             TypeError,
             match=r"species_topologies should "
             "be a list of species",
     ):
         moves = mc.Moves("nvt", methane_oplsaa)
def run_gcmc_restricted():

    # Use mbuild to create molecules
    methane = mbuild.load("C", smiles=True)

    # Create an empty mbuild.Box
    box = mbuild.Box(lengths=[5.0, 5.0, 5.0])

    # Load forcefields
    oplsaa = foyer.forcefields.load_OPLSAA()

    # Use foyer to apply forcefields
    methane_ff = oplsaa.apply(methane)

    # Create box and species list
    box_list = [box]
    species_list = [methane_ff]

    mols_to_add = [[10]]

    system = mc.System(box_list, species_list, mols_to_add=mols_to_add)
    moves = mc.Moves("gcmc", species_list)

    # Specify restricted insertions
    moves.add_restricted_insertions(species_list, [["sphere"]], [[20]])

    mc.run(
        system=system,
        moves=moves,
        run_type="equilibration",
        run_length=100,
        temperature=300.0,
        chemical_potentials=[-35.0],
        prop_freq=10,
    )
Ejemplo n.º 11
0
 def test_add_multiple_restricted_insertions(self, methane_oplsaa):
     moves = mc.Moves("gcmc", [methane_oplsaa])
     moves.add_restricted_insertions([methane_oplsaa], [["slitpore"]],
                                     [[3]])
     with pytest.warns(None) as record:
         moves.add_restricted_insertions([methane_oplsaa], [["cylinder"]],
                                         [[3]])
Ejemplo n.º 12
0
def run_nvt():

    # Use mbuild to create molecules
    methane = mbuild.load("C", smiles=True)

    # Create an empty mbuild.Box
    box = mbuild.Box(lengths=[3.0, 3.0, 3.0])

    # Load forcefields
    oplsaa = foyer.forcefields.load_OPLSAA()

    # Use foyer to apply forcefields
    methane_ff = oplsaa.apply(methane)

    # Create box and species list
    box_list = [box]
    species_list = [methane_ff]

    # Use Cassandra to insert some initial number of species
    mols_to_add = [[50]]

    # Define the system object
    system = mc.System(box_list, species_list, mols_to_add=mols_to_add)
    # Get the move probabilities
    moves = mc.Moves("nvt", species_list)

    # Run a simulation with at 300 K with 10000 MC moves
    mc.run(
        system=system,
        moves=moves,
        run_type="equilibration",
        run_length=10000,
        temperature=300.0,
    )
Ejemplo n.º 13
0
    def test_gcmc_lattice(self, fixed_lattice_trappe, methane_trappe):

        moves = mc.Moves("gcmc", [fixed_lattice_trappe, methane_trappe])
        assert moves.ensemble == "gcmc"
        assert moves.prob_translate == pytest.approx(0.8)
        assert moves.prob_rotate == 0.0
        assert moves.prob_regrow == 0.0
        assert moves.prob_volume == 0.0
        assert moves.prob_angle == 0.0
        assert moves.prob_dihedral == 0.0
        assert moves.prob_insert == 0.1
        assert moves.prob_swap == pytest.approx(0.0)

        # Per box attributes
        assert len(moves.max_translate) == 1
        assert len(moves.max_rotate) == 1
        assert len(moves.max_volume) == 1
        assert len(moves.prob_swap_from_box) == 1
        assert moves.prob_swap_from_box[0] == 1.0
        assert moves.max_volume[0] == 0.0
        # Per species-per-box
        assert len(moves.max_translate[0]) == 2
        assert len(moves.max_rotate[0]) == 2
        # Per species attributes
        assert len(moves.sp_insertable) == 2
        assert len(moves.sp_prob_swap) == 2
        assert len(moves.sp_prob_regrow) == 2

        # Lattice should not be insertable or regrow-able
        assert moves.sp_insertable[0] == False
        assert moves.sp_prob_regrow[0] == 0.0
        # Methane should be insertable and not regrow-able
        assert moves.sp_insertable[1] == True
        assert moves.sp_prob_regrow[1] == 0.0
Ejemplo n.º 14
0
def run_gcmc_adsorption():

    # Use mbuild to create molecules
    lattice = carbon_lattice()
    methane = mbuild.load("C", smiles=True)

    # Load forcefields
    trappe = foyer.forcefields.load_TRAPPE_UA()
    oplsaa = foyer.forcefields.load_OPLSAA()

    # Use foyer to apply forcefields
    typed_lattice = trappe.apply(lattice)
    methane_ff = oplsaa.apply(methane)

    # Create box and species list
    box_list = [lattice]
    species_list = [typed_lattice, methane_ff]

    # Since we have an occupied box we need to specify
    # the number of each species present in the intial config
    mols_in_boxes = [[1, 0]]

    system = mc.System(box_list, species_list, mols_in_boxes=mols_in_boxes)
    moves = mc.Moves("gcmc", species_list)

    custom_args = {
        "chemical_potentials": ["none", -30.0],
        "rcut_min": 0.5,
        "vdw_cutoff": 14.0,
        "charge_cutoff": 14.0,
        "coord_freq": 100,
        "prop_freq": 10,
    }

    mc.run(
        system=system,
        moves=moves,
        run_type="equilibration",
        run_length=10000,
        temperature=300.0,
        **custom_args,
    )
Ejemplo n.º 15
0
def run_gemc(job):
    "Run gemc"

    import mbuild
    import foyer
    import mosdef_cassandra as mc

    ff = foyer.Forcefield(job.fn("ff.xml"))

    # Load the compound and apply the ff
    compound = mbuild.load("C(F)(F)C(F)(F)F", smiles=True)
    compound_ff = ff.apply(compound)

    # Create box list and species list
    boxl = job.doc.liqbox_final_dim  # saved in nm
    liq_box = mbuild.load(job.fn("liqbox.xyz"))
    liq_box.periodicity = [boxl, boxl, boxl]
    boxl = job.doc.vapboxl  # nm
    vap_box = mbuild.Box(lengths=[boxl, boxl, boxl])

    box_list = [liq_box, vap_box]
    species_list = [compound_ff]

    mols_in_boxes = [[job.sp.N_liq], [0]]
    mols_to_add = [[0], [job.sp.N_vap]]

    system = mc.System(
        box_list,
        species_list,
        mols_in_boxes=mols_in_boxes,
        mols_to_add=mols_to_add,
    )

    # Create a new moves object
    moves = mc.Moves("gemc", species_list)

    # Edit the volume and swap move probability to be more reasonable
    orig_prob_volume = moves.prob_volume
    orig_prob_swap = moves.prob_swap
    new_prob_volume = 1.0 / (job.sp.N_liq + job.sp.N_vap)
    new_prob_swap = 4.0 / 0.05 / (job.sp.N_liq + job.sp.N_vap)
    moves.prob_volume = new_prob_volume
    moves.prob_swap = new_prob_swap

    moves.prob_translate = (moves.prob_translate + orig_prob_volume -
                            new_prob_volume)
    moves.prob_translate = (moves.prob_translate + orig_prob_swap -
                            new_prob_swap)

    # Define thermo output props
    thermo_props = [
        "energy_total",
        "pressure",
        "volume",
        "nmols",
        "mass_density",
        "enthalpy",
    ]

    # Define custom args
    custom_args = {
        "run_name": "equil",
        "charge_style": "ewald",
        "rcut_min": 1.0,
        "charge_cutoff_box2": 25.0,
        "vdw_cutoff_box1": 12.0,
        "vdw_cutoff_box2": 25.0,
        "units": "sweeps",
        "steps_per_sweep": job.sp.N_liq + job.sp.N_vap,
        "coord_freq": 500,
        "prop_freq": 10,
        "properties": thermo_props,
    }

    # Move into the job dir and start doing things
    with job:
        # Run equilibration
        mc.run(system=system,
               moves=moves,
               run_type="equilibration",
               run_length=job.sp.nsteps_eq,
               temperature=job.sp.T,
               **custom_args)

        # Adjust custom args for production
        custom_args["run_name"] = "prod"
        custom_args["restart_name"] = "equil"

        # Run production
        mc.restart(system=system,
                   moves=moves,
                   run_type="production",
                   run_length=job.sp.nsteps_prod,
                   temperature=job.sp.T,
                   **custom_args)
Ejemplo n.º 16
0
 def test_change_ensemble(self, methane_oplsaa):
     moves = mc.Moves("gcmc", [methane_oplsaa])
     with pytest.raises(AttributeError,
                        match=r"Ensemble cannot be changed"):
         moves.ensemble = "nvt"
Ejemplo n.º 17
0
 def test_type_error_restricted_type_and_value(self, methane_oplsaa):
     moves = mc.Moves("gcmc", [methane_oplsaa])
     with pytest.raises(TypeError):
         moves.add_restricted_insertions([methane_oplsaa], ["cylinder"],
                                         [3])
Ejemplo n.º 18
0
 def test_invalid_restricted_type_and_species(self, methane_oplsaa):
     moves = mc.Moves("gcmc", [methane_oplsaa])
     with pytest.raises(ValueError, match=r"Length of 'species'"):
         moves.add_restricted_insertions([methane_oplsaa],
                                         [["slitpore", None]], [[1, None]])
Ejemplo n.º 19
0
 def test_invalid_ensemble_and_restriction(self, methane_oplsaa):
     moves = mc.Moves("nvt", [methane_oplsaa])
     with pytest.raises(ValueError, match=r"only valid"):
         moves.add_restricted_insertions([methane_oplsaa], [["slitpore"]],
                                         [[1]])
Ejemplo n.º 20
0
 def test_value_error_restricted_type_and_value(self, methane_oplsaa, typ,
                                                value):
     moves = mc.Moves("gcmc", [methane_oplsaa])
     with pytest.raises(ValueError):
         moves.add_restricted_insertions([methane_oplsaa], [[typ]], value)
Ejemplo n.º 21
0
    def test_print_moves(self, methane_oplsaa):
        """Simple test to make sure moves object is printed"""

        moves = mc.Moves("gemc", [methane_oplsaa])
        moves.print()
Ejemplo n.º 22
0
    def test_maxval_setters(self, methane_oplsaa):
        moves = mc.Moves("gemc", [methane_oplsaa])
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_translate = 1.0
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_translate = [[1.0, 1.0], [1.0]]
        with pytest.raises(TypeError, match=r"of type float"):
            moves.max_translate = [[1.0], [True]]
        with pytest.raises(ValueError, match=r"cannot be less than zero"):
            moves.max_translate = [[1.0], [-1.0]]
        moves.max_translate = [[1.0], [1]]
        assert moves.max_translate[1][0] == 1.0

        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_rotate = 1.0
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_rotate = [[1.0, 1.0], [1.0]]
        with pytest.raises(TypeError, match=r"of type float"):
            moves.max_rotate = [[1.0], [True]]
        with pytest.raises(ValueError, match=r"cannot be less than zero"):
            moves.max_rotate = [[1.0], [-1.0]]
        moves.max_rotate = [[1.0], [1]]
        assert moves.max_rotate[1][0] == 1.0

        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_dihedral = 1.0
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_dihedral = [1.0, 1.0, 1.0]
        with pytest.raises(TypeError, match=r"of type float"):
            moves.max_dihedral = [True]
        with pytest.raises(ValueError, match=r"cannot be less than zero"):
            moves.max_dihedral = [-1.0]
        moves.max_dihedral = [1.0]
        assert moves.max_dihedral[0] == 1.0

        with pytest.raises(ValueError, match=r"must be a list"):
            moves.prob_swap_from_box = 1.0
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.prob_swap_from_box = [1.0, 1.0, 1.0]
        with pytest.raises(TypeError, match=r"of type float"):
            moves.prob_swap_from_box = [0.5, True]
        with pytest.raises(ValueError, match=r"cannot be less than zero"):
            moves.prob_swap_from_box = [0.5, -0.5]
        moves.prob_swap_from_box = [0.5, 0.5]
        assert moves.prob_swap_from_box[0] == 0.5

        moves = mc.Moves("gemc", [methane_oplsaa])
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_volume = 1.0
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_volume = [1.0, 1.0, 1.0]
        with pytest.raises(TypeError, match=r"of type float"):
            moves.max_volume = [True]
        with pytest.raises(ValueError, match=r"cannot be less than zero"):
            moves.max_volume = [-100]
        moves.max_volume = [5000.0]
        assert moves.max_volume[0] == 5000.0
        moves = mc.Moves("gemc_npt", [methane_oplsaa])
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_volume = 1.0
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.max_volume = [1.0, 1.0, 1.0]
        with pytest.raises(TypeError, match=r"of type float"):
            moves.max_volume = [True, 50000.0]
        with pytest.raises(ValueError, match=r"cannot be less than zero"):
            moves.max_volume = [-100, 100.0]
        moves.max_volume = [5000.0, 50000.0]
        assert moves.max_volume[1] == 50000.0

        moves = mc.Moves("gemc", [methane_oplsaa])
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.sp_insertable = 1.0
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.sp_insertable = [1.0, 1.0, 1.0]
        with pytest.raises(TypeError, match=r"as a boolean type"):
            moves.sp_insertable = [2.0]
        moves.sp_insertable = [True]
        assert moves.sp_insertable[0] == True

        with pytest.raises(ValueError, match=r"must be a list"):
            moves.sp_prob_swap = 1.0
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.sp_prob_swap = [1.0, 1.0, 1.0]
        with pytest.raises(TypeError, match=r"of type float"):
            moves.sp_prob_swap = [True]
        with pytest.raises(ValueError, match=r"cannot be less than zero"):
            moves.sp_prob_swap = [-1.0]
        moves.sp_prob_swap = [1.0]
        assert moves.sp_prob_swap[0] == 1.0

        with pytest.raises(ValueError, match=r"must be a list"):
            moves.sp_prob_regrow = 1.0
        with pytest.raises(ValueError, match=r"must be a list"):
            moves.sp_prob_regrow = [1.0, 1.0, 1.0]
        with pytest.raises(TypeError, match=r"of type float"):
            moves.sp_prob_regrow = [True]
        with pytest.raises(ValueError, match=r"cannot be less than zero"):
            moves.sp_prob_regrow = [-1.0]
        moves.sp_prob_regrow = [1.0]
        assert moves.sp_prob_regrow[0] == 1.0
Ejemplo n.º 23
0
def equilibrate_liqbox(job):
    "Equilibrate the liquid box"

    import os
    import errno
    import mbuild
    import foyer
    import mosdef_cassandra as mc

    ff = foyer.Forcefield(job.fn("ff.xml"))

    # Load the compound and apply the ff
    compound = mbuild.load("C(F)(F)C(F)(F)F", smiles=True)
    compound_ff = ff.apply(compound)

    # Create box list and species list
    boxl = job.doc.liqboxl
    box = mbuild.Box(lengths=[boxl, boxl, boxl])

    box_list = [box]
    species_list = [compound_ff]

    mols_to_add = [[job.sp.N_liq]]

    system = mc.System(box_list, species_list, mols_to_add=mols_to_add)

    # Create a new moves object
    moves = mc.Moves("npt", species_list)

    # Edit the volume move probability to be more reasonable
    orig_prob_volume = moves.prob_volume
    new_prob_volume = 1.0 / job.sp.N_liq
    moves.prob_volume = new_prob_volume

    moves.prob_translate = (moves.prob_translate + orig_prob_volume -
                            new_prob_volume)

    # Define thermo output props
    thermo_props = [
        "energy_total",
        "pressure",
        "volume",
        "nmols",
        "mass_density",
    ]

    # Define custom args
    custom_args = {
        "run_name": "equil",
        "charge_style": "ewald",
        "rcut_min": 1.0,
        "vdw_cutoff": 12.0,
        "units": "sweeps",
        "steps_per_sweep": job.sp.N_liq,
        "coord_freq": 500,
        "prop_freq": 10,
        "properties": thermo_props,
    }

    # Move into the job dir and start doing things
    with job:
        liq_dir = "liqbox-equil"
        try:
            os.mkdir(liq_dir)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        os.chdir(liq_dir)
        # Run equilibration
        mc.run(system=system,
               moves=moves,
               run_type="equilibration",
               run_length=job.sp.nsteps_liqeq,
               temperature=job.sp.T,
               pressure=job.sp.P,
               **custom_args)
Ejemplo n.º 24
0
 def test_invalid_ensemble(self, methane_oplsaa):
     with pytest.raises(ValueError, match=r"Invalid ensemble"):
         moves = mc.Moves("nvtn", [methane_oplsaa])
Ejemplo n.º 25
0
 def test_invalid_species_type(self):
     with pytest.raises(TypeError,
                        match=r"each species should be "
                        "a parmed.Structure"):
         moves = mc.Moves("nvt", [1])
Ejemplo n.º 26
0
    def test_prob_setters(self, methane_oplsaa):
        moves = mc.Moves("nvt", [methane_oplsaa])
        with pytest.raises(TypeError, match=r"prob_translate must"):
            moves.prob_translate = []
        with pytest.raises(TypeError, match=r"prob_translate must"):
            moves.prob_translate = True
        with pytest.raises(ValueError, match=r"Probability must"):
            moves.prob_translate = -0.2

        with pytest.raises(TypeError, match=r"prob_rotate must"):
            moves.prob_rotate = []
        with pytest.raises(TypeError, match=r"prob_rotate must"):
            moves.prob_rotate = True
        with pytest.raises(ValueError, match=r"Probability must"):
            moves.prob_rotate = -0.2

        with pytest.raises(TypeError, match=r"prob_angle must"):
            moves.prob_angle = []
        with pytest.raises(TypeError, match=r"prob_angle must"):
            moves.prob_angle = True
        with pytest.raises(ValueError, match=r"Probability must"):
            moves.prob_angle = -0.2

        with pytest.raises(TypeError, match=r"prob_dihedral must"):
            moves.prob_dihedral = []
        with pytest.raises(TypeError, match=r"prob_dihedral must"):
            moves.prob_dihedral = True
        with pytest.raises(ValueError, match=r"Probability must"):
            moves.prob_dihedral = -0.2

        with pytest.raises(TypeError, match=r"prob_regrow must"):
            moves.prob_regrow = []
        with pytest.raises(TypeError, match=r"prob_regrow must"):
            moves.prob_regrow = True
        with pytest.raises(ValueError, match=r"Probability must"):
            moves.prob_regrow = -0.2

        with pytest.raises(TypeError, match=r"prob_volume must"):
            moves.prob_volume = []
        with pytest.raises(TypeError, match=r"prob_volume must"):
            moves.prob_volume = True
        with pytest.raises(ValueError, match=r"Probability must"):
            moves.prob_volume = -0.2
        with pytest.raises(ValueError, match=r"Ensemble is nvt."):
            moves.prob_volume = 0.02

        moves = mc.Moves("gemc", [methane_oplsaa])
        with pytest.raises(ValueError, match=r"Ensemble is gemc."):
            moves.prob_volume = 0.0

        moves = mc.Moves("nvt", [methane_oplsaa])
        with pytest.raises(TypeError, match=r"prob_insert must"):
            moves.prob_insert = []
        with pytest.raises(TypeError, match=r"prob_insert must"):
            moves.prob_insert = True
        with pytest.raises(ValueError, match=r"Probability must"):
            moves.prob_insert = -0.2
        with pytest.raises(ValueError, match=r"Ensemble is nvt."):
            moves.prob_insert = 0.2
        moves = mc.Moves("gcmc", [methane_oplsaa])
        with pytest.raises(ValueError, match=r"Ensemble is gcmc."):
            moves.prob_insert = 0.0

        moves = mc.Moves("nvt", [methane_oplsaa])
        with pytest.raises(TypeError, match=r"prob_swap must"):
            moves.prob_swap = []
        with pytest.raises(TypeError, match=r"prob_swap must"):
            moves.prob_swap = True
        with pytest.raises(ValueError, match=r"Probability must"):
            moves.prob_swap = -0.2
        with pytest.raises(ValueError, match=r"Ensemble is nvt."):
            moves.prob_swap = 0.2
        moves = mc.Moves("gemc", [methane_oplsaa])
        with pytest.raises(ValueError, match=r"Ensemble is gemc."):
            moves.prob_swap = 0.0
Ejemplo n.º 27
0
def run_gemc():

    # Use mbuild to create molecules
    methane = mbuild.Compound(name="_CH4")

    # Create two empty mbuild.Box
    # (vapor = larger, liquid = smaller)
    liquid_box = mbuild.Box(lengths=[3.0, 3.0, 3.0])
    vapor_box = mbuild.Box(lengths=[4.0, 4.0, 4.0])

    # Load forcefields
    trappe = foyer.forcefields.load_TRAPPE_UA()

    # Use foyer to apply forcefields
    typed_methane = trappe.apply(methane)

    # Create box and species list
    box_list = [liquid_box, vapor_box]
    species_list = [typed_methane]

    mols_to_add = [[350], [100]]

    system = mc.System(box_list, species_list, mols_to_add=mols_to_add)
    moves = mc.Moves("gemc", species_list)

    moves.prob_volume = 0.010
    moves.prob_swap = 0.11

    thermo_props = [
        "energy_total",
        "energy_intervdw",
        "pressure",
        "volume",
        "nmols",
        "mass_density",
    ]

    custom_args = {
        "run_name": "equil",
        "charge_style": "none",
        "rcut_min": 2.0,
        "vdw_cutoff": 14.0,
        "units": "sweeps",
        "steps_per_sweep": 450,
        "coord_freq": 50,
        "prop_freq": 10,
        "properties": thermo_props,
    }

    mc.run(
        system=system,
        moves=moves,
        run_type="equilibration",
        run_length=250,
        temperature=151.0,
        **custom_args,
    )

    # Set max translate and volume for production
    moves.max_translate = [[0.5], [14.0]]
    moves.max_volume = [700.0]

    # Update run_name and restart_name
    custom_args["run_name"] = "prod"
    custom_args["restart_name"] = "equil"

    mc.restart(
        system=system,
        moves=moves,
        run_type="production",
        run_length=750,
        temperature=151.0,
        **custom_args,
    )