summaryrefslogtreecommitdiff
path: root/cad/src/protein/commands/InsertPeptide/PeptideGenerator.py
blob: 916357ea895c6e473acc22578504a8a69cf8af79 (plain)
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
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details.
"""
PeptideGenerator.py

Peptide Generator can generate short polypeptide chains of arbitrarily choosen
sequence and secondary structure.

@author: Piotr
@version: $Id$
@copyright: 2008 Nanorex, Inc.  See LICENSE file for details.

@see http://www.nanoengineer-1.net/mediawiki/index.php?title=Peptide_generator_dialog
for notes about what's going on here.

History:

Ninad 2008-07-24: Refactoring / cleanup to port PeptideGenerator to the 
                 EditCommand API. (see InsertPeptide_EditCommand)
"""

import foundation.env as env

from geometry.InternalCoordinatesToCartesian import InternalCoordinatesToCartesian

from model.chem import Atom
from model.chunk import Chunk
from model.bond_constants import V_DOUBLE, V_AROMATIC
from operations.bonds_from_atoms import inferBonds

from protein.model.Protein import Protein 
from protein.model.Residue import Residue
from protein.model.Residue import SS_HELIX, SS_STRAND, SS_COIL, AA_3_TO_1

from Numeric import zeros, sqrt, pi, sin, cos, Float
from geometry.VQT import Q, V, norm, vlen, cross, angleBetween

from utilities.debug import print_compact_stack

# Internal coordinate sets for amino acids
# Converted from AMBER all_amino94.in file
# Fixed a few issues: conformation of phenylalanine, connectivity of serine.
# Beware of proline - it needs to be handled in a different way.

ALA_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp3",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB1", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (   9, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  180.000 ),
    (  10, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (  11, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  12, "O  ", "O", "sp2",   11,    5,    3,    1.229,  120.500,    0.000 ),
]

GLY_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA2", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "HA3", "H", "",       5,    3,    2,    1.090,  109.500,   60.000 ),
    (   8, "C  ", "C", "sp2",    5,    3,    2,    1.522,  110.400,  180.000 ),
    (   9, "O  ", "O", "sp2",    8,    5,    3,    1.229,  120.500,    0.000 )
]

SER_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "OG ", "O", "sp3",    7,    5,    3,    1.430,  109.470,  180.000 ),
    (  11, "HG ", "H", "",      10,    7,    5,    0.960,  109.470,  180.000 ),
    (  12, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  13, "O  ", "O", "sp2",   12,    5,    3,    1.229,  120.500,    0.000 ),
]

PHE_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp2a",    7,    5,    3,    1.510,  115.000,  180.000 ),
    (  11, "CD1", "C", "sp2a",   10,    7,    5,    1.400,  120.000,  180.000 ),
    (  12, "HD1", "H", "",      11,   10,    7,    1.090,  120.000,    0.000 ),
    (  13, "CE1", "C", "sp2a",   11,   10,    7,    1.400,  120.000,  180.000 ),
    (  14, "HE1", "H", "",      13,   11,   10,    1.090,  120.000,  180.000 ),
    (  15, "CZ ", "C", "sp2a",   13,   11,   10,    1.400,  120.000,    0.000 ),
    (  16, "HZ ", "H", "",      15,   13,   11,    1.090,  120.000,  180.000 ),
    (  17, "CE2", "C", "sp2a",   15,   13,   11,    1.400,  120.000,    0.000 ),
    (  18, "HE2", "H", "",      17,   15,   13,    1.090,  120.000,  180.000 ),
    (  19, "CD2", "C", "sp2a",   17,   15,   13,    1.400,  120.000,    0.000 ),
    (  20, "HD2", "H", "",      19,   17,   15,    1.090,  120.000,  180.000 ),
    (  21, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  22, "O  ", "O", "sp2",   21,    5,    3,    1.229,  120.500,    0.000 ),
]

GLU_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp3",    7,    5,    3,    1.510,  109.470,  180.000 ),
    (  11, "HG2", "H", "",      10,    7,    5,    1.090,  109.500,  300.000 ),
    (  12, "HG3", "H", "",      10,    7,    5,    1.090,  109.500,   60.000 ),
    (  13, "CD ", "C", "sp2",   10,    7,    5,    1.527,  109.470,  180.000 ),
    (  14, "OE1", "O", "sp2",   13,   10,    7,    1.260,  117.200,   90.000 ),
    (  15, "OE2", "O", "sp3",   13,   10,    7,    1.260,  117.200,  270.000 ),
    (  16, "HE2", "H", "",      15,   13,   10,    0.960,  109.500,  180.000 ),
    (  17, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  18, "O  ", "O", "sp2",   17,    5,    3,    1.229,  120.500,    0.000 ),
]

