def test_weight_filter_apply_no_toolkit():
    """
    Make sure an error is raised when we try to filter by weight but have no toolkit to do it.
    """
    with pytest.raises(ModuleNotFoundError):
        weight = workflow_components.MolecularWeightFilter()
        molecules = get_tautomers()
        _ = weight.apply(molecules=molecules,
                         toolkit_registry=ToolkitRegistry(),
                         processors=1)
def test_weight_filter_validator():
    """
    Make sure the weight filter simple validators work.
    """
    weight = workflow_components.MolecularWeightFilter()

    weight.minimum_weight = 0.0
    assert weight.minimum_weight == 0

    assert "openff-toolkit" in weight.provenance(GLOBAL_TOOLKIT_REGISTRY)
Exemple #3
0
def test_weight_filter_apply():
    """
    Make sure the weight filter returns molecules within the limits.
    """

    weight = workflow_components.MolecularWeightFilter()
    weight.minimum_weight = 0
    weight.maximum_weight = 80

    molecules = get_tautomers()

    result = weight.apply(molecules, processors=1)
    assert result.n_molecules == 14
    assert result.n_filtered == 36
def test_weight_filter_apply(toolkits):
    """
    Make sure the weight filter returns molecules within the limits. As the backend function choice is handled by qcsubmit
    we should test both options.
    """

    weight = workflow_components.MolecularWeightFilter()
    weight.minimum_weight = 0
    weight.maximum_weight = 80

    molecules = get_tautomers()

    result = weight.apply(molecules, processors=1, toolkit_registry=toolkits)
    assert result.n_molecules == 14
    assert result.n_filtered == 36
def test_factory_round_trip(file_type, tmpdir):
    """
    Test round tripping a factory to file with a workflow.
    """
    with tmpdir.as_cwd():
        factory = BasicDatasetFactory(driver="energy", maxiter=1)
        efilter = workflow_components.ElementFilter()
        weight = workflow_components.MolecularWeightFilter()
        conformer = workflow_components.StandardConformerGenerator()
        factory.add_workflow_components(efilter, weight, conformer)
        file_name = "test." + file_type
        factory.export(file_name)

        factory2 = BasicDatasetFactory.from_file(file_name)
        assert factory2.driver == factory.driver
        assert factory2.workflow == factory.workflow
Exemple #6
0
def test_get_wrokflow_component(factory_type):
    """
    Test retrieving a workflow component.
    """

    factory = factory_type()

    efilter = workflow_components.ElementFilter()
    weight = workflow_components.MolecularWeightFilter()
    conformer = workflow_components.StandardConformerGenerator()

    components = [efilter, weight, conformer]

    factory.add_workflow_component(components)

    for component in components:
        assert factory.get_workflow_component(component.component_name) == component
Exemple #7
0
def test_adding_multipule_workflow_components(factory_type):
    """
    Test adding a list of workflow components.
    """

    factory = factory_type()

    efilter = workflow_components.ElementFilter()
    weight = workflow_components.MolecularWeightFilter()
    conformer = workflow_components.StandardConformerGenerator()

    components = [efilter, weight, conformer]

    factory.add_workflow_component(components)

    assert len(factory.workflow) == 3
    for component in components:
        assert component.component_name in factory.workflow
Exemple #8
0
def test_remove_workflow_componet(factory_type):
    """
    Test removing a workflow component through the API.
    """

    factory = factory_type()
    efilter = workflow_components.ElementFilter()
    weight = workflow_components.MolecularWeightFilter()
    conformer = workflow_components.StandardConformerGenerator()

    components = [efilter, weight, conformer]

    factory.add_workflow_component(components)

    assert len(factory.workflow) == 3

    for component in components:
        factory.remove_workflow_component(component.component_name)

    assert factory.workflow == {}
Exemple #9
0
def test_clear_workflow(factory_type):
    """
    Test clearing out the workflow.
    """

    factory = factory_type()

    efilter = workflow_components.ElementFilter()
    weight = workflow_components.MolecularWeightFilter()
    conformer = workflow_components.StandardConformerGenerator()

    components = [efilter, weight, conformer]

    factory.add_workflow_component(components)

    factory.clear_workflow()

    assert factory.workflow == {}

    factory.add_workflow_component(components)

    factory.workflow = {}

    assert factory.workflow == {}