TheochemUI / eOn

eOn v3 and beyond
https://theochemui.github.io/eOn/
BSD 3-Clause "New" or "Revised" License
2 stars 2 forks source link

BUG: Fix setting potentials on the fly #94

Closed HaoZeke closed 3 months ago

HaoZeke commented 3 months ago

There's a failing test on main. Consider Sulfolene:

``` Generated by eOn 25.000000 25.000000 25.000000 90.000000 90.000000 90.000000 4 2 4 6 1 15.990000 12.011000 1.008000 32.065000 O Coordinates of component 1 10.477713 12.379463 12.871778 0 1 9.838316 12.065258 10.599445 0 2 C Coordinates of component 2 13.632107 12.976546 11.590461 0 3 12.574398 13.442847 10.828786 0 4 13.839846 11.585323 11.720681 0 5 13.015406 10.695876 11.089027 0 6 H Coordinates of component 3 14.180164 13.651700 12.258033 0 7 12.293139 14.494230 10.914210 0 8 12.410976 13.061416 9.811738 0 9 12.993463 9.652122 11.395309 0 10 14.546376 11.239529 12.484877 0 11 12.591733 10.859365 10.096371 0 12 S Coordinates of component 4 10.972953 12.113958 11.523496 0 13 ```
➜ ./eonclient -s pos.con -p lj
Energy:         -8.9245813315
(free) Forces:         
 0.4635285374 -0.2484100126 -1.3089178734
 1.0831339486  0.0575693479  0.8861347983
-2.2011600279 -2.2340200666 -2.0906423413
 2.2379653746 -2.4027761490  2.5039616183
-2.7115340676  0.9726026339 -2.4177810365
 2.1495273152  3.6240405639  2.3242048032
 0.8236610515  1.0294167816  1.0403261788
-0.4885817819  1.8617266713  0.0369450472
-0.2347437545 -0.4603965820 -1.2106122015
-0.0650385926 -2.2484176061  0.5602311744
 1.0383193139 -0.5129147026  1.1574891481
-0.8131215857  0.3109686072 -1.7894098098
-1.2819557309  0.2506105131  0.3080704941
Max atom force: 4.8120749843e+00

While with morse

➜ ./eonclient -s pos.con -p morse_pt
Energy:         1611.8700112470
(free) Forces:         
 -64.9255529323   38.3477815674  194.5301234723
-157.2886548113   -7.6114688656 -134.6124664082
-164.7476210787 -274.9078619357 -285.3046914386
  76.0495351973 -338.6679011745  421.1129959773
-226.0688310947  166.3553382123 -318.8578493811
 106.5522349347  385.3497379225  298.4154272441
 364.5553407650  448.2974684116  440.5020643725
-201.2596791185  742.2766860827   84.4900912592
-106.2677131119 -272.6711417402 -696.3144528269
 -12.0384568833 -743.5173938902  239.3852594376
 469.9999208172 -229.5719642973  504.7019921138
-293.6330322207  125.0680086493 -697.9750654055
 209.0725095372  -38.7472889424  -50.0734284165
Max atom force: 7.8119673700e+02

So far so good, adnd that's what the test is supposed to check..

TEST_F(MatterTest, SetPotential) {
  params->potential = PotType::LJ;
  double m1_ipot = m1->getPotentialEnergy();
  params->potential = PotType::MORSE_PT;
  auto pot{helper_functions::makePotential(params->potential, params)};
  ASSERT_NE(m1->getPotential(), pot);
  m1->setPotential(pot);
  ASSERT_EQ(m1->getPotential()->getType(), pot->getType());
  double m1_fpot = m1->getPotentialEnergy();
  ASSERT_NEAR(m1_ipot, -8.9245813315, 1e-5);
  ASSERT_NEAR(m1_fpot, 1611.8672392832, 1e-5);
  ASSERT_NE(m1_ipot, m1_fpot);
}

However it is failing:

meson test -C bbidr -vvv
Updated potential energy: -2509.99
Recomputing potential...
Potential type: morse_pt
Using non-surrogate potential...
Updated potential energy: 1611.87
../gtests/MatterTest.cpp:72: Failure
The difference between m1_ipot and -8.9245813315 is 2501.0699999999974, which exceeds 1e-5, where