-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpdbxyz-for-amoeba.py
2154 lines (2131 loc) · 113 KB
/
pdbxyz-for-amoeba.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## This is the version meant for AMOEBA parameter sets!
## !! NOTE !!
## This version will only work if the nucleic acid strands are explicitly
## labeled for 5' and 3' ends (e.g., using A3, A5, RA3, RA5, DA3, DA5)
## In the future, I would love for the convert_names call to have
## subfunctions for N Term/C Term, DNA/RNA, NSA
## And even have an AMOBA call too (so it's just one function with if statements)
## Probably want to consider N/C term as common with the except of proline & N/H
import parmed as pmd
import numpy as np
import pandas as pd
import re
import sys
infile="PDB_test_NC.pdb"
outfile="PDB_test_NC.xyz"
# param_file="amoebapro13.prm"
# param_file="amoebabio09.prm"
param_file="amoebabio18.prm"
atom_lines="atom-lines.txt"
test_csv="test.csv"
def clean_atoms_AMOEBA(temp):
"""AMOEBA doesn't use 4-letter hydrogens because everything is awful."""
for atom in temp.atoms:
if atom.name in ('HD11', 'HD12', 'HD13'):
atom.name = 'HD1'
if atom.name in ('HD21', 'HD22', 'HD23'):
atom.name = 'HD2'
if atom.name in ('HG11', 'HG12', 'HG13'):
atom.name = 'HG1'
if atom.name in ('HG21', 'HG22', 'HG23'):
atom.name = 'HG2'
if atom.name in ('HE21', 'HE22'):
atom.name = 'HE2'
# if atom.name == 'H2\'1':
# atom.name = '1H2\''
# if atom.name == 'H2\'2':
# atom.name = '2H2\''
## Terminal hydrogens on DNA are different
## in the stinking parameter file, so fix it.
for atom in temp.atoms:
if atom.name == 'H5\'':
atom.name = 'H5\'1'
# atom.name = '1H5\''
## AMOEBA18 doesn't distinguish this
if atom.name == 'H5\'\'':
atom.name = 'H5\'2'
# atom.name = '2H5\''
if atom.name == 'H2\'':
atom.name = 'H2\'1'
# atom.name = '1H2\''
## AMOEBA19 doesn't distinguish this
if atom.name == 'H2\'\'':
atom.name = 'H2\'2'
# atom.name = '2H2\''
if atom.name == 'HO3\'':
atom.name = 'H3T'
if atom.name == 'HO5\'':
atom.name = 'H5T'
if atom.name == 'HO2\'':
atom.name = 'HO\'2'
# if atom.name == 'H5\'1':
# atom.name = '1H5\''
# if atom.name == 'H5\'2':
# atom.name = '2H5\''
## Deal with C and N Terminals
## If there's a terminal OXT for the protein, use as CTERM
for residue in temp.residues:
for atom in residue.atoms:
## Standardize ions
## If the +/- is last character, don't escape it.
if atom.name in ('K+', 'K', 'K\+1', 'k', 'k+'):
atom.name = 'K'
residue.name = 'K'
elif atom.name in ('NA', 'NA+', 'NA\+1', 'NA1+', 'Na', 'Na+',
'Na1+'):
atom.name = 'NA'
residue.name = 'NA'
elif atom.name in ('MG', 'MG2', 'MG2+', 'Mg2', 'MG\+2', 'Mg2+',
'Mg\+2'):
atom.name = 'MG'
residue.name = 'MG'
elif atom.name in ('ZN', 'ZN2', 'ZN2+', 'Zn2', 'ZN\+2', 'Zn2+',
'Zn\+2'):
atom.name = 'ZN'
residue.name = 'ZN'
elif atom.name in ('CL', 'CL-', 'CL1-', 'Cl', 'CL\-1', 'Cl1-',
'Cl\-1'):
atom.name = 'CL'
residue.name = 'CL'
else:
continue
## Assume HIE as default
if residue.name in ('HIS'):
print("Assuming HIE as the default protonation for HIS", residue.number)
print(" If you get an error for HIE HD1, please verify if that")
print(" residue should be either HID or HIP and modify your input.\n")
residue.name = 'HIE'
## This just makes the deoxy/ribo distinction cleaner & addresses the
## "new"/AMBER naming scheme
elif residue.name in ('A'):
residue.name = 'RA'
elif residue.name in ('A3'):
residue.name = 'RA3'
elif residue.name in ('A5'):
residue.name = 'RA5'
elif residue.name in ('C'):
residue.name = 'RC'
elif residue.name in ('C3'):
residue.name = 'RC3'
elif residue.name in ('C5'):
residue.name = 'RC5'
elif residue.name in ('G'):
residue.name = 'RG'
elif residue.name in ('G3'):
residue.name = 'RG3'
elif residue.name in ('G5'):
residue.name = 'RG5'
elif residue.name in ('U'):
residue.name = 'RU'
elif residue.name in ('U3'):
residue.name = 'RU3'
elif residue.name in ('U5'):
residue.name = 'RU5'
## If there's an H3 in a protein residue, use NTERM
if residue.name in ('ALA', 'ARG', 'ASH', 'ASN', 'ASP', 'CYM', 'CYS',
'CYX', 'GLH', 'GLN', 'GLU', 'GLY', 'HID', 'HIE', 'HIP', 'ILE',
'LEU', 'LYN', 'LYS', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TRP', 'TYD',
'TYR', 'VAL'):
for atom in residue.atoms:
if atom.name == 'H3':
residue.name = 'N'+residue.name
## And CTERM for OXT
elif atom.name == 'OXT':
residue.name = 'C'+residue.name
## Mercileslly taken from Mark's pdbtinker.py
def load_pdb(filename, AMOEBA):
"""Loads in PDB using parmed and sets atom masses to zero. Atom masses are
then used to store the Tinker atom types for XYZ conversion."""
system = pmd.load_file(filename)
for atom in system.atoms:
atom.mass = 0
if AMOEBA == True:
clean_atoms_AMOEBA(system)
else:
# clean_atoms(system)
print("Try another version of this script, please.\n\
This one hasn't passed all the AMBER-based tests.")
return system
## grep "^atom" param_file > atom_lines
def read_prm(param_file, atom_lines):
"""Based on using grep to locate atom lines."""
parm_atom_lines = []
pattern = '(?i)^atom ' # case insensitive, starts line
# keep the space to not match "atomic" in AMOEBA
for line in open(param_file).readlines():
if re.match(pattern, line):
parm_atom_lines.append(line)
## Write a file of all the atom lines for use later
with open(atom_lines, 'w') as filehandle:
filehandle.writelines("%s" % line for line in parm_atom_lines)
filehandle.close()
def fix_params(atom_lines,test_csv):
"""Read the atom_lines file into a pandas object. Rewrite the story
(quoted) section into PDB residue names and atom names through as series
of string replacements. This will work well for AMBER or AMOEBA sets."""
lines = pd.read_csv(atom_lines, sep='[\s]{2,}', header=None,
names=["what","T_type","T_atom_class","A_atom_type","A_names","element",
"mass","connectivity"], engine='python')
##
## Remove the double quotes in the A_names column
lines.A_names = lines.A_names.replace({'"':''}, regex=True)
##
## Determine if AMOEBA or AMBER based on aspartic acid
## While they vary by the space, this *should* check user-adjusted lines
## Labeled Aspartate in AMOEBA sets, but aspartic acid in AMBER
## AMBER version needs to be ASP, AMOEBA is ASH
trial = lines[lines['A_names'].str.contains(r'(?i)Aspartate', regex=True)]
if trial.A_names.empty == False:
print("Processing as AMOEBA parameters.\n")
AMOEBA = True
lines.A_names = lines.A_names.str.replace(r'(?i)Aspartic Acid', 'ASH',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Aspartate', 'ASP',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Glutamate', 'GLU',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Glutamic Acid', 'GLH',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)N\-MeAmide Cap', 'XXX',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Amide Cap', 'XXX',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)N\-Terminal PRO',
'NPRO', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)C\-Terminal COOH',
'XXX', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)N\-Terminal NH3\+',
'NTE N', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)N\-Terminal H3N\+',
'NTE HN', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)C\-Terminal COO-',
'CTEO', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)C\-Terminal',
'CTE', regex=True)
### FIGURE OUT DNA/RNA
## Start with Ns that change
lines.A_names = lines.A_names.str.replace(r'(?i)Adenine N9 RNA',
'RA N9', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Adenine N9 DNA',
'DA N9', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cytosine N1 RNA',
'RC N1', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cytosine N1 DNA',
'DC N1', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Guanine N9 RNA',
'RG N9', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Guanine N9 DNA',
'DG N9', regex=True)
## General
lines.A_names = lines.A_names.str.replace(r'(?i)Adenine',
'DRA', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cytosine',
'DRC', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Guanine',
'DRG', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Thymine',
'DT', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Uracil',
'RU', regex=True)
## Specific to amoebabio18
lines.A_names = lines.A_names.str.replace(r'(?i)R\-5\'\-Hydroxyl O5\'T',
'RX5 O5T', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R\-3\'\-Hydroxyl O3\'T',
'RX3 O3T', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D\-5\'\-Hydroxyl O5\'T',
'DX5 O5T', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D\-3\'\-Hydroxyl O3\'T',
'DX3 O3T', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R-Phosphodiester',
'RP', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D-Phosphodiester',
'DP', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Phosphodiester',
'DRP', regex=True)
#
else:
print("Processing as AMBER parameters.")
AMOEBA = False
## The default params list incorrectly uses Glutamic Acid to mean GLU
## NOT glutamate. If you need the actual glutamic acid, you need to add
## params for GLH
lines.A_names = lines.A_names.str.replace(r'(?i)Glutamic Acid', 'GLU',
regex=True)
##
## Replace names of special residues (use the ?i regex to ignore case)
## Histidine
lines.A_names = lines.A_names.str.replace(r'(?i)Histidine \(HD\)', 'HID',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Histidine \(HE\)', 'HIE',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Histidine \(\+\)', 'HIP',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)HIS \(HD\)', 'HID',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)HIS \(HE\)', 'HIE',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)HIS \(\+\)', 'HIP',
regex=True)
## Cysteine
lines.A_names = lines.A_names.str.replace(r'(?i)Cysteine \(\-SH\)', 'CYS',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cystine \(\-SS\-\)', 'CYX',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cysteine Anion', 'CYM',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cystine', 'CYX',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)CYS \(\-SH\)', 'CYS',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)CYS \(\-SS\-\)', 'CYX',
regex=True)
## Lysine
lines.A_names = lines.A_names.str.replace(r'(?i)Lysine \(NH2\)', 'LYN',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Lysine \(Neutral\)', 'LYN',
regex=True)
## Tyrosine
lines.A_names = lines.A_names.str.replace(r'(?i)Tyrosine Anion', 'TYD',
regex=True)
## Asp
lines.A_names = lines.A_names.str.replace(r'(?i)Aspartic Acid \(COOH\)',
'ASH', regex=True)
## Caps and Termini
lines.A_names = lines.A_names.str.replace(r'(?i)Acetyl Cap', 'ACE',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)N\-MeAmide Cap', 'NME',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)N\-MeAmide', 'NME',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)N\-Term ', 'N',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)C\-Term ', 'C',
regex=True)
## Atypical residues
lines.A_names = lines.A_names.str.replace(r'(?i)Ornithine', 'ORN',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)MethylAlanine', 'AIB',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Pyroglutamate', 'PCA',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Acetyl', 'ACE',
regex=True)
##
## Replace standards with 3 letter codes
lines.A_names = lines.A_names.str.replace(r'(?i)Aspartic Acid', 'ASP',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Phenylalanine', 'PHE',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Alanine', 'ALA',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Arginine', 'ARG',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Asparagine', 'ASN',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cysteine', 'CYS',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Glutamine', 'GLN',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Glycine', 'GLY',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Histidine', 'HIS',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Isoleucine', 'ILE',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Leucine', 'LEU',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Lysine', 'LYS',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Methionine', 'MET',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Proline', 'PRO',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Serine', 'SER',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Threonine', 'THR',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Tryptophan', 'TRP',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Tyrosine', 'TYR',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Valine', 'VAL',
regex=True)
##
## RNA
lines.A_names = lines.A_names.str.replace(r'(?i)R-Adenosine', 'RA',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R-Guanosine', 'RG',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R-Cytosine', 'RC',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R-Uracil', 'RU',
regex=True)
# lines.A_names = lines.A_names.str.replace(r'(?i)R\-Phosphodiester', 'RX',
# regex=True)
## The O5' and HO5' have same name in prm file; address it
lines.A_names = lines.A_names.str.replace(r'(?i)R\-5\'\-Hydroxyl O5\'',
'RX5 HO5\'', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R\-5\'\-Hydroxyl', 'RX5',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R\-5\'\-Phosphate', 'RX5',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R\-3\'\-Phosphate', 'RX3',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R\-3\'\-Hydroxyl O3\'',
'RX3 HO3\'', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)R\-3\'\-Hydroxyl', 'RX3',
regex=True)
##
## DNA
lines.A_names = lines.A_names.str.replace(r'(?i)D-Adenosine', 'DA',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D-Guanosine', 'DG',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D-Cytosine', 'DC',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D-Thymine', 'DT',
regex=True)
# lines.A_names = lines.A_names.str.replace(r'(?i)D-Phosphodiester', 'DX',
# regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D\-5\'\-Hydroxyl O5\'T',
'DX5 O5\'', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D\-5\'\-Hydroxyl', 'DX5',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D\-5\'\-Phosphate', 'DX5',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D\-3\'\-Hydroxyl O3\'T',
'DX3 O3\'', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D\-3\'\-Hydroxyl', 'DX3',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)D\-3\'\-Phosphate', 'DX3',
regex=True)
## Change how HO'5 and HO'3 appear
lines.A_names = lines.A_names.str.replace(r'(?i)HO\'5', 'HO5\'',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)HO\'3', 'HO3\'',
regex=True)
##
## AMOEBA nucleics...
##
## Deal with Amoebabio09 pyrimadine and purines
## Based on https://stackoverflow.com/questions/45308569/python-regex-match-and-replace-beginning-and-end-of-string-but-keep-the-middle
lines.A_names = lines.A_names.replace(to_replace='^(.*? )?(.*?)( \(CU\))$', value=r'RCU \2', regex=True)
lines.A_names = lines.A_names.replace(to_replace='^R(.*? )?(.*?)( \(AG\))$', value=r'RAG \2', regex=True)
lines.A_names = lines.A_names.replace(to_replace='^(.*? )?(.*?)( \(CT\))$', value=r'DCT \2', regex=True)
lines.A_names = lines.A_names.replace(to_replace='^D(.*? )?(.*?)( \(AG\))$', value=r'DAG \2', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Deoxyribose', 'DX',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Ribose', 'RX',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)HO\'5', 'H5T', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)HO\'3', 'H3T', regex=True)
##
## Do the same with water
lines.A_names = lines.A_names.str.replace(r'(?i)TIP3P Oxygen', 'WAT O',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)TIP3P Hydrogen', 'WAT H',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)AMOEBA Water', 'WAT',
regex=True)
##
## Remove the word "Ion"
lines.A_names = lines.A_names.replace({' Ion':''}, regex=True)
## Do the same with ions
lines.A_names = lines.A_names.str.replace(r'(?i)Lithium', 'LI',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Sodium', 'NA', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Potassium', 'K',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Rubidium', 'RB', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cesium', 'CS', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Beryllium', 'BE',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Magnesium', 'MG',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Calcium', 'CA',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Zinc', 'ZN', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Fluoride', 'F', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Chloride', 'CL',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Bromide', 'BR', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Iodide', 'I', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Barium', 'BA', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Strontium', 'SR',
regex=True)
## Now standardize them for string search
lines.A_names = lines.A_names.str.replace(r'(?i)Li\+', 'LI', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Na\+', 'NA', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)K\+', 'K', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Rb\+', 'RB', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cs\+', 'CS', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Be\+', 'BE', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Mg\+2', 'MG', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Ca\+2', 'CA', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Zn\+2', 'ZN', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)F\-', 'F', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Cl\-', 'CL', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Br\-', 'BR', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)I\-', 'I', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Ba\+2', 'BA', regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)Sr\+2', 'SR', regex=True)
##
## User-defined
## The search string is what is listed in the string of the prm file's
## atom line for a given atom type and the replace string is the ResName
## in the PDB
# lines.A_names = lines.A_names.str.replace(r'(?i)DUP -Phosphate', 'DUP',
# regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)DUP-Uracil', 'DUP',
regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)DGP and DCP PO4', 'DXP',
regex=True)
# lines.A_names = lines.A_names.str.replace(r'(?i)DUP-Uracil', 'CTP',
# regex=True)
lines.A_names = lines.A_names.str.replace(r'(?i)DUP -Phosphate', 'CTP',
regex=True)
##
## Print the new lines for testing
#lines.to_csv(test_csv, index=False, encoding='utf8')
## Now split the column into two columns
convert = lines['A_names'].str.split(" ", n=1, expand=True)
## Add those new columns back into the atom lines
lines['ResName'] = convert[0]
lines['AtomName'] = convert[1]
## Print the new lines for testing
lines.to_csv(test_csv, index=False, encoding='utf8')
return lines, AMOEBA
def convert_names_AMOEBA(system, lines):
"""For every atom, find lines matching the residue name in the
pandas_object. From those lines, check for lines that match the atom name.
If a match isn't found, check through the known naming problems. Update the
atom mass with the TINKER type if a match is found; if no match is found,
keep the atom mass as zero. This is intended for AMOEBA parameter sets,
because they default to ALA.
"""
print(
'''If I didn't find residues, they'll be listed here:
Residue Name | Atom Name | Search ResName | Search Atom Name
''')
for residue in system.residues:
for atom in residue.atoms:
## Set RES_NAME so that you don't mess with weird copies and can
## Overwrite it for N/C TERM atoms in loop
RES_NAME = residue.name
test_name = atom.name
#############################################
## Deal with NTERM... ##
#############################################
if residue.name in ('NALA', 'NARG', 'NASH', 'NASN', 'NASP', 'NCYM',
'NCYS', 'NCYX', 'NGLH', 'NGLN', 'NGLU', 'NGLY', 'NHID', 'NHIE',
'NHIP', 'NHIS', 'NILE', 'NLEU', 'NLYN', 'NLYS', 'NMET', 'NPHE',
'NSER', 'NTHR', 'NTRP', 'NTYD', 'NTYR', 'NVAL'):
# It's HN for N-Terminal
if atom.name in ('H1', 'H2', 'H3'):
res_test = lines[lines.ResName == 'NTE']
atom_test = res_test[res_test.AtomName == 'HN']
elif atom.name == 'N':
res_test = lines[lines.ResName == 'NTE']
atom_test = res_test[res_test.AtomName == 'N']
else:
RES_NAME = residue.name[1:]
elif residue.name == 'NPRO':
if atom.name in ('N'):
res_test = lines[lines.ResName == 'NPRO']
atom_test = res_test[res_test.AtomName == 'NH2+']
elif atom.name in ('H1', 'H2', 'H3'):
res_test = lines[lines.ResName == 'NPRO']
atom_test = res_test[res_test.AtomName == 'H2N+']
elif atom.name in ('CA', 'C', 'O', 'HA', 'CD', 'HD'):
test_name = atom.name
res_test = lines[lines.ResName == residue.name]
atom_test = res_test[res_test.AtomName == test_name]
else:
RES_NAME = residue.name[1:]
elif residue.name in ('CALA', 'CARG', 'CASH', 'CASN', 'CASP',
'CCYM', 'CCYS', 'CCYX', 'CGLH', 'CGLN', 'CGLU', 'CGLY', 'CHID',
'CHIE', 'CHIP', 'CHIS', 'CILE', 'CLEU', 'CLYN', 'CLYS', 'CMET',
'CPHE', 'CPRO', 'CSER', 'CTHR', 'CTRP', 'CTYD', 'CTYR', 'CVAL'):
if atom.name in ('OXT','C'):
# It's HN for N-Terminal
test_RN = 'CTEO'
test_name = atom.name
res_test = lines[lines.ResName == test_RN]
## Use the first letter for OXT vs C because of how param
## file is written....
atom_test = res_test[res_test.A_atom_type == test_name[0]]
else:
RES_NAME = residue.name[1:]
if RES_NAME in ('ALA', 'ARG', 'ASH', 'ASN', 'ASP', 'CYS',\
'CYM', 'CYX', 'GLH', 'GLN', 'GLU', 'GLY', 'HID', 'HIE', 'HIP',\
'HIS', 'ILE', 'LEU', 'LYN', 'LYS', 'MET', 'PHE', 'PRO',\
'SER', 'THR', 'TRP', 'TYD', 'TYR', 'VAL'):
test_name = atom.name
res_test = lines[lines.ResName == RES_NAME]
atom_test = res_test[res_test.AtomName == test_name]
#############################################
## Deal with AMOEBA ALA Standard... ##
#############################################
# IGNORE Proline, Glycine, Cysteine Anion (CYM), & N-TERM
if RES_NAME in ('ALA'):
if atom.name in ('HB1', 'HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H'):
test_name = 'HN'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('ARG'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('NH1', 'NH2'):
test_name = 'NH'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_name = 'HN'
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HG2', 'HG3'):
test_name = 'HG'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HD2', 'HD3'):
test_name = 'HD'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HH11', 'HH12', 'HH21', 'HH22'):
test_name = 'HH'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('ASH','TRP'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H','HN'):
test_name = 'HN'
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2','HB3'):
test_name = 'HB'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
else:
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('ASN'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('ASP'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('OD1', 'OD2'):
test_name = 'OD'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('CYM'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('CB', 'HB'):
test_RN = 'CYS'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('SG'):
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('CYS'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('CYX'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('CB'):
test_RN = 'CYS'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('GLH'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H','HN'):
test_name = 'HN'
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HG2', 'HG3'):
test_name = 'HG'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('GLN'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HG2', 'HG3'):
test_name = 'HG'
atom_test = res_test[res_test.AtomName == test_name]
else:
test_RN = RES_NAME
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('GLU'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('OE1', 'OE2'):
test_name = 'OE'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HG2', 'HG3'):
test_name = 'HG'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('GLY'):
if atom.name in ('H', 'HN'):
test_name = 'HN'
atom_test = res_test[res_test.AtomName == test_name]
if atom.name in ('HA2', 'HA3'):
test_name = 'HA'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('HIE','HIP','HID'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_RN = RES_NAME
test_name = 'HB'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
else:
test_RN = RES_NAME
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('ILE'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('CD1', 'CD2'):
test_name = 'CD'
atom_test = res_test[res_test.AtomName == test_name]
## Might need condition for HD
elif atom.name in ('HD1', 'HD2', 'HD3'):
test_name = 'HD'
atom_test = res_test[res_test.AtomName == test_name]
## Deal with Amoebabio09 not labeling HG1 and HG2, but
## rather relying on order
elif atom.name in ('HG1', 'HG2'):
test_RN = 'ILE'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
if atom_test.empty == True:
test_name = 'HG'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
## If there's not 1 match, select the first row
if len(atom_test) > 1:
atom_test = atom_test.iloc[0]
elif atom.name in ('CG1', 'CG2'):
test_RN = 'ILE'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
if atom_test.empty == True:
test_name = 'CG'
atom_test = res_test[res_test.AtomName == test_name]
## If there's not 1 match, select the first row
if len(atom_test) > 1:
atom_test = atom_test.iloc[0]
elif RES_NAME in ('LEU'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('CD1', 'CD2'):
test_name = 'CD'
atom_test = res_test[res_test.AtomName == test_name]
## Might need condition for HB
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HD1', 'HD2'):
test_name = 'HD'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('LYN', 'LYS'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H', 'HN'):
test_RN = 'ALA'
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_RN = RES_NAME
test_name = 'HB'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HZ1', 'HZ2', 'HZ3'):
test_RN = RES_NAME
## Why it's not HZ is yet another thing to ask the
## TINKER developers
test_name = 'HN'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HD2', 'HD3'):
test_RN = RES_NAME
test_name = 'HD'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HE2', 'HE3'):
test_RN = RES_NAME
test_name = 'HE'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HG2', 'HG3'):
test_RN = RES_NAME
test_name = 'HG'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('MET'):
test_RN = RES_NAME
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H','HN'):
test_name = 'HN'
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HE1', 'HE2', 'HE3'):
test_name = 'HE'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HG2', 'HG3'):
test_name = 'HG'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('PHE'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H','HN'):
test_name = 'HN'
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('CE1', 'CE2'):
test_name = 'CE'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('CD1', 'CD2'):
test_name = 'CD'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HE1', 'HE2'):
test_name = 'HE'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HD1', 'HD2'):
test_name = 'HD'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('PRO'):
if atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
## Might need condition for HG
elif atom.name in ('HG2', 'HG3'):
test_name = 'HG'
atom_test = res_test[res_test.AtomName == test_name]
## Might need condition for HD
elif atom.name in ('HD2', 'HD3'):
test_name = 'HD'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('SER'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H','HN'):
test_name = 'HN'
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('HB2', 'HB3'):
test_name = 'HB'
atom_test = res_test[res_test.AtomName == test_name]
elif RES_NAME in ('THR'):
if atom.name in ('N','CA','C','O','HA'):
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('H','HN'):
test_name = 'HN'
test_RN = 'ALA'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
## Named differently between AMOEBA versions
elif atom.name in ('OG1'):
test_RN = 'THR'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
if atom_test.empty == True:
test_name = 'O'
atom_test = res_test[res_test.AtomName == test_name]
elif atom.name in ('CG2'):
test_RN = 'THR'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
if atom_test.empty == True:
test_name = 'CG'
atom_test = res_test[res_test.AtomName == test_name]
## Deal with Amoebabio09 not labeling HG1 and HG2, but
## rather relying on order
elif atom.name in ('HG1', 'HG2'):
test_RN = 'THR'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
if atom_test.empty == True:
test_name = 'HG'
res_test = lines[lines.ResName == test_RN]
atom_test = res_test[res_test.AtomName == test_name]
## If there's not 1 match, select the first row
if len(atom_test) > 1: