Skip to content
This repository
Newer
Older
100644 1092 lines (1005 sloc) 52.19 kb
fe65e49f »
2013-08-23 Add DSSP unit test.
1 # Copyright 2009-2011 by Eric Talevich. All rights reserved.
2 # Revisions copyright 2009-2013 by Peter Cock. All rights reserved.
3 # Revisions copyright 2013 Lenna X. Peterson. All rights reserved.
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
4 #
5 # Converted by Eric Talevich from an older unit test copyright 2002
6 # by Thomas Hamelryck.
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
7 #
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
8 # This code is part of the Biopython distribution and governed by its
9 # license. Please see the LICENSE file that should have been included
10 # as part of this package.
11
12 """Unit tests for the Bio.PDB module."""
de12c5e0 »
2013-09-09 Add: from __future__ import print_statement
13 from __future__ import print_function
14
af5153b8 »
2010-05-29 Added a unit test for PDB model numbers, based on Konstanin Okonechni…
15 import os
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
16 import tempfile
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
17 import unittest
18 import warnings
b09ebbf6 »
2013-09-06 Import StringIO via _py3k module in tests
19 from Bio._py3k import StringIO
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
20
9252f1c1 »
2009-11-11 No code changes. Removing white space before ':' character to match P…
21 try:
162d02b9 »
2010-08-16 Split Bio.KDTree dependent parts of test_PDB.py into a separate file
22 import numpy
288e01c5 »
2013-07-17 PyPy 2.0 has numpy.dot now, but not numpy.linalg
23 from numpy import dot # Missing on old PyPy's micronumpy
8b480b99 »
2011-09-16 Skip test_PDB.py under PyPy
24 del dot
288e01c5 »
2013-07-17 PyPy 2.0 has numpy.dot now, but not numpy.linalg
25 from numpy.linalg import svd, det # Missing in PyPy 2.0 numpypy
9252f1c1 »
2009-11-11 No code changes. Removing white space before ':' character to match P…
26 except ImportError:
cb1f5449 »
2010-10-18 Use ImportError subclass for missing Python dependencies (see Gentoo …
27 from Bio import MissingPythonDependencyError
28 raise MissingPythonDependencyError(
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
29 "Install NumPy if you want to use Bio.PDB.")
f18561cc »
2010-02-04 Test the Polypeptide class get_sequence method
30
31 from Bio.Seq import Seq
32 from Bio.Alphabet import generic_protein
716c5db7 »
2013-02-27 Added unit tests for PDBIO
33 from Bio.PDB import PDBParser, PPBuilder, CaPPBuilder, PDBIO, Select
16b50cf4 »
2009-04-24 Adding PDB exposure test (Bug 2759) and removing non-deterministic wa…
34 from Bio.PDB import HSExposureCA, HSExposureCB, ExposureCN
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
35 from Bio.PDB.PDBExceptions import PDBConstructionException, PDBConstructionWarning
c836f3bb »
2011-08-17 Add test for transform method.
36 from Bio.PDB import rotmat, Vector
716c5db7 »
2013-02-27 Added unit tests for PDBIO
37 from Bio.PDB import Residue, Atom
c0a3d5b5 »
2013-08-27 Move dependency free DSSP testing into test_PDB.py
38 from Bio.PDB import make_dssp_dict
5d087068 »
2013-11-25 Bio/PDB/NACCESS: Various NACCESS fixes and unit tests
39 from Bio.PDB.NACCESS import process_asa_data, process_rsa_data
6a8a0a51 »
2010-06-03 PDB: Added a unit test for permissive parser warnings (Bug 2820)
40
fd82a0a7 »
2012-12-06 Add blank lines where needed (PEP8 E302).
41
6a8a0a51 »
2010-06-03 PDB: Added a unit test for permissive parser warnings (Bug 2820)
42 # NB: the 'A_' prefix ensures this test case is run first
43 class A_ExceptionTest(unittest.TestCase):
44 """Errors and warnings while parsing of flawed PDB files.
45
46 These tests must be executed because of the way Python's warnings module
47 works -- a warning is only logged the first time it is encountered.
48 """
49 def test_1_warnings(self):
50 """Check warnings: Parse a flawed PDB file in permissive mode.
51
52 NB: The try/finally block is adapted from the warnings.catch_warnings
53 context manager in the Python 2.6 standard library.
54 """
55 warnings.simplefilter('always', PDBConstructionWarning)
56 try:
57 # Equivalent to warnings.catch_warnings -- hackmagic
58 orig_showwarning = warnings.showwarning
59 all_warns = []
bfa8b256 »
2012-12-05 Add a blank line before and after functions (PEP8 E301).
60
6a8a0a51 »
2010-06-03 PDB: Added a unit test for permissive parser warnings (Bug 2820)
61 def showwarning(*args, **kwargs):
f4917021 »
2010-08-21 test_PDB.py: capture warning messages correctly (Py3 compat)
62 all_warns.append(args[0])
bfa8b256 »
2012-12-05 Add a blank line before and after functions (PEP8 E301).
63
6a8a0a51 »
2010-06-03 PDB: Added a unit test for permissive parser warnings (Bug 2820)
64 warnings.showwarning = showwarning
65 # Trigger warnings
66 p = PDBParser(PERMISSIVE=True)
67 p.get_structure("example", "PDB/a_structure.pdb")
d69b77fc »
2010-12-22 Only need one warning per problem element, not two
68 self.assertEqual(len(all_warns), 14)
6a8a0a51 »
2010-06-03 PDB: Added a unit test for permissive parser warnings (Bug 2820)
69 for wrn, msg in zip(all_warns, [
d9500da6 »
2012-12-05 Distinguish continuation lines from the next logical line (PEP8 E125).
70 # Expected warning messages:
71 "Used element 'N' for Atom (name=N) with given element ''",
72 "Used element 'C' for Atom (name=CA) with given element ''",
73 "Atom names ' CA ' and 'CA ' differ only in spaces at line 17.",
74 "Used element 'CA' for Atom (name=CA ) with given element ''",
75 'Atom N defined twice in residue <Residue ARG het= resseq=2 icode= > at line 21.',
76 'disordered atom found with blank altloc before line 33.',
77 "Residue (' ', 4, ' ') redefined at line 43.",
78 "Blank altlocs in duplicate residue SER (' ', 4, ' ') at line 43.",
79 "Residue (' ', 10, ' ') redefined at line 75.",
80 "Residue (' ', 14, ' ') redefined at line 106.",
81 "Residue (' ', 16, ' ') redefined at line 135.",
82 "Residue (' ', 80, ' ') redefined at line 633.",
83 "Residue (' ', 81, ' ') redefined at line 646.",
84 'Atom O defined twice in residue <Residue HOH het=W resseq=67 icode= > at line 822.'
85 ]):
25509a5c »
2010-12-22 Show spaces more clearly in this warning
86 self.assertTrue(msg in str(wrn), str(wrn))
6a8a0a51 »
2010-06-03 PDB: Added a unit test for permissive parser warnings (Bug 2820)
87 finally:
88 warnings.showwarning = orig_showwarning
89
90 def test_2_strict(self):
91 """Check error: Parse a flawed PDB file in strict mode."""
6577ab44 »
2011-05-06 Hide PDBConstructionWarning in one of test_PDB.py strict tests
92 warnings.simplefilter('ignore', PDBConstructionWarning)
93 try:
94 parser = PDBParser(PERMISSIVE=False)
95 self.assertRaises(PDBConstructionException,
96 parser.get_structure, "example", "PDB/a_structure.pdb")
97 finally:
98 warnings.filters.pop()
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
99
6a8a0a51 »
2010-06-03 PDB: Added a unit test for permissive parser warnings (Bug 2820)
100 def test_3_bad_xyz(self):
101 """Check error: Parse an entry with bad x,y,z value."""
102 data = "ATOM 9 N ASP A 152 21.554 34.953 27.691 1.00 19.26 N\n"
103 parser = PDBParser(PERMISSIVE=False)
104 s = parser.get_structure("example", StringIO(data))
105 data = "ATOM 9 N ASP A 152 21.ish 34.953 27.691 1.00 19.26 N\n"
106 self.assertRaises(PDBConstructionException,
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
107 parser.get_structure, "example", StringIO(data))
6a8a0a51 »
2010-06-03 PDB: Added a unit test for permissive parser warnings (Bug 2820)
108
e68fb679 »
2013-08-08 PDBParser blank occupancy as 1
109 def test_4_occupancy(self):
110 """Parse file with missing occupancy"""
111 permissive = PDBParser(PERMISSIVE=True)
112 structure = permissive.get_structure("test", "PDB/occupancy.pdb")
113 atoms = structure[0]['A'][(' ', 152, ' ')]
114 # Blank occupancy behavior set in Bio/PDB/PDBParser
500c3c2e »
2013-08-09 PDB: blank occupancy as None
115 self.assertEqual(atoms['N'].get_occupancy(), None)
e68fb679 »
2013-08-08 PDBParser blank occupancy as 1
116 self.assertEqual(atoms['CA'].get_occupancy(), 1.0)
117 self.assertEqual(atoms['C'].get_occupancy(), 0.0)
118
119 strict = PDBParser(PERMISSIVE=False)
120 self.assertRaises(PDBConstructionException,
121 strict.get_structure, "test", "PDB/occupancy.pdb")
122
6a8a0a51 »
2010-06-03 PDB: Added a unit test for permissive parser warnings (Bug 2820)
123
c21f3015 »
2010-06-03 Reordered and renamed test cases in test_PDB.py
124 class HeaderTests(unittest.TestCase):
125 """Tests for parse_pdb_header."""
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
126
c21f3015 »
2010-06-03 Reordered and renamed test cases in test_PDB.py
127 def test_capsid(self):
128 """Parse the header of a known PDB file (1A8O)."""
129 parser = PDBParser()
130 struct = parser.get_structure('1A8O', 'PDB/1A8O.pdb')
131 self.assertAlmostEqual(struct.header['resolution'], 1.7)
132 # Case-insensitive string comparisons
133 known_strings = {
134 'author': 'T.R.Gamble,S.Yoo,F.F.Vajdos,U.K.Von Schwedler,D.K.Worthylake,H.Wang,J.P.Mccutcheon,W.I.Sundquist,C.P.Hill',
135 'deposition_date': '1998-03-27',
136 'head': 'viral protein',
137 'journal': 'AUTH T.R.GAMBLE,S.YOO,F.F.VAJDOS,U.K.VON SCHWEDLER,AUTH 2 D.K.WORTHYLAKE,H.WANG,J.P.MCCUTCHEON,W.I.SUNDQUIST,AUTH 3 C.P.HILLTITL STRUCTURE OF THE CARBOXYL-TERMINAL DIMERIZATIONTITL 2 DOMAIN OF THE HIV-1 CAPSID PROTEIN.REF SCIENCE V. 278 849 1997REFN ISSN 0036-8075PMID 9346481DOI 10.1126/SCIENCE.278.5339.849',
138 'journal_reference': 't.r.gamble,s.yoo,f.f.vajdos,u.k.von schwedler, d.k.worthylake,h.wang,j.p.mccutcheon,w.i.sundquist, c.p.hill structure of the carboxyl-terminal dimerization domain of the hiv-1 capsid protein. science v. 278 849 1997 issn 0036-8075 9346481 10.1126/science.278.5339.849 ',
139 'keywords': 'capsid, core protein, hiv, c-terminal domain, viral protein',
140 'name': ' hiv capsid c-terminal domain',
141 'release_date': '1998-10-14',
142 'structure_method': 'x-ray diffraction',
143 }
195c1ac6 »
2013-09-07 Avoid my_dict.iteritems() in tests for Python 3 compatibility.
144 for key, expect in known_strings.items():
c21f3015 »
2010-06-03 Reordered and renamed test cases in test_PDB.py
145 self.assertEqual(struct.header[key].lower(), expect.lower())
146
147 def test_fibril(self):
148 """Parse the header of another PDB file (2BEG)."""
149 parser = PDBParser()
150 struct = parser.get_structure('2BEG', 'PDB/2BEG.pdb')
151 known_strings = {
152 'author': 'T.Luhrs,C.Ritter,M.Adrian,D.Riek-Loher,B.Bohrmann,H.Dobeli,D.Schubert,R.Riek',
153 'deposition_date': '2005-10-24',
154 'head': 'protein fibril',
155 'journal': "AUTH T.LUHRS,C.RITTER,M.ADRIAN,D.RIEK-LOHER,B.BOHRMANN,AUTH 2 H.DOBELI,D.SCHUBERT,R.RIEKTITL 3D STRUCTURE OF ALZHEIMER'S AMYLOID-{BETA}(1-42)TITL 2 FIBRILS.REF PROC.NATL.ACAD.SCI.USA V. 102 17342 2005REFN ISSN 0027-8424PMID 16293696DOI 10.1073/PNAS.0506723102",
156 'journal_reference': "t.luhrs,c.ritter,m.adrian,d.riek-loher,b.bohrmann, h.dobeli,d.schubert,r.riek 3d structure of alzheimer's amyloid-{beta}(1-42) fibrils. proc.natl.acad.sci.usa v. 102 17342 2005 issn 0027-8424 16293696 10.1073/pnas.0506723102 ",
157 'keywords': "alzheimer's, fibril, protofilament, beta-sandwich, quenched hydrogen/deuterium exchange, pairwise mutagenesis, protein fibril",
158 'name': " 3d structure of alzheimer's abeta(1-42) fibrils",
159 'release_date': '2005-11-22',
160 'structure_method': 'solution nmr',
161 }
195c1ac6 »
2013-09-07 Avoid my_dict.iteritems() in tests for Python 3 compatibility.
162 for key, expect in known_strings.items():
c21f3015 »
2010-06-03 Reordered and renamed test cases in test_PDB.py
163 self.assertEqual(struct.header[key].lower(), expect.lower())
ed22f3ac »
2010-04-19 Fix typo in PDBParser exception (only half fixed by previous update t…
164
1c197449 »
2009-11-18 Adding a small real PDB file containing some HETATM lines for use in …
165
c21f3015 »
2010-06-03 Reordered and renamed test cases in test_PDB.py
166 class ParseTest(unittest.TestCase):
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
167 def setUp(self):
168 warnings.simplefilter('ignore', PDBConstructionWarning)
169 p = PDBParser(PERMISSIVE=1)
170 self.structure = p.get_structure("example", "PDB/a_structure.pdb")
b5f7c6e4 »
2010-11-03 Don't use warnings.resetwarnings() as it clears all filters (even thi…
171 warnings.filters.pop()
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
172
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
173 def test_c_n(self):
174 """Extract polypeptides using C-N."""
175 ppbuild = PPBuilder()
176 polypeptides = ppbuild.build_peptides(self.structure[1])
177 self.assertEqual(len(polypeptides), 1)
178 pp = polypeptides[0]
179 # Check the start and end positions
180 self.assertEqual(pp[0].get_id()[1], 2)
181 self.assertEqual(pp[-1].get_id()[1], 86)
f18561cc »
2010-02-04 Test the Polypeptide class get_sequence method
182 # Check the sequence
183 s = pp.get_sequence()
75dd0b74 »
2010-07-05 Use assertTrue in unit tests (added in Python 2.4) since the earlier …
184 self.assertTrue(isinstance(s, Seq))
f18561cc »
2010-02-04 Test the Polypeptide class get_sequence method
185 self.assertEqual(s.alphabet, generic_protein)
186 self.assertEqual("RCGSQGGGSTCPGLRCCSIWGWCGDSEPYCGRTCENKCWSGER"
187 "SDHRCGAAVGNPPCGQDRCCSVHGWCGGGNDYCSGGNCQYRC",
188 str(s))
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
189
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
190 def test_ca_ca(self):
191 """Extract polypeptides using CA-CA."""
192 ppbuild = CaPPBuilder()
193 polypeptides = ppbuild.build_peptides(self.structure[1])
194 self.assertEqual(len(polypeptides), 1)
195 pp = polypeptides[0]
196 # Check the start and end positions
197 self.assertEqual(pp[0].get_id()[1], 2)
198 self.assertEqual(pp[-1].get_id()[1], 86)
f18561cc »
2010-02-04 Test the Polypeptide class get_sequence method
199 # Check the sequence
200 s = pp.get_sequence()
75dd0b74 »
2010-07-05 Use assertTrue in unit tests (added in Python 2.4) since the earlier …
201 self.assertTrue(isinstance(s, Seq))
f18561cc »
2010-02-04 Test the Polypeptide class get_sequence method
202 self.assertEqual(s.alphabet, generic_protein)
203 self.assertEqual("RCGSQGGGSTCPGLRCCSIWGWCGDSEPYCGRTCENKCWSGER"
204 "SDHRCGAAVGNPPCGQDRCCSVHGWCGGGNDYCSGGNCQYRC",
205 str(s))
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
206
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
207 def test_structure(self):
208 """Verify the structure of the parsed example PDB file."""
209 # Structure contains 2 models
4f877613 »
2010-07-05 Use documented assertEqual method in preference of undocumented asser…
210 self.assertEqual(len(self.structure), 2)
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
211 # --- Checking model 0 ---
212 m0 = self.structure[0]
213 # Model 0 contains 1 chain
4f877613 »
2010-07-05 Use documented assertEqual method in preference of undocumented asser…
214 self.assertEqual(len(m0), 1)
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
215 # Chain 'A' contains 1 residue
4f877613 »
2010-07-05 Use documented assertEqual method in preference of undocumented asser…
216 self.assertEqual(len(m0['A']), 1)
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
217 # Residue ('H_PCA', 1, ' ') contains 8 atoms.
218 residue = m0['A'].get_list()[0]
4f877613 »
2010-07-05 Use documented assertEqual method in preference of undocumented asser…
219 self.assertEqual(residue.get_id(), ('H_PCA', 1, ' '))
e9b4365d »
2010-12-01 Adapted script to accomodate Atom Element changes
220 self.assertEqual(len(residue), 9)
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
221 # --- Checking model 1 ---
222 m1 = self.structure[1]
223 # Model 1 contains 3 chains
4f877613 »
2010-07-05 Use documented assertEqual method in preference of undocumented asser…
224 self.assertEqual(len(m1), 3)
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
225 # Deconstruct this data structure to check each chain
226 chain_data = [ # chain_id, chain_len, [(residue_id, residue_len), ...]
227 ('A', 86, [ ((' ', 0, ' '), 1 ),
228 ((' ', 2, ' '), 11),
229 ((' ', 3, ' '), 6, 1), # disordered
230 ((' ', 4, ' '), 4 ),
231 ((' ', 5, ' '), 6 ),
232 ((' ', 6, ' '), 9 ),
233 ((' ', 7, ' '), 4 ),
234 ((' ', 8, ' '), 4 ),
235 ((' ', 9, ' '), 4 ),
236 ((' ', 10, ' '), 6, ['GLY', 'SER']), # point mut
237 ((' ', 11, ' '), 7 ),
238 ((' ', 12, ' '), 6 ),
239 ((' ', 13, ' '), 7 ),
240 ((' ', 14, ' '), 4, ['ALA', 'GLY']), # point mut
241 ((' ', 15, ' '), 8, 3), # disordered
242 ((' ', 16, ' '), 11, ['ARG', 'TRP']), # point mut
243 ((' ', 17, ' '), 6 ),
244 ((' ', 18, ' '), 6 ),
245 ((' ', 19, ' '), 6 ),
246 ((' ', 20, ' '), 8 ),
247 ((' ', 21, ' '), 14),
248 ((' ', 22, ' '), 4 ),
249 ((' ', 23, ' '), 14),
250 ((' ', 24, ' '), 6 ),
251 ((' ', 25, ' '), 4 ),
252 ((' ', 26, ' '), 8 ),
253 ((' ', 27, ' '), 6 ),
254 ((' ', 28, ' '), 9, 5), # disordered
255 ((' ', 29, ' '), 7 ),
256 ((' ', 30, ' '), 12),
257 ((' ', 31, ' '), 6 ),
258 ((' ', 32, ' '), 4 ),
259 ((' ', 33, ' '), 11),
260 ((' ', 34, ' '), 7 ),
261 ((' ', 35, ' '), 6 ),
262 ((' ', 36, ' '), 9 ),
263 ((' ', 37, ' '), 8 ),
264 ((' ', 38, ' '), 9 ),
265 ((' ', 39, ' '), 6 ),
266 ((' ', 40, ' '), 14),
267 ((' ', 41, ' '), 6 ),
268 ((' ', 42, ' '), 4 ),
269 ((' ', 43, ' '), 9 ),
270 ((' ', 44, ' '), 11),
271 ((' ', 45, ' '), 6, 1), # disordered
272 ((' ', 46, ' '), 8 ),
273 ((' ', 47, ' '), 10),
274 ((' ', 48, ' '), 11),
275 ((' ', 49, ' '), 6 ),
276 ((' ', 50, ' '), 4 ),
277 ((' ', 51, ' '), 5 ),
278 ((' ', 52, ' '), 5 ),
279 ((' ', 53, ' '), 7 ),
280 ((' ', 54, ' '), 4 ),
281 ((' ', 55, ' '), 8 ),
282 ((' ', 56, ' '), 7 ),
283 ((' ', 57, ' '), 7 ),
284 ((' ', 58, ' '), 6 ),
285 ((' ', 59, ' '), 4 ),
286 ((' ', 60, ' '), 9 ),
287 ((' ', 61, ' '), 8 ),
288 ((' ', 62, ' '), 11),
289 ((' ', 63, ' '), 6 ),
290 ((' ', 64, ' '), 6 ),
291 ((' ', 65, ' '), 6 ),
292 ((' ', 66, ' '), 7 ),
293 ((' ', 67, ' '), 10),
294 ((' ', 68, ' '), 4 ),
295 ((' ', 69, ' '), 14),
296 ((' ', 70, ' '), 6 ),
297 ((' ', 71, ' '), 4 ),
298 ((' ', 72, ' '), 4 ),
299 ((' ', 73, ' '), 4 ),
300 ((' ', 74, ' '), 8, 3), # disordered
301 ((' ', 75, ' '), 8 ),
302 ((' ', 76, ' '), 12),
303 ((' ', 77, ' '), 6 ),
304 ((' ', 78, ' '), 6 ),
305 ((' ', 79, ' '), 4, 4), # disordered
306 ((' ', 80, ' '), 4, ['GLY', 'SER']), # point mut
307 ((' ', 81, ' '), 8, ['ASN', 'LYS']), # point mut
308 ((' ', 82, ' '), 6 ),
309 ((' ', 83, ' '), 9 ),
310 ((' ', 84, ' '), 12),
311 ((' ', 85, ' '), 11),
312 ((' ', 86, ' '), 6 ),
313 ]),
314 ('B', 4, [ (('H_NAG', 1, ' '), 14),
315 (('H_NAG', 2, ' '), 14),
316 (('H_NAG', 3, ' '), 14),
317 (('H_NAG', 4, ' '), 14),
318 ]),
319 (' ', 76, [ (('W', 1, ' '), 1),
320 (('W', 2, ' '), 1),
321 (('W', 3, ' '), 1),
322 (('W', 4, ' '), 1),
323 (('W', 5, ' '), 1),
324 (('W', 6, ' '), 1),
325 (('W', 7, ' '), 1),
326 (('W', 8, ' '), 1),
327 (('W', 9, ' '), 1),
328 (('W', 10, ' '), 1),
329 (('W', 11, ' '), 1),
330 (('W', 12, ' '), 1),
331 (('W', 13, ' '), 1),
332 (('W', 14, ' '), 1),
333 (('W', 15, ' '), 1),
334 (('W', 16, ' '), 1),
335 (('W', 17, ' '), 1),
336 (('W', 18, ' '), 1),
337 (('W', 19, ' '), 1),
338 (('W', 20, ' '), 1),
339 (('W', 21, ' '), 1),
340 (('W', 22, ' '), 1),
341 (('W', 23, ' '), 1),
342 (('W', 24, ' '), 1),
343 (('W', 25, ' '), 1),
344 (('W', 26, ' '), 1),
345 (('W', 27, ' '), 1),
346 (('W', 28, ' '), 1),
347 (('W', 29, ' '), 1),
348 (('W', 30, ' '), 1),
349 (('W', 31, ' '), 1),
350 (('W', 32, ' '), 1),
351 (('W', 33, ' '), 1),
352 (('W', 34, ' '), 1),
353 (('W', 35, ' '), 1),
354 (('W', 36, ' '), 1),
355 (('W', 37, ' '), 1),
356 (('W', 38, ' '), 1),
357 (('W', 39, ' '), 1),
358 (('W', 40, ' '), 1),
359 (('W', 41, ' '), 1),
360 (('W', 42, ' '), 1),
361 (('W', 43, ' '), 1),
362 (('W', 44, ' '), 1),
363 (('W', 45, ' '), 1),
364 (('W', 46, ' '), 1),
365 (('W', 47, ' '), 1),
366 (('W', 48, ' '), 1),
367 (('W', 49, ' '), 1),
368 (('W', 50, ' '), 1),
369 (('W', 51, ' '), 1),
370 (('W', 52, ' '), 1),
371 (('W', 53, ' '), 1),
372 (('W', 54, ' '), 1),
373 (('W', 55, ' '), 1),
374 (('W', 56, ' '), 1),
375 (('W', 57, ' '), 1),
376 (('W', 58, ' '), 1),
377 (('W', 59, ' '), 1),
378 (('W', 60, ' '), 1),
379 (('W', 61, ' '), 1),
380 (('W', 62, ' '), 1),
381 (('W', 63, ' '), 1),
382 (('W', 64, ' '), 1),
383 (('W', 65, ' '), 1),
384 (('W', 66, ' '), 1),
385 (('W', 67, ' '), 1),
386 (('W', 68, ' '), 1),
387 (('W', 69, ' '), 1),
388 (('W', 70, ' '), 1),
389 (('W', 71, ' '), 1),
390 (('W', 72, ' '), 1),
391 (('W', 73, ' '), 1),
392 (('W', 74, ' '), 1),
393 (('W', 75, ' '), 1),
394 (('W', 77, ' '), 1),
395 ])
396 ]
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
397
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
398 for c_idx, chn in enumerate(chain_data):
399 # Check chain ID and length
400 chain = m1.get_list()[c_idx]
4f877613 »
2010-07-05 Use documented assertEqual method in preference of undocumented asser…
401 self.assertEqual(chain.get_id(), chn[0])
402 self.assertEqual(len(chain), chn[1])
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
403 for r_idx, res in enumerate(chn[2]):
404 residue = chain.get_list()[r_idx]
405 # Check residue ID and atom count
4f877613 »
2010-07-05 Use documented assertEqual method in preference of undocumented asser…
406 self.assertEqual(residue.get_id(), res[0])
407 self.assertEqual(len(residue), res[1])
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
408 disorder_lvl = residue.is_disordered()
409 if disorder_lvl == 1:
410 # Check the number of disordered atoms
411 disordered_count = sum(1 for atom in residue
412 if atom.is_disordered())
413 if disordered_count:
4f877613 »
2010-07-05 Use documented assertEqual method in preference of undocumented asser…
414 self.assertEqual(disordered_count, res[2])
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
415 elif disorder_lvl == 2:
416 # Point mutation -- check residue names
4f877613 »
2010-07-05 Use documented assertEqual method in preference of undocumented asser…
417 self.assertEqual(residue.disordered_get_id_list(), res[2])
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
418
062cf979 »
2009-11-18 Parse atom element field in PDB files (Bug 2495)
419 def test_details(self):
420 """Verify details of the parsed example PDB file."""
421 structure = self.structure
422 self.assertEqual(len(structure), 2)
423
424 #First model
425 model = structure[0]
426 self.assertEqual(model.id, 0)
427 self.assertEqual(model.level, "M")
428 self.assertEqual(len(model), 1)
429 chain = model["A"]
430 self.assertEqual(chain.id, "A")
431 self.assertEqual(chain.level, "C")
432 self.assertEqual(len(chain), 1)
433 self.assertEqual(" ".join(residue.resname for residue in chain), "PCA")
434 self.assertEqual(" ".join(atom.name for atom in chain.get_atoms()),
e9b4365d »
2010-12-01 Adapted script to accomodate Atom Element changes
435 "N CA CB CG CD OE C O CA ")
062cf979 »
2009-11-18 Parse atom element field in PDB files (Bug 2495)
436 self.assertEqual(" ".join(atom.element for atom in chain.get_atoms()),
e9b4365d »
2010-12-01 Adapted script to accomodate Atom Element changes
437 "N C C C C O C O CA")
062cf979 »
2009-11-18 Parse atom element field in PDB files (Bug 2495)
438 #Second model
439 model = structure[1]
440 self.assertEqual(model.id, 1)
441 self.assertEqual(model.level, "M")
442 self.assertEqual(len(model), 3)
443 chain = model["A"]
444 self.assertEqual(chain.id, "A")
445 self.assertEqual(chain.level, "C")
446 self.assertEqual(len(chain), 86)
447 self.assertEqual(" ".join(residue.resname for residue in chain),
448 "CYS ARG CYS GLY SER GLN GLY GLY GLY SER THR CYS "
449 "PRO GLY LEU ARG CYS CYS SER ILE TRP GLY TRP CYS "
450 "GLY ASP SER GLU PRO TYR CYS GLY ARG THR CYS GLU "
451 "ASN LYS CYS TRP SER GLY GLU ARG SER ASP HIS ARG "
452 "CYS GLY ALA ALA VAL GLY ASN PRO PRO CYS GLY GLN "
453 "ASP ARG CYS CYS SER VAL HIS GLY TRP CYS GLY GLY "
454 "GLY ASN ASP TYR CYS SER GLY GLY ASN CYS GLN TYR "
455 "ARG CYS")
456 self.assertEqual(" ".join(atom.name for atom in chain.get_atoms()),
457 "C N CA C O CB CG CD NE CZ NH1 NH2 N CA C O CB SG "
458 "N CA C O N CA C O CB OG N CA C O CB CG CD OE1 NE2 "
459 "N CA C O N CA C O N CA C O N CA C O CB OG N CA C "
460 "O CB OG1 CG2 N CA C O CB SG N CA C O CB CG CD N "
461 "CA C O N CA C O CB CG CD1 CD2 N CA C O CB CG CD NE "
462 "CZ NH1 NH2 N CA C O CB SG N CA C O CB SG N CA C O "
463 "CB OG N CA C O CB CG1 CG2 CD1 N CA C O CB CG CD1 "
464 "CD2 NE1 CE2 CE3 CZ2 CZ3 CH2 N CA C O N CA C O CB "
465 "CG CD1 CD2 NE1 CE2 CE3 CZ2 CZ3 CH2 N CA C O CB SG "
466 "N CA C O N CA C O CB CG OD1 OD2 N CA C O CB OG N "
467 "CA C O CB CG CD OE1 OE2 N CA C O CB CG CD N CA C O "
468 "CB CG CD1 CD2 CE1 CE2 CZ OH N CA C O CB SG N CA C "
469 "O N CA C O CB CG CD NE CZ NH1 NH2 N CA C O CB OG1 "
470 "CG2 N CA C O CB SG N CA C O CB CG CD OE1 OE2 N CA "
471 "C O CB CG OD1 ND2 N CA C O CB CG CD CE NZ N CA C O "
472 "CB SG N CA C O CB CG CD1 CD2 NE1 CE2 CE3 CZ2 CZ3 "
473 "CH2 N CA C O CB OG N CA C O N CA C O CB CG CD OE1 "
474 "OE2 N CA C O CB CG CD NE CZ NH1 NH2 N CA C O CB OG "
475 "N CA C O CB CG OD1 OD2 N CA C O CB CG ND1 CD2 CE1 "
476 "NE2 N CA C O CB CG CD NE CZ NH1 NH2 N CA C O CB SG "
477 "N CA C O N CA C O CB N CA C O CB N CA C O CB CG1 "
478 "CG2 N CA C O N CA C O CB CG OD1 ND2 N CA C O CB CG "
479 "CD N CA C O CB CG CD N CA C O CB SG N CA C O N CA "
480 "C O CB CG CD OE1 NE2 N CA C O CB CG OD1 OD2 N CA C "
481 "O CB CG CD NE CZ NH1 NH2 N CA C O CB SG N CA C O "
482 "CB SG N CA C O CB OG N CA C O CB CG1 CG2 N CA C O "
483 "CB CG ND1 CD2 CE1 NE2 N CA C O N CA C O CB CG CD1 "
484 "CD2 NE1 CE2 CE3 CZ2 CZ3 CH2 N CA C O CB SG N CA C "
485 "O N CA C O N CA C O N CA C O CB CG OD1 ND2 N CA C O "
486 "CB CG OD1 OD2 N CA C O CB CG CD1 CD2 CE1 CE2 CZ OH "
487 "N CA C O CB SG N CA C O CB OG N CA C O N CA C O N "
488 "CA C O CB CG OD1 ND2 N CA C O CB SG N CA C O CB CG "
489 "CD OE1 NE2 N CA C O CB CG CD1 CD2 CE1 CE2 CZ OH N "
490 "CA C O CB CG CD NE CZ NH1 NH2 N CA C O CB SG")
491 self.assertEqual(" ".join(atom.element for atom in chain.get_atoms()),
492 "C N C C O C C C N C N N N C C O C S N C C O N C C O "
493 "C O N C C O C C C O N N C C O N C C O N C C O N C C "
494 "O C O N C C O C O C N C C O C S N C C O C C C N C C "
495 "O N C C O C C C C N C C O C C C N C N N N C C O C S "
496 "N C C O C S N C C O C O N C C O C C C C N C C O C C "
497 "C C N C C C C C N C C O N C C O C C C C N C C C C C "
498 "N C C O C S N C C O N C C O C C O O N C C O C O N C "
499 "C O C C C O O N C C O C C C N C C O C C C C C C C O "
500 "N C C O C S N C C O N C C O C C C N C N N N C C O C "
501 "O C N C C O C S N C C O C C C O O N C C O C C O N N "
502 "C C O C C C C N N C C O C S N C C O C C C C N C C C "
503 "C C N C C O C O N C C O N C C O C C C O O N C C O C "
504 "C C N C N N N C C O C O N C C O C C O O N C C O C C "
505 "N C C N N C C O C C C N C N N N C C O C S N C C O N "
506 "C C O C N C C O C N C C O C C C N C C O N C C O C C "
507 "O N N C C O C C C N C C O C C C N C C O C S N C C O "
508 "N C C O C C C O N N C C O C C O O N C C O C C C N C "
509 "N N N C C O C S N C C O C S N C C O C O N C C O C C "
510 "C N C C O C C N C C N N C C O N C C O C C C C N C C "
511 "C C C N C C O C S N C C O N C C O N C C O N C C O C "
512 "C O N N C C O C C O O N C C O C C C C C C C O N C C "
513 "O C S N C C O C O N C C O N C C O N C C O C C O N N "
514 "C C O C S N C C O C C C O N N C C O C C C C C C C O "
515 "N C C O C C C N C N N N C C O C S")
516
6a2d018b »
2010-05-29 PDB: added 2 simple unit tests for header parsing
517
c21f3015 »
2010-06-03 Reordered and renamed test cases in test_PDB.py
518 class ParseReal(unittest.TestCase):
519 """Testing with real PDB files."""
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
520
521 def test_empty(self):
522 """Parse an empty file."""
523 parser = PDBParser()
056c8606 »
2011-07-21 This should fix the test under Windows
524 filenumber, filename = tempfile.mkstemp()
525 os.close(filenumber)
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
526 try:
056c8606 »
2011-07-21 This should fix the test under Windows
527 struct = parser.get_structure('MT', filename)
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
528 # Structure has no children (models)
529 self.assertFalse(len(struct))
530 finally:
056c8606 »
2011-07-21 This should fix the test under Windows
531 os.remove(filename)
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
532
544e4855 »
2010-08-26 Fix for Bug 3096, based on patch from Siong Kong
533 def test_c_n(self):
534 """Extract polypeptides from 1A80."""
535 parser = PDBParser(PERMISSIVE=False)
536 structure = parser.get_structure("example", "PDB/1A8O.pdb")
537 self.assertEqual(len(structure), 1)
538 for ppbuild in [PPBuilder(), CaPPBuilder()]:
539 #==========================================================
540 #First try allowing non-standard amino acids,
541 polypeptides = ppbuild.build_peptides(structure[0], False)
542 self.assertEqual(len(polypeptides), 1)
543 pp = polypeptides[0]
544 # Check the start and end positions
545 self.assertEqual(pp[0].get_id()[1], 151)
546 self.assertEqual(pp[-1].get_id()[1], 220)
547 # Check the sequence
548 s = pp.get_sequence()
549 self.assertTrue(isinstance(s, Seq))
550 self.assertEqual(s.alphabet, generic_protein)
551 #Here non-standard MSE are shown as M
552 self.assertEqual("MDIRQGPKEPFRDYVDRFYKTLRAEQASQEVKNWMTETLLVQ"
553 "NANPDCKTILKALGPGATLEEMMTACQG", str(s))
554 #==========================================================
555 #Now try strict version with only standard amino acids
556 #Should ignore MSE 151 at start, and then break the chain
557 #at MSE 185, and MSE 214,215
558 polypeptides = ppbuild.build_peptides(structure[0], True)
559 self.assertEqual(len(polypeptides), 3)
560 #First fragment
561 pp = polypeptides[0]
562 self.assertEqual(pp[0].get_id()[1], 152)
563 self.assertEqual(pp[-1].get_id()[1], 184)
564 s = pp.get_sequence()
565 self.assertTrue(isinstance(s, Seq))
566 self.assertEqual(s.alphabet, generic_protein)
567 self.assertEqual("DIRQGPKEPFRDYVDRFYKTLRAEQASQEVKNW", str(s))
568 #Second fragment
569 pp = polypeptides[1]
570 self.assertEqual(pp[0].get_id()[1], 186)
571 self.assertEqual(pp[-1].get_id()[1], 213)
572 s = pp.get_sequence()
573 self.assertTrue(isinstance(s, Seq))
574 self.assertEqual(s.alphabet, generic_protein)
575 self.assertEqual("TETLLVQNANPDCKTILKALGPGATLEE", str(s))
576 #Third fragment
577 pp = polypeptides[2]
578 self.assertEqual(pp[0].get_id()[1], 216)
579 self.assertEqual(pp[-1].get_id()[1], 220)
580 s = pp.get_sequence()
581 self.assertTrue(isinstance(s, Seq))
582 self.assertEqual(s.alphabet, generic_protein)
583 self.assertEqual("TACQG", str(s))
1c197449 »
2009-11-18 Adding a small real PDB file containing some HETATM lines for use in …
584
585 def test_strict(self):
586 """Parse 1A8O.pdb file in strict mode."""
587 parser = PDBParser(PERMISSIVE=False)
588 structure = parser.get_structure("example", "PDB/1A8O.pdb")
589 self.assertEqual(len(structure), 1)
590 model = structure[0]
591 self.assertEqual(model.id, 0)
592 self.assertEqual(model.level, "M")
593 self.assertEqual(len(model), 1)
594 chain = model["A"]
595 self.assertEqual(chain.id, "A")
596 self.assertEqual(chain.level, "C")
597 self.assertEqual(len(chain), 158)
598 self.assertEqual(" ".join(residue.resname for residue in chain),
599 "MSE ASP ILE ARG GLN GLY PRO LYS GLU PRO PHE ARG "
600 "ASP TYR VAL ASP ARG PHE TYR LYS THR LEU ARG ALA "
601 "GLU GLN ALA SER GLN GLU VAL LYS ASN TRP MSE THR "
602 "GLU THR LEU LEU VAL GLN ASN ALA ASN PRO ASP CYS "
603 "LYS THR ILE LEU LYS ALA LEU GLY PRO GLY ALA THR "
604 "LEU GLU GLU MSE MSE THR ALA CYS GLN GLY HOH HOH "
605 "HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH "
606 "HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH "
607 "HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH "
608 "HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH "
609 "HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH "
610 "HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH "
611 "HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH HOH "
612 "HOH HOH")
613 self.assertEqual(" ".join(atom.name for atom in chain.get_atoms()),
614 "N CA C O CB CG SE CE N CA C O CB CG OD1 OD2 N CA "
615 "C O CB CG1 CG2 CD1 N CA C O CB CG CD NE CZ NH1 "
616 "NH2 N CA C O CB CG CD OE1 NE2 N CA C O N CA C O "
617 "CB CG CD N CA C O CB CG CD CE NZ N CA C O CB CG "
618 "CD OE1 OE2 N CA C O CB CG CD N CA C O CB CG CD1 "
619 "CD2 CE1 CE2 CZ N CA C O CB CG CD NE CZ NH1 NH2 N "
620 "CA C O CB CG OD1 OD2 N CA C O CB CG CD1 CD2 CE1 "
621 "CE2 CZ OH N CA C O CB CG1 CG2 N CA C O CB CG OD1 "
622 "OD2 N CA C O CB CG CD NE CZ NH1 NH2 N CA C O CB "
623 "CG CD1 CD2 CE1 CE2 CZ N CA C O CB CG CD1 CD2 CE1 "
624 "CE2 CZ OH N CA C O CB CG CD CE NZ N CA C O CB "
625 "OG1 CG2 N CA C O CB CG CD1 CD2 N CA C O CB CG CD "
626 "NE CZ NH1 NH2 N CA C O CB N CA C O CB CG CD OE1 "
627 "OE2 N CA C O CB CG CD OE1 NE2 N CA C O CB N CA C "
628 "O CB OG N CA C O CB CG CD OE1 NE2 N CA C O CB CG "
629 "CD OE1 OE2 N CA C O CB CG1 CG2 N CA C O CB CG CD "
630 "CE NZ N CA C O CB CG OD1 ND2 N CA C O CB CG CD1 "
631 "CD2 NE1 CE2 CE3 CZ2 CZ3 CH2 N CA C O CB CG SE CE "
632 "N CA C O CB OG1 CG2 N CA C O CB CG CD OE1 OE2 N "
633 "CA C O CB OG1 CG2 N CA C O CB CG CD1 CD2 N CA C "
634 "O CB CG CD1 CD2 N CA C O CB CG1 CG2 N CA C O CB "
635 "CG CD OE1 NE2 N CA C O CB CG OD1 ND2 N CA C O CB "
636 "N CA C O CB CG OD1 ND2 N CA C O CB CG CD N CA C "
637 "O CB CG OD1 OD2 N CA C O CB SG N CA C O CB CG CD "
638 "CE NZ N CA C O CB OG1 CG2 N CA C O CB CG1 CG2 "
639 "CD1 N CA C O CB CG CD1 CD2 N CA C O CB CG CD CE "
640 "NZ N CA C O CB N CA C O CB CG CD1 CD2 N CA C O N "
641 "CA C O CB CG CD N CA C O N CA C O CB N CA C O CB "
642 "OG1 CG2 N CA C O CB CG CD1 CD2 N CA C O CB CG CD "
643 "OE1 OE2 N CA C O CB CG CD OE1 OE2 N CA C O CB CG "
644 "SE CE N CA C O CB CG SE CE N CA C O CB OG1 CG2 N "
645 "CA C O CB N CA C O CB SG N CA C O CB CG CD OE1 "
646 "NE2 N CA C O OXT O O O O O O O O O O O O O O O O "
647 "O O O O O O O O O O O O O O O O O O O O O O O O "
648 "O O O O O O O O O O O O O O O O O O O O O O O O "
649 "O O O O O O O O O O O O O O O O O O O O O O O O")
062cf979 »
2009-11-18 Parse atom element field in PDB files (Bug 2495)
650 self.assertEqual(" ".join(atom.element for atom in chain.get_atoms()),
651 "N C C O C C SE C N C C O C C O O N C C O C C C C "
652 "N C C O C C C N C N N N C C O C C C O N N C C O "
653 "N C C O C C C N C C O C C C C N N C C O C C C O "
654 "O N C C O C C C N C C O C C C C C C C N C C O C "
655 "C C N C N N N C C O C C O O N C C O C C C C C C "
656 "C O N C C O C C C N C C O C C O O N C C O C C C "
657 "N C N N N C C O C C C C C C C N C C O C C C C C "
658 "C C O N C C O C C C C N N C C O C O C N C C O C "
659 "C C C N C C O C C C N C N N N C C O C N C C O C "
660 "C C O O N C C O C C C O N N C C O C N C C O C O "
661 "N C C O C C C O N N C C O C C C O O N C C O C C "
662 "C N C C O C C C C N N C C O C C O N N C C O C C "
663 "C C N C C C C C N C C O C C SE C N C C O C O C N "
664 "C C O C C C O O N C C O C O C N C C O C C C C N "
665 "C C O C C C C N C C O C C C N C C O C C C O N N "
666 "C C O C C O N N C C O C N C C O C C O N N C C O "
667 "C C C N C C O C C O O N C C O C S N C C O C C C "
668 "C N N C C O C O C N C C O C C C C N C C O C C C "
669 "C N C C O C C C C N N C C O C N C C O C C C C N "
670 "C C O N C C O C C C N C C O N C C O C N C C O C "
671 "O C N C C O C C C C N C C O C C C O O N C C O C "
672 "C C O O N C C O C C SE C N C C O C C SE C N C C "
673 "O C O C N C C O C N C C O C S N C C O C C C O N "
674 "N C C O O O O O O O O O O O O O O O O O O O O O "
675 "O O O O O O O O O O O O O O O O O O O O O O O O "
676 "O O O O O O O O O O O O O O O O O O O O O O O O "
677 "O O O O O O O O O O O O O O O O O O O O O")
1c197449 »
2009-11-18 Adding a small real PDB file containing some HETATM lines for use in …
678
af5153b8 »
2010-05-29 Added a unit test for PDB model numbers, based on Konstanin Okonechni…
679 def test_model_numbering(self):
680 """Preserve model serial numbers during I/O."""
681 def confirm_numbering(struct):
682 self.assertEqual(len(struct), 20)
683 for idx, model in enumerate(struct):
75dd0b74 »
2010-07-05 Use assertTrue in unit tests (added in Python 2.4) since the earlier …
684 self.assertTrue(model.serial_num, idx + 1)
685 self.assertTrue(model.serial_num, model.id + 1)
af5153b8 »
2010-05-29 Added a unit test for PDB model numbers, based on Konstanin Okonechni…
686 parser = PDBParser()
687 struct1 = parser.get_structure("1mot", "PDB/1MOT.pdb")
688 confirm_numbering(struct1)
689 # Round trip: serialize and parse again
690 io = PDBIO()
691 io.set_structure(struct1)
9039c263 »
2011-07-21 This should fix the test under Windows (part 2)
692 filenumber, filename = tempfile.mkstemp()
693 os.close(filenumber)
af5153b8 »
2010-05-29 Added a unit test for PDB model numbers, based on Konstanin Okonechni…
694 try:
9039c263 »
2011-07-21 This should fix the test under Windows (part 2)
695 io.save(filename)
696 struct2 = parser.get_structure("1mot", filename)
af5153b8 »
2010-05-29 Added a unit test for PDB model numbers, based on Konstanin Okonechni…
697 confirm_numbering(struct2)
698 finally:
9039c263 »
2011-07-21 This should fix the test under Windows (part 2)
699 os.remove(filename)
1c197449 »
2009-11-18 Adding a small real PDB file containing some HETATM lines for use in …
700
fe65e49f »
2013-08-23 Add DSSP unit test.
701
716c5db7 »
2013-02-27 Added unit tests for PDBIO
702 class WriteTest(unittest.TestCase):
703 def setUp(self):
704 warnings.simplefilter('ignore', PDBConstructionWarning)
705 self.parser = PDBParser(PERMISSIVE=1)
706 self.structure = self.parser.get_structure("example", "PDB/1A8O.pdb")
707 warnings.filters.pop()
708
709 def test_pdbio_write_structure(self):
710 """Write a full structure using PDBIO"""
711 io = PDBIO()
712 struct1 = self.structure
713 # Write full model to temp file
714 io.set_structure(struct1)
715 filenumber, filename = tempfile.mkstemp()
716 os.close(filenumber)
717 try:
718 io.save(filename)
719 struct2 = self.parser.get_structure("1a8o", filename)
720 nresidues = len(list(struct2.get_residues()))
721 self.assertEqual(len(struct2), 1)
722 self.assertEqual(nresidues, 158)
723 finally:
724 os.remove(filename)
725
726 def test_pdbio_write_residue(self):
727 """Write a single residue using PDBIO"""
728 io = PDBIO()
729 struct1 = self.structure
730 residue1 = list(struct1.get_residues())[0]
731 # Write full model to temp file
732 io.set_structure(residue1)
733 filenumber, filename = tempfile.mkstemp()
734 os.close(filenumber)
735 try:
736 io.save(filename)
737 struct2 = self.parser.get_structure("1a8o", filename)
738 nresidues = len(list(struct2.get_residues()))
739 self.assertEqual(nresidues, 1)
740 finally:
741 os.remove(filename)
742
743 def test_pdbio_write_custom_residue(self):
744 """Write a chainless residue using PDBIO"""
745 io = PDBIO()
746
747 res = Residue.Residue((' ', 1, ' '), 'DUM', '')
748 atm = Atom.Atom('CA', [0.1, 0.1, 0.1], 1.0, 1.0, ' ', 'CA', 1, 'C')
749 res.add(atm)
750
751 # Write full model to temp file
752 io.set_structure(res)
753 filenumber, filename = tempfile.mkstemp()
754 os.close(filenumber)
755 try:
756 io.save(filename)
757 struct2 = self.parser.get_structure("res", filename)
758 latoms = list(struct2.get_atoms())
759 self.assertEqual(len(latoms), 1)
760 self.assertEqual(latoms[0].name, 'CA')
761 self.assertEqual(latoms[0].parent.resname, 'DUM')
762 self.assertEqual(latoms[0].parent.parent.id, 'A')
763 finally:
764 os.remove(filename)
765
766 def test_pdbio_select(self):
767 """Write a selection of the structure using a Select subclass"""
768
769 # Selection class to filter all alpha carbons
770 class CAonly(Select):
771 """
772 Accepts only CA residues
773 """
774 def accept_atom(self, atom):
775 if atom.name == "CA" and atom.element == "C":
776 return 1
777
778 io = PDBIO()
779 struct1 = self.structure
780 # Write to temp file
781 io.set_structure(struct1)
782 filenumber, filename = tempfile.mkstemp()
783 os.close(filenumber)
784 try:
785 io.save(filename, CAonly())
786 struct2 = self.parser.get_structure("1a8o", filename)
787 nresidues = len(list(struct2.get_residues()))
788 self.assertEqual(nresidues, 70)
789 finally:
790 os.remove(filename)
c21f3015 »
2010-06-03 Reordered and renamed test cases in test_PDB.py
791
b58986ed »
2013-08-27 Fix PDBIO blank occupancy handling
792 def test_pdbio_missing_occupancy(self):
793 """Write PDB file with missing occupancy"""
794
795 from Bio import BiopythonWarning
796 warnings.simplefilter('ignore', BiopythonWarning)
797
798 io = PDBIO()
799 structure = self.parser.get_structure("test", "PDB/occupancy.pdb")
800 io.set_structure(structure)
801 filenumber, filename = tempfile.mkstemp()
802 os.close(filenumber)
803 try:
804 io.save(filename)
805 struct2 = self.parser.get_structure("test", filename)
806 atoms = struct2[0]['A'][(' ', 152, ' ')]
807 self.assertEqual(atoms['N'].get_occupancy(), None)
808 finally:
809 os.remove(filename)
810 warnings.filters.pop()
811
812
c21f3015 »
2010-06-03 Reordered and renamed test cases in test_PDB.py
813 class Exposure(unittest.TestCase):
814 "Testing Bio.PDB.HSExposure."
815 def setUp(self):
816 warnings.simplefilter('ignore', PDBConstructionWarning)
817 pdb_filename = "PDB/a_structure.pdb"
818 structure=PDBParser(PERMISSIVE=True).get_structure('X', pdb_filename)
b5f7c6e4 »
2010-11-03 Don't use warnings.resetwarnings() as it clears all filters (even thi…
819 warnings.filters.pop()
c21f3015 »
2010-06-03 Reordered and renamed test cases in test_PDB.py
820 self.model=structure[1]
821 #Look at first chain only
822 a_residues=list(self.model["A"].child_list)
823 self.assertEqual(86, len(a_residues))
824 self.assertEqual(a_residues[0].get_resname(), "CYS")
825 self.assertEqual(a_residues[1].get_resname(), "ARG")
826 self.assertEqual(a_residues[2].get_resname(), "CYS")
827 self.assertEqual(a_residues[3].get_resname(), "GLY")
828 #...
829 self.assertEqual(a_residues[-3].get_resname(), "TYR")
830 self.assertEqual(a_residues[-2].get_resname(), "ARG")
831 self.assertEqual(a_residues[-1].get_resname(), "CYS")
832 self.a_residues = a_residues
833 self.radius = 13.0
834
835 def test_HSExposureCA(self):
836 """HSExposureCA."""
837 hse = HSExposureCA(self.model, self.radius)
838 residues = self.a_residues
839 self.assertEqual(0, len(residues[0].xtra))
840 self.assertEqual(0, len(residues[1].xtra))
841 self.assertEqual(3, len(residues[2].xtra))
842 self.assertAlmostEqual(0.81250973133184456, residues[2].xtra["EXP_CB_PCB_ANGLE"])
843 self.assertEqual(14, residues[2].xtra["EXP_HSE_A_D"])
844 self.assertEqual(14, residues[2].xtra["EXP_HSE_A_U"])
845 self.assertEqual(3, len(residues[3].xtra))
846 self.assertAlmostEqual(1.3383737, residues[3].xtra["EXP_CB_PCB_ANGLE"])
847 self.assertEqual(13, residues[3].xtra["EXP_HSE_A_D"])
848 self.assertEqual(16, residues[3].xtra["EXP_HSE_A_U"])
849 #...
850 self.assertEqual(3, len(residues[-2].xtra))
851 self.assertAlmostEqual(0.77124014456278489, residues[-2].xtra["EXP_CB_PCB_ANGLE"])
852 self.assertEqual(24, residues[-2].xtra["EXP_HSE_A_D"])
853 self.assertEqual(24, residues[-2].xtra["EXP_HSE_A_U"])
854 self.assertEqual(0, len(residues[-1].xtra))
855
856 def test_HSExposureCB(self):
857 """HSExposureCB."""
858 hse = HSExposureCB(self.model, self.radius)
859 residues = self.a_residues
860 self.assertEqual(0, len(residues[0].xtra))
861 self.assertEqual(2, len(residues[1].xtra))
862 self.assertEqual(20, residues[1].xtra["EXP_HSE_B_D"])
863 self.assertEqual(5, residues[1].xtra["EXP_HSE_B_U"])
864 self.assertEqual(2, len(residues[2].xtra))
865 self.assertEqual(10, residues[2].xtra["EXP_HSE_B_D"])
866 self.assertEqual(18, residues[2].xtra["EXP_HSE_B_U"])
867 self.assertEqual(2, len(residues[3].xtra))
868 self.assertEqual(7, residues[3].xtra["EXP_HSE_B_D"])
869 self.assertEqual(22, residues[3].xtra["EXP_HSE_B_U"])
870 #...
871 self.assertEqual(2, len(residues[-2].xtra))
872 self.assertEqual(14, residues[-2].xtra["EXP_HSE_B_D"])
873 self.assertEqual(34, residues[-2].xtra["EXP_HSE_B_U"])
874 self.assertEqual(2, len(residues[-1].xtra))
875 self.assertEqual(23, residues[-1].xtra["EXP_HSE_B_D"])
876 self.assertEqual(15, residues[-1].xtra["EXP_HSE_B_U"])
877
878 def test_ExposureCN(self):
879 """HSExposureCN."""
880 hse = ExposureCN(self.model, self.radius)
881 residues = self.a_residues
882 self.assertEqual(0, len(residues[0].xtra))
883 self.assertEqual(1, len(residues[1].xtra))
884 self.assertEqual(25, residues[1].xtra["EXP_CN"])
885 self.assertEqual(1, len(residues[2].xtra))
886 self.assertEqual(28, residues[2].xtra["EXP_CN"])
887 self.assertEqual(1, len(residues[3].xtra))
888 self.assertEqual(29, residues[3].xtra["EXP_CN"])
889 #...
890 self.assertEqual(1, len(residues[-2].xtra))
891 self.assertEqual(48, residues[-2].xtra["EXP_CN"])
892 self.assertEqual(1, len(residues[-1].xtra))
893 self.assertEqual(38, residues[-1].xtra["EXP_CN"])
894
fd82a0a7 »
2012-12-06 Add blank lines where needed (PEP8 E302).
895
cf3a92ed »
2010-12-01 Added Test for Atom Element from Atom Name
896 class Atom_Element(unittest.TestCase):
1b0e9633 »
2010-12-03 added one more test for ions.
897 """induces Atom Element from Atom Name"""
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
898
cf3a92ed »
2010-12-01 Added Test for Atom Element from Atom Name
899 def setUp(self):
900 warnings.simplefilter('ignore', PDBConstructionWarning)
e9b4365d »
2010-12-01 Adapted script to accomodate Atom Element changes
901 pdb_filename = "PDB/a_structure.pdb"
cf3a92ed »
2010-12-01 Added Test for Atom Element from Atom Name
902 structure=PDBParser(PERMISSIVE=True).get_structure('X', pdb_filename)
903 warnings.filters.pop()
1b0e9633 »
2010-12-03 added one more test for ions.
904 self.residue = structure[0]['A'][('H_PCA', 1, ' ')]
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
905
cf3a92ed »
2010-12-01 Added Test for Atom Element from Atom Name
906 def test_AtomElement(self):
907 """ Atom Element """
e9b4365d »
2010-12-01 Adapted script to accomodate Atom Element changes
908 atoms = self.residue.child_list
909 self.assertEqual('N', atoms[0].element) # N
910 self.assertEqual('C', atoms[1].element) # Alpha Carbon
911 self.assertEqual('CA', atoms[8].element) # Calcium
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
912
1b0e9633 »
2010-12-03 added one more test for ions.
913 def test_ions(self):
914 """Element for magnesium is assigned correctly."""
915 pdb_filename = "PDB/ions.pdb"
916 structure=PDBParser(PERMISSIVE=True).get_structure('X', pdb_filename)
917 # check magnesium atom
918 atoms = structure[0]['A'][('H_ MG', 1, ' ')].child_list
919 self.assertEqual('MG', atoms[0].element)
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
920
a5cb0954 »
2013-08-06 Improve assignment of PDB atom element from name.
921 def test_hydrogens(self):
922
923 def quick_assign(fullname):
924 return Atom.Atom(fullname.strip(), None, None, None, None,
925 fullname, None).element
926
927 pdb_elements = dict(
928 H=(
929 ' H ', ' HA ', ' HB ', ' HD1', ' HD2', ' HE ', ' HE1', ' HE2',
930 ' HE3', ' HG ', ' HG1', ' HH ', ' HH2', ' HZ ', ' HZ2', ' HZ3',
931 '1H ', '1HA ', '1HB ', '1HD ', '1HD1', '1HD2', '1HE ', '1HE2',
932 '1HG ', '1HG1', '1HG2', '1HH1', '1HH2', '1HZ ', '2H ', '2HA ',
933 '2HB ', '2HD ', '2HD1', '2HD2', '2HE ', '2HE2', '2HG ', '2HG1',
934 '2HG2', '2HH1', '2HH2', '2HZ ', '3H ', '3HB ', '3HD1', '3HD2',
a9c2f38e »
2013-08-06 Test that PDBParser assigns "HE21" as a hydrogen
935 '3HE ', '3HG1', '3HG2', '3HZ ', 'HE21',
a5cb0954 »
2013-08-06 Improve assignment of PDB atom element from name.
936 ),
937 O=(' OH ',),
938 C=(' CH2',),
939 N=(' NH1', ' NH2'),
940 )
941
195c1ac6 »
2013-09-07 Avoid my_dict.iteritems() in tests for Python 3 compatibility.
942 for element, atom_names in pdb_elements.items():
a5cb0954 »
2013-08-06 Improve assignment of PDB atom element from name.
943 for fullname in atom_names:
944 e = quick_assign(fullname)
945 #warnings.warn("%s %s" % (fullname, e))
946 self.assertEqual(e, element)
fd82a0a7 »
2012-12-06 Add blank lines where needed (PEP8 E302).
947
fe65e49f »
2013-08-23 Add DSSP unit test.
948
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
949 class IterationTests(unittest.TestCase):
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
950
5abe9706 »
2010-12-22 added tests for PDB.Structure iteration functions.
951 def setUp(self):
952 self.struc = PDBParser(PERMISSIVE=True).get_structure('X', "PDB/a_structure.pdb")
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
953
5abe9706 »
2010-12-22 added tests for PDB.Structure iteration functions.
954 def test_get_chains(self):
955 """Yields chains from different models separately."""
956 chains = [chain.id for chain in self.struc.get_chains()]
14977ce6 »
2013-10-05 Apply 2to3 ws_comma fixer (white space changes)
957 self.assertEqual(chains, ['A', 'A', 'B', ' '])
5dcf3a87 »
2011-07-17 Unittest for PDB parsing an empty file (Bug #3266)
958
5abe9706 »
2010-12-22 added tests for PDB.Structure iteration functions.
959 def test_get_residues(self):
960 """Yields all residues from all models."""
961 residues = [resi.id for resi in self.struc.get_residues()]
962 self.assertEqual(len(residues), 167)
963
964 def test_get_atoms(self):
965 """Yields all atoms from the structure, excluding duplicates and ALTLOCs which are not parsed."""
966 atoms = ["%12s"%str((atom.id, atom.altloc)) for atom in self.struc.get_atoms()]
967 self.assertEqual(len(atoms), 756)
968
969
1b0e9633 »
2010-12-03 added one more test for ions.
970 #class RenumberTests(unittest.TestCase):
971 # """Tests renumbering of structures."""
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
972 #
1b0e9633 »
2010-12-03 added one more test for ions.
973 # def setUp(self):
974 # warnings.simplefilter('ignore', PDBConstructionWarning)
975 # pdb_filename = "PDB/1A8O.pdb"
976 # self.structure=PDBParser(PERMISSIVE=True).get_structure('X', pdb_filename)
977 # warnings.filters.pop()
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
978 #
1b0e9633 »
2010-12-03 added one more test for ions.
979 # def test_renumber_residues(self):
980 # """Residues in a structure are renumbered."""
981 # self.structure.renumber_residues()
982 # nums = [resi.id[1] for resi in self.structure[0]['A'].child_list]
01e54197 »
2013-09-05 Resolve more print statements in the unit tests.
983 # print(nums)
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
984 #
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
985 # -------------------------------------------------------------
986
fe65e49f »
2013-08-23 Add DSSP unit test.
987
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
988 class TransformTests(unittest.TestCase):
c836f3bb »
2011-08-17 Add test for transform method.
989
990 def setUp(self):
991 self.s = PDBParser(PERMISSIVE=True).get_structure(
992 'X', "PDB/a_structure.pdb")
993 self.m = self.s.get_list()[0]
994 self.c = self.m.get_list()[0]
995 self.r = self.c.get_list()[0]
996 self.a = self.r.get_list()[0]
997
998 def get_total_pos(self, o):
999 """
1000 Returns the sum of the positions of atoms in an entity along
1001 with the number of atoms.
1002 """
1003 if hasattr(o, "get_coord"):
1004 return o.get_coord(), 1
14977ce6 »
2013-10-05 Apply 2to3 ws_comma fixer (white space changes)
1005 total_pos = numpy.array((0.0, 0.0, 0.0))
c836f3bb »
2011-08-17 Add test for transform method.
1006 total_count = 0
1007 for p in o.get_list():
1008 pos, count = self.get_total_pos(p)
1009 total_pos += pos
1010 total_count += count
1011 return total_pos, total_count
1012
1013 def get_pos(self, o):
1014 """
1015 Returns the average atom position in an entity.
1016 """
1017 pos, count = self.get_total_pos(o)
1018 return 1.0*pos/count
1019
1020 def test_transform(self):
1021 """Transform entities (rotation and translation)."""
1022 for o in (self.s, self.m, self.c, self.r, self.a):
14977ce6 »
2013-10-05 Apply 2to3 ws_comma fixer (white space changes)
1023 rotation = rotmat(Vector(1, 3, 5), Vector(1, 0, 0))
1024 translation=numpy.array((2.4, 0, 1), 'f')
c836f3bb »
2011-08-17 Add test for transform method.
1025 oldpos = self.get_pos(o)
1026 o.transform(rotation, translation)
1027 newpos = self.get_pos(o)
5192d13e »
2012-12-04 Fix whitespace before and after operators (PEP8 E221 and E222).
1028 newpos_check = numpy.dot(oldpos, rotation) + translation
c836f3bb »
2011-08-17 Add test for transform method.
1029 for i in range(0, 3):
1030 self.assertAlmostEqual(newpos[i], newpos_check[i])
1031
0d8299a9 »
2011-08-17 Adding copy method for Entities
1032
b1c85978 »
2012-12-04 Trim EOL whitespace (PEP8 W291, W293), batch 3.
1033 class CopyTests(unittest.TestCase):
0d8299a9 »
2011-08-17 Adding copy method for Entities
1034
1035 def setUp(self):
1036 self.s = PDBParser(PERMISSIVE=True).get_structure(
1037 'X', "PDB/a_structure.pdb")
1038 self.m = self.s.get_list()[0]
1039 self.c = self.m.get_list()[0]
1040 self.r = self.c.get_list()[0]
1041 self.a = self.r.get_list()[0]
1042
1043 def test_atom_copy(self):
1044 aa = self.a.copy()
1045 self.assertFalse(self.a is aa)
1046 self.assertFalse(self.a.get_coord() is aa.get_coord())
1047
1048 def test_entitity_copy(self):
1049 """Make a copy of a residue."""
1050 for e in (self.s, self.m, self.c, self.r):
1051 ee = e.copy()
1052 self.assertFalse(e is ee)
1053 self.assertFalse(e.get_list()[0] is ee.get_list()[0])
1054
1055
c0a3d5b5 »
2013-08-27 Move dependency free DSSP testing into test_PDB.py
1056 class DsspTests(unittest.TestCase):
1057 """Tests for DSSP parsing etc which don't need the binary tool.
1058
1059 See also test_DSSP_tool.py for run time testing with the tool.
1060 """
1061 def test_DSSP_file(self):
1062 """Test parsing of pregenerated DSSP"""
1063 dssp, keys = make_dssp_dict("PDB/2BEG.dssp")
1064 self.assertEqual(len(dssp), 130)
1065
5e1d51a2 »
2013-08-30 Finally fix DSSP problem.
1066 def test_DSSP_noheader_file(self):
1067 """Test parsing of pregenerated DSSP missing header information"""
1068 # New DSSP prints a line containing only whitespace and "."
1069 dssp, keys = make_dssp_dict("PDB/2BEG_noheader.dssp")
1070 self.assertEqual(len(dssp), 130)
1071
5d087068 »
2013-11-25 Bio/PDB/NACCESS: Various NACCESS fixes and unit tests
1072 class NACCESSTests(unittest.TestCase):
1073 """Tests for NACCESS parsing etc which don't need the binary tool.
1074
1075 See also test_NACCESS_tool.py for run time testing with the tool.
1076 """
1077 def test_NACCESS_rsa_file(self):
1078 """Test parsing of pregenerated rsa NACCESS file"""
1079 with open("PDB/1A8O.rsa") as rsa:
1080 naccess = process_rsa_data(rsa)
1081 self.assertEqual(len(naccess), 66)
1082
1083 def test_NACCESS_asa_file(self):
1084 """Test parsing of pregenerated asa NACCESS file"""
1085 with open("PDB/1A8O.asa") as asa:
1086 naccess = process_asa_data(asa)
1087 self.assertEqual(len(naccess), 524)
c0a3d5b5 »
2013-08-27 Move dependency free DSSP testing into test_PDB.py
1088
95b29986 »
2009-04-23 Adding unittest version of test_PDB.py converted by Eric Talevich (Bu…
1089 if __name__ == '__main__':
1090 runner = unittest.TextTestRunner(verbosity=2)
1091 unittest.main(testRunner=runner)
Something went wrong with that request. Please try again.