예제 #1
0
def test_unkown_fromat_error():
    with pytest.raises(IOError):
        ff = vermouth.forcefield.ForceField(name='test_ff')
        test_path = Path("random_file.extension")
        MetaMolecule.from_sequence_file(force_field=ff,
                                        file_path=test_path,
                                        mol_name="test")
예제 #2
0
def example_system():
    """
    Create a dummy test system with three types of molecules AA, BB and
    NA. NA is the molecule to be used a ligand. AA and BB are composed
    of different residues.
    """
    # dummy vermouth force-field
    force_field = vermouth.forcefield.ForceField(name='test_ff')
    # monomers used in the meta-molecule
    ALA = Monomer(resname="ALA", n_blocks=2)
    GLU = Monomer(resname="GLU", n_blocks=1)
    THR = Monomer(resname="THR", n_blocks=1)
    # two meta-molecules
    meta_mol_A = MetaMolecule.from_monomer_seq_linear(force_field,
                                                      [ALA, GLU, THR],
                                                      "AA")
    meta_mol_B = MetaMolecule.from_monomer_seq_linear(force_field,
                                                      [GLU, ALA, THR],
                                                      "BB")
    NA = MetaMolecule()
    NA.add_monomer(current=0, resname="NA", connections=[])
    molecules = [meta_mol_A, meta_mol_A.copy(),
                 meta_mol_B.copy(), NA, NA.copy(),
                 NA.copy(), NA.copy()]
    top = Topology(force_field=force_field)
    top.molecules = molecules
    top.mol_idx_by_name = {"AA":[0, 1], "BB": [2], "NA":[3, 4, 5, 6]}
    return top
예제 #3
0
    def test_from_seq_file(file_name, edges, nodes, attrs):
        ff = vermouth.forcefield.ForceField(name='test_ff')
        name = "test"
        meta_mol = MetaMolecule.from_sequence_file(ff, Path(file_name), name)

        assert len(nx.get_node_attributes(meta_mol, "resid")) == len(nodes)
        assert set(meta_mol.nodes) == set(nodes)
        assert set(meta_mol.edges) == set(edges)
예제 #4
0
    def test_from_monomer_seq_linear(monomers, edges, nodes, attrs):
        ff = vermouth.forcefield.ForceField(name='test_ff')
        name = "test"
        meta_mol = MetaMolecule.from_monomer_seq_linear(ff, monomers, name)

        assert nx.get_node_attributes(meta_mol, "resname") == attrs
        assert list(meta_mol.nodes) == nodes
        assert list(meta_mol.edges) == edges
예제 #5
0
 def test_get_edge_resname():
     ff = vermouth.forcefield.ForceField(name='test_ff')
     meta_mol = MetaMolecule(name="test", force_field=ff)
     meta_mol.add_monomer(0, "PEO", [])
     meta_mol.add_monomer(1, "PEO", [(1, 0)])
     name = meta_mol.get_edge_resname((1, 0))
     assert name == ["PEO", "PEO"]
예제 #6
0
    def test_from_json(file_name, edges, nodes, attrs):
        ff = vermouth.forcefield.ForceField(name='test_ff')
        name = "test"
        meta_mol = MetaMolecule.from_json(ff, file_name, name)

        #assert nx.get_node_attributes(meta_mol, "resname") == attrs
        print(meta_mol.edges)
        assert set(meta_mol.nodes) == set(nodes)
        assert set(meta_mol.edges) == set(edges)
예제 #7
0
def test_molecule():
    # dummy vermouth force-field
    force_field = vermouth.forcefield.ForceField(name='test_ff')
    # monomers used in the meta-molecule
    ALA = Monomer(resname="ALA", n_blocks=4)
    GLU = Monomer(resname="GLU", n_blocks=2)
    THR = Monomer(resname="THR", n_blocks=3)
    # two meta-molecules
    mol = MetaMolecule.from_monomer_seq_linear(force_field, [ALA, GLU, THR],
                                               "AA")
    return mol
예제 #8
0
    def test_from_itp():
        file_name = TEST_DATA + "/itp/PEO.itp"
        edges = [(0, 1), (1, 2)]
        nodes = [0, 1, 2]
        attrs = {0: 'PEO', 1: 'PEO', 2: 'PEO'}

        ff = vermouth.forcefield.ForceField(name='test_ff')
        name = "PEO"
        meta_mol = MetaMolecule.from_itp(ff, file_name, name)

        assert set(meta_mol.nodes) == set(nodes)
        assert set(meta_mol.edges) == set(edges)
