Пример #1
0
def test_apply_link_to_residue(example_meta_molecule, link_defs,
                               link_to_resids, inter_types, link_inters,
                               link_non_edges, link_patterns, expected_nodes,
                               expected_inters):
    links = []
    processor = ApplyLinks()
    for link_nodes, link_to_resid, interactions, non_edges, patterns, inter_type in zip(
            link_defs, link_to_resids, link_inters, link_non_edges,
            link_patterns, inter_types):
        link = Link()
        link.add_nodes_from(link_nodes)
        link.interactions[inter_type] = interactions
        link.non_edges = non_edges
        link.patterns = patterns
        link.make_edges_from_interaction_type(inter_type)
        processor.apply_link_between_residues(example_meta_molecule, link,
                                              link_to_resid)

    for nodes, inter_idxs, inter_type in zip(expected_nodes, expected_inters,
                                             inter_types):
        for inter_nodes, inter_idx in zip(nodes, inter_idxs):
            interaction = link_inters[inter_idx[0]][inter_idx[1]]
            new_interactions = processor.applied_links[inter_type][
                inter_nodes][0]
            assert new_interactions.atoms == tuple(inter_nodes[:-1])
            assert new_interactions.parameters == interaction.parameters
            assert new_interactions.meta == interaction.meta
def test_parse_patterns(tokens, expected):
    """
    Test that _parse_patterns works as expected.
    """
    existing = [[['X', {}], ['Y', {}]]]
    full_expected = copy.copy(existing)
    full_expected.append(expected)
    tokens = collections.deque(tokens)
    context = Link()
    context.patterns = existing
    ffinput._parse_patterns(tokens, context, 'link')
    assert context.patterns == full_expected
Пример #3
0
def test_apply_link_fail(example_meta_molecule, link_defs, link_to_resids,
                         inter_types, link_inters, link_non_edges,
                         link_patterns):
    links = []

    with pytest.raises(polyply.src.apply_links.MatchError):
        processor = ApplyLinks()
        for link_nodes, link_to_resid, interactions, non_edges, patterns, inter_type in zip(
                link_defs, link_to_resids, link_inters, link_non_edges,
                link_patterns, inter_types):
            link = Link()
            link.add_nodes_from(link_nodes)
            link.interactions[inter_type] = interactions
            link.non_edges = non_edges
            link.patterns = patterns
            link.make_edges_from_interaction_type(inter_type)
            processor.apply_link_between_residues(example_meta_molecule, link,
                                                  link_to_resid)