PRO_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.337,  117.000,  180.000 ),
    (   4, "CD ", "C", "sp3",    3,    2,    1,    1.458,  126.100,  356.100 ),
    (   5, "HD2", "H", "",       4,    3,    2,    1.090,  109.500,   80.000 ),
    (   6, "HD3", "H", "",       4,    3,    2,    1.090,  109.500,  320.000 ),
    (   7, "CG ", "C", "sp3",    4,    3,    2,    1.500,  103.200,  200.100 ),
    (   8, "HG2", "H", "",       7,    4,    3,    1.090,  109.500,  218.000 ),
    (   9, "HG3", "H", "",       7,    4,    3,    1.090,  109.500,   98.000 ),
    (  10, "CB ", "C", "sp3",    7,    4,    3,    1.510,  106.000,  338.300 ),
    (  11, "HB2", "H", "",      10,    7,    4,    1.090,  109.500,  256.300 ),
    (  12, "HB3", "H", "",      10,    7,    4,    1.090,  109.500,  136.300 ),
    (  13, "CA ", "C", "sp3",    3,    2,    1,    1.451,  120.600,  175.200 ),
    (  14, "HA ", "H", "",      13,    3,    2,    1.090,  109.500,   60.000 ),
    (  15, "C  ", "C", "sp2",   13,    3,    2,    1.522,  109.500,  300.000 ),
    (  16, "O  ", "O", "sp2",   15,   13,    3,    1.229,  120.500,    0.000 ),
]

CYS_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "SG ", "S", "sp3",    7,    5,    3,    1.810,  116.000,  180.000 ),
    (  11, "HG ", "H", "",      10,    7,    5,    1.330,   96.000,  180.000 ),
    (  12, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  13, "O  ", "O", "sp2",   12,    5,    3,    1.229,  120.500,    0.000 ),
]

MET_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp3",    7,    5,    3,    1.525,  109.470,  180.000 ),
    (  11, "HG2", "H", "",      10,    7,    5,    1.090,  109.500,  300.000 ),
    (  12, "HG3", "H", "",      10,    7,    5,    1.090,  109.500,   60.000 ),
    (  13, "SD ", "S", "sp3",   10,    7,    5,    1.810,  110.000,  180.000 ),
    (  14, "CE ", "C", "sp3",   13,   10,    7,    1.780,  100.000,  180.000 ),
    (  15, "HE1", "H",  "",     14,   13,   10,    1.090,  109.500,   60.000 ),
    (  16, "HE2", "H",  "",     14,   13,   10,    1.090,  109.500,  180.000 ),
    (  17, "HE3", "H", "",      14,   13,   10,    1.090,  109.500,  300.000 ),
    (  18, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  19, "O  ", "O", "sp2",   18,    5,    3,    1.229,  120.500,    0.000 ),
]

THR_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB ", "H", "",       7,    5,    3,    1.090,  109.500,  180.000 ),
    (   9, "CG2", "C", "sp3",    7,    5,    3,    1.525,  109.470,  300.000 ),
    (  10, "HG2", "H", "",       9,    7,    5,    1.090,  109.500,   60.000 ),
    (  11, "HG2", "H", "",       9,    7,    5,    1.090,  109.500,  180.000 ),
    (  12, "HG2", "H", "",       9,    7,    5,    1.090,  109.500,  300.000 ),
    (  13, "OG1", "O", "sp3",    7,    5,    3,    1.430,  109.470,   60.000 ),
    (  14, "HG1", "H", "",      13,    7,    5,    0.960,  109.470,  180.000 ),
    (  15, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  16, "O  ", "O", "sp2",   15,    5,    3,    1.229,  120.500,    0.000 ),
]

LEU_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp3",    7,    5,    3,    1.525,  109.470,  180.000 ),
    (  11, "HG ", "H", "",      10,    7,    5,    1.090,  109.500,  300.000 ),
    (  12, "CD1", "C", "sp3",   10,    7,    5,    1.525,  109.470,   60.000 ),
    (  13, "HD1", "H", "",      12,   10,    7,    1.090,  109.500,   60.000 ),
    (  14, "HD1", "H", "",      12,   10,    7,    1.090,  109.500,  180.000 ),
    (  15, "HD1", "H", "",      12,   10,    7,    1.090,  109.500,  300.000 ),
    (  16, "CD2", "C", "sp3",   10,    7,    5,    1.525,  109.470,  180.000 ),
    (  17, "HD2", "H",  "",     16,   10,    7,    1.090,  109.500,   60.000 ),
    (  18, "HD2", "H",  "",     16,   10,    7,    1.090,  109.500,  180.000 ),
    (  19, "HD2", "H",  "",     16,   10,    7,    1.090,  109.500,  300.000 ),
    (  20, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  21, "O  ", "O", "sp2",   20,    5,    3,    1.229,  120.500,    0.000 ),
]


