summaryrefslogtreecommitdiff
path: root/cad/src/commands/InsertPeptide/PeptideGenerator.py
blob: 7b6ca8b0ca7d8dee0bccb3b7072d690dc1190328 (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
# 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.
"""

import foundation.env as env
import platform

from commands.InsertPeptide.PeptideGeneratorPropertyManager import PeptideGeneratorPropertyManager
from command_support.GeneratorBaseClass import GeneratorBaseClass

from utilities.Log import greenmsg

from model.chem import Atom
from model.chunk import Chunk

from model.bonds import bond_atoms
from model.bonds import NeighborhoodGenerator
from model.bond_constants import atoms_are_bonded
from model.bond_constants import V_SINGLE, V_DOUBLE, V_AROMATIC
from operations.bonds_from_atoms import inferBonds

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

# 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", "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, "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", "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, "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", "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, "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.400,  120.000,  240.000 ),
    (  12, "HD1", "H", "",      11,   10,    7,    1.090,  120.000,    0.000 ),
    (  13, "CE1", "C", "sp2",   11,   10,    7,    1.400,  120.000,  180.000 ),
    (  14, "HE1", "H", "",      13,   11,   10,    1.090,  120.000,  180.000 ),
    (  15, "CZ ", "C", "sp2",   13,   11,   10,    1.400,  120.000,    0.000 ),
    (  16, "HZ ", "H", "",      15,   13,   11,    1.090,  120.000,  180.000 ),
    (  17, "CE2", "C", "sp2",   15,   13,   11,    1.400,  120.000,    0.000 ),
    (  18, "HE2", "H", "",      17,   15,   13,    1.090,  120.000,  180.000 ),
    (  19, "CD2", "C", "sp2",   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", "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, "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", "sp3",   10,    7,    5,    1.527,  109.470,  180.000 ),
    (  14, "OE1", "O", "sp3",   13,   10,    7,    1.260,  117.200,   90.000 ),
    (  15, "OE2", "O", "sp3",   13,   10,    7,    1.260,  117.200,  270.000 ),
    (  16, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  17, "O  ", "O", "sp2",   16,    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", "sp3",    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", "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, "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", "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, "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", "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, "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", "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, "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", "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,  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", "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, "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", "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, "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,  115.000,  180.000 ),
    (  11, "CD1", "C", "sp3",   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", "sp2",   13,   11,   10,    1.310,  109.000,    0.000 ),
    (  16, "CZ2", "C", "sp2",   15,   13,   11,    1.400,  128.000,  180.000 ),
    (  17, "HZ2", "H", "",      16,   15,   13,    1.090,  120.000,    0.000 ),
    (  18, "CH2", "C", "sp2",   16,   15,   13,    1.390,  116.000,  180.000 ),
    (  19, "HH2", "H", "",      18,   16,   15,    1.090,  120.000,  180.000 ),
    (  20, "CZ3", "C", "sp2",   18,   16,   15,    1.350,  121.000,    0.000 ),
    (  21, "HZ3", "H",  "",     20,   18,   16,    1.090,  120.000,  180.000 ),
    (  22, "CE3", "C", "sp2",   20,   18,   16,    1.410,  122.000,    0.000 ),
    (  23, "HE3", "H", "",      22,   20,   18,    1.090,  120.000,  180.000 ),
    (  24, "CD2", "C", "sp2",   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", "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, "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,  109.470,  180.000 ),
    (  11, "CD1", "C", "sp2",   10,    7,    5,    1.400,  120.000,  180.000 ),
    (  12, "HD1", "H", "",      11,   10,    7,    1.090,  120.000,    0.000 ),
    (  13, "CE1", "C", "sp2",   11,   10,    7,    1.400,  120.000,  180.000 ),
    (  14, "HE1", "H", "",      13,   11,   10,    1.090,  120.000,  180.000 ),
    (  15, "CZ ", "C", "sp2",   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", "sp2",   15,   13,   11,    1.400,  120.000,    0.000 ),
    (  19, "HE2", "H", "",      18,   15,   13,    1.090,  120.000,  180.000 ),
    (  20, "CD2", "C", "sp2",   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", "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, "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", "C", "sp3",   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, "HZ3", "H", "",      19,   16,   13,    1.010,  109.470,  300.000 ),
    (  23, "C  ", "C", "sp2",    5,    3,    2,    1.522,  111.100,  180.000 ),
    (  24, "O  ", "O", "sp2",   23,    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", "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, "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", "sp3",   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",  "sp3",  18,   16,   13,    1.330,  118.000,  180.000 ),
    (  23, "HH2", "H",  "",     22,   18,   16,    1.010,  119.800,    0.000 ),
    (  24, "HH2", "H",  "",     22,   18,   16,    1.010,  119.800,  180.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 ),
]               

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", "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, "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", "sp2",   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", "sp2",   13,   11,   10,    1.310,  109.000,    0.000 ),
    (  16, "CD2", "C", "sp2",   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", "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, "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.527,  109.470,  180.000 ),
    (  11, "OD1",  "O", "sp3",  10,    7,    5,    1.260,  117.200,   90.000 ),
    (  12, "OD2",  "O", "sp3",  10,    7,    5,    1.260,  117.200,  270.000 ),
    (  13, "C  ",  "C", "sp2",   5,    3,    2,    1.522,  111.100,  180.000 ),
    (  14, "O  ",  "O", "sp2",  13,    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", "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, "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.522,  111.100,  180.000 ),
    (  11, "OD1", "O", "sp3",   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", "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, "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.522,  111.100,  180.000 ),
    (  14, "OE1", "O", "sp3",   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 ),
]                   


# all amino acids, z-matrices and their sizes
AMINO_ACIDS = [
    ( "Alanine",       "ALA", "A", ALA_ZMATRIX, 13 ),
    ( "Arginine",      "ARG", "R", ARG_ZMATRIX, 27 ),
    ( "Asparagine",    "ARG", "N", ASN_ZMATRIX, 17 ),
    ( "Aspartic Acid", "ARG", "D", ASP_ZMATRIX, 15 ),
    ( "Cysteine",      "CYS", "C", CYS_ZMATRIX, 14 ),
    ( "Glutamic Acid", "GLU", "E", GLU_ZMATRIX, 18 ),
    ( "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, 25 ),
    ( "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.insertPeptideAction.setVisible(enable)

class PeptideGenerator(PeptideGeneratorPropertyManager, GeneratorBaseClass):
    """
    The Peptide Generator class for the "Build > Peptide" command.
    """

    cmd = greenmsg("Build Peptide: ")
    prefix = 'Peptide'   # used for gensym
    # Generators for DNA, peptides, nanotubes and graphene have their MT name generated 
    # (in GeneratorBaseClass) from the prefix.
    create_name_from_prefix = True 

    # Peptide sponsor keywords
    sponsor_keyword = ('Peptides', 'Proteins')

    def __init__(self, win):
        self.coords = zeros([30,3], Float)		
        self.prev_coords = zeros([3,3], Float)

        self.peptide_mol = None
        self.length = 0
        self.prev_psi = 0

        PeptideGeneratorPropertyManager.__init__(self)
        GeneratorBaseClass.__init__(self, win)

    def gather_parameters(self):
        """
        Return all the parameters from the Property Manager dialog.
        """        

        return (self.length)

    def _buildResiduum(self, mol, zmatrix, n_atoms, phi, psi):
        """
	Builds cartesian coordinates for an amino acid from the internal coordinates table.
	mol is a chunk to where the amino acid will be added. 

	zmatrix is an internal coordinates array corresponding to a given amino acid.
	n_atoms is a number of atoms to be build + 3 dummy atoms.
	phi is a peptide bond PHI angle.
	psi is a peptide bond PSI angle.

	Note: currently, it doesn't rebuild bonds, so inferBonds has to be called after.
	Unfortunately, the bond order is not correctly recognized this way.
	"""

        if mol==None:
            return

        if self.prev_coords: # assign three previous atom positions
            for i in range (0,3):
                self.coords[i][0] = self.prev_coords[i][0]
                self.coords[i][1] = self.prev_coords[i][1]
                self.coords[i][2] = self.prev_coords[i][2]
        else: # if no prev_coords are given, compute the first three atom positions
            num, name, atom_name, atom_type, atom_c, atom_b, atom_a, r, a, t = zmatrix[1]
            self.coords[1][0] = r;
            self.coords[1][1] = 0.0;
            self.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 mc==1: 
                self.coords[2][0] = self.coords[0][0]+r*ccos
            else:
                self.coords[2][0] = self.coords[0][0]-r*ccos					
            self.coords[2][1] = r * sin(DEG2RAD*a)
            self.coords[2][2] = 0.0

        for n in range (3, n_atoms): # generate all coordinates using three atoms 
                                        # as a frame of reference
            num, name, atom_name, atom_type, atom_c, atom_b, atom_a, r, a, t = zmatrix[n]
            cosa = cos(DEG2RAD*a)
            xb = self.coords[atom_b][0]-self.coords[atom_c][0]
            yb = self.coords[atom_b][1]-self.coords[atom_c][1]
            zb = self.coords[atom_b][2]-self.coords[atom_c][2]
            rbc = 1.0/sqrt(xb*xb+yb*yb+zb*zb)
            if abs(cosa)>=0.999: # almost linear bond
                rbc = r*rbc*cosa
                self.coords[n][0] = self.coords[atom_c][0]+xb*rbc
                self.coords[n][1] = self.coords[atom_c][1]+yb*rbc
                self.coords[n][2] = self.coords[atom_c][2]+zb*rbc
            else:
                xa = self.coords[atom_a][0]-self.coords[atom_c][0]
                ya = self.coords[atom_a][1]-self.coords[atom_c][1]
                za = self.coords[atom_a][2]-self.coords[atom_c][2]
                xyb = sqrt(xb*xb+yb*yb)
                inv = False
                if xyb<=0.001:
                    xpa = za
                    za = -xa
                    xa = xpa
                    xpb = zb
                    zb = -xb
                    xb = xpb
                    xyb = sqrt(xb*xb+yb*yb)
                    inv = True
                costh = xb/xyb
                sinth = yb/xyb
                xpa = xa*costh+ya*sinth
                ypa = ya*costh-xa*sinth
                sinph = zb*rbc
                cosph = sqrt(abs(1.0-sinph*sinph))
                xqa = xpa*cosph+za*sinph
                zqa = za*cosph-xpa*sinph      
                yza = sqrt(ypa*ypa+zqa*zqa)
                if yza<1e-8:
                    coskh = 1.0
                    sinkh = 0.0
                else:
                    coskh = ypa/yza
                    sinkh = zqa/yza				
                # apply the peptide bond conformation 
                if name=="N  ":
                    t = self.prev_psi
                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
                sina = sin(DEG2RAD*a)
                sind = -sin(DEG2RAD*t)
                cosd = cos(DEG2RAD*t)
                xd = r*cosa
                yd = r*sina*cosd
                zd = r*sina*sind     
                ypd = yd * coskh - zd * sinkh
                zpd = zd * coskh + yd * sinkh
                xpd = xd * cosph - zpd * sinph
                zqd = zpd * cosph + xd * sinph
                xqd = xpd * costh - ypd * sinth
                yqd = ypd * costh + xpd * sinth
                if inv: 
                    xrd = -zqd
                    zqd = xqd
                    xqd = xrd
                self.coords[n][0] = xqd+self.coords[atom_c][0]
                self.coords[n][1] = yqd+self.coords[atom_c][1]
                self.coords[n][2] = zqd+self.coords[atom_c][2]
                # store previous coordinates for the next building step
                if name=="N  ":
                    self.prev_coords[0][0] = self.coords[n][0]
                    self.prev_coords[0][1] = self.coords[n][1]
                    self.prev_coords[0][2] = self.coords[n][2]
                if name=="CA ":
                    self.prev_coords[1][0] = self.coords[n][0]
                    self.prev_coords[1][1] = self.coords[n][1]
                    self.prev_coords[1][2] = self.coords[n][2]
                if name=="C  ":
                    self.prev_coords[2][0] = self.coords[n][0]
                    self.prev_coords[2][1] = self.coords[n][1]
                    self.prev_coords[2][2] = self.coords[n][2]
                # add a new atom to the molecule	
                atom = Atom(atom_name, V(self.coords[n][0], self.coords[n][1], self.coords[n][2]), mol)    
                atom.set_atomtype_but_dont_revise_singlets(atom_type)
                
                if name=="CA ": # set c-alpha flag for visualization
                    atom.is_calpha = True
                else:
                    atom.is_calpha = False

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

        self.prev_psi = self.psi # remember previous psi angle
        self.length += 1 # increase amino acid counter

        return        

    def build_struct(self, name, params, position, mol=None, createPrinted=False):
        """
        Build a peptide from a sequence entered through the Property Manager dialog.
        """

        # create a molecule	
        mol = Chunk(self.win.assy,name)

        # generate dummy atom positions
        # starting approximately at <position>

        self.prev_coords[0][0] = position[0]-2.0
        self.prev_coords[0][1] = position[1]
        self.prev_coords[0][2] = position[2]

        self.prev_coords[1][0] = position[0]-1.5
        self.prev_coords[1][1] = position[1]+1.5
        self.prev_coords[1][2] = position[2]

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

        # Generate the peptide chain.
        self.length = 1	
        for index, phi, psi in self.peptide_cache:
            name, short_name, symbol, zmatrix, size = AMINO_ACIDS[index]
            self._buildResiduum(mol, zmatrix, size, phi, psi)

        # Compute bonds (slow!)
        # This should be replaced by a proper bond assignment. 
        inferBonds(mol)

        # Assign proper bond orders.
        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.element.symbol=="C" and 
                             bond.atom2.element.symbol=="C")): 
                            bond.set_v6(V_AROMATIC)
                        else:
                            bond.set_v6(V_DOUBLE)
                            
                    
        return mol

    def addAminoAcid(self, index):        
        """
	Adds a new amino acid to the peptide molecule.
	This is going to be displayed after user accepts or previews the structure.
	"""

        # add a new amino acid and chain conformation to the peptide cache
        self.peptide_cache.append((index,self.phi,self.psi))

        return

# end