From 73a5cf6ca2ec41d867b83154b9f21c9319b8d4d3 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jan 2021 16:39:33 +0100 Subject: [PATCH] MP2 OK --- Makefile | 16 +- ao/lib/basis.ml | 3 +- bin/build_doc.sh | 2 + bin/tangle.sh | 79 +- common/lib/charge.ml | 8 +- common/lib/charge.mli | 8 +- common/lib/util.ml | 7 +- common/lib/util.mli | 5 +- common/util.org | 12 +- docs/ao.html | 239 +++ docs/common.html | 2339 +++++++++++++++++++++++++++ docs/config.el | 1 + docs/config_tangle.el | 71 + docs/gaussian.html | 239 +++ docs/gaussian_integrals.html | 239 +++ docs/linear_algebra.html | 239 +++ docs/mo.html | 379 +++++ docs/operators.html | 239 +++ docs/particles.html | 1048 ++++++++++++ docs/perturbation.html | 361 +++++ docs/simulation.html | 368 +++++ gaussian_integrals/lib/multipole.ml | 2 +- mo/lib/class.ml | 20 +- mo/lib/class.mli | 4 +- mo/lib/frozen_core.ml | 8 +- mo/lib/frozen_core.mli | 10 +- particles/lib/nuclei.ml | 8 +- particles/lib/nuclei.mli | 8 +- particles/lib/nuclei_lexer.mll | 2 +- particles/lib/xyz_ast.mli | 2 +- particles/test/nuclei.ml | 2 +- perturbation/lib/mp2.ml | 135 +- perturbation/lib/mp2.mli | 29 + perturbation/mp2.org | 180 +++ perturbation/test/mp2.ml | 17 +- simulation/lib/simulation.ml | 10 +- simulation/lib/simulation.mli | 10 +- top/lib/install_printers.ml | 2 +- 38 files changed, 6151 insertions(+), 200 deletions(-) create mode 100644 docs/ao.html create mode 100644 docs/common.html create mode 100755 docs/config_tangle.el create mode 100644 docs/gaussian.html create mode 100644 docs/gaussian_integrals.html create mode 100644 docs/linear_algebra.html create mode 100644 docs/mo.html create mode 100644 docs/operators.html create mode 100644 docs/particles.html create mode 100644 docs/perturbation.html create mode 100644 docs/simulation.html create mode 100644 perturbation/lib/mp2.mli create mode 100644 perturbation/mp2.org diff --git a/Makefile b/Makefile index b8cd9b2..93d19e2 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,19 @@ # Frontend to dune. +DIRS=$(shell ls */README.org | sed "s|/README.org||g") +DOCS=$(patsubst %, docs/%.html, $(DIRS)) + .PHONY: default build install uninstall test clean -default: build +default: tangle build doc + + +docs/%.html: %/README.org + - ./bin/tangle.sh $* + - ./bin/build_doc.sh $* + +doc: $(DOCS) -tangle: - -doc: - build: dune build diff --git a/ao/lib/basis.ml b/ao/lib/basis.ml index 7ded4c8..e1a004c 100644 --- a/ao/lib/basis.ml +++ b/ao/lib/basis.ml @@ -21,7 +21,8 @@ let of_nuclei_and_basis_filename ?(kind=`Gaussian) ?operators ?(cartesian=false) { ao_basis ; cartesian } | _ -> failwith "of_nuclei_and_basis_filename needs to be called with `Gaussian" -let not_implemented = Util.not_implemented +let not_implemented () = + Util.not_implemented "Only Gaussian is implemented" let ao_basis t = t.ao_basis diff --git a/bin/build_doc.sh b/bin/build_doc.sh index 0552af5..fe3e969 100755 --- a/bin/build_doc.sh +++ b/bin/build_doc.sh @@ -23,5 +23,7 @@ done CONFIG="--load docs/htmlize.el --load docs/config.el" emacs --batch $CONFIG docs/${DIR}.org -f org-html-export-to-html + +rm docs/${DIR}.org diff --git a/bin/tangle.sh b/bin/tangle.sh index 35bd020..472676d 100755 --- a/bin/tangle.sh +++ b/bin/tangle.sh @@ -14,88 +14,11 @@ fi DIR=${1%/} -cat << EOF > ${PWD}/tmpfile_$DIR -(package-initialize) -(add-to-list 'package-archives - '("gnu" . "https://elpa.gnu.org/packages/")) -(add-to-list 'package-archives - '("melpa-stable" . "https://stable.melpa.org/packages/")) -(add-to-list 'package-archives - '("melpa" . "https://melpa.org/packages/")) -(setq package-archive-priorities '(("melpa-stable" . 100) - ("melpa" . 50) - ("gnu" . 10))) -(require 'cl) -(let* ((required-packages - '(dash - htmlize - ess - evil - gnuplot - tuareg - tramp - bibtex-completion - org-ref - org-gnome - org-evil - org-bullets - org-mime - magit - rustic - auctex)) - - (missing-packages (remove-if #'package-installed-p required-packages))) - (when missing-packages - (message "Missing packages: %s" missing-packages) - (package-refresh-contents) - (dolist (pkg missing-packages) - (package-install pkg) - (message "Package %s has been installed" pkg)))) - -(setq org-alphabetical-lists t) -(setq org-src-fontify-natively t) - -(setq org-src-preserve-indentation t) -(setq org-confirm-babel-evaluate nil) - -(org-babel-do-load-languages - 'org-babel-load-languages - '( - (emacs-lisp . t) - (shell . t) - (python . t) - (C . t) - (ocaml . t) - (gnuplot . t) - (latex . t) - (ditaa . t) - (dot . t) - (org . t) - (makefile . t) - )) - -(setq pwd (file-name-directory buffer-file-name)) -(setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) -(setq lib (concat pwd "lib/")) -(setq testdir (concat pwd "test/")) -(setq mli (concat lib name ".mli")) -(setq ml (concat lib name ".ml")) -(setq c (concat lib name ".c")) -(setq test-ml (concat testdir name ".ml")) - -(org-babel-tangle) -EOF - - cd $DIR for i in *.org do echo "--- $i ----" - emacs --batch ./$i --load=../tmpfile_$DIR + emacs --batch ./$i --load=../docs/config_tangle.el -f org-babel-tangle done -rm ../tmpfile_$DIR - - - diff --git a/common/lib/charge.ml b/common/lib/charge.ml index a3cb3b2..ba43a74 100644 --- a/common/lib/charge.ml +++ b/common/lib/charge.ml @@ -3,11 +3,11 @@ (* This type should be used for all charges in the program (electrons, nuclei,...). *) -(* [[file:../charge.org::*Type][Type:2]] *) +(* [[file:~/QCaml/common/charge.org::*Type][Type:2]] *) type t = float (* Type:2 ends here *) -(* [[file:../charge.org::*Conversions][Conversions:2]] *) +(* [[file:~/QCaml/common/charge.org::*Conversions][Conversions:2]] *) external of_float : float -> t = "%identity" external to_float : t -> float = "%identity" @@ -25,7 +25,7 @@ let to_string x = "0.0" (* Conversions:2 ends here *) -(* [[file:../charge.org::*Simple operations][Simple operations:2]] *) +(* [[file:~/QCaml/common/charge.org::*Simple%20operations][Simple operations:2]] *) let gen_op op = fun a b -> op (to_float a) (to_float b) @@ -39,7 +39,7 @@ let ( / ) = gen_op ( /. ) let is_null t = t == 0. (* Simple operations:2 ends here *) -(* [[file:../charge.org::*Printers][Printers:2]] *) +(* [[file:~/QCaml/common/charge.org::*Printers][Printers:2]] *) let pp ppf x = Format.fprintf ppf "@[%s@]" (to_string x) (* Printers:2 ends here *) diff --git a/common/lib/charge.mli b/common/lib/charge.mli index 762b08a..23b0141 100644 --- a/common/lib/charge.mli +++ b/common/lib/charge.mli @@ -1,14 +1,14 @@ (* Type *) -(* [[file:../charge.org::*Type][Type:1]] *) +(* [[file:~/QCaml/common/charge.org::*Type][Type:1]] *) type t (* Type:1 ends here *) (* Conversions *) -(* [[file:../charge.org::*Conversions][Conversions:1]] *) +(* [[file:~/QCaml/common/charge.org::*Conversions][Conversions:1]] *) val of_float : float -> t val to_float : t -> float @@ -22,7 +22,7 @@ val to_string: t -> string (* Simple operations *) -(* [[file:../charge.org::*Simple operations][Simple operations:1]] *) +(* [[file:~/QCaml/common/charge.org::*Simple%20operations][Simple operations:1]] *) val ( + ) : t -> t -> t val ( - ) : t -> t -> t val ( * ) : t -> float -> t @@ -33,6 +33,6 @@ val is_null : t -> bool (* Printers *) -(* [[file:../charge.org::*Printers][Printers:1]] *) +(* [[file:~/QCaml/common/charge.org::*Printers][Printers:1]] *) val pp : Format.formatter -> t -> unit (* Printers:1 ends here *) diff --git a/common/lib/util.ml b/common/lib/util.ml index 5fcae3b..85bec0e 100644 --- a/common/lib/util.ml +++ b/common/lib/util.ml @@ -39,7 +39,7 @@ let leadz i = leadz i |> Int32.to_int * | ~pow~ | Fast implementation of the power function for small integer powers | * | ~chop~ | In ~chop a f~, evaluate ~f~ only if the absolute value of ~a~ is larger than ~Constants.epsilon~, and return ~a *. f ()~. | * | ~float_of_int_fast~ | Faster implementation of float_of_int for small positive ints | - * | ~not_implemented~ | Fails with error message if some functionality is not implemented | + * | ~not_implemented~ | Fails if some functionality is not implemented | * | ~of_some~ | Extracts the value of an option | *) @@ -123,8 +123,9 @@ let chop f g = else f *. (g ()) -let not_implemented () = - failwith "Not implemented" +exception Not_implemented of string +let not_implemented string = + raise (Not_implemented string) let of_some = function diff --git a/common/lib/util.mli b/common/lib/util.mli index d72fdb7..68df4ba 100644 --- a/common/lib/util.mli +++ b/common/lib/util.mli @@ -35,8 +35,11 @@ val chop : float -> (unit -> float) -> float val pow : float -> int -> float val float_of_int_fast : int -> float -val not_implemented : unit -> 'a val of_some : 'a option -> 'a + +exception Not_implemented of string +val not_implemented : string -> 'a +(* @raise Not_implemented. *) (* General functions:1 ends here *) (* Functions related to the Boys function *) diff --git a/common/util.org b/common/util.org index 62cbcad..3f0d21f 100644 --- a/common/util.org +++ b/common/util.org @@ -213,8 +213,11 @@ val chop : float -> (unit -> float) -> float val pow : float -> int -> float val float_of_int_fast : int -> float -val not_implemented : unit -> 'a val of_some : 'a option -> 'a + +exception Not_implemented of string +val not_implemented : string -> 'a +(* @raise Not_implemented. *) #+end_src | ~fact~ | Factorial function. | @@ -223,7 +226,7 @@ val of_some : 'a option -> 'a | ~pow~ | Fast implementation of the power function for small integer powers | | ~chop~ | In ~chop a f~, evaluate ~f~ only if the absolute value of ~a~ is larger than ~Constants.epsilon~, and return ~a *. f ()~. | | ~float_of_int_fast~ | Faster implementation of float_of_int for small positive ints | - | ~not_implemented~ | Fails with error message if some functionality is not implemented | + | ~not_implemented~ | Fails if some functionality is not implemented | | ~of_some~ | Extracts the value of an option | #+begin_src ocaml :tangle (eval ml) :exports none @@ -306,8 +309,9 @@ let chop f g = else f *. (g ()) -let not_implemented () = - failwith "Not implemented" +exception Not_implemented of string +let not_implemented string = + raise (Not_implemented string) let of_some = function diff --git a/docs/ao.html b/docs/ao.html new file mode 100644 index 0000000..14cc678 --- /dev/null +++ b/docs/ao.html @@ -0,0 +1,239 @@ + + + + + + + +Atomic Orbitals + + + + + + + + + + + + +
+

