This file is indexed.

/usr/lib/python2.7/dist-packages/chempy/tinker/amber.py is in pymol 1.8.4.0+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
#A* -------------------------------------------------------------------
#B* This file contains source code for the PyMOL computer program
#C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific. 
#D* -------------------------------------------------------------------
#E* It is unlawful to modify or remove this copyright notice.
#F* -------------------------------------------------------------------
#G* Please see the accompanying LICENSE file for further information. 
#H* -------------------------------------------------------------------
#I* Additional authors of this source file include:
#-* Scott Dixon, Metaphorics, LLC
#-* 
#-*
#Z* -------------------------------------------------------------------

from __future__ import print_function

from chempy import feedback

import string
import copy

default_extra = { # atomic number, and normal valency (for tinker)
    # NOTE: THIS SET IS ONLY USED IF THERE ARE NO TINKER RECORDS
    # IN THE PARAMETER FILE
    # bromine 
    'BR' : [                 35 ,               1 ],
    # carbon                           
    'C'  : [                  6 ,               3 ],
    'CA' : [                  6 ,               3 ],
    'CB' : [                  6 ,               3 ],
    'CC' : [                  6 ,               3 ],
    'CF' : [                  6 ,               3 ],
    'CK' : [                  6 ,               3 ],
    'CM' : [                  6 ,               3 ],
    'CN' : [                  6 ,               3 ],
    'CQ' : [                  6 ,               3 ],
    'CR' : [                  6 ,               3 ],
    'CT' : [                  6 ,               4 ],
    'CV' : [                  6 ,               3 ],
    'CW' : [                  6 ,               3 ], 
    'CY' : [                  6 ,               2 ],
    'CX' : [                  6 ,               2 ],
    'C5' : [                  6 ,               3 ],
    'C*' : [                  6 ,               3 ],
    # calcium
    'C0' : [                 20 ,               3 ],
    # chloride
    'Cl' : [                 17 ,               1 ], 
    # fluorine
    'F'  : [                  9 ,               1 ],
    # hydrogen
    'H'  : [                  1 ,               1 ],
    'H1' : [                  1 ,               1 ],
    'H2' : [                  1 ,               1 ],
    'H3' : [                  1 ,               1 ],
    'H4' : [                  1 ,               1 ],
    'H5' : [                  1 ,               1 ],
    'HA' : [                  1 ,               1 ],
    'HC' : [                  1 ,               1 ],
    'HO' : [                  1 ,               1 ],
    'HP' : [                  1 ,               1 ],
    'HS' : [                  1 ,               1 ],
    'HW' : [                  1 ,               2 ],
    # iodine
    'I'  : [                 53 ,               1 ],
    # chloride anion
    'IM' : [                 17 ,               0 ],
    # sodium cation
    'IP' : [                 11 ,               0 ],
    # magnesium
    'MG' : [                 12 ,               0 ],
    # nitrogen
    'N'  : [                  7 ,               3 ],
    'N*' : [                  7 ,               2 ],
    'N2' : [                  7 ,               3 ],
    'N3' : [                  7 ,               4 ],
    'NA' : [                  7 ,               3 ],
    'NB' : [                  7 ,               2 ],
    'NC' : [                  7 ,               2 ],
    'NX' : [                  7 ,               2 ],
    'NZ' : [                  7 ,               3 ],
    #
    'OW' : [                  8 ,               2 ],
    'OH' : [                  8 ,               2 ],
    'OS' : [                  8 ,               2 ],
    'O'  : [                  8 ,               1 ],
    'O2' : [                  8 ,               1 ],
    'OM' : [                  8 ,               1 ],
    'OZ' : [                  8 ,               1 ],   
    'P'  : [                 15 ,               4 ],
    'S'  : [                 16 ,               2 ],
    'SO'  : [                16 ,               4 ],
    'SX'  : [                16 ,               2 ],
    'SH' : [                 16 ,               2 ],
    # copper
    'CU' : [                 29 ,               0 ],
    # iron
    'FE' : [                 26 ,               0 ],
    # lithium
    'Li' : [                  3 ,               0 ],
    # potassium
    'K'  : [                 19 ,               0 ],
    # rubidium
    'Rb' : [                 37 ,               0 ],
    # cesium
    'Cs' : [                 55 ,               0 ],
    # calcium (alternate)
    'Ca' : [                 20 ,               0 ],
    # dummy
    'X ' : [                  6 ,               1 ],
    # zinc
    'Z0' : [                 30 ,               0 ],
    'Z4' : [                 30 ,               4 ],
    'Z5' : [                 30 ,               5 ],
    }

