-
Notifications
You must be signed in to change notification settings - Fork 1
/
WW_orientation_R3.py
executable file
·1816 lines (1484 loc) · 73.3 KB
/
WW_orientation_R3.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
############################################################################
##This file is used to calculate the WW orientation entropy with respect to
##the each water pair. Firstly, each H2O coordinates were obtained for calculation
##Then, the angle between each H2O pair is obtained (FrameInfor should be take care
##)
##
##
##
##Xianqiang Sun
##TheoChem&Bio
##KTH
##2012-05-28
###########################################################################
#symmetry for the dictionary
import numpy
import sys
sys.path.append('/home/x/xiansu/pfs/program/numpy/lib/python2.6/site-packages')
from Numeric import *
from datetime import datetime
centreFile=open('optimizedCentre.txt','r')
waterFile=open('waterInforByCentre.txt','r')
allH2OInforFile=open('WW_allCentre_H2O.txt','r')
##conservedH2OInforFile=open('SW_conservedCentre_H2O.txt','r')
angleFile=open('WW_angle.txt','w')
rdfFile=open('rdf_HO_HO.xvg','r')
SorOutput=open('WW_Orien.dat','w')
frameNo=6000
k=1.380648813*(10**(-23)) ## The unit of the boltzmann constant is J/K.
weiH2O=18.0154
mol=6.02214179*(10**23)
pw=0.0331725 ## The unit of this is No. of molecules in per A2.
def getCentreCoord(self):
centreCoord=[]
for centre in self:
centre=centre.split()
centreFloat=[]
for coord in centre:
coord =float(coord)
centreFloat.append(coord)
centreCoord.append(centreFloat)
return centreCoord
##getCentreCoord read the output file from the 'calculatCentre_oop.py'. Read the
##coorditates and save them as list with the float format. The output format is
##the format is:[[x1,y1,z2],[x2,y2,z2]...]
def getWaterInforWithCentre(self):
waterInforWithCentre=[]
for waterInfor in self:
waterInfor=waterInfor.split()
waterInforWithCentre.append(waterInfor)
return waterInforWithCentre
##getWaterInforWithCentre is a function that can be used to read the output waterInfor
##file from 'OptimizeCentre_oop.py'. The water infor were saved as list,[[waterInfor]..]
def orangeWaterInforWithCentre(self,centre):
waterInforAccCentre=[]
for centreNo in range(len(centre)):
eachWaterInforAccCentre=[]
for waterInfor in self:
## print waterInfor[-1]
if waterInfor[-1]==str(centreNo):
eachWaterInforAccCentre.append(waterInfor)
waterInforAccCentre.append(eachWaterInforAccCentre)
return waterInforAccCentre
##getWaterInforWithCentre is organise the water information to lists according the index of
##centres. the water information were saved as[[waterInforInCentre1],[waterInforInCentre1]..].
##WaterInfor in the final result were all saved as list.
def orangeH2OInfor(self):
allH2OInfor=[]
for H2OSet in self:
H2OSetInfor=[]
eachH2O=[]
no=1
for H2O in H2OSet:
if no/3.0==1.0:
eachH2O.append(H2O)
H2OSetInfor.append(eachH2O)
eachH2O=[]
no=1
else:
eachH2O.append(H2O)
no+=1
## for i in H2OSetInfor:
## print i
print 'There were',len(H2OSetInfor), 'in H2OSetInfor!'
allH2OInfor.append(H2OSetInfor)
return allH2OInfor
##orangeH2OInfor can be used to organize a sets of waters which is saved as list H2O informations to sets,
##As there were three atoms in the H2O, therefore, each H2O can be saved as a list. Then, the H2O atom
##lists can be saved as lists. At last the list can be saved according to each centre.
##The output looks like [[[[AtomInfor]...WaterInfor]...CentreInfor]...All H2O]
def removeLessOcuCentre(self,waterInforAccCen,frameNo):
highOcuCentre=[]
for i in range(len(self)):
ocupyNo=len(waterInforAccCen[i])
if (float(ocupyNo)/float(frameNo))>=0.95:
highOcuCentre.append(self[i])
return highOcuCentre
def removeLessOcuWaterInfor(self,waterInforAccCen,frameNo):
highOcuWaterInfor=[]
for i in range(len(self)):
ocupyNo=len(waterInforAccCen[i])
if (float(ocupyNo)/float(frameNo))>=0.95:
highOcuWaterInfor.append(waterInforAccCen[i])
return highOcuWaterInfor
##removeLessOcuCentre is used to obtain the high occupied centre with the ratio>=0.95. The input
##were self: all the centre coordidated; WaterInforAccCen: oranged water information according to
##the centre; frameNo is the total Number of framed you want to calculated.
##These highOcuCentre were saved as list of coordidates. The highOcuWaterInfor were saved according
##to the centre highOcuCentre with the format of [[[waterInforInCentre1],[waterInforInCentre1]]..].
def extractWaterCoor(self):
waterCoor=[]
for waterSet in self:
waterCoorSet=[]
for waterInfor in waterSet:
eachWaterCoor=[]
eachWaterCoorStr=waterInfor[3:-3]
for i in eachWaterCoorStr:
i=float(i)
eachWaterCoor.append(i)
waterCoorSet.append(eachWaterCoor)
waterCoor.append(waterCoorSet)
return waterCoor
##ExtractWaterCoor use the output of function of removeLessOcuWaterInfor.The waterCoord were extracted
##according to each high occupied water coordidate centre. The format of the output is[[waterCoor,waterCoor]
##...]
def getH2OCoord(self):
allH2OCoord=[]
for H2OInforAccCentre in self:
## print len(H2OInforAccCentre)
H2OCoordAccCentre=[]
for H2OInfor in H2OInforAccCentre:
H2OCoord=[]
for H2OAtom in H2OInfor:
H2OAtomCoord=H2OAtom[3:-3]
for number in range(len(H2OAtomCoord)):
H2OAtomCoord[number]=float(H2OAtomCoord[number])
H2OCoord.append(H2OAtomCoord)
H2OCoordAccCentre.append(H2OCoord)
allH2OCoord.append(H2OCoordAccCentre)
print 'The coordinate length in each centre is :',len(H2OCoordAccCentre)
return allH2OCoord
##getH2OCoord is used to extract all the H2O coordidates and save each H2O coordinates
##as list. Then H2O coordinates were saved according to each centre. At last, all
##the H2O coords were saved as a list.
def H2OInforNearbyHighCentre(self,allCentre,conservedH2OInfor,nearbyWaterInfor):
H2OInforAndAround=[]
for conservedCentreNo in range(len(self)):
eachH2OAndAround=[]
eachConservedCentre=self[conservedCentreNo]
eachConservedCentreArray=numpy.array(eachConservedCentre)
eachH2OAndAround.append(conservedH2OInfor[conservedCentreNo])
for allCentreNo in range(len(allCentre)):
aroundCentre=allCentre[allCentreNo]
aroundCentreArray=numpy.array(aroundCentre)
vectorCC=eachConservedCentreArray-aroundCentreArray
vectorCCModulus=numpy.sqrt((vectorCC*vectorCC).sum())
if 5.0>=vectorCCModulus>=1.5:
eachH2OAndAround.append(nearbyWaterInfor[allCentreNo])
if len(eachH2OAndAround)>1:
H2OInforAndAround.append(eachH2OAndAround)
print len(H2OInforAndAround)
return H2OInforAndAround
##H2OInforNearbyHighCentre can be used to find centre around each high occupied centre.The input included
##several information to be calculated. self: the input of the high occupied centre. allcentre: the
##centres for all the optimized centres. conservedH2OInfor inculdes all the H2O infor according to the
##high occupied centre. The nearbyWaterInfor includes all the h2O infors consitant with allCentre
##the output of this functions includes each high occupied H2O infor
##and the H2O infor around each high occupied centre.[[[highOccupiedH2OInfor],[aroundH2OInfor2],[around
##H2OInfor2]],[...]...]. Moreover, the output centre is consistant with centre of findNearByCentre output.
def findNearByWater(self,allCentre,highWaterInfor,waterInfor):
centreAndAround=[]
WWCentreNo=[]
for centreNo in range(len(self)):
eachCentreAndAround=[]
eachCentre=self[centreNo]
eachCentre=numpy.array(eachCentre)
eachCentreAndAround.append(highWaterInfor[centreNo])
no=0
for allCentreNo in range(len(allCentre)):
aroundCentre=allCentre[allCentreNo]
aroundCentre=numpy.array(aroundCentre)
vectorCC=eachCentre-aroundCentre
vectorCCModulus=numpy.sqrt((vectorCC*vectorCC).sum())
if 5.0>=vectorCCModulus>=1.5:
no+=1
eachCentreAndAround.append(waterInfor[allCentreNo])
## print no,'waters arround centre',centreNo
if len(eachCentreAndAround)>1:
WWCentreNo.append(centreNo)
print len(eachCentreAndAround)
centreAndAround.append(eachCentreAndAround)
return centreAndAround
##findNearByWater can be used to find waters around each high occupied centre. The input included
##several information to be calculated. self: the input of the high occupied centre. allcentre: the
##centres for all the optimized centres. The highwaterinfor includes the water informations for all
##the high conserced waters. the output of this functions includes each high occupied water centre
##and the waters around each high occupied centre.[[[highOccupiedCentreInfor1],[aroundWater1],[around
##Water1]],[...]...]
def findNearbyCentre(self,allCentre):
centreNearby=[]
for centreNo in range(len(self)):
eachCentreAndAround=[]
eachCentre=self[centreNo]
eachCentreArray=numpy.array(eachCentre)
eachCentreAndAround.append(eachCentre)
no=0
for allCentreNo in range(len(allCentre)):
aroundCentre=allCentre[allCentreNo]
aroundCentreArray=numpy.array(aroundCentre)
vectorCC=eachCentreArray-aroundCentreArray
vectorCCModulus=numpy.sqrt((vectorCC*vectorCC).sum())
if 5.0>=vectorCCModulus>=1.5:
no+=1
eachCentreAndAround.append(aroundCentre)
## print no,'waters arround centre','centreNo'
if len(eachCentreAndAround)>1:
centreNearby.append(eachCentreAndAround)
## print centreNearby
return centreNearby
##findNearByCentre can be used to find centre around each high occupied centre. The input included
##several information to be calculated. self: the input of the high occupied centre. allcentre: the
##centres for all the optimized centres. the output of this functions includes each high occupied water centre
##and the waters centre around each high occupied centre.[[[highOccupiedCentre1],[aroundCentre2],[around
##centre2]],[...]...]
def findNearbyCentreNo(self,allCentre):
WWCentreNo=[]
for centreNo in range(len(self)):
eachCentreAndAround=[]
eachCentre=self[centreNo]
eachCentreArray=numpy.array(eachCentre)
eachCentreAndAround.append(eachCentre)
no=0
for allCentreNo in range(len(allCentre)):
aroundCentre=allCentre[allCentreNo]
aroundCentreArray=numpy.array(aroundCentre)
vectorCC=eachCentreArray-aroundCentreArray
vectorCCModulus=numpy.sqrt((vectorCC*vectorCC).sum())
if 5.0>=vectorCCModulus>=1.5:
no+=1
eachCentreAndAround.append(aroundCentre)
## print no,'waters arround centre','centreNo'
if len(eachCentreAndAround)>1:
WWCentreNo.append(centreNo)
print WWCentreNo
return WWCentreNo
##findNearByCentreNo can be used to find centre around each high occupied centre. The input included
##several information to be calculated. self: the input of the high occupied centre. allcentre: the
##centres for all the optimized centres. the output of this functions includes each high occupied water centre
##and the waters centre around each high occupied centre.[[[highOccupiedCentre1],[aroundCentre2],[around
##centre2]],[...]...]
def findNearbyCentreAndAroundNo(self,allCentre):
WWCentreNo=[]
for centreNo in range(len(self)):
eachCentreNoAndAround=[]
eachCentre=self[centreNo]
eachCentreArray=numpy.array(eachCentre)
eachCentreNoAndAround.append(centreNo)
no=0
for allCentreNo in range(len(allCentre)):
aroundCentre=allCentre[allCentreNo]
aroundCentreArray=numpy.array(aroundCentre)
vectorCC=eachCentreArray-aroundCentreArray
vectorCCModulus=numpy.sqrt((vectorCC*vectorCC).sum())
if 5.0>=vectorCCModulus>=1.5:
no+=1
eachCentreNoAndAround.append(allCentreNo)
print allCentreNo
print no,'waters arround centre',centreNo
if len(eachCentreNoAndAround)>1:
WWCentreNo.append(eachCentreNoAndAround)
print 'each CenterNo and around:',WWCentreNo
return WWCentreNo
##findNearByCentreAndAroundNo can be used to find centre around each high occupied centre. The input included
##several information to be calculated. self: the input of the high occupied centre. allcentre: the
##centres for all the optimized centres. the output of this functions includes each high occupied water centre
##and the waters centre around each high occupied centre.[[[highOccupiedCentre1No,aroundCentreNo1,aroundCentreNo2],
##[...]...]
def extractWaterCoor(self):
waterCoor=[]
for waterSet in self:
waterCoorSet=[]
for waterInfor in waterSet:
eachWaterCoor=[]
eachWaterCoorStr=waterInfor[3:-3]
## print eachWaterCoorStr
for i in eachWaterCoorStr:
## print i
i=float(i)
eachWaterCoor.append(i)
waterCoorSet.append(eachWaterCoor)
waterCoor.append(waterCoorSet)
return waterCoor
##ExtractWaterCoor use the output of function of removeLessOcuWaterInfor.The waterCoord were extracted
##according to each high occupied water coordidate centre. The format of the output is[[waterCoor,waterCoor]
##...]
def extractWaterCoorAround(self):
waterCoordAround=[]
for eachWaterCentre in waterInforAroundCentre:
## print len(eachWaterCentre)
eachWaterCoordAround=extractWaterCoor(eachWaterCentre)
waterCoordAround.append(eachWaterCoordAround)
## print len(waterCoordAround)
return waterCoordAround
##ExtractWaterCoorAround use mainly use the function of ExtractWaterCoor to extract the water coordinates
##Around each centre. This function read the output of 'findNearByWater' and then the save each waterCoordnate
##according to each high occupied water coordidate centre. The highly accupied centre was saved as the first
##item in each sublist. The waters around this centre were saved as the following items
##The format of the output is[[[centreWaterCoorList],[waterCoorAroundCentre],[waterCoorAroundCentre]..]..]
def calculateGR(self,centre,frameNo):
gr=[]
waterDensPerA2=0.0331725
constant1=(4/3.0)*pi
for centreNo in range(len(centre)):
grNo=range(24)
waterCoorSet=self[centreNo]
## frameNo=len(waterCoorSet)
centreCoor=centre[centreNo]
centreCoor=numpy.array(centreCoor)
for no in range(len(grNo)):
grNo[no]=0
## print grNo
for waterCoor in waterCoorSet:
## print waterCoor, centreCoor
waterCoor=numpy.array(waterCoor)
dist=numpy.linalg.norm(waterCoor-centreCoor)
## print dist
for number in range(24):
nextNumber=number+1
if nextNumber*0.05>dist>=number*0.05:
grNo[number]+=1
## print waterCoor, centreCoor, dist, number
elif dist==24*0.05:
grNo[23]+=1
## print grNo
for number in range(len(grNo)):
prevNumber=number+1
grNo[number]=round(grNo[number]/(constant1*(((prevNumber*0.05)**3)-((number*0.05)**3)))/waterDensPerA2/frameNo,3)
## print grNo
gr.append(grNo)
return gr
##calculateGR is used to calculate the g(r) distribution of each coordidate centre
##the input include : (1),self: the water coordidate sets according to the centre
##(2)Centre:each centre for calculation. (3) frameNo: total frames for the
##calculation. The frameNo information should be included to calculate the
##water density at each centre. The output of this function is list of g(r)
##According to each centre. Moreover, as we have to calculate the g(r) according
##to the distance between the centre and the oxygen coordidated in each frame.
##Each g(r) were saved as list. the form of the output looks like
##[[g(0~0.1),g(0.1~0.2)...g(1.1~1.2)]......]
def calculateGRTheta(self,centre,frameNo):
grTheta=[]
## thetaDensity=frameNo/20.0
reference=numpy.array([0,0,1])
referenceModulus=numpy.sqrt((reference*reference).sum())
for centreNo in range(len(centre)):
grThetaNo=range(20)
waterCoorSet=self[centreNo]
centreCoor=centre[centreNo]
centreCoor=numpy.array(centreCoor)
# frameNo=len(waterCoorSet)
thetaDensity=frameNo/20.0
for no in range(len(grThetaNo)):
grThetaNo[no]=0
for waterCoor in waterCoorSet:
## print waterCoor, centreCoor
waterCoor=numpy.array(waterCoor)
orientation=waterCoor-centreCoor
orientationModulus=numpy.sqrt((orientation*orientation).sum())
dot=numpy.dot(orientation,reference)
cosAngle=dot/referenceModulus/orientationModulus
angle=numpy.arccos(cosAngle)
## print 'the angle of Phi is',angle
for number in range(20):
nextNumber=number+1
if nextNumber*pi/20.0>angle>=number*pi/20.0:
## print 'the angle of Phi is',waterCoor, centreCoor, angle, number
grThetaNo[number]+=1
elif angle==pi:
grThetaNo[19]+=1
## print 'the angle distri bution',grThetaNo
for number in range(len(grThetaNo)):
nextNumber=number+1
grThetaNo[number]=(grThetaNo[number]/(cos(number*pi/20.0)-cos(nextNumber*pi/20.0)))/(frameNo/2.0)
grTheta.append(grThetaNo)
## print grTheta
return grTheta
####????????????????????????????????????????????Maybe A question here
##calculateGRTheta is used to calculate the g(theta) distribution of each coordidate centre
##the input include : (1),self: the water coordidate sets according to the centre
##(2)Centre:each centre for calculation. (3) frameNo: total frames for the
##calculation. The frameNo information should be included to calculate the
##water density at each centre. The output of this function is list of g(theta)
##According to each centre. Moreover, as we have to calculate the g(theta) according
##to the reference oritentation[0, 0,1 ] and the oritentation between the centre and the oxygen coordidated
##in each frame.Each g(theta) were saved as list. the form of the output looks like
##[[g(0~*pi/20.0),g(pi/20.0~2*pi/20.0)...g(pi~19*pi/20.0)]......]
def calculateGRPhi(self,centre,frameNo):
grPhi=[]
## phiDensity=frameNo/20.0
referenceZ=numpy.array([0,0,1])
referenceZModulus=numpy.sqrt((referenceZ*referenceZ).sum())
referenceX=numpy.array([1,0,0])
referenceXModulus=numpy.sqrt((referenceX*referenceX).sum())
for centreNo in range(len(centre)):
grPhiNo=range(40)
waterCoorSet=self[centreNo]
centreCoor=centre[centreNo]
centreCoorArray=numpy.array(centreCoor)
# frameNo=len(waterCoorSet)
phiDensity=frameNo/40.0
for no in range(len(grPhiNo)):
grPhiNo[no]=0
for waterCoor in waterCoorSet:
waterCoorArray=numpy.array(waterCoor)
orientation=waterCoorArray-centreCoorArray
orientationModulus=numpy.sqrt((orientation*orientation).sum())
dot1=numpy.dot(orientation,referenceZ)
cosAngle1=dot1/referenceZModulus/orientationModulus
zReflection=orientationModulus*cosAngle1
waterCoorCopy=[]
waterCoorCopy.extend(waterCoor)
waterCoorCopy[2]=waterCoorCopy[2]-zReflection
newWaterCoorArray=numpy.array(waterCoorCopy)
newOrientation=newWaterCoorArray-centreCoorArray
newOrientationModulus=numpy.sqrt((newOrientation*newOrientation).sum())
dot2=numpy.dot(newOrientation,referenceX)
cosAngle2=dot2/referenceXModulus/newOrientationModulus
angle=numpy.arccos(cosAngle2)
if newOrientation[1]<0:
angle=2*pi-angle
for number in range(40):
nextNumber=number+1
if nextNumber*pi/20.0>angle>=number*pi/20.0:
grPhiNo[number]+=1
elif angle==2*pi:
grPhiNo[39]+=1
print 'the angle distri bution grPhiNo',centreNo, grPhiNo
for number in range(len(grPhiNo)):
grPhiNo[number]=grPhiNo[number]/phiDensity
grPhi.append(grPhiNo)
print 'the angle distri bution grPhiNo',centreNo, grPhiNo
## print grPhi
return grPhi
####????????????????????????????????????????????Maybe A question here
##calculateGRPhi is used to calculate the g(Phi) distribution of each coordidate centre
##the input include : (1),self: the water coordidate sets according to the centre
##(2)Centre:each centre for calculation. (3) frameNo: total frames for the
##calculation. The frameNo information should be included to calculate the
##water density at each centre. The output of this function is list of g(Phi)
##According to each centre. We first calculate the cos(theta) according to [1,0,0]. According to cos(theta)
##The reflection of water Coordidate on XOY plane was found. Therefore, cos(theta) were obtained according to
##the reference oritentation[0,0,1] and the oritentation between the centre and reflection on XOY
##in each frame.Each g(Phi) were saved as list. the form of the output looks like
##[[g(0~*pi/20.0),g(pi/20.0~2*pi/20.0)...g(pi~19*pi/20.0)]......]
def calculateGReachCentre(self,nearbyCentre,frameNo):
grCentreAndAround=[]
for eachWaterNo in range(len(self)):
eachCentre=nearbyCentre[eachWaterNo]
eachWater=self[eachWaterNo]
eachGr=calculateGR(eachWater,eachCentre,frameNo)
grCentreAndAround.append(eachGr)
return grCentreAndAround
##calculateGReachCentre is used to calculate the Gr of for all the centre waters and the arounded waters.
##The input included self: water coordinates which is saved as list of waters and arounded waters. This can be the
##output of function 'extractWaterCoorAround'. nearbycentre is all the centres for the calculation. The centre
##information should be consistant with the self(waterCoordinate). Morover, it can read the output of function
##'findNearbyCentre'. The output of this function looks like[[[centreGr],[aroundWatrer1 Gr]...]......]
def calculateGThetaeachCentre(self,nearbyCentre,frameNo):
gthetaCentreAndAround=[]
for eachWaterNo in range(len(self)):
eachCentre=nearbyCentre[eachWaterNo]
eachWater=self[eachWaterNo]
eachGtheta=calculateGRTheta(eachWater,eachCentre,frameNo)
gthetaCentreAndAround.append(eachGtheta)
return gthetaCentreAndAround
##calculateGThetaeachCentre is used to calculate the GTheta of for all the centre waters and the arounded waters.
##The input included self: water coordinates which is saved as list of waters and arounded waters. This can be the
##output of function 'extractWaterCoorAround'. nearbycentre is all the centres for the calculation. The centre
##information should be consistant with the self(waterCoordinate). Morover, it can read the output of function
##'findNearbyCentre'. The output of this function looks like[[[centreGTheta],[aroundWatrer1 GTheta]...]......]
def calculateGPhieachCentre(self,nearbyCentre,frameNo):
gphiCentreAndAround=[]
for eachWaterNo in range(len(self)):
eachCentre=nearbyCentre[eachWaterNo]
eachWater=self[eachWaterNo]
eachGphi=calculateGRPhi(eachWater,eachCentre,frameNo)
gphiCentreAndAround.append(eachGphi)
return gphiCentreAndAround
##calculateGPhieachCentre is used to calculate the Gphi of for all the centre waters and the arounded waters.
##The input included self: water coordinates which is saved as list of waters and arounded waters. This can be the
##output of function 'extractWaterCoorAround'. nearbycentre is all the centres for the calculation. The centre
##information should be consistant with the self(waterCoordinate). Morover, it can read the output of function
##'findNearbyCentre'. The output of this function looks like[[[centreGPhi],[aroundWatrer1 GPhi]...]......]
def getRdfOO(self):
rdf=[]
for line in self:
line=line.split()
for No in range(len(line)):
eachElement=line[No]
line[No]=float(eachElement)
line[0]=line[0]*10
rdf.append(line)
## print rdf
return rdf
##getRdfOO is used to get the RDF distribution of water with Oxy-Oxy paris.
##the input self is the rdf file and the output is the rdf distribution as lists.
def calculateGRInhTrans(self,rdfOO):
print rdfOO
waterDensPerA2=0.0331725
constant1=(4/3.0)*pi
grInhTrans=[]
for setNo in range(len(self)):
grInhTransSet=[0]
centreSet=self[setNo]
## waterCoordSet=waterCoordAround[setNo]
## print waterCoordSet
## print 'there were :',len(waterCoordSet),'sets in waterCoordSet'
totalNo=len(centreSet)
referenceCentre=centreSet[0]
referenceCentreArray=numpy.array(referenceCentre)
for aroundNo in range(totalNo):
if aroundNo>=1:
aroundCentre=centreSet[aroundNo]
aroundCentreArray=numpy.array(aroundCentre)
distanceVector=referenceCentreArray-aroundCentreArray
distanceModulus=numpy.sqrt((distanceVector*distanceVector).sum())
## print distanceModulus
for line in rdfOO:
## print line
OOdistan=line[0]-distanceModulus
## print line[0]
if OOdistan<=0.015:
grAround=line[1]
## waterCoorNo=len(waterCoordSet[aroundNo])
#### print waterCoorNo
## print distanceModulus
## grAround=round(waterCoorNo/(constant1*((distanceModulus+1.2)**3-(distanceModulus-1.2)**3))/waterDensPerA2/frameNo,3)
print grAround
grAround=numpy.log(grAround)*grAround-grAround+1
grInhTransSet.append(grAround)
grInhTrans.append(grInhTransSet)
print grInhTrans
return grInhTrans
##?????????????????????????Problem in determinning the 0.025
##calculateGRInhTrans is used to calculate the G(r,r) translocation redical distribution function used fir WW translocation entropy
##the input of this function includes self: the output of 'findNearbyCentre' as self: including all the reference centre and centers
##around reference. Therefore, it is a set of centres looks like[[[highOccupiedCentre1],[aroundCentre2],[around
##centre2]],[...]...]. The other input is the water coordinates which includes all the coordinates saved according to the self(centres)
##the output of the fromat is [[G(r1,r1)=0,G(r1,r2),G(r1,r3)...],...].
def calculateGRConstant(self,rdfOO):
print rdfOO
waterDensPerA2=0.0331725
constant1=(4/3.0)*pi
grInhTrans=[]
for setNo in range(len(self)):
grInhTransSet=[0]
centreSet=self[setNo]
## waterCoordSet=waterCoordAround[setNo]
## print waterCoordSet
## print 'there were :',len(waterCoordSet),'sets in waterCoordSet'
totalNo=len(centreSet)
referenceCentre=centreSet[0]
referenceCentreArray=numpy.array(referenceCentre)
for aroundNo in range(totalNo):
if aroundNo>=1:
aroundCentre=centreSet[aroundNo]
aroundCentreArray=numpy.array(aroundCentre)
distanceVector=referenceCentreArray-aroundCentreArray
distanceModulus=numpy.sqrt((distanceVector*distanceVector).sum())
## print distanceModulus
for line in rdfOO:
## print line
OOdistan=line[0]-distanceModulus
## print line[0]
if OOdistan<=0.015:
grAround=line[1]
## waterCoorNo=len(waterCoordSet[aroundNo])
#### print waterCoorNo
## print distanceModulus
## grAround=round(waterCoorNo/(constant1*((distanceModulus+1.2)**3-(distanceModulus-1.2)**3))/waterDensPerA2/frameNo,3)
print grAround
## grAround=numpy.log(grAround)*grAround-grAround+1
grInhTransSet.append(grAround)
grInhTrans.append(grInhTransSet)
print grInhTrans
return grInhTrans
##?????????????????????????Problem in determinning the 0.025
##calculateGRInhTrans is used to calculate the G(r,r) translocation redical distribution function used fir WW translocation entropy
##the input of this function includes self: the output of 'findNearbyCentre' as self: including all the reference centre and centers
##around reference. Therefore, it is a set of centres looks like[[[highOccupiedCentre1],[aroundCentre2],[around
##centre2]],[...]...]. The other input is the water coordinates which includes all the coordinates saved according to the self(centres)
##the output of the fromat is [[G(r1,r1)=0,G(r1,r2),G(r1,r3)...],...].
def getH2OEulerTheta(self,frameNo):
referenceH1=numpy.array([0.79079641377315202, 0.61207926934631729, 0.0])
referenceH2=numpy.array([-0.79079641377315202, 0.61207926934631729, 0.0])
referenceZ=numpy.array([0.0,0.0,1.0])
eulerTheta=[]
## eulerThetaDensity=frameNo/20.0
CentreNo=0
for H2OCoordSet in self:
eulerThetaNo=range(10)
# frameNo=len(H2OCoordSet)
eulerThetaDensity=frameNo/10.0
CentreNo+=1
for no in range(len(eulerThetaNo)):
eulerThetaNo[no]=0
for H2OCoord in H2OCoordSet:
H1=numpy.array(H2OCoord[1])
H2=numpy.array(H2OCoord[2])
OT=numpy.array(H2OCoord[0])
H1=H1-OT
H2=H2-OT
ZH2O=numpy.cross(H1,H2)
ZH2OModulus=numpy.sqrt((ZH2O*ZH2O).sum())
dot1=numpy.dot(referenceZ,ZH2O)
cosAngleTheta=dot1/ZH2OModulus
angleTheta=numpy.arccos(cosAngleTheta)
## print angleTheta
for number in range(10):
nextNumber=number+1
if nextNumber*pi/10.0>angleTheta>=number*pi/10.0:
eulerThetaNo[number]+=1
elif angleTheta==pi:
eulerThetaNo[9]+=1
# print 'the euler Theta No is:',CentreNo, eulerThetaNo
for number in range(len(eulerThetaNo)):
nextNumber=number+1
eulerThetaNo[number]=(eulerThetaNo[number]/(cos(number*pi/10.0)-cos(nextNumber*pi/10.0)))/(frameNo/2.0)
eulerTheta.append(eulerThetaNo)
# print 'the euler Theta No is:',CentreNo,eulerThetaNo
return eulerTheta
##getH2OEulerTheta is used to calculate the Euler distrubution of all the waters.
##The water coordinates were saved as lists with both Oxygen, and Hydeogen atoms.
##The coordinates looks like[[[OxygenCoord],[Hydgrogen1 coordinate],[Hydrogen2 Coordinate]....]...]
##the output of the Euler angle is very similar with other functions. the distribution is
##divided into 20 intergration spaces. The output is [[g(0~*pi/20.0),g(pi/20.0~2*pi/20.0)...g(pi~19*pi/20.0)]......]
def getH2OEulerPhi(self,frameNo):
referenceH1=numpy.array([0.79079641377315202, 0.61207926934631729, 0.0])
referenceH2=numpy.array([-0.79079641377315202, 0.61207926934631729, 0.0])
referenceZ=numpy.array([0.0,0.0,1.0])
referenceY=numpy.array([0.0,1.0,0.0])
referenceX=numpy.array([1.0,0.0,0.0])
revReferenceY=numpy.array([0.0,-1.0,0.0])
eulerPhi=[]
## eulerPhiDensity=frameNo/20.0
CentreNo=0
for H2OCoordSet in self:
eulerPhiNo=range(10)
# frameNo=len(H2OCoordSet)
eulerPhiDensity=frameNo/10.0
CentreNo+=1
for no in range(len(eulerPhiNo)):
eulerPhiNo[no]=0
for H2OCoord in H2OCoordSet:
H1=numpy.array(H2OCoord[1])
H2=numpy.array(H2OCoord[2])
OT=numpy.array(H2OCoord[0])
H1=H1-OT
H2=H2-OT
ZH2O=numpy.cross(H1,H2)
ZH2OOnXY=numpy.copy(ZH2O)
ZH2OOnXY[2]=0.0
ZH2OOnXYModulus=numpy.sqrt((ZH2OOnXY*ZH2OOnXY).sum())
dot1=numpy.dot(revReferenceY,ZH2OOnXY)
cosAnglePhi=dot1/ZH2OOnXYModulus
anglePhi=numpy.arccos(cosAnglePhi)
if ZH2OOnXY[0]<0:
anglePhi=2*pi-anglePhi
for number in range(10):
nextNumber=number+1
if nextNumber*pi/5.0>anglePhi>=number*pi/5.0:
eulerPhiNo[number]+=1
elif anglePhi==2*pi:
eulerPhiNo[9]+=1
# print 'the euler phi No is:',CentreNo, eulerPhiNo
for number in range(len(eulerPhiNo)):
eulerPhiNo[number]=eulerPhiNo[number]/eulerPhiDensity
eulerPhi.append(eulerPhiNo)
# print 'the euler phi No is:',CentreNo, eulerPhiNo
return eulerPhi
##getH2OEulerPhi is used to calculate the Euler distrubution of all the waters.
##The water coordinates were saved as lists with both Oxygen, and Hydeogen atoms.
##The coordinates looks like[[[OxygenCoord],[Hydgrogen1 coordinate],[Hydrogen2 Coordinate]....]...]
##the output of the Euler angle is very similar with other functions. the distribution is
##divided into 20 intergration spaces. The output is [[g(0~*pi/20.0),g(pi/20.0~2*pi/20.0)...g(pi~19*pi/20.0)]......]
def getH2OEulerPsi(self,frameNo):
referenceH1=numpy.array([0.79079641377315202, 0.61207926934631729, 0.0])
referenceH2=numpy.array([-0.79079641377315202, 0.61207926934631729, 0.0])
referenceZ=numpy.array([0.0,0.0,1.0])
referenceY=numpy.array([0.0,1.0,0.0])
revReferenceY=numpy.array([0.0,-1.0,0.0])
eulerPsi=[]
## eulerPsiDensity=frameNo/20.0
CentreNo=0
for H2OCoordSet in self:
# frameNo=len(H2OCoordSet)
eulerPsiDensity=frameNo/10.0
eulerPsiNo=range(10)
CentreNo+=1
for no in range(len(eulerPsiNo)):
eulerPsiNo[no]=0
for H2OCoord in H2OCoordSet:
H1=numpy.array(H2OCoord[1])
H2=numpy.array(H2OCoord[2])
OT=numpy.array(H2OCoord[0])
H1=H1-OT
H2=H2-OT
YH2O=numpy.add(H1,H2)
ZH2O=numpy.cross(H1,H2)
XH2O=numpy.cross(YH2O,ZH2O)
ZH2OOnXY=numpy.copy(ZH2O)
ZH2OOnXY[2]=0.0
crossLine=numpy.cross(referenceZ,ZH2O)
XH2OModulus=numpy.sqrt((XH2O*XH2O).sum())
crossLineModulus=numpy.sqrt((crossLine*crossLine).sum())
## print crossLineModulus
dot1=numpy.dot(crossLine,XH2O)
cosAnglePsi=dot1/XH2OModulus/crossLineModulus
## print cosAnglePsi
anglePsi=numpy.arccos(cosAnglePsi)
## print anglePsi
if XH2O[2]<0:
anglePsi=2*pi-anglePsi
for number in range(10):
nextNumber=number+1
if nextNumber*pi/5.0>anglePsi>=number*pi/5.0:
eulerPsiNo[number]+=1
elif anglePsi==2*pi:
eulerPsiNo[9]+=1
# print 'the euler Psi No is:',CentreNo, eulerPsiNo
for number in range(len(eulerPsiNo)):
eulerPsiNo[number]=eulerPsiNo[number]/eulerPsiDensity
eulerPsi.append(eulerPsiNo)
# print 'the euler Psi No is:',CentreNo, eulerPsiNo
return eulerPsi
##getH2OEulerPsi is used to calculate the Euler distrubution of all the waters.
##The water coordinates were saved as lists with both Oxygen, and Hydeogen atoms.
##The coordinates looks like[[[OxygenCoord],[Hydgrogen1 coordinate],[Hydrogen2 Coordinate]....]...]
##the output of the Euler angle is very similar with other functions. the distribution is
##divided into 20 intergration spaces. The output is [[g(0~*pi/20.0),g(pi/20.0~2*pi/20.0)...g(pi~19*pi/20.0)]......]
def getH2OCoordForWW(self):
H2OCoordForWW=[]
for H2OInforCenAndAround in self:
H2OCoordCentre=getH2OCoord(H2OInforCenAndAround)
H2OCoordForWW.append(H2OCoordCentre)
return H2OCoordForWW
##self is all the H2OinforForWW. therefore, I use the function getH2OCoord to extract all the H2O coordidates. the output of the
##function looks like the output of 'H2OInforNearbyHighCentre' the output:[[[highOccupiedH2OCoord],[aroundH2OCoord2],[around
##H2OCoord2]],[...]...]. Moreover, the output centre is consistant with centre of findNearByCentre output.
def calculateEulerThetaReachCentre(self,nearbyCentre,frameNo):
eulerThetaEacCentreAndAround=[]
for eachH2ONo in range(len(self)):
eachCentre=nearbyCentre[eachH2ONo]
eachH2O=self[eachH2ONo]
eacheulerTheta=getH2OEulerTheta(eachH2O,frameNo)
eulerThetaEacCentreAndAround.append(eacheulerTheta)
return eulerThetaEacCentreAndAround
##calculateEulerThetaReachCentre is used to calculate the gEulerTheta of for all the centre H2O and the arounded H2Os.
##The input included self: H2O coordinates which is saved as list of H2O and arounded H2O. This can be the
##output of function 'getH2OCoordForWW'. nearbycentre is all the centres for the calculation. The centre
##information should be consistant with the self(H2OCoordinate). Morover, it can read the output of function
##'findNearbyCentre'. The output of this function looks like[[[centreGEularTheta],[aroundH2O GEularTheta]...]......]
def calculateEulerPhiReachCentre(self,nearbyCentre,frameNo):
eulerPhiEacCentreAndAround=[]
for eachH2ONo in range(len(self)):
eachCentre=nearbyCentre[eachH2ONo]
eachH2O=self[eachH2ONo]
eacheulerPhi=getH2OEulerPhi(eachH2O,frameNo)
eulerPhiEacCentreAndAround.append(eacheulerPhi)
return eulerPhiEacCentreAndAround
##calculateEulerPhiReachCentre is used to calculate the gEulerPhi of for all the centre H2O and the arounded H2Os.
##The input included self: H2O coordinates which is saved as list of H2O and arounded H2O. This can be the
##output of function 'getH2OCoordForWW'. nearbycentre is all the centres for the calculation. The centre
##information should be consistant with the self(H2OCoordinate). Morover, it can read the output of function
##'findNearbyCentre'. The output of this function looks like[[[centreGEularPhi],[aroundH2O GEularPhi]...]......]
def calculateEulerPsiReachCentre(self,nearbyCentre,frameNo):
eulerPsiEacCentreAndAround=[]
for eachH2ONo in range(len(self)):
eachCentre=nearbyCentre[eachH2ONo]
eachH2O=self[eachH2ONo]
eacheulerPsi=getH2OEulerPsi(eachH2O,frameNo)
eulerPsiEacCentreAndAround.append(eacheulerPsi)
return eulerPsiEacCentreAndAround
##calculateEulerPsiReachCentre is used to calculate the gEulerTheta of for all the centre H2O and the arounded H2Os.
##The input included self: H2O coordinates which is saved as list of H2O and arounded H2O. This can be the
##output of function 'getH2OCoordForWW'. nearbycentre is all the centres for the calculation. The centre
##information should be consistant with the self(H2OCoordinate). Morover, it can read the output of function
##'findNearbyCentre'. The output of this function looks like[[[centreGEularPsi],[aroundH2O GEularPsi]...]......]
def intgGr(self):
sumGr=0
for eachGrNo in range(len(self)):
eachGr=self[eachGrNo]
nextNo=eachGrNo+1
eachGr=eachGr*(((nextNo*0.05)**3)-((eachGrNo*0.05)**3))/3.0
sumGr+=eachGr
## print sumGr
return sumGr
##intgGr is used to do the integration of GR according to the integral of 0.05. The input is a list a GR
##along the distance R. The output of this function is sum(gr*dr)
def intgGtheta(self):
sumGtheta=0
for gthetaNo in range(len(self)):
eachGtheta=self[gthetaNo]
angle1=gthetaNo*pi/20.0
angle2=(gthetaNo+1)*pi/20.0
eachGtheta=eachGtheta*(cos(angle1)-cos(angle2))
sumGtheta+=eachGtheta
return sumGtheta
##intgGtheta is used to do the integration of Gtheta according to the integral of pi/20.0. The input is a list a Gtheta
##along each angle. The output of this function is sum(gtheta*sinTheta*dTheta).
def intgGangle(self):
sumGangle=0
for eachGangle in self:
eachGangle=eachGangle*pi/20.0
sumGangle+=eachGangle
return sumGangle
##intgGangle is used to do the integration of Gangle according to the integral of pi/20.0. The input is a list a Gangle
##along each angle. The output of this function is sum(gangle*dangle)
def getWforWW(self,nearbyCentre,waterCoordAroundCentre,frameNo):
WforWW=[] #single terms for WW entropy calculation
## for centreSetNo in range(len(self)):
## grOOSet=self[centreSetNo]
## OcoordSet=waterCoordAroundCentre[centreSetNo]
## H2OCoordSet=H2OCoordForWW[centreSetNo]
gr=calculateGReachCentre(waterCoordAroundCentre,nearbyCentre,frameNo)
grtheta=calculateGThetaeachCentre(waterCoordAroundCentre,nearbyCentre,frameNo)
grphi=calculateGPhieachCentre(waterCoordAroundCentre,nearbyCentre,frameNo)
## gEtheta=calculateEulerThetaReachCentre(H2OCoordForWW,nearbyCentre,frameNo)
## gEphi=calculateEulerPhiReachCentre(H2OCoordForWW,nearbyCentre,frameNo)
## gEpsi=calculateEulerPsiReachCentre(H2OCoordForWW,nearbyCentre,frameNo)
for centreSetNo in range(len(self)):
WforWWEachCentreAndAround=[]
gRconstantSet=self[centreSetNo]
grSet=gr[centreSetNo]
grthetaSet=grtheta[centreSetNo]
grphiSet=grphi[centreSetNo]
## gEthetaSet=gEtheta[centreSetNo]
## gEphiSet=gEphi[centreSetNo]
## gEpsiSet=gEpsi[centreSetNo]