Atomic Orbitals

+
+
"Atomic basis set"
+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:38

+

Validate

+
+ + diff --git a/docs/common.html b/docs/common.html new file mode 100644 index 0000000..89ed983 --- /dev/null +++ b/docs/common.html @@ -0,0 +1,2339 @@ + + + + + + + +Common + + + + + + + + + + + + + + +
+

Common

+ +
+
"Utility functions used by all the other directories."
+
+
+ + +
+

1 Angular Momentum

+
+

+Azimuthal quantum number, repsesented as \( s,p,d,\dots \) . +

+
+ +
+

1.1 Type

+
+
+
type t =
+  | S | P | D | F | G | H | I | J | K | L | M | N | O
+  | Int of int
+
+exception Angular_momentum_error of string
+
+type kind =
+    Singlet of t
+  | Doublet of (t * t)
+  | Triplet of (t * t * t)
+  | Quartet of (t * t * t * t)
+
+
+
+ +

+An exception is raised when the Angular_momentum.t element can't +be created. +

+ +

+The kind is used to build shells, shell doublets, triplets or +quartets, use in the two-electron operators. +

+
+
+ +
+

1.2 Conversions

+
+
+
val of_char : char -> t
+val to_char : t -> char
+
+val to_int : t -> int
+val of_int : int -> t
+
+val to_string : t -> string
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + +
of_charReturns an Angular_momentum.t when a shell is given as a character (case insensitive)
to_charConverts the angular momentum into a char
of_intReturns a shell given an \(l\) value.
to_intReturns the \(l_{max}\) value of the shell
to_stringConverts the angular momentum into a string
+ +
+Angular_momentum.of_char 'p';;
+- : Angular_momentum.t = P
+
+Angular_momentum.(to_char P);;
+- : char = 'P'
+
+Angular_momentum.of_int 2;;
+- : Angular_momentum.t = D
+
+Angular_momentum.(to_int D);;
+- : int = 2
+
+Angular_momentum.(to_string D);;
+- : string = "D"
+
+
+
+ +
+

1.3 Shell functions

+
+
+
val n_functions : t -> int
+val zkey_array  : kind -> Zkey.t array
+
+
+ + + + +++ ++ + + + + + + + + + + + +
n_functionsReturns the number of cartesian functions in a shell.
zkey_arrayArray of Zkey.t, where each element is a a key associated with the the powers of \(x,y,z\).
+ +
+Angular_momentum.(n_functions D) ;;
+- : int = 6
+
+Angular_momentum.( zkey_array (Doublet (P,S)) );;
+- : Zkey.t array =
+[|< 01125899906842624 | 1, 0, 0, 0, 0, 0 >;
+  < 01099511627776 | 0, 1, 0, 0, 0, 0 >;
+  < 01073741824 | 0, 0, 1, 0, 0, 0 >|]
+
+
+
+ +
+

1.4 Arithmetic

+
+
+
val ( + ) : t -> t -> t
+val ( - ) : t -> t -> t
+
+
+ +
+Angular_momentum.(D + P);;
+- : Angular_momentum.t = F
+
+Angular_momentum.(F - P);;
+- : Angular_momentum.t = D
+
+
+
+ +
+

1.5 Printers

+
+

+Printers can print as a string (default) or as an integer. +

+ +
+
val pp        : Format.formatter -> t -> unit
+val pp_string : Format.formatter -> t -> unit
+val pp_int    : Format.formatter -> t -> unit
+
+
+
+
+ +
+

1.6 TODO Tests

+
+
+
+

2 Bit string

+
+

+We define here a data type to handle bit strings efficiently. When +the bit string contains less than 64 bits, it is stored internally +in a 63-bit integer and uses bitwise instructions. When more than +63 bits are required, the zarith library is used to consider the +bit string as a multi-precision integer. +

+
+ + +
+

2.1 Type

+
+
+
type t
+
+
+
+
+ +
+

2.2 General implementation

+
+
+
val of_int : int -> t
+val of_z   : Z.t -> t
+val zero   : int -> t
+
+val is_zero : t -> bool
+val numbits : t -> int
+val testbit : t -> int -> bool
+
+val neg            : t -> t
+val shift_left     : t -> int -> t
+val shift_right    : t -> int -> t
+val shift_left_one : int -> int -> t
+
+val logor  : t -> t -> t
+val logxor : t -> t -> t
+val logand : t -> t -> t
+val lognot : t -> t
+
+val plus_one  : t -> t
+val minus_one : t -> t
+
+val hamdist        : t -> t -> int
+val trailing_zeros : t -> int
+val popcount       : t -> int
+
+val to_list      : ?accu:(int list) -> t -> int list
+val permutations : int -> int -> t list
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
of_intCreates a bit string from an int
of_zCreates a bit string from an Z.t multi-precision integer
zerozero n creates a zero bit string with n bits
is_zeroTrue if all the bits of the bit string are zero.
numbitsReturns the number of bits used to represent the bit string
testbittestbit t n is true if the n-th bit of the bit string t is set to 1
negReturns the negative of the integer interpretation of the bit string
shift_leftshift_left t n returns a new bit strings with all the bits shifted n positions to the left
shift_rightshift_right t n returns a new bit strings with all the bits shifted n positions to the right
shift_left_oneshift_left_one size n returns a new bit strings with the n-th bit set to one. It is equivalent as shifting 1 by n bits to the left, size is the total number of bits of the bit string
logorBitwise logical or
logxorBitwise logical exclusive or
logandBitwise logical and
lognotBitwise logical negation
plus_oneTakes the integer representation of the bit string and adds one
minus_oneTakes the integer representation of the bit string and removes one
hamdistReturns the Hamming distance, i.e. the number of bits differing between two bit strings
trailing_zerosReturns the number of trailing zeros in the bit string
permutationspermutations m n generates the list of all possible n-bit strings with m bits set to 1. Algorithm adapted from Bit twiddling hacks
popcountReturns the number of bits set to one in the bit string
to_listConverts a bit string into a list of integers indicating the positions where the bits are set to 1. The first value for the position is not 0 but 1
+ +
+Bitstring.of_int 15;;
+- : Bitstring.t =
+++++------------------------------------------------------------
+
+ +
+Bitstring.(shift_left (of_int 15) 2);;
+- : Bitstring.t =
+--++++----------------------------------------------------------
+
+Bitstring.(shift_right (of_int 15) 2);;
+- : Bitstring.t =
+++--------------------------------------------------------------
+
+Bitstring.shift_left_one 32 4;;
+- : Bitstring.t =
+----+-----------------------------------------------------------
+
+Bitstring.(testbit (of_int 15) 3);;
+- : bool = true
+
+Bitstring.(testbit (of_int 15) 4);;
+- : bool = false
+
+ +
+Bitstring.(logor (of_int 15) (of_int 73));;
+- : Bitstring.t =
+++++--+---------------------------------------------------------
+
+Bitstring.(logand (of_int 15) (of_int 10));;
+- : Bitstring.t =
+-+-+------------------------------------------------------------
+
+Bitstring.(logxor (of_int 15) (of_int 73));;
+- : Bitstring.t =
+-++---+---------------------------------------------------------
+
+ + +
+Bitstring.(plus_one (of_int 15));;
+- : Bitstring.t =
+----+-----------------------------------------------------------
+   
+Bitstring.(minus_one (of_int 15));;
+- : Bitstring.t =
+-+++------------------------------------------------------------
+
+ + +
+Bitstring.(trailing_zeros (of_int 12));;
+- : int = 2
+
+Bitstring.(hamdist (of_int 15) (of_int 73));;
+- : int = 3
+
+Bitstring.(popcount (of_int 15));;
+- : int = 4
+
+ +
+Bitstring.(to_list (of_int 45));;
+- : int list = [1; 3; 4; 6]
+
+ +
+   Bitstring.permutations 2 4;;
+- : Bitstring.t list =
+[++--------------------------------------------------------------;
+ +-+-------------------------------------------------------------;
+ -++-------------------------------------------------------------;
+ +--+------------------------------------------------------------;
+ -+-+------------------------------------------------------------;
+ --++------------------------------------------------------------]
+
+
+
+ +
+

2.3 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+
+ +
+

3 Charge

+
+
+ +
+

3.1 Type

+
+
+
type t
+
+
+ +

+This type should be used for all charges in the program (electrons, nuclei,…). +

+
+
+ +
+

3.2 Conversions

+
+
+
val of_float : float -> t
+val to_float : t -> float
+
+val of_int   : int -> t
+val to_int   : t -> int
+
+val of_string: string -> t
+val to_string: t -> string 
+
+
+
+
+ +
+

3.3 Simple operations

+
+
+
val ( + ) : t -> t -> t
+val ( - ) : t -> t -> t
+val ( * ) : t -> float -> t
+val ( / ) : t -> float -> t 
+val is_null : t -> bool
+
+
+
+
+ +
+

3.4 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+
+ +
+

4 Command line

+
+

+This module is a wrapper around the Getopt library and helps to +define command-line arguments. +

+ +

+Here is an example of how to use this module. +First, define the specification: +

+
+
let open Command_line in
+begin
+  set_header_doc (Sys.argv.(0) ^ " - One-line description");
+  set_description_doc "Long description of the command.";
+  set_specs
+    [ { short='c'; long="check"; opt=Optional;
+        doc="Checks the input data";
+        arg=Without_arg; };
+
+      { short='b' ; long="basis" ; opt=Mandatory;
+        arg=With_arg "<string>";
+        doc="Name of the file containing the basis set"; } ;
+
+      { short='m' ; long="multiplicity" ; opt=Optional;
+        arg=With_arg "<int>";
+        doc="Spin multiplicity (2S+1). Default is singlet"; } ;
+    ]
+end;
+
+
+ +

+Then, define what to do with the arguments: +

+
+
let c =
+  Command_line.get_bool "check"
+in
+
+let basis =
+  match Command_line.get "basis" with
+  | Some x -> x
+  | None -> assert false
+in
+
+let multiplicity =
+  match Command_line.get "multiplicity" with
+  | None -> 1
+  | Some n -> int_of_string n
+in
+
+
+
+ +
+

4.1 Type

+
+
+
type short_opt     = char
+type long_opt      = string
+type optional      = Mandatory | Optional
+type documentation = string
+type argument      = With_arg of string | Without_arg | With_opt_arg of string
+
+type description = {
+  short: short_opt ;
+  long : long_opt  ;
+  opt  : optional  ;
+  doc  : documentation ;
+  arg  : argument ;
+}
+
+
+
+ +
    +
  • Short option: in the command line, a dash with a single character +(ex: ls -l)
  • +
  • Long option: in the command line, two dashes with a word +(ex: ls --directory)
  • +
  • Command-line options can be Mandatory or Optional
  • +
  • Documentation of the option is used in the help function
  • +
  • Some options require an argument (ls --ignore="*.ml" ), some +don't (ls -l) and for some arguments the argument is optional +(git --log[=<n>])
  • +
