From 59c9827eaca359d2639af6707c4cfcc3cd76ba57 Mon Sep 17 00:00:00 2001 From: csbrasnett Date: Wed, 9 Oct 2024 18:10:47 +0200 Subject: [PATCH] added test for file coming from itp --- polyply/src/apply_modifications.py | 2 +- polyply/tests/test_apply_modifications.py | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/polyply/src/apply_modifications.py b/polyply/src/apply_modifications.py index 50184a09..84d39ca5 100644 --- a/polyply/src/apply_modifications.py +++ b/polyply/src/apply_modifications.py @@ -75,7 +75,7 @@ def apply_mod(meta_molecule, modifications): target_residue = meta_molecule.nodes[target_resid - 1] # takes care to skip all residues that come from an itp file - if not target_residue.get('from_itp', 'False'): + if target_residue.get('from_itp'): LOGGER.info("meta_molecule has come from itp. Will not attempt to modify.") continue # checks that the resname is a protein resname as defined above diff --git a/polyply/tests/test_apply_modifications.py b/polyply/tests/test_apply_modifications.py index 694ebdfa..1a54069e 100644 --- a/polyply/tests/test_apply_modifications.py +++ b/polyply/tests/test_apply_modifications.py @@ -26,6 +26,7 @@ import polyply.src.ff_parser_sub import networkx as nx from vermouth.molecule import Interaction +from polyply.src.meta_molecule import MetaMolecule @pytest.mark.parametrize('input_mods, expected',( @@ -142,6 +143,36 @@ def test_apply_mod(input_itp, molname, expected, caplog, text): meta=interaction.meta) assert _interaction in meta_mol.molecule.interactions[interaction_type] +def test_from_itp(caplog): + + caplog.set_level(logging.INFO) + #make the meta molecule from the itp and ff files + file_name = TEST_DATA / "itp" / "ALA5.itp" + + ff = vermouth.forcefield.ForceField(name='martini3') + + ff_lines = [] + for file in ['aminoacids.ff', 'modifications.ff']: + with open(TEST_DATA/ "ff" / file) as f: + ff_lines += f.readlines() + polyply.src.ff_parser_sub.read_ff(ff_lines, ff) + + meta_mol = MetaMolecule.from_itp(ff, file_name, "pALA") + + for node in meta_mol.nodes: + meta_mol.nodes[node]['from_itp'] = 'True' + + termini = _patch_protein_termini(meta_mol) + apply_mod(meta_mol, termini) + + expected_msg = "meta_molecule has come from itp. Will not attempt to modify." + for record in caplog.records: + if record.message == expected_msg: + assert True + break + else: + continue + @pytest.mark.parametrize('modifications, expected, text', ( (