Exemplo n.º 1
0
def force_fields():
    """
    Read a bunch of force fields fit for testing
    """
    ffs = {}
    ffs['universal-test'] = ForceField(FF_UNIVERSAL_TEST)
    ffs['pepplane'] = ForceField(FF_PEPPLANE)
    ffs['martini-test'] = ForceField(FF_MARTINI_TEST)
    assert set(ffs.keys()) == {'universal-test', 'pepplane', 'martini-test'}
    assert set(ffs['universal-test'].modifications.keys()) >= {'C-ter', 'N-ter'}
    assert set(ffs['universal-test'].blocks.keys()) >= {'ALA',}
    return ffs
Exemplo n.º 2
0
def compare_itp(filename1, filename2):
    """
    Asserts that two itps are functionally identical
    """
    dummy_ff = ForceField(name='dummy')
    with open(filename1) as fn1:
        vermouth.gmx.read_itp(fn1, dummy_ff)
    dummy_ff2 = ForceField(name='dummy')
    with open(filename2) as fn2:
        vermouth.gmx.read_itp(fn2, dummy_ff2)
    for block in dummy_ff2.blocks.values():
        block._force_field = dummy_ff
    assert set(dummy_ff.blocks.keys()) == set(dummy_ff2.blocks.keys())
    for name in dummy_ff.blocks:
        block1 = dummy_ff.blocks[name]
        block2 = dummy_ff2.blocks[name]
        assert_equal_blocks(block1, block2)
def force_fields():
    """
    Creates a simple forcefield for tests
    """
    ffa = ForceField(name='test_A')
    block_a = Block(name='block_A', force_field=ffa)
    block_a.add_nodes_from(['A1', 'A2', 'B1', 'B2'])
    for node in block_a.nodes:
        block_a.nodes[node]['atomname'] = node
        block_a.nodes[node]['resname'] = 'block_A'
    block_a.add_edges_from([('A1', 'A2'), ('B1', 'B2')])
    ffa.blocks['block_A'] = block_a
    ffa.modifications['block_A'] = Link(block_a)
    block_b = Block(name='block_B', force_field=ffa)
    block_b.add_node('A', atomname='A', resname='block_B', replace={'atomname': 'B'})
    ffa.blocks['block_B'] = block_b
    return {'test_A': ffa}
Exemplo n.º 4
0
def test_raise_residue_error(top_lines):
    lines = textwrap.dedent(top_lines)
    lines = lines.splitlines()
    force_field = ForceField("test")
    topology = Topology(force_field)
    read_topology(lines=lines, topology=topology, cwdir="./")
    topology.preprocess()
    topology.volumes = {"GLY": 0.53, "GLU": 0.67, "ASP": 0.43}
    with pytest.raises(IOError):
        polyply.src.check_residue_equivalence.check_residue_equivalence(
            topology)
Exemplo n.º 5
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
Exemplo n.º 6
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'}
Exemplo n.º 7
0
def example_topology():
    top_lines = """
    [ defaults ]
    1   1   no   1.0     1.0
    [ atomtypes ]
    N0 45.0 0.000 A 0.0 0.0
    [ nonbond_params ]
    N0   N0   1 4.700000e-01    3.700000e+00
    [ moleculetype ]
    testA 1
    [ atoms ]
    1    N0  1   GLY    BB   1 0.00     45
    2    N0  1   GLY    SC1  1 0.00     45
    3    N0  1   GLY    SC2  1 0.00     45
    4    N0  2   GLU    BB   2 0.00     45
    5    N0  2   GLU    SC1  2 0.00     45
    6    N0  2   GLU    SC2  2 0.00     45
    [ bonds ]
    1    2    1  0.47 2000
    2    3    1  0.47 2000
    1    4    1  0.47 2000
    4    5    1  0.47 2000
    4    6    1  0.47 2000
    [ moleculetype ]
    testB 1
    [ atoms ]
    1    N0  1   ASP    BB   1 0.00
    2    N0  1   ASP    SC1  1 0.00
    3    N0  1   ASP    SC2  1 0.00
    [ bonds ]
    1    2    1  0.47 2000
    2    3    1  0.47 2000
    [ system ]
    test system
    [ molecules ]
    testA 2
    testB 1
    """
    lines = textwrap.dedent(top_lines)
    lines = lines.splitlines()
    force_field = ForceField("test")
    topology = Topology(force_field)
    read_topology(lines=lines, topology=topology, cwdir="./")
    topology.preprocess()
    topology.volumes = {"GLY": 0.53, "GLU": 0.67, "ASP": 0.43}
    return topology
Exemplo n.º 8
0
    def from_gmx_topfile(cls, path, name):
        """
        Read a gromacs topology file and return an topology object.

        Parameters
        ----------
        path:  str
           The name of the topology file
        name:  str
           The name of the system
        """
        with open(path, 'r') as _file:
            lines = _file.readlines()

        cwdir = os.path.dirname(path)
        force_field = ForceField(name)
        topology = cls(force_field=force_field, name=name)
        read_topology(lines=lines, topology=topology, cwdir=cwdir)
        return topology