+
+
+ +
+

4.2 Mutable attributes

+
+

+All the options are stored in the hash table dict where the key +is the long option and the value is a value of type description. +

+ +
+
val set_header_doc : string -> unit
+val set_description_doc : string -> unit
+val set_footer_doc : string -> unit
+
+
+ +

+Functions to set the header, footer and main description of the +documentation provided by the help function: +

+ +
+
val anonymous : long_opt -> optional -> documentation -> description
+
+
+ +

+Function to create an anonymous argument. +

+
+
+ +
+

4.3 Query functions

+
+
+
val get       : long_opt -> string option
+val get_bool  : long_opt -> bool
+val anon_args : unit -> string list
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
getReturns the argument associated with a long option
get_boolTrue if the Optional argument is present in the command-line
anon_argsReturns the list of anonymous arguments
+
+
+ + +
+

4.4 Specification

+
+
+
val set_specs : description list -> unit
+
+
+ +

+Sets the specifications of the current program from a list of +descrption variables. +

+
+
+
+ +
+

5 Constants

+
+

+All constants used in the program. +

+
+ +
+

5.1 Thresholds

+
+
+
val epsilon          : float
+val integrals_cutoff : float
+
+
+ + + + +++ ++ + + + + + + + + + + + +
epsilonValue below which a float is considered null. Default is ε = 2.10-15
integrals_cutoffCutoff value for integrals. Default is ε
+
+
+ +
+

5.2 Mathematical constants

+
+
+
val pi             : float
+val two_pi         : float
+val sq_pi          : float
+val sq_pi_over_two : float
+val pi_inv         : float
+val two_over_sq_pi : float
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
pi\(\pi = 3.141~592~653~589~793~12\)
two_pi\(2 \pi\)
sq_pi\(\sqrt{\pi}\)
sq_pi_over_two\(\sqrt{\pi} / 2\)
pi_inv\(1 / \pi\)
two_over_sq_pi\(2 / \sqrt{\pi}\)
+
+
+ +
+

5.3 Physical constants

+
+
+
val a0       : float
+val a0_inv   : float
+val ha_to_ev : float
+val ev_to_ha : float
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + +
a0Bohr's radius : \(a_0 = 0.529~177~210~67(23)\) angstrom
a0_inv\(1 / a_0\)
ha_to_evHartree to eV conversion factor : \(27.211~386~02(17)\)
ev_to_haeV to Hartree conversion factor : 1 / ha_to_ev
+
+
+
+ +
+

6 Coordinate

+
+

+Coordinates in 3D space. +

+ +

+All operations on points are done in atomic units. Therefore, +all coordinates are given in bohr and manipulated with this +module. +

+
+ +
+

6.1 Type

+
+
+
type bohr 
+type angstrom 
+
+type xyz = {
+  x : float ;
+  y : float ;
+  z : float ;
+}
+
+type 'a point = xyz
+
+type t = bohr point
+
+type axis = X | Y | Z
+
+
+
+
+ +
+

6.2 Creation

+
+
+
val make          : 'a point -> t
+val make_angstrom : 'a point -> angstrom point
+val zero             : bohr point
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
makeCreates a point in atomic units
make_angstromCreates a point in angstrom
zero\((0., 0., 0.)\)
+
+
+ +
+

6.3 Conversion

+
+
+
val bohr_to_angstrom : bohr point -> angstrom point
+val angstrom_to_bohr : angstrom point -> bohr point
+
+
+ + + + +++ ++ + + + + + + + + + + + +
bohr_to_angstromConverts a point in bohr to angstrom
angstrom_to_bohrConverts a point in angstrom to bohr
+
+
+ +
+

6.4 Vector operations

+
+
+
val neg    : t -> t
+val get    : axis -> bohr point -> float
+val dot    : t -> t -> float
+val norm   : t -> float
+val ( |. ) : float -> t -> t
+val ( |+ ) : t -> t -> t
+val ( |- ) : t -> t -> t
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
negNegative of a point
getExtracts the projection of the coordinate on an axis
dotDot product
norm\(\ell{^2}\) norm of the vector
¦.Scales the vector by a constant
¦+Adds two vectors
¦-Subtracts two vectors
+ +
+Coordinate.neg { x=1. ; y=2. ; z=3. } ;;
+- : Coordinate.t =  -1.0000  -2.0000  -3.0000
+
+Coordinate.(get Y { x=1. ; y=2. ; z=3. }) ;;
+- : float = 2.
+
+Coordinate.(
+  2. |. { x=1. ; y=2. ; z=3. }
+) ;;
+- : Coordinate.t =   2.0000   4.0000   6.0000
+
+Coordinate.(
+  { x=1. ; y=2. ; z=3. } |+ { x=2. ; y=3. ; z=1. } 
+);;
+- : Coordinate.t =   3.0000   5.0000   4.0000
+
+Coordinate.(
+  { x=1. ; y=2. ; z=3. } |- { x=2. ; y=3. ; z=1. } 
+);;
+- : Coordinate.t =  -1.0000  -1.0000   2.0000
+
+
+
+ + +
+

6.5 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+val pp_bohr: Format.formatter -> t -> unit
+val pp_angstrom : Format.formatter -> t -> unit
+
+
+ +

+Coordinates can be printed in bohr or angstrom. +

+
+
+
+ +
+

7 Non-negative float

+
+
+ +
+

7.1 Type

+
+
+
type t = private float
+
+
+
+
+ +
+

7.2 Conversions

+
+
+
val of_float        : float -> t
+val unsafe_of_float : float -> t
+val to_float        : t -> float
+
+val of_string       : string -> t
+val to_string       : t -> string
+
+
+ +

+The of_float function checks that the float is non-negative. +The unsafe variant doesn't do this check. +

+
+
+
+ +
+

8 Powers

+
+

+Contains powers of x, y and z describing the polynomials in atomic basis sets. +

+
+ +
+

8.1 Type

+
+
+
type t = private {
+  x   : int ;
+  y   : int ;
+  z   : int ;
+  tot : int ; 
+}
+
+
+ +

+tot always contains x+y+z. +

+
+
+ +
+

8.2 Conversions

+
+
+
val of_int_tuple : int * int * int -> t
+val to_int_tuple : t -> int * int * int 
+
+
+ +
+Powers.of_int_tuple (2,3,1);;
+- : Powers.t = x^2 + y^3 + z^1
+
+Powers.(to_int_tuple (of_int_tuple (2,3,1)));;
+- : int * int * int = (2, 3, 1)
+
+
+
+ +
+

8.3 Operations

+
+
+
val get  : Coordinate.axis -> t -> int
+val incr : Coordinate.axis -> t -> t 
+val decr : Coordinate.axis -> t -> t
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
getReturns the value of the power for \(x\), \(y\) or \(z\)
incrReturns a new Powers.t with the power on the given axis incremented
decrReturns a new Powers.t with the power on the given axis decremented. As opposed to of_int_tuple, the values may become negative
+ +
+Powers.get Coordinate.Y (Powers.of_int_tuple (2,3,1));;
+- : int = 3
+
+Powers.incr Coordinate.Y (Powers.of_int_tuple (2,3,1));;
+- : Powers.t = x^2 + y^4 + z^1
+
+Powers.decr Coordinate.Y (Powers.of_int_tuple (2,3,1));;
+- : Powers.t = x^2 + y^2 + z^1
+
+
+
+ + +
+

8.4 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+
+ +
+

9 QCaml

+
+

+QCaml-specific parameters +

+ +
+
val root : string
+val name : string
+
+
+ + + + +++ ++ + + + + + + + + + + + +
rootPath to the QCaml source directory
name"QCaml"
+
+
+ +
+

10 Range

+
+

+A range is a sorted list of integers in an interval. +

+ +
    +
  • "[a-b]" : range between a and b (included)
  • +
  • "[a]" : the list with only one integer a
  • +
  • "a" : equivalent to "[a]"
  • +
  • "[36-53,72-107,126-131]" represents the list of integers +[ 37 ; 37 ; 38 ; … ; 52 ; 53 ; 72 ; 73 ; … ; 106 ; 107 ; 126 ; 127 ; … ; 130 ; 131 ].
  • +
+
+ +
+

10.1 Type

+
+
+
type t
+
+
+
+
+ +
+

10.2 Conversion

+
+
+
val of_string   : string -> t
+val to_string   : t -> string
+val to_int_list : t -> int list
+
+
+
+
+ +
+

10.3 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+
+ +
+

11 Spin

+
+

+Electron spin +

+
+ +
+

11.1 Type

+
+
+
type t = Alfa | Beta
+
+
+ +

+Note : +Alfa if written with an 'f' instead of 'ph' because it has the same number of +letters as Beta, so the alignment of the code is nicer. +

+
+
+ +
+

11.2 Functions

+
+
+
val other : t -> t
+
+
+ +

+Returns the opposite spin +

+
+
+ +
+

11.3 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+
+ +
+

12 Util

+
+

+Utility functions. +

+
+ + +
+

12.1 External C functions

+
+ + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
erf_floatError function erf from libm
erfc_floatComplementary error function erfc from libm
gamma_floatGamma function gamma from libm
popcntpopcnt instruction
trailzctz instruction
leadzbsf instruction
+
+ +
+

12.1.1 Erf

+
+
+
external erf_float : float -> float = "erf_float_bytecode" "erf_float" [@@unboxed] [@@noalloc]
+
+
+
+
+ +
+

12.1.2 Erfc

+
+
+
external erfc_float : float -> float = "erfc_float_bytecode" "erfc_float" [@@unboxed] [@@noalloc]
+
+
+
+
+ +
+

12.1.3 Gamma

+
+
+
external gamma_float : float -> float = "gamma_float_bytecode" "gamma_float" [@@unboxed] [@@noalloc]
+
+
+
+
+ +
+

12.1.4 Popcnt

+
+
+
val popcnt : int64 -> int
+
+
+
+
+ +
+

12.1.5 Trailz

+
+
+
val trailz : int64 -> int
+
+
+
+
+ +
+

12.1.6 Leadz

+
+
+
val leadz : int64 -> int
+
+
+
+
+ +
+

12.1.7 Test

+
+
+ +
+

12.2 General functions

+
+
+
val fact : int -> float
+(* @raise Invalid_argument for negative arguments or arguments >100. *)
+val binom       : int -> int -> int
+val binom_float : int -> int -> float
+
+val chop              : float -> (unit -> float) -> float
+val pow               : float -> int -> float
+val float_of_int_fast : int -> float
+
+val of_some : 'a option -> 'a
+
+exception Not_implemented of string
+val not_implemented : string -> 'a
+(* @raise Not_implemented. *)
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
factFactorial function.
binomBinomial coefficient. binom n k = \(C_n^k\)
binom_floatfloat variant of binom
powFast implementation of the power function for small integer powers
chopIn chop a f, evaluate f only if the absolute value of a is larger than Constants.epsilon, and return a *. f ().
float_of_int_fastFaster implementation of floatofint for small positive ints
not_implementedFails if some functionality is not implemented
of_someExtracts the value of an option
+
+
+ +
+

12.3 Functions related to the Boys function

