8 #ifndef SRC_APPS_CHEM_MOLECULARORBITALS_H_
9 #define SRC_APPS_CHEM_MOLECULARORBITALS_H_
19 template<
typename T, std::
size_t NDIM>
class Function;
23 template<
typename T, std::
size_t NDIM>
41 const std::vector<int>& set)
51 for (
int i=s.start; i<s.end+1; ++i) result.
mo.push_back(
copy(
mo[i]));
64 std::vector<Function<T,NDIM> >
get_mos()
const {
72 [[nodiscard]] std::vector<std::string>
get_irreps()
const {
122 std::size_t nmo =
mo.size();
123 std::vector<int> set = std::vector<int>(
static_cast<size_t>(nmo), 0);
124 for (
size_t i = 1; i < nmo; ++i) {
127 if (
eps(i) -
eps(i - 1) > bandwidth ||
get_occ()(i) != 1.0) ++(set[i]);
134 std::vector<Slice> blocks;
136 for (
size_t i=1; i<localized_set.size(); ++i) {
137 if (not (localized_set[i]==localized_set[i-1])) {
138 blocks.push_back(
Slice(ilo, i-1));
143 blocks.push_back(
Slice(ilo,localized_set.size()-1));
182 void pretty_print(std::string message, std::vector<std::string> flags=std::vector<std::string>())
const {
184 if (flags.size()==0) flags.resize(
mo.size());
186 if (
irreps.size()==0)
irreps=std::vector<std::string>(
mo.size(),
"unknown");
187 print(
"orbital # irrep energy occupation localize_set");
188 for (
int i=
mo.size()-1; i>=0; --i) {
190 constexpr std::size_t
bufsize=1024;
194 cout << std::string(buf) <<endl;
201 World& world=
mo.front().world();
204 if (world.
rank() == 0) {
205 auto flags=std::vector<std::string>(dummy_mo.
get_mos().size(),
"active");
206 for (
int i=0; i<freeze; ++i) flags[i]=
"frozen";
207 dummy_mo.
pretty_print(
"diagonal Fock matrix elements with core/valence separation for freezing",flags);
208 print(
"\nfreezing orbitals: ", freeze,
"\n");
217 template <
typename Archive>
219 std::size_t nmo=
mo.size();
221 if (nmo!=
mo.size())
mo.resize(nmo);
222 for (
auto&
m :
mo) ar &
m;
224 if (ar.is_input_archive) {
225 if (
irreps.size()==0)
irreps=std::vector<std::string>(nmo,
"unknown");
234 if (mo1.
mo.size()!=mo2.
mo.size())
return false;
235 if (mo1.
mo.size()==0)
return true;
237 World& world=mo1.
mo.front().world();
246 std::vector<std::string>& irrep_out,
Tensor<double>& occ_out, std::vector<int>& set_out)
const;
253 const std::size_t nmo_alpha,
const std::size_t nmo_beta) {
267 bool spinrestricted =
false;
272 double current_energy=0, converged_to_thresh=0;
273 std::string
xc, localize_method;
278 ar & current_energy & spinrestricted;
279 ar &
L&
k1&
molecule&
xc & localize_method & converged_to_thresh;
283 bool have_beta=(not spinrestricted) and (nmo_beta>0);
287 return std::make_pair(amo,bmo);
296 bool spinrestricted =
false;
298 double current_energy=0.0, converged_to_thresh=1.e10;
300 std::string
xc, localize_method;
304 ar & current_energy & spinrestricted;
305 ar &
L&
k1&
molecule&
xc & localize_method & converged_to_thresh;
314 unsigned int nmo = 0;
320 for (
unsigned int i = 0; i <
mo.size(); ++i)
322 unsigned int n_core =
molecule.n_core_orb_all();
323 if (nmo > nmo_from_input) {
326 mo = std::vector<Function<T,NDIM> >(
mo.begin() + n_core,
327 mo.begin() + n_core + nmo_from_input);
336 unsigned int nmo=
mo.size();
340 for (
unsigned int i = 0; i <
mo.size(); ++i)
364 std::vector<Vector<typename Tensor<T>::scalar_type,3>>
compute_center(
368 std::vector<Function<T,NDIM> >
mo;
Contracted Gaussian basis.
Definition: apps/periodic_old/molecularbasis.h:424
Contracted Gaussian basis.
Definition: madness/chem/molecularbasis.h:465
long size() const
Returns the number of elements in the tensor.
Definition: basetensor.h:138
A multiresolution adaptive numerical function.
Definition: mra.h:122
Definition: MolecularOrbitals.h:24
void invalidate_eps()
Definition: MolecularOrbitals.h:166
MolecularOrbitals get_subset(const int iset) const
Definition: MolecularOrbitals.h:45
MolecularOrbitals & set_mos(const std::vector< Function< T, NDIM > > &mo_new)
setters will always invalidate all other member variables
Definition: MolecularOrbitals.h:85
std::vector< Function< T, NDIM > > get_mos() const
Definition: MolecularOrbitals.h:64
static void save_restartaodata(World &world, const Molecule &molecule, const MolecularOrbitals< T, NDIM > &amo, const MolecularOrbitals< T, NDIM > &bmo, const AtomicBasisSet &aobasis)
save MOs in the AO projection for geometry restart
Definition: MolecularOrbitals.cc:83
std::vector< std::string > irreps
Definition: MolecularOrbitals.h:370
void print_cubefiles(const std::string name, const std::vector< std::string > cubefile_header) const
Definition: MolecularOrbitals.cc:66
void write_to(std::vector< Function< T, NDIM > > &mo_out, Tensor< double > &eps_out, std::vector< std::string > &irrep_out, Tensor< double > &occ_out, std::vector< int > &set_out) const
Definition: MolecularOrbitals.cc:34
MolecularOrbitals & update_localize_set(const std::vector< int > &set)
updates will keep other member variables
Definition: MolecularOrbitals.h:103
MolecularOrbitals & set_all_orbitals_occupied()
Definition: MolecularOrbitals.h:148
static std::pair< MolecularOrbitals< T, NDIM >, MolecularOrbitals< T, NDIM > > read_restartdata(World &world, const std::string filename, const Molecule &molecule, const std::size_t nmo_alpha, const std::size_t nmo_beta)
reads amo and bmo from the restartdata file
Definition: MolecularOrbitals.h:252
std::size_t size() const
Definition: MolecularOrbitals.h:60
void save_mos(archive::ParallelOutputArchive<> &ar, const Molecule &molecule) const
legacy code
Definition: MolecularOrbitals.h:334
void serialize(Archive &ar)
Definition: MolecularOrbitals.h:218
friend bool similar(const MolecularOrbitals &mo1, const MolecularOrbitals &mo2, const double thresh=1.e-6)
Definition: MolecularOrbitals.h:232
Tensor< double > get_occ() const
Definition: MolecularOrbitals.h:80
static std::pair< MolecularOrbitals< T, NDIM >, MolecularOrbitals< T, NDIM > > read_restartaodata(World &world, const Molecule &molecule, const bool have_beta)
uses AO-projection as a restart guess
Definition: MolecularOrbitals.cc:104
void invalidate_occ()
Definition: MolecularOrbitals.h:174
Tensor< double > eps
Definition: MolecularOrbitals.h:369
MolecularOrbitals(const std::vector< Function< T, NDIM > > &mo)
Definition: MolecularOrbitals.h:31
std::vector< std::string > get_irreps() const
Definition: MolecularOrbitals.h:72
static std::vector< Slice > convert_set_to_slice(const std::vector< int > &localized_set)
Definition: MolecularOrbitals.h:133
MolecularOrbitals & update_occ(const Tensor< double > &occ_new)
Definition: MolecularOrbitals.h:97
MolecularOrbitals & update_mos(const std::vector< Function< T, NDIM > > &mo_new)
updates will keep other member variables
Definition: MolecularOrbitals.h:92
MolecularOrbitals & recompute_localize_sets(const double bandwidth=1.5)
group orbitals into sets of similar orbital energies for localization
Definition: MolecularOrbitals.h:120
Tensor< double > get_eps() const
Definition: MolecularOrbitals.h:68
void invalidate_mos()
Definition: MolecularOrbitals.h:162
std::vector< int > get_localize_sets() const
Definition: MolecularOrbitals.h:76
void invalidate_irreps()
Definition: MolecularOrbitals.h:170
void invalidate_localize_sets()
Definition: MolecularOrbitals.h:178
MolecularOrbitals(const std::vector< Function< T, NDIM > > &mo, const Tensor< double > &eps)
Definition: MolecularOrbitals.h:35
void pretty_print(std::string message, std::vector< std::string > flags=std::vector< std::string >()) const
Definition: MolecularOrbitals.h:182
MolecularOrbitals(const std::vector< Function< T, NDIM > > &mo, const Tensor< double > &eps, const std::vector< std::string > &irrep, const Tensor< double > &occ, const std::vector< int > &set)
Definition: MolecularOrbitals.h:39
void project_ao(World &world, const Tensor< T > &Saomo, const std::vector< Function< double, 3 > > &aos)
Definition: MolecularOrbitals.cc:141
std::vector< Function< T, NDIM > > mo
Definition: MolecularOrbitals.h:368
MolecularOrbitals & update_mos_and_eps(const std::vector< Function< T, NDIM > > &mo_new, const Tensor< double > &eps_new)
updates will keep other member variables
Definition: MolecularOrbitals.h:109
MolecularOrbitals(const MolecularOrbitals< T, NDIM > &other)=default
std::vector< int > localize_sets
Definition: MolecularOrbitals.h:372
Tensor< double > occ
Definition: MolecularOrbitals.h:371
MolecularOrbitals()=default
static void save_restartdata(World &world, const std::string filename, const Molecule &molecule, const MolecularOrbitals< T, NDIM > &amo, const MolecularOrbitals< T, NDIM > &bmo)
reads amo and bmo from the restartdata file
Definition: MolecularOrbitals.h:293
void invalidate_all()
Definition: MolecularOrbitals.h:154
void print_frozen_orbitals(const long freeze) const
Definition: MolecularOrbitals.h:199
void post_process_mos(World &world, const double thresh, const int k)
Definition: MolecularOrbitals.cc:53
void load_mos(archive::ParallelInputArchive<> &ar, const Molecule &molecule, const std::size_t nmo_from_input)
legacy code
Definition: MolecularOrbitals.h:312
std::vector< Vector< typename Tensor< T >::scalar_type, 3 > > compute_center(const Function< typename Tensor< T >::scalar_type, NDIM > metric2=Function< typename Tensor< T >::scalar_type, NDIM >()) const
Definition: MolecularOrbitals.cc:155
MolecularOrbitals & recompute_irreps(const std::string pointgroup, const Function< typename Tensor< T >::scalar_type, NDIM > &metric)
Definition: MolecularOrbitals.cc:24
Definition: molecule.h:124
A slice defines a sub-range or patch of a dimension.
Definition: slice.h:103
TensorTypeData< T >::scalar_type scalar_type
C++ typename of the real type associated with a complex type.
Definition: tensor.h:409
void clear()
Frees all memory and resests to state of default constructor.
Definition: tensor.h:1884
A parallel world class.
Definition: world.h:132
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition: world.h:318
An archive for storing local or parallel data wrapping a BinaryFstreamOutputArchive.
Definition: parallel_archive.h:321
Objects that implement their own parallel archive interface should derive from this class.
Definition: parallel_archive.h:58
const std::size_t bufsize
Definition: derivatives.cc:16
const double m
Definition: gfit.cc:199
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition: madness_exception.h:190
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition: madness_exception.h:134
const char * version()
Get the MADNESS version number.
Definition: info.cc:17
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
static const char * filename
Definition: legendre.cc:96
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
double norm2(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norm of a vector of functions.
Definition: vmra.h:851
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
std::vector< std::string > cubefile_header(std::string filename="input", const bool &no_orient=false)
Definition: molecule.cc:69
std::string name(const FuncType &type, const int ex=-1)
Definition: ccpairfunction.h:28
XCfunctional xc
Definition: newsolver_lda.cc:53
Implements ParallelInputArchive and ParallelOutputArchive for parallel serialization of data.
static const double L
Definition: rk.cc:46
static const double thresh
Definition: rk.cc:45
static const long k
Definition: rk.cc:44
Defines and implements most of Tensor.
static const std::size_t NDIM
Definition: testpdiff.cc:42
double k1
Definition: testperiodic.cc:67
static Molecule molecule
Definition: testperiodicdft.cc:38
static AtomicBasisSet aobasis
Definition: testperiodicdft.cc:39