pdb-tools 2.4.12__py3-none-any.whl → 2.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/METADATA +19 -11
  2. pdb_tools-2.5.1.dist-info/RECORD +55 -0
  3. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/WHEEL +1 -1
  4. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/entry_points.txt +1 -1
  5. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info}/top_level.txt +0 -1
  6. pdbtools/pdb_selmodel.py +194 -0
  7. pdbtools/pdb_tidy.py +17 -9
  8. pdb_tools-2.4.12.dist-info/RECORD +0 -103
  9. tests/__init__.py +0 -38
  10. tests/config.py +0 -25
  11. tests/test_pdb_b.py +0 -161
  12. tests/test_pdb_chain.py +0 -160
  13. tests/test_pdb_chainbows.py +0 -140
  14. tests/test_pdb_chainxseg.py +0 -156
  15. tests/test_pdb_chkensemble.py +0 -191
  16. tests/test_pdb_delchain.py +0 -165
  17. tests/test_pdb_delelem.py +0 -165
  18. tests/test_pdb_delhetatm.py +0 -115
  19. tests/test_pdb_delinsertion.py +0 -226
  20. tests/test_pdb_delres.py +0 -241
  21. tests/test_pdb_delresname.py +0 -171
  22. tests/test_pdb_element.py +0 -151
  23. tests/test_pdb_fixinsert.py +0 -223
  24. tests/test_pdb_fromcif.py +0 -124
  25. tests/test_pdb_gap.py +0 -125
  26. tests/test_pdb_head.py +0 -142
  27. tests/test_pdb_intersect.py +0 -139
  28. tests/test_pdb_keepcoord.py +0 -115
  29. tests/test_pdb_merge.py +0 -106
  30. tests/test_pdb_mkensemble.py +0 -132
  31. tests/test_pdb_occ.py +0 -161
  32. tests/test_pdb_reatom.py +0 -243
  33. tests/test_pdb_reres.py +0 -281
  34. tests/test_pdb_rplchain.py +0 -172
  35. tests/test_pdb_rplresname.py +0 -172
  36. tests/test_pdb_seg.py +0 -160
  37. tests/test_pdb_segxchain.py +0 -146
  38. tests/test_pdb_selaltloc.py +0 -943
  39. tests/test_pdb_selatom.py +0 -165
  40. tests/test_pdb_selchain.py +0 -210
  41. tests/test_pdb_selelem.py +0 -165
  42. tests/test_pdb_selhetatm.py +0 -116
  43. tests/test_pdb_selres.py +0 -257
  44. tests/test_pdb_selresname.py +0 -171
  45. tests/test_pdb_selseg.py +0 -165
  46. tests/test_pdb_shiftres.py +0 -241
  47. tests/test_pdb_sort.py +0 -254
  48. tests/test_pdb_splitchain.py +0 -242
  49. tests/test_pdb_splitmodel.py +0 -235
  50. tests/test_pdb_splitseg.py +0 -251
  51. tests/test_pdb_tidy.py +0 -312
  52. tests/test_pdb_tocif.py +0 -238
  53. tests/test_pdb_tofasta.py +0 -158
  54. tests/test_pdb_uniqname.py +0 -156
  55. tests/test_pdb_validate.py +0 -142
  56. tests/test_pdb_wc.py +0 -161
  57. tests/utils.py +0 -56
  58. {pdb_tools-2.4.12.dist-info → pdb_tools-2.5.1.dist-info/licenses}/LICENSE +0 -0