ILE_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  109.470,   60.000 ),
    (   8, "HB ", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "CG2", "C", "sp3",    7,    5,    3,    1.525,  109.470,   60.000 ),
    (  10, "HG2", "H", "",       9,    7,    5,    1.090,  109.500,   60.000 ),
    (  11, "HG2", "H", "",       9,    7,    5,    1.090,  109.500,  180.000 ),
    (  12, "HG2", "H", "",       9,    7,    5,    1.090,  109.500,  300.000 ),
    (  13, "CG1", "C", "sp3",    7,    5,    3,    1.525,  109.470,  180.000 ),
    (  14, "HG1", "H", "",      13,    7,    5,    1.090,  109.500,  300.000 ),
    (  15, "HG1", "H", "",      13,    7,    5,    1.090,  109.500,   60.000 ),
    (  16, "CD1", "C", "sp3",   13,    7,    5,    1.525,  109.470,  180.000 ),
    (  17, "HD1", "H",  "",     16,   13,    7,    1.090,  109.500,   60.000 ),
    (  18, "HD1", "H",  "",     16,   13,    7,    1.090,  109.500,  180.000 ),
    (  19, "HD1", "H",  "",     16,   13,    7,    1.090,  109.500,  300.000 ),
    (  20, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  21, "O  ", "O", "sp2",   20,    5,    3,    1.229,  120.500,    0.000 ),
]

VAL_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB ", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "CG1", "C", "sp3",    7,    5,    3,    1.525,  109.470,   60.000 ),
    (  10, "HG1", "H", "",       9,    7,    5,    1.090,  109.500,   60.000 ),
    (  11, "HG1", "H", "",       9,    7,    5,    1.090,  109.500,  180.000 ),
    (  12, "HG1", "H", "",       9,    7,    5,    1.090,  109.500,  300.000 ),
    (  13, "CG2", "C", "sp3",    7,    5,    3,    1.525,  109.470,  180.000 ),
    (  14, "HG2", "H", "",      13,    7,    5,    1.090,  109.500,   60.000 ),
    (  15, "HG2", "H", "",      13,    7,    5,    1.090,  109.500,  180.000 ),
    (  16, "HG2", "H", "",      13,    7,    5,    1.090,  109.500,  300.000 ),
    (  17, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  18, "O  ", "O", "sp2",   17,    5,    3,    1.229,  120.500,    0.000 ),
]

TRP_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp2",    7,    5,    3,    1.510,  115.000,  180.000 ),
    (  11, "CD1", "C", "sp2",   10,    7,    5,    1.340,  127.000,  180.000 ),
    (  12, "HD1", "H", "",      11,   10,    7,    1.090,  120.000,    0.000 ),
    (  13, "NE1", "N", "sp3",   11,   10,    7,    1.430,  107.000,  180.000 ),
    (  14, "HE1", "H", "",      13,   11,   10,    1.010,  125.500,  180.000 ),
    (  15, "CE2", "C", "sp2a",   13,   11,   10,    1.310,  109.000,    0.000 ),
    (  16, "CZ2", "C", "sp2a",   15,   13,   11,    1.400,  128.000,  180.000 ),
    (  17, "HZ2", "H", "",      16,   15,   13,    1.090,  120.000,    0.000 ),
    (  18, "CH2", "C", "sp2a",   16,   15,   13,    1.390,  116.000,  180.000 ),
    (  19, "HH2", "H", "",      18,   16,   15,    1.090,  120.000,  180.000 ),
    (  20, "CZ3", "C", "sp2a",   18,   16,   15,    1.350,  121.000,    0.000 ),
    (  21, "HZ3", "H",  "",     20,   18,   16,    1.090,  120.000,  180.000 ),
    (  22, "CE3", "C", "sp2a",   20,   18,   16,    1.410,  122.000,    0.000 ),
    (  23, "HE3", "H", "",      22,   20,   18,    1.090,  120.000,  180.000 ),
    (  24, "CD2", "C", "sp2a",   22,   20,   18,    1.400,  117.000,    0.000 ),
    (  25, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  26, "O  ", "O", "sp2",   25,    5,    3,    1.229,  120.500,    0.000 ),
]

TYR_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp2a",    7,    5,    3,    1.510,  109.470,  180.000 ),
    (  11, "CD1", "C", "sp2a",   10,    7,    5,    1.400,  120.000,  180.000 ),
    (  12, "HD1", "H", "",      11,   10,    7,    1.090,  120.000,    0.000 ),
    (  13, "CE1", "C", "sp2a",   11,   10,    7,    1.400,  120.000,  180.000 ),
    (  14, "HE1", "H", "",      13,   11,   10,    1.090,  120.000,  180.000 ),
    (  15, "CZ ", "C", "sp2a",   13,   11,   10,    1.400,  120.000,    0.000 ),
    (  16, "OH ", "O", "sp3",   15,   13,   11,    1.360,  120.000,  180.000 ),
    (  17, "HH ", "H", "",      16,   15,   13,    0.960,  113.000,    0.000 ),
    (  18, "CE2", "C", "sp2a",   15,   13,   11,    1.400,  120.000,    0.000 ),
    (  19, "HE2", "H", "",      18,   15,   13,    1.090,  120.000,  180.000 ),
    (  20, "CD2", "C", "sp2a",   18,   15,   13,    1.400,  120.000,    0.000 ),
    (  21, "HD2", "H", "",      20,   18,   15,    1.090,  120.000,  180.000 ),
    (  22, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  23, "O  ", "O", "sp2",   22,    5,    3,    1.229,  120.500,    0.000 ),
]

