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) {
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
48 /// Multiply the "new" method's convergence threshold by this factor (default 1.0).
51 return *this;
52 }
53
55 return aobasis;
56 }
57
58 void print_info() const {
59 print("Localizer info");
60 print("method ",method);
61 print("aobasis ",aobasis.get_name());
62 print("metric ", metric.is_initialized());
63 print("core-valence separation ",enforce_core_valence_separation);
64 print("thresh_degenerate ",thresh_degenerate);
65 }
66
67 /// localize the orbitals
68 template<typename T, std::size_t NDIM>
70
71 /// localize the orbitals, possibly enforce core-valence separation
72 template<typename T, std::size_t NDIM>
74 bool randomize) const;
75
76 template<typename T, std::size_t NDIM>
78
79 template<typename T, std::size_t NDIM>
81
82 /// localize orbitals while enforcing core-valence separation
83
84 /// @param[in] World the world
85 /// @param[in] mo_in the input orbitals
86 /// @param[in] Fock the Fock matrix for canonicalizing the orbitals first
87 /// @param[in] method the localization method
88 /// @param[in] tolloc localization tolerance
89 /// @param[in] randomize initially randomize the localization procedure
90 template<typename T, std::size_t NDIM>
92 const MolecularOrbitals<T, NDIM>& mo_in, const Tensor<T>& Fock) const;
93
94 template<typename T>
95 static bool check_core_valence_separation(const Tensor<T>& Fock, const std::vector<int>& localized_set,
96 const bool silent=false);
97
98 template<typename T>
99 static std::size_t determine_frozen_orbitals(const Tensor<T> fmat);
100
101 static bool check_frozen_consistency(const long nfrozen, const std::vector<int>& localize_sets);
102
103 /// given a unitary transformation matrix undo mere reordering
104 template<typename T>
105 static void undo_reordering(Tensor<T>& U, const Tensor<double>& occ) {
106 Tensor<double> eval(U.dim(0)); // dummy tensor
107 undo_reordering(U,occ,eval);
108 }
109
110 /// given a unitary transformation matrix undo mere reordering
111 template<typename T>
112 static void undo_reordering(Tensor<T>& U, const Tensor<double>& occ, Tensor<double>& eval);
113
114 /// given a unitary transformation matrix undo rotations between degenerate columns
115 template<typename T>
116 static void undo_degenerate_rotations(Tensor<T>& U, const Tensor<double>& eval, const double thresh_degenerate);
117
118 /// given a unitary transformation matrix undo rotations within blocks of localized orbitals
119 template<typename T>
120 static void undo_rotations_within_sets(Tensor<T>& U, const std::vector<int>& localized_set);
121
122 /// find sets of degenerate states/orbitals
123 static std::vector<Slice> find_degenerate_blocks(const Tensor<double>& eval, const double thresh_degenerate);
124
125 /// given a unitary transformation matrix undo the rotations within the blocks
126 template<typename T>
127 static Tensor<T> undo_rotation(const Tensor<T>& U_in, const std::vector<Slice>& blocks);
128
129private:
130
131 template<typename T, std::size_t NDIM>
133 localize_PM(World& world, const std::vector<Function<T, NDIM>>& mo, const std::vector<int>& set,
134 const double thresh = 1e-9, const bool randomize = true, const bool doprint = false) const;
135
136 template<typename T, std::size_t NDIM>
138 const std::vector<Function<T, NDIM>>& mo,
139 const std::vector<int>& set,
140 const double thresh = 1e-9,
141 const bool randomize = true,
142 const bool doprint = false) const;
143
144 template<typename T, std::size_t NDIM>
146 const std::vector<Function<T, NDIM>>& mo,
147 const std::vector<int>& set,
148 const double thresh = 1e-9,
149 const bool randomize = true,
150 const bool doprint = false) const;
151
152 template<typename T>
153 inline double DIP(const Tensor<T>& dip, int i, int j, int k, int l) const {
154 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);
155 }
156
157 template<typename T>
159
160
161 std::vector<int> at_to_bf, at_nbf; /// map atoms to basis functions in the "new" algorithm
164 std::vector<Function<double, 3>> ao;
165 Function<double,3> metric; /// =R for computing matrix elements of operators
166 double thetamax=0.1; /// maximum rotation(?)
167 const double tolloc = 1e-6; // was std::min(1e-6,0.01*dconv) but now trying to avoid unnecessary change
168 double tolloc_scale = 1.0; // multiplies tolloc, "new" method only
169 double thresh_degenerate; /// when are orbitals degenerate
170 bool enforce_core_valence_separation=false; /// no rotations between core and valence orbitals (distinguished by 'set')
171 std::string method="new"; /// localization method
172
173};
174
175}
176
177#endif //MADNESS_LOCALIZER_H
Definition test_ar.cc:118
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:870
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
double tolloc_scale
Definition localizer.h:168
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:709
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:166
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:717
double DIP(const Tensor< T > &dip, int i, int j, int k, int l) const
Definition localizer.h:153
std::vector< Function< double, 3 > > ao
Definition localizer.h:164
double thetamax
=R for computing matrix elements of operators
Definition localizer.h:166
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:111
std::string method
no rotations between core and valence orbitals (distinguished by 'set')
Definition localizer.h:171
std::string get_method()
Definition localizer.h:34
static std::size_t determine_frozen_orbitals(const Tensor< T > fmat)
Definition localizer.cc:576
const double tolloc
maximum rotation(?)
Definition localizer.h:167
std::vector< int > at_to_bf
Definition localizer.h:161
AtomicBasisSet aobasis
map atoms to basis functions in the "new" algorithm
Definition localizer.h:162
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:688
Localizer & set_method(const std::string method1)
Definition localizer.h:29
Function< double, 3 > metric
Definition localizer.h:165
static bool check_core_valence_separation(const Tensor< T > &Fock, const std::vector< int > &localized_set, const bool silent=false)
Definition localizer.cc:139
std::vector< int > at_nbf
Definition localizer.h:161
Localizer & set_tolloc_scale(const double scale)
Multiply the "new" method's convergence threshold by this factor (default 1.0).
Definition localizer.h:49
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:306
static std::vector< Slice > find_degenerate_blocks(const Tensor< double > &eval, const double thresh_degenerate)
find sets of degenerate states/orbitals
Definition localizer.cc:667
Molecule molecule
Definition localizer.h:163
Tensor< T > matrix_exponential(const Tensor< T > &A) const
Definition localizer.cc:725
bool enforce_core_valence_separation
when are orbitals degenerate
Definition localizer.h:170
void print_info() const
Definition localizer.h:58
AtomicBasisSet get_aobasis() const
Definition localizer.h:54
MolecularOrbitals< T, NDIM > localize(const MolecularOrbitals< T, NDIM > &mo_in, bool randomize) const
localize the orbitals
Definition localizer.cc:19
double thresh_degenerate
Definition localizer.h:169
Tensor< T > compute_localization_matrix(World &world, const MolecularOrbitals< T, NDIM > &mo_in, bool randomize) const
Definition localizer.cc:71
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:317
static void undo_reordering(Tensor< T > &U, const Tensor< double > &occ)
given a unitary transformation matrix undo mere reordering
Definition localizer.h:105
static bool check_frozen_consistency(const long nfrozen, const std::vector< int > &localize_sets)
Definition localizer.cc:605
MolecularOrbitals< T, NDIM > separate_core_valence(const MolecularOrbitals< T, NDIM > &mo_in, const Tensor< T > &Fock) const
Definition localizer.cc:94
Definition MolecularOrbitals.h:24
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 DFParameters.h:10
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
void scale(World &world, std::vector< Function< T, NDIM > > &v, const std::vector< Q > &factors, bool fence=true)
Scales inplace a vector of functions by distinct values.
Definition vmra.h:873
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
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:2187
static const double thresh
Definition rk.cc:45
static const long k
Definition rk.cc:44
void e()
Definition test_sig.cc:75