+
+
+
val incomplete_gamma : alpha:float -> float -> float
+(* @raise Failure when the calculation doesn't converge. *)
+
+
+ +

+The lower Incomplete Gamma function is implemented : +\[ + \gamma(\alpha,x) = \int_0^x e^{-t} t^{\alpha-1} dt + \] +

+ +

+p: \(\frac{1}{\Gamma(\alpha)} \int_0^x e^{-t} t^{\alpha-1} dt\) +

+ +

+q: \(\frac{1}{\Gamma(\alpha)} \int_x^\infty e^{-t} t^{\alpha-1} dt\) +

+ +

+Reference : Haruhiko Okumura: C-gengo niyoru saishin algorithm jiten +(New Algorithm handbook in C language) (Gijyutsu hyouron sha, +Tokyo, 1991) p.227 [in Japanese] +

+ + +
+
val boys_function : maxm:int -> float -> float array
+
+
+ +

+The Generalized Boys function is implemented, +maxm is the maximum total angular momentum. +

+ +

+\[ + F_m(x) = \frac{\gamma(m+1/2,x)}{2x^{m+1/2}} + \] +where \(\gamma\) is the incomplete gamma function. +

+ +
    +
  • \(F_0(0.) = 1\)
  • +
  • \(F_0(t) = \frac{\sqrt{\pi}}{2\sqrt{t}} \text{erf} ( \sqrt{t} )\)
  • +
  • \(F_m(0.) = \frac{1}{2m+1}\)
  • +
  • \(F_m(t) = \frac{\gamma{m+1/2,t}}{2t^{m+1/2}}\)
  • +
  • \(F_m(t) = \frac{ 2t\, F_{m+1}(t) + e^{-t} }{2m+1}\)
  • +
+
+
+ +
+

12.4 List functions

+
+
+
val list_some  : 'a option list -> 'a list
+val list_range : int -> int -> int list
+val list_pack  : int -> 'a list -> 'a list list
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
list_someFilters out all None elements of the list, and returns the elements without the Some
list_rangeCreates a list of consecutive integers
list_packlist_pack n l Creates a list of n-elements lists
+
+
+ +
+

12.5 Array functions

+
+
+
val array_range   : int -> int -> int array
+val array_sum     : float array -> float
+val array_product : float array -> float
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
array_rangeCreates an array of consecutive integers
array_sumReturns the sum of all the elements of the array
array_productReturns the product of all the elements of the array
+
+
+ +
+

12.6 Stream functions

+
+
+
val stream_range   : int -> int -> int Stream.t
+val stream_to_list : 'a Stream.t -> 'a list
+val stream_fold    : ('a -> 'b -> 'a) -> 'a -> 'b Stream.t -> 'a
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
stream_rangeCreates a stream returning consecutive integers
stream_to_listRead a stream and put items in a list
stream_foldApply a fold to the elements of the stream
+
+
+ +
+

12.7 Printers

+
+
+
val pp_float_array_size   : Format.formatter -> float array -> unit
+val pp_float_array        : Format.formatter -> float array -> unit
+val pp_float_2darray_size : Format.formatter -> float array array -> unit
+val pp_float_2darray      : Format.formatter -> float array array -> unit
+val pp_bitstring          : int -> Format.formatter -> Z.t -> unit
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + +
pp_float_arrayPrinter for float arrays
pp_float_array_sizePrinter for float arrays with size
pp_float_2darrayPrinter for matrices
pp_float_2darray_sizePrinter for matrices with size
pp_bitstringPrinter for bit strings (used by Bitstring module)
+ +
+pp_float_array_size:
+[ 6:   1.000000   1.732051   1.732051   1.000000   1.732051   1.000000 ]
+
+pp_float_array: 
+[    1.000000   1.732051   1.732051   1.000000   1.732051   1.000000 ]
+
+pp_float_2darray_size
+[
+  2:[ 6:  1.000000   1.732051   1.732051   1.000000   1.732051   1.000000 ]
+    [ 4:  1.000000   2.000000   3.000000   4.000000 ] ]
+
+pp_float_2darray:
+[ [   1.000000   1.732051   1.732051   1.000000   1.732051   1.000000 ]
+  [   1.000000   2.000000   3.000000   4.000000 ] ]
+
+pp_bitstring 14:
++++++------+--
+
+
+
+
+ +
+

13 Zkey

+
+

+Encodes the powers of x, y, z in a compact form, suitable for being +used as keys in a hash table. +

+ +

+Internally, the Zkey.t is made of two integers, left and right. +The small integers x, y and z are stored compactly in this 126-bits +space: +

+ +
+                                Left                                                                Right
+ 3 [--------------------------------------------------------------]       [------------------|---------------|---------------|---------------]
+                                                                                                     x               y               z        
+
+ 6 [--------------------------------------------------------------]       [---|----------|----------|----------|----------|----------|---------]
+                                                                                   x1         y1         z1         x2         y2         z2        
+
+ 9 [---------------------------------|----------|----------|---------]    [---|----------|----------|----------|----------|----------|---------]
+                                          x1         y1         z1                 x2         y2         z2         x3         y3         z3        
+
+12 [---|----------|----------|----------|----------|----------|---------] [---|----------|----------|----------|----------|----------|---------]
+            x1         y1         z1         x2         y2         z2              x3         y3         z3         x4         y4         z4
+
+ +

+The values of x,y,z should be positive and should not exceed 32767 for +kind=3. For all other kinds kinds the values should not exceed 1023. +

+
+ +
+

13.1 Types

+
+
+
type t 
+
+type kind =
+  | Three  of  Powers.t
+  | Four   of (int * int * int * int)
+  | Six    of (Powers.t * Powers.t)
+  | Nine   of (Powers.t * Powers.t * Powers.t)
+  | Twelve of (Powers.t * Powers.t * Powers.t * Powers.t)
+
+
+
+
+ +
+

13.2 Conversions

+
+
+
val of_powers_three  : Powers.t -> t
+val of_powers_six    : Powers.t -> Powers.t -> t
+val of_powers_nine   : Powers.t -> Powers.t -> Powers.t -> t
+val of_powers_twelve : Powers.t -> Powers.t -> Powers.t -> Powers.t -> t
+val of_powers        : kind -> t
+val of_int_array     : int array -> t
+val of_int_four      : int -> int -> int -> int -> t
+val to_int_array     : t -> int array
+val to_powers        : t -> kind
+val to_string        : t -> string
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
of_powers_threeCreate from a Powers.t
of_powers_sixCreate from two Powers.t
of_powers_nineCreate from three Powers.t
of_powers_twelveCreate from four Powers.t
of_powersCreate using the kind type
of_int_arrayConvert from an int array
of_int_fourCreate from four ints
to_int_arrayConvert to an int array
to_powersConvert to an Powers.t array
to_stringPretty printing
+
+
+ +
+

13.3 Functions for hash tables

+
+
+
val hash    : t -> int
+val equal   : t -> t -> bool
+val compare : t -> t -> int
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
hashAssociates a nonnegative integer to any Zkey
equalThe equal function. True if two Zkeys are equal
compareComparison function, used for sorting
+
+
+ +
+

13.4 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+
+ +
+

14 Zmap

+
+

+A hash table where the keys are Zkey +

+
+ +
+

14.1 Type

+
+
+
include module type of Hashtbl.Make(Zkey)
+
+
+
+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:38

+

Validate

+
+ + diff --git a/docs/config.el b/docs/config.el index d1244e4..c9889e4 100755 --- a/docs/config.el +++ b/docs/config.el @@ -71,6 +71,7 @@ with class 'color and highest min-color value." (setq org-html-htmlize-output-type 'css) ; default: 'inline-css (setq org-html-htmlize-font-prefix "org-") ; default: "org-" +(setq org-confirm-babel-evaluate nil) (setq c "c") (setq ml "ml") diff --git a/docs/config_tangle.el b/docs/config_tangle.el new file mode 100755 index 0000000..dc8eb04 --- /dev/null +++ b/docs/config_tangle.el @@ -0,0 +1,71 @@ +;; Thanks to Tobias's answer on Emacs Stack Exchange: +;; https://emacs.stackexchange.com/questions/38437/org-mode-batch-export-missing-syntax-highlighting + +(package-initialize) +(add-to-list 'package-archives + '("gnu" . "https://elpa.gnu.org/packages/")) +(add-to-list 'package-archives + '("melpa-stable" . "https://stable.melpa.org/packages/")) +(add-to-list 'package-archives + '("melpa" . "https://melpa.org/packages/")) +(setq package-archive-priorities '(("melpa-stable" . 100) + ("melpa" . 50) + ("gnu" . 10))) +(require 'cl) +(let* ((required-packages + '(dash + htmlize + ess + evil + gnuplot + tuareg + tramp + bibtex-completion + org-ref + org-gnome + org-evil + org-bullets + org-mime + magit + rustic + auctex)) + + (missing-packages (remove-if #'package-installed-p required-packages))) + (when missing-packages + (message "Missing packages: %s" missing-packages) + (package-refresh-contents) + (dolist (pkg missing-packages) + (package-install pkg) + (message "Package %s has been installed" pkg)))) + +(setq org-alphabetical-lists t) +(setq org-src-fontify-natively t) + +(setq org-src-preserve-indentation t) +(setq org-confirm-babel-evaluate nil) + +(org-babel-do-load-languages + 'org-babel-load-languages + '( + (emacs-lisp . t) + (shell . t) + (python . t) + (C . t) + (ocaml . t) + (gnuplot . t) + (latex . t) + (ditaa . t) + (dot . t) + (org . t) + (makefile . t) + )) + +(setq pwd (file-name-directory buffer-file-name)) +(setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) +(setq lib (concat pwd "lib/")) +(setq testdir (concat pwd "test/")) +(setq mli (concat lib name ".mli")) +(setq ml (concat lib name ".ml")) +(setq c (concat lib name ".c")) +(setq test-ml (concat testdir name ".ml")) + diff --git a/docs/gaussian.html b/docs/gaussian.html new file mode 100644 index 0000000..e4718ed --- /dev/null +++ b/docs/gaussian.html @@ -0,0 +1,239 @@ + + + + + + + +Gaussian + + + + + + + + + + + + +
+

Gaussian

+
+
"Gaussian basis sets"
+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:38

+

Validate

+
+ + diff --git a/docs/gaussian_integrals.html b/docs/gaussian_integrals.html new file mode 100644 index 0000000..fa665f2 --- /dev/null +++ b/docs/gaussian_integrals.html @@ -0,0 +1,239 @@ + + + + + + + +Gaussian integrals + + + + + + + + + + + + +
+

Gaussian integrals

+
+
"Integrals on the Gaussian basis sets"
+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:38

+

Validate

+
+ + diff --git a/docs/linear_algebra.html b/docs/linear_algebra.html new file mode 100644 index 0000000..5a7d34b --- /dev/null +++ b/docs/linear_algebra.html @@ -0,0 +1,239 @@ + + + + + + + +Linear Algebra + + + + + + + + + + + + +
+

Linear Algebra

+
+
"Linear algebra utilities of QCaml libraries."
+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:38

+

Validate

+
+ + diff --git a/docs/mo.html b/docs/mo.html new file mode 100644 index 0000000..bea6af6 --- /dev/null +++ b/docs/mo.html @@ -0,0 +1,379 @@ + + + + + + + +Molecular orbitals + + + + + + + + + + + + +
+

Molecular orbitals

+
+

Table of Contents

+ +
+
+
"Molecular orbitals"
+
+
+ + +
+

1 Frozen core

+
+

+Defines how the core electrons are frozen, for each atom. +

+
+ +
+

1.1 Type

+
+
+
type kind =
+  | All_electron
+  | Small
+  | Large
+
+
+ +
+
type t
+
+
+
+
+ +
+

1.2 Creation

+
+
+
val make : kind -> Particles.Nuclei.t -> t
+
+val of_int_list  : int list  -> t
+val of_int_array : int array -> t
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
makeCreates a Frozen_core.t with the same kind for all atoms
of_int_arrayCreates a Frozen_core.t giving the number of frozen electrons per atom
of_int_listCreates a Frozen_core.t giving the number of frozen electrons per atom
+ +
+let f = Frozen_core.(make Small nuclei) ;;
+val f : Frozen_core.t = [|0; 2; 2; 0|]
+
+let f = Frozen_core.(of_int_list [0; 2; 2; 0])
+val f : Frozen_core.t = [|0; 2; 2; 0|]
+
+
+
+ +
+

1.3 Access

+
+
+
val num_elec : t -> int
+val num_mos  : t -> int
+
+
+ + + + +++ ++ + + + + + + + + + + + +
num_elecNumber of frozen electrons
num_mosNumber of frozen molecular orbitals
+ +
+Frozen_core.num_elec f ;;
+- : int = 4
+
+Frozen_core.num_mos f ;;
+- : int = 2
+
+
+
+ +
+

1.4 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:38

+

Validate

+
+ + diff --git a/docs/operators.html b/docs/operators.html new file mode 100644 index 0000000..a0d1f18 --- /dev/null +++ b/docs/operators.html @@ -0,0 +1,239 @@ + + + + + + + +Operators + + + + + + + + + + + + +
+

Operators

+
+
"Parameteried operators, such as F12 and range-separation"
+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:38

+

Validate

+
+ + diff --git a/docs/particles.html b/docs/particles.html new file mode 100644 index 0000000..7ae5acc --- /dev/null +++ b/docs/particles.html @@ -0,0 +1,1048 @@ + + + + + + + +Common + + + + + + + + + + + + + + +
+

Common

+ +
+
"Information relative to particles (electrons and nuclei)."
+
+
+ + +
+

1 Electrons

+
+

+Data structure which contains the number of α and β electrons. +

+
+ +
+

1.1 Type

+
+
+
type t 
+
+
+
+
+ +
+

1.2 Creation

+
+
+
open Common
+
+val make : int -> int -> t
+
+val of_atoms : ?multiplicity:int -> ?charge:int -> Nuclei.t -> t
+(* @param multiplicity default is 1
+   @param charge       default is 0
+   @raise Invalid_argument if the spin multiplicity is not compatible with
+    the molecule and the total charge.
+*)
+
+
+ + + + +++ ++ + + + + + + + + + + + +
makemake n_alfa n_beta
of_atomsCreates the data relative to electrons for a molecular system described by Nuclei.t for a given total charge and spin multiplicity.
+
+
+ +
+

1.3 Access

+
+
+
val charge       : t -> Charge.t
+val n_elec       : t -> int
+val n_alfa       : t -> int
+val n_beta       : t -> int
+val multiplicity : t -> int 
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + +
chargeSum of the charges of the electrons
n_elecNumber of electrons
n_alfaNumber of alpha electrons
n_betaNumber of beta electrons
multiplicitySpin multiplicity: \(2S+1\)
+
+
+ +
+

1.4 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+ +
+

1.5 Tests

+
+
+ +
+

2 Element

+
+

+Chemical elements. +

+
+ +
+

2.1 Type

+
+
+
type t =
+  |X
+  |H                                                 |He
+  |Li|Be                              |B |C |N |O |F |Ne
+  |Na|Mg                              |Al|Si|P |S |Cl|Ar
+  |K |Ca|Sc|Ti|V |Cr|Mn|Fe|Co|Ni|Cu|Zn|Ga|Ge|As|Se|Br|Kr
+  |Rb|Sr|Y |Zr|Nb|Mo|Tc|Ru|Rh|Pd|Ag|Cd|In|Sn|Sb|Te|I |Xe
+                          |Pt          
+
+exception ElementError of string
+
+open Common
+
+
+
+
+ +
+

2.2 Conversion

+
+
+
val of_string      : string -> t
+val to_string      : t -> string
+val to_long_string : t -> string
+
+val to_int : t -> int 
+val of_int : int -> t
+
+val to_charge : t -> Charge.t
+val of_charge : Charge.t -> t
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
of_stringCreates an Element.t from a chemical symbol or from the full name of the element (case insensitive)
to_stringGets the chemical symbol of the Element.t in a string
to_long_stringGets the full name of the Element.t in a string
to_intConvert to the atomic charge, with int type
of_intCreate from the atomic charge, with int type
to_chargeConvert to the atomic charge, with Charge.t type
of_chargeCreate from the atomic charge, with Charge.t type
+ +
+Element.of_string "Fe" ;;
+- : Element.t = Particles.Element.Fe
+
+Element.of_string "hydrogen" ;;
+- : Element.t = Particles.Element.H
+
+Element.of_string "Kryptonite" ;;
+Exception: Particles.Element.ElementError "Element Kryptonite unknown".
+
+Element.(to_long_string Fe) ;;
+- : string = "Iron"
+
+Element.(to_string Fe);;
+- : string = "Fe"
+
+
+
+ +
+

2.3 Database information

+
+
+
val covalent_radius : t -> Non_negative_float.t
+val vdw_radius      : t -> Non_negative_float.t
+val mass            : t -> Mass.t
+val small_core      : t -> int
+val large_core      : t -> int
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + +
covalent_radiusCovalent radii of the elements, in atomic units
vdw_radiusVan der Waals radii of the elements, in atomic units
massAtomic mass of the elements, in atomic units)
small_coreNumber of electrons in the small core model (all except the outermost two shells)
large_coreNumber of electrons in the large core model (all except the outermost shell)
+
+
+ +
+