Exemplo n.º 9
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
Exemplo n.º 10
0
def test_raise_residue_no_error():
    """
    This test makes sure that we actually skip molecules that are defined
    in the top file but not used in the actual system.
    """
    top_lines = """
    [ defaults ]
    1   1   no   1.0     1.0
    [ atomtypes ]
    N0 72.0 0.000 A 0.0 0.0
    N1 72.0 0.000 A 0.0 0.0
    [ nonbond_params ]
    N0   N0   1 4.700000e-01    3.700000e+00
    N1   N1   1 4.700000e-01    3.700000e+00
    [ moleculetype ]
    testA 1
    [ atoms ]
    1    N0   1   GLY    BB   1 0.00     45
    2    N0   1   GLY    SC1  1 0.00     45
    3    N0   1   GLY    SC2  1 0.00     45
    4    N1   2   GLU    BB   2 0.00     45
    5    N1   2   GLU    SC1  2 0.00     45
    6    N1   2   GLU    SC2  2 0.00     45
    7    N1   2   GLU    SC3  2 0.00     45
    [ bonds ]
    1     2    1  0.47 2000
    2     3    1  0.47 2000
    3     4    1  0.47 2000
    4     5    1  0.47 2000
    5     6    1  0.47 2000
    6     7    1  0.47 2000
    [ moleculetype ]
    testB 1
    [ atoms ]
    1    N0   1   ASP    BB   1 0.00     45
    2    N0   1   ASP    SC3  1 0.00     45
    3    N0   1   ASP    SC4  1 0.00     45
    4    N1   2   GLU    BB   2 0.00     45
    5    N1   2   GLU    SC1  2 0.00     45
    6    N1   2   GLU    SC2  2 0.00     45
    7    N1   2   GLU    SC3  2 0.00     45
    [ bonds ]
    1     2    1  0.47 2000
    2     3    1  0.47 2000
    3     4    1  0.47 2000
    4     5    1  0.47 2000
    5     6    1  0.47 2000
    5     7    1  0.47 2000
    [ system ]
    test system
    [ molecules ]
    testA 1
    """
    lines = textwrap.dedent(top_lines)
    lines = lines.splitlines()
    force_field = ForceField("test")
    topology = Topology(force_field)
    read_topology(lines=lines, topology=topology, cwdir="./")
    topology.preprocess()
    topology.volumes = {"GLY": 0.53, "GLU": 0.67, "ASP": 0.43}
    polyply.src.check_residue_equivalence.check_residue_equivalence(topology)