LYS_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp3",    7,    5,    3,    1.525,  109.470,  180.000 ),
    (  11, "HG2", "H", "",      10,    7,    5,    1.090,  109.500,  300.000 ),
    (  12, "HG3", "H", "",      10,    7,    5,    1.090,  109.500,   60.000 ),
    (  13, "CD ", "C", "sp3",   10,    7,    5,    1.525,  109.470,  180.000 ),
    (  14, "HD2", "H", "",      13,   10,    7,    1.090,  109.500,  300.000 ),
    (  15, "HD3", "H", "",      13,   10,    7,    1.090,  109.500,   60.000 ),
    (  16, "CE ", "C", "sp3",   13,   10,    7,    1.525,  109.470,  180.000 ),
    (  17, "HE2", "H", "",      16,   13,   10,    1.090,  109.500,  300.000 ),
    (  18, "HE3", "H", "",      16,   13,   10,    1.090,  109.500,   60.000 ),
    (  19, "NZ ", "N", "sp3",   16,   13,   10,    1.470,  109.470,  180.000 ),
    (  20, "HZ1", "H",  "",     19,   16,   13,    1.010,  109.470,   60.000 ),
    (  21, "HZ2", "H",  "",     19,   16,   13,    1.010,  109.470,  180.000 ),
    (  22, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  23, "O  ", "O", "sp2",   22,    5,    3,    1.229,  120.500,    0.000 ),
]

ARG_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp3",    7,    5,    3,    1.525,  109.470,  180.000 ),
    (  11, "HG2", "H", "",      10,    7,    5,    1.090,  109.500,  300.000 ),
    (  12, "HG3", "H", "",      10,    7,    5,    1.090,  109.500,   60.000 ),
    (  13, "CD ", "C", "sp3",   10,    7,    5,    1.525,  109.470,  180.000 ),
    (  14, "HD2", "H", "",      13,   10,    7,    1.090,  109.500,  300.000 ),
    (  15, "HD3", "H", "",      13,   10,    7,    1.090,  109.500,   60.000 ),
    (  16, "NE ", "N", "sp3",   13,   10,    7,    1.480,  111.000,  180.000 ),
    (  17, "HE ", "H", "",      16,   13,   10,    1.010,  118.500,    0.000 ),
    (  18, "CZ ", "C", "sp2",   16,   13,   10,    1.330,  123.000,  180.000 ),
    (  19, "NH1", "N", "sp3",   18,   16,   13,    1.330,  122.000,    0.000 ),
    (  20, "HH1", "H",  "",     19,   18,   16,    1.010,  119.800,    0.000 ),
    (  21, "HH1", "H",  "",     19,   18,   16,    1.010,  119.800,  180.000 ),
    (  22, "NH2", "N",  "sp2",  18,   16,   13,    1.330,  118.000,  180.000 ),
    (  23, "HH2", "H",  "",     22,   18,   16,    1.010,  119.800,    0.000 ),
    (  24, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  25, "O  ", "O", "sp2",   24,    5,    3,    1.229,  120.500,    0.000 ),
]

HIS_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp2",    7,    5,    3,    1.510,  115.000,  180.000 ),
    (  11, "ND1", "N", "sp3",   10,    7,    5,    1.390,  122.000,  180.000 ),
    (  12, "HD1", "H", "",      11,   10,    7,    1.010,  126.000,    0.000 ),
    (  13, "CE1", "C", "sp2",   11,   10,    7,    1.320,  108.000,  180.000 ),
    (  14, "HE1", "H", "",      13,   11,   10,    1.090,  120.000,  180.000 ),
    (  15, "NE2", "N", "sp2s",   13,   11,   10,    1.310,  109.000,    0.000 ),
    (  16, "CD2", "C", "sp2s",   15,   13,   11,    1.360,  110.000,    0.000 ),
    (  17, "HD2", "H", "",      16,   15,   13,    1.090,  120.000,  180.000 ),
    (  18, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  19, "O  ", "O", "sp2",   18,    5,    3,    1.229,  120.500,    0.000 ),
]

ASP_ZMATRIX = [
    (   0, "DUM",  "",  "",     -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM",  "",  "",      0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM",  "",  "",      1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ",  "N", "sp2(graphitic)",   2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ",  "H", "",      3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ",  "C", "sp3",   3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ",  "H", "",      5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ",  "C", "sp3",   5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2",  "H", "",      7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3",  "H", "",      7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ",  "C", "sp2",   7,    5,    3,    1.527,  109.470,  180.000 ),
    (  11, "OD1",  "O", "sp2",  10,    7,    5,    1.260,  117.200,   90.000 ),
    (  12, "OD2",  "O", "sp3",  10,    7,    5,    1.260,  117.200,  270.000 ),
    (  13, "HD2",  "H", "",     12,   10,    7,    0.960,  109.500,  180.000 ),
    (  14, "C  ",  "C", "sp2",   5,    3,    2,    1.522,  111.100,  180.000 ),
    (  15, "O  ",  "O", "sp2",  14,    5,    3,    1.229,  120.500,    0.000 ),
]

