def test_no_residue_crossing():
    """
    Make sure we don't cross residue boundaries
    """
    mapping = {'C1': {'B1': 1}, 'C2': {'B1': 1}, 'C3': {'B1': 1}}
    extra = ()
    mappings = {'universal': {'martini22': {'IPO': Mapping(FF_UNIVERSAL.blocks['IPO'],
                                                           FF_MARTINI.blocks['IPO'],
                                                           mapping=mapping,
                                                           references={},
                                                           ff_from=FF_UNIVERSAL,
                                                           ff_to=FF_MARTINI,
                                                           names=('IPO',),
                                                           extra=extra)}}}

    cg = do_mapping(AA_MOL, mappings, FF_MARTINI, attribute_keep=['chain'])

    expected = Molecule(force_field=FF_MARTINI)
    expected.add_nodes_from((
        (0, {'resid': 1, 'resname': 'IPO', 'atomname': 'B1', 'chain': 'A', 'charge_group': 1}),
        (1, {'resid': 2, 'resname': 'IPO', 'atomname': 'B1', 'chain': 'A', 'charge_group': 2}),
        (2, {'resid': 3, 'resname': 'IPO', 'atomname': 'B1', 'chain': 'A', 'charge_group': 3}),
    ))
    expected.add_edges_from(([0, 1], [1, 2]))

    print(cg.nodes(data=True))
    print(cg.edges())
    print('-'*80)
    print(expected.nodes(data=True))
    print(expected.edges())
    assert equal_graphs(cg, expected)
def test_no_residue_crossing():
    """
    Make sure we don't cross residue boundaries
    """
    mapping = {
        (0, 'C1'): [(0, 'B1')],
        (0, 'C2'): [(0, 'B1')],
        (0, 'C3'): [(0, 'B1')]
    }
    weights = {
        (0, 'B1'): {
            (0, 'C1'): 1,
            (0, 'C2'): 1,
            (0, 'C3'): 1,
        }
    }
    extra = ()
    mappings = {'universal': {'martini22': {'IPO': (mapping, weights, extra)}}}

    cg = do_mapping(AA_MOL, mappings, FF_MARTINI)

    expected = Molecule(force_field=FF_MARTINI)
    expected.add_nodes_from((
        (0, {
            'resid': 1,
            'resname': 'IPO',
            'atomname': 'B1',
            'chain': 'A',
            'charge_group': 1
        }),
        (1, {
            'resid': 2,
            'resname': 'IPO',
            'atomname': 'B1',
            'chain': 'A',
            'charge_group': 2
        }),
        (2, {
            'resid': 3,
            'resname': 'IPO',
            'atomname': 'B1',
            'chain': 'A',
            'charge_group': 3
        }),
    ))
    expected.add_edges_from(([0, 1], [1, 2]))

    print(cg.nodes(data=True))
    print(cg.edges())
    print('-' * 80)
    print(expected.nodes(data=True))
    print(expected.edges())
    assert _equal_graphs(cg, expected)
Example #3
0
def example_mol():
    mol = Molecule(force_field=ForceField(FF_UNIVERSAL_TEST))
    nodes = [
        {
            'chain': 'A',
            'resname': 'A',
            'resid': 1
        },  # 0, R1
        {
            'chain': 'A',
            'resname': 'A',
            'resid': 2
        },  # 1, R2
        {
            'chain': 'A',
            'resname': 'A',
            'resid': 2
        },  # 2, R2
        {
            'chain': 'A',
            'resname': 'B',
            'resid': 2
        },  # 3, R3
        {
            'chain': 'B',
            'resname': 'A',
            'resid': 1
        },  # 4, R4
        {
            'chain': 'B',
            'resname': 'A',
            'resid': 2
        },  # 5, R5
        {
            'chain': 'B',
            'resname': 'A',
            'resid': 2
        },  # 6, R5
        {
            'chain': 'B',
            'resname': 'B',
            'resid': 2
        },  # 7, R6
        {
            'chain': 'A',
            'resname': 'C',
            'resid': 3
        },  # 8, R7
    ]
    mol.add_nodes_from(enumerate(nodes))
    mol.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (4, 7),
                        (3, 8)])
    return mol
