Create adjacency matrix from connectivity lists.
Array i12 and n12 contain the connectivity list in the following
format: i12(0:n(j),j) contains the index of all the atoms connected
to atom with index j.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=ip), | intent(inout) | :: | i12(:,:) |
Indices of connected atoms for each atom in the molecule |
||
type(yale_sparse), | intent(out) | :: | sparse |
Adjacency matrix in Yale format () |
subroutine adj_mat_from_conn(i12, sparse)
!! Create adjacency matrix \(\mathbb C_1\) from connectivity lists.
!! Array i12 and n12 contain the connectivity list in the following
!! format: i12(0:n(j),j) contains the index of all the atoms connected
!! to atom with index j.
use mod_utils, only: sort_ivec_inplace
use mod_memory, only: mallocate, mfree
implicit none
integer(ip), intent(inout) :: i12(:,:)
!! Indices of connected atoms for each atom in the molecule
type(yale_sparse), intent(out) :: sparse
!! Adjacency matrix in Yale format (\(\mathbb C_1\))
integer(ip) :: i, j, n, m
integer(ip), allocatable :: nnz(:)
n = size(i12, 2)
m = size(i12, 1)
call mallocate('adj_mat_from_conn [nnz]', n, nnz)
!$omp parallel do default(shared) &
!$omp private(j,i)
do i=1, n
! Count the number of non-zero elements and move them to the left
nnz(i) = 0
do j=1, m
if(i12(j,i) /= 0) then
nnz(i) = nnz(i) + 1
i12(nnz(i),i) = i12(j,i)
end if
end do
call sort_ivec_inplace(i12(1:nnz(i),i))
end do
call compress_list(n, i12, nnz, sparse)
call mfree('adj_mat_from_conn [nnz]', nnz)
end subroutine adj_mat_from_conn