9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-07-25 11:57:23 +02:00

allow no basis set
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
Anthony Scemama 2023-05-10 14:44:45 +02:00
parent 52da1de877
commit 46e3faed3c
6 changed files with 161 additions and 157 deletions

5
data/basis/none Normal file
View File

@ -0,0 +1,5 @@
$DATA
HYDROGEN
$END

View File

@ -247,8 +247,7 @@ end = struct
let read () = let read () =
if (Ezfio.has_ao_basis_ao_basis ()) then try
begin
let result = let result =
{ ao_basis = read_ao_basis (); { ao_basis = read_ao_basis ();
ao_num = read_ao_num () ; ao_num = read_ao_num () ;
@ -267,9 +266,8 @@ end = struct
|> MD5.to_string |> MD5.to_string
|> Ezfio.set_ao_basis_ao_md5 ; |> Ezfio.set_ao_basis_ao_md5 ;
Some result Some result
end with
else | _ -> (Ezfio.set_ao_basis_ao_md5 "None" ; None)
None
;; ;;

View File

@ -478,6 +478,7 @@ let run ?o b au c d m p cart xyz_file =
let nmax = let nmax =
Nucl_number.get_max () Nucl_number.get_max ()
in in
let rec do_work (accu:(Atom.t*Nucl_number.t) list) (n:int) = function let rec do_work (accu:(Atom.t*Nucl_number.t) list) (n:int) = function
| [] -> accu | [] -> accu
| e::tail -> | e::tail ->
@ -520,141 +521,144 @@ let run ?o b au c d m p cart xyz_file =
in in
let long_basis = Long_basis.of_basis basis in let long_basis = Long_basis.of_basis basis in
let ao_num = List.length long_basis in let ao_num = List.length long_basis in
Ezfio.set_ao_basis_ao_num ao_num; if ao_num > 0 then
Ezfio.set_ao_basis_ao_basis b; begin
Ezfio.set_basis_basis b; Ezfio.set_ao_basis_ao_num ao_num;
let ao_prim_num = list_map (fun (_,g,_) -> List.length g.Gto.lc) long_basis Ezfio.set_ao_basis_ao_basis b;
and ao_nucl = list_map (fun (_,_,n) -> Nucl_number.to_int n) long_basis Ezfio.set_basis_basis b;
and ao_power= let ao_prim_num = list_map (fun (_,g,_) -> List.length g.Gto.lc) long_basis
let l = list_map (fun (x,_,_) -> x) long_basis in and ao_nucl = list_map (fun (_,_,n) -> Nucl_number.to_int n) long_basis
(list_map (fun t -> Positive_int.to_int Angmom.Xyz.(t.x)) l)@ and ao_power=
(list_map (fun t -> Positive_int.to_int Angmom.Xyz.(t.y)) l)@ let l = list_map (fun (x,_,_) -> x) long_basis in
(list_map (fun t -> Positive_int.to_int Angmom.Xyz.(t.z)) l) (list_map (fun t -> Positive_int.to_int Angmom.Xyz.(t.x)) l)@
in (list_map (fun t -> Positive_int.to_int Angmom.Xyz.(t.y)) l)@
let ao_prim_num_max = List.fold_left (fun s x -> (list_map (fun t -> Positive_int.to_int Angmom.Xyz.(t.z)) l)
if x > s then x
else s) 0 ao_prim_num
in
let gtos =
list_map (fun (_,x,_) -> x) long_basis
in
let create_expo_coef ec =
let coefs =
begin match ec with
| `Coefs -> list_map (fun x->
list_map (fun (_,coef) ->
AO_coef.to_float coef) x.Gto.lc) gtos
| `Expos -> list_map (fun x->
list_map (fun (prim,_) -> AO_expo.to_float
prim.GaussianPrimitive.expo) x.Gto.lc) gtos
end
in in
let rec get_n n accu = function let ao_prim_num_max = List.fold_left (fun s x ->
| [] -> List.rev accu if x > s then x
| h::tail -> else s) 0 ao_prim_num
let y = in
begin match List.nth_opt h n with let gtos =
| Some x -> x list_map (fun (_,x,_) -> x) long_basis
| None -> 0. in
let create_expo_coef ec =
let coefs =
begin match ec with
| `Coefs -> list_map (fun x->
list_map (fun (_,coef) ->
AO_coef.to_float coef) x.Gto.lc) gtos
| `Expos -> list_map (fun x->
list_map (fun (prim,_) -> AO_expo.to_float
prim.GaussianPrimitive.expo) x.Gto.lc) gtos
end end
in in
get_n n (y::accu) tail let rec get_n n accu = function
| [] -> List.rev accu
| h::tail ->
let y =
begin match List.nth_opt h n with
| Some x -> x
| None -> 0.
end
in
get_n n (y::accu) tail
in
let rec build accu = function
| n when n=ao_prim_num_max -> accu
| n -> build ( accu @ (get_n n [] coefs) ) (n+1)
in
build [] 0
in in
let rec build accu = function
| n when n=ao_prim_num_max -> accu
| n -> build ( accu @ (get_n n [] coefs) ) (n+1)
in
build [] 0
in
let ao_coef = create_expo_coef `Coefs let ao_coef = create_expo_coef `Coefs
and ao_expo = create_expo_coef `Expos and ao_expo = create_expo_coef `Expos
in
let () =
let shell_num = List.length basis in
let lc : (GaussianPrimitive.t * Qptypes.AO_coef.t) list list =
list_map ( fun (g,_) -> g.Gto.lc ) basis
in
let ang_mom =
list_map (fun (l : (GaussianPrimitive.t * Qptypes.AO_coef.t) list) ->
let x, _ = List.hd l in
Angmom.to_l x.GaussianPrimitive.sym |> Qptypes.Positive_int.to_int
) lc
in
let expo =
list_map (fun l -> list_map (fun (x,_) -> Qptypes.AO_expo.to_float x.GaussianPrimitive.expo) l ) lc
|> List.concat
in
let coef =
list_map (fun l ->
list_map (fun (_,x) -> Qptypes.AO_coef.to_float x) l
) lc
|> List.concat
in
let shell_prim_num =
list_map List.length lc
in
let shell_idx =
let rec make_list n accu = function
| 0 -> accu
| i -> make_list n (n :: accu) (i-1)
in in
let rec aux count accu = function let () =
| [] -> List.rev accu let shell_num = List.length basis in
| l::rest -> let lc : (GaussianPrimitive.t * Qptypes.AO_coef.t) list list =
let new_l = make_list count accu (List.length l) in list_map ( fun (g,_) -> g.Gto.lc ) basis
aux (count+1) new_l rest in
in let ang_mom =
aux 1 [] lc list_map (fun (l : (GaussianPrimitive.t * Qptypes.AO_coef.t) list) ->
in let x, _ = List.hd l in
let prim_num = List.length coef in Angmom.to_l x.GaussianPrimitive.sym |> Qptypes.Positive_int.to_int
Ezfio.set_basis_typ "Gaussian"; ) lc
Ezfio.set_basis_shell_num shell_num; in
Ezfio.set_basis_prim_num prim_num ; let expo =
Ezfio.set_basis_shell_prim_num (Ezfio.ezfio_array_of_list list_map (fun l -> list_map (fun (x,_) -> Qptypes.AO_expo.to_float x.GaussianPrimitive.expo) l ) lc
~rank:1 ~dim:[| shell_num |] ~data:shell_prim_num); |> List.concat
Ezfio.set_basis_shell_ang_mom (Ezfio.ezfio_array_of_list in
~rank:1 ~dim:[| shell_num |] ~data:ang_mom ) ; let coef =
Ezfio.set_basis_shell_index (Ezfio.ezfio_array_of_list list_map (fun l ->
~rank:1 ~dim:[| prim_num |] ~data:shell_idx) ; list_map (fun (_,x) -> Qptypes.AO_coef.to_float x) l
Ezfio.set_basis_basis_nucleus_index (Ezfio.ezfio_array_of_list ) lc
~rank:1 ~dim:[| shell_num |] |> List.concat
~data:( list_map (fun (_,n) -> Nucl_number.to_int n) basis) in
) ; let shell_prim_num =
Ezfio.set_basis_nucleus_shell_num(Ezfio.ezfio_array_of_list list_map List.length lc
~rank:1 ~dim:[| nucl_num |] in
~data:( let shell_idx =
list_map (fun (_,n) -> Nucl_number.to_int n) basis let rec make_list n accu = function
|> List.fold_left (fun accu i -> | 0 -> accu
match accu with | i -> make_list n (n :: accu) (i-1)
| [] -> [(1,i)] in
| (h,j) :: rest -> if j == i then ((h+1,j)::rest) else ((1,i)::(h,j)::rest) let rec aux count accu = function
) [] | [] -> List.rev accu
|> List.rev | l::rest ->
|> List.map fst let new_l = make_list count accu (List.length l) in
)) ; aux (count+1) new_l rest
Ezfio.set_basis_prim_coef (Ezfio.ezfio_array_of_list in
~rank:1 ~dim:[| prim_num |] ~data:coef) ; aux 1 [] lc
Ezfio.set_basis_prim_expo (Ezfio.ezfio_array_of_list in
~rank:1 ~dim:[| prim_num |] ~data:expo) ; let prim_num = List.length coef in
Ezfio.set_basis_typ "Gaussian";
Ezfio.set_basis_shell_num shell_num;
Ezfio.set_basis_prim_num prim_num ;
Ezfio.set_basis_shell_prim_num (Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| shell_num |] ~data:shell_prim_num);
Ezfio.set_basis_shell_ang_mom (Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| shell_num |] ~data:ang_mom ) ;
Ezfio.set_basis_shell_index (Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| prim_num |] ~data:shell_idx) ;
Ezfio.set_basis_basis_nucleus_index (Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| shell_num |]
~data:( list_map (fun (_,n) -> Nucl_number.to_int n) basis)
) ;
Ezfio.set_basis_nucleus_shell_num(Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| nucl_num |]
~data:(
list_map (fun (_,n) -> Nucl_number.to_int n) basis
|> List.fold_left (fun accu i ->
match accu with
| [] -> [(1,i)]
| (h,j) :: rest -> if j == i then ((h+1,j)::rest) else ((1,i)::(h,j)::rest)
) []
|> List.rev
|> List.map fst
)) ;
Ezfio.set_basis_prim_coef (Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| prim_num |] ~data:coef) ;
Ezfio.set_basis_prim_expo (Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| prim_num |] ~data:expo) ;
Ezfio.set_ao_basis_ao_prim_num (Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_prim_num (Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| ao_num |] ~data:ao_prim_num) ; ~rank:1 ~dim:[| ao_num |] ~data:ao_prim_num) ;
Ezfio.set_ao_basis_ao_nucl(Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_nucl(Ezfio.ezfio_array_of_list
~rank:1 ~dim:[| ao_num |] ~data:ao_nucl) ; ~rank:1 ~dim:[| ao_num |] ~data:ao_nucl) ;
Ezfio.set_ao_basis_ao_power(Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_power(Ezfio.ezfio_array_of_list
~rank:2 ~dim:[| ao_num ; 3 |] ~data:ao_power) ; ~rank:2 ~dim:[| ao_num ; 3 |] ~data:ao_power) ;
Ezfio.set_ao_basis_ao_coef(Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_coef(Ezfio.ezfio_array_of_list
~rank:2 ~dim:[| ao_num ; ao_prim_num_max |] ~data:ao_coef) ; ~rank:2 ~dim:[| ao_num ; ao_prim_num_max |] ~data:ao_coef) ;
Ezfio.set_ao_basis_ao_expo(Ezfio.ezfio_array_of_list Ezfio.set_ao_basis_ao_expo(Ezfio.ezfio_array_of_list
~rank:2 ~dim:[| ao_num ; ao_prim_num_max |] ~data:ao_expo) ; ~rank:2 ~dim:[| ao_num ; ao_prim_num_max |] ~data:ao_expo) ;
Ezfio.set_ao_basis_ao_cartesian(cart); Ezfio.set_ao_basis_ao_cartesian(cart);
in in
match Input.Ao_basis.read () with match Input.Ao_basis.read () with
| None -> failwith "Error in basis" | None -> failwith "Error in basis"
| Some x -> Input.Ao_basis.write x | Some x -> Input.Ao_basis.write x
end
in in
let () = let () =
try write_file () with try write_file () with
@ -781,7 +785,7 @@ If a file with the same name as the basis set exists, this file will be read. O
run ?o:output basis au charge dummy multiplicity pseudo cart xyz_filename run ?o:output basis au charge dummy multiplicity pseudo cart xyz_filename
) )
with with
| Failure txt -> Printf.eprintf "Fatal error: %s\n%!" txt (* | Failure txt -> Printf.eprintf "Fatal error: %s\n%!" txt *)
| Command_line.Error txt -> Printf.eprintf "Command line error: %s\n%!" txt | Command_line.Error txt -> Printf.eprintf "Command line error: %s\n%!" txt