Example #4
0
def test_single_residue_mol():
    mol = Molecule(force_field=ForceField(FF_UNIVERSAL_TEST))
    nodes = [
        {'chain': 'A', 'resname': 'A', 'resid': 2},
        {'chain': 'A', 'resname': 'A', 'resid': 2},
    ]
    mol.add_nodes_from(enumerate(nodes))
    mol.add_edges_from([(0, 1)])

    modification = [({'resname': 'A', 'resid': 2}, 'C-ter'),]
    annotate_modifications(mol, modification, [])

    assert mol.nodes[0] == {'modification': ['C-ter'], 'resname': 'A', 'resid': 2, 'chain': 'A'}
    assert mol.nodes[1] == {'modification': ['C-ter'], 'resname': 'A', 'resid': 2, 'chain': 'A'}
def modified_molecule(modifications):
    """
    Provides a molecule with modifications
    """
    mol = Molecule(force_field=FF_UNIVERSAL)
    mol.add_nodes_from(enumerate((
        # Lone PTM
        {'atomname': 'A', 'resid': 1, 'modifications': [modifications['mA']]},
        {'atomname': 'mA', 'resid': 1, 'PTM_atom': True, 'modifications': [modifications['mA']]},
        {'atomname': 'B', 'resid': 2},  # Spacer
        # Two PTMs on neighbouring residues
        {'atomname': 'C', 'resid': 3, 'modifications': [modifications['mC']]},
        {'atomname': 'mC', 'resid': 3, 'PTM_atom': True, 'modifications': [modifications['mC']]},
        {'atomname': 'D', 'resid': 4, 'modifications': [modifications['mD']]},
        {'atomname': 'mD', 'resid': 4, 'PTM_atom': True, 'modifications': [modifications['mD']]},
        {'atomname': 'E', 'resid': 5},  # Spacer
        # Bridging PTMs
        {'atomname': 'F', 'resid': 6, 'modifications': [modifications['mFG']]},
        {'atomname': 'mF', 'resid': 6, 'PTM_atom': True, 'modifications': [modifications['mFG']]},
        {'atomname': 'G', 'resid': 7, 'modifications': [modifications['mFG']]},
        {'atomname': 'mG', 'resid': 7, 'PTM_atom': True, 'modifications': [modifications['mFG']]},
        {'atomname': 'H', 'resid': 8},  # Spacer
        # Two PTMs for one residue
        {'atomname': 'I', 'resid': 9, 'modifications': [modifications['mI'], modifications['mI2']]},
        {'atomname': 'mI', 'resid': 9, 'PTM_atom': True, 'modifications': [modifications['mI']]},
        {'atomname': 'mI2', 'resid': 9, 'PTM_atom': True, 'modifications': [modifications['mI2']]},
        # Two PTMs for one residue, but a single mod mapping
        {'atomname': 'J', 'resid': 10, 'modifications': [modifications['mJ'], modifications['mJ2']]},
        {'atomname': 'mJ', 'resid': 10, 'PTM_atom': True, 'modifications': [modifications['mJ']]},
        {'atomname': 'mJ2', 'resid': 10, 'PTM_atom': True, 'modifications': [modifications['mJ2']]}
    )))
    mol.add_edges_from((
        (0, 1), (0, 2),  # A
        (2, 3),  # B
        (3, 4), (3, 5),  # C
        (5, 6), (5, 7),  # D
        (7, 8),  # E
        (8, 9), (8, 10),  # F
        (9, 11),  # Bridge between mF and mG
        (10, 11), (10, 12),  # G
        (12, 13),  # H
        (13, 14), (13, 15), (13, 16),  # I
        (16, 17), (16, 18)  # J
    ))
    return mol
Example #6
0
def test_nter_cter_modifications(node_data, edge_data, expected):
    """
    Tests that 'nter' and 'cter' specifications only match protein N and C
    termini
    """
    mol = Molecule(force_field=ForceField(FF_UNIVERSAL_TEST))
    mol.add_nodes_from(enumerate(node_data))
    mol.add_edges_from(edge_data)
    modification = [({'resname': 'cter'}, 'C-ter'), ({'resname': 'nter'}, 'N-ter')]

    annotate_modifications(mol, modification, [])

    found = {}
    for node_idx in mol:
        node = mol.nodes[node_idx]
        if 'modification' in node:
            found[node['resid']] = node['modification']

    assert found == expected
