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
17 """A collection of residues from a PDB structure.
18
19 This class provides code to work with SCOP domain definitions. These
20 are concisely expressed as a one or more chain fragments. For example,
21 "(1bba A:10-20,B:)" indicates residue 10 through 20 (inclusive) of
22 chain A, and every residue of chain B in the pdb structure 1bba. The pdb
23 id and brackets are optional. In addition "-" indicates every residue of
24 a pbd structure with one unnamed chain.
25
26 Start and end residue ids consist of the residue sequence number and an
27 optional single letter insertion code. e.g. "12", "-1", "1a", "1000"
28
29
30 pdbid -- An optional PDB id, e.g. "1bba"
31
32 fragments -- A sequence of tuples (chainID, startResID, endResID)
33
34 """
35
36
38 self.pdbid = ''
39 self.fragments = ()
40 if str is not None : self._parse(str)
41
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
88