@@ -1,242 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- #
4
- # Copyright 1118 João Pedro Rodrigues
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- """
19
- Unit Tests for `pdb_splitchain`.
20
- """
21
-
22
- import os
23
- import shutil
24
- import sys
25
- import tempfile
26
- import unittest
27
-
28
- from config import data_dir
29
- from utils import OutputCapture
30
-
31
-
32
- class TestTool(unittest.TestCase):
33
- """
34
- Generic class for testing tools.
35
- """
36
-
37
- def setUp(self):
38
- # Dynamically import the module
39
- name = 'pdbtools.pdb_splitchain'
40
- self.module = __import__(name, fromlist=[''])
41
- self.tempdir = tempfile.mkdtemp() # set temp dir
42
- os.chdir(self.tempdir)
43
-
44
- def tearDown(self):
45
- os.chdir(os.path.dirname(os.path.abspath('.'))) # cd ../
46
- shutil.rmtree(self.tempdir)
47
-
48
- def exec_module(self):
49
- """
50
- Execs module.
51
- """
52
-
53
- with OutputCapture() as output:
54
- try:
55
- self.module.main()
56
- except SystemExit as e:
57
- self.retcode = e.code
58
-
59
- self.stdout = output.stdout
60
- self.stderr = output.stderr
61
-
62
- return
63
-
64
-
65
- def test_default(self):
66
- """$ pdb_splitchain data/dummy.pdb"""
67
-
68
- # Copy input file to tempdir
69
-
70
- # Simulate input
71
- src = os.path.join(data_dir, 'dummy.pdb')
72
- dst = os.path.join(self.tempdir, 'dummy.pdb')
73
- shutil.copy(src, dst)
74
- sys.argv = ['', dst]
75
-
76
- # Execute the script
77
- self.exec_module()
78
-
79
- # Validate results
80
- self.assertEqual(self.retcode, 0) # ensure the program exited OK.
81
- self.assertEqual(len(self.stdout), 0) # no output
82
- self.assertEqual(len(self.stderr), 0) # no errors
83
-
84
- # Read files created by script and then delete
85
- ofiles = [f for f in os.listdir(self.tempdir) if f.startswith('dummy')]
86
- self.assertEqual(len(ofiles), 4 + 1) # ori + 4 chains
87
-
88
- # Make sure each file has the chain it should have
89
- records = (('ATOM', 'HETATM', 'TER', 'ANISOU'))
90
- for fpath in ofiles:
91
- if fpath == 'dummy.pdb':
92
- continue
93
-
94
- with open(os.path.join(self.tempdir, fpath), 'r') as handle:
95
- fname_chain = fpath.split('_')[1][:-4] # xxx_(X).pdb
96
- pdb_chains = [l[21] for l in handle if l.startswith(records)]
97
-
98
- self.assertEqual(fname_chain, list(set(pdb_chains))[0])
99
-
100
- def test_run_fhandler(self):
101
- """pdb_splitchain.run(fhandler)"""
102
- from pdbtools import pdb_splitchain
103
-
104
- src = os.path.join(data_dir, 'dummy.pdb')
105
- dst = os.path.join(self.tempdir, 'dummy.pdb')
106
- shutil.copy(src, dst)
107
-
108
- with open(dst, 'r') as fin:
109
- pdb_splitchain.run(fin)
110
-
111
- # Read files created by script and then delete
112
- ofiles = [f for f in os.listdir(self.tempdir) if f.startswith('dummy')]
113
- self.assertEqual(len(ofiles), 4 + 1) # ori + 4 chains
114
-
115
- # Make sure each file has the chain it should have
116
- records = (('ATOM', 'HETATM', 'TER', 'ANISOU'))
117
- for fpath in ofiles:
118
- if fpath == 'dummy.pdb':
119
- continue
120
-
121
- with open(os.path.join(self.tempdir, fpath), 'r') as handle:
122
- fname_chain = fpath.split('_')[1][:-4] # xxx_(X).pdb
123
- pdb_chains = [l[21] for l in handle if l.startswith(records)]
124
-
125
- self.assertEqual(fname_chain, list(set(pdb_chains))[0])
126
-
127
- def test_run_iterable(self):
128
- """pdb_splitchain.run(iterable)"""
129
- from pdbtools import pdb_splitchain
130
-
131
- src = os.path.join(data_dir, 'dummy.pdb')
132
- dst = os.path.join(self.tempdir, 'dummy.pdb')
133
- shutil.copy(src, dst)
134
-
135
- with open(dst, 'r') as fin:
136
- lines = fin.readlines()
137
-
138
- pdb_splitchain.run(lines)
139
-
140
- # Read files created by script and then delete
141
- ofiles = [
142
- f
143
- for f in os.listdir(self.tempdir)
144
- if f.startswith('splitchains')
145
- ]
146
- self.assertEqual(len(ofiles), 4) # 4 chains
147
-
148
- # Make sure each file has the chain it should have
149
- records = (('ATOM', 'HETATM', 'TER', 'ANISOU'))
150
- for fpath in ofiles:
151
-
152
- with open(os.path.join(self.tempdir, fpath), 'r') as handle:
153
- fname_chain = fpath.split('_')[1][:-4] # xxx_(X).pdb
154
- pdb_chains = [l[21] for l in handle if l.startswith(records)]
155
-
156
- self.assertEqual(fname_chain, list(set(pdb_chains))[0])
157
-
158
- def test_run_iterable_with_name(self):
159
- """pdb_splitchain.run(iterable)"""
160
- from pdbtools import pdb_splitchain
161
-
162
- src = os.path.join(data_dir, 'dummy.pdb')
163
- dst = os.path.join(self.tempdir, 'dummy.pdb')
164
- shutil.copy(src, dst)
165
-
166
- with open(dst, 'r') as fin:
167
- lines = fin.readlines()
168
-
169
- pdb_splitchain.run(lines, outname='newname')
170
-
171
- # Read files created by script and then delete
172
- ofiles = [f for f in os.listdir(self.tempdir) if f.startswith('newname')]
173
- self.assertEqual(len(ofiles), 4) # 4 chains
174
-
175
- # Make sure each file has the chain it should have
176
- records = (('ATOM', 'HETATM', 'TER', 'ANISOU'))
177
- for fpath in ofiles:
178
-
179
- with open(os.path.join(self.tempdir, fpath), 'r') as handle:
180
- fname_chain = fpath.split('_')[1][:-4] # xxx_(X).pdb
181
- pdb_chains = [l[21] for l in handle if l.startswith(records)]
182
-
183
- self.assertEqual(fname_chain, list(set(pdb_chains))[0])
184
-
185
- def test_file_not_found(self):
186
- """$ pdb_splitchain not_existing.pdb"""
187
-
188
- afile = os.path.join(data_dir, 'not_existing.pdb')
189
- sys.argv = ['', afile]
190
-
191
- self.exec_module()
192
-
193
- self.assertEqual(self.retcode, 1) # exit code is 1 (error)
194
- self.assertEqual(len(self.stdout), 0) # nothing written to stdout
195
- self.assertEqual(self.stderr[0][:22],
196
- "ERROR!! File not found") # proper error message
197
-
198
- @unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
199
- def test_file_missing(self):
200
- """$ pdb_splitchain -10"""
201
-
202
- sys.argv = ['', '-10']
203
-
204
- self.exec_module()
205
-
206
- self.assertEqual(self.retcode, 1)
207
- self.assertEqual(len(self.stdout), 0) # no output
208
- self.assertEqual(self.stderr[0][:38],
209
- "ERROR!! File not found or not readable")
210
-
211
- @unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
212
- def test_helptext(self):
213
- """$ pdb_splitchain"""
214
-
215
- sys.argv = ['']
216
-
217
- self.exec_module()
218
-
219
- self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
220
- self.assertEqual(len(self.stdout), 0) # no output
221
- self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
222
-
223
- def test_invalid_option(self):
224
- """$ pdb_splitchain -A data/dummy.pdb"""
225
-
226
- sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
227
-
228
- self.exec_module()
229
-
230
- self.assertEqual(self.retcode, 1)
231
- self.assertEqual(len(self.stdout), 0)
232
- self.assertEqual(self.stderr[0][:22],
233
- "ERROR!! Script takes 1") # proper error message
234
-
235
-
236
- if __name__ == '__main__':
237
- from config import test_dir
238
-
239
- mpath = os.path.abspath(os.path.join(test_dir, '..'))
240
- sys.path.insert(0, mpath) # so we load dev files before any installation
241
-
242
- unittest.main()
@@ -1,235 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
- #
4
- # Copyright 1118 João Pedro Rodrigues
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- """
19
- Unit Tests for `pdb_splitmodel`.
20
- """
21
-
22
- import os
23
- import shutil
24
- import sys
25
- import tempfile
26
- import unittest
27
-
28
- from config import data_dir
29
- from utils import OutputCapture
30
-
31
-
32
- class TestTool(unittest.TestCase):
33
- """
34
- Generic class for testing tools.
35
- """
36
-
37
- def setUp(self):
38
- # Dynamically import the module
39
- name = 'pdbtools.pdb_splitmodel'
40
- self.module = __import__(name, fromlist=[''])
41
- self.tempdir = tempfile.mkdtemp() # set temp dir
42
- os.chdir(self.tempdir)
43
-
44
- def tearDown(self):
45
- os.chdir(os.path.dirname(os.path.abspath('.'))) # cd ../
46
- shutil.rmtree(self.tempdir)
47
-
48
- def exec_module(self):
49
- """
50
- Execs module.
51
- """
52
-
53
- with OutputCapture() as output:
54
- try:
55
- self.module.main()
56
- except SystemExit as e:
57
- self.retcode = e.code
58
-
59
- self.stdout = output.stdout
60
- self.stderr = output.stderr
61
-
62
- return
63
-
64
- def test_default(self):
65
- """$ pdb_splitmodel data/ensemble_OK.pdb"""
66
-
67
- # Copy input file to tempdir
68
-
69
- # Simulate input
70
- src = os.path.join(data_dir, 'ensemble_OK.pdb')
71
- dst = os.path.join(self.tempdir, 'ensemble_OK.pdb')
72
- shutil.copy(src, dst)
73
- sys.argv = ['', dst]
74
-
75
- # Execute the script
76
- self.exec_module()
77
-
78
- # Validate results
79
- self.assertEqual(self.retcode, 0) # ensure the program exited OK.
80
- self.assertEqual(len(self.stdout), 0) # no output
81
- self.assertEqual(len(self.stderr), 0) # no errors
82
-
83
- # Read files created by script
84
- ofiles = [f for f in os.listdir(self.tempdir)
85
- if f.startswith('ensemble_OK')]
86
- self.assertEqual(len(ofiles), 2 + 1) # ori + 2 models
87
-
88
- for fpath in ofiles:
89
- if fpath == 'ensemble_OK.pdb':
90
- continue
91
-
92
- with open(os.path.join(self.tempdir, fpath), 'r') as handle:
93
- n_lines = len(handle.readlines())
94
- self.assertEqual(n_lines, 2)
95
-
96
- def test_run_iterable(self):
97
- """pdb_splitmodel.run(iterable)"""
98
- from pdbtools import pdb_splitmodel
99
-
100
- # Copy input file to tempdir
101
-
102
- # Simulate input
103
- src = os.path.join(data_dir, 'ensemble_OK.pdb')
104
- dst = os.path.join(self.tempdir, 'ensemble_OK.pdb')
105
- shutil.copy(src, dst)
106
-
107
- with open(dst, 'r') as fin:
108
- lines = fin.readlines()
109
-
110
- pdb_splitmodel.run(lines)
111
-
112
- # Read files created by script
113
- ofiles = [f for f in os.listdir(self.tempdir)
114
- if f.startswith('splitmodels')]
115
- self.assertEqual(len(ofiles), 2)
116
-
117
- for fpath in ofiles:
118
- if fpath == 'ensemble_OK.pdb':
119
- continue
120
-
121
- with open(os.path.join(self.tempdir, fpath), 'r') as handle:
122
- n_lines = len(handle.readlines())
123
- self.assertEqual(n_lines, 2)
124
-
125
- def test_run_iterable_with_name(self):
126
- """pdb_splitmodel.run(iterable)"""
127
- from pdbtools import pdb_splitmodel
128
-
129
- # Copy input file to tempdir
130
-
131
- # Simulate input
132
- src = os.path.join(data_dir, 'ensemble_OK.pdb')
133
- dst = os.path.join(self.tempdir, 'ensemble_OK.pdb')
134
- shutil.copy(src, dst)
135
-
136
- with open(dst, 'r') as fin:
137
- lines = fin.readlines()
138
-
139
- pdb_splitmodel.run(lines, outname='newname')
140
-
141
- # Read files created by script
142
- ofiles = [f for f in os.listdir(self.tempdir)
143
- if f.startswith('newname')]
144
- self.assertEqual(len(ofiles), 2)
145
-
146
- for fpath in ofiles:
147
- with open(os.path.join(self.tempdir, fpath), 'r') as handle:
148
- n_lines = len(handle.readlines())
149
- self.assertEqual(n_lines, 2)
150
-
151
- def test_run_fhandler(self):
152
- """pdb_splitmodel.run(fhandler)"""
153
- from pdbtools import pdb_splitmodel
154
-
155
- # Copy input file to tempdir
156
-
157
- # Simulate input
158
- src = os.path.join(data_dir, 'ensemble_OK.pdb')
159
- dst = os.path.join(self.tempdir, 'ensemble_OK.pdb')
160
- shutil.copy(src, dst)
161
-
162
- with open(dst, 'r') as fin:
163
- pdb_splitmodel.run(fin)
164
-
165
- # Read files created by script
166
- ofiles = [f for f in os.listdir(self.tempdir)
167
- if f.startswith('ensemble_OK')]
168
- self.assertEqual(len(ofiles), 2 + 1) # ori + 2 models
169
-
170
- for fpath in ofiles:
171
- if fpath == 'ensemble_OK.pdb':
172
- continue
173
-
174
- with open(os.path.join(self.tempdir, fpath), 'r') as handle:
175
- n_lines = len(handle.readlines())
176
- self.assertEqual(n_lines, 2)
177
-
178
- def test_file_not_found(self):
179
- """$ pdb_splitmodel not_existing.pdb"""
180
-
181
- afile = os.path.join(data_dir, 'not_existing.pdb')
182
- sys.argv = ['', afile]
183
-
184
- self.exec_module()
185
-
186
- self.assertEqual(self.retcode, 1) # exit code is 1 (error)
187
- self.assertEqual(len(self.stdout), 0) # nothing written to stdout
188
- self.assertEqual(self.stderr[0][:22],
189
- "ERROR!! File not found") # proper error message
190
-
191
- @unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
192
- def test_file_missing(self):
193
- """$ pdb_splitmodel -10"""
194
-
195
- sys.argv = ['', '-10']
196
-
197
- self.exec_module()
198
-
199
- self.assertEqual(self.retcode, 1)
200
- self.assertEqual(len(self.stdout), 0) # no output
201
- self.assertEqual(self.stderr[0][:38],
202
- "ERROR!! File not found or not readable")
203
-
204
- @unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
205
- def test_helptext(self):
206
- """$ pdb_splitmodel"""
207
-
208
- sys.argv = ['']
209
-
210
- self.exec_module()
211
-
212
- self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
213
- self.assertEqual(len(self.stdout), 0) # no output
214
- self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
215
-
216
- def test_invalid_option(self):
217
- """$ pdb_splitmodel -A data/ensemble_OK.pdb"""
218
-
219
- sys.argv = ['', '-A', os.path.join(data_dir, 'ensemble_OK.pdb')]
220
-
221
- self.exec_module()
222
-
223
- self.assertEqual(self.retcode, 1)
224
- self.assertEqual(len(self.stdout), 0)
225
- self.assertEqual(self.stderr[0][:22],
226
- "ERROR!! Script takes 1") # proper error message
227
-
228
-
229
- if __name__ == '__main__':
230
- from config import test_dir
231
-
232
- mpath = os.path.abspath(os.path.join(test_dir, '..'))
233
- sys.path.insert(0, mpath) # so we load dev files before any installation
234
-
235
- unittest.main()