forked from Tarcyrian/AKEngelsPraktikum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lisa_Charges_test.py
1352 lines (1112 loc) · 47.5 KB
/
Lisa_Charges_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import subprocess
import copy
import numpy as np
import math as m
'''Klasse Atom_xyz:
Beinhaltet die eingelesenen Symbole
und Koordinaten in einer Liste'''
class atom_xyz(object):
def __init__(self, symbol, coords):
self.symbol = symbol
self.coords = coords
'''Klasse charge_xyz:
Beinhaltet die Koordinaten und die
dazugehörgen Ladungen'''
class charge_xyz(object):
def __init__(self, coords, charge):
self.coords = coords
self.charge = charge
'''Funktion readXYZ:
Liest die angegebene Datei ein und speichert
sowohl die Symbole als auch die Koordinaten seperat ab
und fügt sie anschließend an eine Liste ret an.'''
def readXYZ(name):
ret = []
f = open(name, "r")
for line in f:
tmp = line.split()
if len(tmp) == 4:
sym = tmp[0]
coords = list(map(float, tmp[1:]))
ret.append(atom_xyz(sym, coords))
f.close()
return ret
'''Funktion readcharges:
List die angegebene Datei ein und speichert
sowohl die Koordinaten als auch die Ladungen seperat ab
und fügt sie anschließend an eine Liste charges an.'''
def readcharges(file):
charges = []
f = open(file, "r")
for line in f:
tmp = line.split()
if len(tmp) == 4:
coord = list(map(float, tmp[0:3]))
charge = float(tmp[3])
charges.append(charge_xyz(coord, charge))
f.close()
return charges
'''Funktion moveToCenterofGeo:
Berechnet Center of Geometry und gibt die
veränderten Koordinaten zurück.'''
def moveToCenterofGeo(ret):
centerOfGeo = [0.0, 0.0, 0.0]
for i in range(len(ret)):
j = 0
while j < 3:
centerOfGeo[j] += ret[i].coords[j]
j += 1
k = 0
while k < 3:
centerOfGeo[k] /= len(ret)
k += 1
negativeCenterOfGeo = copy.deepcopy(centerOfGeo)
l = 0
while l < 3:
negativeCenterOfGeo[l] *= -1.0
l += 1
for i in range(len(ret)):
m = 0
while m < 3:
ret[i].coords[m] += negativeCenterOfGeo[m]
m += 1
return ret
'''Funktion duplicateDIP:
Dupliziert ret und verschiebt x oder y um einen konstanten Wert.
Hängt die veränderten Koordinaten an die ursprüngliche Datei an
und gibt sie zurück.'''
def duplicateDIP(ret, verschiebung, x, y):
ret2 = copy.deepcopy(ret)
for i in range(len(ret)):
if verschiebung == "xp":
ret2[i].coords[0] += x
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
elif verschiebung == "xn":
ret2[i].coords[0] -= x
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
elif verschiebung == "yp":
ret2[i].coords[1] += y
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
elif verschiebung == "yn":
ret2[i].coords[1] -= y
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
return ret
'''Funktion duplicatePDIR:
Dupliziert ret und verschiebt x oder y um einen konstanten Wert.
Hängt die veränderten Koordinaten an die ursprüngliche Datei an
und gibt sie zurück.'''
def duplicatePDIR(ret, x, difb, difc, verschiebung):
ret2 = copy.deepcopy(ret)
for i in range(len(ret)):
if verschiebung == "ap":
ret2[i].coords[0] += x
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
elif verschiebung == "an":
ret2[i].coords[0] -= x
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
elif verschiebung == "bp":
ret2[i].coords[0] += difb[0]
ret2[i].coords[1] += difb[1]
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
elif verschiebung == "bn":
ret2[i].coords[0] -= difb[0]
ret2[i].coords[1] -= difb[1]
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
elif verschiebung == "cp":
ret2[i].coords[0] += difc[0]
ret2[i].coords[1] += difc[1]
ret2[i].coords[2] += difc[2]
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
elif verschiebung == "cn":
ret2[i].coords[0] -= difc[0]
ret2[i].coords[1] -= difc[1]
ret2[i].coords[2] -= difc[2]
ret.append(atom_xyz(ret2[i].symbol, ret2[i].coords))
return ret
'''Bildet die Ladungen um DIP1 und speichert sie in einer Liste.'''
countChargesDIP1 = 0
def getchargesDIP1(charge, a, b, c, numberLayers):
global countChargesDIP1
newcharge =[]
# First layer DIP1
if numberLayers >= 1:
countChargesDIP1 += 1
charge1 = copy.deepcopy(charge)
for i in range(len(charge)):
charge1[i].coords[0] += a
newcharge.append(charge_xyz(charge1[i].coords, charge1[i].charge))
countChargesDIP1 += 1
charge2 = copy.deepcopy(charge)
for i in range(len(charge)):
charge2[i].coords[0] -= a
newcharge.append(charge_xyz(charge2[i].coords, charge2[i].charge))
countChargesDIP1 += 1
charge3 = copy.deepcopy(charge)
for i in range(len(charge)):
charge3[i].coords[0] += 2*a
newcharge.append(charge_xyz(charge3[i].coords, charge3[i].charge))
countChargesDIP1 += 1
charge4 = copy.deepcopy(charge)
for i in range(len(charge)):
charge4[i].coords[0] -= 2*a
newcharge.append(charge_xyz(charge4[i].coords, charge4[i].charge))
# Begin row DIP1 +b
countChargesDIP1 += 1
charge5 = copy.deepcopy(charge)
for i in range(len(charge)):
charge5[i].coords[1] += b
newcharge.append(charge_xyz(charge5[i].coords, charge5[i].charge))
countChargesDIP1 += 1
charge6 = copy.deepcopy(charge)
for i in range(len(charge)):
charge6[i].coords[0] += a
charge6[i].coords[1] += b
newcharge.append(charge_xyz(charge6[i].coords, charge6[i].charge))
countChargesDIP1 += 1
charge7 = copy.deepcopy(charge)
for i in range(len(charge)):
charge7[i].coords[0] -= a
charge7[i].coords[1] += b
newcharge.append(charge_xyz(charge7[i].coords, charge7[i].charge))
countChargesDIP1 += 1
charge8 = copy.deepcopy(charge)
for i in range(len(charge)):
charge8[i].coords[0] += 2*a
charge8[i].coords[1] += b
newcharge.append(charge_xyz(charge8[i].coords, charge8[i].charge))
countChargesDIP1 += 1
charge9 = copy.deepcopy(charge)
for i in range(len(charge)):
charge9[i].coords[0] -= 2*a
charge9[i].coords[1] += b
newcharge.append(charge_xyz(charge9[i].coords, charge9[i].charge))
# Begin row DIP1 -b
countChargesDIP1 += 1
charge10 = copy.deepcopy(charge)
for i in range(len(charge)):
charge10[i].coords[1] -= b
newcharge.append(charge_xyz(charge10[i].coords, charge10[i].charge))
countChargesDIP1 += 1
charge11 = copy.deepcopy(charge)
for i in range(len(charge)):
charge11[i].coords[0] += a
charge11[i].coords[1] -= b
newcharge.append(charge_xyz(charge11[i].coords, charge11[i].charge))
countChargesDIP1 += 1
charge12 = copy.deepcopy(charge)
for i in range(len(charge)):
charge12[i].coords[0] -= a
charge12[i].coords[1] -= b
newcharge.append(charge_xyz(charge12[i].coords, charge12[i].charge))
countChargesDIP1 += 1
charge13 = copy.deepcopy(charge)
for i in range(len(charge)):
charge13[i].coords[0] += 2*a
charge13[i].coords[1] -= b
newcharge.append(charge_xyz(charge13[i].coords, charge13[i].charge))
countChargesDIP1 += 1
charge14 = copy.deepcopy(charge)
for i in range(len(charge)):
charge14[i].coords[0] -= 2*a
charge14[i].coords[1] -= b
newcharge.append(charge_xyz(charge14[i].coords, charge14[i].charge))
# Second layer DIP1 failed attempt
# if numberLayers >= 2:
# for i in range(5):
# for j in range(3):
# countChargesDIP1 += 1
# chargeSecondLayer = copy.deepcopy(charge)
# for k in range(len(charge)):
# chargeSecondLayer[k].coords[0] += -2*a + i*a
# chargeSecondLayer[k].coords[1] += -b + j*b
# chargeSecondLayer[k].coords[2] += c
# newcharge.append(charge_xyz(chargeSecondLayer[k].coords, chargeSecondLayer[k].charge))
return newcharge
'''Bildet die Ladungen um DIP2 und speichert sie in einer Liste.'''
countChargesDIP2 = 0
def getchargesDIP2(charge, a, b, c, numberLayers):
global countChargesDIP2
chargegeaendert = []
countChargesDIP2 += 1
for i in range(len(charge)):
chargegeaendert.append(charge_xyz(charge[i].coords, charge[i].charge))
countChargesDIP2 +=1
charge1 = copy.deepcopy(charge)
for i in range(len(charge1)):
charge1[i].coords[0] -= 2 * a
chargegeaendert.append(charge_xyz(charge1[i].coords, charge1[i].charge))
countChargesDIP2 +=1
charge2 = copy.deepcopy(charge)
for i in range(len(charge2)):
charge2[i].coords[0] -= a
chargegeaendert.append(charge_xyz(charge2[i].coords, charge2[i].charge))
countChargesDIP2 +=1
charge3 = copy.deepcopy(charge)
for i in range(len(charge3)):
charge3[i].coords[1] += b
chargegeaendert.append(charge_xyz(charge3[i].coords, charge3[i].charge))
countChargesDIP2 +=1
charge4 = copy.deepcopy(charge)
for i in range(len(charge4)):
charge4[i].coords[0] += a
charge4[i].coords[1] += b
chargegeaendert.append(charge_xyz(charge4[i].coords, charge4[i].charge))
countChargesDIP2 +=1
charge5 = copy.deepcopy(charge)
for i in range(len(charge5)):
charge5[i].coords[1] += b
charge5[i].coords[0] -= 2 * a
chargegeaendert.append(charge_xyz(charge5[i].coords, charge5[i].charge))
countChargesDIP2 +=1
charge6 = copy.deepcopy(charge)
for i in range(len(charge6)):
charge6[i].coords[1] += b
charge6[i].coords[0] -= a
chargegeaendert.append(charge_xyz(charge6[i].coords, charge6[i].charge))
countChargesDIP2 +=1
charge7 = copy.deepcopy(charge)
for i in range(len(charge7)):
charge7[i].coords[0] += a
chargegeaendert.append(charge_xyz(charge7[i].coords, charge7[i].charge))
# Row DIP2 +2b
countChargesDIP2 +=1
charge8 = copy.deepcopy(charge)
for i in range(len(charge8)):
charge8[i].coords[1] += 2*b
chargegeaendert.append(charge_xyz(charge8[i].coords, charge8[i].charge))
countChargesDIP2 +=1
charge9 = copy.deepcopy(charge)
for i in range(len(charge9)):
charge9[i].coords[0] += a
charge9[i].coords[1] += 2*b
chargegeaendert.append(charge_xyz(charge9[i].coords, charge9[i].charge))
countChargesDIP2 +=1
charge10 = copy.deepcopy(charge)
for i in range(len(charge10)):
charge10[i].coords[1] += 2*b
charge10[i].coords[0] -= 2 * a
chargegeaendert.append(charge_xyz(charge10[i].coords, charge10[i].charge))
countChargesDIP2 +=1
charge11 = copy.deepcopy(charge)
for i in range(len(charge11)):
charge11[i].coords[1] += 2*b
charge11[i].coords[0] -= a
chargegeaendert.append(charge_xyz(charge11[i].coords, charge11[i].charge))
# Row DIP2 -b
countChargesDIP2 +=1
charge12 = copy.deepcopy(charge)
for i in range(len(charge12)):
charge12[i].coords[1] -= b
chargegeaendert.append(charge_xyz(charge12[i].coords, charge12[i].charge))
countChargesDIP2 +=1
charge13 = copy.deepcopy(charge)
for i in range(len(charge13)):
charge13[i].coords[0] += a
charge13[i].coords[1] -= b
chargegeaendert.append(charge_xyz(charge13[i].coords, charge13[i].charge))
countChargesDIP2 +=1
charge14 = copy.deepcopy(charge)
for i in range(len(charge14)):
charge14[i].coords[1] -= b
charge14[i].coords[0] -= 2 * a
chargegeaendert.append(charge_xyz(charge14[i].coords, charge14[i].charge))
countChargesDIP2 +=1
charge15 = copy.deepcopy(charge)
for i in range(len(charge15)):
charge15[i].coords[1] -= b
charge15[i].coords[0] -= a
chargegeaendert.append(charge_xyz(charge15[i].coords, charge15[i].charge))
# Second layer DIP2 failed attempt
# if numberLayers >= 2:
# for i in range(4):
# for j in range(4):
# countChargesDIP2 +=1
# chargeSecondLayer = copy.deepcopy(charge)
# for k in range(len(charge)):
# chargeSecondLayer[k].coords[0] += -2*a + i*a
# chargeSecondLayer[k].coords[1] += -b + j*b
# chargeSecondLayer[k].coords[2] += c
# chargegeaendert.append(charge_xyz(chargeSecondLayer[k].coords, chargeSecondLayer[k].charge))
return chargegeaendert
'''Bildet die Ladungen um PDIR und speichert sie in einer Liste.
Die Ladungen werden anhand der Rotationsaxe ausgewählt.'''
countChargesPDIR=0
def getchargesPDIR(charge, difb, a, difc, rotAxis, numberLayers):
newcharge = []
global countChargesPDIR
difbplusa = difb[0] + a
difbminusa = difb[0] - a
minusdifbminusa = - difb[0] - a
minusdifbplusa = - difb[0] + a
# if numberLayers >= 1:
# #+a
# if rotAxis=="a" or rotAxis=="0":
# countChargesPDIR +=1
# charge1 = copy.deepcopy(charge)
# for i in range(len(charge1)):
# charge1[i].coords[0] += a
# newcharge.append(charge_xyz(charge1[i].coords, charge1[i].charge))
# #-a
# if rotAxis=="a" or rotAxis=="b" or rotAxis=="0":
# countChargesPDIR +=1
# charge2 = copy.deepcopy(charge)
# for i in range(len(charge2)):
# charge2[i].coords[0] -= a
# newcharge.append(charge_xyz(charge2[i].coords, charge2[i].charge))
# #+b
# if rotAxis=="b" or rotAxis=="0":
# countChargesPDIR +=1
# charge3 = copy.deepcopy(charge)
# for i in range(len(charge3)):
# charge3[i].coords[0] += difb[0]
# charge3[i].coords[1] += difb[1]
# newcharge.append(charge_xyz(charge3[i].coords, charge3[i].charge))
# #+b+a
# if rotAxis=="0":
# countChargesPDIR +=1
# charge4 = copy.deepcopy(charge)
# for i in range(len(charge4)):
# charge4[i].coords[0] += difbplusa
# charge4[i].coords[1] += difb[1]
# newcharge.append(charge_xyz(charge4[i].coords, charge4[i].charge))
# #+b-a
# if rotAxis=="b" or rotAxis=="0":
# countChargesPDIR +=1
# charge5 = copy.deepcopy(charge)
# for i in range(len(charge5)):
# charge5[i].coords[0] += difbminusa
# charge5[i].coords[1] += difb[1]
# newcharge.append(charge_xyz(charge5[i].coords, charge5[i].charge))
# #-b
# if rotAxis=="a" or rotAxis=="b" or rotAxis=="0":
# countChargesPDIR +=1
# charge6 = copy.deepcopy(charge)
# for i in range(len(charge6)):
# charge6[i].coords[0] -= difb[0]
# charge6[i].coords[1] -= difb[1]
# newcharge.append(charge_xyz(charge6[i].coords, charge6[i].charge))
# #-b-a
# if rotAxis=="a" or rotAxis=="b" or rotAxis=="0":
# countChargesPDIR +=1
# charge7 = copy.deepcopy(charge)
# for i in range(len(charge7)):
# charge7[i].coords[0] += minusdifbminusa
# charge7[i].coords[1] -= difb[1]
# newcharge.append(charge_xyz(charge7[i].coords, charge7[i].charge))
# #-b+a
# if rotAxis=="a" or rotAxis=="0":
# countChargesPDIR +=1
# charge8 = copy.deepcopy(charge)
# for i in range(len(charge8)):
# charge8[i].coords[0] += minusdifbplusa
# charge8[i].coords[1] -= difb[1]
# newcharge.append(charge_xyz(charge8[i].coords, charge8[i].charge))
# #Begin second shell
# #+2a
# if rotAxis=="a" or rotAxis=="0":
# countChargesPDIR +=1
# charge9 = copy.deepcopy(charge)
# for i in range(len(charge9)):
# charge9[i].coords[0] += 2*a
# newcharge.append(charge_xyz(charge9[i].coords, charge9[i].charge))
# #-2a
# if rotAxis=="a" or rotAxis=="0" or rotAxis=="b":
# countChargesPDIR +=1
# charge10 = copy.deepcopy(charge)
# for i in range(len(charge10)):
# charge10[i].coords[0] -= 2*a
# newcharge.append(charge_xyz(charge10[i].coords, charge10[i].charge))
# #-2a+b
# if rotAxis=="0" or rotAxis=="b":
# countChargesPDIR +=1
# charge11 = copy.deepcopy(charge)
# for i in range(len(charge11)):
# charge11[i].coords[0] += -2*a + difb[0]
# charge11[i].coords[1] += difb[1]
# newcharge.append(charge_xyz(charge11[i].coords, charge11[i].charge))
# #-2a+2b
# if rotAxis=="0" or rotAxis=="b":
# countChargesPDIR +=1
# charge12 = copy.deepcopy(charge)
# for i in range(len(charge12)):
# charge12[i].coords[0] += -2*a + 2*difb[0]
# charge12[i].coords[1] += 2*difb[1]
# newcharge.append(charge_xyz(charge12[i].coords, charge12[i].charge))
# #-a+2b
# if rotAxis=="b" or rotAxis=="0":
# countChargesPDIR +=1
# charge13 = copy.deepcopy(charge)
# for i in range(len(charge13)):
# charge13[i].coords[0] += -a + 2*difb[0]
# charge13[i].coords[1] += 2*difb[1]
# newcharge.append(charge_xyz(charge13[i].coords, charge13[i].charge))
# #+a+2b
# if rotAxis=="0":
# countChargesPDIR +=1
# charge14 = copy.deepcopy(charge)
# for i in range(len(charge14)):
# charge14[i].coords[0] += a + 2*difb[0]
# charge14[i].coords[1] += 2*difb[1]
# newcharge.append(charge_xyz(charge14[i].coords, charge14[i].charge))
# #+2a+2b
# if rotAxis=="0":
# countChargesPDIR +=1
# charge15 = copy.deepcopy(charge)
# for i in range(len(charge15)):
# charge15[i].coords[0] += 2*(a + difb[0])
# charge15[i].coords[1] += 2*difb[1]
# newcharge.append(charge_xyz(charge15[i].coords, charge15[i].charge))
# #+2a+b
# if rotAxis=="0":
# countChargesPDIR +=1
# charge16 = copy.deepcopy(charge)
# for i in range(len(charge16)):
# charge16[i].coords[0] += 2*a + difb[0]
# charge16[i].coords[1] += difb[1]
# newcharge.append(charge_xyz(charge16[i].coords, charge16[i].charge))
# #+2b
# if rotAxis=="b" or rotAxis=="0":
# countChargesPDIR +=1
# charge17 = copy.deepcopy(charge)
# for i in range(len(charge17)):
# charge17[i].coords[0] += 2*difb[0]
# charge17[i].coords[1] += 2*difb[1]
# newcharge.append(charge_xyz(charge17[i].coords, charge17[i].charge))
# #gap of one because of duplicate charge
# #-2a-b
# if rotAxis=="a" or rotAxis=="0" or rotAxis=="b":
# countChargesPDIR +=1
# charge19 = copy.deepcopy(charge)
# for i in range(len(charge19)):
# charge19[i].coords[0] += -2*a - difb[0]
# charge19[i].coords[1] -= difb[1]
# newcharge.append(charge_xyz(charge19[i].coords, charge19[i].charge))
# #+2a-b
# if rotAxis=="a" or rotAxis=="0":
# countChargesPDIR +=1
# charge20 = copy.deepcopy(charge)
# for i in range(len(charge20)):
# charge20[i].coords[0] += 2*a - difb[0]
# charge20[i].coords[1] -= difb[1]
# newcharge.append(charge_xyz(charge20[i].coords, charge20[i].charge))
# #+2a-2b
# if rotAxis=="0" or rotAxis=="a":
# countChargesPDIR +=1
# charge21 = copy.deepcopy(charge)
# for i in range(len(charge21)):
# charge21[i].coords[0] += 2*(a - difb[0])
# charge21[i].coords[1] -= 2*difb[1]
# newcharge.append(charge_xyz(charge21[i].coords, charge21[i].charge))
# #+a-2b
# if rotAxis=="0" or rotAxis=="a":
# countChargesPDIR +=1
# charge22 = copy.deepcopy(charge)
# for i in range(len(charge22)):
# charge22[i].coords[0] += a - 2*difb[0]
# charge22[i].coords[1] -= 2*difb[1]
# newcharge.append(charge_xyz(charge22[i].coords, charge22[i].charge))
# #-2b
# if rotAxis=="b" or rotAxis=="0" or rotAxis=="a":
# countChargesPDIR +=1
# charge23 = copy.deepcopy(charge)
# for i in range(len(charge23)):
# charge23[i].coords[0] -= 2*difb[0]
# charge23[i].coords[1] -= 2*difb[1]
# newcharge.append(charge_xyz(charge23[i].coords, charge23[i].charge))
# #-2b-a
# if rotAxis=="b" or rotAxis=="0" or rotAxis=="a":
# countChargesPDIR +=1
# charge24 = copy.deepcopy(charge)
# for i in range(len(charge24)):
# charge24[i].coords[0] -= 2*difb[0] + a
# charge24[i].coords[1] -= 2*difb[1]
# newcharge.append(charge_xyz(charge24[i].coords, charge24[i].charge))
# #-2b-2a
# if rotAxis=="0" or rotAxis=="a" or rotAxis=="b":
# countChargesPDIR +=1
# charge25 = copy.deepcopy(charge)
# for i in range(len(charge25)):
# charge25[i].coords[0] -= 2* (difb[0] + a)
# charge25[i].coords[1] -= 2*difb[1]
# newcharge.append(charge_xyz(charge25[i].coords, charge25[i].charge))
beginMultiplierA = -2
beginMultiplierB = -2
moleculesA = 5
moleculesB = 5
# Adjust values
if rotAxis == "a":
beginMultiplierB = 1 - numberLayers
moleculesB = numberLayers
if rotAxis == "b":
beginMultiplierA = 1 - numberLayers
moleculesA = numberLayers
#Begin first layer (middle)
if (numberLayers >= 1 and (rotAxis == "c" or rotAxis == "0")) or (rotAxis == "a") or (rotAxis == "b"):
for i in range(moleculesB):
for j in range(moleculesA):
if (beginMultiplierB != -i or beginMultiplierA != -j):
countChargesPDIR +=1
chargeFirstLayer = copy.deepcopy(charge)
for k in range(len(chargeFirstLayer)):
chargeFirstLayer[k].coords[0] += beginMultiplierA*a + beginMultiplierB*difb[0] + j*a + i*difb[0]
chargeFirstLayer[k].coords[1] += beginMultiplierB*difb[1] + i*difb[1]
newcharge.append(charge_xyz(chargeFirstLayer[k].coords, chargeFirstLayer[k].charge))
#Begin second layer (-z)
if (numberLayers >= 2 and (rotAxis == "c" or rotAxis == "0")) or (rotAxis == "a") or (rotAxis == "b"):
for i in range(moleculesB):
for j in range(moleculesA):
countChargesPDIR +=1
chargeSecondLayer = copy.deepcopy(charge)
for k in range(len(chargeSecondLayer)):
chargeSecondLayer[k].coords[0] += beginMultiplierA*a + beginMultiplierB*difb[0] + j*a + i*difb[0] - difc[0]
chargeSecondLayer[k].coords[1] += beginMultiplierB*difb[1] + i*difb[1] - difc[1]
chargeSecondLayer[k].coords[2] += -difc[2]
newcharge.append(charge_xyz(chargeSecondLayer[k].coords, chargeSecondLayer[k].charge))
#Begin third layer (+z)
if (numberLayers >= 3 and (rotAxis == "c" or rotAxis == "0")) or (rotAxis == "a") or (rotAxis == "b"):
for i in range(moleculesB):
for j in range(moleculesA):
countChargesPDIR +=1
chargeThirdLayer = copy.deepcopy(charge)
for k in range(len(chargeThirdLayer)):
chargeThirdLayer[k].coords[0] += beginMultiplierA*a + beginMultiplierB*difb[0] + j*a + i*difb[0] + difc[0]
chargeThirdLayer[k].coords[1] += beginMultiplierB*difb[1] + i*difb[1] + difc[1]
chargeThirdLayer[k].coords[2] += difc[2]
newcharge.append(charge_xyz(chargeThirdLayer[k].coords, chargeThirdLayer[k].charge))
return newcharge
'''Funktion shiftcoord:
verschiebt die eingegebene Koordinate um den eingegebenen Wert
und speichert die neue Koordinate zusammen mit den unveränderten
in einer neuen Liste.'''
def shiftcoord(xyz, input_file, shiftsize):
newcoord = []
coord = []
for i in range(len(input_file)):
if xyz == "x":
input_file[i].coords[0] = (input_file[i].coords[0] + shiftsize)
newcoord.append(atom_xyz(input_file[i].symbol, input_file[i].coords))
elif xyz == "y":
input_file[i].coords[1] = (input_file[i].coords[1] + shiftsize)
newcoord.append(atom_xyz(input_file[i].symbol, input_file[i].coords))
elif xyz == "z":
input_file[i].coords[2] = (input_file[i].coords[2] + shiftsize)
newcoord.append(atom_xyz(input_file[i].symbol, input_file[i].coords))
return newcoord
'''Funktion shiftcoordcharges:
verschiebt die eingegebene Koordinate um den eingegebenen Wert
und speichert die neue Koordinate zusammen mit den unveränderten
in einer neuen Liste.'''
def shiftcoordcharges(xyz, input_file, shiftsize):
newcoord = []
coord = []
for i in range(len(input_file)):
if xyz == "x":
input_file[i].coords[0] = (input_file[i].coords[0] + shiftsize)
newcoord.append(charge_xyz(input_file[i].coords, input_file[i].charge))
elif xyz == "y":
input_file[i].coords[1] = (input_file[i].coords[1] + shiftsize)
newcoord.append(charge_xyz(input_file[i].coords, input_file[i].charge))
elif xyz == "z":
input_file[i].coords[2] = (input_file[i].coords[2] + shiftsize)
newcoord.append(charge_xyz(input_file[i].coords, input_file[i].charge))
return newcoord
'''Mathematische Umformung um in Richtung der b-Achse des PDIRs zu verschieben.
Gibt eine Liste zurück mit x- und y-Koordinaten,
welche die Differenz zur b-Achse beschreibt'''
def getbPDIR(gamma, b):
difb = []
gammastrich = 180 - gamma
g = m.radians(gammastrich)
y = m.sin(g) * b
x = m.cos(g) * b
difb.append(x)
difb.append(y)
return difb
'''Mathematische Umformung um in Richtung der c-Achse des PDIRs zu verschieben.
Gibt eine Liste zurück mit x-, y- und z-Koordinaten,
welche die Differenz zur c-Achse beschreibt'''
def getcPDIR(alpha, beta, gamma, c):
difc = []
betastrich = 90 - beta
gammastrich = 180 - gamma
g = m.radians(gammastrich)
betastra = m.radians(betastrich)
alphara = m.radians(alpha)
betara = m.radians(beta)
x = m.cos(betara) * c
y = m.cos(alphara) * c * m.sin(g)
z = m.cos(betastra) * c
difc.append(x)
difc.append(y)
difc.append(z)
return difc
'''Funktion rot_axis_angle:
Erstellt eine Rotationsmatrix'''
def rot_axis_angle(axis, angle): # [0,1,0] |90
axis /= np.linalg.norm(axis)
theta = m.radians(angle)
costheta = m.cos(theta)
sintheta = m.sin(theta)
Ex = np.array(
[[0.0, -axis[2], axis[1]], [axis[2], 0, -axis[0]], [-axis[1], axis[0], 0.0]])
A = costheta * \
np.eye(3) + (1.0 - costheta) * \
np.dot(axis.reshape(3, 1), axis.reshape(1, 3)) + \
sintheta * Ex
return A
'''Funktion product_matrix_vector:
Multipliziert eine Matrix mit einem Vektor und gibt
das Ergebnis zurück.
Speichert das Ergebnis in der Klasse atom.'''
def product_matrix_vector(matrix, input_file):
newcoord = []
for i in range(len(input_file)):
vec = input_file[i].coords
newvec = np.dot(matrix,vec)
newcoord.append(atom_xyz(input_file[i].symbol, newvec))
return newcoord
'''Funktion product_matrix_vector_charges:
Multipliziert eine Matrix mit einem Vektor und gibt das Ergebnis zurück.
Speichert das Ergebnis in der Klasse charge.'''
def product_matrix_vector_charges(matrix, input_file):
newcoord = []
for i in range(len(input_file)):
vec = input_file[i].coords
newvec = np.dot(matrix,vec)
newcoord.append(charge_xyz(newvec, input_file[i].charge))
return newcoord
'''Speichert die Symbole und Koordinaten von DIP und PDIR in einer Liste ab.'''
def getonefile (retPDIR, ret):
ret1 = copy.deepcopy(ret)
for i in range(len(retPDIR)):
ret1.append(atom_xyz(retPDIR[i].symbol, retPDIR[i].coords))
return ret1
'''Schreibt sowohl die Ladungen (mit Atomsymbol) als auch
DIP und PDIR in eine xyz Datei.'''
def outputeverythingDIPPDIR(retDIP, retPDIR, retDIPPDIR, chargesDIP,
chargesPDIR, step):
totallength = int(len(retDIPPDIR))
lengthchargesDIP = int(len(chargesDIP))
lengthchargesPDIR = int(len(chargesPDIR))
ret1 = copy.deepcopy(retDIP)
ret2 = []
ret3 = []
global countChargesPDIR
global countChargesDIP1
global countChargesDIP2
lengthfile = lengthchargesDIP + totallength + lengthchargesPDIR
f = open("everything{}.xyz".format(step), "w")
f.write(str(lengthfile))
f.write("\n")
f.write("\n")
i = 0
while i < (countChargesDIP2+countChargesDIP1):
for j in range(len(ret1)):
ret2.append(atom_xyz(ret1[j].symbol, ret1[j].coords))
i += 1
n = 0
while n < countChargesPDIR:
for j in range(len(retPDIR)):
ret3.append(atom_xyz(retPDIR[j].symbol, retPDIR[j].coords))
n += 1
for j in range(len(chargesDIP)):
f.write(str(ret2[j].symbol))
f.write(" ")
k = 0
while k < 3:
f.write(str(np.array(chargesDIP[j].coords[k])))
f.write(" ")
k += 1
f.write("\n")
for j in range(len(chargesPDIR)):
f.write(str(ret3[j].symbol))
f.write(" ")
k = 0
while k < 3:
f.write(str(np.array(chargesPDIR[j].coords[k])))
f.write(" ")
k += 1
f.write("\n")
for l in range(len(retDIPPDIR)):
f.write(str(retDIPPDIR[l].symbol))
f.write(" ")
m = 0
while m < 3:
f.write(str(np.array(retDIPPDIR[l].coords[m])))
f.write(" ")
m += 1
f.write("\n")
f.close()
def mergeChargeCoords(coords, charges, path):
f = open(path, "w")
for j in range(len(coords)):
k = 0
while k < 3:
f.write(str(np.array(coords[j].coords[k])))
f.write(" ")
k += 1
f.write(str(charges[j].charge))
f.write("\n")
f.close()
'''Funktion output:
Öffnet eine neue xyz-Datei und speichert dort
die veränderten Koordinaten und Symbole ab.'''
def output(newcoord, step):
f = open("neueKoordinaten{}.xyz".format(step), "w")
f.write(str(int(len(newcoord))))
f.write("\n")
f.write("\n")
for a in range(len(newcoord)):
f.write(str(newcoord[a].symbol))
f.write(" ")
j = 0
while j < 3:
f.write(str(np.array(newcoord[a].coords[j])))
f.write(" ")
j += 1
f.write("\n")
f.close()
'''Öffnet eine neue xyz-Datei und speichert dort
die veränderten Koordinaten und Ladungen ab.'''
def outputchargesDIP(newcoord, step):
f = open("neuechargesDIP{}.txt".format(step), "w")
f.write(str(int(len(newcoord))))
f.write("\n")
f.write("\n")
for a in range(len(newcoord)):
j = 0
while j<3:
f.write(str(np.array(newcoord[a].coords[j])))
f.write(" ")
j += 1
f.write(str(float(newcoord[a].charge)))
f.write("\n")
f.close()
'''Funktion make_com:
Erstellt eine com-Datei'''
def make_com(xyz1, xyz2, chargesDIP, chargesPDIR, char):
if char == "Ja":
head = """%NProcShared=8
%Mem=6GB
%chk=gs.chk
#p wB97XD/cc-pVDZ charge gfinput pop=full TD(nstates=8)
Dimer
0 1
"""
with open("gauss.com","w") as out_file:
out_file.write(head)
for struct in xyz1:
out_file.write("{} {:12.6f} {:12.6f} {:12.6f}\n".format(struct.symbol, *struct.coords))
for struct in xyz2:
out_file.write("{} {:12.6f} {:12.6f} {:12.6f}\n".format(struct.symbol, *struct.coords))
out_file.write("\n")
for struct in chargesDIP:
out_file.write("{:12.6f} {:12.6f} {:12.6f} {:12.6f}\n".format(*struct.coords, struct.charge))
for struct in chargesPDIR:
out_file.write("{:12.6f} {:12.6f} {:12.6f} {:12.6f}\n".format(*struct.coords, struct.charge))
out_file.write("\n\n\n\n")
else:
head = """%NProcShared=8
%Mem=6GB
%chk=gs.chk
#p wB97XD/cc-pVDZ gfinput pop=full TD(nstates=8)
Dimer
0 1
"""
with open("gauss.com","w") as out_file:
out_file.write(head)
for struct in xyz1:
out_file.write("{} {:12.6f} {:12.6f} {:12.6f}\n".format(struct.symbol, *struct.coords))
for struct in xyz2:
out_file.write("{} {:12.6f} {:12.6f} {:12.6f}\n".format(struct.symbol, *struct.coords))
out_file.write("\n")
'''Funktion make_sh:
Erstellt eine sh-Datei'''
def make_sh(step, xyz):
head = """#PBS -l nodes=1:ppn=8
#PBS -l walltime=800:00:00
#PBS -l mem=8GB
#PBS -N {}_{}Dimer
cd $PBS_O_WORKDIR
cp -rf * $TMPDIR
cd $TMPDIR
# setenv g16root /apps/gaussian/g16_A
# source $g16root/g16/bsd/g16.login
# setenv GAUSS_SCRDIR $TMPDIR
g16 gauss.com
rm Gau-*
cp -rf * $PBS_O_WORKDIR