diff --git a/Notebooks/F12_matrix.ipynb b/Notebooks/F12_matrix.ipynb index 7c9b946..5ee5b29 100644 --- a/Notebooks/F12_matrix.ipynb +++ b/Notebooks/F12_matrix.ipynb @@ -235,8 +235,10 @@ ] }, { - "cell_type": "raw", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "let () = ignore @@ MOBasis.f12_ints aux_basis\n", "let () = ignore @@ MOBasis.two_e_ints aux_basis" @@ -246,14 +248,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Determinant-based functions" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Integrals" + "## Integral-based functions" ] }, { @@ -286,30 +281,117 @@ "source": [ "let cancel_singles = false \n", "\n", - "let f12_integrals mo_basis =\n", - "\n", + "let mos_cabs = \n", + " Util.list_range (mo_num+1) aux_num\n", " \n", - " let two_e_ints = MOBasis.f12_ints mo_basis in\n", - " let f2 i j k l s s' =\n", - " let ijkl = F12.get_phys two_e_ints i j k l in\n", - " let ijlk = F12.get_phys two_e_ints i j l k in\n", - " if s' <> s then\n", - " ijkl \n", - " else\n", - " (ijkl -. ijlk) \n", + "let mos_in = \n", + " Util.list_range 1 mo_num\n", + "\n", + "let mos_a k =\n", + " Determinant.alfa k\n", + " |> Spindeterminant.to_list\n", + " \n", + "let mos_b k =\n", + " Determinant.beta k\n", + " |> Spindeterminant.to_list\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### H integrals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "let h_one =\n", + " let h = \n", + " MOBasis.one_e_ints aux_basis\n", + " in fun i j _ -> h.{i,j}\n", + " \n", + "let h_two = \n", + " let two_e_ints = MOBasis.two_e_ints aux_basis in\n", + " let h2 i j k l (s:Spin.t) (s':Spin.t) =\n", + " if s' <> s then\n", + " ERI.get_phys two_e_ints i j k l\n", + " else\n", + " (ERI.get_phys two_e_ints i j k l) -. \n", + " (ERI.get_phys two_e_ints i j l k)\n", " in\n", - " ( (fun _ _ _ -> 0.),\n", - " (if cancel_singles then\n", - " (fun i j k l s s' ->\n", - " (* Required to cancel out single excitations *)\n", - " if (i=k && j<>l) || (j=l && i<>k) then\n", - " 0.\n", - " else\n", - " f2 i j k l s s'\n", - " ) \n", - " else f2),\n", - " None\n", - " )\n", + " h2\n", + "\n", + " \n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### F12 integrals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "let f_two = \n", + " let two_e_ints = MOBasis.f12_ints aux_basis in\n", + " let f2 i j k l (s:Spin.t) (s':Spin.t) =\n", + " if s' <> s then\n", + " 0.5 *. F12.get_phys two_e_ints i j k l\n", + " else\n", + " 0.5 *. (\n", + " (F12.get_phys two_e_ints i j k l) -. \n", + " (F12.get_phys two_e_ints i j l k) )\n", + " in\n", + " let f3 i j k l (s:Spin.t) (s':Spin.t) = \n", + " if (i=k && j<>l) || (j=l && i<>k) then\n", + " 0.\n", + " else\n", + " f2 i j k l s s'\n", + " in\n", + " if cancel_singles then f3 else f2\n", + "\n", + "let f_one = fun _ _ _ -> 0.\n", + "\n", + "(*\n", + "let f_two = h_two\n", + "\n", + "let f_one = h_one\n", + "*)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Determinant-based functions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Integrals" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "let f12_integrals mo_basis =\n", + " ( f_one, f_two, None )\n", "\n", "let h_ij mo_basis ki kj =\n", " let integrals =\n", @@ -353,7 +435,7 @@ "outputs": [], "source": [ "let is_a_double det_space =\n", - " let mo_class = DeterminantSpace.mo_class det_space in\n", + " let mo_class = DeterminantSpace.mo_class det_space in\n", " let mo_num = Array.length @@ MOClass.mo_class_array mo_class in\n", " let m l =\n", " List.fold_left (fun accu i ->\n", @@ -423,7 +505,8 @@ "let ci = CI.make ~n_states:state in_space\n", "\n", "let ci_coef, ci_energy = Lazy.force ci.eigensystem \n", - "\n" + "\n", + "let _ = print_newline () \n" ] }, { @@ -438,7 +521,7 @@ "metadata": {}, "source": [ "let p12 det_space =\n", - " let mo_class = DeterminantSpace.mo_class det_space in\n", + " let mo_class = DeterminantSpace.mo_class det_space in\n", " let mo_num = Array.length @@ MOClass.mo_class_array mo_class in\n", " let m l =\n", " List.fold_left (fun accu i ->\n", @@ -477,20 +560,6 @@ " \n" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Integral-based functions" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": {}, @@ -518,9 +587,7 @@ }, { "cell_type": "raw", - "metadata": { - "collapsed": true - }, + "metadata": {}, "source": [ "let m_H_aux, m_F_aux = \n", " \n", @@ -573,10 +640,6 @@ "metadata": {}, "outputs": [], "source": [ - "let mos_cabs = \n", - " Util.list_range (mo_num+1) aux_num\n", - "\n", - "\n", "let generate_alphas ki kj exc cabs l r =\n", " (* Check input excitation degree *)\n", " let d = Determinant.degree ki kj in\n", @@ -637,7 +700,7 @@ " List.map (fun particle' ->\n", " Some (Determinant.double_excitation Spin.Alfa hole particle Spin.Beta hole' particle' ki)\n", " ) mos_cabs\n", - " ) mos_a \n", + " ) mos_b \n", " ) mos_cabs\n", " ) mos_a\n", " ]\n", @@ -646,6 +709,7 @@ " |> List.concat\n", " |> List.concat\n", " |> Util.list_some\n", + " |> List.filter (fun x -> Determinant.is_none x = false)\n", " |> List.map (fun x -> Determinant.set_phase Phase.Pos x)\n", " in\n", "\n", @@ -703,45 +767,58 @@ " \n", " \n", "let compute_HaaF ki alphas kj =\n", - " List.fold_left (fun accu alpha -> accu\n", + " List.fold_left (fun accu alpha -> accu\n", " +. h_ij aux_basis ki alpha\n", " *. f_ij aux_basis alpha kj\n", " ) 0. alphas\n" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "let ki = det_I.(0) \n", - "let kj = det_I.(0)\n", - "let alphas =\n", - " generate_alphas ki kj 0 1 1 1\n", + "let check n integral_value exc cabs lexc rexc =\n", + " let det_list =\n", + " match n with\n", + " | 0 -> det_I\n", + " | n -> Array.sub det_I 0 n\n", + " in\n", + " Printf.printf \"Checking...\\n%!\";\n", + " let result =\n", + " Array.mapi (fun i ki -> \n", + " Array.mapi (fun j kj -> \n", + " if i > j then 0. else\n", + " if Determinant.degree ki kj <> exc then 0. else\n", + " let alphas = generate_alphas ki kj exc cabs lexc rexc in\n", + " let det_value =\n", + " compute_HaaF ki alphas kj\n", + " in\n", + " integral_value ki kj -. det_value \n", + " ) det_list\n", + " ) det_list\n", + " |> Array.to_list\n", + " |> Array.concat\n", + " in\n", + " let error = \n", + " Array.fold_left (fun accu x -> accu +. x *. x) 0. result\n", + " /. (float_of_int @@ Array.length result)\n", + " in\n", + " if error < epsilon_float then\n", + " Printf.printf \"OK: %e\\n%!\" error\n", + " else\n", + " Printf.printf \"Failed: %e\\n%!\" error\n", "\n", - "let _ =\n", - " compute_HaaF ki alphas kj\n", - "\n", - " \n", - "(*\n", - "|> SetDet.iter (fun x -> Format.printf \"@[%a@]@;\" (Determinant.pp 24) x)\n", - "*)" + " " ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], - "source": [] + "source": [ + "# 0 2 22" + ] }, { "cell_type": "code", @@ -751,14 +828,20 @@ }, "outputs": [], "source": [ - "String.concat" + "png_image \"0_2_22.png\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# 0 1 11" + "$i,j$ : orbital indices of MOs occupied in $|I\\rangle$.\n", + "\n", + "$$\n", + "\\sum_{j} \\sum_{i accu +. \n", + " List.fold_left (fun accu i -> accu +. \n", + " List.fold_left (fun accu b -> accu +. \n", + " List.fold_left (fun accu a ->\n", + " accu +. h_two i j a b s s' *. f_two a b i j s s'\n", + " ) 0. mos_cabs\n", + " ) 0. mos_cabs\n", + " ) 0. (mos_a ki)\n", + " ) 0. (mos_b ki)\n", + " +.\n", + " (* Alpha-Alpha / Beta-Beta *)\n", + " List.fold_left (fun accu (mos,s) -> \n", + " let s' = s in accu +.\n", + " List.fold_left (fun accu j -> accu +. \n", + " List.fold_left (fun accu i -> accu +. \n", + " if i < j then accu else\n", + " List.fold_left (fun accu b -> accu +. \n", + " List.fold_left (fun accu a -> \n", + " if b > a then accu else\n", + " accu +. h_two i j a b s s' *. f_two a b i j s s'\n", + " ) 0. mos_cabs\n", + " ) 0. mos_cabs\n", + " ) 0. mos\n", + " ) 0. mos\n", + " ) 0. [ (mos_a ki,Spin.Alfa) ; (mos_b ki,Spin.Beta)]\n", + " \n", + "let _ =\n", + " check 10 integral_value 0 2 2 2\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 1 2 22" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "png_image \"1_2_22.png\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$|J\\rangle = \\hat{T}_{i}^{k}|I\\rangle$\n", + "\n", + "$j$ : orbital indices of MOs occupied both in $|I\\rangle$ and $|J\\rangle$.\n", + "\n", + "\n", + "$$\n", + "\\sum_{j} \\sum_{b}\\sum_{a\n", + " hole, particle, spin, phase\n", + " | _ -> assert false\n", + " in\n", + " \n", + " let mos, mos' =\n", + " match s with\n", + " | Spin.Alfa -> mos_a ki, mos_b ki\n", + " | Spin.Beta -> mos_b ki, mos_a ki\n", + " in\n", + "\n", + " (* Alpha-Beta *)\n", + " let s' = Spin.other s in\n", + " List.fold_left (fun accu j -> accu +. \n", + " List.fold_left (fun accu b -> accu +. \n", + " List.fold_left (fun accu a ->\n", + " accu +. h_two h j a b s s' *. f_two a b p j s s'\n", + " ) 0. mos_cabs\n", + " ) 0. mos_cabs\n", + " ) 0. mos' \n", + " +.\n", + " (* Alpha-Alpha / Beta-Beta *)\n", + " let s' = s in \n", + " List.fold_left (fun accu j -> accu +. \n", + " List.fold_left (fun accu b -> accu +. \n", + " List.fold_left (fun accu a -> \n", + " if b > a then accu else\n", + " accu +. h_two h j a b s s' *. f_two a b p j s s'\n", + " ) 0. mos_cabs\n", + " ) 0. mos_cabs\n", + " ) 0. mos \n", + " \n", + "\n", + "let _ = check 10 integral_value 1 2 2 2" ] }, { @@ -796,5 +987,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }