1
2
3
4
5
6
7
8
9 import re
10
11 """A collection of residues from a PDB structure."""
12
13 _pdbid_re = re.compile(r"^(\w\w\w\w)(?:$|\s+|_)(.*)")
14 _fragment_re = re.compile(r"\(?(\w:)?(-?\w*)-?(-?\w*)\)?(.*)")
15
16
18 """A collection of residues from a PDB structure.
19
20 This class provides code to work with SCOP domain definitions. These
21 are concisely expressed as one or more chain fragments. For example,
22 "(1bba A:10-20,B:)" indicates residue 10 through 20 (inclusive) of
23 chain A, and every residue of chain B in the pdb structure 1bba. The pdb
24 id and brackets are optional. In addition "-" indicates every residue of
25 a pbd structure with one unnamed chain.
26
27 Start and end residue ids consist of the residue sequence number and an
28 optional single letter insertion code. e.g. "12", "-1", "1a", "1000"
29
30
31 pdbid -- An optional PDB id, e.g. "1bba"
32
33 fragments -- A sequence of tuples (chainID, startResID, endResID)
34
35 """
36
38 self.pdbid = ''
39 self.fragments = ()
40 if str is not None:
41 self._parse(str)
42
44 str = str.strip()
45
46
47 m = _pdbid_re.match(str)
48 if m is not None:
49 self.pdbid = m.group(1)
50 str = m.group(2)
51
52 if str=='' or str == '-' or str=='(-)':
53 return
54
55 fragments = []
56 for l in str.split(","):
57 m = _fragment_re.match(l)
58 if m is None:
59 raise ValueError("I don't understand the format of %s" % l)
60 chain, start, end, postfix = m.groups()
61
62 if postfix != "":
63 raise ValueError("I don't understand the format of %s" % l)
64
65 if chain:
66 if chain[-1] != ':':
67 raise ValueError("I don't understand the chain in %s" % l)
68 chain = chain[:-1]
69 else:
70 chain =""
71
72 fragments.append((chain, start, end))
73 self.fragments = tuple(fragments)
74
91