From 3f8bcb67e100ba96b4137af7f9b7ed947b5218f8 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 14:06:06 +0200 Subject: [PATCH 01/18] change deprecated pkg_resources to importlib --- polyply/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/polyply/__init__.py b/polyply/__init__.py index 9ef7d384..d3d1b783 100644 --- a/polyply/__init__.py +++ b/polyply/__init__.py @@ -19,16 +19,23 @@ # Find the data directory once. try: - import pkg_resources + import importlib.resources import files, as_file + import atexit + from contextlib import ExitStack except ImportError: import os DATA_PATH = os.path.join(os.path.dirname(__file__), 'data') TEST_DATA = os.path.join(os.path.dirname(__file__), 'tests/test_data') del os else: - DATA_PATH = pkg_resources.resource_filename('polyply', 'data') - TEST_DATA = pkg_resources.resource_filename('polyply', 'tests/test_data') - del pkg_resources + ref_data = files('polyply') / 'data' + ref_test = files('polyply') / 'test' + file_manager = ExitStack() + atexit.register(file_manager.close) + DATA_PATH = file_manager.enter_context(as_file(ref_data)) + TEST_DATA = file_manager.enter_context(as_file(ref_test)) + + del files, as_file, atexit, ExitStack del pbr From ed4a1d05b5a28b345d949842d0ea9b36400fbf73 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 14:10:17 +0200 Subject: [PATCH 02/18] fix typo --- polyply/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyply/__init__.py b/polyply/__init__.py index d3d1b783..f8e0603c 100644 --- a/polyply/__init__.py +++ b/polyply/__init__.py @@ -19,7 +19,7 @@ # Find the data directory once. try: - import importlib.resources import files, as_file + from importlib.resources import files, as_file import atexit from contextlib import ExitStack except ImportError: From f9580ebfde9bc893526a2cfb2db38ce5f777c691 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:06:38 +0200 Subject: [PATCH 03/18] use API of gen_params instead of argparse --- polyply/tests/test_gen_params.py | 153 ++++++++++++++----------------- 1 file changed, 68 insertions(+), 85 deletions(-) diff --git a/polyply/tests/test_gen_params.py b/polyply/tests/test_gen_params.py index 5a76f719..7f7a698a 100644 --- a/polyply/tests/test_gen_params.py +++ b/polyply/tests/test_gen_params.py @@ -25,99 +25,82 @@ from polyply.src.graph_utils import find_missing_edges from polyply.src.logging import LOGGER -class TestGenParams(): - @staticmethod - @pytest.mark.parametrize('args_in, ref_file', ( - (["-f", TEST_DATA + "/gen_params/input/PEO.martini.3.itp" - ,"-seq", "PEO:10", "-name", "PEO", "-o", - TEST_DATA + "/gen_params/output/PEO_out.itp"], - TEST_DATA + "/gen_params/ref/PEO_10.itp"), - (["-f", TEST_DATA + "/gen_params/input/PS.martini.2.itp", - "-seqf", TEST_DATA + "/gen_params/input/PS.json", - "-name", "PS", - "-o", TEST_DATA + "/gen_params/output/PS_out.itp"] - , - TEST_DATA + "/gen_params/ref/PS_10.itp"), - (["-f", TEST_DATA + "/gen_params/input/P3HT.martini.2.itp", - "-seq", "P3HT:10", - "-name", "P3HT", - "-o", TEST_DATA + "/gen_params/output/P3HT_out.itp"], - TEST_DATA + "/gen_params/ref/P3HT_10.itp"), - (["-f", TEST_DATA + "/gen_params/input/PPI.ff", - "-seqf", TEST_DATA + "/gen_params/input/PPI.json", - "-name", "PPI", - "-o", TEST_DATA + "/gen_params/output/PPI_out.itp"], - TEST_DATA + "/gen_params/ref/G3.itp"), - (["-f", TEST_DATA + "/gen_params/input/test.ff", - "-seq", "N1:1", "N2:1", "N1:1", "N2:1", "N3:1", - "-name", "test", - "-o", TEST_DATA + "/gen_params/output/test_out.itp"], - TEST_DATA + "/gen_params/ref/test_rev.itp"), - # check if edge attributes are parsed and properly applied - (["-f", TEST_DATA+"/gen_params/input/test_edge_attr.ff", - "-seqf", TEST_DATA + "/gen_params/input/test_edge_attr.json", - "-name", "test", - "-o", TEST_DATA + "/gen_params/output/test_edge_attr_out.itp"], - TEST_DATA + "/gen_params/ref/test_edge_attr_ref.itp"), - # check if nodes can be removed - (["-f", TEST_DATA+"/gen_params/input/removal.ff", - "-seq", "PEO:3", - "-name", "test", - "-o", TEST_DATA + "/gen_params/output/removal.itp"], - TEST_DATA + "/gen_params/ref/removal.itp") - )) - def test_gen_params(args_in, ref_file): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter, - ) - parser.add_argument('-name', required=True, type=str, dest="name", - help="name of the final molecule") - file_group = parser.add_argument_group('Input and output files') - file_group.add_argument('-f', dest='inpath', required=False, type=Path, - help='Input file (ITP|FF)', nargs="*") - file_group.add_argument('-o', dest='outpath', type=Path, - help='Output ITP (ITP)') - file_group.add_argument('-seq', dest='seq', required=False, nargs='+', - type=str, help='linear sequence') - file_group.add_argument('-seqf', dest='seq_file', required=False, type=Path, - help='linear sequence') - ff_group = parser.add_argument_group('Force field selection') - ff_group.add_argument('-lib', dest='lib', required=False, type=str, - help='force-fields to include from library', nargs='*') - dna_group = parser.add_argument_group('DNA specifc options') - dna_group.add_argument('-dsdna', dest='dsdna', action='store_true', - help='complement single sequence to dsDNA sequence') +@pytest.mark.parametrize('inpath, seq, seqf, name, outpath, ref_file', ( + ([TEST_DATA / "gen_params/input/PEO.martini.3.itp"], + ["PEO:10"], + None, + "PEO", + TEST_DATA / "gen_params/output/PEO_out.itp", + TEST_DATA / "gen_params/ref/PEO_10.itp"), + ([TEST_DATA / "gen_params/input/PS.martini.2.itp"], + None, + TEST_DATA / "gen_params/input/PS.json", + "PS", + TEST_DATA / "gen_params/output/PS_out.itp", + TEST_DATA / "gen_params/ref/PS_10.itp"), + ([TEST_DATA / "gen_params/input/P3HT.martini.2.itp"], + ["P3HT:10"], + None, + "P3HT", + TEST_DATA / "gen_params/output/P3HT_out.itp", + TEST_DATA / "gen_params/ref/P3HT_10.itp"), + ([TEST_DATA / "gen_params/input/PPI.ff"], + None, + TEST_DATA / "gen_params/input/PPI.json", + "PPI", + TEST_DATA / "gen_params/output/PPI_out.itp", + TEST_DATA / "gen_params/ref/G3.itp"), + ([TEST_DATA / "gen_params/input/test.ff"], + ["N1:1", "N2:1", "N1:1", "N2:1", "N3:1"], + None, + "test", + TEST_DATA / "gen_params/output/test_out.itp", + TEST_DATA / "gen_params/ref/test_rev.itp"), + # check if edge attributes are parsed and properly applied + ([TEST_DATA / "gen_params/input/test_edge_attr.ff"], + None, + TEST_DATA / "gen_params/input/test_edge_attr.json", + "test", + TEST_DATA / "gen_params/output/test_edge_attr_out.itp", + TEST_DATA / "gen_params/ref/test_edge_attr_ref.itp"), + # check if nodes can be removed + ([TEST_DATA / "gen_params/input/removal.ff"], + ["PEO:3"], + None, + "test", + TEST_DATA / "gen_params/output/removal.itp", + TEST_DATA / "gen_params/ref/removal.itp") + )) +def test_gen_params(inpath, seq, seqf, name, outpath, ref_file): + gen_params(inpath=inpath, seq=seq, seq_file=seqf, name=name, outpath=outpath) - args = parser.parse_args(args_in) - gen_params(**vars(args)) + force_field = vermouth.forcefield.ForceField(name='test_ff') - force_field = vermouth.forcefield.ForceField(name='test_ff') + for path_name in [outpath, ref_file]: + with open(path_name, 'r') as _file: + lines = _file.readlines() + vermouth.gmx.itp_read.read_itp(lines, force_field) - for path_name in [args.outpath, ref_file]: - with open(path_name, 'r') as _file: - lines = _file.readlines() - vermouth.gmx.itp_read.read_itp(lines, force_field) + ref_name = name + "ref" - ref_name = args.name + "ref" + #1. Check that all nodes and attributes are the same + assert set(force_field.blocks[ref_name].nodes) == set(force_field.blocks[name].nodes) + for node in force_field.blocks[ref_name].nodes: + ref_attrs = nx.get_node_attributes(force_field.blocks[ref_name], node) + new_attrs = nx.get_node_attributes(force_field.blocks[name], node) + assert new_attrs == ref_attrs - #1. Check that all nodes and attributes are the same - assert set(force_field.blocks[ref_name].nodes) == set(force_field.blocks[args.name].nodes) - for node in force_field.blocks[ref_name].nodes: - ref_attrs = nx.get_node_attributes(force_field.blocks[ref_name], node) - new_attrs = nx.get_node_attributes(force_field.blocks[args.name], node) - assert new_attrs == ref_attrs + #2. Check that all interactions are the same + int_types_ref = force_field.blocks[ref_name].interactions.keys() + int_types_new = force_field.blocks[name].interactions.keys() + assert int_types_ref == int_types_new - #2. Check that all interactions are the same - int_types_ref = force_field.blocks[ref_name].interactions.keys() - int_types_new = force_field.blocks[args.name].interactions.keys() - assert int_types_ref == int_types_new - - for key in force_field.blocks[ref_name].interactions: - for term in force_field.blocks[ref_name].interactions[key]: - assert term in force_field.blocks[args.name].interactions[key] + for key in force_field.blocks[ref_name].interactions: + for term in force_field.blocks[ref_name].interactions[key]: + assert term in force_field.blocks[name].interactions[key] def test_find_missing_links(): - fname = TEST_DATA + "/gen_params/ref/P3HT_10.itp" + fname = TEST_DATA / "gen_params/ref/P3HT_10.itp" ff = vermouth.forcefield.ForceField("test") meta_mol = MetaMolecule.from_itp(ff, fname, "P3HTref") meta_mol.molecule.remove_edge(39, 45) # resid 7,8 From 33ec27f0dfe8163a3e3bc7fd1808e6a9df52257d Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:10:17 +0200 Subject: [PATCH 04/18] use pathlib in case importlib fails --- polyply/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/polyply/__init__.py b/polyply/__init__.py index f8e0603c..26f37a1f 100644 --- a/polyply/__init__.py +++ b/polyply/__init__.py @@ -23,10 +23,10 @@ import atexit from contextlib import ExitStack except ImportError: - import os - DATA_PATH = os.path.join(os.path.dirname(__file__), 'data') - TEST_DATA = os.path.join(os.path.dirname(__file__), 'tests/test_data') - del os + from pathlib import Path + DATA_PATH = Path(__file__).parent / 'data' + TEST_DATA = Path(__file__).parent / 'tests/test_data') + del Path else: ref_data = files('polyply') / 'data' ref_test = files('polyply') / 'test' From 90f6dca717b240c4db4f89aeee85587717dac484 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:10:46 +0200 Subject: [PATCH 05/18] fix typo --- polyply/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyply/__init__.py b/polyply/__init__.py index 26f37a1f..faa563db 100644 --- a/polyply/__init__.py +++ b/polyply/__init__.py @@ -25,7 +25,7 @@ except ImportError: from pathlib import Path DATA_PATH = Path(__file__).parent / 'data' - TEST_DATA = Path(__file__).parent / 'tests/test_data') + TEST_DATA = Path(__file__).parent / 'tests/test_data' del Path else: ref_data = files('polyply') / 'data' From 9b734acf448f8cc39973e6178b9ea7ef4a69bff7 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:12:28 +0200 Subject: [PATCH 06/18] update tests meta molecule to use TEST_DATA as Path --- polyply/tests/test_meta_molecule.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/polyply/tests/test_meta_molecule.py b/polyply/tests/test_meta_molecule.py index 492cb69f..f1f024d2 100644 --- a/polyply/tests/test_meta_molecule.py +++ b/polyply/tests/test_meta_molecule.py @@ -94,26 +94,26 @@ def test_from_monomer_seq_linear(monomers, edges, nodes, attrs): @staticmethod @pytest.mark.parametrize('file_name, edges, nodes, attrs', ( # multiple blocks from single monomer - (TEST_DATA + "/json/linear.json", + (TEST_DATA / "json/linear.json", [(0,1), (1,2)], [0,1,2], {0: 'PEO', 1: 'PEO', 2: 'PEO'} ), # two blocks from two monomers - (TEST_DATA + "/json/single_branch.json", + (TEST_DATA / "json/single_branch.json", [(1,2),(2,3),(3,4),(2,5)], [1,2,3,4,5], {1: 'PEO', 2: 'PEO', 3: 'PS', 4: 'PS', 5:'PEO'} ), # two blocks from two monomers - (TEST_DATA + "/json/double_branch.json", + (TEST_DATA / "json/double_branch.json", [(1,2),(2,3),(2,4),(4,5),(5,6),(5,8),(6,7)], [1,2,3,4,5,6,7,8], {1: 'PEO', 2: 'PEO', 3: 'PS', 4: 'PEO', 5:'PEO', 6: 'PS', 7: 'PS', 8: 'PEO'} ), # Hyperbranched - (TEST_DATA + "/json/hyperbranched.json", + (TEST_DATA / "json/hyperbranched.json", [(0, 1), (0, 2), (0, 3), (1, 4), (1, 5), (2, 6), (2, 7), (3, 8), (3, 9), (4, 10), (4, 11), (5, 12), (5, 13)], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], @@ -121,7 +121,7 @@ def test_from_monomer_seq_linear(monomers, edges, nodes, attrs): 7: 'N1', 8: 'N2', 9: 'N3', 10: 'N3', 11: 'N2', 12: 'N3', 13: 'N3'} ), # check that ordering is restored - (TEST_DATA + "/json/linear_rev.json", + (TEST_DATA / "json/linear_rev.json", [(0, 1), (1, 2)], [0, 1, 2], {0: 'PEO', 1: 'PEO', 2: 'PEO'} @@ -130,7 +130,7 @@ def test_from_monomer_seq_linear(monomers, edges, nodes, attrs): 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) + meta_mol = MetaMolecule.from_sequence_file(ff, file_name, name) assert len(nx.get_node_attributes(meta_mol, "resid")) == len(nodes) assert set(meta_mol.nodes) == set(nodes) @@ -146,7 +146,7 @@ def test_resid_assignment_error(): @staticmethod def test_from_itp(): - file_name = TEST_DATA + "/itp/PEO.itp" + file_name = TEST_DATA / "itp/PEO.itp" edges = [(0,1), (1,2)] nodes = [0, 1, 2] attrs = {0: 'PEO', 1: 'PEO', 2: 'PEO'} @@ -160,7 +160,7 @@ def test_from_itp(): @staticmethod def test_from_block(): - file_name = TEST_DATA + "/itp/PEO.itp" + file_name = TEST_DATA / "itp/PEO.itp" edges = [(0,1), (1,2)] nodes = [0, 1, 2] attrs = {0: 'PEO', 1: 'PEO', 2: 'PEO'} From ccb9ec4325e4785f43e01dfacb98592d47876b17 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:18:04 +0200 Subject: [PATCH 07/18] only write temp files with standard name for testing gen_params --- .../test_data/gen_params/output/P3HT_out.itp | 241 ------------- .../test_data/gen_params/output/PEO_out.itp | 78 ----- .../test_data/gen_params/output/PPI_out.itp | 41 --- .../test_data/gen_params/output/PS_out.itp | 320 ------------------ .../test_data/gen_params/output/removal.itp | 20 -- .../gen_params/output/test_edge_attr_out.itp | 64 ---- .../test_data/gen_params/output/test_out.itp | 23 -- polyply/tests/test_gen_params.py | 15 +- 8 files changed, 4 insertions(+), 798 deletions(-) delete mode 100644 polyply/tests/test_data/gen_params/output/P3HT_out.itp delete mode 100644 polyply/tests/test_data/gen_params/output/PEO_out.itp delete mode 100644 polyply/tests/test_data/gen_params/output/PPI_out.itp delete mode 100644 polyply/tests/test_data/gen_params/output/PS_out.itp delete mode 100644 polyply/tests/test_data/gen_params/output/removal.itp delete mode 100644 polyply/tests/test_data/gen_params/output/test_edge_attr_out.itp delete mode 100644 polyply/tests/test_data/gen_params/output/test_out.itp diff --git a/polyply/tests/test_data/gen_params/output/P3HT_out.itp b/polyply/tests/test_data/gen_params/output/P3HT_out.itp deleted file mode 100644 index d02b73c1..00000000 --- a/polyply/tests/test_data/gen_params/output/P3HT_out.itp +++ /dev/null @@ -1,241 +0,0 @@ -; /coarse/fabian/current-projects/polymer_itp_builder/vermouth_dev/venvv/bin/pytest test_gen_params.py - -; Please cite the following papers: - -[ moleculetype ] -P3HT 1 - -[ atoms ] - 1 SC5 1 P3HT S1 1 0.0 45.0 - 2 SC5 1 P3HT C2 2 0.0 45.0 - 3 SC5 1 P3HT C3 3 0.0 45.0 - 4 VS 1 P3HT V4 4 0.0 0.0 - 5 SC3 1 P3HT C5 5 0.0 45.0 - 6 SC3 1 P3HT C6 6 0.0 45.0 - 7 SC5 2 P3HT S1 7 0.0 45.0 - 8 SC5 2 P3HT C2 8 0.0 45.0 - 9 SC5 2 P3HT C3 9 0.0 45.0 -10 VS 2 P3HT V4 10 0.0 0.0 -11 SC3 2 P3HT C5 11 0.0 45.0 -12 SC3 2 P3HT C6 12 0.0 45.0 -13 SC5 3 P3HT S1 13 0.0 45.0 -14 SC5 3 P3HT C2 14 0.0 45.0 -15 SC5 3 P3HT C3 15 0.0 45.0 -16 VS 3 P3HT V4 16 0.0 0.0 -17 SC3 3 P3HT C5 17 0.0 45.0 -18 SC3 3 P3HT C6 18 0.0 45.0 -19 SC5 4 P3HT S1 19 0.0 45.0 -20 SC5 4 P3HT C2 20 0.0 45.0 -21 SC5 4 P3HT C3 21 0.0 45.0 -22 VS 4 P3HT V4 22 0.0 0.0 -23 SC3 4 P3HT C5 23 0.0 45.0 -24 SC3 4 P3HT C6 24 0.0 45.0 -25 SC5 5 P3HT S1 25 0.0 45.0 -26 SC5 5 P3HT C2 26 0.0 45.0 -27 SC5 5 P3HT C3 27 0.0 45.0 -28 VS 5 P3HT V4 28 0.0 0.0 -29 SC3 5 P3HT C5 29 0.0 45.0 -30 SC3 5 P3HT C6 30 0.0 45.0 -31 SC5 6 P3HT S1 31 0.0 45.0 -32 SC5 6 P3HT C2 32 0.0 45.0 -33 SC5 6 P3HT C3 33 0.0 45.0 -34 VS 6 P3HT V4 34 0.0 0.0 -35 SC3 6 P3HT C5 35 0.0 45.0 -36 SC3 6 P3HT C6 36 0.0 45.0 -37 SC5 7 P3HT S1 37 0.0 45.0 -38 SC5 7 P3HT C2 38 0.0 45.0 -39 SC5 7 P3HT C3 39 0.0 45.0 -40 VS 7 P3HT V4 40 0.0 0.0 -41 SC3 7 P3HT C5 41 0.0 45.0 -42 SC3 7 P3HT C6 42 0.0 45.0 -43 SC5 8 P3HT S1 43 0.0 45.0 -44 SC5 8 P3HT C2 44 0.0 45.0 -45 SC5 8 P3HT C3 45 0.0 45.0 -46 VS 8 P3HT V4 46 0.0 0.0 -47 SC3 8 P3HT C5 47 0.0 45.0 -48 SC3 8 P3HT C6 48 0.0 45.0 -49 SC5 9 P3HT S1 49 0.0 45.0 -50 SC5 9 P3HT C2 50 0.0 45.0 -51 SC5 9 P3HT C3 51 0.0 45.0 -52 VS 9 P3HT V4 52 0.0 0.0 -53 SC3 9 P3HT C5 53 0.0 45.0 -54 SC3 9 P3HT C6 54 0.0 45.0 -55 SC5 10 P3HT S1 55 0.0 45.0 -56 SC5 10 P3HT C2 56 0.0 45.0 -57 SC5 10 P3HT C3 57 0.0 45.0 -58 VS 10 P3HT V4 58 0.0 0.0 -59 SC3 10 P3HT C5 59 0.0 45.0 -60 SC3 10 P3HT C6 60 0.0 45.0 - -[ bonds ] - 5 6 1 0.360 5000 -11 12 1 0.360 5000 -17 18 1 0.360 5000 -23 24 1 0.360 5000 -29 30 1 0.360 5000 -35 36 1 0.360 5000 -41 42 1 0.360 5000 -47 48 1 0.360 5000 -53 54 1 0.360 5000 -59 60 1 0.360 5000 - 4 10 1 0.380 50000 -10 16 1 0.380 50000 -16 22 1 0.380 50000 -22 28 1 0.380 50000 -28 34 1 0.380 50000 -34 40 1 0.380 50000 -40 46 1 0.380 50000 -46 52 1 0.380 50000 -52 58 1 0.380 50000 - -[ constraints ] - 1 2 1 0.240 - 1 3 1 0.240 - 2 3 1 0.240 - 3 5 1 0.285 - 7 8 1 0.240 - 7 9 1 0.240 - 8 9 1 0.240 - 9 11 1 0.285 -13 14 1 0.240 -13 15 1 0.240 -14 15 1 0.240 -15 17 1 0.285 -19 20 1 0.240 -19 21 1 0.240 -20 21 1 0.240 -21 23 1 0.285 -25 26 1 0.240 -25 27 1 0.240 -26 27 1 0.240 -27 29 1 0.285 -31 32 1 0.240 -31 33 1 0.240 -32 33 1 0.240 -33 35 1 0.285 -37 38 1 0.240 -37 39 1 0.240 -38 39 1 0.240 -39 41 1 0.285 -43 44 1 0.240 -43 45 1 0.240 -44 45 1 0.240 -45 47 1 0.285 -49 50 1 0.240 -49 51 1 0.240 -50 51 1 0.240 -51 53 1 0.285 -55 56 1 0.240 -55 57 1 0.240 -56 57 1 0.240 -57 59 1 0.285 - -[ angles ] - 1 3 5 2 180 250 - 3 5 6 1 155 25 - 7 9 11 2 180 250 - 9 11 12 1 155 25 -13 15 17 2 180 250 -15 17 18 1 155 25 -19 21 23 2 180 250 -21 23 24 1 155 25 -25 27 29 2 180 250 -27 29 30 1 155 25 -31 33 35 2 180 250 -33 35 36 1 155 25 -37 39 41 2 180 250 -39 41 42 1 155 25 -43 45 47 2 180 250 -45 47 48 1 155 25 -49 51 53 2 180 250 -51 53 54 1 155 25 -55 57 59 2 180 250 -57 59 60 1 155 25 - 2 3 10 1 160 180 - 8 9 16 1 160 180 -14 15 22 1 160 180 -20 21 28 1 160 180 -26 27 34 1 160 180 -32 33 40 1 160 180 -38 39 46 1 160 180 -44 45 52 1 160 180 -50 51 58 1 160 180 - 4 8 9 1 160 180 -10 14 15 1 160 180 -16 20 21 1 160 180 -22 26 27 1 160 180 -28 32 33 1 160 180 -34 38 39 1 160 180 -40 44 45 1 160 180 -46 50 51 1 160 180 -52 56 57 1 160 180 - 4 10 16 1 158 180 -10 16 22 1 158 180 -16 22 28 1 158 180 -22 28 34 1 158 180 -28 34 40 1 158 180 -34 40 46 1 158 180 -40 46 52 1 158 180 -46 52 58 1 158 180 - -[ dihedrals ] - 1 4 10 7 9 0.0 1.8 1 - 1 4 10 7 9 0.0 -9.5 2 - 7 10 16 13 9 0.0 1.8 1 - 7 10 16 13 9 0.0 -9.5 2 -13 16 22 19 9 0.0 1.8 1 -13 16 22 19 9 0.0 -9.5 2 -19 22 28 25 9 0.0 1.8 1 -19 22 28 25 9 0.0 -9.5 2 -25 28 34 31 9 0.0 1.8 1 -25 28 34 31 9 0.0 -9.5 2 -31 34 40 37 9 0.0 1.8 1 -31 34 40 37 9 0.0 -9.5 2 -37 40 46 43 9 0.0 1.8 1 -37 40 46 43 9 0.0 -9.5 2 -43 46 52 49 9 0.0 1.8 1 -43 46 52 49 9 0.0 -9.5 2 -49 52 58 55 9 0.0 1.8 1 -49 52 58 55 9 0.0 -9.5 2 - -[ exclusions ] - 1 7 8 9 - 7 13 14 15 -13 19 20 21 -19 25 26 27 -25 31 32 33 -31 37 38 39 -37 43 44 45 -43 49 50 51 -49 55 56 57 - 2 7 8 9 - 8 13 14 15 -14 19 20 21 -20 25 26 27 -26 31 32 33 -32 37 38 39 -38 43 44 45 -44 49 50 51 -50 55 56 57 - 3 7 8 9 - 9 13 14 15 -15 19 20 21 -21 25 26 27 -27 31 32 33 -33 37 38 39 -39 43 44 45 -45 49 50 51 -51 55 56 57 - -[ virtual_sitesn ] - 4 2 1 2 3 -10 2 7 8 9 -16 2 13 14 15 -22 2 19 20 21 -28 2 25 26 27 -34 2 31 32 33 -40 2 37 38 39 -46 2 43 44 45 -52 2 49 50 51 -58 2 55 56 57 - diff --git a/polyply/tests/test_data/gen_params/output/PEO_out.itp b/polyply/tests/test_data/gen_params/output/PEO_out.itp deleted file mode 100644 index 9ff56220..00000000 --- a/polyply/tests/test_data/gen_params/output/PEO_out.itp +++ /dev/null @@ -1,78 +0,0 @@ -; /coarse/fabian/current-projects/polymer_itp_builder/vermouth_dev/venvv/bin/pytest test_gen_params.py - -; Please cite the following papers: - -[ moleculetype ] -PEO 1 - -[ atoms ] - 1 SN1a 1 PEO EO 1 0.0 45.0 - 2 SN1a 2 PEO EO 2 0.0 45.0 - 3 SN1a 3 PEO EO 3 0.0 45.0 - 4 SN1a 4 PEO EO 4 0.0 45.0 - 5 SN1a 5 PEO EO 5 0.0 45.0 - 6 SN1a 6 PEO EO 6 0.0 45.0 - 7 SN1a 7 PEO EO 7 0.0 45.0 - 8 SN1a 8 PEO EO 8 0.0 45.0 - 9 SN1a 9 PEO EO 9 0.0 45.0 -10 SN1a 10 PEO EO 10 0.0 45.0 - -[ bonds ] - 1 2 1 0.37 7000 - 2 3 1 0.37 7000 - 3 4 1 0.37 7000 - 4 5 1 0.37 7000 - 5 6 1 0.37 7000 - 6 7 1 0.37 7000 - 7 8 1 0.37 7000 - 8 9 1 0.37 7000 - 9 10 1 0.37 7000 - -[ angles ] - 1 2 3 2 135.00 50 - 1 2 3 10 135.00 75 - 2 3 4 2 135.00 50 - 2 3 4 10 135.00 75 - 3 4 5 2 135.00 50 - 3 4 5 10 135.00 75 - 4 5 6 2 135.00 50 - 4 5 6 10 135.00 75 - 5 6 7 2 135.00 50 - 5 6 7 10 135.00 75 - 6 7 8 2 135.00 50 - 6 7 8 10 135.00 75 - 7 8 9 2 135.00 50 - 7 8 9 10 135.00 75 - 8 9 10 2 135.00 50 - 8 9 10 10 135.00 75 - -[ dihedrals ] - 1 2 3 4 1 180.00 1.96 1 - 1 2 3 4 1 0 0.18 2 - 1 2 3 4 1 0 0.33 3 - 1 2 3 4 1 0 0.12 4 - 2 3 4 5 1 180.00 1.96 1 - 2 3 4 5 1 0 0.18 2 - 2 3 4 5 1 0 0.33 3 - 2 3 4 5 1 0 0.12 4 - 3 4 5 6 1 180.00 1.96 1 - 3 4 5 6 1 0 0.18 2 - 3 4 5 6 1 0 0.33 3 - 3 4 5 6 1 0 0.12 4 - 4 5 6 7 1 180.00 1.96 1 - 4 5 6 7 1 0 0.18 2 - 4 5 6 7 1 0 0.33 3 - 4 5 6 7 1 0 0.12 4 - 5 6 7 8 1 180.00 1.96 1 - 5 6 7 8 1 0 0.18 2 - 5 6 7 8 1 0 0.33 3 - 5 6 7 8 1 0 0.12 4 - 6 7 8 9 1 180.00 1.96 1 - 6 7 8 9 1 0 0.18 2 - 6 7 8 9 1 0 0.33 3 - 6 7 8 9 1 0 0.12 4 - 7 8 9 10 1 180.00 1.96 1 - 7 8 9 10 1 0 0.18 2 - 7 8 9 10 1 0 0.33 3 - 7 8 9 10 1 0 0.12 4 - diff --git a/polyply/tests/test_data/gen_params/output/PPI_out.itp b/polyply/tests/test_data/gen_params/output/PPI_out.itp deleted file mode 100644 index 68d0a041..00000000 --- a/polyply/tests/test_data/gen_params/output/PPI_out.itp +++ /dev/null @@ -1,41 +0,0 @@ -; /coarse/fabian/current-projects/polymer_itp_builder/vermouth_dev/venvv/bin/pytest test_gen_params.py - -; Please cite the following papers: - -[ moleculetype ] -PPI 1 - -[ atoms ] - 1 N1 1 N1 BB 1 0.0 - 2 N1 2 N1 BB 2 0.0 - 3 N2 3 N2 BB 3 0.0 - 4 N2 4 N2 BB 4 0.0 - 5 N2 5 N2 BB 5 0.0 - 6 N2 6 N2 BB 6 0.0 - 7 N3 7 N3 BB 7 0.0 - 8 N3 8 N3 BB 8 0.0 - 9 N3 9 N3 BB 9 0.0 -10 N3 10 N3 BB 10 0.0 -11 N3 11 N3 BB 11 0.0 -12 N3 12 N3 BB 12 0.0 -13 N3 13 N3 BB 13 0.0 -14 N3 14 N3 BB 14 0.0 - -[ bonds ] -; inner - 2 5 1 0.350 1250 - 1 2 1 0.350 1250 - 1 3 1 0.350 1250 - 1 4 1 0.350 1250 - 2 6 1 0.350 1250 - -; outer - 3 7 1 0.250 1250 - 3 8 1 0.250 1250 - 4 9 1 0.250 1250 - 4 10 1 0.250 1250 - 5 11 1 0.250 1250 - 5 12 1 0.250 1250 - 6 13 1 0.250 1250 - 6 14 1 0.250 1250 - diff --git a/polyply/tests/test_data/gen_params/output/PS_out.itp b/polyply/tests/test_data/gen_params/output/PS_out.itp deleted file mode 100644 index b7701178..00000000 --- a/polyply/tests/test_data/gen_params/output/PS_out.itp +++ /dev/null @@ -1,320 +0,0 @@ -; /coarse/fabian/current-projects/polymer_itp_builder/vermouth_dev/venvv/bin/pytest test_gen_params.py - -; Please cite the following papers: - -[ moleculetype ] -PS 1 - -[ atoms ] - 1 STY 1 PS R1 1 0.0 45.0 - 2 STY 1 PS R2 2 0.0 45.0 - 3 STY 1 PS R3 3 0.0 45.0 - 4 SCY 1 PS B 4 0.0 45.0 - 5 STY 2 PS R1 5 0.0 45.0 - 6 STY 2 PS R2 6 0.0 45.0 - 7 STY 2 PS R3 7 0.0 45.0 - 8 SCY 2 PS B 8 0.0 45.0 - 9 STY 3 PS R1 9 0.0 45.0 -10 STY 3 PS R2 10 0.0 45.0 -11 STY 3 PS R3 11 0.0 45.0 -12 SCY 3 PS B 12 0.0 45.0 -13 STY 4 PS R1 13 0.0 45.0 -14 STY 4 PS R2 14 0.0 45.0 -15 STY 4 PS R3 15 0.0 45.0 -16 SCY 4 PS B 16 0.0 45.0 -17 STY 5 PS R1 17 0.0 45.0 -18 STY 5 PS R2 18 0.0 45.0 -19 STY 5 PS R3 19 0.0 45.0 -20 SCY 5 PS B 20 0.0 45.0 -21 STY 6 PS R1 21 0.0 45.0 -22 STY 6 PS R2 22 0.0 45.0 -23 STY 6 PS R3 23 0.0 45.0 -24 SCY 6 PS B 24 0.0 45.0 -25 STY 7 PS R1 25 0.0 45.0 -26 STY 7 PS R2 26 0.0 45.0 -27 STY 7 PS R3 27 0.0 45.0 -28 SCY 7 PS B 28 0.0 45.0 -29 STY 8 PS R1 29 0.0 45.0 -30 STY 8 PS R2 30 0.0 45.0 -31 STY 8 PS R3 31 0.0 45.0 -32 SCY 8 PS B 32 0.0 45.0 -33 STY 9 PS R1 33 0.0 45.0 -34 STY 9 PS R2 34 0.0 45.0 -35 STY 9 PS R3 35 0.0 45.0 -36 SCY 9 PS B 36 0.0 45.0 -37 STY 10 PS R1 37 0.0 45.0 -38 STY 10 PS R2 38 0.0 45.0 -39 STY 10 PS R3 39 0.0 45.0 -40 SCY 10 PS B 40 0.0 45.0 - -[ bonds ] - 1 4 1 0.270000 8000.000000 - 5 8 1 0.270000 8000.000000 - 9 12 1 0.270000 8000.000000 -13 16 1 0.270000 8000.000000 -17 20 1 0.270000 8000.000000 -21 24 1 0.270000 8000.000000 -25 28 1 0.270000 8000.000000 -29 32 1 0.270000 8000.000000 -33 36 1 0.270000 8000.000000 -37 40 1 0.270000 8000.000000 - 4 5 1 0.270000 8000.000000 - 8 9 1 0.270000 8000.000000 -12 13 1 0.270000 8000.000000 -16 17 1 0.270000 8000.000000 -20 21 1 0.270000 8000.000000 -24 25 1 0.270000 8000.000000 -28 29 1 0.270000 8000.000000 -32 33 1 0.270000 8000.000000 -36 37 1 0.270000 8000.000000 - -[ constraints ] - 2 3 1 0.270000 - 3 1 1 0.270000 - 1 2 1 0.270000 - 6 7 1 0.270000 - 7 5 1 0.270000 - 5 6 1 0.270000 -10 11 1 0.270000 -11 9 1 0.270000 - 9 10 1 0.270000 -14 15 1 0.270000 -15 13 1 0.270000 -13 14 1 0.270000 -18 19 1 0.270000 -19 17 1 0.270000 -17 18 1 0.270000 -22 23 1 0.270000 -23 21 1 0.270000 -21 22 1 0.270000 -26 27 1 0.270000 -27 25 1 0.270000 -25 26 1 0.270000 -30 31 1 0.270000 -31 29 1 0.270000 -29 30 1 0.270000 -34 35 1 0.270000 -35 33 1 0.270000 -33 34 1 0.270000 -38 39 1 0.270000 -39 37 1 0.270000 -37 38 1 0.270000 - -[ exclusions ] - 1 2 - 1 3 - 1 4 - 2 3 - 2 4 - 3 4 - 5 6 - 5 7 - 5 8 - 6 7 - 6 8 - 7 8 - 9 10 - 9 11 - 9 12 -10 11 -10 12 -11 12 -13 14 -13 15 -13 16 -14 15 -14 16 -15 16 -17 18 -17 19 -17 20 -18 19 -18 20 -19 20 -21 22 -21 23 -21 24 -22 23 -22 24 -23 24 -25 26 -25 27 -25 28 -26 27 -26 28 -27 28 -29 30 -29 31 -29 32 -30 31 -30 32 -31 32 -33 34 -33 35 -33 36 -34 35 -34 36 -35 36 -37 38 -37 39 -37 40 -38 39 -38 40 -39 40 - 1 5 - 5 9 - 9 13 -13 17 -17 21 -21 25 -25 29 -29 33 -33 37 - 1 6 - 5 10 - 9 14 -13 18 -17 22 -21 26 -25 30 -29 34 -33 38 - 1 7 - 5 11 - 9 15 -13 19 -17 23 -21 27 -25 31 -29 35 -33 39 - 1 8 - 5 12 - 9 16 -13 20 -17 24 -21 28 -25 32 -29 36 -33 40 - 2 5 - 6 9 -10 13 -14 17 -18 21 -22 25 -26 29 -30 33 -34 37 - 3 5 - 7 9 -11 13 -15 17 -19 21 -23 25 -27 29 -31 33 -35 37 - 4 5 - 8 9 -12 13 -16 17 -20 21 -24 25 -28 29 -32 33 -36 37 - 4 6 - 8 10 -12 14 -16 18 -20 22 -24 26 -28 30 -32 34 -36 38 - 4 7 - 8 11 -12 15 -16 19 -20 23 -24 27 -28 31 -32 35 -36 39 - 4 8 - 8 12 -12 16 -16 20 -20 24 -24 28 -28 32 -32 36 -36 40 - 4 9 - 8 13 -12 17 -16 21 -20 25 -24 29 -28 33 -32 37 - -[ angles ] - 4 1 2 1 136.000000 100.000000 - 4 1 3 1 136.000000 100.000000 - 8 5 6 1 136.000000 100.000000 - 8 5 7 1 136.000000 100.000000 -12 9 10 1 136.000000 100.000000 -12 9 11 1 136.000000 100.000000 -16 13 14 1 136.000000 100.000000 -16 13 15 1 136.000000 100.000000 -20 17 18 1 136.000000 100.000000 -20 17 19 1 136.000000 100.000000 -24 21 22 1 136.000000 100.000000 -24 21 23 1 136.000000 100.000000 -28 25 26 1 136.000000 100.000000 -28 25 27 1 136.000000 100.000000 -32 29 30 1 136.000000 100.000000 -32 29 31 1 136.000000 100.000000 -36 33 34 1 136.000000 100.000000 -36 33 35 1 136.000000 100.000000 -40 37 38 1 136.000000 100.000000 -40 37 39 1 136.000000 100.000000 - 4 5 6 1 136.000000 100.000000 - 8 9 10 1 136.000000 100.000000 -12 13 14 1 136.000000 100.000000 -16 17 18 1 136.000000 100.000000 -20 21 22 1 136.000000 100.000000 -24 25 26 1 136.000000 100.000000 -28 29 30 1 136.000000 100.000000 -32 33 34 1 136.000000 100.000000 -36 37 38 1 136.000000 100.000000 - 4 5 7 1 136.000000 100.000000 - 8 9 11 1 136.000000 100.000000 -12 13 15 1 136.000000 100.000000 -16 17 19 1 136.000000 100.000000 -20 21 23 1 136.000000 100.000000 -24 25 27 1 136.000000 100.000000 -28 29 31 1 136.000000 100.000000 -32 33 35 1 136.000000 100.000000 -36 37 39 1 136.000000 100.000000 - 1 4 5 1 120.000000 25.000000 - 5 8 9 1 120.000000 25.000000 - 9 12 13 1 120.000000 25.000000 -13 16 17 1 120.000000 25.000000 -17 20 21 1 120.000000 25.000000 -21 24 25 1 120.000000 25.000000 -25 28 29 1 120.000000 25.000000 -29 32 33 1 120.000000 25.000000 -33 36 37 1 120.000000 25.000000 - 4 5 8 1 52.000000 550.000000 - 8 9 12 1 52.000000 550.000000 -12 13 16 1 52.000000 550.000000 -16 17 20 1 52.000000 550.000000 -20 21 24 1 52.000000 550.000000 -24 25 28 1 52.000000 550.000000 -28 29 32 1 52.000000 550.000000 -32 33 36 1 52.000000 550.000000 -36 37 40 1 52.000000 550.000000 - diff --git a/polyply/tests/test_data/gen_params/output/removal.itp b/polyply/tests/test_data/gen_params/output/removal.itp deleted file mode 100644 index 69c2c5fd..00000000 --- a/polyply/tests/test_data/gen_params/output/removal.itp +++ /dev/null @@ -1,20 +0,0 @@ -; /Users/fabian/ProgramDev/dev_env/bin/pytest test_gen_params.py - -; Please cite the following papers: - -[ moleculetype ] -test 1 - -[ atoms ] -1 SN1a 1 PEO EO 1 0.0 45.0 -2 SN2a 1 PEO EP 1 0.0 45.0 -3 SN1a 2 PEO EO 2 0.0 45.0 -4 SN2a 2 PEO EP 2 0.0 45.0 -5 SN1a 3 PEO EO 3 0.0 45.0 - -[ bonds ] -1 2 1 0.44 7000 -3 4 1 0.44 7000 -2 3 1 0.37 7000 -4 5 1 0.37 7000 - diff --git a/polyply/tests/test_data/gen_params/output/test_edge_attr_out.itp b/polyply/tests/test_data/gen_params/output/test_edge_attr_out.itp deleted file mode 100644 index 61ba8ac8..00000000 --- a/polyply/tests/test_data/gen_params/output/test_edge_attr_out.itp +++ /dev/null @@ -1,64 +0,0 @@ -; /coarse/fabian/current-projects/polymer_itp_builder/vermouth_dev/venvv/bin/pytest test_gen_params.py - -; Please cite the following papers: - -[ moleculetype ] -test 3 - -[ atoms ] - 1 SP3 1 GLC A 1 0.0 - 2 SP3 1 GLC B 2 0.0 - 3 SP1 1 GLC C 3 0.0 - 4 TP3 2 GLC A 4 0.0 - 5 SP2 2 GLC B 5 0.0 - 6 SP1 2 GLC C 6 0.0 - 7 TP3 3 GLC A 7 0.0 - 8 SP3 3 GLC B 8 0.0 - 9 SP2 3 GLC C 9 0.0 -10 TP3 4 GLC A 10 0.0 -11 SP3 4 GLC B 11 0.0 -12 SP1 4 GLC C 12 0.0 -13 TP3 5 GLC A 13 0.0 -14 SP2 5 GLC B 14 0.0 -15 SP1 5 GLC C 15 0.0 -16 TP3 6 GLC A 16 0.0 -17 SP3 6 GLC B 17 0.0 -18 SP2 6 GLC C 18 0.0 -19 TP3 7 GLC A 19 0.0 -20 SP3 7 GLC B 20 0.0 -21 SP2 7 GLC C 21 0.0 - -[ bonds ] -; a13 - 5 7 1 0.32 5500 -14 19 1 0.32 5500 - -; a16 - 3 4 1 0.37 6500 - 6 10 1 0.37 6500 -12 13 1 0.37 6500 -15 16 1 0.37 6500 - -[ constraints ] - 1 2 1 0.336 - 1 3 1 0.311 - 2 3 1 0.405 - 4 5 1 0.336 - 4 6 1 0.311 - 5 6 1 0.405 - 7 8 1 0.336 - 7 9 1 0.311 - 8 9 1 0.405 -10 11 1 0.336 -10 12 1 0.311 -11 12 1 0.405 -13 14 1 0.336 -13 15 1 0.311 -14 15 1 0.405 -16 17 1 0.336 -16 18 1 0.311 -17 18 1 0.405 -19 20 1 0.336 -19 21 1 0.311 -20 21 1 0.405 - diff --git a/polyply/tests/test_data/gen_params/output/test_out.itp b/polyply/tests/test_data/gen_params/output/test_out.itp deleted file mode 100644 index 46b33e94..00000000 --- a/polyply/tests/test_data/gen_params/output/test_out.itp +++ /dev/null @@ -1,23 +0,0 @@ -; /coarse/fabian/current-projects/polymer_itp_builder/vermouth_dev/venvv/bin/pytest test_gen_params.py - -; Please cite the following papers: - -[ moleculetype ] -test 1 - -[ atoms ] -1 N1 1 N1 BB 1 0.0 -2 N2 2 N2 BB 2 0.0 -3 N1 3 N1 BB 3 0.0 -4 N2 4 N2 BB 4 0.0 -5 N3 5 N3 BB 5 0.0 - -[ bonds ] -; inner -1 2 1 0.350 1250 -2 3 1 0.350 1250 -3 4 1 0.350 1250 - -; outer -4 5 1 0.250 1250 - diff --git a/polyply/tests/test_gen_params.py b/polyply/tests/test_gen_params.py index 7f7a698a..29ba733d 100644 --- a/polyply/tests/test_gen_params.py +++ b/polyply/tests/test_gen_params.py @@ -25,58 +25,51 @@ from polyply.src.graph_utils import find_missing_edges from polyply.src.logging import LOGGER -@pytest.mark.parametrize('inpath, seq, seqf, name, outpath, ref_file', ( +@pytest.mark.parametrize('inpath, seq, seqf, name, ref_file', ( ([TEST_DATA / "gen_params/input/PEO.martini.3.itp"], ["PEO:10"], None, "PEO", - TEST_DATA / "gen_params/output/PEO_out.itp", TEST_DATA / "gen_params/ref/PEO_10.itp"), ([TEST_DATA / "gen_params/input/PS.martini.2.itp"], None, TEST_DATA / "gen_params/input/PS.json", "PS", - TEST_DATA / "gen_params/output/PS_out.itp", TEST_DATA / "gen_params/ref/PS_10.itp"), ([TEST_DATA / "gen_params/input/P3HT.martini.2.itp"], ["P3HT:10"], None, "P3HT", - TEST_DATA / "gen_params/output/P3HT_out.itp", TEST_DATA / "gen_params/ref/P3HT_10.itp"), ([TEST_DATA / "gen_params/input/PPI.ff"], None, TEST_DATA / "gen_params/input/PPI.json", "PPI", - TEST_DATA / "gen_params/output/PPI_out.itp", TEST_DATA / "gen_params/ref/G3.itp"), ([TEST_DATA / "gen_params/input/test.ff"], ["N1:1", "N2:1", "N1:1", "N2:1", "N3:1"], None, "test", - TEST_DATA / "gen_params/output/test_out.itp", TEST_DATA / "gen_params/ref/test_rev.itp"), # check if edge attributes are parsed and properly applied ([TEST_DATA / "gen_params/input/test_edge_attr.ff"], None, TEST_DATA / "gen_params/input/test_edge_attr.json", "test", - TEST_DATA / "gen_params/output/test_edge_attr_out.itp", TEST_DATA / "gen_params/ref/test_edge_attr_ref.itp"), # check if nodes can be removed ([TEST_DATA / "gen_params/input/removal.ff"], ["PEO:3"], None, "test", - TEST_DATA / "gen_params/output/removal.itp", TEST_DATA / "gen_params/ref/removal.itp") )) -def test_gen_params(inpath, seq, seqf, name, outpath, ref_file): - gen_params(inpath=inpath, seq=seq, seq_file=seqf, name=name, outpath=outpath) +def test_gen_params(inpath, seq, seqf, name, ref_file): + gen_params(inpath=inpath, seq=seq, seq_file=seqf, name=name) force_field = vermouth.forcefield.ForceField(name='test_ff') - for path_name in [outpath, ref_file]: + for path_name in [Path("polymer.itp"), ref_file]: with open(path_name, 'r') as _file: lines = _file.readlines() vermouth.gmx.itp_read.read_itp(lines, force_field) From 70a94ca97f2bc3a492195c32fbee65b558c548c7 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:20:44 +0200 Subject: [PATCH 08/18] run gen_param in tmp_dir --- polyply/tests/test_gen_params.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/polyply/tests/test_gen_params.py b/polyply/tests/test_gen_params.py index 29ba733d..d3bc5992 100644 --- a/polyply/tests/test_gen_params.py +++ b/polyply/tests/test_gen_params.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import os from pathlib import Path import textwrap import argparse @@ -64,12 +64,13 @@ "test", TEST_DATA / "gen_params/ref/removal.itp") )) -def test_gen_params(inpath, seq, seqf, name, ref_file): +def test_gen_params(tmp_path, inpath, seq, seqf, name, ref_file): + os.chdir(tmp_path) gen_params(inpath=inpath, seq=seq, seq_file=seqf, name=name) force_field = vermouth.forcefield.ForceField(name='test_ff') - for path_name in [Path("polymer.itp"), ref_file]: + for path_name in [tmp_path / "polymer.itp", ref_file]: with open(path_name, 'r') as _file: lines = _file.readlines() vermouth.gmx.itp_read.read_itp(lines, force_field) From 3ea84d3b1ab9ca7e6ef36c6d20454f4767fe2a33 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:43:36 +0200 Subject: [PATCH 09/18] update path usag in gen_seq test --- polyply/tests/test_gen_seq.py | 65 ++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/polyply/tests/test_gen_seq.py b/polyply/tests/test_gen_seq.py index d573e371..ac7324f5 100644 --- a/polyply/tests/test_gen_seq.py +++ b/polyply/tests/test_gen_seq.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os import json from pathlib import Path import networkx as nx @@ -168,36 +169,52 @@ def test_tag_nodes(tags, expected, seed): _tag_nodes(graph, tags, seed) assert nx.get_node_attributes(graph, "chiral") == expected -@pytest.mark.parametrize('args, ref_file', ( - (dict(outpath=TEST_DATA + "/gen_seq/output/PPI.json", - macro_strings=["A:3:2:N1-1.0"], - seq=["A", "A"], - name="test", - connects=["0:1:0-0"]), - TEST_DATA + "/gen_seq/ref/PPI_ref.json"), - (dict(outpath=TEST_DATA + "/gen_seq/output/PEO_PS.json", - macro_strings=["A:11:1:PEO-1", "B:11:1:PS-1"], - connects=["0:1:10-0"], - name="test", - seq=["A", "B"]), - TEST_DATA + "/gen_seq/ref/PEO_PS_ref.json"), - (dict(outpath=TEST_DATA + "/gen_seq/output/lysoPEG.json", - inpath=[Path(TEST_DATA + "/gen_seq/input/molecule_0.itp")], - macro_strings=["A:5:1:PEG-1.0"], - from_file=["PROT:molecule_0"], - name="test", - seq=["PROT", "A"], - connects=["0:1:0-0"]), - TEST_DATA + "/gen_seq/ref/lyso_PEG.json") +@pytest.mark.parametrize('inpath, macro_strings, seq, name, from_file, connects, ref_file', ( + ([], + ["A:3:2:N1-1.0"], + ["A", "A"], + "test", + None, + ["0:1:0-0"], + TEST_DATA / "gen_seq/ref/PPI_ref.json"), + ([], + ["A:11:1:PEO-1", "B:11:1:PS-1"], + ["A", "B"], + "test", + None, + ["0:1:10-0"], + TEST_DATA / "gen_seq/ref/PEO_PS_ref.json"), + ([Path(TEST_DATA / "gen_seq/input/molecule_0.itp")], + ["A:5:1:PEG-1.0"], + ["PROT", "A"], + "test", + ["PROT:molecule_0"], + ["0:1:0-0"], + TEST_DATA / "gen_seq/ref/lyso_PEG.json") )) -def test_gen_seq(args, ref_file): - gen_seq(**args) +def test_gen_seq(tmp_path, + inpath, + macro_strings, + seq, name, + from_file, + connects, + ref_file): + + os.chdir(tmp_path) + outpath = Path("new_seq.json") + gen_seq(inpath=inpath, + outpath=outpath, + macro_strings=macro_strings, + seq=seq, + name=name, + from_file=from_file, + connects=connects) with open(ref_file) as _file: js_graph = json.load(_file) ref_graph = json_graph.node_link_graph(js_graph) - with open(args["outpath"]) as _file: + with open(outpath) as _file: js_graph = json.load(_file) out_graph = json_graph.node_link_graph(js_graph) From d80ae30762022315bc56e3d9fb679ece0198d777 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:43:49 +0200 Subject: [PATCH 10/18] update path usage in test_lib_files --- polyply/tests/test_lib_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyply/tests/test_lib_files.py b/polyply/tests/test_lib_files.py index f296cc7e..5e0994a2 100644 --- a/polyply/tests/test_lib_files.py +++ b/polyply/tests/test_lib_files.py @@ -30,7 +30,7 @@ from polyply import TEST_DATA from vermouth.tests.helper_functions import find_in_path -INTEGRATION_DATA = Path(TEST_DATA + '/library_tests') +INTEGRATION_DATA = TEST_DATA / 'library_tests' PATTERN = '{path}/{library}/{polymer}/polyply' From 84066603b281078bb6f68c7cb9d5adb4342e3881 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:45:36 +0200 Subject: [PATCH 11/18] update path usage in test_topology --- polyply/tests/test_topology.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/polyply/tests/test_topology.py b/polyply/tests/test_topology.py index 19d0cb66..9af9d466 100644 --- a/polyply/tests/test_topology.py +++ b/polyply/tests/test_topology.py @@ -31,7 +31,7 @@ class TestTopology: @staticmethod def test_from_gmx_topfile(): - top = Topology.from_gmx_topfile(TEST_DATA+"/topology_test/system.top", "test") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") assert len(top.molecules) == 1 @staticmethod @@ -44,8 +44,8 @@ def test_add_positions_from_gro(): no coordinates defined and require the build and backmap attribute to be True. In all other cases they need to be False. """ - top = Topology.from_gmx_topfile(TEST_DATA + "/topology_test/system.top", "test") - top.add_positions_from_file(TEST_DATA + "/topology_test/test.gro") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") + top.add_positions_from_file(TEST_DATA / "topology_test/test.gro") # check that the box is correctly read assert np.allclose(top.box, np.array([10.0, 11.0, 12.0])) @@ -72,8 +72,8 @@ def test_add_meta_positions_from_gro(): have no coordinates defined at either level and require the build and backmap attribute to be True. In all other cases the build attribute is False and backmap is True. """ - top = Topology.from_gmx_topfile(TEST_DATA + "/topology_test/system.top", "test") - top.add_positions_from_file(TEST_DATA + "/topology_test/meta.gro", resolution="meta_mol") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") + top.add_positions_from_file(TEST_DATA / "topology_test/meta.gro", resolution="meta_mol") # check that the box is correctly read assert np.allclose(top.box, np.array([10.0, 11.0, 12.0])) @@ -95,13 +95,13 @@ def test_add_positions_from_pdb(): the meta_molecule positions are defined as well. In addition all build and backmap attributes have to be False. """ - top = Topology.from_gmx_topfile(TEST_DATA + "/topology_test/pdb.top", "test") - top.add_positions_from_file(TEST_DATA + "/topology_test/test.pdb") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/pdb.top", "test") + top.add_positions_from_file(TEST_DATA / "topology_test/test.pdb") # check that the box is correctly read assert np.allclose(top.box, np.array([11.8249, 12.0688, 11.0944])) - pdb_mols = read_pdb(TEST_DATA + "/topology_test/test.pdb") + pdb_mols = read_pdb(TEST_DATA / "topology_test/test.pdb") for idx, meta_mol in enumerate(top.molecules): for node in meta_mol.molecule.nodes: ref_pos = pdb_mols[idx].nodes[node]['position'] @@ -119,13 +119,13 @@ def test_add_positions_from_file_fail(): This test checks if coordinates for a residue at the molecule level are incomplete the appropiate error is raised. """ - top = Topology.from_gmx_topfile(TEST_DATA + "/topology_test/system.top", "test") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") with pytest.raises(IOError): - top.add_positions_from_file(TEST_DATA + "/topology_test/fail.gro") + top.add_positions_from_file(TEST_DATA / "topology_test/fail.gro") @staticmethod def test_convert_to_vermouth_system(): - top = Topology.from_gmx_topfile(TEST_DATA + "/topology_test/system.top", "test") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") system = top.convert_to_vermouth_system() assert isinstance(system, vermouth.system.System) assert len(system.molecules) == 1 From 87caf0ee3eae7a9438852e9ef0cafbd363472a6c Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:46:28 +0200 Subject: [PATCH 12/18] update path usage in test_simple_seq_parsers --- polyply/tests/test_simple_seq_parsers.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/polyply/tests/test_simple_seq_parsers.py b/polyply/tests/test_simple_seq_parsers.py index 1ae743c1..fb8c4635 100644 --- a/polyply/tests/test_simple_seq_parsers.py +++ b/polyply/tests/test_simple_seq_parsers.py @@ -96,14 +96,14 @@ def test_monomers_to_linear_nx_graph(example_meta_molecule): "fasta" )) def test_sequence_parses(extension): - filepath = Path(TEST_DATA + "/simple_seq_files/test."+ extension) + filepath = Path(TEST_DATA / "simple_seq_files/test."+ extension) seq_graph = MetaMolecule.parsers[extension](filepath) monomers = ["DA5", "DT", "DC", "DG", "DT", "DA", "DC", "DA", "DT3"] ref_graph = _monomers_to_linear_nx_graph(monomers) assert nx.is_isomorphic(seq_graph, ref_graph, node_match=_node_match) def test_ig_cirle(): - filepath = Path(TEST_DATA + "/simple_seq_files/test_circle.ig") + filepath = Path(TEST_DATA / "simple_seq_files/test_circle.ig") seq_graph = MetaMolecule.parsers["ig"](filepath) monomers = ["DA", "DT", "DC", "DG", "DT", "DA", "DC", "DA", "DT"] ref_graph = _monomers_to_linear_nx_graph(monomers) @@ -114,7 +114,7 @@ def test_ig_cirle(): node_match=_node_match) def test_ig_termination_fail(): - filepath = Path(TEST_DATA + "/simple_seq_files/test_fail.ig") + filepath = Path(TEST_DATA / "simple_seq_files/test_fail.ig") with pytest.raises(FileFormatError): seq_graph = MetaMolecule.parsers["ig"](filepath) @@ -123,14 +123,14 @@ def test_ig_termination_fail(): "fasta" )) def test_sequence_parses_RNA(extension): - filepath = Path(TEST_DATA + "/simple_seq_files/test_RNA."+ extension) + filepath = Path(TEST_DATA / "simple_seq_files/test_RNA."+ extension) seq_graph = MetaMolecule.parsers[extension](filepath) monomers = ["A5", "U", "C", "G", "U", "A", "C", "A", "U3"] ref_graph = _monomers_to_linear_nx_graph(monomers) assert nx.is_isomorphic(seq_graph, ref_graph, node_match=_node_match) def test_sequence_parses_PROTEIN(): - filepath = Path(TEST_DATA + "/simple_seq_files/test_protein.fasta") + filepath = Path(TEST_DATA / "simple_seq_files/test_protein.fasta") seq_graph = MetaMolecule.parsers["fasta"](filepath) monomers = ["GLY", "ALA", "LYS", "TRP", "ASN", "VAL", "PHE", "PRO", "SER"] ref_graph = _monomers_to_linear_nx_graph(monomers) @@ -144,7 +144,7 @@ def test_unkown_nucleotype_error(): def test_ig_warning(caplog): ref_msg = ("Found only the letters A, C, G, T on first line." " Are you missing the title line in your .ig file?") - filepath = Path(TEST_DATA + "/simple_seq_files/test_ig_warning.ig") + filepath = Path(TEST_DATA / "simple_seq_files/test_ig_warning.ig") with caplog.at_level(logging.WARNING): seq_graph = MetaMolecule.parsers["ig"](filepath) for record in caplog.records: From 830af578ecd5e430f8931689557cc673fd147bda Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:47:47 +0200 Subject: [PATCH 13/18] update path usage --- polyply/tests/test_gen_coords_logic.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/polyply/tests/test_gen_coords_logic.py b/polyply/tests/test_gen_coords_logic.py index a827e71f..3363f07c 100644 --- a/polyply/tests/test_gen_coords_logic.py +++ b/polyply/tests/test_gen_coords_logic.py @@ -32,8 +32,8 @@ def test_no_positions_generated(tmp_path, monkeypatch): errors and preserve all positions given in the input to rounding accuracy. """ monkeypatch.chdir(tmp_path) - top_file = TEST_DATA + "/topology_test/system.top" - pos_file = TEST_DATA + "/topology_test/complete.gro" + top_file = TEST_DATA / "topology_test/system.top" + pos_file = TEST_DATA / "topology_test/complete.gro" out_file = tmp_path / "out.gro" gen_coords(toppath=top_file, coordpath=pos_file, @@ -68,8 +68,8 @@ def test_box_input(tmp_path, caplog, box_input, box_ref, density, warning): "Will try to pack all molecules in the box " "provided with starting coordinates."),} - top_file = TEST_DATA + "/topology_test/system.top" - pos_file = TEST_DATA + "/topology_test/complete.gro" + top_file = TEST_DATA / "topology_test/system.top" + pos_file = TEST_DATA / "topology_test/complete.gro" out_file = tmp_path / "out.gro" with caplog.at_level(logging.WARNING): @@ -101,8 +101,8 @@ def test_backmap_only(tmp_path, monkeypatch): same as they have been put in. """ monkeypatch.chdir(tmp_path) - top_file = TEST_DATA + "/topology_test/system.top" - pos_file = TEST_DATA + "/topology_test/cog.gro" + top_file = TEST_DATA / "topology_test/system.top" + pos_file = TEST_DATA / "topology_test/cog.gro" out_file = tmp_path / "out.gro" gen_coords(toppath=top_file, coordpath_meta=pos_file, @@ -126,8 +126,8 @@ def test_backmap_only(tmp_path, monkeypatch): def test_warning_partial_metamol_coords(tmp_path, monkeypatch, caplog): caplog.set_level(logging.WARNING) - top_file = TEST_DATA + "/topology_test/system.top" - pos_file = TEST_DATA + "/topology_test/cog_missing.gro" + top_file = TEST_DATA / "topology_test/system.top" + pos_file = TEST_DATA / "topology_test/cog_missing.gro" out_file = tmp_path / "out.gro" with caplog.at_level(logging.WARNING): From 662d29edc947aff3c3055e1f0d2d61ba55eb3446 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:47:58 +0200 Subject: [PATCH 14/18] update path usage --- polyply/tests/test_generate_templates.py | 2 +- polyply/tests/test_random_walk.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/polyply/tests/test_generate_templates.py b/polyply/tests/test_generate_templates.py index ff4bd11f..bbe20911 100644 --- a/polyply/tests/test_generate_templates.py +++ b/polyply/tests/test_generate_templates.py @@ -178,7 +178,7 @@ def test_extract_block(): @staticmethod def test_run_molecule(): - top = polyply.src.topology.Topology.from_gmx_topfile(TEST_DATA + "/topology_test/system.top", "test") + top = polyply.src.topology.Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") top.gen_pairs() top.convert_nonbond_to_sig_eps() GenerateTemplates(topology=top, max_opt=10).run_molecule(top.molecules[0]) diff --git a/polyply/tests/test_random_walk.py b/polyply/tests/test_random_walk.py index f5e36cc1..3dfb0ba2 100644 --- a/polyply/tests/test_random_walk.py +++ b/polyply/tests/test_random_walk.py @@ -131,7 +131,7 @@ def test__take_step(): @pytest.fixture def nonbond_matrix(): - toppath = TEST_DATA + "/struc_build/system.top" + toppath = TEST_DATA / "struc_build/system.top" topology = Topology.from_gmx_topfile(name="test", path=toppath) topology.preprocess() topology.volumes = {"PEO":0.43} @@ -140,7 +140,7 @@ def nonbond_matrix(): box=np.array([10., 10., 10.])) @pytest.fixture def molecule(): - toppath = TEST_DATA + "/struc_build/system.top" + toppath = TEST_DATA / "struc_build/system.top" topology = Topology.from_gmx_topfile(name="test", path=toppath) return topology.molecules[0] From 87477677ef54a7ef616276c138eac7f3ea6396d6 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 15:52:18 +0200 Subject: [PATCH 15/18] fix path usage in simple_seq parse test --- polyply/tests/test_simple_seq_parsers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/polyply/tests/test_simple_seq_parsers.py b/polyply/tests/test_simple_seq_parsers.py index fb8c4635..87fd7433 100644 --- a/polyply/tests/test_simple_seq_parsers.py +++ b/polyply/tests/test_simple_seq_parsers.py @@ -96,7 +96,8 @@ def test_monomers_to_linear_nx_graph(example_meta_molecule): "fasta" )) def test_sequence_parses(extension): - filepath = Path(TEST_DATA / "simple_seq_files/test."+ extension) + part_path = "simple_seq_files/test." + extension + filepath = TEST_DATA / part_path seq_graph = MetaMolecule.parsers[extension](filepath) monomers = ["DA5", "DT", "DC", "DG", "DT", "DA", "DC", "DA", "DT3"] ref_graph = _monomers_to_linear_nx_graph(monomers) @@ -123,7 +124,8 @@ def test_ig_termination_fail(): "fasta" )) def test_sequence_parses_RNA(extension): - filepath = Path(TEST_DATA / "simple_seq_files/test_RNA."+ extension) + part_path = "simple_seq_files/test_RNA." + extension + filepath = TEST_DATA / part_path seq_graph = MetaMolecule.parsers[extension](filepath) monomers = ["A5", "U", "C", "G", "U", "A", "C", "A", "U3"] ref_graph = _monomers_to_linear_nx_graph(monomers) From e02bab771755fb4fdfea63114bf86765b2dd0577 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 16:01:24 +0200 Subject: [PATCH 16/18] fix path to test-data --- polyply/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyply/__init__.py b/polyply/__init__.py index faa563db..6615e635 100644 --- a/polyply/__init__.py +++ b/polyply/__init__.py @@ -29,7 +29,7 @@ del Path else: ref_data = files('polyply') / 'data' - ref_test = files('polyply') / 'test' + ref_test = files('polyply') / 'test/test_data' file_manager = ExitStack() atexit.register(file_manager.close) DATA_PATH = file_manager.enter_context(as_file(ref_data)) From 81332dd7746b609c799ad6c8d1e26fe432d11609 Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Thu, 5 Oct 2023 16:04:28 +0200 Subject: [PATCH 17/18] fix typo in path variable --- polyply/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polyply/__init__.py b/polyply/__init__.py index 6615e635..acc386b3 100644 --- a/polyply/__init__.py +++ b/polyply/__init__.py @@ -29,7 +29,7 @@ del Path else: ref_data = files('polyply') / 'data' - ref_test = files('polyply') / 'test/test_data' + ref_test = files('polyply') / 'tests/test_data' file_manager = ExitStack() atexit.register(file_manager.close) DATA_PATH = file_manager.enter_context(as_file(ref_data)) From 7520a329ef6496d350ed5b374635c41e430f5ebf Mon Sep 17 00:00:00 2001 From: Fabian Grunewald Date: Mon, 9 Oct 2023 15:32:35 +0200 Subject: [PATCH 18/18] fix partial paths in tests --- polyply/__init__.py | 2 +- polyply/tests/test_gen_coords_logic.py | 10 +++---- polyply/tests/test_gen_params.py | 36 ++++++++++++------------ polyply/tests/test_gen_seq.py | 8 +++--- polyply/tests/test_generate_templates.py | 2 +- polyply/tests/test_meta_molecule.py | 14 ++++----- polyply/tests/test_random_walk.py | 4 +-- polyply/tests/test_simple_seq_parsers.py | 10 +++---- polyply/tests/test_topology.py | 22 +++++++-------- 9 files changed, 54 insertions(+), 54 deletions(-) diff --git a/polyply/__init__.py b/polyply/__init__.py index acc386b3..7f7e4d1a 100644 --- a/polyply/__init__.py +++ b/polyply/__init__.py @@ -29,7 +29,7 @@ del Path else: ref_data = files('polyply') / 'data' - ref_test = files('polyply') / 'tests/test_data' + ref_test = files('polyply') / 'tests'/ 'test_data' file_manager = ExitStack() atexit.register(file_manager.close) DATA_PATH = file_manager.enter_context(as_file(ref_data)) diff --git a/polyply/tests/test_gen_coords_logic.py b/polyply/tests/test_gen_coords_logic.py index 3363f07c..c3e4546e 100644 --- a/polyply/tests/test_gen_coords_logic.py +++ b/polyply/tests/test_gen_coords_logic.py @@ -101,8 +101,8 @@ def test_backmap_only(tmp_path, monkeypatch): same as they have been put in. """ monkeypatch.chdir(tmp_path) - top_file = TEST_DATA / "topology_test/system.top" - pos_file = TEST_DATA / "topology_test/cog.gro" + top_file = TEST_DATA / "topology_test" / "system.top" + pos_file = TEST_DATA / "topology_test" / "cog.gro" out_file = tmp_path / "out.gro" gen_coords(toppath=top_file, coordpath_meta=pos_file, @@ -125,9 +125,9 @@ def test_backmap_only(tmp_path, monkeypatch): assert np.allclose(res_pos, ref_pos, atol=0.0009) def test_warning_partial_metamol_coords(tmp_path, monkeypatch, caplog): - caplog.set_level(logging.WARNING) - top_file = TEST_DATA / "topology_test/system.top" - pos_file = TEST_DATA / "topology_test/cog_missing.gro" + caplog.set_level(logging.WARNING) + top_file = TEST_DATA / "topology_test" / "system.top" + pos_file = TEST_DATA / "topology_test" / "cog_missing.gro" out_file = tmp_path / "out.gro" with caplog.at_level(logging.WARNING): diff --git a/polyply/tests/test_gen_params.py b/polyply/tests/test_gen_params.py index d3bc5992..bf4eee3d 100644 --- a/polyply/tests/test_gen_params.py +++ b/polyply/tests/test_gen_params.py @@ -26,43 +26,43 @@ from polyply.src.logging import LOGGER @pytest.mark.parametrize('inpath, seq, seqf, name, ref_file', ( - ([TEST_DATA / "gen_params/input/PEO.martini.3.itp"], + ([TEST_DATA / "gen_params" / "input" / "PEO.martini.3.itp"], ["PEO:10"], None, "PEO", - TEST_DATA / "gen_params/ref/PEO_10.itp"), - ([TEST_DATA / "gen_params/input/PS.martini.2.itp"], + TEST_DATA / "gen_params" / "ref" / "PEO_10.itp"), + ([TEST_DATA / "gen_params"/ "input"/"PS.martini.2.itp"], None, - TEST_DATA / "gen_params/input/PS.json", + TEST_DATA / "gen_params" / "input" / "PS.json", "PS", - TEST_DATA / "gen_params/ref/PS_10.itp"), - ([TEST_DATA / "gen_params/input/P3HT.martini.2.itp"], + TEST_DATA / "gen_params" / "ref" / "PS_10.itp"), + ([TEST_DATA / "gen_params" / "input" / "P3HT.martini.2.itp"], ["P3HT:10"], None, "P3HT", - TEST_DATA / "gen_params/ref/P3HT_10.itp"), - ([TEST_DATA / "gen_params/input/PPI.ff"], + TEST_DATA / "gen_params" / "ref" / "P3HT_10.itp"), + ([TEST_DATA / "gen_params" / "input" / "PPI.ff"], None, - TEST_DATA / "gen_params/input/PPI.json", + TEST_DATA / "gen_params" / "input" / "PPI.json", "PPI", - TEST_DATA / "gen_params/ref/G3.itp"), - ([TEST_DATA / "gen_params/input/test.ff"], + TEST_DATA / "gen_params" / "ref" / "G3.itp"), + ([TEST_DATA / "gen_params" / "input" / "test.ff"], ["N1:1", "N2:1", "N1:1", "N2:1", "N3:1"], None, "test", - TEST_DATA / "gen_params/ref/test_rev.itp"), + TEST_DATA / "gen_params" / "ref" / "test_rev.itp"), # check if edge attributes are parsed and properly applied - ([TEST_DATA / "gen_params/input/test_edge_attr.ff"], + ([TEST_DATA / "gen_params" / "input" / "test_edge_attr.ff"], None, - TEST_DATA / "gen_params/input/test_edge_attr.json", + TEST_DATA / "gen_params" / "input" / "test_edge_attr.json", "test", - TEST_DATA / "gen_params/ref/test_edge_attr_ref.itp"), + TEST_DATA / "gen_params" / "ref" / "test_edge_attr_ref.itp"), # check if nodes can be removed - ([TEST_DATA / "gen_params/input/removal.ff"], + ([TEST_DATA / "gen_params" / "input" / "removal.ff"], ["PEO:3"], None, "test", - TEST_DATA / "gen_params/ref/removal.itp") + TEST_DATA / "gen_params" / "ref" / "removal.itp") )) def test_gen_params(tmp_path, inpath, seq, seqf, name, ref_file): os.chdir(tmp_path) @@ -94,7 +94,7 @@ def test_gen_params(tmp_path, inpath, seq, seqf, name, ref_file): assert term in force_field.blocks[name].interactions[key] def test_find_missing_links(): - fname = TEST_DATA / "gen_params/ref/P3HT_10.itp" + fname = TEST_DATA / "gen_params" / "ref" / "P3HT_10.itp" ff = vermouth.forcefield.ForceField("test") meta_mol = MetaMolecule.from_itp(ff, fname, "P3HTref") meta_mol.molecule.remove_edge(39, 45) # resid 7,8 diff --git a/polyply/tests/test_gen_seq.py b/polyply/tests/test_gen_seq.py index ac7324f5..da050033 100644 --- a/polyply/tests/test_gen_seq.py +++ b/polyply/tests/test_gen_seq.py @@ -176,21 +176,21 @@ def test_tag_nodes(tags, expected, seed): "test", None, ["0:1:0-0"], - TEST_DATA / "gen_seq/ref/PPI_ref.json"), + TEST_DATA / "gen_seq" / "ref" / "PPI_ref.json"), ([], ["A:11:1:PEO-1", "B:11:1:PS-1"], ["A", "B"], "test", None, ["0:1:10-0"], - TEST_DATA / "gen_seq/ref/PEO_PS_ref.json"), - ([Path(TEST_DATA / "gen_seq/input/molecule_0.itp")], + TEST_DATA / "gen_seq" / "ref" / "PEO_PS_ref.json"), + ([Path(TEST_DATA / "gen_seq" / "input" / "molecule_0.itp")], ["A:5:1:PEG-1.0"], ["PROT", "A"], "test", ["PROT:molecule_0"], ["0:1:0-0"], - TEST_DATA / "gen_seq/ref/lyso_PEG.json") + TEST_DATA / "gen_seq" / "ref" / "lyso_PEG.json") )) def test_gen_seq(tmp_path, inpath, diff --git a/polyply/tests/test_generate_templates.py b/polyply/tests/test_generate_templates.py index bbe20911..b48f78fd 100644 --- a/polyply/tests/test_generate_templates.py +++ b/polyply/tests/test_generate_templates.py @@ -178,7 +178,7 @@ def test_extract_block(): @staticmethod def test_run_molecule(): - top = polyply.src.topology.Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") + top = polyply.src.topology.Topology.from_gmx_topfile(TEST_DATA / "topology_test" / "system.top", "test") top.gen_pairs() top.convert_nonbond_to_sig_eps() GenerateTemplates(topology=top, max_opt=10).run_molecule(top.molecules[0]) diff --git a/polyply/tests/test_meta_molecule.py b/polyply/tests/test_meta_molecule.py index f1f024d2..9cd948bb 100644 --- a/polyply/tests/test_meta_molecule.py +++ b/polyply/tests/test_meta_molecule.py @@ -94,26 +94,26 @@ def test_from_monomer_seq_linear(monomers, edges, nodes, attrs): @staticmethod @pytest.mark.parametrize('file_name, edges, nodes, attrs', ( # multiple blocks from single monomer - (TEST_DATA / "json/linear.json", + (TEST_DATA / "json" / "linear.json", [(0,1), (1,2)], [0,1,2], {0: 'PEO', 1: 'PEO', 2: 'PEO'} ), # two blocks from two monomers - (TEST_DATA / "json/single_branch.json", + (TEST_DATA / "json" / "single_branch.json", [(1,2),(2,3),(3,4),(2,5)], [1,2,3,4,5], {1: 'PEO', 2: 'PEO', 3: 'PS', 4: 'PS', 5:'PEO'} ), # two blocks from two monomers - (TEST_DATA / "json/double_branch.json", + (TEST_DATA / "json" / "double_branch.json", [(1,2),(2,3),(2,4),(4,5),(5,6),(5,8),(6,7)], [1,2,3,4,5,6,7,8], {1: 'PEO', 2: 'PEO', 3: 'PS', 4: 'PEO', 5:'PEO', 6: 'PS', 7: 'PS', 8: 'PEO'} ), # Hyperbranched - (TEST_DATA / "json/hyperbranched.json", + (TEST_DATA / "json" / "hyperbranched.json", [(0, 1), (0, 2), (0, 3), (1, 4), (1, 5), (2, 6), (2, 7), (3, 8), (3, 9), (4, 10), (4, 11), (5, 12), (5, 13)], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], @@ -121,7 +121,7 @@ def test_from_monomer_seq_linear(monomers, edges, nodes, attrs): 7: 'N1', 8: 'N2', 9: 'N3', 10: 'N3', 11: 'N2', 12: 'N3', 13: 'N3'} ), # check that ordering is restored - (TEST_DATA / "json/linear_rev.json", + (TEST_DATA / "json" / "linear_rev.json", [(0, 1), (1, 2)], [0, 1, 2], {0: 'PEO', 1: 'PEO', 2: 'PEO'} @@ -146,7 +146,7 @@ def test_resid_assignment_error(): @staticmethod def test_from_itp(): - file_name = TEST_DATA / "itp/PEO.itp" + file_name = TEST_DATA / "itp" / "PEO.itp" edges = [(0,1), (1,2)] nodes = [0, 1, 2] attrs = {0: 'PEO', 1: 'PEO', 2: 'PEO'} @@ -160,7 +160,7 @@ def test_from_itp(): @staticmethod def test_from_block(): - file_name = TEST_DATA / "itp/PEO.itp" + file_name = TEST_DATA / "itp" / "PEO.itp" edges = [(0,1), (1,2)] nodes = [0, 1, 2] attrs = {0: 'PEO', 1: 'PEO', 2: 'PEO'} diff --git a/polyply/tests/test_random_walk.py b/polyply/tests/test_random_walk.py index 3dfb0ba2..52dbdf3d 100644 --- a/polyply/tests/test_random_walk.py +++ b/polyply/tests/test_random_walk.py @@ -131,7 +131,7 @@ def test__take_step(): @pytest.fixture def nonbond_matrix(): - toppath = TEST_DATA / "struc_build/system.top" + toppath = TEST_DATA / "struc_build" / "system.top" topology = Topology.from_gmx_topfile(name="test", path=toppath) topology.preprocess() topology.volumes = {"PEO":0.43} @@ -140,7 +140,7 @@ def nonbond_matrix(): box=np.array([10., 10., 10.])) @pytest.fixture def molecule(): - toppath = TEST_DATA / "struc_build/system.top" + toppath = TEST_DATA / "struc_build" / "system.top" topology = Topology.from_gmx_topfile(name="test", path=toppath) return topology.molecules[0] diff --git a/polyply/tests/test_simple_seq_parsers.py b/polyply/tests/test_simple_seq_parsers.py index 87fd7433..a0b5827f 100644 --- a/polyply/tests/test_simple_seq_parsers.py +++ b/polyply/tests/test_simple_seq_parsers.py @@ -96,7 +96,7 @@ def test_monomers_to_linear_nx_graph(example_meta_molecule): "fasta" )) def test_sequence_parses(extension): - part_path = "simple_seq_files/test." + extension + part_path = Path("simple_seq_files") / ("test." + extension) filepath = TEST_DATA / part_path seq_graph = MetaMolecule.parsers[extension](filepath) monomers = ["DA5", "DT", "DC", "DG", "DT", "DA", "DC", "DA", "DT3"] @@ -104,7 +104,7 @@ def test_sequence_parses(extension): assert nx.is_isomorphic(seq_graph, ref_graph, node_match=_node_match) def test_ig_cirle(): - filepath = Path(TEST_DATA / "simple_seq_files/test_circle.ig") + filepath = TEST_DATA / "simple_seq_files" / "test_circle.ig" seq_graph = MetaMolecule.parsers["ig"](filepath) monomers = ["DA", "DT", "DC", "DG", "DT", "DA", "DC", "DA", "DT"] ref_graph = _monomers_to_linear_nx_graph(monomers) @@ -115,7 +115,7 @@ def test_ig_cirle(): node_match=_node_match) def test_ig_termination_fail(): - filepath = Path(TEST_DATA / "simple_seq_files/test_fail.ig") + filepath = Path(TEST_DATA / "simple_seq_files" / "test_fail.ig") with pytest.raises(FileFormatError): seq_graph = MetaMolecule.parsers["ig"](filepath) @@ -124,7 +124,7 @@ def test_ig_termination_fail(): "fasta" )) def test_sequence_parses_RNA(extension): - part_path = "simple_seq_files/test_RNA." + extension + part_path = Path("simple_seq_files") / ("test_RNA." + extension) filepath = TEST_DATA / part_path seq_graph = MetaMolecule.parsers[extension](filepath) monomers = ["A5", "U", "C", "G", "U", "A", "C", "A", "U3"] @@ -132,7 +132,7 @@ def test_sequence_parses_RNA(extension): assert nx.is_isomorphic(seq_graph, ref_graph, node_match=_node_match) def test_sequence_parses_PROTEIN(): - filepath = Path(TEST_DATA / "simple_seq_files/test_protein.fasta") + filepath = Path(TEST_DATA / "simple_seq_files" / "test_protein.fasta") seq_graph = MetaMolecule.parsers["fasta"](filepath) monomers = ["GLY", "ALA", "LYS", "TRP", "ASN", "VAL", "PHE", "PRO", "SER"] ref_graph = _monomers_to_linear_nx_graph(monomers) diff --git a/polyply/tests/test_topology.py b/polyply/tests/test_topology.py index 9af9d466..b7cba2ea 100644 --- a/polyply/tests/test_topology.py +++ b/polyply/tests/test_topology.py @@ -31,7 +31,7 @@ class TestTopology: @staticmethod def test_from_gmx_topfile(): - top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test" / "system.top", "test") assert len(top.molecules) == 1 @staticmethod @@ -44,8 +44,8 @@ def test_add_positions_from_gro(): no coordinates defined and require the build and backmap attribute to be True. In all other cases they need to be False. """ - top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") - top.add_positions_from_file(TEST_DATA / "topology_test/test.gro") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test" / "system.top", "test") + top.add_positions_from_file(TEST_DATA / "topology_test" / "test.gro") # check that the box is correctly read assert np.allclose(top.box, np.array([10.0, 11.0, 12.0])) @@ -72,8 +72,8 @@ def test_add_meta_positions_from_gro(): have no coordinates defined at either level and require the build and backmap attribute to be True. In all other cases the build attribute is False and backmap is True. """ - top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") - top.add_positions_from_file(TEST_DATA / "topology_test/meta.gro", resolution="meta_mol") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test" / "system.top", "test") + top.add_positions_from_file(TEST_DATA / "topology_test" / "meta.gro", resolution="meta_mol") # check that the box is correctly read assert np.allclose(top.box, np.array([10.0, 11.0, 12.0])) @@ -95,13 +95,13 @@ def test_add_positions_from_pdb(): the meta_molecule positions are defined as well. In addition all build and backmap attributes have to be False. """ - top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/pdb.top", "test") - top.add_positions_from_file(TEST_DATA / "topology_test/test.pdb") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test" / "pdb.top", "test") + top.add_positions_from_file(TEST_DATA / "topology_test" / "test.pdb") # check that the box is correctly read assert np.allclose(top.box, np.array([11.8249, 12.0688, 11.0944])) - pdb_mols = read_pdb(TEST_DATA / "topology_test/test.pdb") + pdb_mols = read_pdb(TEST_DATA / "topology_test" / "test.pdb") for idx, meta_mol in enumerate(top.molecules): for node in meta_mol.molecule.nodes: ref_pos = pdb_mols[idx].nodes[node]['position'] @@ -119,13 +119,13 @@ def test_add_positions_from_file_fail(): This test checks if coordinates for a residue at the molecule level are incomplete the appropiate error is raised. """ - top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test" / "system.top", "test") with pytest.raises(IOError): - top.add_positions_from_file(TEST_DATA / "topology_test/fail.gro") + top.add_positions_from_file(TEST_DATA / "topology_test" / "fail.gro") @staticmethod def test_convert_to_vermouth_system(): - top = Topology.from_gmx_topfile(TEST_DATA / "topology_test/system.top", "test") + top = Topology.from_gmx_topfile(TEST_DATA / "topology_test" / "system.top", "test") system = top.convert_to_vermouth_system() assert isinstance(system, vermouth.system.System) assert len(system.molecules) == 1