1 /* Ergo, version 3.8, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2019 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
30 /** @file SCF_unrestricted.h
31 
32     @brief Class for self-consistent field (SCF) procedure;
33     spin-unrestricted case.
34 
35     @author: Elias Rudberg <em>responsible</em>.
36 */
37 
38 #ifndef SCF_UNRESTRICTED_HEADER
39 #define SCF_UNRESTRICTED_HEADER
40 
41 #include "SCF_general.h"
42 
43 
44 class SCF_unrestricted : public SCF_general
45 {
46  public:
47 
48   // Constructor
49   SCF_unrestricted(const Molecule& molecule_,
50 		   const Molecule& extraCharges_,
51 		   const BasisInfoStruct & basisInfo_,
52 		   const IntegralInfo & integralInfo_,
53 		   const char* guessDmatFileName_,
54 		   const JK::Params& J_K_params_,
55 		   const Dft::GridParams& gridParams_,
56 		   const SCF::Options& scfopts,
57 		   const SCF::MatOptions& matOpts,
58 		   ergo_real threshold_integrals_1el_input,
59 		   int alpha_beta_diff_input);
60 
61   // Destructor
62   ~SCF_unrestricted();
63 
64   void get_Fock_matrices(symmMatrix & FockMatrix_a, symmMatrix & FockMatrix_b);
65   void get_no_of_electrons(int & noOfElectrons_a, int & noOfElectrons_b);
66 
67  private:
68   void initialize_matrices();
69   void check_params();
70   void get_starting_guess_density();
71   void initialize_homo_lumo_limits();
72   void write_matrices_to_file();
73   void get_2e_part_and_energy();
74   void output_sparsity_S_F_D(SCF_statistics & stats);
75   void calculate_energy();
76   void get_FDSminusSDF();
77   void get_error_measure();
78   void add_to_DIIS_list();
79   void update_best_fock_so_far();
80   void combine_old_fock_matrices(ergo_real stepLength);
81   void use_diis_to_get_new_fock_matrix();
82   void clear_diis_list();
83   void clear_error_matrices();
84   void save_current_fock_as_fprev();
85   void get_new_density_matrix();
86   void write_density_to_file();
87   void save_final_potential();
88   void add_random_disturbance_to_starting_guess();
89   void output_expected_values_pos_operator();
90   void output_density_images();
91   void output_density_images_orbital(generalVector &eigVec, const std::string &filename_id);
92   void write_diag_dens_to_file();
93   void report_final_results();
94   void save_density_as_prevdens();
95   void update_subspace_diff();
96   void disturb_fock_matrix(ergo_real subspaceError);
97   void disturb_dens_matrix(ergo_real subspaceError);
98   void do_spin_flip(int atomCount);
99   void disturb_dens_matrix_exact(ergo_real subspaceError);
100   void save_full_matrices_for_matlab();
101   void report_density_difference();
102   void create_mtx_files_F(int const scfIter);
103   void create_mtx_files_D(int const scfIter);
104   void create_eigenvalues_files() const;
105   void create_eigenvectors_files() const;
106   void create_eigvec_file(const generalVector &eigVec_alpha,
107 			  const generalVector &eigVec_beta,
108 			  const char *vector_name,
109 			  const char *filename_id) const;
110   void create_gabedit_file() const;
111   void compute_dipole_moment();
112   void do_mulliken_pop_stuff();
113   void compute_gradient_fixeddens();
114 
115   void get_S2(ergo_real & S2_exact, ergo_real & S2);
116 
117   symmMatrix densityMatrix_alpha;
118   symmMatrix densityMatrix_beta;
119   symmMatrix FockMatrix_alpha;
120   symmMatrix FockMatrix_beta;
121   symmMatrix Fprev_alpha;
122   symmMatrix Fprev_beta;
123   symmMatrix Dprev_alpha;
124   symmMatrix Dprev_beta;
125   symmMatrix F_ort_prev_alpha; // Used by purification
126   symmMatrix F_ort_prev_beta; // Used by purification
127   symmMatrix D_ort_prev_alpha; // Used for computing eigenvectors
128   symmMatrix D_ort_prev_beta; // Used for computing eigenvectors
129   symmMatrix bestFockMatrixSoFar_alpha;
130   symmMatrix bestFockMatrixSoFar_beta;
131   symmMatrix bestFockMatrixSoFar2_alpha;
132   symmMatrix bestFockMatrixSoFar2_beta;
133   normalMatrix ErrorMatrix_alpha;
134   normalMatrix ErrorMatrix_beta;
135   symmMatrix G_alpha;
136   symmMatrix G_beta;
137 
138   // HOMO/LUMO info
139   intervalType homoInterval_F_ort_prev_alpha;
140   intervalType lumoInterval_F_ort_prev_alpha;
141   intervalType homoInterval_F_ort_prev_beta;
142   intervalType lumoInterval_F_ort_prev_beta;
143   intervalType homoInterval_Fprev_alpha;
144   intervalType lumoInterval_Fprev_alpha;
145   intervalType homoInterval_Fprev_beta;
146   intervalType lumoInterval_Fprev_beta;
147 
148   int alpha_beta_diff;
149   int noOfElectrons_alpha;
150   int noOfElectrons_beta;
151 
152   std::vector<generalVector> eigVecOCC_alpha;
153   std::vector<generalVector> eigVecUNOCC_alpha;
154   std::vector<ergo_real> eigValOCC_alpha;
155   std::vector<ergo_real> eigValUNOCC_alpha;
156   std::vector<generalVector> eigVecOCC_beta;
157   std::vector<generalVector> eigVecUNOCC_beta;
158   std::vector<ergo_real> eigValOCC_beta;
159   std::vector<ergo_real> eigValUNOCC_beta;
160 };
161 
162 
163 
164 
165 
166 #endif
167