Skip to content

gemdat.rdf

RDFData(x, y, symbol, state) dataclass

Data class for storing radial distribution data.

Parameters:

  • x (ndarray) –

    1D array with x data (bins)

  • y (ndarray) –

    1D array with y data (counts)

  • symbol (str) –

    Distance to species with this symbol

  • state (str) –

    State that the floating species is in, e.g. the jump that it is making.

radial_distribution(*, transitions, floating_specie, max_dist=5.0, resolution=0.1)

Calculate and sum RDFs for the floating species in the given sites data.

Parameters:

  • transitions (Transitions) –

    Input transitions data

  • floating_specie (str) –

    Name of the floating specie

  • max_dist (float, default: 5.0 ) –

    Max distance for rdf calculation

  • resolution (float, default: 0.1 ) –

    Width of the bins

Returns:

  • rdfs ( dict[str, ndarray] ) –

    Dictionary with rdf arrays per symbol

Source code in src/gemdat/rdf.py
 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
def radial_distribution(
    *,
    transitions: Transitions,
    floating_specie: str,
    max_dist: float = 5.0,
    resolution: float = 0.1,
) -> dict[str, list[RDFData]]:
    """Calculate and sum RDFs for the floating species in the given sites data.

    Parameters
    ----------
    transitions: Transitions
        Input transitions data
    floating_specie : str
        Name of the floating specie
    max_dist : float, optional
        Max distance for rdf calculation
    resolution : float, optional
        Width of the bins

    Returns
    -------
    rdfs : dict[str, np.ndarray]
        Dictionary with rdf arrays per symbol
    """
    # note: needs trajectory with ALL species
    trajectory = transitions.trajectory
    sites = transitions.sites
    base_structure = trajectory.get_structure(0)
    lattice = trajectory.get_lattice()

    coords = trajectory.positions
    sp_coords = trajectory.filter(floating_specie).positions

    states2str = _get_states(sites.labels)
    states_array = _get_states_array(transitions, sites.labels)
    symbol_indices = _get_symbol_indices(base_structure)

    bins = np.arange(0, max_dist + resolution, resolution)
    length = len(bins) + 1

    rdfs: dict[tuple[str, str],
               np.ndarray] = defaultdict(lambda: np.zeros(length, dtype=int))

    n_steps = len(trajectory)

    for i in track(range(n_steps), transient=True):

        t_coords = coords[i]
        t_sp_coords = sp_coords[i]

        dists = lattice.get_all_distances(t_sp_coords, t_coords)

        rdf = np.digitize(dists, bins, right=True)

        states = np.unique(states_array[i], axis=0)

        t_states = states_array[i]

        for state in states:
            k_idx = np.argwhere(t_states == state)
            state_str = states2str[state]

            for symbol, symbol_idx in symbol_indices.items():
                rdf_state = rdf[k_idx, symbol_idx].flatten()
                rdfs[state_str, symbol] += np.bincount(rdf_state,
                                                       minlength=length)

    ret: dict[str, list[RDFData]] = {}

    for (state, symbol), values in rdfs.items():
        rdf_data = RDFData(
            x=bins,
            # Drop last element with distance > max_dist
            y=values[:-1],
            symbol=symbol,
            state=state,
        )
        ret.setdefault(state, [])
        ret[state].append(rdf_data)

    return ret