@@ -21,6 +21,15 @@ def rdf(sys,
21
21
Maximal range of rdf calculation
22
22
nbins: int
23
23
Number of bins for rdf calculation
24
+
25
+ Returns
26
+ -------
27
+ xx: np.array
28
+ The lattice of r
29
+ rdf: np.array
30
+ The value of rdf at r
31
+ coord: np.array
32
+ The coordination number up to r
24
33
"""
25
34
return compute_rdf (sys ['cells' ], sys ['coords' ], sys ['atom_types' ],
26
35
sel_type = sel_type ,
@@ -36,12 +45,16 @@ def compute_rdf(box,
36
45
nframes = box .shape [0 ]
37
46
xx = None
38
47
all_rdf = []
48
+ all_cod = []
39
49
for ii in range (nframes ):
40
- xx , rdf = _compute_rdf_1frame (box [ii ], posis [ii ], atype , sel_type , max_r , nbins )
50
+ xx , rdf , cod = _compute_rdf_1frame (box [ii ], posis [ii ], atype , sel_type , max_r , nbins )
41
51
all_rdf .append (rdf )
52
+ all_cod .append (cod )
42
53
all_rdf = np .array (all_rdf ).reshape ([nframes , - 1 ])
54
+ all_cod = np .array (all_cod ).reshape ([nframes , - 1 ])
43
55
all_rdf = np .average (all_rdf , axis = 0 )
44
- return xx , all_rdf
56
+ all_cod = np .average (all_cod , axis = 0 )
57
+ return xx , all_rdf , all_cod
45
58
46
59
def _compute_rdf_1frame (box ,
47
60
posis ,
@@ -65,6 +78,7 @@ def _compute_rdf_1frame(box,
65
78
nlist = ase .neighborlist .NeighborList (max_r , self_interaction = False , bothways = True , primitive = ase .neighborlist .NewPrimitiveNeighborList )
66
79
nlist .update (atoms )
67
80
stat = np .zeros (nbins )
81
+ stat_acc = np .zeros (nbins )
68
82
hh = max_r / float (nbins )
69
83
for ii in range (natoms ) :
70
84
# atom "0"
@@ -90,13 +104,17 @@ def _compute_rdf_1frame(box,
90
104
for ii in sel_type [1 ]:
91
105
c1 += np .sum (atype == ii )
92
106
rho1 = c1 / np .linalg .det (box )
107
+ # compute coordination number
108
+ for ii in range (1 , nbins ):
109
+ stat_acc [ii ] = stat_acc [ii - 1 ] + stat [ii - 1 ]
110
+ stat_acc = stat_acc / c0
93
111
# compute rdf
94
112
for ii in range (nbins ):
95
113
vol = 4. / 3. * np .pi * ( ((ii + 1 )* hh ) ** 3 - ((ii )* hh ) ** 3 )
96
114
rho = stat [ii ] / vol
97
115
stat [ii ] = rho / rho1 / c0
98
116
xx = np .arange (0 , max_r - 1e-12 , hh )
99
- return xx , stat
117
+ return xx , stat , stat_acc
100
118
101
119
if __name__ == '__main__' :
102
120
import dpdata
0 commit comments