1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """
25 Write cleaned peptide_chains as PDB for import into XPlor
26
27 This is vintage code. See L{Biskit.PDBCleaner} for a more recent
28 version. The writing of single chains could easily be done with PDBModel.
29
30 @todo: re-implement pdb2xplor with PDBCleaner / PDBModel
31 """
32 from Scientific.IO.PDB import *
33 import commands
34 import os.path
35
36 import tools as T
37
39 """
40 Take chain from chainCleaner; write single PDB with
41 unique segementID and no chainID
42 """
43
45 """
46 Take chains from ChainCleaner and write pdb files.
47 File names are created from segid of each chain + '_seg.pdb'
48
49 @param path: output path for PDB files
50 @type path: string
51 """
52 self.path = T.absfile( path )
53
54
56 """
57 Create pdb file and write header.
58
59 @param chain: Scientific.IO.PDB.PeptideChain object
60 @type chain: chain object
61 @param fname: file name
62 @type fname: string
63
64 @return: handle of open file
65 @rtype: PDBFile
66 """
67 f = PDBFile(fname, 'w')
68 try:
69 for c in chain.comments:
70 f.writeComment(c)
71 except:
72 pass
73 return f
74
75
77 """
78 Remove TER record from PDB.
79
80 @param fname: name of existing file.
81 @type fname: string
82 """
83 try:
84
85 path = os.path.dirname( fname )
86 command = 'egrep -v "^TER " %s > %s/temp.pdb'%( fname, path )
87 commands.getstatusoutput(command)
88 os.rename('%s/temp.pdb'%path, fname)
89 except (OSError):
90 T.errWriteln("Error removing 'TER' statement from %s: ")
91 T.errWriteln( T.lastError() )
92
93
95 """
96 Write single chain as PDB. File name will be segid + '_seg.pdb'.
97
98 @param chain: Scientific.IO.PDB.PeptideChain object
99 @type chain: chain object
100 """
101 if (chain <> None):
102 try:
103
104 fname = self.path + '/' + chain.segment_id + "_seg.PDB"
105 file = self._startPDB(chain, fname)
106 chain.writeToFile(file)
107 file.close()
108 self.removeTER(file.file.file.name)
109 return 1
110
111 except (IOError):
112 T.errWriteln("Error writing chain to file %s:" % fname)
113 T.errWriteln( T.lastError() )
114
115 return 0
116
117
118
119
120
121 import Biskit.test as BT
122
123 -class Test(BT.BiskitTest):
124 """Test ChainWriter"""
125
127 self.fname = T.testRoot() + '/rec/1A2P_rec_original.pdb'
128 self.outPath = T.tempDir()
129
149
151 T.tryRemove( self.outPath + '/1A2P_waters.pdb' )
152 T.tryRemove( self.outPath + '/1A2A_seg.PDB' )
153
154
155
156 if __name__ == '__main__':
157
158 BT.localTest()
159