From 7f3af66066f723872467751fac2789643732e42c Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Sun, 24 Jan 2021 12:39:30 -0500 Subject: [PATCH 01/16] abspath call to find_path --- package/MDAnalysis/topology/ITPParser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/topology/ITPParser.py b/package/MDAnalysis/topology/ITPParser.py index e2962632781..a11572c31f7 100644 --- a/package/MDAnalysis/topology/ITPParser.py +++ b/package/MDAnalysis/topology/ITPParser.py @@ -268,7 +268,7 @@ def find_path(self, path): path = path.name except AttributeError: pass - + path = os.path.abspath(path) current_dir = os.path.dirname(current_file) dir_path = os.path.join(current_dir, path) if os.path.exists(dir_path): From eb6b8aaff3de7fd847ff238df8d26cd3e4d82b3e Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Sun, 24 Jan 2021 12:47:49 -0500 Subject: [PATCH 02/16] Update CHANGELOG --- package/CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/package/CHANGELOG b/package/CHANGELOG index e4be7bb036c..6377c19cf10 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -21,6 +21,7 @@ The rules for this file: * 2.0.0 Fixes + * ITPParser now accepts relative paths * atommethods (_get_prev/next_residues_by_resid) returns empty residue group when given empty residue group (Issue #3089) * MOL2 files without bonds can now be read and written (Issue #3057) From 45fa573bbf5a332ceb4ddcc4ce3ffed4e6fde603 Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Sun, 24 Jan 2021 17:06:19 -0500 Subject: [PATCH 03/16] Update changelog --- package/CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 6377c19cf10..d19886c2a01 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -21,7 +21,7 @@ The rules for this file: * 2.0.0 Fixes - * ITPParser now accepts relative paths + * ITPParser now accepts relative paths (Issue #3037) * atommethods (_get_prev/next_residues_by_resid) returns empty residue group when given empty residue group (Issue #3089) * MOL2 files without bonds can now be read and written (Issue #3057) From 26806fc939a16490dcb1a77bae36c7356103c733 Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Mon, 25 Jan 2021 10:59:20 -0500 Subject: [PATCH 04/16] Slight change to ITPParser --- package/MDAnalysis/topology/ITPParser.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package/MDAnalysis/topology/ITPParser.py b/package/MDAnalysis/topology/ITPParser.py index a11572c31f7..336ac55d8a1 100644 --- a/package/MDAnalysis/topology/ITPParser.py +++ b/package/MDAnalysis/topology/ITPParser.py @@ -265,10 +265,9 @@ def find_path(self, path): current_file = self.current_file try: - path = path.name + path = os.path.abspath(path.name) except AttributeError: pass - path = os.path.abspath(path) current_dir = os.path.dirname(current_file) dir_path = os.path.join(current_dir, path) if os.path.exists(dir_path): From 9c9ed5048ad5f8bb1685c66bfdf4ca959c0709c8 Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Thu, 11 Mar 2021 15:19:22 -0500 Subject: [PATCH 05/16] test for itpparsefix --- testsuite/MDAnalysisTests/topology/test_itp.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index b16fd38bb12..7638c6e5b58 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -335,3 +335,9 @@ def test_missing_endif(self): with pytest.raises(IOError): with self.parser(ITP_no_endif) as p: top = p.parse(include_dir=GMX_DIR) + +class Testrelativepath: + + def test_relpath(self): + u=mda.Universe('../data/gromacs_ala10.itp', format='ITP') + \ No newline at end of file From 62307b66fbae0fc2556b52e8a0f1e6b775c27e74 Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Thu, 11 Mar 2021 15:31:30 -0500 Subject: [PATCH 06/16] fix PEP8 issues --- testsuite/MDAnalysisTests/topology/test_itp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index 7638c6e5b58..f04c2efd8d3 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -338,6 +338,6 @@ def test_missing_endif(self): class Testrelativepath: + def test_relpath(self): - u=mda.Universe('../data/gromacs_ala10.itp', format='ITP') - \ No newline at end of file + u = mda.Universe('../data/gromacs_ala10.itp', format='ITP') From a69ecff18cc00e5fa307819fc891f419bf31bf05 Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Thu, 11 Mar 2021 15:37:25 -0500 Subject: [PATCH 07/16] PEP8 fix --- testsuite/MDAnalysisTests/topology/test_itp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index f04c2efd8d3..4946ac9bd1d 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -338,6 +338,5 @@ def test_missing_endif(self): class Testrelativepath: - def test_relpath(self): u = mda.Universe('../data/gromacs_ala10.itp', format='ITP') From c7b2fb0186cb6a62e85e14cd9845abcbbc43d6fa Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Sun, 14 Mar 2021 21:00:49 -0400 Subject: [PATCH 08/16] Create temporary directory when testing --- testsuite/MDAnalysisTests/topology/test_itp.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index 4946ac9bd1d..3de937a64a3 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -338,5 +338,12 @@ def test_missing_endif(self): class Testrelativepath: - def test_relpath(self): - u = mda.Universe('../data/gromacs_ala10.itp', format='ITP') + + def test_relpath(self,tmp_path): + content="[ atoms ]\n"+\ + " 1 H 1 SOL HW1 1 0.41 1.00800" + d = tmp_path / "sub" + d.mkdir() + p = d / "test.itp" + p.write_text(content) + u = mda.Universe(tmp_path / "sub/test.itp", format='ITP') From 16cad3dc15a5535bfda6adc14a9b547b57c19258 Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Sun, 21 Mar 2021 20:54:27 -0400 Subject: [PATCH 09/16] Fix PEP8 errors --- testsuite/MDAnalysisTests/topology/test_itp.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index 3de937a64a3..1173e26f6b4 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -338,10 +338,9 @@ def test_missing_endif(self): class Testrelativepath: - - def test_relpath(self,tmp_path): - content="[ atoms ]\n"+\ - " 1 H 1 SOL HW1 1 0.41 1.00800" + def test_relpath(self, tmp_path): + content="[ atoms ]\n" +\ + " 1 H 1 SOL HW1 1 0.41 1.00800" d = tmp_path / "sub" d.mkdir() p = d / "test.itp" From dda1efa6961d7f28ed46badbd07b162b33d45f4b Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Tue, 30 Mar 2021 19:39:57 -0400 Subject: [PATCH 10/16] Fixed tests to demonstrate relative path and relative string Thanks to Lilyminium! --- package/CHANGELOG | 2 +- .../MDAnalysisTests/topology/test_itp.py | 34 +++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index ea6766abf3d..8ec781fe238 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -21,7 +21,7 @@ The rules for this file: * 2.0.0 Fixes - * ITPParser now accepts relative paths (Issue #3037) + * ITPParser now accepts relative paths (Issue #3037, PR #3108) * ValueError raised when empty atomgroup is given to DensityAnalysis without a user defined grid. UserWarning displayed when user defined grid is provided. (Issue #3055) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index 1173e26f6b4..c4b71b787f2 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -21,7 +21,7 @@ # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 # import pytest - +from pathlib import Path import MDAnalysis as mda import numpy as np from numpy.testing import assert_almost_equal, assert_equal @@ -336,13 +336,25 @@ def test_missing_endif(self): with self.parser(ITP_no_endif) as p: top = p.parse(include_dir=GMX_DIR) -class Testrelativepath: - - def test_relpath(self, tmp_path): - content="[ atoms ]\n" +\ - " 1 H 1 SOL HW1 1 0.41 1.00800" - d = tmp_path / "sub" - d.mkdir() - p = d / "test.itp" - p.write_text(content) - u = mda.Universe(tmp_path / "sub/test.itp", format='ITP') +class TestRelativePath: + + def test_relstring(self, tmpdir): + content="""[ atoms ] + 1 H 1 SOL HW1 1 0.41 1.00800""" + p=tmpdir.mkdir("sub1").join("test.itp") + p.write(content) + p2=tmpdir.mkdir("sub2") + p2.chdir() + with p2.as_cwd() as pchange: + u = mda.Universe(str("../sub1/test.itp"), format='ITP') + + def test_relpath(self, tmpdir): + content="""[ atoms ] + 1 H 1 SOL HW1 1 0.41 1.00800""" + p=tmpdir.mkdir("sub1").join("test.itp") + p.write(content) + p2=tmpdir.mkdir("sub2") + p2.chdir() + with p2.as_cwd() as pchange: + relpath=Path("../sub1/test.itp") + u = mda.Universe(relpath, format='ITP') From 13273cba0145d77cfec2192bc25238c5740d1655 Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Thu, 1 Apr 2021 21:05:37 -0400 Subject: [PATCH 11/16] Try to #include itp file --- .../MDAnalysisTests/data/gromacs/gromos54a7_edited.ff/test.itp | 2 ++ testsuite/MDAnalysisTests/topology/test_itp.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 testsuite/MDAnalysisTests/data/gromacs/gromos54a7_edited.ff/test.itp diff --git a/testsuite/MDAnalysisTests/data/gromacs/gromos54a7_edited.ff/test.itp b/testsuite/MDAnalysisTests/data/gromacs/gromos54a7_edited.ff/test.itp new file mode 100644 index 00000000000..def77229992 --- /dev/null +++ b/testsuite/MDAnalysisTests/data/gromacs/gromos54a7_edited.ff/test.itp @@ -0,0 +1,2 @@ +[ atoms ] +1 H 1 SOL HW1 1 0.41 1.00800 \ No newline at end of file diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index c4b71b787f2..407a9823867 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -339,7 +339,8 @@ def test_missing_endif(self): class TestRelativePath: def test_relstring(self, tmpdir): - content="""[ atoms ] + content=""" #include "../../data/gromacs/gromos54a7_edited.ff/test.itp" + [ atoms ] 1 H 1 SOL HW1 1 0.41 1.00800""" p=tmpdir.mkdir("sub1").join("test.itp") p.write(content) From 4d7fe4411a25252635a94af0202bf04bd1a9da44 Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Wed, 7 Apr 2021 16:43:48 -0400 Subject: [PATCH 12/16] Update test_itp.py --- testsuite/MDAnalysisTests/topology/test_itp.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index 407a9823867..8a3653ed494 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -339,14 +339,18 @@ def test_missing_endif(self): class TestRelativePath: def test_relstring(self, tmpdir): - content=""" #include "../../data/gromacs/gromos54a7_edited.ff/test.itp" + content=""" #include "../sub3/test2.itp" [ atoms ] 1 H 1 SOL HW1 1 0.41 1.00800""" + content2= """[ atoms ] + 1 H 1 SOL HW1 1 0.41 1.00800""" p=tmpdir.mkdir("sub1").join("test.itp") p.write(content) + p3=tmpdir.mkdir("sub3").join("test2.itp") + p3.write(content2) p2=tmpdir.mkdir("sub2") p2.chdir() - with p2.as_cwd() as pchange: + with p2.as_cwd() as pchange: u = mda.Universe(str("../sub1/test.itp"), format='ITP') def test_relpath(self, tmpdir): From abc9bb3064a94ab218b8bf04d8de778bf1e02b4e Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Sat, 10 Apr 2021 17:26:14 -0400 Subject: [PATCH 13/16] Adding another test! --- .../MDAnalysisTests/topology/test_itp.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index 7d4e0344841..7986f7e165d 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -394,3 +394,24 @@ def test_relpath(self, tmpdir): with p2.as_cwd() as pchange: relpath=Path("../sub1/test.itp") u = mda.Universe(relpath, format='ITP') + + def test_relative_path(self, tmpdir): + test_itp_content = '#include "../atoms.itp"' + atoms_itp_content = """ + [ moleculetype ] + UNK 3 + + [ atoms ] + 1 H 1 SOL HW1 1 0.41 1.00800 + """ + with tmpdir.as_cwd(): + with open("atoms.itp", "w") as f: + f.write(atoms_itp_content) + subdir = tmpdir.mkdir("subdir") + with subdir.as_cwd(): + with open("test.itp", "w") as f: + f.write(test_itp_content) + subsubdir = subdir.mkdir("subsubdir") + with subsubdir.as_cwd(): + u = mda.Universe("../test.itp") + assert len(u.atoms) == 1 From 3a1b2b5eb5c3c62669f672f28ad6bfb06c194270 Mon Sep 17 00:00:00 2001 From: Aditya Kamath Date: Thu, 15 Apr 2021 16:10:06 -0400 Subject: [PATCH 14/16] Correct PEP8 errors --- .../MDAnalysisTests/topology/test_itp.py | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index 7986f7e165d..6b4adcc3090 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -369,30 +369,35 @@ def test_missing_endif(self): class TestRelativePath: + def test_relstring(self, tmpdir): - content=""" #include "../sub3/test2.itp" - [ atoms ] - 1 H 1 SOL HW1 1 0.41 1.00800""" - content2= """[ atoms ] - 1 H 1 SOL HW1 1 0.41 1.00800""" - p=tmpdir.mkdir("sub1").join("test.itp") + content = """ #include "../sub3/test2.itp" + [ atoms ] + 1 H 1 SOL HW1 1 0.41 1.00800 + """ + content2 = """[ atoms ] + 1 H 1 SOL HW1 1 0.41 1.00800 + """ + p = tmpdir.mkdir("sub1").join("test.itp") p.write(content) - p3=tmpdir.mkdir("sub3").join("test2.itp") + p3 = tmpdir.mkdir("sub3").join("test2.itp") p3.write(content2) - p2=tmpdir.mkdir("sub2") + p2 = tmpdir.mkdir("sub2") p2.chdir() - with p2.as_cwd() as pchange: + with p2.as_cwd() as pchange: u = mda.Universe(str("../sub1/test.itp"), format='ITP') def test_relpath(self, tmpdir): - content="""[ atoms ] - 1 H 1 SOL HW1 1 0.41 1.00800""" - p=tmpdir.mkdir("sub1").join("test.itp") + content = """ + [ atoms ] + 1 H 1 SOL HW1 1 0.41 1.00800 + """ + p = tmpdir.mkdir("sub1").join("test.itp") p.write(content) - p2=tmpdir.mkdir("sub2") + p2 = tmpdir.mkdir("sub2") p2.chdir() with p2.as_cwd() as pchange: - relpath=Path("../sub1/test.itp") + relpath = Path("../sub1/test.itp") u = mda.Universe(relpath, format='ITP') def test_relative_path(self, tmpdir): @@ -414,4 +419,4 @@ def test_relative_path(self, tmpdir): subsubdir = subdir.mkdir("subsubdir") with subsubdir.as_cwd(): u = mda.Universe("../test.itp") - assert len(u.atoms) == 1 + assert len(u.atoms) == 1 From b14e1e5becea3959ee394ebefae40bcc7d45d1ce Mon Sep 17 00:00:00 2001 From: Aditya Kamath <48089312+aditya-kamath@users.noreply.github.com> Date: Thu, 15 Apr 2021 17:32:17 -0400 Subject: [PATCH 15/16] minor pep8 Co-authored-by: Lily Wang <31115101+lilyminium@users.noreply.github.com> --- testsuite/MDAnalysisTests/topology/test_itp.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index 6b4adcc3090..6d24590c03b 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -368,8 +368,6 @@ def test_missing_endif(self): top = p.parse(include_dir=GMX_DIR) class TestRelativePath: - - def test_relstring(self, tmpdir): content = """ #include "../sub3/test2.itp" [ atoms ] From 84d0fd421416b42f103abe50e67cc866609e65d2 Mon Sep 17 00:00:00 2001 From: Aditya Kamath <48089312+aditya-kamath@users.noreply.github.com> Date: Thu, 15 Apr 2021 17:32:29 -0400 Subject: [PATCH 16/16] minor pep8 2 Co-authored-by: Lily Wang <31115101+lilyminium@users.noreply.github.com> --- testsuite/MDAnalysisTests/topology/test_itp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testsuite/MDAnalysisTests/topology/test_itp.py b/testsuite/MDAnalysisTests/topology/test_itp.py index 6d24590c03b..bd79384a0ae 100644 --- a/testsuite/MDAnalysisTests/topology/test_itp.py +++ b/testsuite/MDAnalysisTests/topology/test_itp.py @@ -367,6 +367,7 @@ def test_missing_endif(self): with self.parser(ITP_no_endif) as p: top = p.parse(include_dir=GMX_DIR) + class TestRelativePath: def test_relstring(self, tmpdir): content = """ #include "../sub3/test2.itp"