2.4 Printers

+
+
+
val pp      : Format.formatter -> t -> unit
+val pp_long : Format.formatter -> t -> unit
+
+
+
+
+
+ +
+

3 Atomic mass

+
+

+Atomic mass, a non-negative float. +

+ +
+
include module type of Common.Non_negative_float
+
+
+
+
+ +
+

4 Nuclei

+
+
+ +
+

4.1 Type

+
+
+
open Common
+
+type t = (Element.t * Coordinate.t) array
+
+
+
+
+ +
+

4.2 xyz file lexer/parser

+
+
+
+

4.2.1 Lexer

+
+

+nuclei_lexer.mll contains the description of the lexemes used in +an xyz file. +

+ +
+
{
+open Xyz_parser
+}
+
+let eol = ['\n']
+let white = [' ' '\t']+
+let word = [^' ' '\t' '\n']+
+let letter = ['A'-'Z' 'a'-'z']
+let integer = ['0'-'9']+
+let real = '-'? (integer '.' integer | integer '.' | '.' integer) (['e' 'E'] ('+'|'-')? integer)?
+
+
+rule read_all = parse
+  | eof            { EOF }
+  | eol            { EOL }
+  | white   as w   { SPACE w }
+  | integer as i   { INTEGER (int_of_string i) }
+  | real    as f   { FLOAT (float_of_string f) }
+  | word    as w   { WORD w }
+
+
+{
+(* DEBUG
+ let () =
+   let ic = open_in "h2o.xyz" in
+   let lexbuf = Lexing.from_channel ic in
+   while true do
+     let s =
+      match read_all lexbuf with
+      | EOL -> "EOL"
+      | SPACE w -> "SPACE("^w^")"
+      | INTEGER i -> "INTEGER("^(string_of_int i)^")"
+      | FLOAT f -> "FLOAT("^(string_of_float f)^")"
+      | WORD w -> "WORD("^w^")"
+      | EOF -> "EOF"
+     in
+     print_endline s
+   done;
+*)
+}
+
+
+
+
+ +
+

4.2.2 Parser

+
+

+xyz_parser.mly parses nuclear coordinates in xyz format. +

+
+
%{
+open Common
+
+let make_angstrom x y z =
+  Coordinate.(make_angstrom {
+    x ; y ; z
+  })
+
+let output_of f x y z =
+  let a = make_angstrom x y z in
+  fun e ->
+  {
+    Xyz_ast.
+    element = f e;
+    coord = a ;
+  }
+
+let output_of_string = output_of Element.of_string
+let output_of_int    = output_of Element.of_int
+
+%}
+
+%token EOL
+%token <string> SPACE
+%token <string> WORD
+%token <int> INTEGER
+%token <float> FLOAT
+%token EOF
+
+%start input
+%type <Xyz_ast.xyz_file> input
+
+%% /* Grammar rules and actions follow */
+
+input:
+  | integer title atoms_xyz {
+      {
+        number_of_atoms = $1;
+        file_title = $2;
+        nuclei = $3;
+      }
+    }
+;
+
+
+integer:
+  | INTEGER EOL { $1 }
+  | INTEGER SPACE EOL { $1 }
+  | SPACE INTEGER EOL { $2 }
+  | SPACE INTEGER SPACE EOL { $2 }
+;
+
+title:
+  | title_list EOL { $1 }
+;
+
+text:
+  | WORD    { $1 }
+  | SPACE   { $1 }
+  | FLOAT   { (string_of_float $1)}
+  | INTEGER { (string_of_int $1)}
+;
+
+title_list:
+  | { "" }
+  | title_list text { ($1 ^ $2) }
+;
+
+atoms_xyz:
+  | atoms_list EOL { List.rev $1 }
+  | atoms_list EOF { List.rev $1 }
+;
+
+atoms_list:
+  | { [] }
+  | atoms_list WORD    SPACE FLOAT SPACE FLOAT SPACE FLOAT       EOL { output_of_string $4 $6 $8 $2 :: $1 }
+  | atoms_list WORD    SPACE FLOAT SPACE FLOAT SPACE FLOAT SPACE EOL { output_of_string $4 $6 $8 $2 :: $1 }
+  | atoms_list INTEGER SPACE FLOAT SPACE FLOAT SPACE FLOAT       EOL { output_of_int    $4 $6 $8 $2 :: $1 }
+  | atoms_list INTEGER SPACE FLOAT SPACE FLOAT SPACE FLOAT SPACE EOL { output_of_int    $4 $6 $8 $2 :: $1 }
+  | atoms_list SPACE WORD    SPACE FLOAT SPACE FLOAT SPACE FLOAT       EOL { output_of_string $5 $7 $9 $3 :: $1 }
+  | atoms_list SPACE WORD    SPACE FLOAT SPACE FLOAT SPACE FLOAT SPACE EOL { output_of_string $5 $7 $9 $3 :: $1 }
+  | atoms_list SPACE INTEGER SPACE FLOAT SPACE FLOAT SPACE FLOAT       EOL { output_of_int    $5 $7 $9 $3 :: $1 }
+  | atoms_list SPACE INTEGER SPACE FLOAT SPACE FLOAT SPACE FLOAT SPACE EOL { output_of_int    $5 $7 $9 $3 :: $1 }
+;
+
+
+ +

+When an xyz file is read by xyz_parser.mly, it is converted into +an xyz_file data structure. +

+ +
+
open Common
+
+type nucleus =
+  {
+    element: Element.t ;
+    coord  : Coordinate.angstrom Coordinate.point;
+  }
+
+type xyz_file =
+  {
+    number_of_atoms : int ;
+    file_title      : string ;
+    nuclei          : nucleus list ;
+  }
+
+
+
+
+
+ +
+