예제 #9
0
    def test_add_blocks():
        lines = """
        [ moleculetype ]
        ; name nexcl.
        PEO         1
        ;
        [ atoms ]
        1  SN1a    1   PEO   CO1  1   0.000  45
        2  SN1a    1   PEO   CO2  1   0.000  45
        3  SN1a    1   PEO   CO3  1   0.000  45
        4  SN1a    1   PEO   CO4  1   0.000  45
        [ bonds ]
        ; back bone bonds
        1  2   1   0.37 7000
        2  3   1   0.37 7000
        2  4   1   0.37 7000
        4  5   1   0.37 7000
        """
        lines = textwrap.dedent(lines).splitlines()
        ff = vermouth.forcefield.ForceField(name='test_ff')
        polyply.src.polyply_parser.read_polyply(lines, ff)
        meta_mol = MetaMolecule(name="test", force_field=ff)
        meta_mol.add_monomer(0,"PEO",[])
        meta_mol.add_monomer(1,"PEO",[(1,0)])
        new_meta_mol = polyply.src.map_to_molecule.MapToMolecule().run_molecule(meta_mol)

        bonds = [Interaction(atoms=(0, 1), parameters=['1', '0.37', '7000'], meta={}),
                 Interaction(atoms=(1, 2), parameters=['1', '0.37', '7000'], meta={}),
                 Interaction(atoms=(1, 3), parameters=['1', '0.37', '7000'], meta={}),
                 Interaction(atoms=(4, 5), parameters=['1', '0.37', '7000'], meta={}),
                 Interaction(atoms=(5, 6), parameters=['1', '0.37', '7000'], meta={}),
                 Interaction(atoms=(5, 7), parameters=['1', '0.37', '7000'], meta={})]

        assert new_meta_mol.molecule.interactions['bonds'] == bonds
예제 #10
0
    def test_multi_excl_block():
        lines = """
        [ moleculetype ]
        ; name nexcl.
        PEO         1
        ;
        [ atoms ]
        1  SN1a    1   PEO   CO1  1   0.000  45
        [ moleculetype ]
        ; name nexcl.
        MIX         2
        ;
        [ atoms ]
        1  SN1a    1   MIX  C1  1   0.000  45
        2  SN1a    1   MIX  C2  1   0.000  45
        3  SC1     1   MIX  C1  2   0.000  45
        4  SC1     1   MIX  C2  2   0.000  45
        [ bonds ]
        ; back bone bonds
        1  2   1   0.37 7000
        2  3   1   0.37 7000
        3  4   1   0.37 7000
        """
        lines = textwrap.dedent(lines).splitlines()
        ff = vermouth.forcefield.ForceField(name='test_ff')
        polyply.src.polyply_parser.read_polyply(lines, ff)
        meta_mol = MetaMolecule(name="test", force_field=ff)
        meta_mol.add_monomer(0,"PEO",[])
        meta_mol.add_monomer(1,"MIX",[(1,0)])

        new_meta_mol = polyply.src.map_to_molecule.MapToMolecule().run_molecule(meta_mol)
        assert nx.get_node_attributes(new_meta_mol.molecule, "exclude") == {0: 1, 1: 2, 2: 2, 3: 2, 4: 2}
예제 #11
0
    def test_from_block():
        file_name = TEST_DATA + "/itp/PEO.itp"
        edges = [(0, 1), (1, 2)]
        nodes = [0, 1, 2]
        attrs = {0: 'PEO', 1: 'PEO', 2: 'PEO'}

        ff = vermouth.forcefield.ForceField(name='test_ff')
        name = "PEO"
        with open(file_name, "r") as _file:
            lines = _file.readlines()
        read_itp(lines, ff)
        meta_mol = MetaMolecule.from_block(ff, name)

        assert set(meta_mol.nodes) == set(nodes)
        assert set(meta_mol.edges) == set(edges)
