Beispiel #1
0
def main():

    setup_timestamp_logging()

    # Load in the force field
    force_field_path = "smirnoff99Frosst-1.1.0.offxml"
    force_field_source = SmirnoffForceFieldSource.from_path(force_field_path)

    # Load in the data set containing the pure and binary properties.
    data_set = PhysicalPropertyDataSet.from_json("pure_data_set.json")
    data_set.merge(PhysicalPropertyDataSet.from_json("binary_data_set.json"))

    # Set up a server object to run the calculations using.
    server = setup_server(backend_type=BackendType.LocalGPU,
                          max_number_of_workers=1,
                          port=8001)

    with server:

        # Request the estimates.
        property_estimator = EvaluatorClient(
            ConnectionOptions(server_port=8001))

        for calculation_layer in ["SimulationLayer", "ReweightingLayer"]:

            options = RequestOptions()
            options.calculation_layers = [calculation_layer]

            parameter_gradient_keys = [
                ParameterGradientKey(tag="vdW",
                                     smirks="[#6X4:1]",
                                     attribute="epsilon"),
                ParameterGradientKey(tag="vdW",
                                     smirks="[#6X4:1]",
                                     attribute="rmin_half"),
            ]

            request, _ = property_estimator.request_estimate(
                property_set=data_set,
                force_field_source=force_field_source,
                options=options,
                parameter_gradient_keys=parameter_gradient_keys,
            )

            # Wait for the results.
            results, _ = request.results(True, 5)

            layer_name = re.sub(r"(?<!^)(?=[A-Z])", "_",
                                calculation_layer).lower()
            results.json(f"pure_binary_{layer_name}.json", True)
Beispiel #2
0
def main(input_data_set_path, server_port):

    # Create the options which propertyestimator should use.
    estimator_options = RequestOptions()

    # Choose which calculation layers to make available.
    estimator_options.calculation_layers = ["SimulationLayer"]

    # Load in the training data set and create schemas for each of the types
    # of property to be calculated.
    training_set = PhysicalPropertyDataSet.from_json(input_data_set_path)

    # Zero out any undefined uncertainties due to a bug in ForceBalance.
    for physical_property in training_set:
        physical_property.uncertainty = 0.0 * physical_property.default_unit()

    data_set_path = "training_set.json"
    training_set.json(data_set_path, format=True)

    # Create the force balance options
    target_options = Evaluator_SMIRNOFF.OptionsFile()
    target_options.connection_options = ConnectionOptions(
        server_address="localhost", server_port=server_port)
    target_options.estimation_options = estimator_options

    target_options.data_set_path = data_set_path

    # Set the property weights and denominators.
    target_options.weights = {x: 1.0 for x in training_set.property_types}
    target_options.denominators = calculate_denominators(training_set)

    # Save the options to file.
    with open("options.json", "w") as file:
        file.write(target_options.to_json())
def find_training_smiles():
    """Returns the smiles of all of the substances which
    appeared in the training set.

    Returns
    -------
    list of tuple of str
        The smiles patterns of the training substances.
    """

    # Find those alcohols which were included in the training set
    training_set = PhysicalPropertyDataSet.from_json(
        os.path.join(
            "..",
            "..",
            "..",
            "pure_mixture_optimisation",
            "force_balance",
            "alcohol_ester",
            "h_mix_rho_x_rho_pure_h_vap",
            "targets",
            "mixture_data",
            "training_set.json",
        )
    ).to_pandas()

    training_smiles = data_frame_to_smiles_tuples(training_set)
    training_smiles = set(x for y in training_smiles for x in y)

    return training_smiles
Beispiel #4
0
def main():

    setup_timestamp_logging()

    # Load in the force field
    force_field_path = "openff-1.0.0-refit.offxml"
    force_field_source = SmirnoffForceFieldSource.from_path(force_field_path)

    # Load in the test set.
    data_set = PhysicalPropertyDataSet.from_json("full_set.json")

    # Set up a server object to run the calculations using.
    working_directory = "working_directory"

    # Set up a backend to run the calculations on. This assume running
    # on a HPC resources with the LSF queue system installed.
    queue_resources = QueueWorkerResources(
        number_of_threads=1,
        number_of_gpus=1,
        preferred_gpu_toolkit=QueueWorkerResources.GPUToolkit.CUDA,
        per_thread_memory_limit=5 * unit.gigabyte,
        wallclock_time_limit="05:59",
    )

    worker_script_commands = [
        "conda activate forcebalance", "module load cuda/10.1"
    ]

    calculation_backend = DaskLSFBackend(
        minimum_number_of_workers=1,
        maximum_number_of_workers=50,
        resources_per_worker=queue_resources,
        queue_name="gpuqueue",
        setup_script_commands=worker_script_commands,
        adaptive_interval="1000ms",
    )

    with calculation_backend:

        server = EvaluatorServer(
            calculation_backend=calculation_backend,
            working_directory=working_directory,
            port=8002,
        )

        with server:

            # Request the estimates.
            client = EvaluatorClient(ConnectionOptions(server_port=8002))

            request, _ = client.request_estimate(
                property_set=data_set,
                force_field_source=force_field_source,
            )

            # Wait for the results.
            results, _ = request.results(True, 5)
            results.json(f"results.json")
