Esempio n. 1
0
 def test_restart_run_name_multiple_invalid_files(self):
     with temporary_directory() as tmp_dir:
         with temporary_cd(tmp_dir):
             Path("prod.inp").touch()
             Path("equil.rst.001.inp").touch()
             Path("equil.rst.002.inp").touch()
             with pytest.raises(ValueError, match=r"Multiple"):
                 get_restart_name(None, None)
Esempio n. 2
0
    def test_restart_run_name_single_file(self):
        with temporary_directory() as tmp_dir:
            with temporary_cd(tmp_dir):
                Path("equil.inp").touch()
                restart_from, run_name = get_restart_name(None, None)
                assert run_name == "equil.rst.001"

        with temporary_directory() as tmp_dir:
            with temporary_cd(tmp_dir):
                Path("equil.rst.001.inp").touch()
                restart_from, run_name = get_restart_name(None, None)
                assert run_name == "equil.rst.002"
Esempio n. 3
0
 def test_restart_run_name_no_files(self):
     with pytest.raises(FileNotFoundError):
         get_restart_name(None, None)
Esempio n. 4
0
 def test_restart_run_name_max_iterations(self):
     with pytest.raises(ValueError, match=r"Maximum number"):
         get_restart_name("equil.rst.999", None)
Esempio n. 5
0
 def test_restart_run_name_iterate(self):
     restart_from, run_name = get_restart_name("equil.rst.002", None)
     assert run_name == "equil.rst.003"
Esempio n. 6
0
 def test_restart_run_name_none(self):
     restart_from, run_name = get_restart_name("equil", None)
     assert run_name == "equil.rst.001"
Esempio n. 7
0
 def test_restart_run_name_equal(self):
     restart_from, run_name = get_restart_name("equil", "equil")
     assert run_name == "equil.rst.001"
Esempio n. 8
0
 def test_restart_run_name_simple(self):
     restart_from, run_name = get_restart_name("equil", "equil.rst")
     assert run_name == "equil.rst"
Esempio n. 9
0
def restart(total_run_length=None,
            restart_from=None,
            run_name=None,
            run_type=None):
    """Restart a Monte Carlo simulation from a checkpoint file with Cassandra

    The function requires the following in the working directory. These items
    would have all been generated for the original run:
        * Cassandra input (.inp) file named {restart_from}.inp
        * Cassandra checkpoint file (.chk) name {restart_from}.out.chk
        * MCF files for each species
        * Fragment libraries for each species

    The maximum translation, rotation, and volume move sizes are read from
    the checkpoint file. Similarly, the starting structure is taken from the
    checkpoint file. If the "restart_name" is not provided or if the
    "run_name" is the same as "restart_name", ".rst.N" will be appended to the
    "run_name".

    If you wish to extend a simulation you will need to specify the _total_
    number of simulation steps desired with the total_run_length option. For example,
    if your original run was 1e6 MC steps, but you wish to extend it by an
    additional 1e6 steps, use total_run_length=2000000.

    Parameters
    ----------
    total_run_length: int, optional, default=None
        total length of the MC simulation; if None, use original simulation length
    restart_from: str, optional, default=None
        name of run to restart from; if None, searches current
        directory for Cassandra inp files
    run_name: str, optional, default=None
        name of this run; if None, appends ".rst.NNN." to run_name,
        where "NNN" is the restart iteration "001", "002", ...,
    run_type : str, "equilibration" or "production", default=None
        the type of run; in "equilibration" mode, Cassandra adaptively changes
        the maximum translation, rotation, and volume move sizes to achieve
        an acceptance ratio of 0.5. If None, use the same choice as the
        previous run.
    """
    valid_run_types = ["equilibration", "equil", "production", "prod"]
    # Check that the user has the Cassandra binary on their PATH
    # Also need library_setup.py on the PATH and python2
    py, fraglib_setup, cassandra = detect_cassandra_binaries()

    # Parse the arguments
    if total_run_length is not None:
        if not isinstance(total_run_length, int):
            raise TypeError("`total_run_length` must be an integer")
    if run_name is not None:
        if not isinstance(run_name, str):
            raise TypeError("`run_name` must be a string")
    if run_type is not None:
        if (not isinstance(run_type, str)
                or run_type.lower() not in valid_run_types):
            raise TypeError(f"`run_type` must be one of: {valid_run_types}")
        if run_type.lower() == "equil" or run_type.lower() == "equilibration":
            run_type = "equilibration"
        if run_type.lower() == "prod" or run_type.lower() == "production":
            run_type = "production"

    restart_from, run_name = get_restart_name(restart_from, run_name)
    checkpoint_name = restart_from + ".out.chk"
    if not os.path.isfile(checkpoint_name):
        raise FileNotFoundError(
            f"Checkpoint file: {checkpoint_name} does not exist.")

    write_restart_input(restart_from, run_name, run_type, total_run_length)

    log_file = "mosdef_cassandra_{}.log".format(
        datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S.%f"))

    print("Running Cassandra...")
    _run_cassandra(cassandra, run_name + ".inp", log_file)