Skip to content

Commit

Permalink
output of dipole from -dipole
Browse files Browse the repository at this point in the history
  • Loading branch information
gg27fyla committed Oct 28, 2024
1 parent 6bfd1a2 commit c66dc6d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion external/CxxThreadPool
2 changes: 1 addition & 1 deletion external/tblite
Submodule tblite updated 63 files
+84 −53 .github/workflows/build.yml
+10 −12 .github/workflows/wheel.yml
+1 −0 README.md
+2 −2 app/cli.f90
+25 −29 app/driver_guess.f90
+6 −7 app/driver_run.f90
+2 −2 assets/ci/build-env.yaml
+1 −1 config/cmake/Findmstore.cmake
+2 −2 config/meson.build
+4 −0 doc/index.rst
+0 −1 doc/tutorial/index.rst
+0 −84 doc/tutorial/parallel.rst
+1 −11 include/tblite/result.h
+1 −1 man/tblite-guess.1.adoc
+23 −23 python/tblite/interface.py
+9 −33 python/tblite/library.py
+0 −1 python/tblite/meson.build
+0 −1 python/tblite/py.typed
+1 −61 python/tblite/test_interface.py
+6 −29 src/tblite/api/calculator.f90
+17 −41 src/tblite/api/result.f90
+367 −928 src/tblite/ceh/ceh.f90
+36 −60 src/tblite/ceh/h0.f90
+22 −58 src/tblite/ceh/singlepoint.f90
+1 −1 src/tblite/context/CMakeLists.txt
+1 −1 src/tblite/context/meson.build
+1 −7 src/tblite/context/type.f90
+1 −3 src/tblite/coulomb/charge/effective.f90
+0 −2 src/tblite/coulomb/charge/gamma.f90
+9 −23 src/tblite/coulomb/charge/type.f90
+1 −240 src/tblite/double_dictionary.f90
+192 −730 src/tblite/integral/diat_trafo.f90
+57 −46 src/tblite/integral/dipole.f90
+60 −48 src/tblite/integral/multipole.f90
+115 −76 src/tblite/integral/overlap.f90
+28 −28 src/tblite/integral/trafo.f90
+4 −6 src/tblite/ncoord.f90
+9 −17 src/tblite/ncoord/erf.f90
+6 −14 src/tblite/ncoord/erf_en.f90
+5 −13 src/tblite/ncoord/exp.f90
+0 −2 src/tblite/ncoord/type.f90
+1 −9 src/tblite/output/ascii.f90
+9 −32 src/tblite/wavefunction/guess.f90
+1 −0 src/tblite/wavefunction/type.f90
+2 −11 src/tblite/xtb/gfn1.f90
+2 −11 src/tblite/xtb/gfn2.f90
+2 −11 src/tblite/xtb/ipea1.f90
+0 −1 src/tblite/xtb/singlepoint.f90
+1 −1 subprojects/mstore.wrap
+152 −77 test/api/main.c
+446 −688 test/unit/test_ceh.f90
+1 −171 test/unit/test_double_dictionary.f90
+7 −14 test/unit/test_gfn1_xtb.f90
+6 −12 test/unit/test_gfn2_xtb.f90
+95 −94 test/unit/test_hamiltonian.f90
+61 −61 test/unit/test_integral_multipole.f90
+283 −1,512 test/unit/test_integral_overlap.f90
+6 −12 test/unit/test_ipea1_xtb.f90
+98 −106 test/unit/test_ncoord.f90
+2 −4 test/unit/test_post_processing.f90
+4 −8 test/unit/test_spin.f90
+6 −12 test/unit/test_xtb_external.f90
+5 −7 test/unit/test_xtb_param.f90
6 changes: 2 additions & 4 deletions src/capabilities/optimiser/OptimiseDipoleScaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ struct OptDipoleFunctor : TFunctor<double> {
int operator()(const Vector& scaling, Eigen::VectorXd& fvec) const {
// calculation of residuals
for (int i = 0; i < m_conformers.size(); ++i) {
auto conf = m_conformers.at(i);
fvec(i) = (conf.getDipole() - conf.CalculateDipoleMoment(scaling, m_bond)).norm();
const auto& conf = m_conformers.at(i);
fvec(i) = conf.getDipole().norm() - conf.CalculateDipoleMoment(scaling).norm();
}
return 0;
}
int no_parameter;
int no_points;
std::vector<Molecule> m_conformers;
bool m_bond;

int inputs() const { return no_parameter; }
int values() const { return no_points; }
Expand All @@ -80,7 +79,6 @@ inline Vector OptimiseDipoleScaling(const std::vector<Molecule>& conformers, Vec

OptDipoleFunctor functor(2, conformers.size());
functor.m_conformers = conformers;
functor.m_bond = bond;
Eigen::NumericalDiff numDiff(functor);
Eigen::LevenbergMarquardt lm(numDiff);

Expand Down
61 changes: 33 additions & 28 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,50 +955,55 @@ int main(int argc, char **argv) {
const Vector one = VectorXd::Ones(mol.AtomCount());

const auto result = OptimiseDipoleScaling(conformers, one);
std::cout << "nonlinear Scaling vector, 1 as initial guess:\n"
std::cout << "nonlinear Scaling vector:\n"
<< result << "\n"
<< "Dipole: " << mol.CalculateDipoleMoment(result).norm() << std::endl
<< std::endl;

const auto result2 = OptimiseDipoleScaling(conformers, theta, true);
std::cout << "nonlinear Scaling vector, with bond true:\n"
<< result2 << "\n"
<< "Dipole: " << mol.CalculateDipoleMoment(result2, true).norm() << std::endl
<< std::endl;

//TODO make it faster...

double r2_anal = 0;
double r2_LM = 0;
double r2_LM2 = 0;
//double r2_anal_dn = 0;
//double r2_LM_dn = 0;
//double r2_LM1_dn = 0;
//double r2_LM2_dn = 0;
double r2_lin = 0;
double r2_nlin = 0;
double r2_lin_diffofnorm = 0;
double r2_nlin_diffofnorm = 0;

for (const auto& conf : conformers) {
const double residual = conf.CalculateDipoleMoment(theta).norm() - conf.getDipole().norm();
r2_anal += residual * residual;
const double residual_1 = conf.CalculateDipoleMoment(result).norm() - conf.getDipole().norm();
r2_LM += residual_1 * residual_1;
const double residual_2 = conf.CalculateDipoleMoment(result2).norm() - conf.getDipole().norm();
r2_LM2 += residual_2 * residual_2;
//r2_anal_dn += std::pow((conf.CalculateDipoleMoment(theta) - conf.getDipole()).norm(), 2);
//r2_LM_dn += std::pow((conf.CalculateDipoleMoment(result) - conf.getDipole()).norm(), 2);
//r2_LM1_dn += std::pow((conf.CalculateDipoleMoment(result1) - conf.getDipole()).norm(), 2);
//r2_LM2_dn += std::pow((conf.CalculateDipoleMoment(result2) - conf.getDipole()).norm(), 2);
const double residual = (conf.CalculateDipoleMoment(theta) - conf.getDipole()).norm();
r2_lin += residual * residual;
const double residual_1 = (conf.CalculateDipoleMoment(result) - conf.getDipole()).norm();
r2_nlin += residual_1 * residual_1;
const double residual_2 = conf.CalculateDipoleMoment(theta).norm() - conf.getDipole().norm();
r2_lin_diffofnorm += residual_2 * residual_2;
const double residual_3 = conf.CalculateDipoleMoment(result).norm() - conf.getDipole().norm();
r2_nlin_diffofnorm += residual_3 * residual_3;
}
std::cout << "Residuals:" << std::endl
<< "anal: " << r2_anal << std::endl
<< "LM 1 as initial guess: " << r2_LM << std::endl
<< "LM bond true: " << r2_LM2 << std::endl;
std::cout << "Residuals magnitute of diffrence of Vector:" << std::endl
<< "linear: " << r2_lin << std::endl
<< "nonlinear " << r2_nlin << std::endl;
std::cout << "Residuals diffrence of magnitute of Vector:" << std::endl
<< "linear: " << r2_lin_diffofnorm << std::endl
<< "nonlinear: " << r2_lin_diffofnorm << std::endl;

std::vector<double> vec_theta(theta.data(), theta.data() + theta.rows() * theta.cols());
std::vector<double> vec_nonlinear_scaling(result.data(), result.data() + result.rows() * result.cols());
json scaling_vector;
scaling_vector["scaling_vector"] = Tools::DoubleVector2String(vec_theta);
std::ofstream out(lm_basename + "_scaling_vector.json");
out << scaling_vector << std::endl;

std::ofstream file_dipole;
file_dipole.open(lm_basename + "_dipole.out", std::ios_base::app);
file_dipole << "linear Dipole of Fragments (x y z magn.); nonlinear Dipole of Fragments (x y z magn.); gfn2 Dipoles (x y z magn.)" << std::endl;
for (const auto& conf : conformers){
const auto dipole_lin = conf.CalculateDipoleMoment(vec_theta);
const auto dipole_nlin = conf.CalculateDipoleMoment(vec_nonlinear_scaling);
const auto dipole_gfn2 = conf.getDipole();
file_dipole << dipole_lin[0] << " " << dipole_lin[1] << " " << dipole_lin[2] << " " << dipole_lin.norm() << "; ";
file_dipole << dipole_nlin[0] << " " << dipole_nlin[1] << " " << dipole_nlin[2] << " " << dipole_nlin.norm() << "; ";
file_dipole << dipole_gfn2[0] << " " << dipole_gfn2[1] << " " << dipole_gfn2[2] << " " << dipole_gfn2.norm() << std::endl;
};
file_dipole.close();



} else if (strcmp(argv[1], "-stride") == 0) {
Expand Down

0 comments on commit c66dc6d

Please sign in to comment.