Skip to content

Commit

Permalink
Port molecular orbital table from Avogadro v1 (#1888)
Browse files Browse the repository at this point in the history
* Initial port of code from Avogadro v1

* Move energies and occupancies to BasisSet class, add const qualifiers
* Allow both beta and alpha symmetry labels
* Move Gaussian and Slater concurrent classes to qtgui for orbital table
* For now, skip the progress bar

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis authored Dec 27, 2024
1 parent a9eee7b commit 52a45ce
Show file tree
Hide file tree
Showing 21 changed files with 1,785 additions and 122 deletions.
112 changes: 111 additions & 1 deletion avogadro/core/basisset.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class AVOGADROCORE_EXPORT BasisSet
/**
* @return The number of molecular orbitals in the BasisSet.
*/
virtual unsigned int molecularOrbitalCount(ElectronType type = Paired) = 0;
virtual unsigned int molecularOrbitalCount(
ElectronType type = Paired) const = 0;

/**
* Check if the given MO number is the HOMO or not.
Expand Down Expand Up @@ -134,6 +135,72 @@ class AVOGADROCORE_EXPORT BasisSet
*/
virtual bool isValid() = 0;

/**
* @return the orbital symmetry labels (if they exist) for the MOs
*/
std::vector<std::string> symmetryLabels(ElectronType type = Paired) const
{
if (type == Paired || type == Alpha)
return m_symmetryLabels[0];
else
return m_symmetryLabels[1];
}

/**
* Set the orbital symmetry labels (a1, t2g, etc.) for the molecular
* orbitals
*/
void setSymmetryLabels(const std::vector<std::string>& labels,
ElectronType type = Paired);

/**
* @brief Set the molecular orbital energies, expected in Hartrees.
* @param energies The vector containing energies for the MOs of type
* @param type The type of the electrons being set.
*/
void setMolecularOrbitalEnergy(const std::vector<double>& energies,
ElectronType type = Paired);

/**
* @brief Set the molecular orbital occupancies.
* @param occ The occupancies for the MOs of type.
* @param type The type of the electrons being set.
*/
void setMolecularOrbitalOccupancy(const std::vector<unsigned char>& occ,
ElectronType type = Paired);

std::vector<double>& moEnergy(ElectronType type = Paired)
{
if (type == Paired || type == Alpha)
return m_moEnergy[0];
else
return m_moEnergy[1];
}

std::vector<double> moEnergy(ElectronType type = Paired) const
{
if (type == Paired || type == Alpha)
return m_moEnergy[0];
else
return m_moEnergy[1];
}

std::vector<unsigned char>& moOccupancy(ElectronType type = Paired)
{
if (type == Paired || type == Alpha)
return m_moOccupancy[0];
else
return m_moOccupancy[1];
}

std::vector<unsigned char> moOccupancy(ElectronType type = Paired) const
{
if (type == Paired || type == Alpha)
return m_moOccupancy[0];
else
return m_moOccupancy[1];
}

protected:
/**
* Total number of electrons, 0 is alpha electrons and 1 is beta electrons.
Expand All @@ -159,6 +226,22 @@ class AVOGADROCORE_EXPORT BasisSet
* The name of the theory used for the calculation.
*/
std::string m_theoryName;

/**
* The orbital symmetry labels (if they exist) for the MOs
*/
std::vector<std::string> m_symmetryLabels[2];

/**
* @brief This block stores energies for the molecular orbitals (same
* convention as the molecular orbital coefficients).
*/
std::vector<double> m_moEnergy[2];

/**
* @brief The occupancy of the molecular orbitals.
*/
std::vector<unsigned char> m_moOccupancy[2];
};

inline void BasisSet::setElectronCount(unsigned int n, ElectronType type)
Expand Down Expand Up @@ -194,6 +277,33 @@ inline unsigned int BasisSet::electronCount(ElectronType type) const
}
}

inline void BasisSet::setSymmetryLabels(const std::vector<std::string>& labels,
ElectronType type)
{
if (type == Paired || type == Alpha)
m_symmetryLabels[0] = labels;
else
m_symmetryLabels[1] = labels;
}

inline void BasisSet::setMolecularOrbitalEnergy(
const std::vector<double>& energies, ElectronType type)
{
if (type == Beta)
m_moEnergy[1] = energies;
else
m_moEnergy[0] = energies;
}

