Find the competing nearest images of an interatomic vector.
Counts the images within the switching interval of the nearest image,
excluding the atom itself, in nimg and returns the minimum squared
distance in min_r2. If list is empty, the images are only counted.
Otherwise, list must hold all images (size(list) >= nimg) and receives
their translation indices sorted by distance. A list of size(trans, 2)
is always sufficient.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | trans(:,:) |
Translation vectors |
||
| real(kind=wp), | intent(in) | :: | rij(3) |
Interatomic vector |
||
| integer, | intent(out) | :: | nimg |
Number of images within the switching interval |
||
| integer, | intent(inout) | :: | list(:) |
Indices of the nearest translation images |
||
| real(kind=wp), | intent(out) | :: | min_r2 |
Minimum squared distance found |
pure subroutine find_wsc_pairs(trans, rij, nimg, list, min_r2) !> Translation vectors real(wp), intent(in) :: trans(:, :) !> Interatomic vector real(wp), intent(in) :: rij(3) !> Number of images within the switching interval integer, intent(out) :: nimg !> Indices of the nearest translation images integer, intent(inout) :: list(:) !> Minimum squared distance found real(wp), intent(out) :: min_r2 integer :: itr, pos, nkept real(wp) :: r2 nimg = 0 min_r2 = huge(1.0_wp) ! First pass, distance to the nearest image other than the atom itself do itr = 1, size(trans, 2) r2 = sum((rij - trans(:, itr))**2) if (r2 < thr) cycle if (r2 < min_r2) min_r2 = r2 end do ! Second pass, collect all images within the interval, sorted by insertion nkept = 0 do itr = 1, size(trans, 2) r2 = sum((rij - trans(:, itr))**2) if (r2 < thr .or. r2 - min_r2 > tol) cycle nimg = nimg + 1 pos = nkept + 1 do while (pos > 1) if (sum((rij - trans(:, list(pos - 1)))**2) <= r2) exit if (pos <= size(list)) list(pos) = list(pos - 1) pos = pos - 1 end do if (pos <= size(list)) then list(pos) = itr nkept = min(nkept + 1, size(list)) end if end do end subroutine find_wsc_pairs