4.3 Conversion

+
+
+
val of_xyz_string : string -> t
+val to_xyz_string  : t -> string
+val of_xyz_file   : string -> t
+
+val of_zmt_string : string -> t
+val of_zmt_file   : string -> t
+
+val to_string      : t -> string
+
+val of_filename : string -> t
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
of_xyz_stringCreate from a string, in xyz format
of_xyz_fileCreate from a file, in xyz format
of_zmt_stringCreate from a string, in z-matrix format
of_zmt_fileCreate from a file, in z-matrix format
to_stringTransform to a string, for printing
of_filenameDetects the type of file (xyz, z-matrix) and reads the file
+
+
+ +
+

4.4 TODO Query

+
+
+
val formula    : t -> string
+val repulsion  : t -> float
+val charge     : t -> Charge.t
+val small_core : t -> int
+val large_core : t -> int
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + +
formulaReturns the chemical formula
repulsionNuclear repulsion energy, in atomic units
chargeSum of the charges of the nuclei
small_coreNumber of core electrons in the small core model
large_coreNumber of core electrons in the large core model
+
+
+ +
+

4.5 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+ +
+

4.6 Tests

+
+
+ +
+

5 Z-matrix

+
+

+Z-matrix representation of nuclear coordinates. +

+
+ +
+

5.1 Type

+
+
+
type t 
+
+
+
+
+ +
+

5.2 Conversion

+
+
+
val of_string      : string -> t
+val to_xyz         : t -> (Element.t * float * float * float) array
+val to_xyz_string  : t -> string
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
of_stringReads a z-matrix from a string
to_xyzConverts to xyz format, as in the Nuclei module
to_xyz_stringConverts to xyz format, as a string
+ +
+let zmt = Zmatrix.of_string "
+ n
+ n    1 nn
+ h    1 hn         2 hnn
+ h    2 hn         1 hnn          3 dih4
+ h    1 hn         2 hnn          4 dih5
+ h    2 hn         1 hnn          3 dih5
+
+nn          1.446
+hn          1.016
+hnn         106.0
+dih4        -54.38
+dih5         54.38
+" ;;
+- : Zmatrix.t = N  
+N       1 1.446000
+H       1 1.016000     2 106.000000
+H       2 1.016000     1 106.000000     3 -54.380000
+H       1 1.016000     2 106.000000     4 54.380000
+H       2 1.016000     1 106.000000     3 54.380000
+
+
+Zmatrix.to_xyz zmt ;;
+- : (Element.t * float * float * float) array =
+[|(N, 0., 0., 0.); (N, 0., 0., 1.446);
+  (H, -0.976641883073332107, 0., -0.280047553510071046);
+  (H, -0.568802835186988709, 0.793909757123734683, 1.726047553510071);
+  (H, 0.314092649983635563, 0.924756819385119, -0.280047553510071101);
+  (H, -0.568802835186988709, -0.793909757123734683, 1.726047553510071)|]
+
+
+Zmatrix.to_xyz_string zmt ;;
+- : string =
+"N 0.000000 0.000000 0.000000
+N 0.000000 0.000000 1.446000
+H -0.976642 0.000000 -0.280048
+H -0.568803 0.793910 1.726048
+H 0.314093 0.924757 -0.280048
+H -0.568803 -0.793910 1.726048"
+
+
+
+ + +
+

5.3 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:37

+

Validate

+
+ + diff --git a/docs/perturbation.html b/docs/perturbation.html new file mode 100644 index 0000000..dd6b937 --- /dev/null +++ b/docs/perturbation.html @@ -0,0 +1,361 @@ + + + + + + + +Perturbation + + + + + + + + + + + + +
+

Perturbation

+
+

Table of Contents

+ +
+
+
"Perturbation theory"
+
+
+ + +
+

1 MP2

+
+
+ +
+

1.1 Type

+
+
+
type t
+
+
+
+
+ +
+

1.2 Creation

+
+
+
val make : frozen_core:Mo.Frozen_core.t -> Mo.Basis.t -> t
+
+
+ + + + +++ ++ + + + + + + +
makeCreates an MP2 data structure
+ +
+let mp2 =
+  Mp2.make ~frozen_core:(Mo.Frozen_core.(make Small molecule)) mo_basis
+  ;;
+- : Mp2.t : <abstr>
+
+
+
+ +
+

1.3 Access

+
+
+
val energy      : t -> float
+val mo_basis    : t -> Mo.Basis.t
+val frozen_core : t -> Mo.Frozen_core.t
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + +
energyReturns the MP2 energy
mo_basisReturns the MO basis on which the MP2 energy was computed
frozen_coreReturns the frozencore scheme used to compute the MP2 energy
+ +
+
+
+
+
+ +
+

1.4 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+ +
+

1.5 Tests

+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:38

+

Validate

+
+ + diff --git a/docs/simulation.html b/docs/simulation.html new file mode 100644 index 0000000..4cd8dcf --- /dev/null +++ b/docs/simulation.html @@ -0,0 +1,368 @@ + + + + + + + +Simulation + + + + + + + + + + + + +
+

Simulation

+
+

Table of Contents

+ +
+
+
"Data describing a simulation (AOs, operators, nuclear coordinate,...)"
+
+
+ + +
+

1 Simulation

+
+

+Contains the state of the simulation. +

+ +
+
open Common
+open Particles
+open Operators
+
+
+
+ +
+

1.1 Type

+
+
+
type t
+
+
+
+
+ +
+

1.2 Access

+
+
+
val nuclei            : t -> Nuclei.t
+val charge            : t -> Charge.t
+val electrons         : t -> Electrons.t
+val ao_basis          : t -> Ao.Basis.t
+val nuclear_repulsion : t -> float
+val operators         : t -> Operator.t list
+
+
+ + + + +++ ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
nucleiNuclear coordinates used in the smiulation
chargeTotal charge (electrons + nuclei)
electronsElectrons used in the simulation
ao_basisAtomic basis set
nuclear_repulsionNuclear repulsion energy
operatorsList of extra operators (range-separation, f12, etc)
+
+
+ +
+

1.3 Creation

+
+
+
val make : ?multiplicity:int -> ?charge:int -> 
+  ?operators:Operator.t list-> nuclei:Nuclei.t ->
+  Ao.Basis.t -> t
+
+
+ +

+Defaults: +

+
    +
  • multiplicity : 1
  • +
  • charge : 0
  • +
  • operators : []
  • +
+
+
+ +
+

1.4 Printers

+
+
+
val pp : Format.formatter -> t -> unit
+
+
+
+
+
+
+
+

Author: Anthony Scemama

+

Created: 2021-01-01 Fri 16:38

+

Validate

