Skip to content

Commit cdfa4ec

Browse files
committed
Add arc support in testgrad
1 parent 419d410 commit cdfa4ec

File tree

3 files changed

+74
-52
lines changed

3 files changed

+74
-52
lines changed

src/xanalyze.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "tool/ioprint.h"
1818
#include "tool/ioread.h"
1919
#include "tool/iotext.h"
20-
#include <fstream>
2120
#include <tinker/detail/atomid.hh>
2221
#include <tinker/detail/atoms.hh>
2322
#include <tinker/detail/bound.hh>
@@ -34,6 +33,8 @@
3433

3534
#include "tinker9.h"
3635

36+
#include <fstream>
37+
3738
namespace tinker {
3839
static void xAnalyzeE()
3940
{

src/xdynamic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "tool/iofortstr.h"
55
#include "tool/ioprint.h"
66
#include "tool/ioread.h"
7-
#include <chrono>
8-
#include <cmath>
97
#include <tinker/detail/bath.hh>
108
#include <tinker/detail/bound.hh>
119
#include <tinker/detail/inform.hh>
@@ -14,6 +12,9 @@
1412

1513
#include "tinker9.h"
1614

15+
#include <chrono>
16+
#include <cmath>
17+
1718
namespace tinker {
1819
void xDynamic(int, char**)
1920
{

src/xtestgrad.cpp

Lines changed: 69 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#include "ff/energy.h"
2+
#include "ff/nblist.h"
3+
#include "tool/iofortstr.h"
24
#include "tool/ioprint.h"
5+
#include <tinker/detail/files.hh>
36
#include <tinker/detail/inform.hh>
47
#include <tinker/routines.h>
58

69
#include "tinker9.h"
710

11+
#include <fstream>
12+
813
#define TINKER_TESTGRAD_VIRIAL 0
914

1015
namespace tinker {
@@ -26,21 +31,6 @@ void xTestgrad(int, char**)
2631

2732
rc_flag = flags;
2833
initialize();
29-
energy(rc_flag);
30-
31-
std::vector<double> gdx(n), gdy(n), gdz(n);
32-
copyGradient(calc::grad, gdx.data(), gdy.data(), gdz.data());
33-
34-
const int len_e = 20 + digits;
35-
const char* fmt_e = "\n Total Potential Energy :%1$*2$.*3$f Kcal/mole\n\n";
36-
print(out, fmt_e, esum, len_e, digits);
37-
38-
#if TINKER_TESTGRAD_VIRIAL
39-
const char* fmt_v = " %-36s%12.3f %12.3f %12.3f\n";
40-
print(out, fmt_v, "Internal Virial Tensor :", vir[0], vir[1], vir[2]);
41-
print(out, fmt_v, "", vir[3], vir[4], vir[5]);
42-
print(out, fmt_v, "", vir[6], vir[7], vir[8]);
43-
#endif
4434

4535
std::string fmt_t;
4636
std::string fmt;
@@ -57,41 +47,71 @@ void xTestgrad(int, char**)
5747
"dE/dX %1$5s dE/dY %1$5s dE/dZ %1$8s Norm\n";
5848
fmt = "\n Anlyt%10d %12.4f%12.4f%12.4f %12.4f";
5949
}
60-
print(out, fmt_t, "");
61-
// auto do_print = [](int i, int n, int top_m) {
62-
// if (n <= 2 * top_m)
63-
// return true;
64-
// else if (i < top_m)
65-
// return true;
66-
// else if (i >= n - top_m)
67-
// return true;
68-
// else
69-
// return false;
70-
// };
71-
// int print_top_n = 15;
72-
for (int i = 0; i < n; ++i) {
73-
// if (not do_print(i, n, print_top_n))
74-
// continue;
75-
76-
real x1 = gdx[i];
77-
real y1 = gdy[i];
78-
real z1 = gdz[i];
79-
real norm = x1 * x1 + y1 * y1 + z1 * z1;
80-
norm = std::sqrt(norm);
81-
print(out, fmt, i + 1, x1, y1, z1, norm);
82-
}
8350

84-
double totnorm = 0;
85-
for (int i = 0; i < n; ++i) {
86-
totnorm += gdx[i] * gdx[i] + gdy[i] * gdy[i] + gdz[i] * gdz[i];
87-
}
88-
totnorm = std::sqrt(totnorm);
89-
double rms = totnorm / std::sqrt(n);
90-
print(out, "\n\n Total Gradient Norm and RMS Gradient per Atom :\n");
91-
const char* fmt3 = "\n Anlyt %1$-30s%2$*3$.*4$f\n";
92-
const int len3 = 13 + digits;
93-
print(out, fmt3, "Total Gradient Norm Value", totnorm, len3, digits);
94-
print(out, fmt3, "RMS Gradient over All Atoms", rms, len3, digits);
51+
FstrView fsw = files::filename;
52+
std::string fname = fsw.trim();
53+
std::ifstream ipt(fname);
54+
bool done = false;
55+
int nframe_processed = 0;
56+
do {
57+
readFrameCopyinToXyz(ipt, done);
58+
nblistRefresh();
59+
nframe_processed++;
60+
if (nframe_processed > 1)
61+
print(out, "\n Analysis for Archive Structure :%16d\n", nframe_processed);
62+
63+
energy(rc_flag);
64+
65+
std::vector<double> gdx(n), gdy(n), gdz(n);
66+
copyGradient(calc::grad, gdx.data(), gdy.data(), gdz.data());
67+
68+
const int len_e = 20 + digits;
69+
const char* fmt_e = "\n Total Potential Energy :%1$*2$.*3$f Kcal/mole\n\n";
70+
print(out, fmt_e, esum, len_e, digits);
71+
72+
#if TINKER_TESTGRAD_VIRIAL
73+
const char* fmt_v = " %-36s%12.3f %12.3f %12.3f\n";
74+
print(out, fmt_v, "Internal Virial Tensor :", vir[0], vir[1], vir[2]);
75+
print(out, fmt_v, "", vir[3], vir[4], vir[5]);
76+
print(out, fmt_v, "", vir[6], vir[7], vir[8]);
77+
#endif
78+
79+
print(out, fmt_t, "");
80+
// auto do_print = [](int i, int n, int top_m) {
81+
// if (n <= 2 * top_m)
82+
// return true;
83+
// else if (i < top_m)
84+
// return true;
85+
// else if (i >= n - top_m)
86+
// return true;
87+
// else
88+
// return false;
89+
// };
90+
// int print_top_n = 15;
91+
for (int i = 0; i < n; ++i) {
92+
// if (not do_print(i, n, print_top_n))
93+
// continue;
94+
95+
real x1 = gdx[i];
96+
real y1 = gdy[i];
97+
real z1 = gdz[i];
98+
real norm = x1 * x1 + y1 * y1 + z1 * z1;
99+
norm = std::sqrt(norm);
100+
print(out, fmt, i + 1, x1, y1, z1, norm);
101+
}
102+
103+
double totnorm = 0;
104+
for (int i = 0; i < n; ++i) {
105+
totnorm += gdx[i] * gdx[i] + gdy[i] * gdy[i] + gdz[i] * gdz[i];
106+
}
107+
totnorm = std::sqrt(totnorm);
108+
double rms = totnorm / std::sqrt(n);
109+
print(out, "\n\n Total Gradient Norm and RMS Gradient per Atom :\n");
110+
const char* fmt3 = "\n Anlyt %1$-30s%2$*3$.*4$f\n";
111+
const int len3 = 13 + digits;
112+
print(out, fmt3, "Total Gradient Norm Value", totnorm, len3, digits);
113+
print(out, fmt3, "RMS Gradient over All Atoms", rms, len3, digits);
114+
} while (not done);
95115

96116
finish();
97117
tinker_f_final();

0 commit comments

Comments
 (0)