|
4 | 4 | #include "md/misc.h"
|
5 | 5 | #include "md/pq.h"
|
6 | 6 | #include "tool/execq.h"
|
| 7 | +#include "tool/iofortstr.h" |
7 | 8 | #include <condition_variable>
|
8 | 9 | #include <future>
|
9 | 10 | #include <mutex>
|
10 | 11 | #include <tinker/detail/atomid.hh>
|
11 | 12 | #include <tinker/detail/atoms.hh>
|
| 13 | +#include <tinker/detail/couple.hh> |
12 | 14 | #include <tinker/detail/deriv.hh>
|
| 15 | +#include <tinker/detail/files.hh> |
13 | 16 | #include <tinker/detail/moldyn.hh>
|
14 | 17 | #include <tinker/detail/output.hh>
|
15 | 18 | #include <tinker/detail/polar.hh>
|
| 19 | +#include <tinker/detail/titles.hh> |
16 | 20 | #include <tinker/detail/units.hh>
|
17 | 21 | #include <tinker/routines.h>
|
18 | 22 |
|
@@ -174,6 +178,89 @@ void mdsaveAsync(int istep, time_prec dt)
|
174 | 178 | idle_dup = false;
|
175 | 179 | }
|
176 | 180 |
|
| 181 | +void mdDebugSaveSync() |
| 182 | +{ |
| 183 | + auto DOT3 = [](const double* a, const double* b) -> double { |
| 184 | + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; |
| 185 | + }; |
| 186 | + |
| 187 | + static bool first = true; |
| 188 | + static std::vector<pos_prec> qx, qy, qz; |
| 189 | + static std::string fname, title; |
| 190 | + if (first) { |
| 191 | + first = false; |
| 192 | + qx.resize(n); |
| 193 | + qy.resize(n); |
| 194 | + qz.resize(n); |
| 195 | + FstrView fstr = files::filename; |
| 196 | + fname = fstr.trim(); |
| 197 | + auto pos = fname.find_last_of('.'); |
| 198 | + fname = fname.substr(0, pos) + ".dbg"; |
| 199 | + FstrView ftitl = titles::title; |
| 200 | + title = ftitl.trim(); |
| 201 | + FILE* ftmp = fopen(fname.c_str(), "w"); |
| 202 | + fclose(ftmp); |
| 203 | + } |
| 204 | + |
| 205 | + FILE* fout = fopen(fname.c_str(), "a"); |
| 206 | + |
| 207 | + darray::copyout(g::q0, n, qx.data(), xpos); |
| 208 | + darray::copyout(g::q0, n, qy.data(), ypos); |
| 209 | + darray::copyout(g::q0, n, qz.data(), zpos); |
| 210 | + waitFor(g::q0); |
| 211 | + |
| 212 | + bool bign = n > 999999; |
| 213 | + if (bign) |
| 214 | + fprintf(fout, "%8d %s\n", n, title.c_str()); |
| 215 | + else |
| 216 | + fprintf(fout, "%6d %s\n", n, title.c_str()); |
| 217 | + |
| 218 | + if (box_shape != BoxShape::UNBOUND) { |
| 219 | + double ax[3] = {lvec1.x, lvec2.x, lvec3.x}; |
| 220 | + double bx[3] = {lvec1.y, lvec2.y, lvec3.y}; |
| 221 | + double cx[3] = {lvec1.z, lvec2.z, lvec3.z}; |
| 222 | + |
| 223 | + double xb = std::sqrt(DOT3(ax, ax)); |
| 224 | + double yb = std::sqrt(DOT3(bx, bx)); |
| 225 | + double zb = std::sqrt(DOT3(cx, cx)); |
| 226 | + |
| 227 | + double cos_a = DOT3(bx, cx) / (yb * zb); |
| 228 | + double cos_b = DOT3(cx, ax) / (zb * xb); |
| 229 | + double cos_c = DOT3(ax, bx) / (xb * yb); |
| 230 | + |
| 231 | + double al = 90.0; |
| 232 | + double be = 90.0; |
| 233 | + double ga = 90.0; |
| 234 | + if (cos_a != 0.0) al = (180 / M_PI) * std::acos(cos_a); |
| 235 | + if (cos_b != 0.0) be = (180 / M_PI) * std::acos(cos_b); |
| 236 | + if (cos_c != 0.0) ga = (180 / M_PI) * std::acos(cos_c); |
| 237 | + |
| 238 | + if (bign) |
| 239 | + fprintf(fout, " %14.6lf%14.6lf%14.6lf%14.6lf%14.6lf%14.6lf\n", xb, yb, zb, al, be, ga); |
| 240 | + else |
| 241 | + fprintf(fout, " %12.6lf%12.6lf%12.6lf%12.6lf%12.6lf%12.6lf\n", xb, yb, zb, al, be, ga); |
| 242 | + } |
| 243 | + |
| 244 | + const char* fcord; |
| 245 | + const char* fcoup; |
| 246 | + if (bign) { |
| 247 | + fcord = "%8d %c%c%c%14.6lf%14.6lf%14.6lf%8d"; |
| 248 | + fcoup = "%8d"; |
| 249 | + } else { |
| 250 | + fcord = "%6d %c%c%c%12.6lf%12.6lf%12.6lf%6d"; |
| 251 | + fcoup = "%6d"; |
| 252 | + } |
| 253 | + for (int i = 0; i < n; ++i) { |
| 254 | + const char* nm = atomid::name[i]; |
| 255 | + fprintf(fout, fcord, i + 1, nm[0], nm[1], nm[2], qx[i], qy[i], qz[i], atoms::type[i]); |
| 256 | + for (int k = 0; k < couple::n12[i]; ++k) |
| 257 | + fprintf(fout, fcoup, couple::i12[i][k]); |
| 258 | + fprintf(fout, "%s", "\n"); |
| 259 | + } |
| 260 | + |
| 261 | + fclose(fout); |
| 262 | +} |
| 263 | + |
177 | 264 | void mdsaveSynchronize()
|
178 | 265 | {
|
179 | 266 | if (fut_dup_then_write.valid())
|
|
0 commit comments