26#include <boost/format.hpp>
39 Index nstates)
const {
40 std::ofstream out(filename);
42 throw std::runtime_error(
"DiabatWriter: could not open " + filename);
44 Write(out, orbitals, type, nstates);
51 throw std::runtime_error(
52 "DiabatWriter: only restricted closed-shell BSE is supported.");
55 throw std::runtime_error(
56 "DiabatWriter: only singlet or triplet BSE states can be written.");
61 throw std::runtime_error(
"DiabatWriter: orbitals contain no BSE " +
76 if (orbitals.
getBSEvmax() != nocc - 1 || cmin != nocc) {
77 throw std::runtime_error(
78 "DiabatWriter: BSE window does not start at HOMO/LUMO.");
81 throw std::runtime_error(
82 "DiabatWriter: BSE eigenvector size does not match the BSE window.");
85 throw std::runtime_error(
86 "DiabatWriter: full BSE requested but no anti-resonant (Y) part "
91 if (nstates > 0 && nstates < nwrite) {
95 Eigen::VectorXd osc = Eigen::VectorXd::Zero(nwrite);
98 const Index n = std::min<Index>(nwrite, all.size());
99 osc.head(n) = all.head(n);
103 const double spin_factor = 1.0 / std::sqrt(2.0);
104 const std::string rule(60,
'-');
107 out <<
"# Written by VOTCA-XTP (orb2diabat) from BSE "
108 << (singlet ?
"singlets" :
"triplets") <<
", "
109 << (tda ?
"Tamm-Dancoff" :
"full BSE") <<
", window MO " << vmin + 1
111 out <<
"Method: " << (tda ?
"TDA" :
"TDDFT") <<
"\n";
112 out <<
"Orbitals are not spin-polarized.\n";
113 out <<
"Number of electrons: " << 2 * nocc <<
"\n";
114 out <<
"Number of alpha electrons: " << nocc <<
"\n";
115 out <<
"Number of beta electrons: " << nocc <<
"\n";
116 out <<
"Number of occupied orbitals (alpha): " << nocc <<
"\n";
117 out <<
"Number of virtual orbitals (alpha): " << nbasis - nocc <<
"\n";
118 out <<
"Number of occupied orbitals (beta): " << nocc <<
"\n";
119 out <<
"Number of virtual orbitals (beta): " << nbasis - nocc <<
"\n";
120 out << boost::format(
121 "Total energy of the reference ground state (a.u.): "
124 out <<
"\nState Information:\n\n";
126 for (
Index i = 0; i < nwrite; ++i) {
128 Eigen::VectorXd x = spin_factor * es.
eigenvectors().col(i);
133 const double nx = x.squaredNorm();
134 const double ny = tda ? 0.0 : y.squaredNorm();
136 out <<
"\n State index: " << i + 1 <<
"\n\n";
137 out << boost::format(
" Total energy (a.u.): %.12E\n") % (e0 + omega);
138 out << boost::format(
" Excitation energy (eV): %16.12f\n") %
140 out <<
" Multiplicity: " << (singlet ?
"Singlet" :
"Triplet") <<
"\n";
141 out << boost::format(
" <S^2>: %9.6f\n") % (singlet ? 0.0 : 2.0);
142 out << boost::format(
" Strength: %12.6f\n") % osc(i);
143 out << boost::format(
" Normalization factor: %9.6f\n") % (2.0 * (nx - ny));
144 out <<
" Amplitudes:\n " << rule <<
"\n";
146 for (
Index v = 0; v < vtotal; ++v) {
147 for (
Index c = 0; c < ctotal; ++c) {
148 out << boost::format(
" %6d --> %5d % .15E alpha\n") %
149 (vmin + v + 1) % (cmin + c + 1) % x(v * ctotal + c);
153 for (
Index v = 0; v < vtotal; ++v) {
154 for (
Index c = 0; c < ctotal; ++c) {
155 out << boost::format(
" %6d <-- %5d % .15E alpha\n") %
156 (vmin + v + 1) % (cmin + c + 1) % y(v * ctotal + c);
160 out <<
" " << rule <<
"\n";
161 out << boost::format(
" X: %12.8f Y: %11.8f\n") % (2.0 * nx) %
void Write(std::ostream &out, const Orbitals &orbitals, QMStateType type, Index nstates=-1) const
void WriteFile(const std::string &filename, const Orbitals &orbitals, QMStateType type, Index nstates=-1) const
static constexpr const char * FormatIdentifier
First line Diabat 2.0 uses to recognise its native state format.
Container for molecular orbitals and derived one-particle data.
Index getBSEvmax() const
Return the highest valence orbital included in BSE.
const tools::EigenSystem & BSETriplets() const
Return read-only access to triplet BSE eigenpairs.
Index getBSEcmin() const
Return the lowest conduction orbital included in BSE.
double getDFTTotalEnergy() const
Return the stored total DFT energy.
Index getSpin() const
Return the stored spin multiplicity.
bool hasUnrestrictedOrbitals() const
Report whether separate beta-spin orbitals are present.
const tools::EigenSystem & BSESinglets() const
Return read-only access to singlet BSE eigenpairs.
Index getBSEcmax() const
Return the highest conduction orbital included in BSE.
bool getTDAApprox() const
Return whether the Tamm-Dancoff approximation is enabled.
bool hasBSESinglets() const
Report whether singlet BSE eigenpairs are available.
Index getBSEvmin() const
Return the lowest valence orbital included in BSE.
Eigen::VectorXd Oscillatorstrengths() const
bool hasTransitionDipoles() const
Report whether transition dipole moments have been computed.
bool hasBSETriplets() const
Report whether triplet BSE eigenpairs are available.
Index getBasisSetSize() const
Return the number of AO basis functions in the DFT basis.
Index getLumo() const
Return the default LUMO index used by spin-agnostic callers.
std::string ToLongString() const
Charge transport classes.
Provides a means for comparing floating point numbers.