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
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"]
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}
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
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)
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
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)])