2
! Copyright (C) 1996-2016 The SIESTA group
3
! This file is distributed under the terms of the
4
! GNU General Public License: see COPYING in the top directory
5
! or http://www.gnu.org/copyleft/gpl.txt.
6
! See Docs/Contributors.txt for a list of contributors.
10
use precision, only : dp
11
use parallel, only : Node, Nodes
12
use parallelsubs, only : GlobalToLocalOrb
13
use atmfuncs, only : rcut, orb_gindex
14
use neighbour, only : jna=>jan, r2ij, xij, mneighb,
15
& reset_neighbour_arrays
16
use alloc, only : re_alloc, de_alloc
17
use m_new_matel, only : new_matel
18
use m_iodm_old, only : write_dm
19
use m_matio, only : write_mat
20
use atomlist, only: no_l
30
subroutine rmatrix(nua, na, no, scell, xa, indxua, rmaxo,
31
& maxnh, lasto, iphorb, isa,
32
& numh, listhptr, listh, Rmat)
33
C *********************************************************************
34
C Computes the "R" matrix < phi_1 | R | phi_2>
35
C Energies in Ry. Lengths in Bohr.
37
C **************************** INPUT **********************************
38
C integer nua : Number of atoms in unit cell
39
C integer na : Number of atoms in supercell
40
C integer no : Number of orbitals in supercell
41
C real*8 scell(3,3) : Supercell vectors SCELL(IXYZ,IVECT)
42
C real*8 xa(3,na) : Atomic positions in cartesian coordinates
43
c integer indxua(na) : Index of equivalent atom in unit cell
44
C real*8 rmaxo : Maximum cutoff for atomic orbitals
45
C integer maxnh : First dimension of S and listh
46
C integer lasto(0:na) : Last orbital index of each atom
47
C integer iphorb(no) : Orbital index of each orbital in its atom
48
C integer isa(na) : Species index of each atom
49
C integer numh(nuotot) : Number of nonzero elements of each row
50
C of the overlap matrix
51
C integer listhptr(nuotot) : Pointer to start of rows (-1) of overlap
53
C integer listh(maxnh) : Column indexes of the nonzero elements
54
C of each row of the overlap matrix
55
C **************************** OUTPUT *********************************
56
C real*8 Rmat(maxnh,3) : Matrix elements of "R"
58
integer, intent(in) :: maxnh, na, no, nua
59
integer, intent(in) :: indxua(na), iphorb(no), isa(na),
60
& lasto(0:na), listh(maxnh), numh(*),
62
real(dp) , intent(in) :: scell(3,3), rmaxo, xa(3,na)
63
real(dp), intent(out) :: Rmat(maxnh,3)
64
C Internal variables ......................................................
65
integer :: ia, ind, io, ioa, is, iio, j, ja, jn,
66
& jo, joa, js, jua, nnia, ig, jg
67
real(dp) :: grSij(3) , rij, Sij
68
real(dp), pointer :: Ri(:,:)
72
call timer( 'rmatrix', 1 )
74
C Initialize neighb subroutine
75
call mneighb( scell, 2.d0*rmaxo, na, xa, 0, 0, nnia )
77
C Allocate local memory
79
call re_alloc( Ri, 1, no, 1, 3, 'Ri', 'rmatrix' )
83
call mneighb( scell, 2.d0*rmaxo, na, xa, ia, 0, nnia )
84
do io = lasto(ia-1)+1,lasto(ia)
86
C Is this orbital on this Node?
87
call GlobalToLocalOrb(io,Node,Nodes,iio)
92
ig = orb_gindex(is,ioa)
96
rij = sqrt( r2ij(jn) )
97
do jo = lasto(ja-1)+1,lasto(ja)
101
! Use global indexes for new version of matel
103
jg = orb_gindex(js,joa)
104
if (rcut(is,ioa)+rcut(js,joa) .gt. rij) then
105
call new_MATEL( 'X', ig, jg, xij(1:3,jn),
107
Ri(1,jo) = Ri(1,jo) + Sij
108
call new_MATEL( 'Y', ig, jg, xij(1:3,jn),
110
Ri(2,jo) = Ri(2,jo) + Sij
111
call new_MATEL( 'Z', ig, jg, xij(1:3,jn),
113
Ri(3,jo) = Ri(3,jo) + Sij
118
ind = listhptr(iio)+j
120
Rmat(ind,:) = Ri(jo,:)
127
C Deallocate local memory
128
call reset_neighbour_arrays( )
129
call de_alloc( Ri, 'Ri', 'rmatrix' )
132
call timer( 'rmatrix', 2 )
133
end subroutine rmatrix