Skip to content

Commit

Permalink
replace some vector/array matrices with eigen matrices
Browse files Browse the repository at this point in the history
Signed-off-by: Conrad Hübler <[email protected]>
  • Loading branch information
conradhuebler committed Mar 5, 2024
1 parent a1d8d55 commit a32acc5
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 110 deletions.
4 changes: 2 additions & 2 deletions src/capabilities/curcumaopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void CurcumaOpt::ProcessMoleculesSerial(const std::vector<Molecule>& molecules)
#endif

if (m_hessian) {
Hessian hess(m_method, m_defaults, m_threads);
Hessian hess(m_method, m_defaults, false);
hess.setMolecule(*iter);
hess.CalculateHessian(m_hessian);
}
Expand Down Expand Up @@ -191,7 +191,7 @@ void CurcumaOpt::ProcessMolecules(const std::vector<Molecule>& molecules)

Molecule* mol2 = new Molecule(thread->getMolecule());
if (m_hessian) {
Hessian hess(m_method, m_defaults, m_threads);
Hessian hess(m_method, m_defaults, false);
hess.setMolecule(mol2);
hess.CalculateHessian(m_hessian);
}
Expand Down
22 changes: 11 additions & 11 deletions src/capabilities/hessian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ void HessianThread::Numerical()
m_geom_ip_jm = m_molecule.Coords();
m_geom_im_jm = m_molecule.Coords();

m_geom_ip_jp[m_i][m_xi] += m_d;
m_geom_ip_jp[m_j][m_xj] += m_d;
m_geom_ip_jp(m_i, m_xi) += m_d;
m_geom_ip_jp(m_j, m_xj) += m_d;

m_geom_im_jp[m_i][m_xi] -= m_d;
m_geom_im_jp[m_j][m_xj] += m_d;
m_geom_im_jp(m_i, m_xi) -= m_d;
m_geom_im_jp(m_j, m_xj) += m_d;

m_geom_ip_jm[m_i][m_xi] += m_d;
m_geom_ip_jm[m_j][m_xj] -= m_d;
m_geom_ip_jm(m_i, m_xi) += m_d;
m_geom_ip_jm(m_j, m_xj) -= m_d;

m_geom_im_jm[m_i][m_xi] -= m_d;
m_geom_im_jm[m_j][m_xj] -= m_d;
m_geom_im_jm(m_i, m_xi) -= m_d;
m_geom_im_jm(m_j, m_xj) -= m_d;

EnergyCalculator energy(m_method, m_controller);
energy.setMolecule(m_molecule);
Expand All @@ -104,7 +104,7 @@ void HessianThread::Seminumerical()
m_geom_ip_jp = m_molecule.Coords();
m_geom_im_jp = m_molecule.Coords();

m_geom_ip_jp[m_i][m_xi] += m_d;
m_geom_ip_jp(m_i, m_xi) += m_d;
// std::cout << m_controller << std::endl;

EnergyCalculator energy(m_method, m_controller);
Expand All @@ -115,7 +115,7 @@ void HessianThread::Seminumerical()
energy.CalculateEnergy(true, false);
Matrix gradientp = energy.Gradient();

m_geom_im_jp[m_i][m_xi] -= m_d;
m_geom_im_jp(m_i, m_xi) -= m_d;

energy.updateGeometry(m_geom_im_jp);
energy.CalculateEnergy(true, false);
Expand All @@ -130,7 +130,7 @@ Hessian::Hessian(const std::string& method, const json& controller, bool silent)

{
UpdateController(controller);
m_threads = m_controller["threads"];
m_threads = m_defaults["threads"];
/* Yeah, thats not really correct, but it works a bit */
if (m_method.compare("gfnff") == 0) {
m_scale_functions = [](double val) -> double {
Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/hessian.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class HessianThread : public CxxThread {
json m_controller, m_parameter;
Molecule m_molecule;
Matrix m_gradient;
std::vector<std::array<double, 3>> m_geom_ip_jp, m_geom_im_jp, m_geom_ip_jm, m_geom_im_jm;
Geometry m_geom_ip_jp, m_geom_im_jp, m_geom_ip_jm, m_geom_im_jm;
int m_i, m_j, m_xi, m_xj;
bool m_fullnumerical = true;
double m_dd = 0;
Expand Down
14 changes: 13 additions & 1 deletion src/core/energycalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ void EnergyCalculator::updateGeometry(const std::vector<double>& geometry)
}
// m_containsNaN = std::isnan(m_geometry[m_atoms - 1][0]);
}

void EnergyCalculator::updateGeometry(const Matrix& geometry)
{
m_geometry = geometry;
for (int i = 0; i < m_atoms; ++i) {
m_coord[3 * i + 0] = geometry(i, 0) / au;
m_coord[3 * i + 1] = geometry(i, 1) / au;
m_coord[3 * i + 2] = geometry(i, 2) / au;
}
}

/*
void EnergyCalculator::updateGeometry(const std::vector<std::array<double, 3>>& geometry)
{
for (int i = 0; i < m_atoms; ++i) {
Expand All @@ -297,7 +309,7 @@ void EnergyCalculator::updateGeometry(const std::vector<std::array<double, 3>>&
m_geometry(i, 2) = geometry[i][2];
}
}

*/
double EnergyCalculator::CalculateEnergy(bool gradient, bool verbose)
{
m_ecengine(gradient, verbose);
Expand Down
4 changes: 2 additions & 2 deletions src/core/energycalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class EnergyCalculator {
void updateGeometry(const double* coord);
void updateGeometry(const std::vector<double>& geometry);

void updateGeometry(const std::vector<std::array<double, 3>>& geometry);

// void updateGeometry(const std::vector<std::array<double, 3>>& geometry);
void updateGeometry(const Matrix& geometry);
void updateGeometry(const Eigen::VectorXd& geometry);

void getGradient(double* coord);
Expand Down
2 changes: 1 addition & 1 deletion src/core/forcefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ForceField::ForceField(const json& controller)
{
m_threadpool = new CxxThreadPool();
m_threadpool->setProgressBar(CxxThreadPool::ProgressBarType::None);
m_threads = 16;
m_threads = 1;
}

void ForceField::UpdateGeometry(const Matrix& geometry)
Expand Down
Loading

0 comments on commit a32acc5

Please sign in to comment.