def test_residue_crossing():
    '''
    Make sure we do cross residue boundaries and can rename residues
    '''
    mapping = {'C1': {'B1': 1}, 'C2': {'B1': 1}, 'C3': {'B1': 1},
               'C4': {'B2': 1}, 'C5': {'B2': 1}, 'C6': {'B2': 1},
               'C7': {'B3': 1}, 'C8': {'B3': 1}, 'C9': {'B3': 1},
               }
    extra = ()
    mappings = {
        'universal': {
            'martini22': {
                'IPO_large': Mapping(FF_UNIVERSAL.blocks['IPO_large'],
                                     FF_MARTINI.blocks['IPO_large'],
                                     mapping=mapping,
                                     references={},
                                     ff_from=FF_UNIVERSAL,
                                     ff_to=FF_MARTINI,
                                     names=('IPO', 'IPO', 'IPO'),
                                     extra=extra)
            }
        }
    }

    cg = do_mapping(AA_MOL, mappings, FF_MARTINI, attribute_keep=('chain',))

    expected = Molecule()
    expected.add_nodes_from((
        (0, {'resid': 1, 'resname': 'IPO_large', 'atomname': 'B1', 'chain': 'A', 'charge_group': 1}),
        (1, {'resid': 2, 'resname': 'IPO_large', 'atomname': 'B1', 'chain': 'A', 'charge_group': 1}),
        (2, {'resid': 3, 'resname': 'IPO_large', 'atomname': 'B1', 'chain': 'A', 'charge_group': 1}),
    ))
    expected.add_edges_from(([0, 1], [1, 2]))

    print(cg.nodes(data=True))
    print(cg.edges())
    print('-'*80)
    print(expected.nodes(data=True))
    print(expected.edges())
    assert equal_graphs(cg, expected)
def test_make_bonds(nodes, edges, expected_edges):
    """
    Test to make sure that make_bonds makes the bonds it is expected to, and not
    too many.
    nodes is a List[List[Dict]], allowing for multiple molecules
    edges is a List[List[Tuple[Int, Int, Dict]]], allowing for
        multiple molecules
    expected_edges is a List[Dict[Tuple[Int, Int], Dict]], allowing for
        multiple molecules
    """
    system = System(force_field=get_native_force_field('universal'))
    for node_set, edge_set in zip(nodes, edges):
        mol = Molecule()
        mol.add_nodes_from(enumerate(node_set))
        mol.add_edges_from(edge_set)
        system.add_molecule(mol)
    MakeBonds().run_system(system)
    # Make sure number of connected components is the same
    assert len(system.molecules) == len(expected_edges)
    # Make sure that for every molecule found, the edges are correct
    for found_mol, ref_edges in zip(system.molecules, expected_edges):
        assert dict(found_mol.edges) == ref_edges
