22 integer,
parameter ::
dp = kind(1.0d0)
35 subroutine prg_get_charges(rho_bml,over_bml,hindex,charges,numel,spindex,mdimin,threshold)
36 character(20) :: bml_type, bml_mode
37 integer :: i, j, nats, norb, nsp
39 integer,
intent(in) :: hindex(:,:), mdimin, spindex(:)
40 real(
dp) :: znuc, this_charge, this_diag
41 real(
dp),
allocatable :: rho_diag(:)
42 real(
dp),
allocatable,
intent(inout) :: charges(:)
43 real(
dp),
intent(in) :: numel(:), threshold
45 real(c_double),
pointer :: rho_bml_ptr(:,:), over_bml_ptr(:,:)
46 type(c_ptr) :: rho_bml_c_ptr, over_bml_c_ptr
48 type(bml_matrix_t) :: aux_bml
49 type(bml_matrix_t),
intent(inout) :: over_bml, rho_bml
51 norb = bml_get_n(rho_bml)
52 bml_type = bml_get_type(rho_bml)
53 bml_mode = bml_get_distribution_mode(rho_bml)
54 nats =
size(hindex,dim=2)
63 if(.not.
allocated(charges))
allocate(charges(nats))
65 if(.not.
allocated(rho_diag))
allocate(rho_diag(norb))
68 rho_bml_c_ptr = bml_get_data_ptr_dense(rho_bml)
69 over_bml_c_ptr = bml_get_data_ptr_dense(over_bml)
70 ld = bml_get_ld_dense(rho_bml)
71 call c_f_pointer(rho_bml_c_ptr,rho_bml_ptr,shape=[ld,norb])
72 call c_f_pointer(over_bml_c_ptr,over_bml_ptr,shape=[ld,norb])
84 this_diag = this_diag + over_bml_ptr(i,j)*rho_bml_ptr(j,i)
87 rho_diag(i) = this_diag
95 this_charge = -numel(spindex(i))
97 do j = hindex(1,i),hindex(2,i)
98 this_charge = this_charge + rho_diag(j)
101 charges(i) = this_charge
107 call bml_zero_matrix(bml_type,bml_element_real,
dp,norb,mdim,aux_bml, &
110 call bml_multiply(rho_bml,over_bml,aux_bml,1.0_dp,0.0_dp,threshold)
114 bml_get_distribution_mode(aux_bml) == bml_dmode_distributed)
then
119 call bml_get_diagonal(aux_bml,rho_diag)
124 znuc = numel(spindex(i))
126 do j = hindex(1,i),hindex(2,i)
127 charges(i) = charges(i) + rho_diag(j)
129 charges(i) = charges(i) - znuc
132 call bml_deallocate(aux_bml)
151 subroutine prg_get_hscf(ham0_bml,over_bml,ham_bml,spindex,hindex,hubbardu,charges,&
152 coulomb_pot_r,coulomb_pot_k,mdimin,threshold)
153 character(20) :: bml_type
154 integer :: i, j, nats, norb, mdim
155 integer,
intent(in) :: hindex(:,:), mdimin, spindex(:)
156 real(
dp),
allocatable :: coulomb_pot(:), diagonal(:)
157 real(
dp),
intent(in) :: charges(:), coulomb_pot_k(:), coulomb_pot_r(:), hubbardu(:)
158 real(
dp),
intent(in) :: threshold
159 type(bml_matrix_t),
save :: aux_bml
160 type(bml_matrix_t),
intent(in) :: ham0_bml, over_bml
161 type(bml_matrix_t),
intent(inout) :: ham_bml
162 integer,
save :: maxnorb = 0
164 type(c_ptr) :: aux_bml_c_ptr
166 real(c_double),
pointer :: aux_bml_ptr(:,:)
169 nats =
size(coulomb_pot_r)
171 norb = bml_get_n(ham0_bml)
172 if(hindex(2,nats) .ne. norb)
then
173 write(*,*)
"ERROR in prg_get_hscf. hindex incompatible with ham0"
177 if(mdimin.lt.0.or.mdimin.gt.norb)
then
183 bml_type = bml_get_type(ham0_bml)
190 if(bml_allocated(ham_bml))
then
191 if(norb.ne.bml_get_n(ham_bml))
then
192 call bml_deallocate(ham_bml)
193 call bml_copy_new(ham0_bml,ham_bml)
195 call bml_copy(ham0_bml,ham_bml)
198 call bml_copy_new(ham0_bml,ham_bml)
204 if(.not.bml_allocated(aux_bml))
then
205 call bml_zero_matrix(bml_type,bml_element_real,
dp,norb,mdim,aux_bml)
206 elseif(norb.gt.maxnorb)
then
207 call bml_deallocate(aux_bml)
208 call bml_zero_matrix(bml_type,bml_element_real,
dp,norb,mdim,aux_bml)
211 call bml_set_n_dense(aux_bml,norb)
214 aux_bml_c_ptr = bml_get_data_ptr_dense(aux_bml)
215 ld = bml_get_ld_dense(aux_bml)
217 call c_f_pointer(aux_bml_c_ptr,aux_bml_ptr,shape=[ld,norb])
226 aux_bml_ptr(i,j) = 0.0_dp
234 do j = hindex(1,i),hindex(2,i)
235 aux_bml_ptr(j,j) = hubbardu(spindex(i))*charges(i) &
236 + coulomb_pot_r(i) + coulomb_pot_k(i)
242 call bml_multiply(over_bml,aux_bml,ham_bml,0.5_dp,1.0_dp,threshold)
244 call bml_multiply(aux_bml,over_bml,ham_bml,0.5_dp,1.0_dp,threshold)
247 call bml_zero_matrix(bml_type,bml_element_real,
dp,norb,mdim,aux_bml)
249 allocate(coulomb_pot(nats))
251 coulomb_pot = coulomb_pot_k + coulomb_pot_r
253 allocate(diagonal(norb))
256 do j = hindex(1,i),hindex(2,i)
257 diagonal(j) = hubbardu(spindex(i))*charges(i) + coulomb_pot(i)
261 call bml_set_diagonal(aux_bml,diagonal)
264 deallocate(coulomb_pot)
266 call bml_multiply(over_bml,aux_bml,ham_bml,0.5_dp,1.0_dp,threshold)
268 call bml_multiply(aux_bml,over_bml,ham_bml,0.5_dp,1.0_dp,threshold)
270 call bml_deallocate(aux_bml)
277 subroutine prg_get_hscf_v2(ham0_bml,over_bml,ham_bml,spindex,hindex,hubbardu,charges,&
278 coulomb_pot_r,coulomb_pot_k,mdimin,threshold)
279 character(20) :: bml_type
280 integer :: i, j, nats, norb, mdim
281 integer,
intent(in) :: hindex(:,:), mdimin, spindex(:)
282 real(
dp),
allocatable :: coulomb_pot(:), diagonal(:)
283 real(
dp),
intent(in) :: charges(:), coulomb_pot_k(:),coulomb_pot_r(:), hubbardu(:)
284 real(
dp),
intent(in) :: threshold
285 type(bml_matrix_t) :: aux_bml
286 type(bml_matrix_t),
intent(in) :: ham0_bml, over_bml
287 type(bml_matrix_t),
intent(inout) :: ham_bml
289 nats =
size(coulomb_pot_r)
290 allocate(coulomb_pot(nats))
292 norb = bml_get_n(ham0_bml)
293 if(hindex(2,nats) .ne. norb)
then
294 write(*,*)
"ERROR in prg_get_hscf. hindex incompatible with ham0"
304 allocate(diagonal(norb))
306 if (bml_allocated(ham_bml))
then
307 call bml_deallocate(ham_bml)
310 bml_type = bml_get_type(ham0_bml)
312 coulomb_pot = coulomb_pot_k + coulomb_pot_r
314 if(bml_allocated(ham_bml))
then
315 call bml_deallocate(ham_bml)
318 call bml_zero_matrix(bml_type,bml_element_real,
dp,mdim,norb,ham_bml)
319 call bml_zero_matrix(bml_type,bml_element_real,
dp,mdim,norb,aux_bml)
322 do j = hindex(1,i),hindex(2,i)
323 diagonal(j) = hubbardu(spindex(i))*charges(i) + coulomb_pot(i)
327 call bml_set_diagonal(aux_bml,diagonal)
328 call bml_multiply(over_bml,aux_bml,ham_bml,0.5_dp,1.0_dp,threshold)
330 call bml_multiply(aux_bml,over_bml,ham_bml,0.5_dp,1.0_dp,threshold)
333 deallocate(coulomb_pot)
334 call bml_deallocate(aux_bml)
339 coulomb_pot_r,coulomb_pot_k,mdimin,threshold,maxorb)
340 character(20) :: bml_type
341 integer :: i, j, nats, norb, mdim
342 integer,
intent(in) :: hindex(:,:), mdimin, spindex(:), maxorb
343 real(
dp),
allocatable :: coulomb_pot(:), diagonal(:)
344 real(
dp),
intent(in) :: charges(:), coulomb_pot_k(:),coulomb_pot_r(:), hubbardu(:)
345 real(
dp),
intent(in) :: threshold
346 real(
dp),
allocatable,
save :: zero(:,:)
347 type(bml_matrix_t),
save :: zero_bml, aux_bml
348 type(bml_matrix_t),
intent(in) :: ham0_bml, over_bml
349 type(bml_matrix_t),
intent(inout) :: ham_bml
351 nats =
size(coulomb_pot_r)
352 allocate(coulomb_pot(nats))
354 bml_type = bml_get_type(ham_bml)
356 if(.not.bml_allocated(zero_bml))
then
357 allocate(zero(maxorb,maxorb))
359 call bml_import_from_dense(bml_type,zero,zero_bml)
360 call bml_import_from_dense(bml_type,zero,aux_bml)
363 norb = bml_get_n(ham0_bml)
364 if(hindex(2,nats) .ne. norb)
then
365 write(*,*)
"ERROR in prg_get_hscf. hindex incompatible with ham0"
369 if(mdimin.ne.norb)
then
370 write(*,*)
"ERROR in prg_ge_hscf_maxorb: mdim must equal norb"
374 call bml_set_n_dense(aux_bml,norb)
375 call bml_set_n_dense(zero_bml,norb)
376 call bml_copy(zero_bml,aux_bml)
378 allocate(diagonal(norb))
380 call bml_copy(ham0_bml,ham_bml)
382 bml_type = bml_get_type(ham_bml)
384 coulomb_pot = coulomb_pot_k + coulomb_pot_r
388 do j = hindex(1,i),hindex(2,i)
389 diagonal(j) = hubbardu(spindex(i))*charges(i) + coulomb_pot(i)
393 call bml_set_diagonal(aux_bml,diagonal)
394 call bml_multiply(over_bml,aux_bml,ham_bml,0.5_dp,1.0_dp,threshold)
396 call bml_multiply(aux_bml,over_bml,ham_bml,0.5_dp,1.0_dp,threshold)
399 deallocate(coulomb_pot)
A module to compute the Mulliken charges of a chemical system.
subroutine, public prg_get_hscf(ham0_bml, over_bml, ham_bml, spindex, hindex, hubbardu, charges, coulomb_pot_r, coulomb_pot_k, mdimin, threshold)
Constructs the SCF Hamiltonian given H0, HubbardU and charges. This routine does: ,...
subroutine, public prg_get_hscf_v2(ham0_bml, over_bml, ham_bml, spindex, hindex, hubbardu, charges, coulomb_pot_r, coulomb_pot_k, mdimin, threshold)
subroutine, public prg_get_charges(rho_bml, over_bml, hindex, charges, numel, spindex, mdimin, threshold)
Constructs the charges from the density matrix.
subroutine, public prg_get_hscf_maxorb(ham0_bml, over_bml, ham_bml, spindex, hindex, hubbardu, charges, coulomb_pot_r, coulomb_pot_k, mdimin, threshold, maxorb)
Module to handle input output files for the PROGRESS lib.
subroutine, public prg_allgatherparallel(a)
integer function, public getnranks()
A module to read and handle chemical systems.