def main():

    # Set up logging
    logging.basicConfig(level=logging.INFO)

    output_directory = "training_sets"
    os.makedirs(output_directory, exist_ok=True)

    rho_pure_h_vap = PhysicalPropertyDataSet.from_json(
        "../../../pure_optimisation/data_set_generation/expanded_set/training_set.json"
    )

    rho_pure = PhysicalPropertyDataSet.from_json(
        "../../../pure_optimisation/data_set_generation/expanded_set/training_set.json"
    )
    rho_pure.filter_by_property_types("Density")

    h_mix_rho_x = PhysicalPropertyDataSet.from_json(
        "../../../mixture_optimisation/data_set_generation/"
        "expanded_set/training_sets/h_mix_rho_x_training_set.json")

    h_mix_rho_x_rho_pure = PhysicalPropertyDataSet()
    h_mix_rho_x_rho_pure.merge(rho_pure)
    h_mix_rho_x_rho_pure.merge(h_mix_rho_x)
    h_mix_rho_x_rho_pure.json(
        os.path.join(output_directory, "h_mix_rho_x_rho_pure.json"))
    h_mix_rho_x_rho_pure.to_pandas().to_csv(
        os.path.join(output_directory, "h_mix_rho_x_rho_pure.csv"))

    h_mix_rho_x_rho_pure_h_vap = PhysicalPropertyDataSet()
    h_mix_rho_x_rho_pure_h_vap.merge(rho_pure_h_vap)
    h_mix_rho_x_rho_pure_h_vap.merge(h_mix_rho_x)
    h_mix_rho_x_rho_pure_h_vap.json(
        os.path.join(output_directory, "h_mix_rho_x_rho_pure_h_vap.json"))
    h_mix_rho_x_rho_pure_h_vap.to_pandas().to_csv(
        os.path.join(output_directory, "h_mix_rho_x_rho_pure_h_vap.csv"))
Beispiel #6
0
def main():

    setup_timestamp_logging()

    # Load in the force field
    force_field_path = "smirnoff99Frosst-1.1.0.offxml"
    force_field_source = SmirnoffForceFieldSource.from_path(force_field_path)

    # Create a data set containing three solvation free energies.
    data_set = PhysicalPropertyDataSet.from_json("hydration_data_set.json")
    data_set.json("hydration_data_set.json", format=True)

    # Set up a server object to run the calculations using.
    server = setup_server(backend_type=BackendType.LocalGPU,
                          max_number_of_workers=1,
                          port=8002)

    with server:

        # Request the estimates.
        property_estimator = EvaluatorClient(
            ConnectionOptions(server_port=8002))

        options = RequestOptions()
        options.calculation_layers = ["SimulationLayer"]
        options.add_schema("SimulationLayer", "SolvationFreeEnergy",
                           _get_fixed_lambda_schema())

        request, _ = property_estimator.request_estimate(
            property_set=data_set,
            force_field_source=force_field_source,
            options=options,
        )

        # Wait for the results.
        results, _ = request.results(True, 60)

        # Save the result to file.
        results.json(f"results.json", True)
Beispiel #7
0
def main():

    # Set up logging
    logging.basicConfig(level=logging.INFO)

    output_directory = "training_sets"
    os.makedirs(output_directory, exist_ok=True)

    pure_density_h_vap = PhysicalPropertyDataSet.from_json(
        "../../pure_optimisation/data_set_generation/training_set.json"
    )

    pure_density = PhysicalPropertyDataSet.from_json(
        "../../pure_optimisation/data_set_generation/training_set.json"
    )
    pure_density.filter_by_property_types("Density")

    h_mix_v_excess = PhysicalPropertyDataSet.from_json(
        "../../mixture_optimisation/data_set_generation/"
        "training_sets/h_mix_v_excess_training_set.json"
    )
    h_mix_binary_density = PhysicalPropertyDataSet.from_json(
        "../../mixture_optimisation/data_set_generation/"
        "training_sets/h_mix_density_training_set.json"
    )

    h_mix_binary_density_pure_density = PhysicalPropertyDataSet()
    h_mix_binary_density_pure_density.merge(pure_density)
    h_mix_binary_density_pure_density.merge(h_mix_binary_density)
    h_mix_binary_density_pure_density.json(
        os.path.join(output_directory, "h_mix_binary_density_pure_density.json")
    )
    h_mix_binary_density_pure_density.to_pandas().to_csv(
        os.path.join(output_directory, "h_mix_binary_density_pure_density.csv")
    )

    h_mix_v_excess_pure_density = PhysicalPropertyDataSet()
    h_mix_v_excess_pure_density.merge(pure_density)
    h_mix_v_excess_pure_density.merge(h_mix_v_excess)
    h_mix_v_excess_pure_density.json(
        os.path.join(output_directory, "h_mix_v_excess_pure_density.json")
    )
    h_mix_v_excess_pure_density.to_pandas().to_csv(
        os.path.join(output_directory, "h_mix_v_excess_pure_density.csv")
    )

    h_mix_binary_density_pure_density_h_vap = PhysicalPropertyDataSet()
    h_mix_binary_density_pure_density_h_vap.merge(pure_density_h_vap)
    h_mix_binary_density_pure_density_h_vap.merge(h_mix_binary_density)
    h_mix_binary_density_pure_density_h_vap.json(
        os.path.join(output_directory, "h_mix_binary_density_pure_density_h_vap.json")
    )
    h_mix_binary_density_pure_density_h_vap.to_pandas().to_csv(
        os.path.join(output_directory, "h_mix_binary_density_pure_density_h_vap.csv")
    )

    h_mix_v_excess_pure_density_h_vap = PhysicalPropertyDataSet()
    h_mix_v_excess_pure_density_h_vap.merge(pure_density_h_vap)
    h_mix_v_excess_pure_density_h_vap.merge(h_mix_v_excess)
    h_mix_v_excess_pure_density_h_vap.json(
        os.path.join(output_directory, "h_mix_v_excess_pure_density_h_vap.json")
    )
    h_mix_v_excess_pure_density_h_vap.to_pandas().to_csv(
        os.path.join(output_directory, "h_mix_v_excess_pure_density_h_vap.csv")
    )