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)
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)