Beispiel #1
0
def test_thermoml_mole_constraints():
    """A collection of tests to ensure that the Mole fraction constraint is
    implemented correctly alongside solvent constraints."""

    # Mole fraction
    data_set = ThermoMLDataSet.from_file(
        get_data_filename("test/properties/mole.xml"))

    assert data_set is not None
    assert len(data_set) > 0

    # Mole fraction + Solvent: Mass fraction
    data_set = ThermoMLDataSet.from_file(
        get_data_filename("test/properties/mole_mass.xml"))

    assert data_set is not None
    assert len(data_set) > 0

    # Mole fraction + Solvent: Mole fraction
    data_set = ThermoMLDataSet.from_file(
        get_data_filename("test/properties/mole_mole.xml"))

    assert data_set is not None
    assert len(data_set) > 0

    # Mole fraction + Solvent: Molality
    data_set = ThermoMLDataSet.from_file(
        get_data_filename("test/properties/mole_molality.xml"))

    assert data_set is not None
    assert len(data_set) > 0
Beispiel #2
0
def test_gradient_reduced_potentials(use_subset):

    substance = Substance.from_components("O")
    thermodynamic_state = ThermodynamicState(298 * unit.kelvin,
                                             1.0 * unit.atmosphere)

    with tempfile.TemporaryDirectory() as directory:

        force_field_path = path.join(directory, "ff.json")

        with open(force_field_path, "w") as file:
            file.write(build_tip3p_smirnoff_force_field().json())

        reduced_potentials = OpenMMGradientPotentials(f"reduced_potentials")
        reduced_potentials.substance = substance
        reduced_potentials.thermodynamic_state = thermodynamic_state
        reduced_potentials.statistics_path = get_data_filename(
            "test/statistics/stats_pandas.csv")
        reduced_potentials.force_field_path = force_field_path
        reduced_potentials.trajectory_file_path = get_data_filename(
            "test/trajectories/water.dcd")
        reduced_potentials.coordinate_file_path = get_data_filename(
            "test/trajectories/water.pdb")
        reduced_potentials.use_subset_of_force_field = use_subset
        reduced_potentials.enable_pbc = True
        reduced_potentials.parameter_key = ParameterGradientKey(
            "vdW", "[#1]-[#8X2H2+0:1]-[#1]", "epsilon")

        reduced_potentials.execute(directory, ComputeResources())
        assert path.isfile(reduced_potentials.forward_potentials_path)
        assert path.isfile(reduced_potentials.reverse_potentials_path)
Beispiel #3
0
def test_thermoml_from_files():
    """A test to ensure that ThermoML archive files can be loaded from local sources."""

    data_set = ThermoMLDataSet.from_file(
        get_data_filename("properties/single_density.xml"),
        get_data_filename("properties/single_dielectric.xml"),
        get_data_filename("properties/single_enthalpy_mixing.xml"),
    )

    assert data_set is not None
    assert len(data_set) == 3

    data_set = ThermoMLDataSet.from_file("dummy_filename")
    assert data_set is None
Beispiel #4
0
def test_build_docked_coordinates_protocol():
    """Tests docking a methanol molecule into alpha-Cyclodextrin."""

    if not has_openeye():
        pytest.skip("The `BuildDockedCoordinates` protocol requires OpenEye.")

    ligand_substance = Substance()
    ligand_substance.add_component(
        Component("CO", role=Component.Role.Ligand),
        ExactAmount(1),
    )

    # TODO: This test could likely be made substantially faster
    #       by storing the binary prepared receptor. Would this
    #       be in breach of any oe license terms?
    with tempfile.TemporaryDirectory() as temporary_directory:

        build_docked_coordinates = BuildDockedCoordinates("build_methanol")
        build_docked_coordinates.ligand_substance = ligand_substance
        build_docked_coordinates.number_of_ligand_conformers = 5
        build_docked_coordinates.receptor_coordinate_file = get_data_filename(
            "test/molecules/acd.mol2")
        build_docked_coordinates.execute(temporary_directory,
                                         ComputeResources())

        docked_pdb = PDBFile(
            build_docked_coordinates.docked_complex_coordinate_path)
        assert docked_pdb.topology.getNumResidues() == 2
