def test_metrics_and_conditions_to_json():
    """
    Test for the metrics_to_json and conditions_to_json methods.

    Returns
    ----------
    boolean : result of the test.
    """
    # Parse yaml file
    yaml_obj = yp.YamlParser(ARGS_1, vf.VALID_FLAGS_PLATFORM)
    yaml_obj.read()
    # Build interaction restrictions
    interaction_restrictions = ir.InteractionRestrictionsBuilder()
    interaction_restrictions.parse_interaction_restrictions(
        PDB_FILE, yaml_obj.interaction_restrictions)

    errors = []
    # Check metrics json output
    metrics = interaction_restrictions.metrics_to_json()
    expected_metrics_output = open(EXPECTED_METRICS, "r").read()
    if not metrics == expected_metrics_output:
        errors.append(
            f"Error in metrics json: {metrics} == {expected_metrics_output} ")

    # Check conditions json output
    conditions = interaction_restrictions.conditions_to_json()
    expected_conditions_output = open(EXPECTED_CONDITIONS, "r").read()
    if not conditions == expected_conditions_output:
        errors.append(
            f"conditions json assert: {conditions} == {expected_conditions_output} "
        )

    # assert no error message has been registered, else print messages
    assert not errors
Пример #2
0
def run_platform(input_yaml):
    '''
    High level function to run a PELE job. It will:
    1) Parse the input.yaml
    2) Launch job
    3) Return job parametrs
    '''
    yaml_obj = yp.YamlParser(input_yaml, vf.VALID_FLAGS_PLATFORM)
    yaml_obj.read()
    job_params = lc.Launcher(yaml_obj).launch()
    return job_params
Пример #3
0
def run_platform(input_yaml):
    """
    High level function to run the PELE platform from an input yaml file.
    .. todo ::
        * In the future we might have other type of runners. We should specify
        that this one runs the platform starting from a yaml file. So,
        something like run_platform_from_yaml could be more appropriate.

    It will:
    1) Parse the input.yaml
    2) Launch job
    3) Return job parameters

    Parameters
    ----------
    input_yaml : str
        The path pointing to the input yaml file

    Returns
    -------
    job_params : an EnviroBuilder object
        The corresponding EnviroBuilder object with the parameters of the
        simulation
    """
    # Generate the yaml object from the input yaml
    from pele_platform.Utilities.Helpers import yaml_parser
    from pele_platform.Checker import valid_flags

    yaml_obj = yaml_parser.YamlParser(input_yaml,
                                      valid_flags.VALID_FLAGS_PLATFORM)

    # Attempt to parse the yaml object
    try:
        yaml_obj.read()
    except AttributeError:
        from pele_platform.Errors import custom_errors

        raise custom_errors.WrongYamlFile(
            "Input file: {}".format(input_yaml)
            + "does not look like a correct yaml file")

    # Initialize job launcher
    from pele_platform.Utilities.Helpers.launcher import Launcher

    launcher = Launcher(yaml_obj)

    # Run launcher
    job_params = launcher.launch()

    # Return job parameters
    return job_params
def test_check_SyntaxError_exception(file):
    """
    Function to test an input file that should throw a Syntax Error exception.

    Parameters
    ----------
    file : Path of the input.yaml file.
    """
    # Parse yaml file
    yaml_obj = yp.YamlParser(file, vf.VALID_FLAGS_PLATFORM)
    yaml_obj.read()
    # Build interaction restrictions
    interaction_restrictions = ir.InteractionRestrictionsBuilder()
    with pytest.raises(SyntaxError):
        interaction_restrictions.parse_interaction_restrictions(
            PDB_FILE, yaml_obj.interaction_restrictions)
Пример #5
0
def run_platform_from_yaml(input_yaml):
    """
    High level function to run the PELE platform from an input yaml file.

    It will:
    1) Parse the input.yaml
    2) Launch job
    3) Return job parameters

    Parameters
    ----------
    input_yaml : str
        The path pointing to the input yaml file

    Returns
    -------
    job_params : a Parameters object
        The corresponding Parameters object with the parameters of the
        simulation
    """
    # Generate the yaml object from the input yaml
    from pele_platform.Utilities.Helpers import yaml_parser
    from pele_platform.Checker import valid_flags

    yaml_obj = yaml_parser.YamlParser(input_yaml,
                                      valid_flags.VALID_FLAGS_PLATFORM)

    # Attempt to parse the yaml object
    try:
        yaml_obj.read()
    except AttributeError:
        from pele_platform.Errors import custom_errors

        raise custom_errors.WrongYamlFile(
            "Input file: {}".format(input_yaml) +
            "does not look like a correct yaml file")

    # Initialize job launcher
    from pele_platform.Utilities.Helpers.launcher import Launcher

    launcher = Launcher(yaml_obj)

    # Run launcher
    job_params = launcher.launch()

    # Return job parameters
    return job_params
def _read_args(file):
    """
    Internal function: parse yaml file and prepare args.

    Parameters
    ----------
    file : str
        Path of the input.yaml file.

    Returns
    ----------
    args : simulation args.
    """
    # Parse yaml file
    yaml_obj = yp.YamlParser(file, vf.VALID_FLAGS_PLATFORM)
    yaml_obj.read()

    # Prepare params
    launcher = Launcher(yaml_obj)
    launcher._define_package_to_run()

    return launcher._args