class Parameters:

    def __init__(self,fname):
        if feedback['actions']:
            print(' '+str(self.__class__)+': loading from "%s"...' % fname)
        f = open(fname)
        # skip
        l = f.readline()
        # read names & molecular weights
        self.type = []
        self.mw = {}
        while 1:
            l = string.strip(f.readline())
            if not len(l): break
            a2 = string.strip(l[0:2])
            self.type.append(a2)
            self.mw[a2] = [float(l[3:13]),string.strip(l[34:])]
        # skip 1
        l = f.readline()
        # read bonds
        self.bond = {}
        while 1:
            l = string.strip(f.readline())
            if not len(l): break
            a5 = l[0:5]
            self.bond[a5] = [float(l[5:12]),float(l[12:22]),
                                  string.strip(l[22:])]
        # read angles
        self.angle = {}
        while 1:
            l = string.strip(f.readline())
            if not len(l): break
            a5 = l[0:8]
            self.angle[a5] = [float(l[8:16]),float(l[16:28]),
                                  string.strip(l[28:])]
        # read torsion 
        self.torsion = {}
        while 1:
            l = string.strip(f.readline())
            if not len(l): break
            a5 = l[0:11]
            if a5 in self.torsion:
                self.torsion[a5].extend(
                    [int(l[11:15]),
                     float(l[15:27]),
                     float(l[27:36]),
                     abs(int(float(l[40:52]))),
                     string.strip(l[52:])])
            else:
                self.torsion[a5] = [int(l[11:15]),
                                          float(l[15:27]),
                                          float(l[27:36]),
                                          abs(int(float(l[40:52]))),
                                          string.strip(l[52:])]
        # read impropers
        self.improper = {}
        while 1:
            l = string.strip(f.readline())
            if not len(l): break
            a5 = l[0:11]
            self.improper[a5] = [float(l[15:27]),
                                        float(l[27:40]),
                                        abs(int(float(l[40:51]))),
                                        string.strip(l[51:])]
        # skip
        while 1:
            l = string.strip(f.readline())
            if not len(l): break
        # read vdw equivalents 
        self.vdw_eq = {}
        while 1:
            l = string.strip(f.readline())
            if not len(l): break
            a4 = string.strip(l[0:4])
            l = l[4:]
            while len(l):
                self.vdw_eq[string.strip(l[0:4])] = a4
                l = l[4:]
        # skip
        l = string.strip(f.readline())
        # read vdw parameters
        self.vdw = {}
        while 1:
            l = string.strip(f.readline())
            if not len(l): break
            l = '  ' + l
            a4 = string.strip(l[0:4])
            self.vdw[a4] =  [float(l[4:20]),
                                  float(l[20:37]),
                                  string.strip(l[37:])]
            
        # read extra tinker information if present
        self.extra = {}
        while 1:
            l = f.readline()
            if not l: break
            if l[0:6] == 'TINKER':
                self.extra[string.strip(l[6:12])]  = [
                    int(l[12:18]),
                    int(l[18:24])]
        if not self.extra:
                self.extra = default_extra
        # now generate redundant equivalents
        for a in self.vdw_eq.keys():
            self.vdw[a] = self.vdw[self.vdw_eq[a]]
        for a in list(self.bond.keys()):
            k = a[3:5]+'-'+a[0:2]
            self.bond[k] = self.bond[a]
        for a in list(self.angle.keys()):
            k = a[6:8]+'-'+a[3:5]+'-'+a[0:2]
            self.angle[k] = self.angle[a]
            
    def dump(self):
        for b in self.type:
            print(b)
        kees = list(self.mw.keys())
        kees.sort()
        for b in kees:
            print(b,self.mw[b])
        kees = list(self.vdw_eq.keys())
        kees.sort()
        for b in kees:
            print(b,self.vdw_eq[b])
        kees = list(self.vdw.keys())
        kees.sort()
        for b in kees:
            print(b,self.vdw[b])
        kees = list(self.bond.keys())
        kees.sort()
        for b in kees:
            print(b,self.bond[b])
        kees = list(self.angle.keys())
        kees.sort()
        for b in kees:
            print(b,self.angle[b])
        kees = list(self.torsion.keys())
        kees.sort()
        for b in kees:
            print(b,self.torsion[b])
        kees = list(self.improper.keys())
        kees.sort()
        for b in kees:
            print(b,self.improper[b])
        kees = list(self.vdw.keys())
        kees.sort()
        for b in kees:
            print(b,self.vdw[b])
            