inline void BasisSet::setMolecularOrbitalOccupancy(
const std::vector<unsigned char>& occ, ElectronType type)
{
if (type == Beta)
m_moOccupancy[1] = occ;
else
m_moOccupancy[0] = occ;
}

} // namespace Avogadro::Core

#endif
20 changes: 1 addition & 19 deletions avogadro/core/gaussianset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,6 @@ bool GaussianSet::setActiveSetStep(int index)
return true;
}

void GaussianSet::setMolecularOrbitalEnergy(const vector<double>& energies,
ElectronType type)
{
if (type == Beta)
m_moEnergy[1] = energies;
else
m_moEnergy[0] = energies;
}

void GaussianSet::setMolecularOrbitalOccupancy(const vector<unsigned char>& occ,
ElectronType type)
{
if (type == Beta)
m_moOccupancy[1] = occ;
else
m_moOccupancy[0] = occ;
}

void GaussianSet::setMolecularOrbitalNumber(const vector<unsigned int>& nums,
ElectronType type)
{
Expand All @@ -195,7 +177,7 @@ bool GaussianSet::setSpinDensityMatrix(const MatrixX& m)
return true;
}

unsigned int GaussianSet::molecularOrbitalCount(ElectronType type)
unsigned int GaussianSet::molecularOrbitalCount(ElectronType type) const
{
size_t index(0);
if (type == Beta)
Expand Down
61 changes: 1 addition & 60 deletions avogadro/core/gaussianset.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,6 @@ class AVOGADROCORE_EXPORT GaussianSet : public BasisSet
*/
bool setActiveSetStep(int index);

/**
* @brief Set the molecular orbital energies, expected in Hartrees.
* @param energies The vector containing energies for the MOs of type
* @param type The type of the electrons being set.
*/
void setMolecularOrbitalEnergy(const std::vector<double>& energies,
ElectronType type = Paired);

/**
* @brief Set the molecular orbital occupancies.
* @param occ The occupancies for the MOs of type.
* @param type The type of the electrons being set.
*/
void setMolecularOrbitalOccupancy(const std::vector<unsigned char>& occ,
ElectronType type = Paired);

/**
* @brief This enables support of sparse orbital sets, and provides a mapping
* from the index in memory to the actual molecular orbital number.
Expand Down Expand Up @@ -182,7 +166,7 @@ class AVOGADROCORE_EXPORT GaussianSet : public BasisSet
/**
* @return The number of molecular orbitals in the GaussianSet.
*/
unsigned int molecularOrbitalCount(ElectronType type = Paired) override;
unsigned int molecularOrbitalCount(ElectronType type = Paired) const override;

/**
* Debug routine, outputs all of the data in the GaussianSet.
Expand Down Expand Up @@ -260,38 +244,6 @@ class AVOGADROCORE_EXPORT GaussianSet : public BasisSet
return m_moMatrix[1];
}

std::vector<double>& moEnergy(ElectronType type = Paired)
{
if (type == Paired || type == Alpha)
return m_moEnergy[0];
else
return m_moEnergy[1];
}

std::vector<double> moEnergy(ElectronType type = Paired) const
{
if (type == Paired || type == Alpha)
return m_moEnergy[0];
else
return m_moEnergy[1];
}

std::vector<unsigned char>& moOccupancy(ElectronType type = Paired)
{
if (type == Paired || type == Alpha)
return m_moOccupancy[0];
else
return m_moOccupancy[1];
}

std::vector<unsigned char> moOccupancy(ElectronType type = Paired) const
{
if (type == Paired || type == Alpha)
return m_moOccupancy[0];
else
return m_moOccupancy[1];
}

std::vector<unsigned int>& moNumber(ElectronType type = Paired)
{
if (type == Paired || type == Alpha)
Expand Down Expand Up @@ -337,17 +289,6 @@ class AVOGADROCORE_EXPORT GaussianSet : public BasisSet
*/
std::vector<MatrixX> m_moMatrixSet[2];

/**
* @brief This block stores energies for the molecular orbitals (same
* convention as the molecular orbital coefficients).
*/
std::vector<double> m_moEnergy[2];

/**
* @brief The occupancy of the molecular orbitals.
*/
std::vector<unsigned char> m_moOccupancy[2];

/**
* @brief This stores the molecular orbital number (when they are sparse). It
* is used to lookup the actual index of the molecular orbital data.
Expand Down
8 changes: 3 additions & 5 deletions avogadro/core/slaterset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ bool SlaterSet::addDensityMatrix(const Eigen::MatrixXd& d)
return true;
}

unsigned int SlaterSet::molecularOrbitalCount(ElectronType)
unsigned int SlaterSet::molecularOrbitalCount(ElectronType) const
{
return static_cast<unsigned int>(m_overlap.cols());
}

void SlaterSet::outputAll()
{
}
void SlaterSet::outputAll() {}

void SlaterSet::initCalculation()
{
Expand Down Expand Up @@ -133,7 +131,7 @@ void SlaterSet::initCalculation()
}
}
// Convert the exponents into Angstroms
for (double & m_zeta : m_zetas)
for (double& m_zeta : m_zetas)
m_zeta = m_zeta / BOHR_TO_ANGSTROM_D;

m_initialized = true;
Expand Down
2 changes: 1 addition & 1 deletion avogadro/core/slaterset.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class AVOGADROCORE_EXPORT SlaterSet : public BasisSet
/**
* @return The number of molecular orbitals in the BasisSet.
*/
unsigned int molecularOrbitalCount(ElectronType type = Paired) override;
unsigned int molecularOrbitalCount(ElectronType type = Paired) const override;

/**
* @return True of the basis set is valid, false otherwise.
Expand Down
7 changes: 7 additions & 0 deletions avogadro/io/cjsonformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,13 @@ bool CjsonFormat::deserialize(std::istream& file, Molecule& molecule,
numArray.push_back(static_cast<unsigned int>(number));
basis->setMolecularOrbitalNumber(numArray);
}
json symmetryLabels = orbitals["symmetries"];
if (symmetryLabels.is_array()) {
std::vector<std::string> symArray;
for (auto& sym : symmetryLabels)
symArray.push_back(sym);
basis->setSymmetryLabels(symArray);
}
json moCoefficients = orbitals["moCoefficients"];
json moCoefficientsA = orbitals["alphaCoefficients"];
json moCoefficientsB = orbitals["betaCoefficients"];
Expand Down
10 changes: 7 additions & 3 deletions avogadro/qtgui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if(QT_VERSION EQUAL 6)
find_package(Qt6 COMPONENTS Widgets REQUIRED)
find_package(Qt6 COMPONENTS Widgets Concurrent REQUIRED)
else()
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Widgets Concurrent REQUIRED)
endif()

# Provide some simple API to find the plugins, scripts, etc.
Expand Down Expand Up @@ -40,6 +40,7 @@ avogadro_headers(QtGui
extensionplugin.h
filebrowsewidget.h
fileformatdialog.h
gaussiansetconcurrent.h
generichighlighter.h
hydrogentools.h
insertfragmentdialog.h
Expand All @@ -62,6 +63,7 @@ avogadro_headers(QtGui
sceneplugin.h
scenepluginmodel.h
scriptloader.h
slatersetconcurrent.h
sortfiltertreeproxymodel.h
toolplugin.h
utilities.h
Expand All @@ -79,6 +81,7 @@ target_sources(QtGui PRIVATE
extensionplugin.cpp
filebrowsewidget.cpp
fileformatdialog.cpp
gaussiansetconcurrent.cpp
generichighlighter.cpp
hydrogentools.cpp
insertfragmentdialog.cpp
Expand All @@ -100,6 +103,7 @@ target_sources(QtGui PRIVATE
sceneplugin.cpp
scenepluginmodel.cpp
scriptloader.cpp
slatersetconcurrent.cpp
sortfiltertreeproxymodel.cpp
toolplugin.cpp
utilities.cpp
Expand All @@ -120,4 +124,4 @@ qt_add_resources(RC_SOURCES ${RCS})
target_sources(QtGui PRIVATE ${RC_SOURCES})

avogadro_add_library(QtGui)
target_link_libraries(QtGui PUBLIC Avogadro::IO Qt::Widgets)
target_link_libraries(QtGui PUBLIC Avogadro::IO Qt::Widgets Qt::Concurrent)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <QtConcurrent/QtConcurrentMap>

namespace Avogadro::QtPlugins {
namespace Avogadro::QtGui {

using Core::BasisSet;
using Core::Cube;
Expand Down Expand Up @@ -147,4 +147,4 @@ void GaussianSetConcurrent::processSpinDensity(GaussianShell& shell)
Vector3 pos = shell.tCube->position(shell.pos);
shell.tCube->setValue(shell.pos, shell.tools->calculateSpinDensity(pos));
}
} // namespace Avogadro::QtPlugins
} // namespace Avogadro::QtGui
Loading

0 comments on commit 52a45ce

Please sign in to comment.