View File

@ -172,25 +172,23 @@ let run check_only ?ndet ?state ezfio_filename =
(* Reorder basis set *) (* Reorder basis set *)
begin begin
let aos = match Input.Ao_basis.read() with
match Input.Ao_basis.read() with | Some aos ->
| Some x -> x let ordering = Input.Ao_basis.ordering aos in
| _ -> assert false let test = Array.copy ordering in
in Array.sort compare test ;
let ordering = Input.Ao_basis.ordering aos in if test <> ordering then
let test = Array.copy ordering in begin
Array.sort compare test ; Printf.eprintf "Warning: Basis set is not properly ordered. Redordering.\n";
if test <> ordering then let new_aos = Input.Ao_basis.reorder aos in
begin Input.Ao_basis.write new_aos;
Printf.eprintf "Warning: Basis set is not properly ordered. Redordering.\n"; match Input.Mo_basis.read() with
let new_aos = Input.Ao_basis.reorder aos in | None -> ()
Input.Ao_basis.write new_aos; | Some mos ->
match Input.Mo_basis.read() with let new_mos = Input.Mo_basis.reorder mos ordering in
| None -> () Input.Mo_basis.write new_mos
| Some mos -> end
let new_mos = Input.Mo_basis.reorder mos ordering in | _ -> ()
Input.Mo_basis.write new_mos
end
end; end;
begin begin

