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 void print_info() const {
53 print("Localizer info");
54 print("method ",method);
55 print("aobasis ",aobasis.get_name());
56 print("metric ", metric.is_initialized());
57 print("core-valence separation ",enforce_core_valence_separation);
58 print("thresh_degenerate ",thresh_degenerate);
59 }
60
61 /// localize the orbitals
62 template<typename T, std::size_t NDIM>
63 MolecularOrbitals<T, NDIM> localize(const MolecularOrbitals<T, NDIM>& mo_in, bool randomize) const;
64
65 /// localize the orbitals, possibly enforce core-valence separation
66 template<typename T, std::size_t NDIM>
68 bool randomize) const;
69
70 template<typename T, std::size_t NDIM>
72
73 template<typename T, std::size_t NDIM>
74 Tensor<T> compute_localization_matrix(World& world, const MolecularOrbitals<T, NDIM>& mo_in, bool randomize) const;
75
76 /// localize orbitals while enforcing core-valence separation
77
78 /// @param[in] World the world
79 /// @param[in] mo_in the input orbitals
80 /// @param[in] Fock the Fock matrix for canonicalizing the orbitals first
81 /// @param[in] method the localization method
82 /// @param[in] tolloc localization tolerance
83 /// @param[in] randomize initially randomize the localization procedure
84 template<typename T, std::size_t NDIM>
86 const MolecularOrbitals<T, NDIM>& mo_in, const Tensor<T>& Fock) const;
87
88 template<typename T>
89 static bool check_core_valence_separation(const Tensor<T>& Fock, const std::vector<int>& localized_set,
90 const bool silent=false);
91
92 template<typename T>
93 static std::size_t determine_frozen_orbitals(const Tensor<T> fmat);
94
95 static bool check_frozen_consistency(const long nfrozen, const std::vector<int>& localize_sets);
96
97 /// given a unitary transformation matrix undo mere reordering
98 template<typename T>
99 static void undo_reordering(Tensor<T>& U, const Tensor<double>& occ) {
100 Tensor<double> eval(U.dim(0)); // dummy tensor
101 undo_reordering(U,occ,eval);
102 }
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, Tensor<double>& eval);
107
108 /// given a unitary transformation matrix undo rotations between degenerate columns
109 template<typename T>
110 static void undo_degenerate_rotations(Tensor<T>& U, const Tensor<double>& eval, const double thresh_degenerate);
111
112 /// given a unitary transformation matrix undo rotations within blocks of localized orbitals
113 template<typename T>
114 static void undo_rotations_within_sets(Tensor<T>& U, const std::vector<int>& localized_set);
115
116 /// find sets of degenerate states/orbitals
117 static std::vector<Slice> find_degenerate_blocks(const Tensor<double>& eval, const double thresh_degenerate);
118
119 /// given a unitary transformation matrix undo the rotations within the blocks
120 template<typename T>
121 static Tensor<T> undo_rotation(const Tensor<T>& U_in, const std::vector<Slice>& blocks);
122
123private:
124
125 template<typename T, std::size_t NDIM>
127 localize_PM(World& world, const std::vector<Function<T, NDIM>>& mo, const std::vector<int>& set,
128 const double thresh = 1e-9, const bool randomize = true, const bool doprint = false) const;
129
130 template<typename T, std::size_t NDIM>
132 const std::vector<Function<T, NDIM>>& mo,
133 const std::vector<int>& set,
134 const double thresh = 1e-9,
135 const bool randomize = true,
136 const bool doprint = false) const;
137
138 template<typename T, std::size_t NDIM>
140 const std::vector<Function<T, NDIM>>& mo,
141 const std::vector<int>& set,
142 const double thresh = 1e-9,
143 const bool randomize = true,
144 const bool doprint = false) const;
145
146 template<typename T>
147 inline double DIP(const Tensor<T>& dip, int i, int j, int k, int l) const {
148 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);
149 }
150
151 template<typename T>
153
154
155 std::vector<int> at_to_bf, at_nbf; /// map atoms to basis functions in the "new" algorithm
158 std::vector<Function<double, 3>> ao;
159 Function<double,3> metric; /// =R for computing matrix elements of operators
160 double thetamax=0.1; /// maximum rotation(?)
161 const double tolloc = 1e-6; // was std::min(1e-6,0.01*dconv) but now trying to avoid unnecessary change
162 double thresh_degenerate; /// when are orbitals degenerate
163 bool enforce_core_valence_separation=false; /// no rotations between core and valence orbitals (distinguished by 'set')
164 std::string method="new"; /// localization method
165
166};
167
168}
169
170#endif //MADNESS_LOCALIZER_H
Definition test_ar.cc:118
Contracted Gaussian basis.
Definition madness/chem/molecularbasis.h:465
std::string get_name() const
Definition madness/chem/molecularbasis.h:505
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:805
A multiresolution adaptive numerical function.
Definition mra.h:122
bool is_initialized() const
Returns true if the function is initialized.
Definition mra.h:147
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:687
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:155
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:695
double DIP(const Tensor< T > &dip, int i, int j, int k, int l) const
Definition localizer.h:147
std::vector< Function< double, 3 > > ao
Definition localizer.h:158
double thetamax
=R for computing matrix elements of operators
Definition localizer.h:160
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:113
std::string method
no rotations between core and valence orbitals (distinguished by 'set')
Definition localizer.h:164
std::string get_method()
Definition localizer.h:34
static std::size_t determine_frozen_orbitals(const Tensor< T > fmat)
Definition localizer.cc:554
const double tolloc
maximum rotation(?)
Definition localizer.h:161
std::vector< int > at_to_bf
Definition localizer.h:155
AtomicBasisSet aobasis
map atoms to basis functions in the "new" algorithm
Definition localizer.h:156
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:666
Localizer & set_method(const std::string method1)
Definition localizer.h:29
Function< double, 3 > metric
Definition localizer.h:159
std::vector< int > at_nbf
Definition localizer.h:155
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:295
static std::vector< Slice > find_degenerate_blocks(const Tensor< double > &eval, const double thresh_degenerate)
find sets of degenerate states/orbitals
Definition localizer.cc:645
Molecule molecule
Definition localizer.h:157
Tensor< T > matrix_exponential(const Tensor< T > &A) const
Definition localizer.cc:703
bool enforce_core_valence_separation
when are orbitals degenerate
Definition localizer.h:163
void print_info() const
Definition localizer.h:52
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:21
double thresh_degenerate
Definition localizer.h:162
Tensor< T > compute_localization_matrix(World &world, const MolecularOrbitals< T, NDIM > &mo_in, bool randomize) const
Definition localizer.cc:73
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:306
static bool check_core_valence_separation(const Tensor< T > &Fock, const std::vector< int > &localized_set, const bool silent=false)
Definition localizer.cc:136
static void undo_reordering(Tensor< T > &U, const Tensor< double > &occ)
given a unitary transformation matrix undo mere reordering
Definition localizer.h:99
static bool check_frozen_consistency(const long nfrozen, const std::vector< int > &localize_sets)
Definition localizer.cc:583
MolecularOrbitals< T, NDIM > separate_core_valence(const MolecularOrbitals< T, NDIM > &mo_in, const Tensor< T > &Fock) const
Definition localizer.cc:96
Definition MolecularOrbitals.h:24
Definition molecule.h:124
A tensor is a multidimension array.
Definition tensor.h:317
A parallel world class.
Definition world.h:132
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:225
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:2002
static const double thresh
Definition rk.cc:45
static const long k
Definition rk.cc:44
void e()
Definition test_sig.cc:75