ASN_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp2",    7,    5,    3,    1.522,  111.100,  180.000 ),
    (  11, "OD1", "O", "sp2",   10,    7,    5,    1.229,  120.500,    0.000 ),
    (  12, "ND2", "N", "sp3",   10,    7,    5,    1.335,  116.600,  180.000 ),
    (  13, "HD2", "H", "",      12,   10,    7,    1.010,  119.800,  180.000 ),
    (  14, "HD2", "H", "",      12,   10,    7,    1.010,  119.800,    0.000 ),
    (  15, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  16, "O  ", "O", "sp2",   15,    5,    3,    1.229,  120.500,    0.000 ),
]

GLN_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "N", "sp2(graphitic)",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    1.010,  119.800,    0.000 ),
    (   5, "CA ", "C", "sp3",    3,    2,    1,    1.449,  121.900,  180.000 ),
    (   6, "HA ", "H", "",       5,    3,    2,    1.090,  109.500,  300.000 ),
    (   7, "CB ", "C", "sp3",    5,    3,    2,    1.525,  111.100,   60.000 ),
    (   8, "HB2", "H", "",       7,    5,    3,    1.090,  109.500,  300.000 ),
    (   9, "HB3", "H", "",       7,    5,    3,    1.090,  109.500,   60.000 ),
    (  10, "CG ", "C", "sp3",    7,    5,    3,    1.525,  109.470,  180.000 ),
    (  11, "HG2", "H", "",      10,    7,    5,    1.090,  109.500,  300.000 ),
    (  12, "HG3", "H", "",      10,    7,    5,    1.090,  109.500,   60.000 ),
    (  13, "CD ", "C", "sp2",   10,    7,    5,    1.522,  111.100,  180.000 ),
    (  14, "OE1", "O", "sp2",   13,   10,    7,    1.229,  120.500,    0.000 ),
    (  15, "NE2", "N", "sp3",   13,   10,    7,    1.335,  116.600,  180.000 ),
    (  16, "HE2", "H", "",      15,   13,   10,    1.010,  119.800,  180.000 ),
    (  17, "HE2", "H", "",      15,   13,   10,    1.010,  119.800,    0.000 ),
    (  18, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  19, "O  ", "O", "sp2",   18,    5,    3,    1.229,  120.500,    0.000 ),
]

NTERM_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "N  ", "H", "",       2,    1,    0,    1.335,  116.600,  180.000 ),
]

# Note: this is just a fake "N  " label for the _buildResidue
# to make it thinking that we are starting a new amino acid.
CTERM_ZMATRIX = [
    (   0, "DUM", "",  "",      -1,   -2,   -3,    0.000,    0.000,    0.000 ),
    (   1, "DUM", "",  "",       0,   -1,   -2,    1.449,    0.000,    0.000 ),
    (   2, "DUM", "",  "",       1,    0,   -1,    1.522,  111.100,    0.000 ),
    (   3, "OXT", "O", "sp3",    2,    1,    0,    1.335,  116.600,  180.000 ),
    (   4, "H  ", "H", "",       3,    2,    1,    0.960,  109.500,    0.000 ),
]

# all amino acids, z-matrices and their sizes
AMINO_ACIDS = [
    ( "Alanine",       "ALA", "A", ALA_ZMATRIX, 13 ),
    ( "Arginine",      "ARG", "R", ARG_ZMATRIX, 26 ),
    ( "Asparagine",    "ARG", "N", ASN_ZMATRIX, 17 ),
    ( "Aspartic Acid", "ARG", "D", ASP_ZMATRIX, 16 ),
    ( "Cysteine",      "CYS", "C", CYS_ZMATRIX, 14 ),
    ( "Glutamic Acid", "GLU", "E", GLU_ZMATRIX, 19 ),
    ( "Glutamine",     "GLN", "Q", GLN_ZMATRIX, 20 ),
    ( "Glycine",       "GLY", "G", GLY_ZMATRIX, 10 ),
    ( "Histidine",     "HIS", "H", HIS_ZMATRIX, 20 ),
    ( "Isoleucine",    "ILE", "I", ILE_ZMATRIX, 22 ),
    ( "Leucine",       "LEU", "L", LEU_ZMATRIX, 22 ),
    ( "Lysine",        "LYS", "K", LYS_ZMATRIX, 24 ),
    ( "Methionine",    "MET", "M", MET_ZMATRIX, 20 ),
    ( "Phenylalanine", "PHE", "F", PHE_ZMATRIX, 23 ),
    ( "Proline",       "PRO", "P", PRO_ZMATRIX, 17 ),
    ( "Serine",        "SER", "S", SER_ZMATRIX, 14 ),
    ( "Threonine",     "THR", "T", THR_ZMATRIX, 17 ),
    ( "Tryptophan",    "TRP", "W", TRP_ZMATRIX, 27 ),
    ( "Tyrosine",      "TYR", "Y", TYR_ZMATRIX, 24 ),
    ( "Valine",        "VAL", "V", VAL_ZMATRIX, 19 )
]

# degrees to radians conversion
DEG2RAD = (pi/180.0)

