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_treat_link_interaction_atoms(atoms, apply_to_all, existing, expected): """ Test that _treat_link_interaction_atoms works as expected. """ context = Link() if apply_to_all: context._apply_to_all_nodes = apply_to_all context.add_nodes_from(existing.items()) ffinput._treat_link_interaction_atoms(atoms, context, 'section') found = dict(context.nodes.items()) assert found == expected
def test_treat_link_interaction_atoms_conflicts(): """ Test that _treat_link_interaction_atoms fails when there is a conflict between the atoms to add ans the existing atoms. """ context = Link() context.add_nodes_from({ 'A': { 'exist': 'before' }, }.items()) atoms = (('A', {'exist': 'after'}), ) with pytest.raises(IOError): ffinput._treat_link_interaction_atoms(atoms, context, 'section')
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)
def modifications(): """ Provides modifications """ mods = {} mod_a = Link(force_field=FF_UNIVERSAL, name='mA') mod_a.add_node('mA', atomname='mA', PTM_atom=True) mods['mA'] = mod_a mod_c = Link(force_field=FF_UNIVERSAL, name='mC') mod_c.add_node('mC', atomname='mC', PTM_atom=True) mods['mC'] = mod_c mod_d = Link(force_field=FF_UNIVERSAL, name='mD') mod_d.add_node('mD', atomname='mD', PTM_atom=True) mods['mD'] = mod_d mod_fg = Link(force_field=FF_UNIVERSAL, name='mFG') mod_fg.add_node('mF', atomname='mF', PTM_atom=True) mod_fg.add_node('mG', atomname='mG', PTM_atom=True) mod_fg.add_edge('mF', 'mG') mod_fg.add_interaction('bond', ['mF', 'mG'], (3, 4)) mods['mFG'] = mod_fg mod_i = Link(force_field=FF_UNIVERSAL, name='mI') mod_i.add_node('mI', atomname='mI', PTM_atom=True) mods['mI'] = mod_i mod_i2 = Link(force_field=FF_UNIVERSAL, name='mI2') mod_i2.add_node('mI2', atomname='mI2', PTM_atom=True) mods['mI2'] = mod_i2 mod_j = Link(force_field=FF_UNIVERSAL, name='mJ') mod_j.add_node('mJ', atomname='mJ', PTM_atom=True) mods['mJ'] = mod_j mod_j2 = Link(force_field=FF_UNIVERSAL, name='mJ2') mod_j2.add_node('mJ2', atomname='mJ2', PTM_atom=True) mods['mJ2'] = mod_j2 mod = Link(name=('mJ', 'mJ2'), force_field=FF_UNIVERSAL) mod.add_nodes_from((['mJ', {'atomname': 'mJ', 'PTM_atom': True}], ['mJ2', {'atomname': 'mJ2', 'PTM_atom': True}], ['J', {'atomname': 'J', 'PTM_atom': False}])) mod.add_edges_from([('J', 'mJ'), ('J', 'mJ2')]) mods[('mJ', 'mJ2')] = mod return mods
def build_forcefield_with_mods(): """ Build a force field that describe some modifications. Returns ------- vermouth.ForceField """ nter = Link(name='N-ter') nter.add_nodes_from(( (0, {'atomname': 'CA', 'PTM_atom': False, 'element': 'C'}), (1, {'atomname': 'N', 'PTM_atom': False, 'element': 'N'}), (2, {'atomname': 'HN', 'PTM_atom': False, 'element': 'H'}), (3, {'atomname': 'H', 'PTM_atom': True, 'element': 'H'}), )) nter.add_edges_from([[0, 1], [1, 2], [1, 3]]) cter = Link(name='C-ter') cter.add_nodes_from(( (0, {'atomname': 'C', 'PTM_atom': False, 'element': 'C'}), (1, {'atomname': 'O', 'PTM_atom': False, 'element': 'O'}), (2, {'atomname': 'OXT', 'PTM_atom': True, 'element': 'O'}), )) cter.add_edges_from([[0, 1], [0, 2]]) gluh = Link(name='GLU-H') gluh.add_nodes_from(( (0, {'atomname': 'CD', 'PTM_atom': False, 'element': 'C'}), (1, {'atomname': 'OE1', 'PTM_atom': False, 'element': 'O'}), (2, {'atomname': 'OE2', 'PTM_atom': False, 'element': 'O'}), (3, {'atomname': 'HE1', 'PTM_atom': True, 'element': 'H'}), )) gluh.add_edges_from([[0, 1], [0, 2], [1, 3]]) forcefield = copy.copy(vermouth.forcefield.get_native_force_field('universal')) forcefield.modifications = {} for mod in [nter, gluh, cter]: forcefield.modifications[mod.name] = mod forcefield.renamed_residues[('GLU', ('GLU-H', 'N-ter'))] = 'GLU0' return forcefield
def make_link(mol_nodes, mol_edges=[]): mol = Link() mol.add_nodes_from(mol_nodes) mol.add_edges_from(mol_edges) return mol