예제 #1
0
def test_unknown_mods_removed(caplog, repaired_graph, known_mod_names):
    """
    Tests that atoms that are part of modifications, but are not recognized, get
    removed from the graph by CanonicalizeModifications
    """
    caplog.set_level(logging.WARNING)
    ff = copy.copy(repaired_graph.force_field)
    for mod_name in known_mod_names:
        assert mod_name in ff.modifications  # Purely defensive

    removed_mods = []
    for name, mod in dict(ff.modifications).items():
        if name not in known_mod_names:
            del ff.modifications[name]
            removed_mods.append(mod)

    repaired_graph.force_field = ff
    mol = repaired_graph.molecules[0]

    assert not caplog.records
    assert len(mol) == 46
    vermouth.CanonicalizeModifications().run_system(repaired_graph)

    assert caplog.records

    for record in caplog.records:
        assert record.levelname == 'WARNING'

    assert len(mol) < 46
    atomnames = dict(mol.nodes(data='atomname')).values()
    for mod in removed_mods:
        for node_key in mod.nodes:
            node = mod.nodes[node_key]
            if node['PTM_atom']:
                assert node['atomname'] not in atomnames

    for node_key in mol.nodes:
        node = mol.nodes[node_key]
        if node.get('PTM_atom'):
            contained_by = [
                mod for mod in ff.modifications.values()
                if node.get('expected', node['atomname']) in dict(
                    mod.nodes(data='atomname')).values()
            ]
            assert len(contained_by) == 1
예제 #2
0
def canonicalized_graph(repaired_graph):
    vermouth.CanonicalizeModifications().run_system(repaired_graph)
    return repaired_graph