class Topology:

    def __init__(self,model):
        self.model = model
        if feedback['actions']:
            print(' '+str(self.__class__)+': searching...')
        # get a connected version too
        cmodel = copy.deepcopy(model).convert_to_connected()
        # find atom types in molecule
        self.present = {}
        for a in model.atom:
            self.present[a.text_type] = 1
        # copy bonds
        self.bond = {}
        for b in model.bond:
            a0 = b.index[0]
            a1 = b.index[1]
            if a0 < a1:
                self.bond[(a0,a1)] = 1
            else:
                self.bond[(a1,a0)] = 1
        # find angles
        self.angle = {}
        ang = self.angle
        for b in model.bond:
            a0 = b.index[0]
            a1 = b.index[1]
            for c in cmodel.bond[a0]: # a0 in center
                a2 = c.index[0] 
                if a2 not in (a0,a1): # outside atom
                    if a1 < a2:
                        an = (a1,a0,a2)
                    else:
                        an = (a2,a0,a1)                  
                    ang[an] = 1
                a2 = c.index[1]
                if a2 not in (a0,a1): # outside atom
                    if a1 < a2:
                        an = (a1,a0,a2)
                    else:
                        an = (a2,a0,a1)                  
                    ang[an] = 1
            for c in cmodel.bond[a1]: # a1 in center
                a2 = c.index[0] 
                if a2 not in (a0,a1): # outside atom
                    if a0 < a2:
                        an = (a0,a1,a2)
                    else:
                        an = (a2,a1,a0)                  
                    ang[an] = 1
                a2 = c.index[1]
                if a2 not in (a0,a1): # outside atom
                    if a0 < a2:
                        an = (a0,a1,a2)
                    else:
                        an = (a2,a1,a0)                  
                    ang[an] = 1
        # find torsions
        self.torsion = {}
        tors = self.torsion
        for b in model.bond: # use bond as center of torsion
            a1 = b.index[0]
            a2 = b.index[1]
            for c in cmodel.bond[a1]: 
                a0 = c.index[0] 
                if a0 not in (a1,a2): # outside atom
                    for d in cmodel.bond[a2]:
                        a3 = d.index[0] 
                        if a3 not in (a0,a1,a2): # outside atom
                            if a0 < a3:
                                to = (a0,a1,a2,a3)
                            else:
                                to = (a3,a2,a1,a0)                        
                            tors[to] = 1
                        a3 = d.index[1] 
                        if a3 not in (a0,a1,a2): # outside atom
                            if a0 < a3:
                                to = (a0,a1,a2,a3)
                            else:
                                to = (a3,a2,a1,a0)
                            tors[to] = 1
                a0 = c.index[1] 
                if a0 not in (a1,a2): # outside atom
                    for d in cmodel.bond[a2]:
                        a3 = d.index[0] 
                        if a3 not in (a0,a1,a2): # outside atom
                            if a0 < a3:
                                to = (a0,a1,a2,a3)
                            else:
                                to = (a3,a2,a1,a0)                        
                            tors[to] = 1
                        a3 = d.index[1] 
                        if a3 not in (a0,a1,a2): # outside atom
                            if a0 < a3:
                                to = (a0,a1,a2,a3)
                            else:
                                to = (a3,a2,a1,a0)                        
                            tors[to] = 1
        # find impropers (only autogenerates for atoms with 3 bonds)
        self.improper = {}
        impr = self.improper
        a2 = 0
        for a in model.atom: # a2 is the center atom 
            bnd = cmodel.bond[a2]
            if len(bnd) == 3:
                lst = []
                for b in bnd:
                    at = b.index[0]
                    if at == a2:
                        at = b.index[1]
                    lst.append(at)
                lst.sort()
                impr[(lst[0],lst[1],a2,lst[2])] = 1
            a2 = a2 + 1
            
        if feedback['actions']:
            print(' '+str(self.__class__)+': found:')
            print(' '+str(self.__class__)+':    types       %6d' % (
                len(list(self.present.keys()))))
            print(' '+str(self.__class__)+':    bonds       %6d' % (
                len(list(self.bond.keys()))))
            print(' '+str(self.__class__)+':    angles      %6d' % (
                len(list(self.angle.keys()))))
            print(' '+str(self.__class__)+':    torsions    %6d' % (
                len(list(self.torsion.keys()))))
            print(' '+str(self.__class__)+':    impropers   %6d' % (
                len(list(self.improper.keys()))))

    def dump(self):
        kees = list(self.present.keys())
        kees.sort()
        for b in kees:
            print(b)
        kees = list(self.bond.keys())
        kees.sort()
        for b in kees:
            print(b)
        kees = list(self.angle.keys())
        kees.sort()
        for b in kees:
            print(b)
        kees = list(self.torsion.keys())
        kees.sort()
        for b in kees:
            print(b)
        kees = list(self.improper.keys())
        kees.sort()
        for b in kees:
            print(b)

    def get_list(self):
        return [list(self.bond.keys()),
                  list(self.angle.keys()),
                  list(self.torsion.keys()),
                  list(self.improper.keys())]

