StageYann/Boys.ipynb

10 KiB

None <html> <head> </head>

Rotation d'orbitales

On peut écrire une matrice de rotation $R$ comme $$ R = \exp(X) $$ où X est une matrice réelle anti-symétrique ($X_{ij} = -X_{ji}$) où $X_{ij}$ est la valeurs de l'angle de la rotation entre $i$ et $j$. Par exemple: $$ R = \left( \begin{array}{cc} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{array} \right) = \exp \left( \begin{array}{cc} 0 & \theta \

  • \theta & 0 \end{array} \right) $$

D'abord on diagonalise $X^2$ : $$ X^2 = W(-\tau^2) W^\dagger. $$ Ensuite, $R$ peut être écrit comme $$ R = W \cos(\tau) W^\dagger + W \tau^{-1} \sin (\tau) W^\dagger X $$

TODO

Ecrire une fonction qui calcule $R$ a partir de $X$. Tu vas avoir besoin de Lacaml:

Pour diagonaliser une matrice : syev

Pour multiplier des matrices : gemm

Localisation de Boys

$N$ orthonormal molecular orbitals $$ \phi_i({\bf r})= \sum_{k=1}^N c_{ik} \chi_k $$ $$ {\cal B}_{2|4} = \sum_{i=1}^N \langle \phi_i | ( {\bf \vec{r}} - \langle \phi_i| {\bf \vec{r}} | \phi_i …\rangle)^{2|4} | \phi_i \rangle $$ $$ {\cal B}_2= \sum_{i=1}^N \big[ \langle x^2 \rangle_i - \langle x \rangle^2_i + \langle y^2 \rangle_i - …\langle y \rangle^2_i + \langle z^2 \rangle_i - \langle z \rangle^2_i \big] $$ $$ {\cal B}2 = \sum{i=1}^N \big[ \langle x^4 \rangle_i - 4 \langle x^3 \rangle_i \langle x \rangle_i

  • 6 \langle x^2 \rangle_i \langle x \rangle^2_i
    • 3 \langle x \rangle^4_i \big] + \big[ ...y...] + \big[ ...z...] $$ Minimization of ${\cal B}$ with respect to an arbitrary rotation $R$ $$ \langle R \phi_i x^n R \phii \rangle = \sum{k,l=1}^N R{ik} R{il} \langle \phi_k| x^n | \phil …\rangle= $$ $$ \sum{k,l=1}^N R{ik} R{il} \sum{m,o=1}^N c{km} c_{ln} \langle \chi_m | x^n |\chio \rangle $$ We need to compute $$ S^x{n;mo}= \langle \chi_m | x^n |\chi_o \rangle $$

Rotation de deux orbitales

