1+ # -*- coding: utf-8 -*-
2+ from pydft import MoleculeBuilder , DFT
3+ from pyqint import FosterBoys , PyQInt
4+ import matplotlib .pyplot as plt
5+ import numpy as np
6+ import os
7+
8+ def main ():
9+ mol = MoleculeBuilder ().from_name ("CO" )
10+ dft = DFT (mol , basis = 'sto3g' )
11+ res = dft .scf (1e-4 , verbose = False )
12+
13+ cgfs = res ['cgfs' ]
14+ orbe = res ['orbe' ]
15+ coeff = res ['orbc' ]
16+
17+ # visualize orbitals
18+ fig , ax = plt .subplots (2 ,5 , figsize = (12 , 5 ), dpi = 300 )
19+ sz = 3
20+ for i in range (0 ,2 ):
21+ for j in range (0 ,5 ):
22+ dens = plot_wavefunction (cgfs , coeff [:,i * 5 + j ], sz = sz )
23+ limit = max (abs (np .min (dens )), abs (np .max (dens )) )
24+ im = ax [i ,j ].contourf (dens , origin = 'lower' ,
25+ extent = [- sz , sz , - sz , sz ], cmap = 'PiYG' , vmin = - limit , vmax = limit ,
26+ levels = 15 )
27+ im = ax [i ,j ].contour (dens , origin = 'lower' , colors = 'black' ,
28+ extent = [- sz , sz , - sz , sz ], vmin = - limit , vmax = limit ,
29+ levels = 15 )
30+ ax [i ,j ].set_xlabel ('x [Bohr]' )
31+ ax [i ,j ].set_ylabel ('z [Bohr]' )
32+ ax [i ,j ].set_aspect ('equal' , adjustable = 'box' )
33+ ax [i ,j ].set_xticks (np .linspace (- 3 ,3 , 7 ))
34+ ax [i ,j ].set_yticks (np .linspace (- 3 ,3 , 7 ))
35+ ax [i ,j ].grid (linestyle = '--' , alpha = 0.5 )
36+ ax [i ,j ].set_title (r'$\psi_{%i}$ ($\epsilon_{%i}$ = %6.4f Ht)' %
37+ (i * 5 + j + 1 , i * 5 + j + 1 , orbe [i * 5 + j ]))
38+ plt .tight_layout ()
39+ plt .savefig (os .path .join (os .path .dirname (__file__ ), "co_contour_canonical.png" ))
40+
41+ resfb = FosterBoys (res ).run ()
42+ cgfs = resfb ['cgfs' ]
43+ orbe = resfb ['orbe' ]
44+ coeff = resfb ['orbc' ]
45+
46+ # visualize orbitals
47+ fig , ax = plt .subplots (2 ,5 , figsize = (12 , 5 ), dpi = 300 )
48+ sz = 3
49+ for i in range (0 ,2 ):
50+ for j in range (0 ,5 ):
51+ dens = plot_wavefunction (cgfs , coeff [:,i * 5 + j ], sz = sz )
52+ limit = max (abs (np .min (dens )), abs (np .max (dens )) )
53+ im = ax [i ,j ].contourf (dens , origin = 'lower' ,
54+ extent = [- sz , sz , - sz , sz ], cmap = 'PiYG' , vmin = - limit , vmax = limit ,
55+ levels = 15 )
56+ im = ax [i ,j ].contour (dens , origin = 'lower' , colors = 'black' ,
57+ extent = [- sz , sz , - sz , sz ], vmin = - limit , vmax = limit ,
58+ levels = 15 )
59+ ax [i ,j ].set_xlabel ('x [Bohr]' )
60+ ax [i ,j ].set_ylabel ('z [Bohr]' )
61+ ax [i ,j ].set_aspect ('equal' , adjustable = 'box' )
62+ ax [i ,j ].set_xticks (np .linspace (- 3 ,3 , 7 ))
63+ ax [i ,j ].set_yticks (np .linspace (- 3 ,3 , 7 ))
64+ ax [i ,j ].grid (linestyle = '--' , alpha = 0.5 )
65+ ax [i ,j ].set_title (r'$\psi_{%i}$ ($\epsilon_{%i}$ = %6.4f Ht)' %
66+ (i * 5 + j + 1 , i * 5 + j + 1 , orbe [i * 5 + j ]))
67+ plt .tight_layout ()
68+ plt .savefig (os .path .join (os .path .dirname (__file__ ), "co_contour_localized.png" ))
69+
70+ def plot_wavefunction (cgfs , coeff , sz = 3.5 ):
71+ # build integrator
72+ integrator = PyQInt ()
73+
74+ # build grid
75+ x = np .linspace (- sz , sz , 251 )
76+ z = np .linspace (- sz , sz , 251 )
77+ xx , zz = np .meshgrid (x ,z )
78+ yy = np .zeros (len (x ) * len (z ))
79+ grid = np .vstack ([xx .flatten (), yy , zz .flatten ()]).reshape (3 ,- 1 ).T
80+ res = integrator .plot_wavefunction (grid , coeff , cgfs ).reshape ((len (z ), len (x )))
81+
82+ return res
83+
84+ if __name__ == '__main__' :
85+ main ()
0 commit comments