def test_peptide():
    """
    Test multiple cg beads in residue
    """
    gly = {'C': {'BB': 1}, 'N': {'BB': 1}, 'O': {'BB': 1}, 'CA': {'BB': 1}}
    ile = {'C': {'BB': 1}, 'N': {'BB': 1}, 'O': {'BB': 1}, 'CA': {'BB': 1},
           'CB': {'SC1': 1}, 'CG1': {'SC1': 1}, 'CG2': {'SC1': 1}, 'CD': {'SC1': 1}}
    leu = {'C': {'BB': 1}, 'N': {'BB': 1}, 'O': {'BB': 1}, 'CA': {'BB': 1},
           'CB': {'SC1': 1}, 'CG': {'SC1': 1}, 'CD1': {'SC1': 1}, 'CD2': {'SC1': 1}}
    extra = ()

    mappings = {'universal': {'martini22': {}}}
    mappings['universal']['martini22']['GLY'] = Mapping(FF_UNIVERSAL.blocks['GLY'],
                                                        FF_MARTINI.blocks['GLY'],
                                                        mapping=gly,
                                                        references={},
                                                        ff_from=FF_UNIVERSAL,
                                                        ff_to=FF_MARTINI,
                                                        names=('GLY',),
                                                        extra=extra)
    mappings['universal']['martini22']['ILE'] = Mapping(FF_UNIVERSAL.blocks['ILE'],
                                                        FF_MARTINI.blocks['ILE'],
                                                        mapping=ile,
                                                        references={},
                                                        ff_from=FF_UNIVERSAL,
                                                        ff_to=FF_MARTINI,
                                                        names=('ILE',),
                                                        extra=extra)
    mappings['universal']['martini22']['LEU'] = Mapping(FF_UNIVERSAL.blocks['LEU'],
                                                        FF_MARTINI.blocks['LEU'],
                                                        mapping=leu,
                                                        references={},
                                                        ff_from=FF_UNIVERSAL,
                                                        ff_to=FF_MARTINI,
                                                        names=('LEU',),
                                                        extra=extra)

    peptide = Molecule(force_field=FF_UNIVERSAL)
    aa = FF_UNIVERSAL.blocks['GLY'].to_molecule()
    peptide.merge_molecule(aa)

    aa = FF_UNIVERSAL.blocks['ILE'].to_molecule()
    peptide.merge_molecule(aa)

    aa = FF_UNIVERSAL.blocks['LEU'].to_molecule()
    peptide.merge_molecule(aa)

    peptide.add_edge(list(peptide.find_atoms(atomname='N', resid=1))[0],
                     list(peptide.find_atoms(atomname='C', resid=2))[0])
    peptide.add_edge(list(peptide.find_atoms(atomname='N', resid=2))[0],
                     list(peptide.find_atoms(atomname='C', resid=3))[0])

    for node in peptide:
        peptide.nodes[node]['atomid'] = node + 1
        peptide.nodes[node]['chain'] = ''

    cg = do_mapping(peptide, mappings, FF_MARTINI, attribute_keep=('chain',))

    expected = Molecule(force_field=FF_MARTINI)
    expected.add_nodes_from({1: {'atomname': 'BB',
                                 'atype': 'P5',
                                 'chain': '',
                                 'charge': 0.0,
                                 'charge_group': 1,
                                 'resid': 1,
                                 'resname': 'GLY'},
                             2: {'atomname': 'BB',
                                 'atype': 'P5',
                                 'chain': '',
                                 'charge': 0.0,
                                 'charge_group': 2,
                                 'resid': 2,
                                 'resname': 'ILE'},
                             3: {'atomname': 'SC1',
                                 'atype': 'AC1',
                                 'chain': '',
                                 'charge': 0.0,
                                 'charge_group': 3,
                                 'resid': 2,
                                 'resname': 'ILE'},
                             4: {'atomname': 'BB',
                                 'atype': 'P5',
                                 'chain': '',
                                 'charge': 0.0,
                                 'charge_group': 4,
                                 'resid': 3,
                                 'resname': 'LEU'},
                             5: {'atomname': 'SC1',
                                 'atype': 'AC1',
                                 'chain': '',
                                 'charge': 0.0,
                                 'charge_group': 5,
                                 'resid': 3,
                                 'resname': 'LEU'}}.items()
                            )
    expected.add_edges_from([(1, 2), (2, 3), (2, 4), (4, 5)])

    for node in expected:
        expected.nodes[node]['atomid'] = node + 1
    print(cg.nodes(data=True))
    print(cg.edges())
    print('-'*80)
    print(expected.nodes(data=True))
    print(expected.edges())

    assert equal_graphs(cg, expected)
FF_MARTINI = vermouth.forcefield.get_native_force_field(name='martini22')
FF_UNIVERSAL = vermouth.forcefield.get_native_force_field(name='universal')