Rotation of angle $\theta$ $$ \tilde{\phi}_1 = cos\theta \phi_1 -sin\theta \phi_2 $$ $$ \tilde{\phi}_2 = sin\theta \phi_1 +cos\theta \phi_2 $$ Let us note $$ {\cal B}_x(\theta) = \langle x^2 \rangle_{\tilde{1}} - \langle x \rangle^2_{\tilde{1}} + \langle x^2 \rangle_{\tilde{2}} - \langle x \rangle^2_{\tilde{2}} $$ and \begin{eqnarray} A^x_{ij} & = & \langle \phi_i| x^2 | \phi_j \rangle \\ B^x_{ij} & = & \langle \phi_i| x | \phi_j \rangle \;\; i,j=1,2 \end{eqnarray} We have $$ {\cal B}_x(\theta) = A^x_{11}+A^x_{22} - ({\tilde B}^{x2}_{11} + {\tilde B}^{x2}_{22}) $$ with $$ {\tilde B}^{x2}_{11}= (cos^2\theta B^x_{11} + sin^2\theta B^x_{22} - sin2\theta B^x_{12})^2 $$ $$ {\tilde B}^{x2}_{22}= (sin^2\theta B^x_{11} + cos^2\theta B^x_{22} + sin2\theta B^x_{12})^2 $$ $$ {\cal B}(\theta)= {\cal B}_x(\theta)+{\cal B}_y(\theta)+{\cal B}_z(\theta)=(x) + (y)+(z) $$ with $$ {\cal B}x(\theta)= A^x{11}+A^x_{22}

  • [(cos^4\theta+ sin^4\theta)({B^x{11}}^2+ {B^x{22}}^2 ) $$ $$
  • 2 sin^2 2\theta {B^x_{12}}^2
  • 2 sin 2\theta cos 2\theta (({B^x{22}} -{B^x{11}} ) {B^x_{12}}] $$ and idem for $y$ and $z$. Using the fact that $$ cos^4\theta+ sin^4\theta= \frac{1}{4} ( 3 + cos4\theta) $$ $$ {\cal B}x(\theta)= A^x{11}+A^x_{22}
  • [ \frac{1}{4} ( 3 + cos4\theta)({B^x{11}}^2+ {B^x{22}}^2 ) $$ $$
  • (1 -cos 4\theta) {B^x_{12}}^2
  • sin 4\theta (({B^x{22}} -{B^x{11}} ) {B^x{12}}] $$ Finally, we get \begin{equation} {\cal B}(\theta)= {\cal B}(0) + \frac{1}{4} [(1-cos4\theta)\beta+sin4\theta \gamma] \end{equation} where $$ {\cal B}(0)= A^x{11}+A^x{22} -((B^{x}{11})^2+(B^{x}{22})^2) + [...y...] + [...z...] $$ $$ \beta= (B^x{11}-B^x{22})^2 - 4 {(B^x{12})}^2 + [...y...] + [...z...] $$ and $$ \gamma= 4 B^x{12} (B^{x}{11}-B^x_{22}) + [...y...] + [...z...] $$ Let us compute the derivative; we get $$ \frac{\partial {\cal B}(\theta)}{\partial \theta} = \beta sin4\theta
  • \gamma cos4\theta $$ Extrema of ${\cal B}(\theta)$ \begin{equation} tg4\theta= -\frac{\gamma}{\beta} \end{equation} There are four extrema: $$ 4\theta; \;\; 4\theta +\pi; \;\; 4\theta+ 2\pi; \;\; 4\theta+ 3\pi $$ Value of the second derivative of $\cal{B}$ at the extrema Value of $\cal{B}$ at the extrema \begin{equation} \frac{\partial^2 B(\theta)}{\partial \theta^2}= 4 cos4\theta \frac{\beta^2 + \gamma^2}{\beta} \end{equation} There are two minima and two maxima since $cos4\theta= -cos4(\theta+\pi)= -cos4(\theta+2\pi)=-cos4(\theta+3\pi)$. Value of $\cal{B}$ at the extrema \begin{equation} {\cal B}(\theta)= {\cal B}(0) + \frac{1}{4} (\beta -\frac{\beta^2 + \gamma^2}{\beta} {cos4\theta}) \end{equation}
In [ ]:
#require "lacaml.top";;
#require "alcotest";;
#require "str";;
#require "bigarray";;
#require "zarith";;
#require "getopt";;
open Lacaml.D
In [ ]:
(*
NB: il faut que je change les noms des matrices car ce n'est pas toujours clair
*)

(* Construction de la matrice X n par n *)
let n =3  
let ran=Mat.random ~range:1. ~from:0. n n;; (* Construction d'une matrice random n*n *)

(* Antisymétrisation de la matrice et 0 sur la diagonale *)
let antisym = Mat.init_cols n n (fun i j -> if i>j then -. ran.{i,j} else ran.{j,i});;

(* 0 sur la diagonale -> X *)
let m = Mat.init_cols n n (fun i j -> if i=j then 0. else antisym.{i,j});; 

(* Fonction 2 en un *)
(*
let x = Mat.init_cols n n (fun i j -> if i=j then 0.
 else if i>j then -. ran.{i,j} else ran.{j,i});;
 *)
In [ ]:
(* Mise au carré de la matrice : X -> X² *)
let mm = gemm m m;;

(* Copie de mm qui va être écrasée : X *)
let copie_mm = lacpy mm;;

(* Diagonalisation de X² *)
let diag = syev mm;;

copie_mm;; (* Copie de la matrice avant diagonalisation *)
mm;; (* Matrice avec les eigenvectors -> W *)
diag;; (* Vecteur contenant les eigenvalues *)
In [ ]:
(* Passage de -tau² à tau² *)
let square_tau= Vec.abs diag;;

(* Passage de tau² à tau *)
let tau = Vec.sqrt square_tau;;

(* Passage du vecteur tau à la matrice avec les valeurs propres sur la diagonale *)
let m_tau = Mat.init_cols n n (fun i j -> if i=j then tau.{i} else 0.)
In [ ]:
(* Calcul de cos tau *)
let cos_tau = Mat.cos m_tau;;

(* Calcul de sin tau *)
let sin_tau = Mat.sin m_tau;; (* NB: Si on applique sin au vecteur tau il faut ensuité créer une matrice avec
des 1 en éléments extra diagonaux, c'est peut être mieux de faire comme ça *)

(* Calcul de la transposée de W (mm) *)
let transpose_mm = Mat.transpose_copy mm;; 
mm;;(* Vérification *) (*OK*)

(* Calcul de tau^-1 *)
(*
let tau_1 = (* Je suis en train de chercher comment le calculer *)
*)
In [ ]:
(* Calcul de R *)
(*
let r = gemm mm (gemm cos_tau transpose_mm) +  gemm( mm gemm(tau_1 gemm( sin_tau (gemm transpose_mm m))))
*)
(* Ne peut pas fonctionner -> + (je n'ai pas trouvé de fonction ?)  et il manque des calculs
Il faut surement découper ce calcul aussi ? *)
</html>