예제 #12
0
    def test_get_links(lines, ref_ids):
        lines = textwrap.dedent(lines).splitlines()
        force_field = vermouth.forcefield.ForceField(name='test_ff')
        vermouth.ffinput.read_ff(lines, force_field)
        meta_mol = MetaMolecule.from_monomer_seq_linear(
            force_field, [Monomer(resname="PEO", n_blocks=5)], "test")
        polyply.src.map_to_molecule.MapToMolecule().run_molecule(meta_mol)

        resids = []
        for edge in meta_mol.edges:
            _, ids = polyply.src.apply_links._get_links(meta_mol, edge)
            resids += ids
        assert len(resids) == len(ref_ids)
        for resid in ids:
            assert resid in ref_ids
예제 #13
0
    def test_add_monomer():
        ff = vermouth.forcefield.ForceField(name='test_ff')
        meta_mol = MetaMolecule(name="test", force_field=ff)
        meta_mol.add_monomer(0, "PEO", [])
        meta_mol.add_monomer(1, "PEO", [(1, 0)])

        assert nx.get_node_attributes(meta_mol, "resname") == {
            0: 'PEO',
            1: 'PEO'
        }
        assert list(meta_mol.nodes) == [0, 1]
        assert list(meta_mol.edges) == [(0, 1)]
def test_riase_multiresidue_error(lines, monomers, bonds, edges, nnodes, from_itp):
    """
    When a single node in the meta_molecule corresponds to a multiresidue block
    but is not labelled with from_itp an error should be raised.
    """
    lines = textwrap.dedent(lines).splitlines()
    ff = vermouth.forcefield.ForceField(name='test_ff')
    polyply.src.polyply_parser.read_polyply(lines, ff)
    # build the meta-molecule
    meta_mol = MetaMolecule(name="test", force_field=ff)
    meta_mol.add_monomer(0, monomers[0], [])
    for node, monomer in enumerate(monomers[1:]):
        meta_mol.add_monomer(node+1, monomer, [(node, node+1)])
    nx.set_node_attributes(meta_mol, from_itp, "from_itp")
    with pytest.raises(IOError):
        new_meta_mol = polyply.src.map_to_molecule.MapToMolecule(ff).run_molecule(meta_mol)
예제 #15
0
    def test_multiresidue_block():
        lines = """
        [ moleculetype ]
        ; name nexcl.
        PEO         1
        ;
        [ atoms ]
        1  SN1a    1   PEO   CO1  1   0.000  45
        [ moleculetype ]
        ; name nexcl.
        MIX         1
        ;
        [ atoms ]
        1  SN1a    1   R1   C1  1   0.000  45
        2  SN1a    1   R1   C2  1   0.000  45
        3  SC1     2   R2   C1  2   0.000  45
        4  SC1     2   R2   C2  2   0.000  45
        [ bonds ]
        ; back bone bonds
        1  2   1   0.37 7000
        2  3   1   0.37 7000
        3  4   1   0.37 7000
        """
        lines = textwrap.dedent(lines).splitlines()
        ff = vermouth.forcefield.ForceField(name='test_ff')
        polyply.src.polyply_parser.read_polyply(lines, ff)
        meta_mol = MetaMolecule(name="test", force_field=ff)
        meta_mol.add_monomer(0,"PEO",[])
        meta_mol.add_monomer(1,"MIX",[(1,0)])

        new_meta_mol = polyply.src.map_to_molecule.MapToMolecule().run_molecule(meta_mol)

        bonds = [Interaction(atoms=(1, 2), parameters=['1', '0.37', '7000'], meta={}),
                 Interaction(atoms=(2, 3), parameters=['1', '0.37', '7000'], meta={}),
                 Interaction(atoms=(3, 4), parameters=['1', '0.37', '7000'], meta={})]

        edges = [(0,1), (1,2)]

        assert new_meta_mol.molecule.interactions['bonds'] == bonds
        assert len(new_meta_mol.nodes) == 3
        assert list(new_meta_mol.edges) == edges
        assert nx.get_node_attributes(new_meta_mol, "resname") == {0: "PEO", 1: "R1", 2: "R2"}