def enablePeptideGenerator(enable):
    """
    This function enables/disables the Peptide Generator command by hiding or
    showing it in the Command Manager toolbar and menu.
    The enabling/disabling is done by the user via the "secret" NE1 debugging
    menu.

    To display the secret debugging menu, hold down Shift+Ctrl+Alt keys
    (or Shift+Cmd+Alt on Mac) and right click over the graphics area.
    Select "debug prefs submenu > Peptide Generator" and
    set the value to True. The "Peptide" option will then appear on the
    "Build" Command Manager toolbar/menu.

    @param enable: If true, the Peptide Generator is enabled. Specifically, it
                   will be added to the "Build" Command Manager toolbar and
                   menu.
    @type  enable: bool
    """
    win = env.mainwindow()
    win.buildProteinAction.setVisible(enable)

def get_unit_length(phi, psi):
    """
    Calculate a length of single amino acid in particular 
    secondary conformation.
    """
    # All unit length values obtained via measurements by me.
    # Fixes bug 2959. --Mark 2008-12-23
    if phi == -57.0 and psi == -47.0:
        unit_length = 1.5 # Alpha helix
    elif phi == -135.0 and psi == 135.0:
        unit_length = 3.4 # Beta strand
    elif phi == -55.0 and psi == -70.0:
        unit_length = 1.05 # Pi helix
    elif phi == -49.0 and psi == -26.0:
        unit_length = 1.95 # 3_10 helix
    elif phi == -75.0 and psi == 150.0:
        unit_length = 3.14 # Polyproline-II helix
    elif phi == -180.0 and psi == 180.0:
        unit_length = 3.6 # Fully extended
    else:
        # User chose "Custom" conformation option in the Insert Peptide PM 
        # which lets the user set any phi-psi angle values.
        # We need a formula to estimate the proper unit_length given the
        # conformational angles phi and psi. It would also be a good idea
        # to check these values to confirm they are an allowed combination.
        # For more info, do a google search for "Ramachandran plot".
        # For now, I'm setting the unit length to 1.5. --Mark 2008-12-23
        unit_length = 1.5
        msg = "\nUser selected custom conformational angles: "\
            "phi=%.2f, psi=%.2f.\nSetting unit_length=%.2f\n" % \
            (phi, psi, unit_length)
        print_compact_stack(msg)
        
    return unit_length
    
