forked from bio-phys/cnt-gaff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acpype.py
executable file
·3590 lines (3192 loc) · 143 KB
/
acpype.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
#!/usr/bin/env python
from __future__ import print_function
from datetime import datetime
from shutil import copy2
from shutil import rmtree
import traceback
import signal
import time
import optparse
import math
import os
import pickle
import sys
import subprocess as sub
import re
"""
Requirements: Python 2.6 or higher or Python 3.x
Antechamber (from AmberTools preferably)
OpenBabel (optional, but strongly recommended)
This code is released under GNU General Public License V3.
<<< NO WARRANTY AT ALL!!! >>>
It was inspired by:
- amb2gmx.pl (Eric Sorin, David Mobley and John Chodera)
and depends on Antechamber and Openbabel
- YASARA Autosmiles:
http://www.yasara.org/autosmiles.htm (Elmar Krieger)
- topolbuild (Bruce Ray)
- xplo2d (G.J. Kleywegt)
For Antechamber, please cite:
1. Wang, J., Wang, W., Kollman P. A.; Case, D. A. "Automatic atom type and
bond type perception in molecular mechanical calculations". Journal of
Molecular Graphics and Modelling , 25, 2006, 247260.
2. Wang, J., Wolf, R. M.; Caldwell, J. W.; Kollman, P. A.; Case, D. A.
"Development and testing of a general AMBER force field". Journal of
Computational Chemistry, 25, 2004, 1157-1174.
If you use this code, I am glad if you cite:
SOUSA DA SILVA, A. W. & VRANKEN, W. F.
ACPYPE - AnteChamber PYthon Parser interfacE.
BMC Research Notes 2012, 5:367 doi:10.1186/1756-0500-5-367
http://www.biomedcentral.com/1756-0500/5/367
Alan Wilter Sousa da Silva, D.Sc.
Bioinformatician, UniProt, EMBL-EBI
Hinxton, Cambridge CB10 1SD, UK.
>>http://www.ebi.ac.uk/~awilter<<
alanwilter _at_ gmail _dot_ com
"""
svnId = '$Id: acpype.py 7828 2014-08-27 18:33:08Z alanwilter $'
try:
svnRev, svnDate, svnTime = svnId.split()[2:5]
except:
svnRev, svnDate, svnTime = '0', '0', '0'
year = datetime.today().year
tag = "%s %s Rev: %s" % (svnDate, svnTime, svnRev)
lineHeader = \
'''
| ACPYPE: AnteChamber PYthon Parser interfacE v. %s (c) %s AWSdS |
''' % (tag, year)
frameLine = (len(lineHeader) - 2) * '='
header = '%s%s%s' % (frameLine, lineHeader, frameLine)
# TODO:
# Howto Charmm and Amber with NAMD
# Howto build topology for a modified amino acid
# CYANA topology files
# List of Topology Formats created by acpype so far:
outTopols = ['gmx', 'cns', 'charmm']
qDict = {'mopac': 0, 'divcon': 1, 'sqm': 2}
# Residues that are not solute, to be avoided when balancing charges in
# amb2gmx mode
ionOrSolResNameList = ['Cl-', 'Na+', 'K+', 'CIO', 'Cs+', 'IB', 'Li+', 'MG2',
'Rb+', 'WAT', 'MOH', 'NMA']
leapGaffFile = 'leaprc.gaff'
# leapAmberFile = 'leaprc.ff99SB' # 'leaprc.ff10' and 'leaprc.ff99bsc0' has extra Atom Types not in parm99.dat
leapAmberFile = 'leaprc.ff12SB'
# "qm_theory='AM1', grms_tol=0.0002, maxcyc=999, tight_p_conv=1, scfconv=1.d-10,"
# "AM1 ANALYT MMOK GEO-OK PRECISE"
cal = 4.184
Pi = 3.141593
qConv = 18.222281775 # 18.2223
radPi = 57.295780 # 180/Pi
maxDist = 3.0
minDist = 0.5
maxDist2 = maxDist ** 2 # squared Ang.
minDist2 = minDist ** 2 # squared Ang.
diffTol = 0.01
dictAmbAtomType2AmbGmxCode = \
{'BR': '1', 'C': '2', 'CA': '3', 'CB': '4', 'CC': '5', 'CK': '6', 'CM': '7', 'CN': '8', 'CQ': '9',
'CR': '10', 'CT': '11', 'CV': '12', 'CW': '13', 'C*': '14', 'Ca': '15', 'F': '16', 'H': '17',
'HC': '18', 'H1': '19', 'H2': '20', 'H3': '21', 'HA': '22', 'H4': '23', 'H5': '24', 'HO': '25',
'HS': '26', 'HW': '27', 'HP': '28', 'I': '29', 'Cl': '30', 'Na': '31', 'IB': '32', 'Mg': '33',
'N': '34', 'NA': '35', 'NB': '36', 'NC': '37', 'N2': '38', 'N3': '39', 'N*': '40', 'O': '41',
'OW': '42', 'OH': '43', 'OS': '44', 'O2': '45', 'P': '46', 'S': '47', 'SH': '48', 'CU': '49',
'FE': '50', 'K': '51', 'Rb': '52', 'Cs': '53', 'Li': '56', 'Zn': '57', 'Sr': '58', 'Ba': '59',
'MCH3A': 'MCH3A', 'MCH3B': 'MCH3B', 'MNH2': 'MNH2', 'MNH3': 'MNH3', 'MW': 'MW'}
dictOplsAtomType2OplsGmxCode = \
{'Ac3+': ['697'], 'Am3+': ['699'], 'Ar': ['Ar', '097'], 'Ba2+': ['414'],
'Br': ['722', '730'], 'Br-': ['402'],
'CT': ['064', '076', '122', '135', '136', '137', '138', '139', '148', '149', '152', '157', '158', '159', '161', '173', '174', '175', '181', '182', '183', '184', '206', '207', '208', '209', '210', '211', '212', '213', '214', '215', '216', '217', '218', '219', '220', '223', '224', '225', '229', '230', '242', '243', '244', '256', '257', '258', '259', '273', '274', '275', '276', '291', '292', '293', '294', '297', '305', '306', '307', '308', '331', '371', '373', '375', '391', '396', '421', '431', '443', '448', '453', '455', '458', '461', '468', '476', '482', '484', '486', '490', '491', '492', '498', '499', '505', '515', '516', '645', '670', '671', '672', '673', '674', '675', '676', '677', '678', '679', '680', '681', '701', '725', '747', '748', '755', '756', '757', '758', '762', '764', '765', '766', '774', '775', '776', '782', '783', '903', '904', '905', '906', '907', '908', '912', '913', '914', '915', '942', '943', '944', '945', '951', '957', '959', '960', '961', '962', '963', '964'],
'CA': ['053', '145', '147', '166', '199', '221', '228', '260', '263', '266', '302', '312', '315', '317', '336', '351', '362', '380', '457', '460', '463', '472', '488', '521', '522', '523', '528', '532', '533', '538', '539', '551', '582', '590', '591', '592', '593', '604', '605', '606', '607', '608', '609', '610', '611', '612', '625', '644', '647', '648', '649', '650', '651', '652', '714', '716', '718', '720', '724', '727', '729', '731', '735', '736', '737', '738', '739', '742', '752', '768', '916', '917', '918'],
'C3': ['007', '010', '036', '039', '063', '065', '067', '068', '069', '070', '080', '088', '090', '092', '096', '106', '107', '109', '126', '132', '415', '418', '425', '429'],
'C': ['001', '017', '026', '058', '095', '131', '231', '234', '235', '247', '252', '267', '320', '322', '334', '366', '378', '470', '471', '772', '952'],
'C2': ['005', '009', '015', '016', '019', '022', '027', '028', '031', '034', '037', '056', '057', '061', '071', '081', '089', '091', '093', '110'],
'CT_2': ['223B', '224B', '225B', '246', '283', '284', '285', '292B', '293B', '295', '298', '299', '906B', '912B'],
'CM': ['141', '142', '143', '227', '323', '324', '337', '338', '381', '382', '517', '518', '708'],
'CW': ['508', '514', '543', '552', '561', '567', '575', '583', '588', '637'],
'CB': ['050', '349', '350', '364', '365', '501', '595', '623', '624'],
'CH': ['006', '008', '014', '025', '029', '030', '060', '073'],
'CZ': ['261', '423', '754', '925', '927', '928', '929', '931'],
'CO': ['189', '191', '193', '195', '197', '198'],
'C_2': ['232', '233', '277', '280', '465'],
'CR': ['506', '509', '558', '572', '634'],
'CQ': ['347', '531', '621', '642'],
'CV': ['507', '560', '574', '636'],
'CY': ['711', '712', '713', '733'],
'CS': ['544', '568', '589'],
'CK': ['353', '627'], 'CN': ['502', '594'], 'CP': ['043', '048'], 'CU': ['550', '581'],
'CT_3': ['245', '296'], 'C=': ['150', '178'], 'CD': ['011', '075'],
'C4': ['066'], 'C7': ['077'], 'C8': ['074'], 'C9': ['072'], 'CX': ['510'],
'C!': ['145B'], 'C*': ['500'], 'C+': ['700'], 'C_3': ['271'],
'CC': ['045'], 'CF': ['044'], 'CG': ['049'], 'CT_4': ['160'],
'Ca2+': ['412'],
'Cl': ['123', '151', '226', '264'],
'Cl-': ['401', '709'],
'Cs+': ['410'], 'Cu2+': ['Cu2+'], 'Eu3+': ['705'],
'F': ['164', '719', '721', '726', '728', '786', '956', '965'],
'F-': ['400'], 'Fe2+': ['Fe2+'], 'Gd3+': ['706'],
'HA': ['146', '316', '318', '389', '524', '525', '526', '529', '534', '535', '536', '540', '541', '546', '547', '554', '555', '556', '563', '564', '565', '569', '570', '576', '577', '578', '584', '585', '586', '597', '598', '599', '600', '601', '602', '613', '614', '615', '616', '617', '618', '619', '629', '630', '631', '638', '639', '640', '643', '653', '654', '655', '656', '715', '717', '740', '741', '746'],
'HC': ['140', '144', '153', '156', '165', '176', '185', '190', '192', '194', '196', '255', '279', '282', '329', '330', '332', '344', '372', '374', '376', '392', '416', '419', '422', '426', '430', '432', '444', '449', '454', '456', '459', '462', '469', '477', '483', '485', '487', '702', '710', '759', '763', '777', '778', '779', '784', '911', '926', '930', '950', '958'],
'H': ['004', '013', '041', '047', '128', '240', '241', '250', '254', '314', '325', '327', '339', '342', '343', '357', '358', '360', '367', '369', '383', '385', '387', '388', '428', '479', '481', '504', '513', '545', '553', '562', '596', '632', '744', '745', '909', '910'],
'H3': ['021', '052', '055', '104', '105', '289', '290', '301', '304', '310', '941', '955'],
'HO': ['024', '079', '155', '163', '168', '170', '172', '188', '270', '435'],
'HS': ['033', '086', '087', '204', '205'],
'HW': ['112', '114', '117', '119', '796'],
'H4': ['345', '390'], 'H5': ['355', '359'],
'He': ['130'], 'I': ['732'], 'I-': ['403'], 'K+': ['408'], 'Kr': ['098'],
'LP': ['433', '797'], 'La3+': ['703'], 'Li+': ['404', '406'],
'MCH3A': ['MCH3A'], 'MCH3B': ['MCH3B'], 'MNH2': ['MNH2'], 'MNH3': ['MNH3'],
'MW': ['MW', '115'], 'Mg2+': ['411'],
'NA': ['040', '046', '319', '321', '333', '354', '361', '377', '379', '503', '512', '542', '548', '557', '587', '628'],
'NC': ['311', '335', '346', '348', '363', '520', '527', '530', '537', '603', '620', '622', '641', '646'],
'N': ['003', '012', '094', '237', '238', '239', '249', '251', '265', '478', '480', '787'],
'N3': ['020', '101', '102', '103', '286', '287', '288', '309', '427', '940', '953'],
'N2': ['051', '054', '300', '303', '313', '341', '356', '368', '386', '743'],
'NB': ['042', '352', '511', '549', '559', '573', '580', '626', '635'],
'N*': ['319B', '333B', '354B', '377B'],
'NT': ['127', '900', '901', '902'],
'NZ': ['262', '424', '750', '753'],
'NO': ['760', '767'], 'NY': ['749', '751'],
'Na+': ['405', '407'], 'Nd3+': ['704'], 'Ne': ['129'],
'OS': ['062', '108', '179', '180', '186', '395', '442', '447', '452', '467', '473', '566', '571', '579', '773'],
'O': ['002', '059', '236', '248', '253', '326', '328', '340', '370', '384', '771', '788'],
'OH': ['023', '078', '154', '162', '167', '169', '171', '187', '268', '420', '434'],
'O2': ['018', '125', '272', '394', '441', '446', '451', '954'],
'OW': ['111', '113', '116', '118', '795'],
'O_2': ['278', '281', '466'],
'OY': ['475', '494', '497'],
'OL': ['120'], 'ON': ['761'], 'OU': ['437'], 'O_3': ['269'],
'P': ['393', '440', '445', '450', '785'],
'P+': ['781'], 'Rb+': ['409'],
'S': ['035', '038', '084', '085', '124', '202', '203', '222', '633'],
'SH': ['032', '082', '083', '200', '201', '417', '734'],
'SI': ['SI'], 'SY': ['474'], 'SY2': ['493'], 'SZ': ['496'], 'Sr2+': ['413'],
'Th4+': ['698'], 'U': ['436'], 'Xe': ['099'], 'Yb3+': ['707'], 'Zn2+': ['Zn2+']}
# reverse dictOplsAtomType2OplsGmxCode
oplsCode2AtomTypeDict = {}
for k, v in list(dictOplsAtomType2OplsGmxCode.items()):
for code in v:
oplsCode2AtomTypeDict[code] = k
# if code in oplsCode2AtomTypeDict.keys():
# oplsCode2AtomTypeDict[code].append(k)
# else:
# oplsCode2AtomTypeDict[code] = [k]
# Cross dictAmbAtomType2AmbGmxCode with dictOplsAtomType2OplsGmxCode & add H1,HP,H2
dictAtomTypeAmb2OplsGmxCode = {'H1': ['140', '1.00800'], 'HP': ['140', '1.00800'], 'H2': ['140', '1.00800']}
dictOplsMass = {'SY2': ['32.06000'], 'Zn2+': ['65.37000'], 'CQ': ['12.01100'], 'CP': ['12.01100'], 'Nd3+': ['144.24000'], 'Br-': ['79.90400'], 'Cu2+': ['63.54600'], 'Br': ['79.90400'], 'H': ['1.00800'], 'P': ['30.97376'], 'Sr2+': ['87.62000'], 'ON': ['15.99940'], 'OL': ['0.00000'], 'OH': ['15.99940'], 'OY': ['15.99940'], 'OW': ['15.99940'], 'OU': ['15.99940'], 'OS': ['15.99940'], 'Am3+': ['243.06000'], 'HS': ['1.00800'], 'HW': ['1.00800'], 'HO': ['1.00800'], 'HC': ['1.00800'], 'HA': ['1.00800'], 'O2': ['15.99940'], 'Ca2+': ['40.08000'], 'Th4+': ['232.04000'], 'He': ['4.00260'], 'C': ['12.01100'], 'Cs+': ['132.90540'], 'O': ['15.99940'], 'Gd3+': ['157.25000'], 'S': ['32.06000'], 'P+': ['30.97376'], 'La3+': ['138.91000'], 'H3': ['1.00800'], 'H4': ['1.00800'], 'MNH2': ['0.00000'], 'MW': ['0.00000'], 'NB': ['14.00670'], 'K+': ['39.09830'], 'Ne': ['20.17970'], 'Rb+': ['85.46780'], 'C+': ['12.01100'], 'C*': ['12.01100'], 'NO': ['14.00670'], 'CT_4': ['12.01100'], 'NA': ['14.00670'], 'C!': ['12.01100'], 'NC': ['14.00670'], 'NZ': ['14.00670'], 'CT_2': ['12.01100'], 'CT_3': ['12.01100'], 'NY': ['14.00670'], 'C9': ['14.02700'], 'C8': ['13.01900'], 'C=': ['12.01100'], 'Yb3+': ['173.04000'], 'C3': ['15.03500', '12.01100'], 'C2': ['14.02700'], 'C7': ['12.01100'], 'C4': ['16.04300'], 'CK': ['12.01100'], 'Cl-': ['35.45300'], 'N*': ['14.00670'], 'CH': ['13.01900'], 'CO': ['12.01100'], 'CN': ['12.01100'], 'CM': ['12.01100'], 'F': ['18.99840'], 'CC': ['12.01100'], 'CB': ['12.01100'], 'CA': ['12.01100'], 'CG': ['12.01100'], 'CF': ['12.01100'], 'N': ['14.00670'], 'CZ': ['12.01100'], 'CY': ['12.01100'], 'CX': ['12.01100'], 'Ac3+': ['227.03000'], 'CS': ['12.01100'], 'CR': ['12.01100'], 'N2': ['14.00670'], 'N3': ['14.00670'], 'CW': ['12.01100'], 'CV': ['12.01100'], 'CU': ['12.01100'], 'CT': ['12.01100'], 'SZ': ['32.06000'], 'SY': ['32.06000'], 'Cl': ['35.45300'], 'NT': ['14.00670'], 'O_2': ['15.99940'], 'Xe': ['131.29300'], 'SI': ['28.08000'], 'SH': ['32.06000'], 'Eu3+': ['151.96000'], 'F-': ['18.99840'], 'MNH3': ['0.00000'], 'H5': ['1.00800'], 'C_3': ['12.01100'], 'C_2': ['12.01100'], 'I-': ['126.90450'], 'LP': ['0.00000'], 'I': ['126.90450'], 'Na+': ['22.98977'], 'Li+': ['6.94100'], 'U': ['0.00000'], 'MCH3A': ['0.00000'], 'MCH3B': ['0.00000'], 'CD': ['13.01900', '12.01100'], 'O_3': ['15.99940'], 'Kr': ['83.79800'], 'Fe2+': ['55.84700'], 'Ar': ['39.94800'], 'Mg2+': ['24.30500'], 'Ba2+': ['137.33000']}
for ambKey in dictAmbAtomType2AmbGmxCode:
if ambKey in dictOplsAtomType2OplsGmxCode:
dictAtomTypeAmb2OplsGmxCode[ambKey] = dictOplsAtomType2OplsGmxCode[ambKey] + list(dictOplsMass[ambKey])
# learnt from 22 residues test.
dictAtomTypeAmb2OplsGmxCode = {'HS': ['204', '1.008'], 'HP': ['140', '1.008'], 'HO': ['155', '168', '1.008'], 'HC': ['140', '1.008'], 'HA': ['146', '1.008'], 'O2': ['272', '15.9994'], 'C*': ['500', '12.011'], 'NA': ['503', '512', '14.0067'], 'NB': ['511', '14.0067'], 'CB': ['501', '12.011'], 'C': ['235', '271', '12.011'], 'CN': ['502', '12.011'], 'CM': ['302', '12.011'], 'CC': ['507', '508', '510', '12.011'], 'H': ['240', '241', '290', '301', '304', '310', '504', '513', '1.008'], 'CA': ['145', '166', '12.011'], 'O': ['236', '15.9994'], 'N': ['237', '238', '239', '14.0067'], 'S': ['202', '32.06'], 'CR': ['506', '509', '12.011'], 'N2': ['300', '303', '14.0067'], 'N3': ['287', '309', '14.0067'], 'CW': ['508', '510', '514', '12.011'], 'CV': ['507', '12.011'], 'CT': ['135', '136', '137', '149', '157', '158', '206', '209', '210', '223B', '224B', '245', '246', '274', '283', '284', '285', '292', '292B', '293B', '296', '307', '308', '505', '12.011'], 'OH': ['154', '167', '15.9994'], 'H1': ['140', '1.008'], 'H4': ['146', '1.008'], 'H5': ['146', '1.008'], 'SH': ['200', '32.06']}
# learnt from 22 residues test.
dictAtomTypeGaff2OplsGmxCode = {'cc': ['500', '506', '507', '508', '514', '12.011'], 'ca': ['145', '166', '501', '502', '12.011'], 'h1': ['140', '1.008'], 'h4': ['146', '1.008'], 'h5': ['146', '1.008'], 'cz': ['302', '12.011'], 'c2': ['509', '510', '12.011'], 'nh': ['300', '303', '14.0067'], 'ha': ['146', '1.008'], 'na': ['503', '512', '14.0067'], 'nc': ['511', '14.0067'], 'nd': ['511', '14.0067'], 'hx': ['140', '1.008'], 'hs': ['204', '1.008'], 'hn': ['240', '241', '290', '301', '304', '310', '504', '513', '1.008'], 'ho': ['155', '168', '1.008'], 'c3': ['135', '136', '137', '149', '157', '158', '206', '209', '210', '223B', '224B', '245', '246', '274', '283', '284', '285', '292', '292B', '293B', '296', '307', '308', '505', '12.011'], 'hc': ['140', '1.008'], 'cd': ['500', '506', '507', '508', '514', '12.011'], 'c': ['235', '271', '12.011'], 'oh': ['154', '167', '15.9994'], 'ss': ['202', '32.06'], 'o': ['236', '272', '15.9994'], 'n': ['237', '238', '239', '14.0067'], 'sh': ['200', '32.06'], 'n4': ['287', '309', '14.0067']}
# draft
atomTypeAmber2oplsDict = {'HS': ['HS'], 'HP': ['HC'], 'HO': ['HO'], 'HC': ['HC'],
'HA': ['HA'], 'O2': ['O2'], 'C*': ['C*'], 'NA': ['NA'],
'NB': ['NB'], 'CB': ['CB'], 'CN': ['CN'], 'CV': ['CV'],
'CM': ['CA'], 'CA': ['CA'], 'CR': ['CR'], 'OH': ['OH'],
'H1': ['HC'], 'H4': ['HA'], 'N2': ['N2'], 'N3': ['N3'],
'H5': ['HA'], 'SH': ['SH'], 'N': ['N'], 'S': ['S'], 'O': ['O'],
'C': ['C', 'C_3'], 'CW': ['CW', 'CX'], 'H': ['H', 'H3'],
'CC': ['CX', 'CW', 'CV'], 'CT': ['CT', 'CT_2', 'CT_3']}
# draft
a2oD = {'amber99_2': ['opls_235', 'opls_271'],
'amber99_3': ['opls_302', 'opls_145'],
'amber99_5': ['opls_507', 'opls_508', 'opls_510'],
'amber99_11': ['opls_209', 'opls_158', 'opls_283', 'opls_223B', 'opls_293B',
'opls_284', 'opls_292B', 'opls_274', 'opls_136', 'opls_135',
'opls_292', 'opls_157', 'opls_206', 'opls_137', 'opls_505',
'opls_224B', 'opls_307', 'opls_308', 'opls_210', 'opls_149'],
'amber99_13': ['opls_514'],
'amber99_14': ['opls_500'],
'amber99_17': ['opls_504', 'opls_241', 'opls_240', 'opls_290', 'opls_301',
'opls_310', 'opls_304', 'opls_513'],
'amber99_18': ['opls_140'],
'amber99_19': ['opls_140'],
'amber99_22': ['opls_146'],
'amber99_23': ['opls_146'],
'amber99_25': ['opls_155'],
'amber99_26': ['opls_204'],
'amber99_28': ['opls_140'],
'amber99_34': ['opls_238', 'opls_239', 'opls_237'],
'amber99_35': ['opls_512', 'opls_503'],
'amber99_36': ['opls_511'],
'amber99_38': ['opls_300', 'opls_303'],
'amber99_39': ['opls_309', 'opls_287'],
'amber99_41': ['opls_236'],
'amber99_43': ['opls_154'],
'amber99_45': ['opls_272'],
'amber99_47': ['opls_202'],
'amber99_48': ['opls_200'],
}
global pid
pid = 0
head = "%s created by acpype (Rev: " + svnRev + ") on %s\n"
date = datetime.now().ctime()
usage = \
"""
acpype -i _file_ [-c _string_] [-n _int_] [-m _int_] [-a _string_] [-f] etc. or
acpype -p _prmtop_ -x _inpcrd_ [-d]"""
epilog = \
"""
output: assuming 'root' is the basename of either the top input file,
the 3-letter residue name or user defined (-b option)
root_bcc_gaff.mol2: final mol2 file with 'bcc' charges and 'gaff' atom type
root_AC.inpcrd : coord file for AMBER
root_AC.prmtop : topology and parameter file for AMBER
root_AC.lib : residue library file for AMBER
root_AC.frcmod : modified force field parameters
root_GMX.gro : coord file for GROMACS
root_GMX.top : topology file for GROMACS
root_GMX.itp : molecule unit topology and parameter file for GROMACS
root_GMX_OPLS.itp : OPLS/AA mol unit topol & par file for GROMACS (experimental!)
em.mdp, md.mdp : run parameters file for GROMACS
root_NEW.pdb : final pdb file generated by ACPYPE
root_CNS.top : topology file for CNS/XPLOR
root_CNS.par : parameter file for CNS/XPLOR
root_CNS.inp : run parameters file for CNS/XPLOR
root_CHARMM.rtf : topology file for CHARMM
root_CHARMM.prm : parameter file for CHARMM
root_CHARMM.inp : run parameters file for CHARMM"""
SLEAP_TEMPLATE = \
"""
source %(leapAmberFile)s
source %(leapGaffFile)s
set default fastbld on
#set default disulfide auto
%(res)s = loadpdb %(baseOrg)s.pdb
#check %(res)s
saveamberparm %(res)s %(acBase)s.prmtop %(acBase)s.inpcrd
saveoff %(res)s %(acBase)s.lib
quit
"""
TLEAP_TEMPLATE = \
"""
verbosity 1
source %(leapAmberFile)s
source %(leapGaffFile)s
mods = loadamberparams %(acBase)s.frcmod
%(res)s = loadmol2 %(acMol2FileName)s
check %(res)s
saveamberparm %(res)s %(acBase)s.prmtop %(acBase)s.inpcrd
saveoff %(res)s %(acBase)s.lib
quit
"""
def dotproduct(aa, bb):
return sum((a * b) for a, b in zip(aa, bb))
def crosproduct(a, b):
c = [a[1] * b[2] - a[2] * b[1],
a[2] * b[0] - a[0] * b[2],
a[0] * b[1] - a[1] * b[0]]
return c
def length(v):
return math.sqrt(dotproduct(v, v))
def vec_sub(aa, bb):
return [a - b for a, b in zip(aa, bb)]
def imprDihAngle(a, b, c, d):
ba = vec_sub(a, b)
bc = vec_sub(c, b)
cb = vec_sub(b, c)
cd = vec_sub(d, c)
n1 = crosproduct(ba, bc)
n2 = crosproduct(cb, cd)
angle = math.acos(dotproduct(n1, n2) / (length(n1) * length(n2))) * 180 / Pi
cp = crosproduct(n1, n2)
if (dotproduct(cp, bc) < 0):
angle = -1 * angle
return angle
def invalidArgs(text=None):
if text:
print('ERROR: ' + text)
sys.exit(1)
# verNum = string.split(sys.version)[0]
verNum = re.sub('[^0-9\.]', '', sys.version.split()[0])
version = verNum.split('.') # string.split(verNum, ".")
verList = list(map(int, version))
if verList < [2, 6, 0]:
invalidArgs(text="Python version %s\n Sorry, you need python 2.6 or higher" % verNum)
try:
set()
except NameError:
from sets import Set as set # @UnresolvedImport
def elapsedTime(seconds, suffixes=['y', 'w', 'd', 'h', 'm', 's'], add_s=False, separator=' '):
"""
Takes an amount of seconds and turns it into a human-readable amount of time.
"""
# the formatted time string to be returned
time = []
# the pieces of time to iterate over (days, hours, minutes, etc)
# - the first piece in each tuple is the suffix (d, h, w)
# - the second piece is the length in seconds (a day is 60s * 60m * 24h)
parts = [(suffixes[0], 60 * 60 * 24 * 7 * 52),
(suffixes[1], 60 * 60 * 24 * 7),
(suffixes[2], 60 * 60 * 24),
(suffixes[3], 60 * 60),
(suffixes[4], 60),
(suffixes[5], 1)]
# for each time piece, grab the value and remaining seconds, and add it to
# the time string
for suffix, length in parts:
value = seconds // length
if value > 0:
seconds = seconds % length
time.append('%s%s' % (str(value),
(suffix, (suffix, suffix + 's')[value > 1])[add_s]))
if seconds < 1:
break
return separator.join(time)
def splitBlock(dat):
'''split a amber parm dat file in blocks
0 = mass, 1 = extra + bond, 2 = angle, 3 = dihedral, 4 = improp, 5 = hbond
6 = equiv nbon, 7 = nbon, 8 = END, 9 = etc.
'''
dict_ = {}
count = 0
for line in dat:
line = line.rstrip()
if count in dict_:
dict_[count].append(line)
else:
dict_[count] = [line]
if not line:
count += 1
return dict_
def getParCode(line):
key = line.replace(' -', '-').replace('- ', '-').split()[0]
return key
def parseFrcmod(lista):
heads = ['MASS', 'BOND', 'ANGL', 'DIHE', 'IMPR', 'HBON', 'NONB']
dict_ = {}
for line in lista[1:]:
line = line.strip()
if line[:4] in heads:
head = line[:4]
dict_[head] = []
dd = {}
continue
elif line:
key = line.replace(' -', '-').replace('- ', '-').split()[0]
if key in dd:
if not dd[key].count(line):
dd[key].append(line)
else:
dd[key] = [line]
dict_[head] = dd
for k in dict_.keys():
if not dict_[k]:
dict_.pop(k)
return dict_
def parmMerge(fdat1, fdat2, frcmod=False):
'''merge two amber parm dat/frcmod files and save in /tmp'''
name1 = os.path.basename(fdat1).split('.dat')[0]
if frcmod:
name2 = os.path.basename(fdat2).split('.')[1]
else:
name2 = os.path.basename(fdat2).split('.dat')[0]
mname = '/tmp/' + name1 + name2 + '.dat'
mdatFile = open(mname, 'w')
mdat = ['merged %s %s' % (name1, name2)]
# if os.path.exists(mname): return mname
dat1 = splitBlock(open(fdat1).readlines())
if frcmod:
dHeads = {'MASS': 0, 'BOND': 1, 'ANGL': 2, 'DIHE': 3, 'IMPR': 4, 'HBON': 5, 'NONB': 7}
dat2 = parseFrcmod(open(fdat2).readlines()) # dict
for k in dat2:
for parEntry in dat2[k]:
idFirst = None
for line in dat1[dHeads[k]][:]:
if line:
key = line.replace(' -', '-').replace('- ', '-').split()[0]
if key == parEntry:
if not idFirst:
idFirst = dat1[dHeads[k]].index(line)
dat1[dHeads[k]].remove(line)
rev = dat2[k][parEntry][:]
rev.reverse()
if idFirst is None:
idFirst = 0
for ll in rev:
if dHeads[k] in [0, 1, 7]: # MASS has title in index 0 and so BOND, NONB
dat1[dHeads[k]].insert(idFirst + 1, ll)
else:
dat1[dHeads[k]].insert(idFirst, ll)
dat1[0][0] = mdat[0]
for k in dat1:
for line in dat1[k]:
mdatFile.write(line + '\n')
return mname
dat2 = splitBlock(open(fdat2).readlines())
for k in dat1.keys()[:8]:
if k == 0:
lines = dat1[k][1:-1] + dat2[k][1:-1] + ['']
for line in lines:
mdat.append(line)
if k == 1:
for i in dat1[k]:
if '-' in i:
id1 = dat1[k].index(i)
break
for j in dat2[k]:
if '-' in j:
id2 = dat2[k].index(j)
break
l1 = dat1[k][:id1]
l2 = dat2[k][:id2]
line = ''
for item in l1 + l2:
line += item.strip() + ' '
mdat.append(line)
lines = dat1[k][id1:-1] + dat2[k][id2:-1] + ['']
for line in lines:
mdat.append(line)
if k in [2, 3, 4, 5, 6]: # angles, p dih, imp dih
lines = dat1[k][:-1] + dat2[k][:-1] + ['']
for line in lines:
mdat.append(line)
if k == 7:
lines = dat1[k][:-1] + dat2[k][1:-1] + ['']
for line in lines:
mdat.append(line)
for k in dat1.keys()[8:]:
for line in dat1[k]:
mdat.append(line)
for k in dat2.keys()[9:]:
for line in dat2[k]:
mdat.append(line)
for line in mdat:
mdatFile.write(line + '\n')
mdatFile.close()
return mname
def _getoutput(cmd):
'''to simulate commands.getoutput in order to work with python 2.6 up to 3.x'''
out = sub.Popen(cmd, shell=True, stderr=sub.STDOUT, stdout=sub.PIPE).communicate()[0][:-1]
try:
o = str(out.decode())
except:
o = str(out)
return o
class AbstractTopol(object):
"""
Super class to build topologies
"""
def __init__(self):
if self.__class__ is AbstractTopol:
raise TypeError("Attempt to create istance of abstract class AbstractTopol")
def printDebug(self, text=''):
if self.debug:
print('DEBUG: %s' % text)
def printWarn(self, text=''):
if self.verbose:
print('WARNING: %s' % text)
def printError(self, text=''):
if self.verbose:
print('ERROR: %s' % text)
def printMess(self, text=''):
if self.verbose:
print('==> %s' % text)
def printQuoted(self, text=''):
if self.verbose:
print(10 * '+' + 'start_quote' + 59 * '+')
print(text)
print(10 * '+' + 'end_quote' + 61 * '+')
def guessCharge(self):
"""
Guess the charge of a system based on antechamber
Returns None in case of error
"""
done = False
error = False
charge = self.chargeVal
localDir = os.path.abspath('.')
if not os.path.exists(self.tmpDir):
os.mkdir(self.tmpDir)
if not os.path.exists(os.path.join(self.tmpDir, self.inputFile)):
copy2(self.absInputFile, self.tmpDir)
os.chdir(self.tmpDir)
if self.chargeType == 'user':
if self.ext == '.mol2':
self.printMess("Reading user's charges from mol2 file...")
charge = self.readMol2TotalCharge(self.inputFile)
done = True
else:
self.printWarn("cannot read charges from a PDB file")
self.printWarn("using now 'bcc' method for charge")
if self.chargeVal is None and not done:
self.printWarn("no charge value given, trying to guess one...")
mol2FileForGuessCharge = self.inputFile
if self.ext == ".pdb":
cmd = '%s -ipdb %s -omol2 %s.mol2' % (self.babelExe, self.inputFile,
self.baseName)
self.printDebug("guessCharge: " + cmd)
out = _getoutput(cmd)
self.printDebug(out)
mol2FileForGuessCharge = os.path.abspath(self.baseName + ".mol2")
in_mol = 'mol2'
else:
in_mol = self.ext[1:]
if in_mol == 'mol':
in_mol = 'mdl'
cmd = '%s -i %s -fi %s -o tmp -fo mol2 -c gas -pf y' % \
(self.acExe, mol2FileForGuessCharge, in_mol)
if self.debug:
self.printMess("Debugging...")
cmd = cmd.replace('-pf y', '-pf n')
print(cmd)
log = _getoutput(cmd).strip()
if os.path.exists('tmp'):
charge = self.readMol2TotalCharge('tmp')
else:
try:
charge = float(log.strip().split('equal to the total charge (')[-1].split(') based on Gasteiger atom type, exit')[0])
except:
error = True
if error:
self.printError("guessCharge failed")
os.chdir(localDir)
self.printQuoted(log)
self.printMess("Trying with net charge = 0 ...")
# self.chargeVal = 0
return None
charge = float(charge)
charge2 = int(round(charge))
drift = abs(charge2 - charge)
self.printDebug("Net charge drift '%3.6f'" % drift)
if drift > diffTol:
self.printError("Net charge drift '%3.5f' bigger than tolerance '%3.5f'" % (drift, diffTol))
if not self.force:
sys.exit(1)
self.chargeVal = str(charge2)
self.printMess("... charge set to %i" % charge2)
os.chdir(localDir)
def setResNameCheckCoords(self):
"""Set a 3 letter residue name
and check coords duplication
"""
exit_ = False
localDir = os.path.abspath('.')
if not os.path.exists(self.tmpDir):
os.mkdir(self.tmpDir)
# if not os.path.exists(os.path.join(tmpDir, self.inputFile)):
copy2(self.absInputFile, self.tmpDir)
os.chdir(self.tmpDir)
exten = self.ext[1:]
if self.ext == '.pdb':
tmpFile = open(self.inputFile, 'r')
else:
if exten == 'mol':
exten = 'mdl'
cmd = '%s -i %s -fi %s -o tmp -fo ac -pf y' % \
(self.acExe, self.inputFile, exten)
self.printDebug(cmd)
out = _getoutput(cmd)
if not out.isspace():
self.printDebug(out)
try:
tmpFile = open('tmp', 'r')
except:
rmtree(self.tmpDir)
raise
tmpData = tmpFile.readlines()
residues = set()
coords = {}
for line in tmpData:
if 'ATOM ' in line or 'HETATM' in line:
residues.add(line[17:20])
at = line[0:17]
cs = line[30:54]
if cs in coords:
coords[cs].append(at)
else:
coords[cs] = [at]
# self.printDebug(coords)
if len(residues) > 1:
self.printError("more than one residue detected '%s'" % str(residues))
self.printError("verify your input file '%s'. Aborting ..." % self.inputFile)
sys.exit(1)
dups = ""
shortd = ""
longd = ""
longSet = set()
id_ = 0
items = list(coords.items())
l = len(items)
for item in items:
id_ += 1
if len(item[1]) > 1: # if True means atoms with same coordinates
for i in item[1]:
dups += "%s %s\n" % (i, item[0])
# for i in xrange(0,len(data),f):
# fdata += (data[i:i+f])+' '
for id2 in range(id_, l):
item2 = items[id2]
c1 = list(map(float, [item[0][i:i + 8] for i in range(0, 24, 8)]))
c2 = list(map(float, [item2[0][i:i + 8] for i in range(0, 24, 8)]))
dist2 = self.distance(c1, c2)
if dist2 < minDist2:
dist = math.sqrt(dist2)
shortd += "%8.5f %s %s\n" % (dist, item[1], item2[1])
if dist2 < maxDist2: # and not longOK:
longSet.add(str(item[1]))
longSet.add(str(item2[1]))
if str(item[1]) not in longSet and l > 1:
longd += "%s\n" % item[1]
if dups:
self.printError("Atoms with same coordinates in '%s'!" % self.inputFile)
self.printQuoted(dups[:-1])
exit_ = True
if shortd:
self.printError("Atoms TOO close (< %s Ang.)" % minDist)
self.printQuoted("Dist (Ang.) Atoms\n" + shortd[:-1])
exit_ = True
if longd:
self.printError("Atoms TOO alone (> %s Ang.)" % maxDist)
self.printQuoted(longd[:-1])
exit_ = True
if exit_:
if self.force:
self.printWarn("You chose to proceed anyway with '-f' option. GOOD LUCK!")
else:
self.printError("Use '-f' option if you want to proceed anyway. Aborting ...")
rmtree(self.tmpDir)
sys.exit(1)
resname = list(residues)[0].strip()
newresname = resname
# To avoid resname likes: 001 (all numbers), 1e2 (sci number), ADD : reserved terms for leap
leapWords = ['_cmd_options_', '_types_', 'add', 'addAtomTypes', 'addIons',
'addIons2', 'addPath', 'addPdbAtomMap', 'addPdbResMap', 'alias',
'alignAxes', 'bond', 'bondByDistance', 'center', 'charge',
'check', 'clearPdbAtomMap', 'clearPdbResMap', 'clearVariables',
'combine', 'copy', 'createAtom', 'createParmset', 'createResidue',
'createUnit', 'crossLink', 'debugOff', 'debugOn', 'debugStatus',
'deleteBond', 'deleteOffLibEntry', 'deleteRestraint', 'desc',
'deSelect', 'displayPdbAtomMap', 'displayPdbResMap', 'edit',
'flip', 'groupSelectedAtoms', 'help', 'impose', 'list', 'listOff',
'loadAmberParams', 'loadAmberPrep', 'loadMol2', 'loadOff',
'loadPdb', 'loadPdbUsingSeq', 'logFile', 'matchVariables',
'measureGeom', 'quit', 'relax', 'remove', 'restrainAngle',
'restrainBond', 'restrainTorsion', 'saveAmberParm',
'saveAmberParmPert', 'saveAmberParmPol', 'saveAmberParmPolPert',
'saveAmberPrep', 'saveMol2', 'saveOff', 'saveOffParm', 'savePdb',
'scaleCharges', 'select', 'sequence', 'set', 'setBox', 'solvateBox',
'solvateCap', 'solvateDontClip', 'solvateOct', 'solvateShell',
'source', 'transform', 'translate', 'verbosity', 'zMatrix']
isLeapWord = False
for word in leapWords:
if resname.upper().startswith(word.upper()):
self.printDebug("Residue name is a reserved word: '%s'" % word.upper())
isLeapWord = True
try:
float(resname)
self.printDebug("Residue name is a 'number': '%s'" % resname)
isNumber = True
except ValueError:
isNumber = False
if resname[0].isdigit() or isNumber or isLeapWord:
newresname = 'R' + resname
if not resname.isalnum():
newresname = 'MOL'
if newresname != resname:
self.printWarn("In %s.lib, residue name will be '%s' instead of '%s' elsewhere"
% (self.acBaseName, newresname, resname))
self.resName = newresname
os.chdir(localDir)
self.printDebug("setResNameCheckCoords done")
def distance(self, c1, c2):
# print c1, c2
dist2 = (c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2 + (c1[0] - c2[0]) ** 2 + \
(c1[2] - c2[2]) ** 2
# dist2 = math.sqrt(dist2)
return dist2
def readMol2TotalCharge(self, mol2File):
"""Reads the charges in given mol2 file and returns the total
"""
charge = 0.0
ll = []
cmd = '%s -i %s -fi mol2 -o tmp -fo mol2 -c wc -cf tmp.crg -pf y' % \
(self.acExe, mol2File)
if self.debug:
self.printMess("Debugging...")
cmd = cmd.replace('-pf y', '-pf n')
self.printDebug(cmd)
log = _getoutput(cmd)
if os.path.exists('tmp.crg'):
tmpFile = open('tmp.crg', 'r')
tmpData = tmpFile.readlines()
for line in tmpData:
ll += line.split()
charge = sum(map(float, ll))
if not log.isspace() and self.debug:
self.printQuoted(log)
self.printDebug("readMol2TotalCharge: " + str(charge))
return charge
def execAntechamber(self, chargeType=None, atomType=None):
""" AmaberTools 1.3
To call Antechamber and execute it
Usage: antechamber -i input file name
-fi input file format
-o output file name
-fo output file format
-c charge method
-cf charge file name
-nc net molecular charge (int)
-a additional file name
-fa additional file format
-ao additional file operation
crd only read in coordinate
crg only read in charge
name only read in atom name
type only read in atom type
bond only read in bond type
-m multiplicity (2S+1), default is 1
-rn residue name, overrides input file, default is MOL
-rf residue toplogy file name in prep input file,
default is molecule.res
-ch check file name for gaussian, default is molecule
-ek mopac or sqm keyword, inside quotes
-gk gaussian keyword, inside quotes
-df am1-bcc flag, 2 - use sqm(default); 0 - use mopac
-at atom type, can be gaff (default), amber, bcc and sybyl
-du fix duplicate atom names: yes(y)[default] or no(n)
-j atom type and bond type prediction index, default is 4
0 no assignment
1 atom type
2 full bond types
3 part bond types
4 atom and full bond type
5 atom and part bond type
-s status information: 0(brief), 1(default) or 2(verbose)
-pf remove intermediate files: yes(y) or no(n)[default]
-i -o -fi and -fo must appear; others are optional
List of the File Formats
file format type abbre. index | file format type abbre. index
---------------------------------------------------------------
Antechamber ac 1 | Sybyl Mol2 mol2 2
PDB pdb 3 | Modified PDB mpdb 4
AMBER PREP (int) prepi 5 | AMBER PREP (car) prepc 6
Gaussian Z-Matrix gzmat 7 | Gaussian Cartesian gcrt 8
Mopac Internal mopint 9 | Mopac Cartesian mopcrt 10
Gaussian Output gout 11 | Mopac Output mopout 12
Alchemy alc 13 | CSD csd 14
MDL mdl 15 | Hyper hin 16
AMBER Restart rst 17 | Jaguar Cartesian jcrt 18
Jaguar Z-Matrix jzmat 19 | Jaguar Output jout 20
Divcon Input divcrt 21 | Divcon Output divout 22
Charmm charmm 23 | SQM Output sqmout 24
--------------------------------------------------------------
AMBER restart file can only be read in as additional file.
List of the Charge Methods
charge method abbre. index | charge method abbre. index
----------------------------------------------------------------
RESP resp 1 | AM1-BCC bcc 2
CM1 cm1 3 | CM2 cm2 4
ESP (Kollman) esp 5 | Mulliken mul 6
Gasteiger gas 7 | Read in charge rc 8
Write out charge wc 9 | Delete Charge dc 10
----------------------------------------------------------------
a """
global pid
self.printMess("Executing Antechamber...")
self.makeDir()
ct = chargeType or self.chargeType
at = atomType or self.atomType
if ct == 'user':
ct = ''
else:
ct = '-c %s' % ct
exten = self.ext[1:]
if exten == 'mol':
exten = 'mdl'
cmd = '%s -i %s -fi %s -o %s -fo mol2 %s -nc %s -m %s -s 2 -df %i -at\
%s -pf y %s' % (self.acExe, self.inputFile, exten, self.acMol2FileName,
ct, self.chargeVal, self.multiplicity, self.qFlag, at,
self.ekFlag)
if self.debug:
self.printMess("Debugging...")
cmd = cmd.replace('-pf y', '-pf n')
self.printDebug(cmd)
if os.path.exists(self.acMol2FileName) and not self.force:
self.printMess("AC output file present... doing nothing")
else:
try:
os.remove(self.acMol2FileName)
except:
pass
signal.signal(signal.SIGALRM, self.signal_handler)
signal.alarm(self.timeTol)
p = sub.Popen(cmd, shell=True, stderr=sub.STDOUT, stdout=sub.PIPE)
pid = p.pid
out = str(p.communicate()[0].decode()) # p.stdout.read()
self.acLog = out
if os.path.exists(self.acMol2FileName):
self.printMess("* Antechamber OK *")
else:
self.printQuoted(self.acLog)
return True
def signal_handler(self, _signum, _frame): # , pid = 0):
global pid
pids = self.job_pids_family(pid)
self.printDebug("PID: %s, PIDS: %s" % (pid, pids))
self.printMess("Timed out! Process %s killed, max exec time (%ss) exceeded"
% (pids, self.timeTol))
# os.system('kill -15 %s' % pids)
for i in pids.split():
os.kill(int(i), 15)
raise Exception("Semi-QM taking too long to finish... aborting!")
def job_pids_family(self, jpid):
'''INTERNAL: Return all job processes (PIDs)'''
pid = repr(jpid)
dict_pids = {}
pids = [pid]
cmd = "ps -A -o uid,pid,ppid|grep %i" % os.getuid()
out = _getoutput(cmd).split('\n') # getoutput("ps -A -o uid,pid,ppid|grep %i" % os.getuid()).split('\n')
for item in out:
vec = item.split()
dict_pids[vec[2]] = vec[1]
while 1:
try:
pid = dict_pids[pid]
pids.append(pid)
except KeyError:
break
return ' '.join(pids)
def delOutputFiles(self):
delFiles = ['mopac.in', 'tleap.in', 'sleap.in', 'fixbo.log',
'addhs.log', 'ac_tmp_ot.mol2', 'frcmod.ac_tmp', 'fragment.mol2',
self.tmpDir] # , 'divcon.pdb', 'mopac.pdb', 'mopac.out'] #'leap.log'
self.printMess("Removing temporary files...")
for file_ in delFiles:
file_ = os.path.join(self.absHomeDir, file_)
if os.path.exists(file_):
if os.path.isdir(file_):
rmtree(file_)
else:
os.remove(file_)
def checkXyzAndTopFiles(self):
fileXyz = self.acXyzFileName
fileTop = self.acTopFileName
if os.path.exists(fileXyz) and os.path.exists(fileTop):
# self.acXyz = fileXyz
# self.acTop = fileTop