AA_MOL = Molecule(force_field=FF_UNIVERSAL)
AA_MOL.add_nodes_from((
    (0, {'resid': 1, 'resname': 'IPO', 'atomname': 'C1', 'chain': 'A', 'element': 'C'}),
    (1, {'resid': 1, 'resname': 'IPO', 'atomname': 'C2', 'chain': 'A', 'element': 'C'}),
    (2, {'resid': 1, 'resname': 'IPO', 'atomname': 'C3', 'chain': 'A', 'element': 'C'}),
    (3, {'resid': 2, 'resname': 'IPO', 'atomname': 'C1', 'chain': 'A', 'element': 'C'}),
    (4, {'resid': 2, 'resname': 'IPO', 'atomname': 'C2', 'chain': 'A', 'element': 'C'}),
    (5, {'resid': 2, 'resname': 'IPO', 'atomname': 'C3', 'chain': 'A', 'element': 'C'}),
    (6, {'resid': 3, 'resname': 'IPO', 'atomname': 'C1', 'chain': 'A', 'element': 'C'}),
    (7, {'resid': 3, 'resname': 'IPO', 'atomname': 'C2', 'chain': 'A', 'element': 'C'}),
    (8, {'resid': 3, 'resname': 'IPO', 'atomname': 'C3', 'chain': 'A', 'element': 'C'}),
))
AA_MOL.add_edges_from([(0, 1), (1, 2), (1, 3), (3, 4), (4, 5), (4, 6), (6, 7), (7, 8)])
block_aa = Block(force_field=FF_UNIVERSAL)
block_aa.name = 'IPO'
block_aa.add_nodes_from((
    ('C1', {'resid': 1, 'resname': 'IPO', 'atomname': 'C1'}),
    ('C2', {'resid': 1, 'resname': 'IPO', 'atomname': 'C2'}),
    ('C3', {'resid': 1, 'resname': 'IPO', 'atomname': 'C3'}),
))
block_aa.add_edges_from([('C1', 'C2'), ('C2', 'C3')])

block_cg = Block(force_field=FF_MARTINI)
block_cg.name = 'IPO'
block_cg.add_nodes_from((('B1', {'resid': 1, 'resname': 'IPO', 'atomname': 'B1'}),))

FF_MARTINI.blocks['IPO'] = block_cg
FF_UNIVERSAL.blocks['IPO'] = block_aa
def make_mol(mol_nodes, mol_edges=[], **kwargs):
    mol = Molecule(**kwargs)
    mol.add_nodes_from(mol_nodes)
    mol.add_edges_from(mol_edges)
    return mol
def test_peptide():
    """
    Test multiple cg beads in residue
    """
    gly = {
        (0, 'C'): [(0, 'BB')],
        (0, 'N'): [(0, 'BB')],
        (0, 'O'): [(0, 'BB')],
        (0, 'CA'): [(0, 'BB')]
    }
    ile = {
        (0, 'C'): [(0, 'BB')],
        (0, 'N'): [(0, 'BB')],
        (0, 'O'): [(0, 'BB')],
        (0, 'CA'): [(0, 'BB')],
        (0, 'CB'): [(0, 'SC1')],
        (0, 'CG1'): [(0, 'SC1')],
        (0, 'CG2'): [(0, 'SC1')],
        (0, 'CD'): [(0, 'SC1')]
    }
    leu = {
        (0, 'C'): [(0, 'BB')],
        (0, 'N'): [(0, 'BB')],
        (0, 'O'): [(0, 'BB')],
        (0, 'CA'): [(0, 'BB')],
        (0, 'CB'): [(0, 'SC1')],
        (0, 'CG1'): [(0, 'SC1')],
        (0, 'CD1'): [(0, 'SC1')],
        (0, 'CD2'): [(0, 'SC1')]
    }
    extra = ()
    mappings = {
        'universal': {
            'martini22': {
                'GLY': (gly, _map_weights(gly), extra),
                'ILE': (ile, _map_weights(ile), extra),
                'LEU': (leu, _map_weights(leu), extra),
            }
        }
    }

    peptide = Molecule(force_field=FF_UNIVERSAL)
    aa = FF_UNIVERSAL.blocks['GLY'].to_molecule()
    peptide.merge_molecule(aa)

    aa = FF_UNIVERSAL.blocks['ILE'].to_molecule()
    peptide.merge_molecule(aa)

    aa = FF_UNIVERSAL.blocks['LEU'].to_molecule()
    peptide.merge_molecule(aa)

    peptide.add_edge(
        list(peptide.find_atoms(atomname='N', resid=1))[0],
        list(peptide.find_atoms(atomname='C', resid=2))[0])
    peptide.add_edge(
        list(peptide.find_atoms(atomname='N', resid=2))[0],
        list(peptide.find_atoms(atomname='C', resid=3))[0])

    for node in peptide:
        peptide.nodes[node]['atomid'] = node + 1
        peptide.nodes[node]['chain'] = ''

    cg = do_mapping(peptide, mappings, FF_MARTINI)

    expected = Molecule(force_field=FF_MARTINI)
    expected.add_nodes_from({
        1: {
            'atomname': 'BB',
            'atype': 'P5',
            'chain': '',
            'charge': 0.0,
            'charge_group': 1,
            'resid': 1,
            'resname': 'GLY'
        },
        2: {
            'atomname': 'BB',
            'atype': 'P5',
            'chain': '',
            'charge': 0.0,
            'charge_group': 2,
            'resid': 2,
            'resname': 'ILE'
        },
        3: {
            'atomname': 'SC1',
            'atype': 'AC1',
            'chain': '',
            'charge': 0.0,
            'charge_group': 2,
            'resid': 2,
            'resname': 'ILE'
        },
        4: {
            'atomname': 'BB',
            'atype': 'P5',
            'chain': '',
            'charge': 0.0,
            'charge_group': 3,
            'resid': 3,
            'resname': 'LEU'
        },
        5: {
            'atomname': 'SC1',
            'atype': 'AC1',
            'chain': '',
            'charge': 0.0,
            'charge_group': 3,
            'resid': 3,
            'resname': 'LEU'
        }
    }.items())
    expected.add_edges_from([(1, 2), (2, 3), (2, 4), (4, 5)])

    for node in expected:
        expected.nodes[node]['atomid'] = node + 1

    assert _equal_graphs(cg, expected)
Example #13
0
def charged_molecule(force_field):
    """
    A molecule with charged termini.
    """
    nodes = [(1, {
        'charge_group': 1,
        'resid': 1,
        'resname': 'ALA',
        'atomname': 'BB',
        'charge': 1,
        'atype': 'Qd',
        'modification': force_field.modifications['N-ter'],
        'mapping_weights': {
            0: 1,
            5: 1,
            1: 1,
            4: 1.0,
            2: 1,
            3: 1,
            6: 1,
            7: 1
        },
        'chain': 'A',
        'position': [0.12170435, 0.06658551, -0.0208]
    }),
             (2, {
                 'charge_group': 2,
                 'resid': 2,
                 'resname': 'ALA',
                 'atomname': 'BB',
                 'charge': 0.0,
                 'atype': 'P4',
                 'mapping_weights': {
                     12: 1.0,
                     17: 1.0,
                     13: 1.0,
                     16: 1.0,
                     14: 1.0,
                     15: 1.0
                 },
                 'chain': 'A',
                 'position': [0.45269104, 0.23552239, 0.0214209]
             }),
             (3, {
                 'charge_group': 3,
                 'resid': 3,
                 'resname': 'ALA',
                 'atomname': 'BB',
                 'charge': 0.0,
                 'atype': 'P4',
                 'mapping_weights': {
                     22: 1.0,
                     27: 1.0,
                     23: 1.0,
                     26: 1.0,
                     24: 1.0,
                     25: 1.0
                 },
                 'chain': 'A',
                 'position': [0.74704179, 0.45218955, -0.0214209]
             }),
             (4, {
                 'charge_group': 4,
                 'resid': 4,
                 'resname': 'ALA',
                 'atomname': 'BB',
                 'charge': 0.0,
                 'atype': 'P4',
                 'mapping_weights': {
                     32: 1.0,
                     37: 1.0,
                     33: 1.0,
                     36: 1.0,
                     34: 1.0,
                     35: 1.0
                 },
                 'chain': 'A',
                 'position': [1.07289104, 0.61778657, 0.0214209]
             }),
             (5, {
                 'charge_group': 5,
                 'resid': 5,
                 'resname': 'ALA',
                 'atomname': 'BB',
                 'charge': -1,
                 'atype': 'Qa',
                 'modification': force_field.modifications['C-ter'],
                 'mapping_weights': {
                     42: 1.0,
                     48: 1.0,
                     43: 1,
                     47: 1.0,
                     44: 1,
                     45: 1,
                     46: 1
                 },
                 'chain': 'A',
                 'position': [1.40449639, 0.85126265, -0.01729157]
             })]
    mol = Molecule()
    mol.add_nodes_from(nodes)
    mol.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 5)])
    return mol