Skip to content

Commit e8011ef

Browse files
committed
add a debug function for mdsave
1 parent 9b72143 commit e8011ef

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

include/md/misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const TimeScaleConfig& respaTSConfig();
6868

6969
/// \ingroup md
7070
void mdsaveAsync(int istep, time_prec dt);
71+
void mdDebugSaveSync();
7172
/// \ingroup md
7273
void mdsaveSynchronize();
7374
/// \ingroup md

src/box.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,15 @@ static void boxGetAxesAngles(const Box& p, double& a, double& b, double& c, //
7777
double cos_a = DOT3(bx, cx) / (ybox * zbox);
7878
double cos_b = DOT3(cx, ax) / (zbox * xbox);
7979
double cos_c = DOT3(ax, bx) / (xbox * ybox);
80-
double a_deg = (180 / M_PI) * std::acos(cos_a);
81-
double b_deg = (180 / M_PI) * std::acos(cos_b);
82-
double c_deg = (180 / M_PI) * std::acos(cos_c);
80+
double a_deg = 90.0;
81+
double b_deg = 90.0;
82+
double c_deg = 90.0;
83+
if (cos_a != 0.0)
84+
a_deg = (180 / M_PI) * std::acos(cos_a);
85+
if (cos_b != 0.0)
86+
b_deg = (180 / M_PI) * std::acos(cos_b);
87+
if (cos_c != 0.0)
88+
c_deg = (180 / M_PI) * std::acos(cos_c);
8389

8490
a = xbox;
8591
b = ybox;

src/mdsave.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
#include "md/misc.h"
55
#include "md/pq.h"
66
#include "tool/execq.h"
7+
#include "tool/iofortstr.h"
78
#include <condition_variable>
89
#include <future>
910
#include <mutex>
1011
#include <tinker/detail/atomid.hh>
1112
#include <tinker/detail/atoms.hh>
13+
#include <tinker/detail/couple.hh>
1214
#include <tinker/detail/deriv.hh>
15+
#include <tinker/detail/files.hh>
1316
#include <tinker/detail/moldyn.hh>
1417
#include <tinker/detail/output.hh>
1518
#include <tinker/detail/polar.hh>
19+
#include <tinker/detail/titles.hh>
1620
#include <tinker/detail/units.hh>
1721
#include <tinker/routines.h>
1822

@@ -174,6 +178,89 @@ void mdsaveAsync(int istep, time_prec dt)
174178
idle_dup = false;
175179
}
176180

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+
177264
void mdsaveSynchronize()
178265
{
179266
if (fut_dup_then_write.valid())

0 commit comments

Comments
 (0)