Skip to content

Commit

Permalink
Fixed TREXIO norm problems
Browse files Browse the repository at this point in the history
  • Loading branch information
scemama committed Jan 21, 2025
1 parent 360aae7 commit 33ff78d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 81 deletions.
44 changes: 0 additions & 44 deletions ocaml/Input_ao_basis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module Ao_basis : sig
ao_coef : AO_coef.t array;
ao_expo : AO_expo.t array;
ao_cartesian : bool;
ao_normalized : bool;
primitives_normalized : bool;
} [@@deriving sexp]
;;
val read : unit -> t option
Expand All @@ -36,8 +34,6 @@ end = struct
ao_coef : AO_coef.t array;
ao_expo : AO_expo.t array;
ao_cartesian : bool;
ao_normalized : bool;
primitives_normalized : bool;
} [@@deriving sexp]
;;

Expand Down Expand Up @@ -133,24 +129,6 @@ end = struct
Ezfio.get_ao_basis_ao_cartesian ()
;;

let read_ao_normalized () =
if not (Ezfio.has_ao_basis_ao_normalized()) then
get_default "ao_normalized"
|> bool_of_string
|> Ezfio.set_ao_basis_ao_normalized
;
Ezfio.get_ao_basis_ao_normalized ()
;;

let read_primitives_normalized () =
if not (Ezfio.has_ao_basis_primitives_normalized()) then
get_default "primitives_normalized"
|> bool_of_string
|> Ezfio.set_ao_basis_primitives_normalized
;
Ezfio.get_ao_basis_primitives_normalized ()
;;

let to_long_basis b =
let ao_num = AO_number.to_int b.ao_num in
let gto_array = Array.init (AO_number.to_int b.ao_num)
Expand Down Expand Up @@ -213,8 +191,6 @@ end = struct
ao_coef ;
ao_expo ;
ao_cartesian ;
ao_normalized ;
primitives_normalized ;
} = b
in
write_md5 b ;
Expand Down Expand Up @@ -247,8 +223,6 @@ end = struct
~rank:2 ~dim:[| ao_num ; 3 |] ~data:ao_power) ;

Ezfio.set_ao_basis_ao_cartesian(ao_cartesian);
Ezfio.set_ao_basis_ao_normalized(ao_normalized);
Ezfio.set_ao_basis_primitives_normalized(primitives_normalized);

let ao_coef =
Array.to_list ao_coef
Expand Down Expand Up @@ -280,8 +254,6 @@ end = struct
ao_coef = read_ao_coef () ;
ao_expo = read_ao_expo () ;
ao_cartesian = read_ao_cartesian () ;
ao_normalized = read_ao_normalized () ;
primitives_normalized = read_primitives_normalized () ;
}
in
to_md5 result
Expand Down Expand Up @@ -392,8 +364,6 @@ end = struct
{ ao_basis = name ;
ao_num ; ao_prim_num ; ao_prim_num_max ; ao_nucl ;
ao_power ; ao_coef ; ao_expo ; ao_cartesian ;
ao_normalized = bool_of_string @@ get_default "ao_normalized";
primitives_normalized = bool_of_string @@ get_default "primitives_normalized";
}
;;

