MADNESS 0.10.1
localizer.h
Go to the documentation of this file.
1//
2// Created by Florian Bischoff on 11/1/21.
3//
4
5#ifndef MADNESS_LOCALIZER_H
6#define MADNESS_LOCALIZER_H
7
12#include<madness/mra/mra.h>
14
15
16namespace madness {
17
18class SCF;
19
20//template<typename T, std::size_t NDIM>
21class Localizer {
22public:
23
24 Localizer() = default;
25
27 const std::vector<Function<double, 3>>& ao);
28
29 Localizer& set_method(const std::string method1) {
30 method=method1;
31 return *this;
32 }
33
34 std::string get_method() {
35 return method;
36 }
37
39 metric=copy(R);
40 return *this;
41 }
42
45 return *this;
46 }
47
49 return aobasis;
50 }
51
52 /// hand the cholesky method last iteration's pivot order; it reads the order and
53 /// overwrites it with the one it used (see localize_cholesky)
54 Localizer& set_pivot_state(std::vector<long>* state) {
55 pivot_state = state;
56 return *this;
57 }
58
59 void print_info() const {
60 print("Localizer info");
61 print("method ",method);
62 print("aobasis ",aobasis.get_name());
63 print("metric ", metric.is_initialized());
64 print("core-valence separation ",enforce_core_valence_separation);
65 print("thresh_degenerate ",thresh_degenerate);
66 }
67
68 /// localize the orbitals
69 template<typename T, std::size_t NDIM>
70 MolecularOrbitals<T, NDIM> localize(const MolecularOrbitals<T, NDIM>& mo_in, bool randomize) const;
71
72 /// localize the orbitals, possibly enforce core-valence separation
73 template<typename T, std::size_t NDIM>
75 bool randomize) const;
76
77 template<typename T, std::size_t NDIM>
79
80 template<typename T, std::size_t NDIM>
81 Tensor<T> compute_localization_matrix(World& world, const MolecularOrbitals<T, NDIM>& mo_in, bool randomize) const;
82
83 /// localize orbitals while enforcing core-valence separation
84
85 /// @param[in] World the world
86 /// @param[in] mo_in the input orbitals
87 /// @param[in] Fock the Fock matrix for canonicalizing the orbitals first
88 /// @param[in] method the localization method
89 /// @param[in] tolloc localization tolerance
90 /// @param[in] randomize initially randomize the localization procedure
91 template<typename T, std::size_t NDIM>
93 const MolecularOrbitals<T, NDIM>& mo_in, const Tensor<T>& Fock) const;
94
95 template<typename T>
96 static bool check_core_valence_separation(const Tensor<T>& Fock, const std::vector<int>& localized_set,
97 const bool silent=false);
98
99 template<typename T>
100 static std::size_t determine_frozen_orbitals(const Tensor<T> fmat);
101
102 static bool check_frozen_consistency(const long nfrozen, const std::vector<int>& localize_sets);
103
104 /// given a unitary transformation matrix undo mere reordering
105 template<typename T>
106 static void undo_reordering(Tensor<T>& U, const Tensor<double>& occ) {
107 Tensor<double> eval(U.dim(0)); // dummy tensor
108 undo_reordering(U,occ,eval);
109 }
110
111 /// given a unitary transformation matrix undo mere reordering
112 template<typename T>
113 static void undo_reordering(Tensor<T>& U, const Tensor<double>& occ, Tensor<double>& eval);
114
115 /// given a unitary transformation matrix undo rotations between degenerate columns
116 template<typename T>
117 static void undo_degenerate_rotations(Tensor<T>& U, const Tensor<double>& eval, const double thresh_degenerate);
118
119 /// given a unitary transformation matrix undo rotations within blocks of localized orbitals
120 template<typename T>
121 static void undo_rotations_within_sets(Tensor<T>& U, const std::vector<int>& localized_set);
122
123 /// find sets of degenerate states/orbitals
124 static std::vector<Slice> find_degenerate_blocks(const Tensor<double>& eval, const double thresh_degenerate);
125
126 /// given a unitary transformation matrix undo the rotations within the blocks
127 template<typename T>
128 static Tensor<T> undo_rotation(const Tensor<T>& U_in, const std::vector<Slice>& blocks);
129
130private:
131
132 template<typename T, std::size_t NDIM>
134 localize_PM(World& world, const std::vector<Function<T, NDIM>>& mo, const std::vector<int>& set,
135 const double thresh = 1e-9, const bool randomize = true, const bool doprint = false) const;
136
137 template<typename T, std::size_t NDIM>
139 const std::vector<Function<T, NDIM>>& mo,
140 const std::vector<int>& set,
141 const double thresh = 1e-9,
142 const bool randomize = true,
143 const bool doprint = false) const;
144
145 template<typename T, std::size_t NDIM>
147 const std::vector<Function<T, NDIM>>& mo,
148 const std::vector<int>& set) const;
149
150 template<typename T, std::size_t NDIM>
152 const std::vector<Function<T, NDIM>>& mo,
153 const std::vector<int>& set,
154 const double thresh = 1e-9,
155 const bool randomize = true,
156 const bool doprint = false) const;
157
158 /// the "new" objective optimized with distributed systolic Jacobi sweeps (localize=new_sys)
159 template<typename T, std::size_t NDIM>
161 const std::vector<Function<T, NDIM>>& mo,
162 const std::vector<int>& set,
163 const double thresh = 1e-9,
164 const bool randomize = true,
165 const bool doprint = false) const;
166
167 /// build the "new" method's orthonormal atomic-eigenfunction basis and localization blocks
168 template<typename T, std::size_t NDIM>
169 void prepare_new_basis(World& world, const std::vector<Function<T, NDIM>>& mo,
170 Tensor<T>& C, std::vector<int>& at_to_bf,
171 std::vector<int>& at_nbf) const;
172
173 template<typename T>
174 inline double DIP(const Tensor<T>& dip, int i, int j, int k, int l) const {
175 return dip(i, j, 0) * dip(k, l, 0) + dip(i, j, 1) * dip(k, l, 1) + dip(i, j, 2) * dip(k, l, 2);
176 }
177
178 template<typename T>
180
181
182 std::vector<int> at_to_bf, at_nbf; /// map atoms to basis functions in the "new" algorithm
185 std::vector<Function<double, 3>> ao;
186 Function<double,3> metric; /// =R for computing matrix elements of operators
187 double thetamax=0.1; /// maximum rotation(?)
188 const double tolloc = 1e-6; // was std::min(1e-6,0.01*dconv) but now trying to avoid unnecessary change
189 double thresh_degenerate; /// when are orbitals degenerate
190 bool enforce_core_valence_separation=false; /// no rotations between core and valence orbitals (distinguished by 'set')
191 std::string method="new"; /// localization method
192 std::vector<long>* pivot_state = nullptr; /// cholesky pivot memory across SCF iterations
193
194};
195
196}
197
198#endif //MADNESS_LOCALIZER_H
Definition test_ar.cc:118
Definition test_ar.cc:170
Contracted Gaussian basis.
Definition madness/chem/molecularbasis.h:469
std::string get_name() const
Definition madness/chem/molecularbasis.h:509
long dim(int i) const
Returns the size of dimension i.
Definition basetensor.h:147
Manages data associated with a row/column/block distributed array.
Definition distributed_matrix.h:388
Computes matrix representation of the Fock operator.
Definition SCFOperators.h:1060
A multiresolution adaptive numerical function.
Definition mra.h:144
bool is_initialized() const
Returns true if the function is initialized.
Definition mra.h:172
Definition localizer.h:21
static void undo_rotations_within_sets(Tensor< T > &U, const std::vector< int > &localized_set)
given a unitary transformation matrix undo rotations within blocks of localized orbitals
Definition localizer.cc:926
DistributedMatrix< T > localize_boys(World &world, const std::vector< Function< T, NDIM > > &mo, const std::vector< int > &set, const double thresh=1e-9, const bool randomize=true, const bool doprint=false) const
Definition localizer.cc:171
static void undo_degenerate_rotations(Tensor< T > &U, const Tensor< double > &eval, const double thresh_degenerate)
given a unitary transformation matrix undo rotations between degenerate columns
Definition localizer.cc:934
double DIP(const Tensor< T > &dip, int i, int j, int k, int l) const
Definition localizer.h:174
std::vector< Function< double, 3 > > ao
Definition localizer.h:185
double thetamax
=R for computing matrix elements of operators
Definition localizer.h:187
Localizer & set_enforce_core_valence_separation(const bool value)
Definition localizer.h:43
Tensor< T > compute_core_valence_separation_transformation_matrix(World &world, const MolecularOrbitals< T, NDIM > &mo_in, const Tensor< T > &Fock) const
localize orbitals while enforcing core-valence separation
Definition localizer.cc:116
std::string method
no rotations between core and valence orbitals (distinguished by 'set')
Definition localizer.h:191
std::string get_method()
Definition localizer.h:34
static std::size_t determine_frozen_orbitals(const Tensor< T > fmat)
Definition localizer.cc:793
const double tolloc
maximum rotation(?)
Definition localizer.h:188
std::vector< int > at_to_bf
Definition localizer.h:182
AtomicBasisSet aobasis
map atoms to basis functions in the "new" algorithm
Definition localizer.h:183
static Tensor< T > undo_rotation(const Tensor< T > &U_in, const std::vector< Slice > &blocks)
given a unitary transformation matrix undo the rotations within the blocks
Definition localizer.cc:905
Localizer & set_method(const std::string method1)
Definition localizer.h:29
Function< double, 3 > metric
Definition localizer.h:186
static bool check_core_valence_separation(const Tensor< T > &Fock, const std::vector< int > &localized_set, const bool silent=false)
Definition localizer.cc:144
std::vector< int > at_nbf
Definition localizer.h:182
DistributedMatrix< T > localize_cholesky(World &world, const std::vector< Function< T, NDIM > > &mo, const std::vector< int > &set) const
Cholesky localization: deterministic and non-iterative.
Definition localizer.cc:643
Localizer & set_metric(const Function< double, 3 > &R)
Definition localizer.h:38
DistributedMatrix< T > localize_PM(World &world, const std::vector< Function< T, NDIM > > &mo, const std::vector< int > &set, const double thresh=1e-9, const bool randomize=true, const bool doprint=false) const
Definition localizer.cc:323
static std::vector< Slice > find_degenerate_blocks(const Tensor< double > &eval, const double thresh_degenerate)
find sets of degenerate states/orbitals
Definition localizer.cc:884
Molecule molecule
Definition localizer.h:184
std::vector< long > * pivot_state
localization method
Definition localizer.h:192
Tensor< T > matrix_exponential(const Tensor< T > &A) const
Definition localizer.cc:942
bool enforce_core_valence_separation
when are orbitals degenerate
Definition localizer.h:190
void prepare_new_basis(World &world, const std::vector< Function< T, NDIM > > &mo, Tensor< T > &C, std::vector< int > &at_to_bf, std::vector< int > &at_nbf) const
build the "new" method's orthonormal atomic-eigenfunction basis and localization blocks
Definition localizer.cc:337
Localizer & set_pivot_state(std::vector< long > *state)
Definition localizer.h:54
void print_info() const
Definition localizer.h:59
DistributedMatrix< T > localize_new_systolic(World &world, const std::vector< Function< T, NDIM > > &mo, const std::vector< int > &set, const double thresh=1e-9, const bool randomize=true, const bool doprint=false) const
the "new" objective optimized with distributed systolic Jacobi sweeps (localize=new_sys)
Definition localizer.cc:620
AtomicBasisSet get_aobasis() const
Definition localizer.h:48
MolecularOrbitals< T, NDIM > localize(const MolecularOrbitals< T, NDIM > &mo_in, bool randomize) const
localize the orbitals
Definition localizer.cc:20
double thresh_degenerate
Definition localizer.h:189
Tensor< T > compute_localization_matrix(World &world, const MolecularOrbitals< T, NDIM > &mo_in, bool randomize) const
Definition localizer.cc:72
DistributedMatrix< T > localize_new(World &world, const std::vector< Function< T, NDIM > > &mo, const std::vector< int > &set, const double thresh=1e-9, const bool randomize=true, const bool doprint=false) const
Definition localizer.cc:416
static void undo_reordering(Tensor< T > &U, const Tensor< double > &occ)
given a unitary transformation matrix undo mere reordering
Definition localizer.h:106
static bool check_frozen_consistency(const long nfrozen, const std::vector< int > &localize_sets)
Definition localizer.cc:822
MolecularOrbitals< T, NDIM > separate_core_valence(const MolecularOrbitals< T, NDIM > &mo_in, const Tensor< T > &Fock) const
Definition localizer.cc:99
Definition MolecularOrbitals.h:25
Definition molecule.h:129
A tensor is a multidimensional array.
Definition tensor.h:318
A parallel world class.
Definition world.h:134
static const double R
Definition csqrt.cc:46
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:227
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence.
Definition mra.h:2233
@ mo
moldft orbitals psi
static const double thresh
Definition rk.cc:45
static const long k
Definition rk.cc:44
void e()
Definition test_sig.cc:75