class Subset:
    
    def __init__(self,par,top):
        if feedback['actions']:
            print(' '+str(self.__class__)+': applying parameter set to topology...')
        self.model = top.model
        self.present = copy.deepcopy(top.present)
        atype = []
        for a in self.model.atom:
            atype.append(a.text_type)
        # extra tinker info (atomic number, valency)
        self.miss_extra = []
        self.extra = {}
        s_extra = self.extra
        present = top.present
        p_extra = par.extra
        for kee in present.keys():
            if kee in p_extra:
                s_extra[kee] = p_extra[kee]
            else:
                self.miss_extra.append(kee)
        # molecular weight
        self.miss_mw = []
        self.mw = {}
        s_mw = self.mw
        present = top.present
        p_mw = par.mw
        for kee in present.keys():
            if kee in p_mw:
                s_mw[kee] = p_mw[kee]
            else:
                self.miss_mw.append(kee)
                
        # van der waals
        self.miss_vdw = []
        self.vdw = {}
        s_vdw = self.vdw
        present = top.present
        p_vdw = par.vdw
        for kee in present.keys():
            if kee in p_vdw:
                s_vdw[kee] = p_vdw[kee]
            else:
                self.miss_vdw.append(kee)
        # bonds
        self.miss_bond = []
        self.bond = {}
        s_bond = self.bond
        bond = top.bond
        p_bond = par.bond
        for a in list(bond.keys()):
            kee = "%-2s-%-2s" % (atype[a[0]],atype[a[1]])
            if kee in p_bond:
                s_bond[kee] = p_bond[kee]
            else:
                self.miss_bond.append((a,kee))
        # angles
        self.miss_angle = []
        self.angle = {}
        s_angle = self.angle
        angle = top.angle
        p_angle = par.angle
        for a in angle.keys():
            kee = "%-2s-%-2s-%-2s" % (atype[a[0]],atype[a[1]],atype[a[2]])
            if kee in p_angle:
                s_angle[kee] = p_angle[kee]
            else:
                self.miss_angle.append((a,kee))
        # torsions      
        self.miss_torsion = []
        self.torsion = {}
        s_torsion = self.torsion
        torsion = top.torsion
        p_torsion = par.torsion
        for a in list(torsion.keys()):
            at0=atype[a[0]]
            at1=atype[a[1]]
            at2=atype[a[2]] # center atom
            at3=atype[a[3]]
            while 1: # not a real loop, just "else" avoidance
                kee1 = "%-2s-%-2s-%-2s-%-2s" % (at0,at1,at2,at3)
                if kee1 in p_torsion:
                    s_torsion[kee1] = p_torsion[kee1]
                    break
                kee2 = "%-2s-%-2s-%-2s-%-2s" % (at3,at2,at1,at0)
                if kee2 in p_torsion:
                    s_torsion[kee2] = p_torsion[kee2]
                    break
                kee = "X -%-2s-%-2s-X " % (at1,at2)
                if kee in p_torsion:
                    s_torsion[kee1] = p_torsion[kee]
                    break
                kee = "X -%-2s-%-2s-X " % (at2,at1)
                if kee in p_torsion: 
                    s_torsion[kee2] = p_torsion[kee]
                    break
                self.miss_torsion.append((a,kee1))
                break
        # impropers      
        self.miss_improper = []
        self.improper = {}
        s_improper = self.improper
        improper = top.improper
        p_improper = par.improper
        for a in improper.keys():
            at0=atype[a[0]]
            at1=atype[a[1]]
            at2=atype[a[2]] # center atom
            at3=atype[a[3]]
            while 1: # not a real loop, just "else" avoidance

                kee1 = "%-2s-%-2s-%-2s-%-2s" % (at1,at3,at2,at0)
                if kee1 in p_improper:
                    s_improper[kee1] = p_improper[kee1]
                    break
                kee2 = "%-2s-%-2s-%-2s-%-2s" % (at3,at1,at2,at0)
                if kee2 in p_improper:
                    s_improper[kee2] = p_improper[kee2]
                    break

                kee3 = "%-2s-%-2s-%-2s-%-2s" % (at0,at3,at2,at1)
                if kee3 in p_improper:
                    s_improper[kee3] = p_improper[kee3]
                    break
                kee4 = "%-2s-%-2s-%-2s-%-2s" % (at3,at0,at2,at1)
                if kee4 in p_improper:
                    s_improper[kee4] = p_improper[kee4]
                    break

                kee5 = "%-2s-%-2s-%-2s-%-2s" % (at0,at1,at2,at3)
                if kee5 in p_improper:
                    s_improper[kee5] = p_improper[kee5]
                    break
                kee6 = "%-2s-%-2s-%-2s-%-2s" % (at1,at0,at2,at3)
                if kee6 in p_improper:
                    s_improper[kee6] = p_improper[kee6]
                    break

                kee = "X -%-2s-%-2s-%-2s" % (at3,at2,at0)
                if kee in p_improper:
                    s_improper[kee1] = p_improper[kee]
                    break
                kee = "X -%-2s-%-2s-%-2s" % (at1,at2,at0)
                if kee in p_improper:
                    s_improper[kee2] = p_improper[kee]
                    break
                kee = "X -%-2s-%-2s-%-2s" % (at3,at2,at1)
                if kee in p_improper:
                    s_improper[kee3] = p_improper[kee]
                    break
                kee = "X -%-2s-%-2s-%-2s" % (at0,at2,at1)
                if kee in p_improper:
                    s_improper[kee4] = p_improper[kee]
                    break
                kee = "X -%-2s-%-2s-%-2s" % (at1,at2,at3)
                if kee in p_improper:
                    s_improper[kee5] = p_improper[kee]
                    break
                kee = "X -%-2s-%-2s-%-2s" % (at0,at2,at3)
                if kee in p_improper:
                    s_improper[kee6] = p_improper[kee]
                    break

                kee = "X -X -%-2s-%-2s" % (at2,at0)
                if kee in p_improper:
                    s_improper[kee1] = p_improper[kee]
                    break
                kee = "X -X -%-2s-%-2s" % (at2,at1)
                if kee in p_improper:
                    s_improper[kee3] = p_improper[kee]
                    break
                kee = "X -X -%-2s-%-2s" % (at2,at3)
                if kee in p_improper:
                    s_improper[kee5] = p_improper[kee]
                    break
                self.miss_improper.append((a,kee1))
                break

        if feedback['actions']:
            print(' '+str(self.__class__)+': missing:')
            print(' '+str(self.__class__)+':    mol. wts.         %6d' % (
                len(self.miss_mw)))
            print(' '+str(self.__class__)+':    vdw               %6d' % (
                len(self.miss_vdw)))
            print(' '+str(self.__class__)+':    bonds             %6d' % (
                len(self.miss_bond)))
            print(' '+str(self.__class__)+':    angles            %6d' % (
                len(self.miss_angle)))
            print(' '+str(self.__class__)+':    torsions          %6d' % (
                len(self.miss_torsion)))
            print(' '+str(self.__class__)+':    impropers         %6d (usually okay)' % (
                len(self.miss_improper)))
            print(' '+str(self.__class__)+':    extra tinker info %6d' % (
                len(self.miss_extra)))
        
    def dump(self):
        kees = list(self.mw.keys())
        kees.sort()
        for b in kees:
            print(b,self.mw[b])
        kees = list(self.bond.keys())
        kees.sort()
        for b in kees:
            print(b,self.bond[b])
        kees = list(self.angle.keys())
        kees.sort()
        for b in kees:
            print(b,self.angle[b])
        kees = list(self.torsion.keys())
        kees.sort()
        for b in kees:
            print(b,self.torsion[b])
        kees = list(self.improper.keys())
        kees.sort()
        for b in kees:
            print(b,self.improper[b])
        kees = list(self.vdw.keys())
        kees.sort()
        for b in kees:
            print(b,self.vdw[b])

    def dump_missing(self,impropers=0):
        if len(self.miss_mw):
            print(' '+str(self.__class__)+': missing molecular weights...')
        for b in self.miss_mw:
            print(" ",b)
        if len(self.miss_vdw):
            print(' '+str(self.__class__)+': missing van der Waalss...')
        for b in self.miss_vdw:
            print(" ",b)
        if len(self.miss_bond):
            print(' '+str(self.__class__)+': missing bonds...')
        for b in self.miss_bond:
            print(" ",b)
        if len(self.miss_angle):
            print(' '+str(self.__class__)+': missing angless...')
        for b in self.miss_angle:
            print(" ",b)
        if len(self.miss_torsion):
            print(' '+str(self.__class__)+': missing torsions...')
        for b in self.miss_torsion:
            print(" ",b)
        if impropers:
            if len(self.miss_improper):
                print(' '+str(self.__class__)+': missing impropers...')
            for b in self.miss_improper:
                print(" ",b)

    def complete(self):
        if not ( len(self.miss_mw) or
                    len(self.miss_vdw) or
                    len(self.miss_bond) or
                    len(self.miss_angle) or
                    len(self.miss_torsion) ):
            return 1
        else:
            return 0

    def assign_types(self):
        c = 0
        self.mapping = {}
        map = self.mapping
        kees = list(self.present.keys())
        label = []
        type = []
        kees.sort()
        for a in kees:
            c = c + 1
            st = str(c)
            label.append(st)
            type.append(a)
            map[a] = st
        # assign numeric types 
        for a in self.model.atom:
            a.numeric_type = map[a.text_type]
        
    def write_tinker_prm(self,fname,proofread=None,smooth=None):
        c = 0
        self.mapping = {}
        map = self.mapping
        kees = list(self.present.keys())
        label = []
        type = []
        kees.sort()
        if proofread:
            for a in kees:
                label.append(a)
                type.append(a)
                map[a] = a
        else:
            for a in kees:
                c = c + 1
                st = str(c)
                label.append(st)
                type.append(a)
                map[a] = st
        # assign numeric types as per the parameter we're writing
        for a in self.model.atom:
            a.numeric_type = map[a.text_type]
        f = open(fname,'w')
        if smooth:
            f.write('''
forcefield              SMOOTH AMBER
vdwtype                 GAUSSIAN
gausstype               LJ-2
''')
        else:
            f.write('''
forcefield              AMBER95
vdwtype                 LENNARD-JONES
''')
        f.write('''
radiusrule              ARITHMETIC
radiustype              R-MIN
radiussize              RADIUS
epsilonrule             GEOMETRIC
vdw-14-use
vdw-scale               2.0
chg-14-use
chg-scale               1.2
dielectric              1.0
''')

        # types
        for c in range(len(self.present)):
            at = type[c]
            f.write("atom %6s %6s    %-2s      %-25s %3d %10.3f%6d\n" % (
                label[c],label[c],at,'"'+self.mw[at][1][0:23]+'"',
                self.extra[at][0],
                self.mw[at][0],self.extra[at][1]))
        # van der waals
        for c in range(len(self.present)):
            at = type[c]
            f.write("vdw   %8s          %10.4f %10.4f\n" % (
                map[at],self.vdw[at][0],self.vdw[at][1]))
        # bonds
        bond = {}
        for a in list(self.bond.keys()):
            kee = (map[string.strip(a[0:2])],map[string.strip(a[3:5])])
            bond[kee] = a
        kees = list(bond.keys())
        kees.sort()
        for a in kees:
            kee = bond[a]
            f.write("bond    %6s%5s     %10.1f %10.4f\n" % (
                a[0],a[1],self.bond[kee][0],self.bond[kee][1]))
        # angles
        angle = {}
        for a in list(self.angle.keys()):
            kee = (map[string.strip(a[0:2])],
                     map[string.strip(a[3:5])],
                     map[string.strip(a[6:8])],                
                     )
            angle[kee] = a
        kees = list(angle.keys())
        kees.sort()
        for a in kees:
            kee = angle[a]
            f.write("angle    %5s%5s%5s%9.2f    %8.2f\n" % (
                a[0],a[1],a[2],self.angle[kee][0],self.angle[kee][1]))
        # impropers
        if not smooth:
            improper = {}
            for a in self.improper.keys():
                kee = (map[string.strip(a[0:2])],
                         map[string.strip(a[3:5])],
                         map[string.strip(a[6:8])],
                         map[string.strip(a[9:11])],                                
                         )
                improper[kee] = a
            kees = list(improper.keys())
            kees.sort()
            for a in kees:
                kee = improper[a]
                f.write("imptors  %5s%5s%5s%5s     %10.3f%7.1f%3d\n" % (
                    a[0],a[1],a[2],a[3],self.improper[kee][0],
                    self.improper[kee][1],self.improper[kee][2]))
        else:
            improper = {}
            for a in self.improper.keys():
                kee = (map[string.strip(a[0:2])],
                         map[string.strip(a[3:5])],
                         map[string.strip(a[6:8])],
                         map[string.strip(a[9:11])],                                
                         )
                improper[kee] = a
            kees = list(improper.keys())
            kees.sort()
            for a in kees:
                kee = improper[a]
                f.write("improper %5s%5s%5s%5s      %10.2f       0.00\n" % (
                    a[2],a[0],a[1],a[3],self.improper[kee][0]*3.5))
        # torsions
        torsion = {}
        for a in self.torsion.keys():
            kee = (map[string.strip(a[0:2])],
                     map[string.strip(a[3:5])],
                     map[string.strip(a[6:8])],
                     map[string.strip(a[9:11])],                                
                     )
            torsion[kee] = a
        kees = list(torsion.keys())
        kees.sort()
        for a in kees:
            kee = torsion[a]
            st = "torsion  %5s%5s%5s%5s     " % (
                a[0],a[1],a[2],a[3])
            lst = self.torsion[kee]
            div = lst[0]
            lst = lst[1:]
            while len(lst):
                st = st + "%10.3f%7.1f%3d  " % (
                    lst[0]/div,lst[1],lst[2])
                lst = lst[5:]
            while len(st)>79:
                st = string.replace(st,'  ',' ')
            f.write(st+"\n")
        # null charge records
        for c in range(len(self.present)):
            a = label[c]
            f.write("charge  %6s    %10.4f\n" % (a,0.0))
        f.close()


    def get_list(self):
        list = []
        c = 0
        self.mapping = {}
        map = self.mapping
        kees = list(self.present.keys())
        label = []
        type = []
        kees.sort()
        for a in kees:
            c = c + 1
            st = str(c)
            type.append(a)
            map[a] = c
        # assign numeric types as per the parameter we're writing
        for a in self.model.atom:
            a.numeric_type = map[a.text_type]
        # types
        typ_list = []
        for c in range(len(self.present)):
            at = type[c]
            typ_list.append((map[at],self.extra[at][0],self.mw[at][0],self.extra[at][1]))
        list.append(typ_list)
        # van der waals
        vdw_list = []
        for c in range(len(self.present)):
            at = type[c]
            vdw_list.append((map[at],self.vdw[at][0],self.vdw[at][1]))
        list.append(vdw_list)
        # bonds
        bnd_list = []
        bond = {}
        for a in list(self.bond.keys()):
            kee = (map[string.strip(a[0:2])],map[string.strip(a[3:5])])
            bond[kee] = a
        kees = list(bond.keys())
        kees.sort()
        for a in kees:
            kee = bond[a]
            bnd_list.append((a[0],a[1],self.bond[kee][0],self.bond[kee][1]))
        list.append(bnd_list)
        # angles
        ang_list = []
        angle = {}
        for a in self.angle.keys():
            kee = (map[string.strip(a[0:2])],
                     map[string.strip(a[3:5])],
                     map[string.strip(a[6:8])],                
                     )
            angle[kee] = a
        kees = list(angle.keys())
        kees.sort()
        for a in kees:
            kee = angle[a]
            ang_list.append((a[0],a[1],a[2],self.angle[kee][0],self.angle[kee][1]))
        list.append(ang_list)
        # impropers
        imp_list = []
        improper = {}
        for a in self.improper.keys():
            kee = (map[string.strip(a[0:2])],
                     map[string.strip(a[3:5])],
                     map[string.strip(a[6:8])],
                     map[string.strip(a[9:11])],                                
                     )
            improper[kee] = a
        kees = list(improper.keys())
        kees.sort()
        for a in kees:
            kee = improper[a]
            imp_list.append((a[0],a[1],a[2],a[3],self.improper[kee][0],
                self.improper[kee][1],self.improper[kee][2]))
        list.append(imp_list)
        # torsions
        tor_list = []
        torsion = {}
        for a in self.torsion.keys():
            kee = (map[string.strip(a[0:2])],
                     map[string.strip(a[3:5])],
                     map[string.strip(a[6:8])],
                     map[string.strip(a[9:11])],                                
                     )
            torsion[kee] = a
        kees = list(torsion.keys())
        kees.sort()
        for a in kees:
            kee = torsion[a]
            tor = [ a[0],a[1],a[2],a[3] ]
            lst = self.torsion[kee]
            div = lst[0]
            lst = lst[1:]
            while len(lst):
                tor.extend([lst[0]/div,lst[1],lst[2]])
                lst = lst[5:]
            tor_list.append(tor)
        list.append(tor_list)
        return list