kliff.neighbor#
- class kliff.neighbor.NeighborList(conf, infl_dist, padding_need_neigh=False)[source]#
Neighbor list class.
This uses the same approach that LAMMPS and KIM adopt: The atoms in the configuration (assuming a total of N atoms) are named contributing atoms, and padding atoms are created to satisfy the boundary conditions. The contributing atoms are numbered as 1, 2, … N-1, and the padding atoms are numbered as N, N+1, N+2… Neighbors of atom can include both contributing atoms and padding atoms.
- Parameters
conf (
Configuration
) – atomic configuration.infl_dist (
float
) – Influence distance, within which atoms are interacting with each other. In literatures, this is usually referred ascutoff
.padding_need_neigh (
bool
) – Whether to generate neighbors for padding atoms.
- coords#
2D array Coordinates of contributing and padding atoms.
- species#
list Species string of contributing and padding atoms.
- image#
1D array Atom index, of which an atom is an image. The image of a contributing atom is itself.
- padding_coords#
2D array Coordinates of padding atoms.
- padding_species#
list Species string and padding atoms.
- padding_image#
1D array Atom index, of which a padding atom is an image.
Note
To get the total force on a contributing atom, the forces on all padding atoms that are images of the contributing atom should be added back to the contributing atom.
- get_neigh(index)[source]#
Get the indices, coordinates, and species string of a given atom.
- Parameters
index (
int
) – Atom number whose neighbor info is requested.- Returns
Indices of neighbor atoms in self.coords and self.species. neigh_coords: 2D array of shape (N, 3), where N is the number of neighbors.
Coordinates of neighbor atoms.
neigh_species: Species symbol of neighbor atoms.
- Return type
neigh_indices
- get_numneigh_and_neighlist_1D(request_padding=False)[source]#
Get the number of neighbors and neighbor list for all atoms.
- Parameters
request_padding (
bool
) – IfTrue
, the returned number of neighbors and neighbor list include those for padding atoms; IfFalse
, only return these for contributing atoms.- Returns
1D array; number of neighbors for all atoms. neighlist: 1D array; indices of the neighbors for all atoms stacked into a
1D array. Its total length is
sum(numneigh)
, and the firstnumneigh[0]
components are the neighbors of atom 0, the nextnumneigh[1]
components are the neighbors of atom 1 ….- Return type
numneigh
- get_coords()[source]#
Return coords of both contributing and padding atoms. Shape (N,3).
- Return type
array
- get_species_code(mapping)[source]#
Integer species code of both contributing and padding atoms.
- Parameters
mapping (
Dict
[str
,int
]) – A mapping between species string and its code.- Return type
array
- Returns
1D array of integer species code.
- get_image()[source]#
Return image of both contributing and padding atoms.
It is a 1D array of atom index, of which an atom is an image.
Note
The image of a contributing atom is itself.
- Return type
array
- get_padding_coords()[source]#
Return coords of padding atoms, 2D array of shape (N,3), where N is the number of padding atoms.
- Return type
array
- kliff.neighbor.assemble_forces(forces, n, padding_image)[source]#
Assemble forces on padding atoms back to contributing atoms.
- Parameters
forces (
array
) – Partial forces on both contributing and padding atoms. 2D array of shape (Nc+Np, 3). where Nc is the number of contributing atoms, and Np is the number of padding atoms. The first Nc rows are the forces for contributing atoms.n (
int
) – Number of contributing atoms, i.e. Nc.padding_image (
array
) – atom index, of which the padding atom is an image. 1D int array of shape (Np,).
- Return type
array
- Returns
Total forces on contributing atoms. 2D array of shape (Nc, 3), where Nc is the number of contributing atoms.
- kliff.neighbor.assemble_stress(coords, forces, volume)[source]#
Calculate the virial stress using the negative f dot r method.
- Parameters
coords (
array
) – Coordinates of both contributing and padding atoms. 2D array of shape (Nc+Np, 3), where Nc is the number of contributing atoms, and Np is the number of padding atoms. The first Nc rows are the coords of contributing atoms.forces (
array
) – Partial forces on both contributing and padding atoms. 2D array of shape (Nc+Np, 3), where Nc is the number of contributing atoms, and Np is the number of padding atoms. The first Nc rows are the forces on contributing atoms.volume (
float
) – Volume of the configuration.
- Return type
array
- Returns
Virial stress in Voigt notation. 1D array of shape (6,).