Skip to content

Commit 07070b6

Browse files
committed
update md and xtb
Signed-off-by: Conrad Huebler <[email protected]>
1 parent d84f329 commit 07070b6

File tree

5 files changed

+105
-19
lines changed

5 files changed

+105
-19
lines changed

Diff for: external/tblite

Submodule tblite updated 63 files

Diff for: src/capabilities/simplemd.cpp

+90-14
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ void SimpleMD::LoadControlJson()
226226
m_rm_COM = Json2KeyWord<double>(m_defaults, "rm_COM");
227227
int rattle = Json2KeyWord<int>(m_defaults, "rattle");
228228
m_rattle_maxiter = Json2KeyWord<int>(m_defaults, "rattle_maxiter");
229+
m_rattle_dynamic_tol_iter = Json2KeyWord<int>(m_defaults, "rattle_dynamic_tol_iter");
230+
m_rattle_dynamic_tol = Json2KeyWord<bool>(m_defaults, "rattle_dynamic_tol");
231+
229232
if (rattle == 1) {
230233
Integrator = [=](double* grad) {
231234
this->Rattle(grad);
@@ -718,6 +721,11 @@ nlohmann::json SimpleMD::WriteRestartInformation()
718721
restart["average_Virial"] = m_average_virial_correction;
719722
restart["average_Wall"] = m_average_wall_potential;
720723

724+
restart["rattle"] = m_rattle;
725+
restart["rattle_maxiter"] = m_rattle_maxiter;
726+
restart["rattle_dynamic_tol"] = m_rattle_tolerance;
727+
restart["rattle_dynamic_tol_iter"] = m_rattle_dynamic_tol_iter;
728+
721729
restart["coupling"] = m_coupling;
722730
restart["MaxTopoDiff"] = m_max_top_diff;
723731
restart["impuls"] = m_impuls;
@@ -789,7 +797,7 @@ bool SimpleMD::LoadRestartInformation()
789797

790798
bool SimpleMD::LoadRestartInformation(const json& state)
791799
{
792-
std::string geometry, velocities, constrains, zeta, xi, Q;
800+
std::string geometry, velocities, constrains, xi, Q;
793801

794802
try {
795803
m_method = state["method"];
@@ -879,10 +887,6 @@ bool SimpleMD::LoadRestartInformation(const json& state)
879887
} catch (json::type_error& e) {
880888
}
881889

882-
try {
883-
zeta = state["zeta"];
884-
} catch (json::type_error& e) {
885-
}
886890
try {
887891
xi = state["xi"];
888892
} catch (json::type_error& e) {
@@ -897,6 +901,30 @@ bool SimpleMD::LoadRestartInformation(const json& state)
897901
} catch (json::type_error& e) {
898902
}
899903

904+
try {
905+
m_rattle = state["rattle"];
906+
} catch (json::type_error& e) {
907+
}
908+
909+
try {
910+
m_rattle_tolerance = state["rattle_tolerance"];
911+
} catch (json::type_error& e) {
912+
}
913+
914+
try {
915+
m_rattle_maxiter = state["rattle_maxiter"];
916+
} catch (json::type_error& e) {
917+
}
918+
919+
try {
920+
m_rattle_dynamic_tol = state["rattle_dynamic_tol"];
921+
} catch (json::type_error& e) {
922+
}
923+
924+
try {
925+
m_rattle_dynamic_tol_iter = state["rattle_dynamic_tol_iter"];
926+
} catch (json::type_error& e) {
927+
}
900928
try {
901929
m_rmsd_mtd = state["rmsd_mtd"];
902930
if (m_rmsd_mtd) {
@@ -1112,7 +1140,10 @@ void SimpleMD::start()
11121140
fmt::print(fg(fmt::color::salmon) | fmt::emphasis::bold, "Simulation got unstable, exiting!\n");
11131141

11141142
std::ofstream restart_file("unstable_curcuma.json");
1115-
restart_file << WriteRestartInformation() << std::endl;
1143+
nlohmann::json restart;
1144+
restart[MethodName()[0]] = WriteRestartInformation();
1145+
restart_file << restart << std::endl;
1146+
11161147
m_time_step = 0;
11171148
aborted = true;
11181149

@@ -1127,14 +1158,20 @@ void SimpleMD::start()
11271158
if (m_writerestart > -1 && m_step % m_writerestart == 0) {
11281159
std::ofstream restart_file("curcuma_step_" + std::to_string(int(m_step * m_dT)) + ".json");
11291160
nlohmann::json restart;
1130-
restart_file << WriteRestartInformation() << std::endl;
1161+
restart[MethodName()[0]] = WriteRestartInformation();
1162+
restart_file << restart << std::endl;
11311163
}
11321164
if ((m_step && int(m_step * m_dT) % m_print == 0)) {
11331165
m_Etot = m_Epot + m_Ekin;
11341166
PrintStatus();
11351167
m_time_step = 0;
11361168
}
1137-
1169+
if (m_rattle && m_rattle_dynamic_tol) {
1170+
m_aver_rattle_Temp += m_T;
1171+
m_rattle_counter++;
1172+
if (m_rattle_counter == m_rattle_dynamic_tol_iter)
1173+
AdjustRattleTolerance();
1174+
}
11381175
if (m_impuls > m_T) {
11391176
InitVelocities(m_scale_velo * m_impuls_scaling);
11401177
EKin();
@@ -1187,12 +1224,30 @@ void SimpleMD::start()
11871224
}
11881225
}
11891226
std::ofstream restart_file("curcuma_final.json");
1190-
restart_file << WriteRestartInformation() << std::endl;
1227+
nlohmann::json restart;
1228+
restart[MethodName()[0]] = WriteRestartInformation();
1229+
restart_file << restart << std::endl;
11911230
if (aborted == false)
11921231
std::remove("curcuma_restart.json");
11931232
delete[] gradient;
11941233
}
11951234

1235+
void SimpleMD::AdjustRattleTolerance()
1236+
{
1237+
m_aver_rattle_Temp /= double(m_rattle_counter);
1238+
1239+
// std::pair<double, double> pair(m_rattle_tolerance, m_aver_Temp);
1240+
1241+
if (m_aver_rattle_Temp > m_T0)
1242+
m_rattle_tolerance -= 0.01;
1243+
else if (m_aver_rattle_Temp < m_T0)
1244+
m_rattle_tolerance += 0.01;
1245+
std::cout << m_rattle_counter << " " << m_aver_rattle_Temp << " " << m_rattle_tolerance << std::endl;
1246+
m_rattle_tolerance = std::abs(m_rattle_tolerance);
1247+
m_rattle_counter = 0;
1248+
m_aver_rattle_Temp = 0;
1249+
}
1250+
11961251
void SimpleMD::Verlet(double* grad)
11971252
{
11981253
double ekin = 0;
@@ -1254,7 +1309,7 @@ void SimpleMD::Verlet(double* grad)
12541309
}
12551310
ekin *= 0.5;
12561311
double T = 2.0 * ekin / (kb_Eh * m_dof);
1257-
m_unstable = T > 10000 * m_T;
1312+
m_unstable = T > 10000 * m_T || std::isnan(T);
12581313
m_T = T;
12591314
m_Ekin = ekin;
12601315
ThermostatFunction();
@@ -1275,6 +1330,7 @@ void SimpleMD::Rattle(double* grad)
12751330
* like dT^3 -> dT^2 and
12761331
* updated velocities of the second atom (minus instead of plus)
12771332
*/
1333+
TriggerWriteRestart();
12781334
double* coord = new double[3 * m_natoms];
12791335
double m_dT_inverse = 1 / m_dT;
12801336
std::vector<int> moved(m_natoms, 0);
@@ -1301,8 +1357,7 @@ void SimpleMD::Rattle(double* grad)
13011357
+ (coord[3 * i + 1] - coord[3 * j + 1]) * (coord[3 * i + 1] - coord[3 * j + 1])
13021358
+ (coord[3 * i + 2] - coord[3 * j + 2]) * (coord[3 * i + 2] - coord[3 * j + 2]));
13031359

1304-
if (std::abs(distance - distance_current) > 2 * m_rattle_tolerance * distance) {
1305-
active++;
1360+
if (std::abs(distance - distance_current) > m_rattle_tolerance) {
13061361
move = true;
13071362
double r = distance - distance_current;
13081363
double dx = m_current_geometry[3 * i + 0] - m_current_geometry[3 * j + 0];
@@ -1315,6 +1370,7 @@ void SimpleMD::Rattle(double* grad)
13151370
if (scalarproduct >= m_rattle_tolerance * distance) {
13161371
moved[i] = 1;
13171372
moved[j] = 1;
1373+
active++;
13181374

13191375
double lambda = r / (1 * (m_rmass[i] + m_rmass[j]) * scalarproduct);
13201376
while (std::abs(lambda) > max_mu)
@@ -1340,6 +1396,13 @@ void SimpleMD::Rattle(double* grad)
13401396
if (active == 0)
13411397
break;
13421398
}
1399+
if (iter >= m_rattle_maxiter) {
1400+
std::cout << "numeric difficulties - 1st step in rattle velocity verlet" << std::endl;
1401+
std::ofstream restart_file("unstable_curcuma_" + std::to_string(m_currentStep) + ".json");
1402+
nlohmann::json restart;
1403+
restart[MethodName()[0]] = WriteRestartInformation();
1404+
restart_file << restart << std::endl;
1405+
}
13431406
double ekin = 0;
13441407

13451408
for (int i = 0; i < m_natoms; ++i) {
@@ -1397,6 +1460,7 @@ void SimpleMD::Rattle(double* grad)
13971460
ekin = 0.0;
13981461
while (iter < m_rattle_maxiter) {
13991462
iter++;
1463+
int active = 0;
14001464
for (auto bond : m_bond_constrained) {
14011465
int i = bond.first.first, j = bond.first.second;
14021466
if (moved[i] == 1 && moved[j] == 1) {
@@ -1414,7 +1478,8 @@ void SimpleMD::Rattle(double* grad)
14141478
double mu = -1 * r / ((m_rmass[i] + m_rmass[j]) * distance);
14151479
while (std::abs(mu) > max_mu)
14161480
mu /= 2;
1417-
if (std::abs(mu) > m_rattle_tolerance && std::abs(mu) < max_mu) {
1481+
if (std::abs(mu) > m_rattle_tolerance) {
1482+
active = 1;
14181483
m_virial_correction += mu * distance;
14191484
m_velocities[3 * i + 0] += dx * mu * m_rmass[i];
14201485
m_velocities[3 * i + 1] += dy * mu * m_rmass[i];
@@ -1426,7 +1491,18 @@ void SimpleMD::Rattle(double* grad)
14261491
}
14271492
}
14281493
}
1494+
if (active == 0)
1495+
break;
14291496
}
1497+
1498+
if (iter >= m_rattle_maxiter) {
1499+
std::cout << "numeric difficulties - 2nd in rattle velocity verlet" << iter << std::endl;
1500+
std::ofstream restart_file("unstable_curcuma_" + std::to_string(m_currentStep) + ".json");
1501+
nlohmann::json restart;
1502+
restart[MethodName()[0]] = WriteRestartInformation();
1503+
restart_file << restart << std::endl;
1504+
}
1505+
14301506
if (move)
14311507
RemoveRotations(m_velocities);
14321508

@@ -1436,7 +1512,7 @@ void SimpleMD::Rattle(double* grad)
14361512
}
14371513
ekin *= 0.5;
14381514
double T = 2.0 * ekin / (kb_Eh * m_dof);
1439-
m_unstable = T > 10000 * m_T;
1515+
m_unstable = T > 10000 * m_T || std::isnan(T);
14401516
m_T = T;
14411517
ThermostatFunction();
14421518
EKin();

Diff for: src/capabilities/simplemd.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ static json CurcumaMDJson{
151151
{ "rattle", false },
152152
{ "rattle_tolerance", 1e-1 },
153153
{ "rattle_maxiter", 100 },
154-
{ "thermostat", "csvr" },
154+
{ "rattle_dynamic_tol", false },
155+
{ "rattle_dynamic_tol_iter", 100 },
156+
{ "thermostat", "csvr" }, // can be csvr (default), berendson, none, anderson or nosehover
155157
{ "respa", 1 },
156158
{ "threads", 1 },
157159
{ "dipole", false },
@@ -254,6 +256,8 @@ class SimpleMD : public CurcumaMethod {
254256
void Rattle_Verlet_Second(double* coord, double* grad);
255257
void Rattle_Constrain_Second(double* coord, double* grad);
256258

259+
void AdjustRattleTolerance();
260+
257261
void RemoveRotation(std::vector<double>& velo);
258262
void RemoveRotations(std::vector<double>& velo);
259263

@@ -294,7 +298,7 @@ class SimpleMD : public CurcumaMethod {
294298
double m_single_step = 1;
295299
double m_dT = 0.5, m_currentStep = 0, m_maxtime = 1000;
296300
int m_spin = 0, m_charge = 0, m_print = 100;
297-
double m_T0 = 298.13, m_aver_Temp = 0, m_rmsd = 1.5;
301+
double m_T0 = 298.13, m_aver_Temp = 0, m_aver_rattle_Temp = 0, m_rmsd = 1.5;
298302
double m_x0 = 0, m_y0 = 0, m_z0 = 0;
299303
double m_Ekin_exchange = 0.0;
300304
std::vector<double> m_current_geometry, m_mass, m_velocities, m_gradient, m_rmass, m_virial, m_gradient_bias;
@@ -318,6 +322,7 @@ class SimpleMD : public CurcumaMethod {
318322
int m_unix_started = 0, m_prev_index = 0, m_max_rescue = 10, m_current_rescue = 0, m_currentTime = 0, m_max_top_diff = 15, m_step = 0;
319323
int m_writerestart = -1;
320324
int m_respa = 1;
325+
int m_rattle_dynamic_tol_iter = 100;
321326
double m_pos_conv = 0, m_scale_velo = 1.0, m_coupling = 10;
322327
double m_impuls = 0, m_impuls_scaling = 0.75, m_dt2 = 0;
323328
double m_rattle_tolerance = 1;
@@ -340,6 +345,7 @@ class SimpleMD : public CurcumaMethod {
340345
int m_bias_structure_count = 0;
341346
int m_rmsd_fragment_count = 0;
342347
int m_wall_type = 0;
348+
int m_rattle_counter = 0;
343349
std::vector<double> m_collected_dipole;
344350
Matrix m_topo_initial;
345351
std::vector<Molecule*> m_unique_structures;
@@ -352,7 +358,7 @@ class SimpleMD : public CurcumaMethod {
352358
bool m_rmsd_mtd = false;
353359
bool m_wtmtd = false;
354360
bool m_rmsd_fix_structure = false;
355-
361+
bool m_rattle_dynamic_tol = false;
356362
int m_mtd_dT = -1;
357363
int m_seed = -1;
358364
int m_time_step = 0;
@@ -367,6 +373,8 @@ class SimpleMD : public CurcumaMethod {
367373
int m_chain_length = 3; // Länge der Thermostatkette
368374

369375
double m_anderson = 0.01;
376+
377+
std::vector<std::pair<double, double>> m_rattle_tol_temp;
370378
};
371379

372380
class MDThread : public CxxThread {

Diff for: src/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,8 @@ int main(int argc, char **argv) {
902902
while (!file.AtEnd()) {
903903
Molecule mol = file.Next();
904904
std::pair<double, double> gyr = mol.GyrationRadius(hmass);
905+
if (std::isnan(gyr.first) || std::isnan(gyr.second))
906+
continue;
905907
sum += gyr.first;
906908
sum_mass += gyr.second;
907909
sqrt_sum += sqrt(gyr.first);

0 commit comments

Comments
 (0)