mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-11-06 22:23:42 +01:00
Removed gamess parser
This commit is contained in:
parent
209dadb633
commit
7dba59e4cd
14
.ocamlinit
14
.ocamlinit
@ -7,22 +7,10 @@ let () =
|
|||||||
#require "lacaml";;
|
#require "lacaml";;
|
||||||
#directory "_build";;
|
#directory "_build";;
|
||||||
#directory "_build/Utils";;
|
#directory "_build/Utils";;
|
||||||
|
#directory "_build/Nuclei";;
|
||||||
#directory "_build/Basis";;
|
#directory "_build/Basis";;
|
||||||
#directory "_build/HartreeFock";;
|
#directory "_build/HartreeFock";;
|
||||||
|
|
||||||
#load "Powers.cmo";;
|
|
||||||
#load "Zkey.cmo";;
|
|
||||||
#load "AngularMomentum.cmo";;
|
|
||||||
#load "Constants.cmo";;
|
|
||||||
#load "Util.cmo";;
|
|
||||||
#load "Coordinate.cmo";;
|
|
||||||
#load "Zmap.cmo";;
|
|
||||||
#load "Zkey.cmo";;
|
|
||||||
#load "ContractedShell.cmo";;
|
|
||||||
#load "ShellPair.cmo";;
|
|
||||||
#load "TwoElectronRR.cmo";;
|
|
||||||
#load "ERI.cmo";;
|
|
||||||
|
|
||||||
#use "topfind";;
|
#use "topfind";;
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ let to_string b =
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
let of_nuclei_and_basis_filename ~nuclei ~filename =
|
let of_nuclei_and_basis_filename ~nuclei filename =
|
||||||
let general_basis =
|
let general_basis =
|
||||||
GamessReader.read ~filename
|
GeneralBasis.read filename
|
||||||
in
|
in
|
||||||
of_nuclei_and_general_basis nuclei general_basis
|
of_nuclei_and_general_basis nuclei general_basis
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ val to_string : t -> string
|
|||||||
(** Pretty prints the basis set in a string. *)
|
(** Pretty prints the basis set in a string. *)
|
||||||
|
|
||||||
|
|
||||||
val of_nuclei_and_general_basis : Nuclei.t -> GeneralBasis.t list -> t
|
val of_nuclei_and_general_basis : Nuclei.t -> GeneralBasis.t -> t
|
||||||
(** Takes an array of {!Nuclei.t}, and a {!GeneralBasis.t} (such as cc-pVDZ
|
(** Takes an array of {!Nuclei.t}, and a {!GeneralBasis.t} (such as cc-pVDZ
|
||||||
for instance) and creates the corresponding atomic basis set.
|
for instance) and creates the corresponding atomic basis set.
|
||||||
All the {!Element.t}s of the array of {!Nuclei.t} are searched in
|
All the {!Element.t}s of the array of {!Nuclei.t} are searched in
|
||||||
@ -22,7 +22,7 @@ val of_nuclei_and_general_basis : Nuclei.t -> GeneralBasis.t list -> t
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
val of_nuclei_and_basis_filename : nuclei:Nuclei.t -> filename:string -> t
|
val of_nuclei_and_basis_filename : nuclei:Nuclei.t -> string -> t
|
||||||
(** Same as {!of_nuclei_and_general_basis}, but taking the {!GeneralBasis.t}
|
(** Same as {!of_nuclei_and_general_basis}, but taking the {!GeneralBasis.t}
|
||||||
from a file.
|
from a file.
|
||||||
*)
|
*)
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
exception SyntaxError of string
|
|
||||||
|
|
||||||
open GamessParser
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let eol = ['\n']
|
|
||||||
let white = [' ' '\t']+
|
|
||||||
let element = ['A'-'Z' 'a'-'z']+ white? eol
|
|
||||||
let ang_mom = ['S' 'P' 'D' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O'
|
|
||||||
's' 'p' 'd' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' ]
|
|
||||||
white
|
|
||||||
let integer = ['0'-'9']+
|
|
||||||
let real = '-'? integer '.' integer (['e' 'E'] ('+'|'-')? integer)?
|
|
||||||
|
|
||||||
|
|
||||||
rule read_all_rule = parse
|
|
||||||
| eol { EOL }
|
|
||||||
| white { SPACE }
|
|
||||||
| ang_mom as a { ANG_MOM (a.[0]) }
|
|
||||||
| element as e { ELEMENT (String.trim e) }
|
|
||||||
| integer as i { INTEGER (int_of_string i) }
|
|
||||||
| real as f { FLOAT (float_of_string f) }
|
|
||||||
| eof { EOF }
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
let rec read_all lexbuf =
|
|
||||||
match read_all_rule lexbuf with
|
|
||||||
| SPACE -> read_all_rule lexbuf
|
|
||||||
| x -> x
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
/* Parses basis sets GAMESS format */
|
|
||||||
|
|
||||||
%{
|
|
||||||
|
|
||||||
%}
|
|
||||||
|
|
||||||
%token <string> ELEMENT
|
|
||||||
%token <char> ANG_MOM
|
|
||||||
%token <int> INTEGER
|
|
||||||
%token <float> FLOAT
|
|
||||||
%token SPACE
|
|
||||||
%token EOL
|
|
||||||
%token EOF
|
|
||||||
|
|
||||||
%start input
|
|
||||||
%type <GeneralBasis.t> input
|
|
||||||
|
|
||||||
%% /* Grammar rules and actions follow */
|
|
||||||
|
|
||||||
input:
|
|
||||||
| basis { $1 }
|
|
||||||
| EOL input { $2 }
|
|
||||||
|
|
||||||
basis:
|
|
||||||
| element shell_array EOL { ($1, $2) }
|
|
||||||
| element shell_array EOF { ($1, $2) }
|
|
||||||
|
|
||||||
element:
|
|
||||||
| ELEMENT { Element.of_string $1 }
|
|
||||||
|
|
||||||
shell_array:
|
|
||||||
| shell_list { Array.of_list @@ List.rev $1 }
|
|
||||||
|
|
||||||
shell_list:
|
|
||||||
| { [] }
|
|
||||||
| shell_list shell { $2 :: $1 }
|
|
||||||
|
|
||||||
shell:
|
|
||||||
| ANG_MOM INTEGER EOL primitive_list { (AngularMomentum.of_char $1, Array.of_list @@ List.rev $4 ) }
|
|
||||||
|
|
||||||
primitive_list:
|
|
||||||
| { [] }
|
|
||||||
| primitive_list primitive { $2 :: $1 }
|
|
||||||
|
|
||||||
primitive:
|
|
||||||
| INTEGER FLOAT FLOAT EOL { GeneralBasis.{exponent=$2 ; coefficient=$3 } }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
|||||||
(** Read a basis set file in GAMESS format and return an association list where the key is an
|
|
||||||
Element.t and the value is the parsed basis set. *)
|
|
||||||
let read ~filename =
|
|
||||||
let lexbuf =
|
|
||||||
let ic = open_in filename in
|
|
||||||
Lexing.from_channel ic
|
|
||||||
in
|
|
||||||
let rec aux accu =
|
|
||||||
try
|
|
||||||
let key, basis =
|
|
||||||
GamessParser.input BasisLexer.read_all lexbuf
|
|
||||||
in
|
|
||||||
aux ((key, basis)::accu)
|
|
||||||
with
|
|
||||||
| Parsing.Parse_error -> List.rev accu
|
|
||||||
in
|
|
||||||
aux []
|
|
||||||
|
|
@ -1,15 +1,83 @@
|
|||||||
(** General basis set read from a file *)
|
(** General basis set read from a file *)
|
||||||
type primitive = {
|
|
||||||
exponent: float ;
|
type primitive =
|
||||||
coefficient: float
|
{
|
||||||
|
exponent : float ;
|
||||||
|
coefficient: float ;
|
||||||
}
|
}
|
||||||
|
|
||||||
type general_contracted_shell = AngularMomentum.t * (primitive array)
|
type general_contracted_shell = AngularMomentum.t * (primitive array)
|
||||||
|
|
||||||
type t = Element.t * (general_contracted_shell array)
|
type element_basis = Element.t * (general_contracted_shell array)
|
||||||
|
|
||||||
|
type t = element_basis list
|
||||||
|
|
||||||
|
|
||||||
|
exception No_shell
|
||||||
|
exception Malformed_shell of string
|
||||||
|
|
||||||
|
|
||||||
|
let read_shell ic =
|
||||||
|
try
|
||||||
|
|
||||||
|
let shell, n =
|
||||||
|
try
|
||||||
|
Scanf.sscanf (input_line ic) " %c %d " (fun shell n -> shell, n)
|
||||||
|
with
|
||||||
|
| End_of_file -> raise No_shell
|
||||||
|
| Scanf.Scan_failure m -> raise (Malformed_shell m)
|
||||||
|
in
|
||||||
|
|
||||||
|
let rec loop = function
|
||||||
|
| 0 -> []
|
||||||
|
| i -> let contraction =
|
||||||
|
let line = (input_line ic) in
|
||||||
|
try Scanf.sscanf line " %_d %f %f "
|
||||||
|
(fun exponent coefficient -> { exponent ; coefficient })
|
||||||
|
with _ -> raise (Malformed_shell (Printf.sprintf
|
||||||
|
"Expected %d %c contractions, error at contraction %d:\n%s"
|
||||||
|
n shell (n-i+1) line))
|
||||||
|
in
|
||||||
|
contraction :: loop (pred i)
|
||||||
|
in
|
||||||
|
Some (AngularMomentum.of_char shell, Array.of_list (loop n))
|
||||||
|
|
||||||
|
with
|
||||||
|
| No_shell -> None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let read_element ic =
|
||||||
|
try
|
||||||
|
|
||||||
|
let element =
|
||||||
|
Scanf.sscanf (input_line ic) " %s " Element.of_string
|
||||||
|
in
|
||||||
|
|
||||||
|
let rec loop () =
|
||||||
|
match read_shell ic with
|
||||||
|
| Some shell -> shell :: loop ()
|
||||||
|
| None -> []
|
||||||
|
in
|
||||||
|
Some (element, Array.of_list (loop ()) )
|
||||||
|
|
||||||
|
with
|
||||||
|
| Element.ElementError _ -> None
|
||||||
|
| End_of_file -> None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let read filename =
|
||||||
|
let ic = open_in filename in
|
||||||
|
let rec loop () =
|
||||||
|
match read_element ic with
|
||||||
|
| Some e -> e :: loop ()
|
||||||
|
| None -> []
|
||||||
|
in
|
||||||
|
loop ()
|
||||||
|
|
||||||
|
|
||||||
module Am = AngularMomentum
|
|
||||||
|
|
||||||
let string_of_primitive ?id prim =
|
let string_of_primitive ?id prim =
|
||||||
match id with
|
match id with
|
||||||
@ -22,7 +90,7 @@ let string_of_contracted_shell (angular_momentum, prim_array) =
|
|||||||
Array.length prim_array
|
Array.length prim_array
|
||||||
in
|
in
|
||||||
Printf.sprintf "%s %d\n%s"
|
Printf.sprintf "%s %d\n%s"
|
||||||
(Am.to_string angular_momentum) n
|
(AngularMomentum.to_string angular_momentum) n
|
||||||
(Array.init n (fun i -> string_of_primitive ~id:(i+1) prim_array.(i))
|
(Array.init n (fun i -> string_of_primitive ~id:(i+1) prim_array.(i))
|
||||||
|> Array.to_list
|
|> Array.to_list
|
||||||
|> String.concat "\n")
|
|> String.concat "\n")
|
||||||
|
108
Basis/GeneralBasis.mli
Normal file
108
Basis/GeneralBasis.mli
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
(** General basis set read from a file.
|
||||||
|
|
||||||
|
Basis set files are stored in GAMESS format, for example:
|
||||||
|
{[
|
||||||
|
HYDROGEN
|
||||||
|
S 3
|
||||||
|
1 13.0100000 0.0196850
|
||||||
|
2 1.9620000 0.1379770
|
||||||
|
3 0.4446000 0.4781480
|
||||||
|
S 1
|
||||||
|
1 0.1220000 1.0000000
|
||||||
|
P 1
|
||||||
|
1 0.7270000 1.0000000
|
||||||
|
|
||||||
|
HELIUM
|
||||||
|
S 3
|
||||||
|
1 38.3600000 0.0238090
|
||||||
|
2 5.7700000 0.1548910
|
||||||
|
3 1.2400000 0.4699870
|
||||||
|
S 1
|
||||||
|
1 0.2976000 1.0000000
|
||||||
|
P 1
|
||||||
|
1 1.2750000 1.0000000
|
||||||
|
]}
|
||||||
|
|
||||||
|
When building the atomic basis set of a molecular system, the basis functions
|
||||||
|
are created by picking the data from the general basis set. This data structure
|
||||||
|
simplifies the creation of the atomic basis set.
|
||||||
|
*)
|
||||||
|
|
||||||
|
type primitive = private
|
||||||
|
{
|
||||||
|
exponent : float ;
|
||||||
|
coefficient: float ;
|
||||||
|
}
|
||||||
|
|
||||||
|
type general_contracted_shell = AngularMomentum.t * (primitive array)
|
||||||
|
|
||||||
|
type element_basis = Element.t * (general_contracted_shell array)
|
||||||
|
|
||||||
|
type t = element_basis list
|
||||||
|
|
||||||
|
|
||||||
|
exception No_shell
|
||||||
|
exception Malformed_shell of string
|
||||||
|
|
||||||
|
|
||||||
|
val read : string -> t
|
||||||
|
(** Reads a basis set file and return an association list where
|
||||||
|
the key is an {!Element.t} and the value is the parsed basis set.
|
||||||
|
*)
|
||||||
|
|
||||||
|
|
||||||
|
val read_element : in_channel -> element_basis option
|
||||||
|
(** Reads an element from the input channel [ic]. For example,
|
||||||
|
{[
|
||||||
|
HYDROGEN
|
||||||
|
S 3
|
||||||
|
1 13.0100000 0.0196850
|
||||||
|
2 1.9620000 0.1379770
|
||||||
|
3 0.4446000 0.4781480
|
||||||
|
S 1
|
||||||
|
1 0.1220000 1.0000000
|
||||||
|
P 1
|
||||||
|
1 0.7270000 1.0000000
|
||||||
|
|
||||||
|
}]
|
||||||
|
returns
|
||||||
|
{[
|
||||||
|
Some
|
||||||
|
(Element.H,
|
||||||
|
[(AngularMomentum.S,
|
||||||
|
[{exponent = 13.01; coefficient = 0.019685};
|
||||||
|
{exponent = 1.962; coefficient = 0.137977};
|
||||||
|
{exponent = 0.4446; coefficient = 0.478148}]);
|
||||||
|
(AngularMomentum.S, [{exponent = 0.122; coefficient = 1.}]);
|
||||||
|
(AngularMomentum.P, [{exponent = 0.727; coefficient = 1.}])])
|
||||||
|
]}
|
||||||
|
|
||||||
|
@raise Malformed_shell if the input is not well formed.
|
||||||
|
*)
|
||||||
|
|
||||||
|
|
||||||
|
val read_shell : in_channel -> general_contracted_shell option
|
||||||
|
(** Reads a shell from the input channel [ic]. For example,
|
||||||
|
{[
|
||||||
|
S 3
|
||||||
|
1 13.0100000 0.0196850
|
||||||
|
2 1.9620000 0.1379770
|
||||||
|
3 0.4446000 0.4781480
|
||||||
|
]}
|
||||||
|
returns
|
||||||
|
{[
|
||||||
|
Some
|
||||||
|
(AngularMomentum.S,
|
||||||
|
[{exponent = 13.01 ; coefficient = 0.019685};
|
||||||
|
{exponent = 1.962 ; coefficient = 0.137977};
|
||||||
|
{exponent = 0.4446; coefficient = 0.478148}])
|
||||||
|
]}
|
||||||
|
|
||||||
|
@raise Malformed_shell if the input is not well formed.
|
||||||
|
*)
|
||||||
|
|
||||||
|
|
||||||
|
val to_string : string * (general_contracted_shell array) -> string
|
||||||
|
(** Pretty-prints the basis set of an {Element.t}. *)
|
||||||
|
|
||||||
|
|
@ -37,12 +37,12 @@ let make ?multiplicity:(multiplicity=1) ?charge:(charge=0) ~nuclei basis =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let of_filenames ?multiplicity:(multiplicity=1) ?charge:(charge=0) ~nuclei basis =
|
let of_filenames ?multiplicity:(multiplicity=1) ?charge:(charge=0) ~nuclei basis_filename =
|
||||||
let nuclei =
|
let nuclei =
|
||||||
Nuclei.of_filename nuclei
|
Nuclei.of_filename nuclei
|
||||||
in
|
in
|
||||||
let basis =
|
let basis =
|
||||||
Basis.of_nuclei_and_basis_filename ~nuclei ~filename:basis
|
Basis.of_nuclei_and_basis_filename ~nuclei basis_filename
|
||||||
in
|
in
|
||||||
make ~charge ~multiplicity ~nuclei basis
|
make ~charge ~multiplicity ~nuclei basis
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user