Exemplo n.º 1
0
def test_adding_workflow_components(factory_type):
    """
    Test building workflows from a verity of workflow components.
    """

    factory = factory_type()

    # element filter
    efilter = workflow_components.ElementFilter()
    factory.add_workflow_component(efilter)

    assert len(factory.workflow) == 1

    # conformer generator
    conformer_gen = workflow_components.StandardConformerGenerator()
    conformer_gen.max_conformers = 200
    factory.add_workflow_component(conformer_gen)

    assert len(factory.workflow) == 2

    # add element filter again and make sure the component name has been incremented
    factory.add_workflow_component(efilter)
    assert len(factory.workflow) == 3
    assert efilter.component_name in factory.workflow

    # try to add a non component
    with pytest.raises(InvalidWorkflowComponentError):
        factory.add_workflow_component(3)

    with pytest.raises(ValidationError):
        factory.workflow = {"first component": 3}

    factory.workflow = {"test_conformer": conformer_gen}

    assert len(factory.workflow) == 1
Exemplo n.º 2
0
def test_element_filter_validators():
    """
    Make sure the element filter validators are working.
    """

    elem_filter = workflow_components.ElementFilter()

    with pytest.raises(KeyError):
        elem_filter.allowed_elements = ["carbon", "hydrogen"]

    elem_filter.allowed_elements = [1.02, 2.02, 3.03]

    assert elem_filter.allowed_elements == [1, 2, 3]

    assert "openmm_elements" in elem_filter.provenance()
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
def test_create_dataset(factory_dataset_type):
    """
    Test making a the correct corresponding dataset type from a given factory type.
    """

    factory = factory_dataset_type[0]()
    element_filter = workflow_components.ElementFilter()
    element_filter.allowed_elements = [1, 6, 8, 7]
    factory.add_workflow_component(element_filter)
    conformer_generator = workflow_components.StandardConformerGenerator(
        max_conformers=1)
    factory.add_workflow_component(conformer_generator)

    mols = Molecule.from_file(get_data("tautomers_small.smi"),
                              "smi",
                              allow_undefined_stereo=True)

    # set some settings
    changed_attrs = {
        "compute_tag": "test tag",
        "dataset_tags": ["openff", "test"],
        "maxiter": 400
    }
    for attr, value in changed_attrs.items():
        setattr(factory, attr, value)

    dataset = factory.create_dataset(dataset_name="test name",
                                     molecules=mols,
                                     description="Force field test",
                                     tagline="A test dataset")

    # check the attributes were changed
    for attr, value in changed_attrs.items():
        assert getattr(dataset, attr) == value

    assert dataset.dataset_name == "test name"

    assert isinstance(dataset, factory_dataset_type[1]) is True

    # make sure molecules we filtered and passed
    assert dataset.dataset != {}
    assert dataset.filtered != {}
    assert element_filter.component_name in dataset.filtered_molecules
Exemplo n.º 6
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 == {}
Exemplo n.º 7
0
def test_elementfilter_apply():
    """
    Test applying the element filter to a workflow.
    """

    elem_filter = workflow_components.ElementFilter()
    elem_filter.allowed_elements = [1, 6, 7, 8]

    mols = get_tautomers()

    result = elem_filter.apply(mols, processors=1)

    assert result.component_name == elem_filter.component_name
    assert result.component_description == elem_filter.dict()
    # make sure there are no unwanted elements in the pass set
    for molecue in result.molecules:
        for atom in molecue.atoms:
            assert atom.atomic_number in elem_filter.allowed_elements

    for molecue in result.filtered:
        elements = set([atom.atomic_number for atom in molecue.atoms])
        assert sorted(elements) != sorted(elem_filter.allowed_elements)
Exemplo n.º 8
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 == {}