Beispiel #5
0
def test_statistics_object():

    statistics_object = StatisticsArray.from_openmm_csv(
        get_data_filename("test/statistics/stats_openmm.csv"),
        1 * unit.atmosphere)

    statistics_object.to_pandas_csv("stats_pandas.csv")

    statistics_object = StatisticsArray.from_pandas_csv("stats_pandas.csv")
    assert statistics_object is not None

    subsampled_array = StatisticsArray.from_existing(statistics_object,
                                                     [1, 2, 3])
    assert subsampled_array is not None and len(subsampled_array) == 3

    if os.path.isfile("stats_pandas.csv"):
        os.unlink("stats_pandas.csv")

    reduced_potential = np.array([0.1] * (len(statistics_object) - 1))

    with pytest.raises(ValueError):
        statistics_object[ObservableType.ReducedPotential] = reduced_potential

    reduced_potential = np.array([0.1] * len(statistics_object))

    with pytest.raises(ValueError):
        statistics_object[ObservableType.ReducedPotential] = reduced_potential

    statistics_object[ObservableType.ReducedPotential] = (reduced_potential *
                                                          unit.dimensionless)

    assert ObservableType.ReducedPotential in statistics_object
Beispiel #6
0
def test_calculate_reduced_potential_openmm():

    substance = Substance.from_components("O")
    thermodynamic_state = ThermodynamicState(298 * unit.kelvin,
                                             1.0 * unit.atmosphere)

    with tempfile.TemporaryDirectory() as directory:
        force_field_path = path.join(directory, "ff.json")

        with open(force_field_path, "w") as file:
            file.write(build_tip3p_smirnoff_force_field().json())

        build_coordinates = BuildCoordinatesPackmol("build_coordinates")
        build_coordinates.max_molecules = 10
        build_coordinates.mass_density = 0.05 * unit.grams / unit.milliliters
        build_coordinates.substance = substance
        build_coordinates.execute(directory, None)

        assign_parameters = BuildSmirnoffSystem(f"assign_parameters")
        assign_parameters.force_field_path = force_field_path
        assign_parameters.coordinate_file_path = build_coordinates.coordinate_file_path
        assign_parameters.substance = substance
        assign_parameters.execute(directory, None)

        reduced_potentials = OpenMMReducedPotentials(f"reduced_potentials")
        reduced_potentials.substance = substance
        reduced_potentials.thermodynamic_state = thermodynamic_state
        reduced_potentials.reference_force_field_paths = [force_field_path]
        reduced_potentials.system_path = assign_parameters.system_path
        reduced_potentials.trajectory_file_path = get_data_filename(
            "test/trajectories/water.dcd")
        reduced_potentials.coordinate_file_path = get_data_filename(
            "test/trajectories/water.pdb")
        reduced_potentials.kinetic_energies_path = get_data_filename(
            "test/statistics/stats_pandas.csv")
        reduced_potentials.high_precision = False
        reduced_potentials.execute(directory, ComputeResources())

        assert path.isfile(reduced_potentials.statistics_file_path)

        final_array = StatisticsArray.from_pandas_csv(
            reduced_potentials.statistics_file_path)
        assert ObservableType.ReducedPotential in final_array
Beispiel #7
0
def test_extract_average_statistic():

    statistics_path = get_data_filename("test/statistics/stats_pandas.csv")

    with tempfile.TemporaryDirectory() as temporary_directory:

        extract_protocol = ExtractAverageStatistic("extract_protocol")
        extract_protocol.statistics_path = statistics_path
        extract_protocol.statistics_type = ObservableType.PotentialEnergy
        extract_protocol.execute(temporary_directory, ComputeResources())