def test_multiresidue_block(lines, monomers, bonds, edges, nnodes, from_itp):
    """
    Test multiresidue blocks are correctly identified and parameters from
    the blocks added at the correct place in the fine-grained molecule.
    """
    lines = textwrap.dedent(lines).splitlines()
    ff = vermouth.forcefield.ForceField(name='test_ff')
    polyply.src.polyply_parser.read_polyply(lines, ff)
    # build the meta-molecule
    meta_mol = MetaMolecule(name="test", force_field=ff)
    meta_mol.add_monomer(0, monomers[0], [])
    for node, monomer in enumerate(monomers[1:]):
        meta_mol.add_monomer(node+1, monomer, [(node, node+1)])
    nx.set_node_attributes(meta_mol, from_itp, "from_itp")
    # map to molecule
    new_meta_mol = polyply.src.map_to_molecule.MapToMolecule(ff).run_molecule(meta_mol)
    # check that the disconnected molecule is properly done
    #print(new_meta_mol.nodes)
    for node in new_meta_mol.nodes:
        assert len(new_meta_mol.nodes[node]['graph'].nodes) != 0

    assert len(new_meta_mol.molecule.nodes) == nnodes
    assert list(new_meta_mol.molecule.edges) == edges
    assert new_meta_mol.molecule.interactions['bonds'] == bonds
예제 #17
0
 def test_add_monomer_fail():
     ff = vermouth.forcefield.ForceField(name='test_ff')
     meta_mol = MetaMolecule(name="test", force_field=ff)
     meta_mol.add_monomer(0, "PEO", [])
     with pytest.raises(IOError):
         meta_mol.add_monomer(1, "PEO", [(1, 8)])
예제 #18
0
 def test_resid_assignment_error():
     ff = vermouth.forcefield.ForceField(name='test_ff')
     plain_graph = nx.Graph()
     plain_graph.add_edges_from([("A", "B"), ("B", "C"), ("C", "D")])
     with pytest.raises(IOError):
         MetaMolecule(plain_graph, force_field=ff, mol_name="test")
예제 #19
0
def example_meta_molecule():
    """
    Example molecule with three residues each with
    different attributes for testing the assignment
    of links.

    Names:
    -------
    BB - BB1 - BB - BB1 - BB2 - BB - BB1
          |          |                |
         SC1        SC1              SC1
          |          |                |
         SC2        SC2              SC2

    Nodes:
    ------
     0  - 1    4  - 5 - 6   9 - 10
          |         |           |
          2         7           11
          |         |           |
          3         8           12
    """
    force_field = vermouth.forcefield.ForceField("test")
    block_A = Block(force_field=force_field)
    block_A.add_nodes_from([(0, {
        'resid': 1,
        'atomname': 'BB',
        'atype': 'A',
        'charge': 0.0,
        'other': 'A',
        'resname': 'A'
    }),
                            (1, {
                                'resid': 1,
                                'atomname': 'BB1',
                                'atype': 'B',
                                'charge': 0.0,
                                'other': 'A',
                                'resname': 'A'
                            }),
                            (2, {
                                'resid': 1,
                                'atomname': 'SC1',
                                'atype': 'C',
                                'charge': 0.0,
                                'other': 'A',
                                'resname': 'A'
                            }),
                            (3, {
                                'resid': 1,
                                'atomname': 'SC2',
                                'atype': 'D',
                                'charge': 1.0,
                                'other': 'A',
                                'resname': 'A'
                            })])
    block_A.add_edges_from([(0, 1), (1, 2), (2, 3)])

    block_B = Block(force_field=force_field)
    block_B.add_nodes_from([(0, {
        'resid': 1,
        'atomname': 'BB',
        'atype': 'A',
        'charge': 0.0,
        'resname': 'B'
    }),
                            (1, {
                                'resid': 1,
                                'atomname': 'BB1',
                                'atype': 'B',
                                'charge': 0.0,
                                'resname': 'B'
                            }),
                            (2, {
                                'resid': 1,
                                'atomname': 'BB2',
                                'atype': 'A',
                                'charge': 0.0,
                                'resname': 'B'
                            }),
                            (3, {
                                'resid': 1,
                                'atomname': 'SC1',
                                'atype': 'A',
                                'charge': -0.5,
                                'resname': 'B'
                            }),
                            (4, {
                                'resid': 1,
                                'atomname': 'SC2',
                                'atype': 'C',
                                'charge': 0.5,
                                'resname': 'B'
                            })])
    block_B.add_edges_from([(0, 1), (1, 2), (2, 3), (1, 4)])

    molecule = block_A.to_molecule()
    molecule.merge_molecule(block_B)
    molecule.merge_molecule(block_A)
    molecule.add_edges_from([(1, 4), (6, 9)])

    graph = MetaMolecule._block_graph_to_res_graph(molecule)
    meta_mol = MetaMolecule(graph, force_field=force_field, mol_name="test")
    meta_mol.molecule = molecule
    return meta_mol