View File

@ -22,4 +22,4 @@ ezfio_name: direct
type: logical type: logical
doc: Perform Cholesky decomposition of AO integrals doc: Perform Cholesky decomposition of AO integrals
interface: ezfio,provider,ocaml interface: ezfio,provider,ocaml
default: True default: False

View File

@ -3,7 +3,6 @@ subroutine save_mos
double precision, allocatable :: buffer(:,:) double precision, allocatable :: buffer(:,:)
integer :: i,j integer :: i,j
call system('$QP_ROOT/scripts/save_current_mos.sh '//trim(ezfio_filename))
call ezfio_set_mo_basis_mo_num(mo_num) call ezfio_set_mo_basis_mo_num(mo_num)
call ezfio_set_mo_basis_mo_label(mo_label) call ezfio_set_mo_basis_mo_label(mo_label)
call ezfio_set_mo_basis_ao_md5(ao_md5) call ezfio_set_mo_basis_ao_md5(ao_md5)
@ -27,7 +26,7 @@ subroutine save_mos_no_occ
double precision, allocatable :: buffer(:,:) double precision, allocatable :: buffer(:,:)
integer :: i,j integer :: i,j
call system('$QP_ROOT/scripts/save_current_mos.sh '//trim(ezfio_filename)) ! call system('$QP_ROOT/scripts/save_current_mos.sh '//trim(ezfio_filename))
!call ezfio_set_mo_basis_mo_num(mo_num) !call ezfio_set_mo_basis_mo_num(mo_num)
!call ezfio_set_mo_basis_mo_label(mo_label) !call ezfio_set_mo_basis_mo_label(mo_label)
!call ezfio_set_mo_basis_ao_md5(ao_md5) !call ezfio_set_mo_basis_ao_md5(ao_md5)
@ -48,7 +47,7 @@ subroutine save_mos_truncated(n)
double precision, allocatable :: buffer(:,:) double precision, allocatable :: buffer(:,:)
integer :: i,j,n integer :: i,j,n
call system('$QP_ROOT/scripts/save_current_mos.sh '//trim(ezfio_filename)) ! call system('$QP_ROOT/scripts/save_current_mos.sh '//trim(ezfio_filename))
call ezfio_set_mo_basis_mo_num(n) call ezfio_set_mo_basis_mo_num(n)
call ezfio_set_mo_basis_mo_label(mo_label) call ezfio_set_mo_basis_mo_label(mo_label)