-
Notifications
You must be signed in to change notification settings - Fork 0
/
x_pdb_modif_resid.py
executable file
·91 lines (80 loc) · 2.87 KB
/
x_pdb_modif_resid.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
import sys,os,re
##########################################################################
#
# Peter M.U. Ung @ MSSM
#
# v1. 18.08.15
# v2. 20.02.18 - remove disordered atoms but keep the "A" variant
# replace modified PDB residues with the standard AA, and remove disordered
# atoms while keeping the "A" variant. The modified residues are hidden
# with REMARK
#
##########################################################################
def ReplacePDBModifiedAA( in_pdb, out_pdb ):
name = in_pdb.split('.pdb')[0]
with open(in_pdb, 'r') as fi:
Lines = [ l for l in fi ]
Edited = []
for l in Lines:
### If found atoms with alternate conformation, keep "A" only
if re.search('^ATOM|^HETATM|^ANISOU', l) and l[16] != ' ':
if l[16] == 'A':
l = l[:16]+' '+l[17:]
else:
Edited.append('REMARK CON '+l)
continue
##################
### If found hetero-group, check
if not re.search(r'HETATM', l):
Edited.append(l)
else:
## Replace phospho- residues (Ser, Thr, Tyr, His)
if re.search(r'SEP|TPO|T8L|PTR|NEP', l):
Edited.append('REMARK HET '+l)
m = re.sub('HETATM', 'ATOM ', l)
if re.search(r'SEP', l):
n = re.sub('SEP', 'SER', m)
if re.search(r'TPO|T8L', l):
n = re.sub('TPO|T8L', 'THR', m)
if re.search(r'PTR', m):
n = re.sub('PTR', 'TYR', m)
if re.search(r'NEP', l):
n = re.sub('NEP', 'HIS', m)
if not re.search(r' P |O1P|O2P|O3P| S1 ', n):
Edited.append(n)
## Replace MSE with MET
elif re.search(r'MSE|MHO', l):
Edited.append('REMARK HET '+l)
m = re.sub('HETATM', 'ATOM ', l)
n = re.sub(r'MSE|MHO', 'MET', m)
o = re.sub('SE ', ' SD', n)
if not re.search(r'OD1', o):
Edited.append(o)
## Replace modified CYS
elif re.search(r'CSO|OCS|CSX|CSD|2CO|CME|CSS', l):
Edited.append('REMARK HET '+l)
m = re.sub('HETATM', 'ATOM ', l)
n = re.sub(r'CSO|OCS|CSX|CSD|2CO|CME|CSS', 'CYS', m)
if not re.search(r' OD|OD1|OD2|OD3| OE| SD| CE| CZ| OH', n):
Edited.append(n)
## Replace modified LYS
elif re.search(r'KCX|ALY|MLY', l):
Edited.append('REMARK HET '+l)
m = re.sub('HETATM', 'ATOM ', l)
n = re.sub(r'KCX|ALY|MLY', 'LYS', m)
if not re.search(r'CX |OQ1|OQ2|CH3|CH |OH |CH1|CH2', n):
Edited.append(n)
## Replace modified ARG
elif re.search(r'NMM', l):
Edited.append('REMARK HET '+l)
m = re.sub('HETATM', 'ATOM ', l)
n = re.sub(r'NMM', 'ARG', m)
if not re.search(r'CAA', m):
Edited.append(n)
else:
Edited.append(l)
with open(out_pdb, 'w') as fo:
for l in Edited:
fo.write(l)
########################################################################