class PeptideGenerator:
    prev_coords = zeros([3,3], Float)

    peptide_mol = None
    length = 0
    prev_psi = 0
    
    # Based on analogous Nanotube Builder method.
    def _orient(self, chunk, pt1, pt2):
        """
        Orients the Peptide I{chunk} based on two points. I{pt1} is
        the first endpoint (origin) of the Peptide. The vector I{pt1}, I{pt2}
        defines the direction and central axis of the Peptide.
        
        piotr 080801: I copied this method from Nanotube Builder.
        
        @param pt1: The starting endpoint (origin) of the Peptide.
        @type  pt1: L{V}
        
        @param pt2: The second point of a vector defining the direction
                    and central axis of the Peptide.
        @type  pt2: L{V}
        """
        
        a = V(0.0, 0.0, -1.0)
        # <a> is the unit vector pointing down the center axis of the default
        # structure which is aligned along the Z axis.
        bLine = pt2 - pt1
        bLength = vlen(bLine)
        if bLength == 0:
            return
        b = bLine / bLength
        # <b> is the unit vector parallel to the line (i.e. pt1, pt2).
        axis = cross(a, b)
        # <axis> is the axis of rotation.
        theta = angleBetween(a, b)
        # <theta> is the angle (in degress) to rotate about <axis>.
        scalar = bLength * 0.5
        rawOffset = b * scalar
        
        if theta == 0.0 or theta == 180.0:
            axis = V(0, 1, 0)
            # print "Now cross(a,b) =", axis
            
        rot =  (pi / 180.0) * theta  # Convert to radians
        qrot = Q(axis, rot) # Quat for rotation delta.
        
        # Move and rotate the Peptide into final orientation.
        
        chunk.move(-chunk.center)

        chunk.rot(qrot)
        
        # Bruce suggested I add this. It works here, but not if its 
        # before move() and rot() above. Mark 2008-04-11
        chunk.full_inval_and_update()
        return
        
    def get_number_of_res(self, pos1, pos2, phi, psi):
        """
        Calculate a number of residues necessary to fill 
        the pos1-pos2 vector.
        
        @param pos1, pos2: vector points
        @type pos1, pos2: V
        
        @param phi, psi: peptide chain angles
        @type phi, psi: float
        """
        return 1 + int(vlen(pos2 - pos1) / get_unit_length(phi, psi))
    
    def make_aligned(self, 
                     assy, 
                     name, 
                     aa_idx, 
                     phi, psi, 
                     pos1, pos2, 
                     secondary = SS_COIL, 
                     fake_chain = False, 
                     length = None):
        """
        Build and return a chunk that is a homo-peptide aligned to 
        a pos2-pos1 vector.
        
        @param aa_idx: amino acid type (index in AMINO_ACIDS list)
        @type aa_idx: int
        
        @param name: chunk name
        @type name: string
        
        @param phi, psi: peptide bond angles 
        @type phi, psi: float
        
        @param pos1, pos2: desired peptide positions (beginning and end)
        @type pos1, pos2: V
        
        @param secondary: secondary structure class, used for visual representation
        The actual peptide chain conformation is based on phi / psi angles.
        @type secondary: int
        
        @param fake_chain: if True, create only C-alpha atoms. used for drawing
        peptide trace image during interactive peptide placement (used by
        PeptideLine_GraphicsMode.py)
        @type fake_chain: boolean
        
        @param length: optional peptide length (number of amino acids), if 
        not specified, pos1 and pos2 are used to figure out the length
        @type length: int
        
        @return: A homo-polypeptide chain.
        @rtype:  L{Chunk}
        """

        if not length:
            self.length = self.get_number_of_res(pos1, pos2, phi, psi)
            if self.length == 0:
                return None
        else:
            self.length = length
            
        # Create a molecule
        mol = Chunk(assy, name)
            
        if not fake_chain:
            mol.protein = Protein()
            mol.protein.set_chain_id('A')
            
        # Generate dummy atoms positions
        self.prev_coords[0][0] = pos1[0] - 1.0
        self.prev_coords[0][1] = pos1[1] - 1.0
        self.prev_coords[0][2] = pos1[2] 

        self.prev_coords[1][0] = pos1[0] - 1.0
        self.prev_coords[1][1] = pos1[1] 
        self.prev_coords[1][2] = pos1[2] 

        self.prev_coords[2][0] = pos1[0]
        self.prev_coords[2][1] = pos1[1]
        self.prev_coords[2][2] = pos1[2]

        name, short_name, symbol, zmatrix, size = AMINO_ACIDS[aa_idx]
        
        # Add a N-terminal hydrogen
        self.nterm_hydrogen = None

        # Initially, the Peptide Builder was creating peptide structures
        # saturated at both ends, i.e. with N-terminal hydrogen and C-terminal
        # OH group present. Currently, this code is commented out to allow 
        # connecting multiple peptide structure be creating bonds between
        # the C- and N- terminal ends of two individual structures.
        """
        if not fake_chain:
            atom = Atom("H", pos1, mol)
            atom._is_aromatic = False
            atom._is_single = False
            self.nterm_hydrogen = atom
            mol.protein.add_pdb_atom(atom, "H", 1, name)
            atom.pdb_info = {}
            atom.pdb_info['atom_name'] = "H"
            atom.pdb_info['residue_name'] = short_name
            atom.pdb_info['residue_id'] = "  1 "
            atom.pdb_info['standard_atom'] = True
        """
    
        self.init_ca = None
        
        # Generate the peptide chain.
        for idx in range(int(self.length)):
            self._buildResidue(mol, zmatrix, size, idx+1, phi, psi, secondary, None, short_name, fake_chain=fake_chain)

        # See the comment above.
        """
        # Add a C-terminal OH group
        self._buildResidue(mol, CTERM_ZMATRIX, 5, int(self.length), 0.0, 0.0, secondary, None, short_name, fake_chain=fake_chain)        
        """
        
        # Compute bonds (slow!)
        # This should be replaced by a proper bond assignment.
        
        if not fake_chain:
            inferBonds(mol)

        # Assign proper bond orders.
        i = 1
        for atom in mol.atoms.itervalues():
            if atom.bonds:
                for bond in atom.bonds:
                    if bond.atom1.getAtomTypeName()=="sp2" and \
                       bond.atom2.getAtomTypeName()=="sp2":
                        if (bond.atom1._is_aromatic and
                            bond.atom2._is_aromatic):
                            bond.set_v6(V_AROMATIC)
                        elif ((bond.atom1._is_aromatic == False and
                               bond.atom1._is_aromatic == False) and
                               not (bond.atom1._is_single and
                                    bond.atom2._is_single)):
                            bond.set_v6(V_DOUBLE)
            i += 1
                            
        # Remove temporary attributes.
        for atom in mol.atoms.itervalues():
            del atom._is_aromatic
            del atom._is_single

        # Axis of first selected chunk
        ax = V(0.,0.,1.) 
        mol.rot(Q(mol.getaxis(),ax))
        
        self._orient(mol, pos2, pos1)
        
        if self.init_ca:
            mol.move(pos1 - self.init_ca.posn())
        
        mol_dummy = None
        
        return mol          

    def _buildResidue(self, mol, zmatrix, n_atoms, idx, phi, psi, secondary, init_pos, residue_name, fake_chain=False):
        """
        Builds cartesian coordinates for an amino acid from the internal
        coordinates table.

        @param mol: a chunk to which the amino acid will be added.
        @type mol: Chunk
        
        @param zmatrix: is an internal coordinates array corresponding to a 
        given amino acid.
        @type zmatrix: list
        
        @param n_atoms: size of z-matrix (a number of atoms to be build + 3 
        dummy atoms)
        @type n_atoms: int

        @param idx: is a residue index (1..length).
        @type idx: integer
        
        @param phi, psi: peptide bond phi and psi angles
        @type phi, psi: float
        
        @param init_pos: optional postions of previous CA, C and O atoms.
        @type init_pos: V
        
        @param symbol: current amino acid symbol (used to derermine proline case)
        @type symbol: string
        
        """

        # note: currently, it doesn't rebuild bonds, so inferBonds has to be 
        # called after this method. Unfortunately, the proper bond order can 
        # not be correctly recognized this way. Therefore, temporary atom flags 
        # _is_aromatic and _is_single are used.
        
        #this code was re-factored by EricM and internal-to-cartesian
        # conversion method was moved to geometry.InternalCoordinatesToCartesian

        if mol is None:
            return

        if not init_pos: # assign three previous atom positions
            coords = self.prev_coords
        else: 
            # if no prev_coords are given, compute the first three atom positions
            coords = zeros([3,3], Float)
            num, name, atom_name, atom_type, \
               atom_c, atom_b, atom_a, r, a, t = zmatrix[1]
            coords[0][0] = 0.0;
            coords[0][1] = 0.0;
            coords[0][2] = 0.0;
            coords[1][0] = r;
            coords[1][1] = 0.0;
            coords[1][2] = 0.0;
            ccos = cos(DEG2RAD*a)
            num, name, atom_name, atom_type, \
               atom_c, atom_b, atom_a, r, a, t = zmatrix[2]
            if atom_c == 1:
                coords[2][0] = coords[0][0] + r*ccos
            else:
                coords[2][0] = coords[0][0] - r*ccos
            coords[2][1] = r * sin(DEG2RAD*a)
            coords[2][2] = 0.0
            for i in range (0, 3):
                self.prev_coords[i][0] = coords[i][0] + init_pos[0]
                self.prev_coords[i][1] = coords[i][1] + init_pos[1]
                self.prev_coords[i][2] = coords[i][2] + init_pos[2]

        translator = InternalCoordinatesToCartesian(n_atoms, coords)

        for n in range (3, n_atoms):
            # Generate all coordinates using three previous atoms
            # as a frame of reference,
            num, name, atom_name, atom_type, \
               atom_c, atom_b, atom_a, r, a, t = zmatrix[n]

            # Apply the peptide bond conformation
            if residue_name != "PRO":
                if name == "N  " and not init_pos:
                    t = self.prev_psi + 0.0
                if name == "O  ":
                    t = psi + 180.0
                if name == "HA " or name == "HA2":
                    t = 120.0 + phi
                if name == "CB " or name == "HA3":
                    t = 240.0 + phi
                if name == "C  ":
                    t = phi
            else:
                # proline
                if name == "N  " and not init_pos:
                    t = self.prev_psi + 0.0
                if name == "O  ":
                    t = psi + 180.0
                if name == "CA ":
                    t = phi - 120.0
                if name == "CD ":
                    t = phi + 60.0

            translator.addInternal(n+1, atom_c+1, atom_b+1, atom_a+1, r, a, t)
            xyz = translator.getCartesian(n+1)

            if self.nterm_hydrogen:
                # This is a hack for the first hydrogen atom
                # to make sure the bond length is correct.
                self.nterm_hydrogen.setposn(
                    self.nterm_hydrogen.posn() + \
                    0.325 * norm(xyz))
                self.nterm_hydrogen = None

            # Store previous coordinates for the next building step
            if not init_pos:
                if name=="N  ":
                    self.prev_coords[0][0] = xyz[0]
                    self.prev_coords[0][1] = xyz[1]
                    self.prev_coords[0][2] = xyz[2]
                if name=="CA ":
                    self.prev_coords[1][0] = xyz[0]
                    self.prev_coords[1][1] = xyz[1]
                    self.prev_coords[1][2] = xyz[2]
                if name=="C  ":
                    self.prev_coords[2][0] = xyz[0]
                    self.prev_coords[2][1] = xyz[1]
                    self.prev_coords[2][2] = xyz[2]
                    
            # Add a new atom to the molecule
            if not fake_chain or \
               name == "CA ":
                atom = Atom(
                    atom_name,
                    xyz,
                    mol)

                if not self.init_ca and \
                   name == "CA ":
                    self.init_ca = atom

                if mol.protein:
                    aa = mol.protein.add_pdb_atom(atom, 
                                             name.replace(' ',''), 
                                             idx, 
                                             AA_3_TO_1[residue_name])
                    atom.pdb_info = {}
                    atom.pdb_info['atom_name'] = name.replace(' ','')
                    atom.pdb_info['residue_name'] = residue_name
                    residue_id = "%3d " % idx
                    atom.pdb_info['residue_id'] = residue_id
                    atom.pdb_info['standard_atom'] = True
                    atom.pdb_info['chain_id'] = True
                    if aa:
                        aa.set_secondary_structure(secondary)

                # Create temporary attributes for proper bond assignment.
                atom._is_aromatic = False
                atom._is_single = False

                if atom_type == "sp2a":
                    atom_type = "sp2"
                    atom._is_aromatic = True

                if atom_type == "sp2s":
                    atom_type = "sp2"
                    atom._is_single = True

                atom.set_atomtype_but_dont_revise_singlets(atom_type)
                
                ### debug - output in PDB format	
                ### print "ATOM  %5d  %-3s %3s %c%4d    %8.3f%8.3f%8.3f" % ( n, name, "ALA", ' ', res_num, xyz[0], xyz[1], xyz[2])	

        self.prev_psi = psi # Remember previous psi angle.

        return
    
# end