Skip to content

Commit

Permalink
Removed strip() calls to avoid trimming ATOM/HETATM lines
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoRodrigues committed May 10, 2016
1 parent 9af2c4e commit 9e63aac
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 38 deletions.
5 changes: 2 additions & 3 deletions pdb_b.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ def _alter_bfactor(fhandle, bfactor):
#bfactor = str(round(bfactor, 2)).rjust(6)
bfactor = "{0:>6.2f}".format(bfactor)
for line in fhandle:
line = line.strip()
if coord_re.match(line):
yield line[:60] + bfactor + line[66:] + '\n'
yield line[:60] + bfactor + line[66:]
else:
yield line + '\n'
yield line

if __name__ == '__main__':

Expand Down
5 changes: 2 additions & 3 deletions pdb_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ def _alter_chain(fhandle, chain_id):
chain_id = chain_id

for line in fhandle:
line = line.strip()
if coord_re.match(line):
yield line[:21] + chain_id[0] + line[22:] + '\n'
yield line[:21] + chain_id[0] + line[22:]
else:
yield line + '\n'
yield line

if __name__ == '__main__':
# Check Input
Expand Down
5 changes: 2 additions & 3 deletions pdb_chainxseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ def _swap_chainxseg(fhandle):
fhandle = fhandle

for line in fhandle:
line = line.strip()
if coord_re.match(line):
size_of_line = len(line)
# Pad short lines
if size_of_line < 80:
padding = 80 - size_of_line
line = line + ' '*padding
yield line[:72] + line[21].ljust(4) + line[76:] + '\n'
yield line[:72] + line[21].ljust(4) + line[76:]
else:
yield line + '\n'
yield line

if __name__ == '__main__':
# Check Input
Expand Down
2 changes: 1 addition & 1 deletion pdb_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _join_pdb(pdb_list):
pdb_data.append('MODEL {0:>4d}'.format(i_model))
with open(pdb_f, 'r') as handle:
for line in handle:
line = line.strip()
line = line.strip('\n')
if coord_re.match(line):
pdb_data.append(line)
model_auids.add(auid(line))
Expand Down
5 changes: 2 additions & 3 deletions pdb_occ.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ def _alter_occupancy(fhandle, occup):
coord_re = re.compile('^(ATOM|HETATM)')
occup = str(round(occup, 2)).rjust(6)
for line in fhandle:
line = line.strip()
if coord_re.match(line):
yield line[:54] + occup + line[60:] + '\n'
yield line[:54] + occup + line[60:]
else:
yield line + '\n'
yield line

if __name__ == '__main__':

Expand Down
5 changes: 2 additions & 3 deletions pdb_reatom.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ def _renumber_pdb_atoms(fhandle, satomi):
satomi = satomi

for line in fhandle:
line = line.strip()
if coord_re.match(line):
yield line[:6] + str(satomi).rjust(5) + line[11:] + '\n'
yield line[:6] + str(satomi).rjust(5) + line[11:]
satomi += 1
else:
yield line + '\n'
yield line

if __name__ == '__main__':

Expand Down
5 changes: 2 additions & 3 deletions pdb_reres.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ def _renumber_pdb_residue(fhandle, sresid):
resi = sresid - 1
prev_resi = None
for line in fhandle:
line = line.strip()
if line.startswith(('ATOM', 'HETATM', 'TER')):
if line[22:26] != prev_resi:
prev_resi = line[22:26]
resi += 1

yield line[:22] + str(resi).rjust(4) + line[26:] + '\n'
yield line[:22] + str(resi).rjust(4) + line[26:]
else:
yield line + '\n'
yield line

if __name__ == '__main__':

Expand Down
5 changes: 2 additions & 3 deletions pdb_rplchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ def _alter_chain(fhandle, ori_chain, new_chain):
new_chain = ' '

for line in fhandle:
line = line.strip()
if coord_re.match(line) and line[21] == ori_chain:
yield line[:21] + new_chain + line[22:] + '\n'
yield line[:21] + new_chain + line[22:]
else:
yield line + '\n'
yield line

if __name__ == '__main__':
# Check Input
Expand Down
5 changes: 2 additions & 3 deletions pdb_seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ def _alter_segid(fhandle, seg_id):
seg_id = seg_id[0:4].ljust(4)

for line in fhandle:
line = line.strip()
if coord_re.match(line):
yield line[:72] + seg_id + line[76:] + '\n'
yield line[:72] + seg_id + line[76:]
else:
yield line + '\n'
yield line

if __name__ == '__main__':
# Check Input
Expand Down
3 changes: 1 addition & 2 deletions pdb_selchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ def _select_chain(fhandle, chain_id):
chain_id = chain_id

for line in fhandle:
line = line.strip()
if coord_re.match(line) and line[21] == chain_id:
yield line + '\n'
yield line

if __name__ == '__main__':
# Check Input
Expand Down
3 changes: 1 addition & 2 deletions pdb_selseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ def _select_seg(fhandle, seg_id):
seg_id = seg_id

for line in fhandle:
line = line.strip()
if coord_re.match(line) and line[72:76].strip() == seg_id:
yield line + '\n'
yield line

if __name__ == '__main__':
# Check Input
Expand Down
3 changes: 1 addition & 2 deletions pdb_splitchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def _extract_chains(fhandle):

for line in fhandle:
if coord_re.match(line):
line = line.strip()
# ATOM/HETATM line
if prev_chain != line[21]:
if not line[21] in chain_atoms:
Expand All @@ -67,7 +66,7 @@ def _extract_chains(fhandle):
prev_chain = line[21]
chain_ids.append(line[21])
else:
cur_chain.append(line + '\n')
cur_chain.append(line)

# Output chains to files
for c_id in chain_ids:
Expand Down
3 changes: 1 addition & 2 deletions pdb_splitmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ def _extract_models(fhandle):
output_handle = None

for line in fhandle:
line = line.strip()
if coord_re.match(line):
# ATOM/HETATM line
output_handle.write(line + '\n')
output_handle.write(line)
elif line.startswith('MODEL'):
model_no = line.split()[-1]
output_handle = open(fname_root + '_' + model_no + '.pdb', 'w')
Expand Down
5 changes: 2 additions & 3 deletions pdb_splitseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def _extract_segments(fhandle):
prev_segment, segment_atoms = None, []

for line in fhandle:
line = line.strip()
if coord_re.match(line):
# ATOM/HETATM line
if prev_segment != line[72:76]:
Expand All @@ -66,10 +65,10 @@ def _extract_segments(fhandle):
output_handle.write('END\n')
output_handle.close()
segment_atoms = []
segment_atoms.append(line + '\n')
segment_atoms.append(line)
prev_segment = line[72:76]
else:
segment_atoms.append(line + '\n')
segment_atoms.append(line)

# Output last chain to file
output_handle = open(fname_root + '_' + segment_atoms[-1][72:76].strip() + '.pdb', 'w')
Expand Down
3 changes: 1 addition & 2 deletions pdb_striphet.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ def _remove_hetatm(fhandle):

coord_re = re.compile('^ATOM')
for line in fhandle:
line = line.strip()
if coord_re.match(line):
yield line + '\n'
yield line

if __name__ == '__main__':

Expand Down

0 comments on commit 9e63aac

Please sign in to comment.