Common neighbour analysis (CNA)
This module contains functions to perform the common neighbour analysis and assign CNA patterns (CNAp)
snow.descriptors.cna
longest_path_or_cycle(neigh_common, neigh_list)
Find the longest path or cycle in the subgraph induced by a subset of nodes.
Builds a subgraph from neigh_common using adjacency information from neigh_list, then runs a depth-first search (DFS) from each node to find the longest path or cycle in the subgraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
neigh_common
|
iterable
|
Subset of nodes to consider (e.g. common neighbors of two atoms). |
required |
neigh_list
|
dict
|
Full adjacency list of the graph, mapping each node to its neighbors. Only edges between nodes in neigh_common are considered. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
longest_chain |
int
|
Length of the longest path or cycle found in the subgraph. |
Source code in snow/descriptors/cna.py
calculate_cna(coords, cut_off, return_pairs=False, pbc=False, box=None)
perform the common neighbour analysis for the provided coords.
Automatically finds pairs and assigns a cna signature to each pair. The pairs can
be returned as tuples of indexes of the coordinates if return_pair=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
ndarray
|
array containing the coordainates of each atom |
required |
cut_off
|
float
|
cutoff radius for the determination of nearest neighbours. If None, an adaptive cutoff is computed |
required |
return_pairs
|
bool
|
Wether to return an ordered list of the indices of the atoms forming each pair, by default False |
False
|
pbc
|
bool
|
whether to use periodic boundary conditions or not. |
False
|
box
|
ndarray
|
if pbc are enabled, the simulation box is needed to compute periodic neighbours. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
npairs |
int
|
number of pairs found |
signatures |
ndarray
|
cna signatures (r,s,t) for each found pair in a (n_pairs, 3) array |
pairs |
list
|
the indexes of atoms in pairs corresponding to the computed cna signatures. Only returned if |
Source code in snow/descriptors/cna.py
calculate_cna_fast(coords, cut_off, return_pairs=False, pbc=False, box=None, display_progress=False)
Faster version of calculate_cna that precomputes neighbor sets.
performs common neighbour analysis with a faster algorithm, useful for N>1e5 atoms. This method avoids scanning the entire pair list for every atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
ndarray
|
array containing the coordinates of atoms in the system |
required |
cut_off
|
float
|
cutoff radius for the determination of nearest neighbors. If None, an adaptive cutoff is computed |
required |
return_pair
|
bool
|
Whether to return an ordered list of the indices of the atoms forming a given pair, by default False |
False
|
pbc
|
bool
|
whether to use periodic boundary conditions or not. |
False
|
box
|
ndarray
|
if pbc are enabled, the simulation box is needed to compute periodic neighbours. |
None
|
display_progress
|
Wheter to display a progress bar - needs the tqdm library |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple
|
|
|
npairs |
int
|
number of pairs found |
signatures |
ndarray
|
cna signatures (r,s,t) for each found pair in a (n_pairs, 3) array |
pairs |
list
|
the indexes of atoms in pairs corresponding to the computed cna signatures. Only returned if |
Source code in snow/descriptors/cna.py
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 | |
cna_peratom(coords, cut_off, pbc=False, box=None)
Optimized per-atom CNA calculation.
Computes the cna signatures for all pairs in the system, and assign to each atom the list of signatures it participates to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
ndarray
|
Array containing the coordinates of the atoms in your system. |
required |
cut_off
|
float
|
Cutoff radius for nearest-neighbor determination. If None, an adaptive cutoff is computed |
required |
pbc
|
bool
|
Whether to use or not periodic boundary conditions |
False
|
box
|
ndarray
|
Simulation box. Only needed if you enable PBC |
None
|
Returns:
| Type | Description |
|---|---|
list of tuple[np.ndarray, np.ndarray]
|
For each atom, a tuple (unique_signatures, counts) representing the unique CNA signatures from all pairs involving that atom and their respective counts. |
Source code in snow/descriptors/cna.py
cnap_peratom(coords, cut_off, pbc=False, box=None, display_progress=False)
Computes the per-atom CNA patterns and assigns an integer structure ID.
Tries to match the cna per atom patterns to known patterns in a database for atomic environment characterization (see README.md for ID-structure mapping).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
ndarray
|
(N, 3) array with atomic coordinates |
required |
cut_off
|
float
|
Cutoff radius for neighbor determination. If None, an adaptive cutoff is used |
required |
pbc
|
bool
|
Whether to use or not periodic boundary conditions |
False
|
box
|
ndarray
|
Simulation box. Only needed if you enable PBC |
None
|
display_progress
|
bool
|
Wheter to display a progress bar - needs the tqdm optional dependency library. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
pattenrs_ids |
ndarray
|
Array of (integers) structure IDs per atom |
Source code in snow/descriptors/cna.py
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 | |
write_cna(frame, len_pair, cna, pair_list, file_path='./', signature=True, cna_unique=True)
export cna analysis to files in .csv format
save to file the indexes of atoms making up a pair and their signature (if signature=True).
save to file the unique cna signatures, and their occurrence wrt to the total number as a percentage
Note that if frame==0, previous files named 'signatures.csv' and 'cna_unique.csv' will be flushed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
int
|
config frame id, mostly for reference (and written to file) |
required |
len_pair
|
int
|
number of pairs in the system |
required |
cna
|
ndarray
|
array of the (previously computed) cna signatures |
required |
pair_list
|
list of lists of atomic indexes, to label atoms making up pairs |
required | |
file_path
|
str
|
folder to write output files in |
'./'
|
signature
|
write cna signatures together with corresponding pair indexes in a signatures.csv file |
True
|
|
cna_unique
|
bool
|
write unique cna signatures and their occurrence (as a percentage) in a cna_unique.csv file |
True
|