-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize_native.py
65 lines (55 loc) · 1.65 KB
/
normalize_native.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
def get_residue(line):
column = 25
residue = ''
while (True):
if line[column] != ' ':
residue += line[column]
column -= 1
else:
break
return residue
def spaces(number):
spaces = ''
spaces += ' ' * number
return spaces
def change_residue(line, line_number):
column = 25
deletions = 0
while (True):
if line[column] != ' ':
line = line[:column] + line[column + 1:]
column -= 1
deletions += 1
else:
break
line_number = str(line_number)
pre_spaces = spaces(deletions - len(line_number))
return line[:column] + pre_spaces + line_number + line[column + 1:]
def normalize_native(file_name):
file_path = 'pdb/' + file_name
original = open(file_path, 'r')
split_path = file_path.split('.pdb')
normalized_path = split_path[0] + '_normalized.pdb'
normalized = open(normalized_path, 'w')
residue = 1
previous_residue = ''
for line in original:
if line.startswith('ATOM'):
current_residue = get_residue(line)
if previous_residue != '' and current_residue != previous_residue:
residue += 1
line = change_residue(line, residue)
previous_residue = current_residue
normalized.write(line)
original.close()
normalized.close()
# os.remove(file_path)
# os.rename(normalized_path, file_path)
input_files = [
'T0761-D1.pdb',
'T0765-D1.pdb',
'T0781-D2.pdb'
]
for input_file in input_files:
normalize_native(input_file)