From ecdf2c6968d1e955fc67ddeeb532d2687a5ba4f4 Mon Sep 17 00:00:00 2001 From: The Gitter Badger Date: Sun, 9 Nov 2014 17:23:16 +0000 Subject: [PATCH 1/8] Added Gitter badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..89262a35 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# quantum_package +[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/LCPQ/quantum_package?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) \ No newline at end of file From 94c714357f92df12070d061d43a6967cbdede341 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sun, 9 Nov 2014 18:28:40 +0100 Subject: [PATCH 2/8] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 89262a35..3354ea1f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ -# quantum_package -[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/LCPQ/quantum_package?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) \ No newline at end of file +Quantum package +=============== + +[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/LCPQ/quantum_package?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +Set of quantum chemistry programs and libraries. + +For more information, you can visit the [wiki of the project](http://github.com/LCPQ/quantum_package/wiki>) From 915aae403d6cf83462be56683d8bca9d37fa44d1 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sun, 9 Nov 2014 18:29:09 +0100 Subject: [PATCH 3/8] Delete README.rst --- README.rst | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 README.rst diff --git a/README.rst b/README.rst deleted file mode 100644 index 5dfa5b65..00000000 --- a/README.rst +++ /dev/null @@ -1,9 +0,0 @@ -=============== -Quantum package -=============== - -Set of quantum chemistry programs and libraries. - -For more information, you can visit the -`wiki of the project `_ - From fbebdca621a2e5197f08eae9d657d3dd05e3176a Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 12 Nov 2014 10:27:04 +0100 Subject: [PATCH 4/8] Added Full_CI to qp_edit --- ocaml/Input_full_ci.ml | 27 ++++++++++++++++++++++++++- ocaml/qp_edit.ml | 6 ++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml index 516ca0cf..08c305c8 100644 --- a/ocaml/Input_full_ci.ml +++ b/ocaml/Input_full_ci.ml @@ -9,7 +9,8 @@ module Full_ci : sig do_pt2_end : bool; } with sexp ;; - val read : unit -> t + val read : unit -> t + val write : t-> unit val to_string : t -> string val to_rst : t -> Rst_string.t val of_rst : Rst_string.t -> t @@ -33,6 +34,11 @@ end = struct |> Det_number_max.of_int ;; + let write_n_det_max_fci ndet = + Det_number_max.to_int ndet + |> Ezfio.set_full_ci_n_det_max_fci + ;; + let read_pt2_max () = if not (Ezfio.has_full_ci_pt2_max ()) then get_default "pt2_max" @@ -43,6 +49,11 @@ end = struct |> PT2_energy.of_float ;; + let write_pt2_max pt2_max = + PT2_energy.to_float pt2_max + |> Ezfio.set_full_ci_pt2_max + ;; + let read_do_pt2_end () = if not (Ezfio.has_full_ci_do_pt2_end ()) then get_default "do_pt2_end" @@ -52,6 +63,10 @@ end = struct Ezfio.get_full_ci_do_pt2_end () ;; + let write_do_pt2_end = + Ezfio.set_full_ci_do_pt2_end + ;; + let read () = { n_det_max_fci = read_n_det_max_fci (); @@ -60,6 +75,16 @@ end = struct } ;; + + let write { n_det_max_fci ; + pt2_max ; + do_pt2_end ; + } = + write_n_det_max_fci n_det_max_fci; + write_pt2_max pt2_max; + write_do_pt2_end do_pt2_end; + ;; + let to_string b = Printf.sprintf " n_det_max_fci = %s diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index e4672ff7..c922b83b 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -83,10 +83,12 @@ let set str s = in match s with (* - | Full_ci -> | Hartree_fock -> | Mo_basis -> *) + | Full_ci -> + Input.Full_ci.of_rst str + |> Input.Full_ci.write | Electrons -> Input.Electrons.of_rst str |> Input.Electrons.write @@ -132,7 +134,6 @@ let run ezfio_filename = List.map ~f:get [ Ao_basis ; Mo_basis ; - Full_ci ; Hartree_fock ; ]) in @@ -144,6 +145,7 @@ let run ezfio_filename = Nuclei ; Electrons ; Bielec_integrals ; + Full_ci ; Cisd_sc2 ; Determinants ; ] From 8e55dc9f3386c2e2ee9601d58821118fb74bd23a Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 12 Nov 2014 10:34:54 +0100 Subject: [PATCH 5/8] Added Hartree_fock to qp_edit --- ocaml/Input_hartree_fock.ml | 27 ++++++++++++++++++++++++--- ocaml/qp_edit.ml | 8 +++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/ocaml/Input_hartree_fock.ml b/ocaml/Input_hartree_fock.ml index bd92e69b..56b18b31 100644 --- a/ocaml/Input_hartree_fock.ml +++ b/ocaml/Input_hartree_fock.ml @@ -8,7 +8,8 @@ module Hartree_fock : sig thresh_scf : Threshold.t; } with sexp ;; - val read : unit -> t + val read : unit -> t + val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t val of_rst : Rst_string.t -> t @@ -31,14 +32,25 @@ end = struct |> Strictly_positive_int.of_int ;; - let read_thresh_scf() = + let write_n_it_scf_max n_it_scf_max = + Strictly_positive_int.to_int n_it_scf_max + |> Ezfio.set_hartree_fock_n_it_scf_max + ;; + + let read_thresh_scf () = if not (Ezfio.has_hartree_fock_thresh_scf()) then get_default "thresh_scf" |> Float.of_string |> Ezfio.set_hartree_fock_thresh_scf ; Ezfio.get_hartree_fock_thresh_scf () - |> Threshold.of_float ;; + |> Threshold.of_float + ;; + + let write_thresh_scf thresh_scf = + Threshold.to_float thresh_scf + |> Ezfio.set_hartree_fock_thresh_scf + ;; let read () = @@ -47,6 +59,15 @@ end = struct } ;; + + let write { n_it_scf_max ; + thresh_scf ; + } = + write_n_it_scf_max n_it_scf_max; + write_thresh_scf thresh_scf + ;; + + let to_string b = Printf.sprintf " n_it_scf_max = %s diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index c922b83b..9d151a1c 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -83,9 +83,11 @@ let set str s = in match s with (* - | Hartree_fock -> | Mo_basis -> *) + | Hartree_fock -> + Input.Hartree_fock.of_rst str + |> Input.Hartree_fock.write | Full_ci -> Input.Full_ci.of_rst str |> Input.Full_ci.write @@ -134,7 +136,6 @@ let run ezfio_filename = List.map ~f:get [ Ao_basis ; Mo_basis ; - Hartree_fock ; ]) in String.concat output @@ -145,8 +146,9 @@ let run ezfio_filename = Nuclei ; Electrons ; Bielec_integrals ; - Full_ci ; + Hartree_fock ; Cisd_sc2 ; + Full_ci ; Determinants ; ] in From 680247792db88d073aa36a775f0e1dd66b53a044 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 12 Nov 2014 11:25:13 +0100 Subject: [PATCH 6/8] Add documentation to extend qp_edit --- ocaml/README.rst | 6 ++ ocaml/README_qp_edit.rst | 220 +++++++++++++++++++++++++++++++++++++++ ocaml/qp_edit.ml | 21 ++-- 3 files changed, 233 insertions(+), 14 deletions(-) create mode 100644 ocaml/README_qp_edit.rst diff --git a/ocaml/README.rst b/ocaml/README.rst index 414428dd..2f33b268 100644 --- a/ocaml/README.rst +++ b/ocaml/README.rst @@ -4,3 +4,9 @@ Ocaml scripts This directory contains all the scripts that control the input/output with the user. + +All executables start with `qp_` and all tests start with `test_`. Modules +file names start with a capital letter. + +Info on how to extend the `qp_edit` tool is given in `README_qp_edit.rst`. + diff --git a/ocaml/README_qp_edit.rst b/ocaml/README_qp_edit.rst new file mode 100644 index 00000000..4525d21a --- /dev/null +++ b/ocaml/README_qp_edit.rst @@ -0,0 +1,220 @@ +Adding a new block +================== + +In this section, we assume we will add the `New_keyword` keyword. + +Create the `Input_new_keyword.ml` file +-------------------------------------- + +Copy for example the `Input_full_ci.ml` file as a starting point. + +The template is the following, where `r_x`, `r_y`, ..., `last_r` are the records +of the block. + +.. code-block:: ocaml + + module New_keyword : sig + type t = + { r_x : Type_of_x.t + r_y : Y_type.t + ... + last_r : bool + } with sexp + ;; + val read : unit -> t + val write : t -> unit + val to_string : t -> string + val to_rst : t -> Rst_string.t + val of_rst : Rst_string.t -> t + end = struct + type t = + { r_x : Type_of_x.t + r_y : Y_type.t + ... + last_r : bool + } with sexp + ;; + + let get_default = Qpackage.get_ezfio_default "new_keyword";; + + + ... + + end + +The following functions need to be defined:: + + val read : unit -> t + val write : t -> unit + val to_rst : t -> Rst_string.t + val of_rst : Rst_string.t -> t + + +The type `t` has to be defined in a same way in the `sig` and the `struct`. + +For each record of the type `t`, use types defined in the `Qptypes.ml` file as +much as possible. + +The `get_default` function will fetch the default values in the `ezfio_defaults` file +in the `new_keyword` block. + +For each record `r_x` of the type `t`, create a `read_r_x ()` function +and a `write_r_x r_x` function that performs the I/O in the EZFIO. +To set a default value in the `read_r_x` function, use the following template +(assuming that the `Type_of_x` is built from a `double precision` value in +the EZFIO file). + +.. code-block:: ocaml + + let read_r_x () = + if not (Ezfio.has_new_keyword_r_x ()) then + get_default "r_x" + |> Float.of_string + |> Ezfio.set_new_keyword_r_x + ; + Ezfio.get_new_keyword_r_x () + |> Type_of_x.of_float + ;; + + let write_r_x r_x = + Type_of_x.to_float r_x + |> Ezfio.set_new_keyword_r_x + ;; + + +Then, create a `read` and a `write` function as + +.. code-block:: ocaml + + let read () = + { r_x = read_r_x () ; + r_y = read_r_y () ; + ... + last_r = read_last_r () ; + } + ;; + + let write { r_x ; + r_y + ... + last_r ; + } = + write_r_x r_x; + write_r_y r_y; + ... + write_last_r last_r; + ;; + +Finally, create the functions to write an RST string as + +.. code-block:: ocaml + + let to_rst b = + Printf.sprintf " + You can put here some documentation as long as there is no equal sign. + The record entries should be indented on the right with a blank line + before and a blank line after, as they would be in a rst file. + + Here is the text for r_x + + r_x = %s + + And here is the text for r_y + + r_y = %s + + ... + Finally, the text for last_r + + last_r = %s + " + (Type_of_x.to_string b.r_x) + (Y_type.to_string b.r_y) + ... + (Bool.to_string b.last_r) + ;; + + +and you can use this function to read it back: + +.. code-block:: ocaml + + let of_rst s = + let s = Rst_string.to_string s + |> String.split ~on:'\n' + |> List.filter ~f:(fun line -> + String.contains line '=') + |> List.map ~f:(fun line -> + "("^( + String.tr line ~target:'=' ~replacement:' ' + )^")" ) + |> String.concat + in + Sexp.of_string ("("^s^")") + |> t_of_sexp + ;; + + + + + +Add module to `Input.ml` file +----------------------------- + +Append module to the `Input.ml` file. Use the name of the `Input_new_keyword.ml` without the +`.ml` suffix. + +.. code-block:: ocaml + + include Input_new_keyword;; + + +In the `qp_edit.ml` file +------------------------ + +vim search strings are given in brackets. + +1. (`/type keyword`) : Add a new entry to the keyword type corresponding to the block to add: + +.. code-block:: ocaml + + type keyword = + ... + | New_keyword + ;; + + + +2. (`/keyword_to_string`) : Add a new entry to the `keyword_to_string` function for the title of the block + +.. code-block:: ocaml + + let keyword_to_string = function + ... + | New_keyword -> "My new keyword" + ;; + + +3. (`/let get s`) : Add a new call to the to_rst function of the `Input.New_keyword` module + +.. code-block:: ocaml + + let get s = + let header = (make_header s) + and rst = match s with + ... + | New_keyword -> + Input.New_keyword.(to_rst (read ())) + ... + + +4. (`/let set s`) : Add a new call to the of_rst function of the `Input.New_keyword` module + +.. code-block:: ocaml + + match s with + ... + | New_keyword -> + Input.New_keyword.(write (of_rst str)) + ;; + diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index 9d151a1c..e8c93b9f 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -86,26 +86,19 @@ let set str s = | Mo_basis -> *) | Hartree_fock -> - Input.Hartree_fock.of_rst str - |> Input.Hartree_fock.write + Input.Hartree_fock.(write (of_rst str )) | Full_ci -> - Input.Full_ci.of_rst str - |> Input.Full_ci.write + Input.Full_ci.(write (of_rst str)) | Electrons -> - Input.Electrons.of_rst str - |> Input.Electrons.write + Input.Electrons.(write (of_rst str)) | Determinants -> - Input.Determinants.of_rst str - |> Input.Determinants.write + Input.Determinants.(write (of_rst str)) | Cisd_sc2 -> - Input.Cisd_sc2.of_rst str - |> Input.Cisd_sc2.write + Input.Cisd_sc2.(write (of_rst str)) | Nuclei -> - Input.Nuclei.of_rst str - |> Input.Nuclei.write + Input.Nuclei.(write (of_rst str)) | Bielec_integrals -> - Input.Bielec_integrals.of_rst str - |> Input.Bielec_integrals.write + Input.Bielec_integrals.(write (of_rst str)) (* | Ao_basis -> *) From 7db57da1fdb229a01ec3b62253d95d0e17fd9298 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 12 Nov 2014 11:27:03 +0100 Subject: [PATCH 7/8] Link in ocaml/README.rst --- ocaml/README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ocaml/README.rst b/ocaml/README.rst index 2f33b268..3973e31d 100644 --- a/ocaml/README.rst +++ b/ocaml/README.rst @@ -8,5 +8,6 @@ with the user. All executables start with `qp_` and all tests start with `test_`. Modules file names start with a capital letter. -Info on how to extend the `qp_edit` tool is given in `README_qp_edit.rst`. +Info on how to extend the `qp_edit` tool is given in +`README_qp_edit.rst `_. From a700718078c4087968df7cb74e3f48da89fbeedb Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 12 Nov 2014 17:17:44 +0100 Subject: [PATCH 8/8] qp_edit fails better --- ocaml/Input_bi_integrals.ml | 18 ++---------- ocaml/Input_cis.ml | 5 ++++ ocaml/Input_cisd_sc2.ml | 20 ++----------- ocaml/Input_determinants.ml | 6 ++-- ocaml/Input_electrons.ml | 18 ++---------- ocaml/Input_full_ci.ml | 18 ++---------- ocaml/Input_hartree_fock.ml | 19 ++---------- ocaml/Input_nuclei.ml | 22 +++++++------- ocaml/Makefile | 2 +- ocaml/README_qp_edit.rst | 43 ++++++++++----------------- ocaml/qp_edit.ml | 58 +++++++++++++++++-------------------- 11 files changed, 79 insertions(+), 150 deletions(-) diff --git a/ocaml/Input_bi_integrals.ml b/ocaml/Input_bi_integrals.ml index 8cc8203c..2d864aca 100644 --- a/ocaml/Input_bi_integrals.ml +++ b/ocaml/Input_bi_integrals.ml @@ -17,7 +17,7 @@ module Bielec_integrals : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { read_ao_integrals : bool; @@ -220,20 +220,8 @@ Direct calculation of integrals :: |> Rst_string.of_string ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_cis.ml b/ocaml/Input_cis.ml index 79cf03e8..d5be2a6a 100644 --- a/ocaml/Input_cis.ml +++ b/ocaml/Input_cis.ml @@ -15,6 +15,7 @@ module Cis_dressed : sig val read : unit -> t val to_string : t -> string val to_rst : t -> Rst_string.t + val of_rst : Rst_string.t -> t option end = struct type t = { n_state_cis : States_number.t; @@ -145,6 +146,10 @@ Epstein-Nesbet 2x2 diagonalization :: |> Rst_string.of_string ;; + + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; + end diff --git a/ocaml/Input_cisd_sc2.ml b/ocaml/Input_cisd_sc2.ml index 47dca5e5..6870e69d 100644 --- a/ocaml/Input_cisd_sc2.ml +++ b/ocaml/Input_cisd_sc2.ml @@ -13,7 +13,7 @@ module Cisd_sc2 : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { n_det_max_cisd_sc2 : Det_number_max.t; @@ -118,22 +118,8 @@ Compute E(PT2) at the end :: |> Rst_string.of_string ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; - - + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_determinants.ml b/ocaml/Input_determinants.ml index f4eeee6a..bc476c12 100644 --- a/ocaml/Input_determinants.ml +++ b/ocaml/Input_determinants.ml @@ -23,7 +23,7 @@ module Determinants : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { n_int : N_int_number.t; @@ -538,8 +538,8 @@ psi_det = %s and n_int = Printf.sprintf "(n_int %d)" (N_int_number.get_max ()) in let s = String.concat [ header ; bitkind ; n_int ; psi_coef ; psi_det] in - Sexp.of_string ("("^s^")") - |> t_of_sexp + + Generic_input_of_rst.evaluate_sexp t_of_sexp s ;; end diff --git a/ocaml/Input_electrons.ml b/ocaml/Input_electrons.ml index e4bc3ee2..c3480d04 100644 --- a/ocaml/Input_electrons.ml +++ b/ocaml/Input_electrons.ml @@ -13,7 +13,7 @@ module Electrons : sig val read_elec_num : unit -> Elec_number.t val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { elec_alpha_num : Elec_alpha_number.t; @@ -91,20 +91,8 @@ elec_num = %s (Elec_number.to_string (read_elec_num ())) ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_full_ci.ml b/ocaml/Input_full_ci.ml index 08c305c8..95c15232 100644 --- a/ocaml/Input_full_ci.ml +++ b/ocaml/Input_full_ci.ml @@ -13,7 +13,7 @@ module Full_ci : sig val write : t-> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { n_det_max_fci : Det_number_max.t; @@ -117,20 +117,8 @@ Compute E(PT2) at the end :: |> Rst_string.of_string ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_hartree_fock.ml b/ocaml/Input_hartree_fock.ml index 56b18b31..27fd9b0e 100644 --- a/ocaml/Input_hartree_fock.ml +++ b/ocaml/Input_hartree_fock.ml @@ -12,7 +12,7 @@ module Hartree_fock : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { n_it_scf_max : Strictly_positive_int.t; @@ -93,21 +93,8 @@ SCF convergence criterion (on energy) :: |> Rst_string.of_string ;; - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; - + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; end diff --git a/ocaml/Input_nuclei.ml b/ocaml/Input_nuclei.ml index 11eeb7d4..3526d721 100644 --- a/ocaml/Input_nuclei.ml +++ b/ocaml/Input_nuclei.ml @@ -14,7 +14,7 @@ module Nuclei : sig val write : t -> unit val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { nucl_num : Nucl_number.t ; @@ -203,15 +203,17 @@ Nuclear coordinates in xyz format (Angstroms) :: | _ -> failwith "Error in xyz format" in (* Create the Nuclei.t data structure *) - { nucl_num = List.length atom_list - |> Nucl_number.of_int ~max:nmax; - nucl_label = List.map atom_list ~f:(fun x -> - x.Atom.element) |> Array.of_list ; - nucl_charge = List.map atom_list ~f:(fun x -> - x.Atom.charge ) |> Array.of_list ; - nucl_coord = List.map atom_list ~f:(fun x -> - x.Atom.coord ) |> Array.of_list ; - } + let result = + { nucl_num = List.length atom_list + |> Nucl_number.of_int ~max:nmax; + nucl_label = List.map atom_list ~f:(fun x -> + x.Atom.element) |> Array.of_list ; + nucl_charge = List.map atom_list ~f:(fun x -> + x.Atom.charge ) |> Array.of_list ; + nucl_coord = List.map atom_list ~f:(fun x -> + x.Atom.coord ) |> Array.of_list ; + } + in Some result ;; end diff --git a/ocaml/Makefile b/ocaml/Makefile index 61e531a3..9e137a64 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -10,7 +10,7 @@ endif LIBS= PKGS= -OCAMLCFLAGS="-g" +OCAMLCFLAGS="-g -warn-error A" OCAMLBUILD=ocamlbuild -j 0 -syntax camlp4o -cflags $(OCAMLCFLAGS) -lflags $(OCAMLCFLAGS) MLFILES=$(wildcard *.ml) ezfio.ml Qptypes.ml MLIFILES=$(wildcard *.mli) diff --git a/ocaml/README_qp_edit.rst b/ocaml/README_qp_edit.rst index 4525d21a..dfadea20 100644 --- a/ocaml/README_qp_edit.rst +++ b/ocaml/README_qp_edit.rst @@ -23,9 +23,8 @@ of the block. ;; val read : unit -> t val write : t -> unit - val to_string : t -> string val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option end = struct type t = { r_x : Type_of_x.t @@ -42,12 +41,14 @@ of the block. end -The following functions need to be defined:: +The following functions need to be defined + +.. code-block:: ocaml val read : unit -> t val write : t -> unit val to_rst : t -> Rst_string.t - val of_rst : Rst_string.t -> t + val of_rst : Rst_string.t -> t option The type `t` has to be defined in a same way in the `sig` and the `struct`. @@ -135,26 +136,12 @@ Finally, create the functions to write an RST string as ;; -and you can use this function to read it back: +and you can use the generic `of_rst` function to read it back: .. code-block:: ocaml - let of_rst s = - let s = Rst_string.to_string s - |> String.split ~on:'\n' - |> List.filter ~f:(fun line -> - String.contains line '=') - |> List.map ~f:(fun line -> - "("^( - String.tr line ~target:'=' ~replacement:' ' - )^")" ) - |> String.concat - in - Sexp.of_string ("("^s^")") - |> t_of_sexp - ;; - - + include Generic_input_of_rst;; + let of_rst = of_rst t_of_sexp;; @@ -201,10 +188,11 @@ vim search strings are given in brackets. let get s = let header = (make_header s) - and rst = match s with + and rst = let open Input in + match s with ... | New_keyword -> - Input.New_keyword.(to_rst (read ())) + New_keyword.(to_rst (read ())) ... @@ -212,9 +200,10 @@ vim search strings are given in brackets. .. code-block:: ocaml - match s with - ... - | New_keyword -> - Input.New_keyword.(write (of_rst str)) + let open Input in + match s with + ... + | New_keyword -> write New_keyword.(of_rst, write) + ... ;; diff --git a/ocaml/qp_edit.ml b/ocaml/qp_edit.ml index e8c93b9f..a6241882 100644 --- a/ocaml/qp_edit.ml +++ b/ocaml/qp_edit.ml @@ -44,25 +44,26 @@ let make_header kw = let get s = let header = (make_header s) - and rst = match s with + and rst = let open Input in + match s with | Full_ci -> - Input.Full_ci.(to_rst (read ())) + Full_ci.(to_rst (read ())) | Hartree_fock -> - Input.Hartree_fock.(to_rst (read ())) + Hartree_fock.(to_rst (read ())) | Mo_basis -> - Input.Mo_basis.(to_rst (read ())) + Mo_basis.(to_rst (read ())) | Electrons -> - Input.Electrons.(to_rst (read ())) + Electrons.(to_rst (read ())) | Determinants -> - Input.Determinants.(to_rst (read ())) + Determinants.(to_rst (read ())) | Cisd_sc2 -> - Input.Cisd_sc2.(to_rst (read ())) + Cisd_sc2.(to_rst (read ())) | Nuclei -> - Input.Nuclei.(to_rst (read ())) + Nuclei.(to_rst (read ())) | Ao_basis -> - Input.Ao_basis.(to_rst (read ())) + Ao_basis.(to_rst (read ())) | Bielec_integrals -> - Input.Bielec_integrals.(to_rst (read ())) + Bielec_integrals.(to_rst (read ())) in header^(Rst_string.to_string rst) ;; @@ -81,27 +82,22 @@ let set str s = let str = String.sub ~pos:index_begin ~len:l str |> Rst_string.of_string in - match s with - (* - | Mo_basis -> - *) - | Hartree_fock -> - Input.Hartree_fock.(write (of_rst str )) - | Full_ci -> - Input.Full_ci.(write (of_rst str)) - | Electrons -> - Input.Electrons.(write (of_rst str)) - | Determinants -> - Input.Determinants.(write (of_rst str)) - | Cisd_sc2 -> - Input.Cisd_sc2.(write (of_rst str)) - | Nuclei -> - Input.Nuclei.(write (of_rst str)) - | Bielec_integrals -> - Input.Bielec_integrals.(write (of_rst str)) - (* - | Ao_basis -> - *) + let write (of_rst,w) = + match of_rst str with + | Some data -> w data + | None -> () + in + let open Input in + match s with + | Hartree_fock -> write Hartree_fock.(of_rst, write) + | Full_ci -> write Full_ci.(of_rst, write) + | Electrons -> write Electrons.(of_rst, write) + | Cisd_sc2 -> write Cisd_sc2.(of_rst, write) + | Bielec_integrals -> write Bielec_integrals.(of_rst, write) + | Determinants -> write Determinants.(of_rst, write) + | Nuclei -> write Nuclei.(of_rst, write) + | Ao_basis -> () (* TODO *) + | Mo_basis -> () (* TODO *) ;;