Exemplo n.º 11
0
def topology():
    top_lines = """
    [ defaults ]
    1   1   no   1.0     1.0
    [ atomtypes ]
    N0 72.0 0.000 A 0.0 0.0
    [ nonbond_params ]
    N0   N0   1 4.700000e-01    3.700000e+00
    [ moleculetype ]
    testA 1
    [ atoms ]
    1    N0   1   GLY    BB   1 0.00     45
    2    N0   2   GLY    SC1  1 0.00     45
    3    N0   3   GLY    SC2  1 0.00     45
    4    N0   4   GLU    BB   2 0.00     45
    5    N0   5   GLU    SC1  2 0.00     45
    6    N0   6   GLU    SC2  2 0.00     45
    7    N0   7   GLU    SC2  2 0.00     45
    8    N0   8   GLU    SC2  2 0.00     45
    9    N0   9   GLU    SC2  2 0.00     45
   10    N0  10   GLU    SC2  2 0.00     45
   11    N0  11   GLU    SC2  2 0.00     45
   12    N0  12   GLU    SC2  2 0.00     45
   13    N0  13   GLU    SC2  2 0.00     45
   14    N0  14   GLU    SC2  2 0.00     45
   15    N0  15   GLU    SC2  2 0.00     45
   16    N0  16   GLU    SC2  2 0.00     45
   17    N0  17   GLU    SC2  2 0.00     45
   18    N0  18   GLU    SC2  2 0.00     45
   19    N0  19   GLU    SC2  2 0.00     45
   20    N0  20   GLU    SC2  2 0.00     45
   21    N0  21   GLU    SC2  2 0.00     45
   22    N0  22   GLU    SC2  2 0.00     45
    [ bonds ]
    1     2    1  0.47 2000
    2     3    1  0.47 2000
    3     4    1  0.47 2000
    4     5    1  0.47 2000
    5     6    1  0.47 2000
    6     7    1  0.47 2000
    7     8    1  0.47 2000
    8     9    1  0.47 2000
    9    10    1  0.47 2000
   10    11    1  0.47 2000
   11    12    1  0.47 2000
   12    13    1  0.47 2000
   13    14    1  0.47 2000
   14    15    1  0.47 2000
   15    16    1  0.47 2000
   16    17    1  0.47 2000
   17    18    1  0.47 2000
   18    19    1  0.47 2000
   19    20    1  0.47 2000
   20    21    1  0.47 2000
   21    22    1  0.47 2000
    [ moleculetype ]
    testB 1
    [ atoms ]
    1    N0   1   ASP    BB   1 0.00     45
    2    N0   2   GLY    SC1  1 0.00     45
    3    N0   3   ASP    SC2  1 0.00     45
    4    N0   4   ASP    BB   2 0.00     45
    5    N0   5   GLY    SC1  2 0.00     45
    6    N0   6   ASP    SC2  2 0.00     45
    7    N0   7   ASP    SC2  2 0.00     45
    8    N0   8   GLU    SC2  2 0.00     45
    9    N0   9   GLU    SC2  2 0.00     45
   10    N0  10   GLY    SC2  2 0.00     45
   11    N0  11   ASP    SC2  2 0.00     45
   12    N0  12   GLU    SC2  2 0.00     45
   13    N0  13   ASP    SC2  2 0.00     45
   14    N0  14   ASP    SC2  2 0.00     45
   15    N0  15   GLU    SC2  2 0.00     45
   16    N0  16   ASP    SC2  2 0.00     45
   17    N0  17   ASP    SC2  2 0.00     45
   18    N0  18   GLY    SC2  2 0.00     45
   19    N0  19   ASP    SC2  2 0.00     45
   20    N0  20   ASP    SC2  2 0.00     45
   21    N0  21   GLY    SC2  2 0.00     45
   22    N0  22   ASP    SC2  2 0.00     45
    [ bonds ]
    1     2    1  0.47 2000
    2     3    1  0.47 2000
    3     4    1  0.47 2000
    4     5    1  0.47 2000
    5     6    1  0.47 2000
    6     7    1  0.47 2000
    7     8    1  0.47 2000
    8     9    1  0.47 2000
    9    10    1  0.47 2000
   10    11    1  0.47 2000
   11    12    1  0.47 2000
   12    13    1  0.47 2000
   13    14    1  0.47 2000
   14    15    1  0.47 2000
   15    16    1  0.47 2000
   16    17    1  0.47 2000
   17    18    1  0.47 2000
   18    19    1  0.47 2000
   19    20    1  0.47 2000
   20    21    1  0.47 2000
   21    22    1  0.47 2000
    [ moleculetype ]
    testC 1
    [ atoms ]
    1    N0   1   GLY    BB   1 0.00     45
    2    N0   2   GLY    SC1  1 0.00     45
    3    N0   3   GLY    SC2  1 0.00     45
    4    N0   4   GLU    BB   2 0.00     45
    5    N0   5   GLU    SC1  2 0.00     45
    6    N0   6   GLU    SC2  2 0.00     45
    7    N0   7   GLU    SC2  2 0.00     45
    8    N0   8   GLU    SC2  2 0.00     45
    9    N0   9   GLU    SC2  2 0.00     45
   10    N0  10   GLU    SC2  2 0.00     45
   11    N0  11   GLU    SC2  2 0.00     45
   12    N0  12   GLU    SC2  2 0.00     45
   13    N0  13   GLU    SC2  2 0.00     45
   14    N0  14   GLU    SC2  2 0.00     45
   15    N0  15   GLU    SC2  2 0.00     45
   16    N0  16   GLU    SC2  2 0.00     45
   17    N0  17   GLU    SC2  2 0.00     45
   18    N0  18   GLU    SC2  2 0.00     45
   19    N0  19   GLU    SC2  2 0.00     45
   20    N0  20   GLU    SC2  2 0.00     45
   21    N0  21   GLU    SC2  2 0.00     45
   22    N0  22   GLU    SC2  2 0.00     45
   23    N0  23   GLU    SC2  2 0.00     45
   24    N0  24   GLU    SC2  2 0.00     45
   25    N0  25   GLU    SC2  2 0.00     45
    [ bonds ]
    1     2    1  0.47 2000
    2     3    1  0.47 2000
    3     4    1  0.47 2000
    4     5    1  0.47 2000
    5     6    1  0.47 2000
    6     7    1  0.47 2000
    7     8    1  0.47 2000
    8     9    1  0.47 2000
    9    10    1  0.47 2000
   10    11    1  0.47 2000
   11    12    1  0.47 2000
   12    13    1  0.47 2000
   13    14    1  0.47 2000
   14    15    1  0.47 2000
   15    16    1  0.47 2000
   16    17    1  0.47 2000
   17    18    1  0.47 2000
   18    19    1  0.47 2000
   19    20    1  0.47 2000
   20    21    1  0.47 2000
   21    22    1  0.47 2000
    3    23    1  0.47 2000
    23   24    1  0.47 2000
    3    25    1  0.47 2000
   [ system ]
    test system
    [ molecules ]
    testA 10
    testB 10
    testC 5
    """
    lines = textwrap.dedent(top_lines)
    lines = lines.splitlines()
    force_field = ForceField("test")
    topology = Topology(force_field)
    read_topology(lines=lines, topology=topology, cwdir="./")
    topology.preprocess()
    topology.volumes = {"GLY": 0.53, "GLU": 0.67, "ASP": 0.43}
    return topology