+
+ + diff --git a/gaussian_integrals/lib/multipole.ml b/gaussian_integrals/lib/multipole.ml index ba8a66e..88b080f 100644 --- a/gaussian_integrals/lib/multipole.ml +++ b/gaussian_integrals/lib/multipole.ml @@ -32,7 +32,7 @@ let matrix t = function | "x4" -> t.(12) | "y4" -> t.(13) | "z4" -> t.(14) - | _ -> Util.not_implemented () + | _ -> Util.not_implemented "Multipole" diff --git a/mo/lib/class.ml b/mo/lib/class.ml index 51591ac..c223864 100644 --- a/mo/lib/class.ml +++ b/mo/lib/class.ml @@ -95,18 +95,14 @@ let mo_class_array t = let fci ~frozen_core mo_basis = let mo_num = Basis.size mo_basis in - let ncore = (Nuclei.small_core @@ Simulation.nuclei @@ Basis.simulation mo_basis) / 2 in + let ncore = Frozen_core.num_mos frozen_core in of_list ( - if frozen_core then List.concat [ Util.list_range 1 ncore |> List.map (fun i -> Core i) ; Util.list_range (ncore+1) mo_num |> List.map (fun i -> Active i) ] - else - Util.list_range 1 mo_num - |> List.map (fun i -> Active i) ) let cas_sd mo_basis ~frozen_core n m = @@ -117,19 +113,11 @@ let cas_sd mo_basis ~frozen_core n m = let n_alfa_in_cas = (n - n_unpaired)/2 + n_unpaired in let last_inactive = n_alfa - n_alfa_in_cas in let last_active = last_inactive + m in - let ncore = - if frozen_core then - (Nuclei.small_core @@ Simulation.nuclei @@ Basis.simulation mo_basis) / 2 - |> min last_inactive - else 0 - in + let ncore = min (Frozen_core.num_mos frozen_core) last_inactive in of_list ( List.concat [ - if ncore > 0 then - Util.list_range 1 ncore - |> List.map (fun i -> Core i) - else - [] ; + Util.list_range 1 ncore + |> List.map (fun i -> Core i) ; Util.list_range (ncore+1) last_inactive |> List.map (fun i -> Inactive i) ; Util.list_range (last_inactive+1) last_active diff --git a/mo/lib/class.mli b/mo/lib/class.mli index 0f1be50..94fcb8d 100644 --- a/mo/lib/class.mli +++ b/mo/lib/class.mli @@ -15,12 +15,12 @@ val of_list : mo_class list -> t val to_list : t -> mo_class list -val fci : frozen_core:bool -> Basis.t -> t +val fci : frozen_core:Frozen_core.t -> Basis.t -> t (** Creates the MO classes for FCI calculations : all [Active]. The [n] lowest MOs are [Core] if [frozen_core = true]. *) -val cas_sd: Basis.t -> frozen_core:bool -> int -> int -> t +val cas_sd: Basis.t -> frozen_core:Frozen_core.t -> int -> int -> t (** [cas_sd mo_basis n m ] creates the MO classes for CAS(n,m) + SD calculations. lowest MOs are [Core], then all the next MOs are [Inactive], then [Active], then [Virtual]. diff --git a/mo/lib/frozen_core.ml b/mo/lib/frozen_core.ml index 65333d0..19735bf 100644 --- a/mo/lib/frozen_core.ml +++ b/mo/lib/frozen_core.ml @@ -1,4 +1,4 @@ -(* [[file:../frozen_core.org::*Type][Type:3]] *) +(* [[file:~/QCaml/mo/frozen_core.org::*Type][Type:3]] *) type kind = | All_electron | Small @@ -21,7 +21,7 @@ type t = int array * #+end_example *) -(* [[file:../frozen_core.org::*Creation][Creation:2]] *) +(* [[file:~/QCaml/mo/frozen_core.org::*Creation][Creation:2]] *) let make_ae nuclei = Array.map (fun _ -> 0) nuclei @@ -56,7 +56,7 @@ let of_int_list = Array.of_list * #+end_example *) -(* [[file:../frozen_core.org::*Access][Access:2]] *) +(* [[file:~/QCaml/mo/frozen_core.org::*Access][Access:2]] *) let num_elec t = Array.fold_left ( + ) 0 t @@ -64,7 +64,7 @@ let num_mos t = (num_elec t) / 2 (* Access:2 ends here *) -(* [[file:../frozen_core.org::*Printers][Printers:2]] *) +(* [[file:~/QCaml/mo/frozen_core.org::*Printers][Printers:2]] *) let pp ppf t = Format.fprintf ppf "@[[|"; Array.iter (fun x -> Format.fprintf ppf "@,@[%d@]" x) t; diff --git a/mo/lib/frozen_core.mli b/mo/lib/frozen_core.mli index 8b4499f..f6e65bb 100644 --- a/mo/lib/frozen_core.mli +++ b/mo/lib/frozen_core.mli @@ -2,21 +2,21 @@ * * #+NAME: types *) -(* [[file:../frozen_core.org::types][types]] *) +(* [[file:~/QCaml/mo/frozen_core.org::types][types]] *) type kind = | All_electron | Small | Large (* types ends here *) -(* [[file:../frozen_core.org::*Type][Type:2]] *) +(* [[file:~/QCaml/mo/frozen_core.org::*Type][Type:2]] *) type t (* Type:2 ends here *) (* Creation *) -(* [[file:../frozen_core.org::*Creation][Creation:1]] *) +(* [[file:~/QCaml/mo/frozen_core.org::*Creation][Creation:1]] *) val make : kind -> Particles.Nuclei.t -> t val of_int_list : int list -> t @@ -26,7 +26,7 @@ val of_int_array : int array -> t (* Access *) -(* [[file:../frozen_core.org::*Access][Access:1]] *) +(* [[file:~/QCaml/mo/frozen_core.org::*Access][Access:1]] *) val num_elec : t -> int val num_mos : t -> int (* Access:1 ends here *) @@ -34,6 +34,6 @@ val num_mos : t -> int (* Printers *) -(* [[file:../frozen_core.org::*Printers][Printers:1]] *) +(* [[file:~/QCaml/mo/frozen_core.org::*Printers][Printers:1]] *) val pp : Format.formatter -> t -> unit (* Printers:1 ends here *) diff --git a/particles/lib/nuclei.ml b/particles/lib/nuclei.ml index 1b1839f..c40fdc0 100644 --- a/particles/lib/nuclei.ml +++ b/particles/lib/nuclei.ml @@ -1,4 +1,4 @@ -(* [[file:../nuclei.org::*Type][Type:2]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Type][Type:2]] *) open Common type t = (Element.t * Coordinate.t) array @@ -15,7 +15,7 @@ open Xyz_ast * | ~of_filename~ | Detects the type of file (xyz, z-matrix) and reads the file | *) -(* [[file:../nuclei.org::*Conversion][Conversion:2]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Conversion][Conversion:2]] *) let of_xyz_lexbuf lexbuf = let data = Xyz_parser.input Nuclei_lexer.read_all lexbuf @@ -126,7 +126,7 @@ let to_xyz_string t = * | ~large_core~ | Number of core electrons in the large core model | *) -(* [[file:../nuclei.org::*Query][Query:2]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Query][Query:2]] *) let formula t = let dict = Hashtbl.create 67 in Array.iter (fun (e,_) -> @@ -176,7 +176,7 @@ let large_core a = Array.fold_left (fun accu (e,_) -> accu + (Element.large_core e)) 0 a (* Query:2 ends here *) -(* [[file:../nuclei.org::*Printers][Printers:2]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Printers][Printers:2]] *) let pp ppf t = Format.fprintf ppf "@[%s@]" (to_string t) (* Printers:2 ends here *) diff --git a/particles/lib/nuclei.mli b/particles/lib/nuclei.mli index 98eb078..1949410 100644 --- a/particles/lib/nuclei.mli +++ b/particles/lib/nuclei.mli @@ -2,7 +2,7 @@ * * #+NAME: types *) -(* [[file:../nuclei.org::types][types]] *) +(* [[file:~/QCaml/particles/nuclei.org::types][types]] *) open Common type t = (Element.t * Coordinate.t) array @@ -11,7 +11,7 @@ type t = (Element.t * Coordinate.t) array (* Conversion *) -(* [[file:../nuclei.org::*Conversion][Conversion:1]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Conversion][Conversion:1]] *) val of_xyz_string : string -> t val to_xyz_string : t -> string val of_xyz_file : string -> t @@ -27,7 +27,7 @@ val of_filename : string -> t (* TODO Query *) -(* [[file:../nuclei.org::*Query][Query:1]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Query][Query:1]] *) val formula : t -> string val repulsion : t -> float val charge : t -> Charge.t @@ -38,6 +38,6 @@ val large_core : t -> int (* Printers *) -(* [[file:../nuclei.org::*Printers][Printers:1]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Printers][Printers:1]] *) val pp : Format.formatter -> t -> unit (* Printers:1 ends here *) diff --git a/particles/lib/nuclei_lexer.mll b/particles/lib/nuclei_lexer.mll index 390b551..128a4f7 100644 --- a/particles/lib/nuclei_lexer.mll +++ b/particles/lib/nuclei_lexer.mll @@ -4,7 +4,7 @@ * an xyz file. *) -(* [[file:../nuclei.org::*Lexer][Lexer:1]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Lexer][Lexer:1]] *) { open Xyz_parser } diff --git a/particles/lib/xyz_ast.mli b/particles/lib/xyz_ast.mli index a74f7fe..6bd214d 100644 --- a/particles/lib/xyz_ast.mli +++ b/particles/lib/xyz_ast.mli @@ -4,7 +4,7 @@ * an ~xyz_file~ data structure. *) -(* [[file:../nuclei.org::*Parser][Parser:2]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Parser][Parser:2]] *) open Common type nucleus = diff --git a/particles/test/nuclei.ml b/particles/test/nuclei.ml index c2c8bb3..7695a97 100644 --- a/particles/test/nuclei.ml +++ b/particles/test/nuclei.ml @@ -1,7 +1,7 @@ (* Tests *) -(* [[file:../nuclei.org::*Tests][Tests:1]] *) +(* [[file:~/QCaml/particles/nuclei.org::*Tests][Tests:1]] *) open Common open Particles open Alcotest diff --git a/perturbation/lib/mp2.ml b/perturbation/lib/mp2.ml index 443fe7f..a7ab890 100644 --- a/perturbation/lib/mp2.ml +++ b/perturbation/lib/mp2.ml @@ -1,21 +1,31 @@ -open Linear_algebra - -type t = float +(* [[file:~/QCaml/perturbation/mp2.org::*Type][Type:2]] *) +type t = { + energy : float ; + mo_basis : Mo.Basis.t ; + frozen_core : Mo.Frozen_core.t ; +} +(* Type:2 ends here *) + + + +(* | ~make~ | Creates an MP2 data structure | + * + * #+begin_example + * let mp2 = + * Mp2.make ~frozen_core:(Mo.Frozen_core.(make Small molecule)) mo_basis + * ;; + * - : Mp2.t : + * #+end_example *) + + +(* [[file:~/QCaml/perturbation/mp2.org::*Creation][Creation:2]] *) +open Linear_algebra + +let make_rmp2 mo_basis mo_class = + + let epsilon = Mo.Basis.mo_energies mo_basis in + let eri = Mo.Basis.ee_ints mo_basis in -let make ~frozen_core hf = - let mo_basis = - Mo.Basis.of_hartree_fock hf - in - let epsilon = - Mo.Basis.mo_energies mo_basis - in - let mo_class = - Mo.Class.cas_sd mo_basis ~frozen_core 0 0 - |> Mo.Class.to_list - in - let eri = - Mo.Basis.ee_ints mo_basis - in let inactives = List.filter (fun i -> match i with Mo.Class.Inactive _ -> true | _ -> false) mo_class @@ -24,39 +34,70 @@ let make ~frozen_core hf = match i with Mo.Class.Virtual _ -> true | _ -> false) mo_class in - let rmp2 () = - List.fold_left (fun accu b -> - match b with Mo.Class.Virtual b -> - let eps = -. (epsilon%.(b)) in + List.fold_left (fun accu b -> + match b with Mo.Class.Virtual b -> + let eps = -. (epsilon%.(b)) in + accu +. + List.fold_left (fun accu a -> + match a with Mo.Class.Virtual a -> + let eps = eps -. (epsilon%.(a)) in accu +. - List.fold_left (fun accu a -> - match a with Mo.Class.Virtual a -> - let eps = eps -. (epsilon%.(a)) in - accu +. - List.fold_left (fun accu j -> - match j with Mo.Class.Inactive j -> - let eps = eps +. epsilon%.(j) in - accu +. - List.fold_left (fun accu i -> - match i with Mo.Class.Inactive i -> - let eps = eps +. epsilon%.(i) in - let ijab = Four_idx_storage.get_phys eri i j a b - and abji = Four_idx_storage.get_phys eri a b j i in - let abij = ijab in - accu +. ijab *. ( abij +. abij -. abji) /. eps - | _ -> accu - ) 0. inactives - | _ -> accu - ) 0. inactives - | _ -> accu - ) 0. virtuals - | _ -> accu + List.fold_left (fun accu j -> + match j with Mo.Class.Inactive j -> + let eps = eps +. epsilon%.(j) in + accu +. + List.fold_left (fun accu i -> + match i with Mo.Class.Inactive i -> + let eps = eps +. epsilon%.(i) in + let ijab = Four_idx_storage.get_phys eri i j a b + and abji = Four_idx_storage.get_phys eri a b j i in + let abij = ijab in + accu +. ijab *. ( abij +. abij -. abji) /. eps + | _ -> accu + ) 0. inactives + | _ -> accu + ) 0. inactives + | _ -> accu ) 0. virtuals + | _ -> accu + ) 0. virtuals + + +let make ~frozen_core mo_basis = + + let mo_class = + Mo.Class.cas_sd mo_basis ~frozen_core 0 0 + |> Mo.Class.to_list in - - match Mo.Hartree_fock.kind hf with - | Mo.Hartree_fock.RHF -> rmp2 () - | _ -> failwith "Not implemented" + let energy = + match Mo.Basis.mo_type mo_basis with + | RHF -> make_rmp2 mo_basis mo_class + | ROHF -> Common.Util.not_implemented "ROHF MP2" + | UHF -> Common.Util.not_implemented "UHF MP2" + | _ -> invalid_arg "MP2 needs RHF or ROHF MOs" + in + { energy ; mo_basis ; frozen_core } +(* Creation:2 ends here *) + +(* | ~energy~ | Returns the MP2 energy | + * | ~mo_basis~ | Returns the MO basis on which the MP2 energy was computed | + * | ~frozen_core~ | Returns the frozen_core scheme used to compute the MP2 energy | + * + * #+begin_example + * + * #+end_example *) + + +(* [[file:~/QCaml/perturbation/mp2.org::*Access][Access:2]] *) +let energy t = t.energy +let mo_basis t = t.mo_basis +let frozen_core t = t.frozen_core +(* Access:2 ends here *) + +(* [[file:~/QCaml/perturbation/mp2.org::*Printers][Printers:2]] *) +let pp ppf t = + Format.fprintf ppf "@[E(MP2)=%f@]" t.energy +(* Printers:2 ends here *) diff --git a/perturbation/lib/mp2.mli b/perturbation/lib/mp2.mli new file mode 100644 index 0000000..5017a83 --- /dev/null +++ b/perturbation/lib/mp2.mli @@ -0,0 +1,29 @@ +(* Type *) + + +(* [[file:~/QCaml/perturbation/mp2.org::*Type][Type:1]] *) +type t +(* Type:1 ends here *) + +(* Creation *) + + +(* [[file:~/QCaml/perturbation/mp2.org::*Creation][Creation:1]] *) +val make : frozen_core:Mo.Frozen_core.t -> Mo.Basis.t -> t +(* Creation:1 ends here *) + +(* Access *) + + +(* [[file:~/QCaml/perturbation/mp2.org::*Access][Access:1]] *) +val energy : t -> float +val mo_basis : t -> Mo.Basis.t +val frozen_core : t -> Mo.Frozen_core.t +(* Access:1 ends here *) + +(* Printers *) + + +(* [[file:~/QCaml/perturbation/mp2.org::*Printers][Printers:1]] *) +val pp : Format.formatter -> t -> unit +(* Printers:1 ends here *) diff --git a/perturbation/mp2.org b/perturbation/mp2.org new file mode 100644 index 0000000..60dfa24 --- /dev/null +++ b/perturbation/mp2.org @@ -0,0 +1,180 @@ +#+begin_src elisp tangle: no :results none :exports none +(setq pwd (file-name-directory buffer-file-name)) +(setq name (file-name-nondirectory (substring buffer-file-name 0 -4))) +(setq lib (concat pwd "lib/")) +(setq testdir (concat pwd "test/")) +(setq mli (concat lib name ".mli")) +(setq ml (concat lib name ".ml")) +(setq test-ml (concat testdir name ".ml")) +(org-babel-tangle) +#+end_src + +* MP2 + :PROPERTIES: + :header-args: :noweb yes :comments both + :END: + +** Type + + #+begin_src ocaml :tangle (eval mli) +type t + #+end_src + + #+begin_src ocaml :tangle (eval ml) :exports none +type t = { + energy : float ; + mo_basis : Mo.Basis.t ; + frozen_core : Mo.Frozen_core.t ; +} + #+end_src + +** Creation + + #+begin_src ocaml :tangle (eval mli) +val make : frozen_core:Mo.Frozen_core.t -> Mo.Basis.t -> t + #+end_src + + | ~make~ | Creates an MP2 data structure | + + #+begin_example +let mp2 = + Mp2.make ~frozen_core:(Mo.Frozen_core.(make Small molecule)) mo_basis + ;; +- : Mp2.t : + #+end_example + + #+begin_src ocaml :tangle (eval ml) :exports none +open Linear_algebra + +let make_rmp2 mo_basis mo_class = + + let epsilon = Mo.Basis.mo_energies mo_basis in + let eri = Mo.Basis.ee_ints mo_basis in + + let inactives = + List.filter (fun i -> + match i with Mo.Class.Inactive _ -> true | _ -> false) mo_class + and virtuals = + List.filter (fun i -> + match i with Mo.Class.Virtual _ -> true | _ -> false) mo_class + in + + List.fold_left (fun accu b -> + match b with Mo.Class.Virtual b -> + let eps = -. (epsilon%.(b)) in + accu +. + List.fold_left (fun accu a -> + match a with Mo.Class.Virtual a -> + let eps = eps -. (epsilon%.(a)) in + accu +. + List.fold_left (fun accu j -> + match j with Mo.Class.Inactive j -> + let eps = eps +. epsilon%.(j) in + accu +. + List.fold_left (fun accu i -> + match i with Mo.Class.Inactive i -> + let eps = eps +. epsilon%.(i) in + let ijab = Four_idx_storage.get_phys eri i j a b + and abji = Four_idx_storage.get_phys eri a b j i in + let abij = ijab in + accu +. ijab *. ( abij +. abij -. abji) /. eps + | _ -> accu + ) 0. inactives + | _ -> accu + ) 0. inactives + | _ -> accu + ) 0. virtuals + | _ -> accu + ) 0. virtuals + + +let make ~frozen_core mo_basis = + + let mo_class = + Mo.Class.cas_sd mo_basis ~frozen_core 0 0 + |> Mo.Class.to_list + in + + let energy = + match Mo.Basis.mo_type mo_basis with + | RHF -> make_rmp2 mo_basis mo_class + | ROHF -> Common.Util.not_implemented "ROHF MP2" + | UHF -> Common.Util.not_implemented "UHF MP2" + | _ -> invalid_arg "MP2 needs RHF or ROHF MOs" + in + { energy ; mo_basis ; frozen_core } + #+end_src + +** Access + + #+begin_src ocaml :tangle (eval mli) +val energy : t -> float +val mo_basis : t -> Mo.Basis.t +val frozen_core : t -> Mo.Frozen_core.t + #+end_src + + | ~energy~ | Returns the MP2 energy | + | ~mo_basis~ | Returns the MO basis on which the MP2 energy was computed | + | ~frozen_core~ | Returns the frozen_core scheme used to compute the MP2 energy | + + #+begin_example + + #+end_example + + #+begin_src ocaml :tangle (eval ml) :exports none +let energy t = t.energy +let mo_basis t = t.mo_basis +let frozen_core t = t.frozen_core + #+end_src + + +** Printers + + #+begin_src ocaml :tangle (eval mli) +val pp : Format.formatter -> t -> unit + #+end_src + + #+begin_src ocaml :tangle (eval ml) :exports none +let pp ppf t = + Format.fprintf ppf "@[E(MP2)=%f@]" t.energy + #+end_src + +** Tests + + #+begin_src ocaml :tangle (eval test-ml) :exports none +open Alcotest +open Particles + +let wd = Common.Qcaml.root ^ Filename.dir_sep ^ "test" + +let tests = + [ "HF Water", `Quick, fun () -> + let nuclei = + wd ^ Filename.dir_sep ^ "water.xyz" + |> Nuclei.of_xyz_file + in + let basis_filename = + wd ^ Filename.dir_sep ^ "cc-pvdz" + in + let ao_basis = + Ao.Basis.of_nuclei_and_basis_filename ~kind:`Gaussian + ~cartesian:false ~nuclei basis_filename + in + + let simulation = Simulation.make ~nuclei ao_basis in + + let hf = Mo.Hartree_fock.make ~guess:`Huckel simulation in + Format.printf "%a" (Mo.Hartree_fock.pp) hf; + check (float 2.e-10) "Energy" (-76.0267987005) (Mo.Hartree_fock.energy hf); + + let mo_basis = Mo.Basis.of_hartree_fock hf in + + let frozen_core = Mo.Frozen_core.(make Small nuclei) in + + let e_mp2 = Perturbation.Mp2.make ~frozen_core mo_basis in + + check (float 1.e-9) "MP2" (-0.2016211415) (e_mp2) + ] + + #+end_src + diff --git a/perturbation/test/mp2.ml b/perturbation/test/mp2.ml index efe3cdd..dc0c022 100644 --- a/perturbation/test/mp2.ml +++ b/perturbation/test/mp2.ml @@ -1,3 +1,7 @@ +(* Tests *) + + +(* [[file:~/QCaml/perturbation/mp2.org::*Tests][Tests:1]] *) open Alcotest open Particles @@ -16,12 +20,19 @@ let tests = Ao.Basis.of_nuclei_and_basis_filename ~kind:`Gaussian ~cartesian:false ~nuclei basis_filename in + let simulation = Simulation.make ~nuclei ao_basis in + let hf = Mo.Hartree_fock.make ~guess:`Huckel simulation in Format.printf "%a" (Mo.Hartree_fock.pp) hf; check (float 2.e-10) "Energy" (-76.0267987005) (Mo.Hartree_fock.energy hf); - let e_mp2 = Perturbation.Mp2.make ~frozen_core:true hf in - Printf.printf "%s\n" (string_of_float e_mp2); + + let mo_basis = Mo.Basis.of_hartree_fock hf in + + let frozen_core = Mo.Frozen_core.(make Small nuclei) in + + let e_mp2 = Perturbation.Mp2.make ~frozen_core mo_basis in + check (float 1.e-9) "MP2" (-0.2016211415) (e_mp2) ] - +(* Tests:1 ends here *) diff --git a/simulation/lib/simulation.ml b/simulation/lib/simulation.ml index c15e245..4dcc150 100644 --- a/simulation/lib/simulation.ml +++ b/simulation/lib/simulation.ml @@ -1,10 +1,10 @@ -(* [[file:../simulation.org::*Simulation][Simulation:2]] *) +(* [[file:~/QCaml/simulation/simulation.org::*Simulation][Simulation:2]] *) open Common open Particles open Operators (* Simulation:2 ends here *) -(* [[file:../simulation.org::*Type][Type:2]] *) +(* [[file:~/QCaml/simulation/simulation.org::*Type][Type:2]] *) type t = { charge : Charge.t; electrons : Electrons.t; @@ -24,7 +24,7 @@ type t = { * | ~operators~ | List of extra operators (range-separation, f12, etc) | *) -(* [[file:../simulation.org::*Access][Access:2]] *) +(* [[file:~/QCaml/simulation/simulation.org::*Access][Access:2]] *) let nuclei t = t.nuclei let charge t = t.charge let electrons t = t.electrons @@ -41,7 +41,7 @@ let operators t = t.operators * - operators : ~[]~ *) -(* [[file:../simulation.org::*Creation][Creation:2]] *) +(* [[file:~/QCaml/simulation/simulation.org::*Creation][Creation:2]] *) let make ?(multiplicity=1) ?(charge=0) @@ -65,7 +65,7 @@ let make { charge ; nuclei ; electrons ; ao_basis ; operators} (* Creation:2 ends here *) -(* [[file:../simulation.org::*Printers][Printers:2]] *) +(* [[file:~/QCaml/simulation/simulation.org::*Printers][Printers:2]] *) let pp ppf t = let formula = Nuclei.formula t.nuclei in let n_aos = Ao.Basis.size t.ao_basis in diff --git a/simulation/lib/simulation.mli b/simulation/lib/simulation.mli index 6c55e95..74d51ff 100644 --- a/simulation/lib/simulation.mli +++ b/simulation/lib/simulation.mli @@ -7,7 +7,7 @@ * * #+NAME: open *) -(* [[file:../simulation.org::open][open]] *) +(* [[file:~/QCaml/simulation/simulation.org::open][open]] *) open Common open Particles open Operators @@ -17,14 +17,14 @@ open Operators * * #+NAME: types *) -(* [[file:../simulation.org::types][types]] *) +(* [[file:~/QCaml/simulation/simulation.org::types][types]] *) type t (* types ends here *) (* Access *) -(* [[file:../simulation.org::*Access][Access:1]] *) +(* [[file:~/QCaml/simulation/simulation.org::*Access][Access:1]] *) val nuclei : t -> Nuclei.t val charge : t -> Charge.t val electrons : t -> Electrons.t @@ -36,7 +36,7 @@ val operators : t -> Operator.t list (* Creation *) -(* [[file:../simulation.org::*Creation][Creation:1]] *) +(* [[file:~/QCaml/simulation/simulation.org::*Creation][Creation:1]] *) val make : ?multiplicity:int -> ?charge:int -> ?operators:Operator.t list-> nuclei:Nuclei.t -> Ao.Basis.t -> t @@ -45,6 +45,6 @@ val make : ?multiplicity:int -> ?charge:int -> (* Printers *) -(* [[file:../simulation.org::*Printers][Printers:1]] *) +(* [[file:~/QCaml/simulation/simulation.org::*Printers][Printers:1]] *) val pp : Format.formatter -> t -> unit (* Printers:1 ends here *) diff --git a/top/lib/install_printers.ml b/top/lib/install_printers.ml index ca039ca..0c0b448 100644 --- a/top/lib/install_printers.ml +++ b/top/lib/install_printers.ml @@ -1,4 +1,4 @@ -(* [[file:../install_printers.org::*Intall printers][Intall printers:3]] *) +(* [[file:~/QCaml/top/install_printers.org::*Intall%20printers][Intall printers:3]] *) let printers = [ "Common.Angular_momentum.pp" ;