Beispiel #8
0
def test_concatenate_trajectories():

    import mdtraj

    coordinate_path = get_data_filename("test/trajectories/water.pdb")
    trajectory_path = get_data_filename("test/trajectories/water.dcd")

    original_trajectory = mdtraj.load(trajectory_path, top=coordinate_path)

    with tempfile.TemporaryDirectory() as temporary_directory:

        concatenate_protocol = ConcatenateTrajectories("concatenate_protocol")
        concatenate_protocol.input_coordinate_paths = [
            coordinate_path, coordinate_path
        ]
        concatenate_protocol.input_trajectory_paths = [
            trajectory_path, trajectory_path
        ]
        concatenate_protocol.execute(temporary_directory, ComputeResources())

        final_trajectory = mdtraj.load(
            concatenate_protocol.output_trajectory_path, top=coordinate_path)
        assert len(final_trajectory) == len(original_trajectory) * 2
Beispiel #9
0
def test_extract_uncorrelated_trajectory_data():

    import mdtraj

    coordinate_path = get_data_filename("test/trajectories/water.pdb")
    trajectory_path = get_data_filename("test/trajectories/water.dcd")

    original_trajectory = mdtraj.load(trajectory_path, top=coordinate_path)

    with tempfile.TemporaryDirectory() as temporary_directory:

        extract_protocol = ExtractUncorrelatedTrajectoryData(
            "extract_protocol")
        extract_protocol.input_coordinate_file = coordinate_path
        extract_protocol.input_trajectory_path = trajectory_path
        extract_protocol.equilibration_index = 2
        extract_protocol.statistical_inefficiency = 2.0
        extract_protocol.execute(temporary_directory, ComputeResources())

        final_trajectory = mdtraj.load(extract_protocol.output_trajectory_path,
                                       top=coordinate_path)
        assert len(final_trajectory) == (len(original_trajectory) - 2) / 2
        assert (extract_protocol.number_of_uncorrelated_samples ==
                (len(original_trajectory) - 2) / 2)
Beispiel #10
0
def test_concatenate_statistics():

    statistics_path = get_data_filename("test/statistics/stats_pandas.csv")
    original_array = StatisticsArray.from_pandas_csv(statistics_path)

    with tempfile.TemporaryDirectory() as temporary_directory:

        concatenate_protocol = ConcatenateStatistics("concatenate_protocol")
        concatenate_protocol.input_statistics_paths = [
            statistics_path, statistics_path
        ]
        concatenate_protocol.execute(temporary_directory, ComputeResources())

        final_array = StatisticsArray.from_pandas_csv(
            concatenate_protocol.output_statistics_path)
        assert len(final_array) == len(original_array) * 2
Beispiel #11
0
def test_extract_uncorrelated_statistics_data():

    statistics_path = get_data_filename("test/statistics/stats_pandas.csv")
    original_array = StatisticsArray.from_pandas_csv(statistics_path)

    with tempfile.TemporaryDirectory() as temporary_directory:

        extract_protocol = ExtractUncorrelatedStatisticsData(
            "extract_protocol")
        extract_protocol.input_statistics_path = statistics_path
        extract_protocol.equilibration_index = 2
        extract_protocol.statistical_inefficiency = 2.0
        extract_protocol.execute(temporary_directory, ComputeResources())

        final_array = StatisticsArray.from_pandas_csv(
            extract_protocol.output_statistics_path)
        assert len(final_array) == (len(original_array) - 2) / 2
        assert (extract_protocol.number_of_uncorrelated_samples ==
                (len(original_array) - 2) / 2)
Beispiel #12
0
def build_tip3p_smirnoff_force_field():
    """Combines the smirnoff99Frosst and tip3p offxml files
    into a single one which can be consumed by the property
    estimator.

    Returns
    -------
    SmirnoffForceFieldSource
        The force field containing both smirnoff99Frosst-1.1.0
        and TIP3P parameters
    """
    from openforcefield.typing.engines.smirnoff import ForceField

    smirnoff_force_field_path = "smirnoff99Frosst-1.1.0.offxml"
    tip3p_force_field_path = get_data_filename("forcefield/tip3p.offxml")

    smirnoff_force_field_with_tip3p = ForceField(smirnoff_force_field_path,
                                                 tip3p_force_field_path)

    return SmirnoffForceFieldSource.from_object(
        smirnoff_force_field_with_tip3p)