Expand Down Expand Up @@ -448,14 +418,6 @@ Cartesian coordinates (6d,10f,...) ::
ao_cartesian = %s
Use normalized primitive functions ::
primitives_normalized = %s
Use normalized basis functions ::
ao_normalized = %s
Basis set (read-only) ::
%s
Expand All @@ -469,8 +431,6 @@ Basis set (read-only) ::
" (AO_basis_name.to_string b.ao_basis)
(string_of_bool b.ao_cartesian)
(string_of_bool b.primitives_normalized)
(string_of_bool b.ao_normalized)
(Basis.to_string short_basis
|> String_ext.split ~on:'\n'
|> list_map (fun x-> " "^x)
Expand Down Expand Up @@ -507,8 +467,6 @@ ao_power = %s
ao_coef = %s
ao_expo = %s
ao_cartesian = %s
ao_normalized = %s
primitives_normalized = %s
md5 = %s
"
(AO_basis_name.to_string b.ao_basis)
Expand All @@ -525,8 +483,6 @@ md5 = %s
(b.ao_expo |> Array.to_list |> list_map AO_expo.to_string
|> String.concat ", ")
(b.ao_cartesian |> string_of_bool)
(b.ao_normalized |> string_of_bool)
(b.primitives_normalized |> string_of_bool)
(to_md5 b |> MD5.to_string )

;;
Expand Down
10 changes: 6 additions & 4 deletions scripts/qp_import_trexio.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,11 @@ def write_ezfio(trexio_filename, filename):

shell_factor = trexio.read_basis_shell_factor(trexio_file)
prim_factor = trexio.read_basis_prim_factor(trexio_file)
for i,p in enumerate(prim_factor):
coefficient[i] *= prim_factor[i]
ezfio.set_ao_basis_primitives_normalized(False)
ezfio.set_basis_prim_normalization_factor(prim_factor)
ezfio.set_basis_primitives_normalized(True)
ezfio.set_basis_ao_normalized(False)
for i, shell_idx in enumerate(shell_index):
coefficient[i] *= shell_factor[shell_idx]
ezfio.set_basis_prim_coef(coefficient)

elif basis_type.lower() == "numerical":
Expand Down Expand Up @@ -391,7 +393,7 @@ def write_ezfio(trexio_filename, filename):

# Renormalize MO coefs if needed
if trexio.has_ao_normalization(trexio_file_cart):
ezfio.set_ao_basis_ao_normalized(False)
ezfio.set_basis_ao_normalized(False)
norm = trexio.read_ao_normalization(trexio_file_cart)
# for j in range(mo_num):
# for i,f in enumerate(norm):
Expand Down
12 changes: 0 additions & 12 deletions src/ao_basis/EZFIO.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ doc: If |true|, use |AOs| in Cartesian coordinates (6d,10f,...)
interface: ezfio, provider
default: false

[ao_normalized]
type: logical
doc: Use normalized basis functions
interface: ezfio, provider
default: true

[primitives_normalized]
type: logical
doc: Use normalized primitive functions
interface: ezfio, provider
default: true

[use_cgtos]
type: logical
doc: If true, use cgtos for AO integrals
Expand Down
3 changes: 2 additions & 1 deletion src/ao_basis/aos.irp.f
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@
enddo
ao_coef_normalization_factor(i) = 1.d0/dsqrt(norm)

if (.not.ao_normalized) then
if (ao_normalized) then
do j=1,ao_prim_num(i)
ao_coef_normalized(i,j) = ao_coef_normalized(i,j) * ao_coef_normalization_factor(i)
enddo
else
ao_coef_normalization_factor(i) = 1.d0
endif
enddo
Expand Down
12 changes: 12 additions & 0 deletions src/basis/EZFIO.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,15 @@ size: (basis.prim_num)
interface: ezfio, provider


[primitives_normalized]
type: logical
doc: If true, assume primitive basis functions are normalized
interface: ezfio, provider, ocaml
default: true

[ao_normalized]
type: logical
doc: If true, normalize the basis functions
interface: ezfio, provider, ocaml
default: false

17 changes: 14 additions & 3 deletions src/basis/basis.irp.f
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

logical :: has
PROVIDE ezfio_filename
if (.not.ao_normalized) then
shell_normalization_factor = 1.d0
return
endif

if (mpi_master) then
if (size(shell_normalization_factor) == 0) return

Expand Down Expand Up @@ -70,6 +75,12 @@

logical :: has
PROVIDE ezfio_filename

if (.not.primitives_normalized) then
prim_normalization_factor(:) = 1.d0
return
endif

if (mpi_master) then
if (size(prim_normalization_factor) == 0) return

Expand All @@ -95,9 +106,9 @@

do k=1, prim_num
if (shell_index(k) /= i) cycle
call overlap_gaussian_xyz(C_A,C_A,prim_expo(k),prim_expo(k), &
powA,powA,overlap_x,overlap_y,overlap_z,norm,nz)
prim_normalization_factor(k) = 1.d0/dsqrt(norm)
call overlap_gaussian_xyz(C_A,C_A,prim_expo(k),prim_expo(k), &
powA,powA,overlap_x,overlap_y,overlap_z,norm,nz)
prim_normalization_factor(k) = 1.d0/dsqrt(norm)
enddo
enddo

Expand Down
27 changes: 10 additions & 17 deletions src/trexio/export_trexio_routines.irp.f
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,7 @@ subroutine export_trexio(update,full_path)
call trexio_assert(rc, TREXIO_SUCCESS)

allocate(factor(shell_num))
! if (ao_normalized) then
factor(1:shell_num) = shell_normalization_factor(1:shell_num)
! else
! factor(1:shell_num) = 1.d0
! endif
factor(1:shell_num) = shell_normalization_factor(1:shell_num)
rc = trexio_write_basis_shell_factor(f(1), factor)
call trexio_assert(rc, TREXIO_SUCCESS)

Expand All @@ -291,11 +287,12 @@ subroutine export_trexio(update,full_path)
call trexio_assert(rc, TREXIO_SUCCESS)

allocate(factor(prim_num))
! if (primitives_normalized) then
if (primitives_normalized) then
factor(1:prim_num) = prim_normalization_factor(1:prim_num)
! else
! factor(1:prim_num) = 1.d0
! endif
else
factor(1:prim_num) = 1.d0
endif

rc = trexio_write_basis_prim_factor(f(1), factor)
call trexio_assert(rc, TREXIO_SUCCESS)
deallocate(factor)
Expand Down Expand Up @@ -324,14 +321,10 @@ subroutine export_trexio(update,full_path)
C_A(3) = 0.d0

allocate(factor(ao_num))
if (ao_normalized) then
do i=1,ao_num
l = ao_first_of_shell(ao_shell(i))
factor(i) = (ao_coef_normalized(i,1)+tiny(1.d0))/(ao_coef_normalized(l,1)+tiny(1.d0))
enddo
else
factor(:) = 1.d0
endif
do i=1,ao_num
l = ao_first_of_shell(ao_shell(i))
factor(i) = (ao_coef_normalized(i,1)+tiny(1.d0))/(ao_coef_normalized(l,1)+tiny(1.d0))
enddo
rc = trexio_write_ao_normalization(f(1), factor)
call trexio_assert(rc, TREXIO_SUCCESS)
deallocate(factor)
Expand Down

0 comments on commit 33ff78d

Please sign in to comment.