Skip to content

Commit 3a7c10d

Browse files
committed
add dcd support
1 parent 79b49d9 commit 3a7c10d

File tree

13 files changed

+638
-297
lines changed

13 files changed

+638
-297
lines changed

include/ff/atom.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ void copyPosToXyz(bool refreshNBList);
2929
/// - Tinker uses centers of mass.
3030
void bounds();
3131

32-
void readFrameOpen(const std::string& filename, std::ifstream& input);
33-
void readFrameCopyinToXyz(std::ifstream& input, bool& done);
34-
void readFrameClose(std::ifstream& input);
35-
3632
//====================================================================//
3733
// //
3834
// Global Variables //

include/ff/rwcrd.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
#include <string>
3+
4+
namespace tinker {
5+
enum class CrdFormat
6+
{
7+
NONE,
8+
TXYZ1,
9+
TXYZ2_PBC,
10+
DCD
11+
};
12+
13+
class CrdR;
14+
class CrdReader
15+
{
16+
protected:
17+
CrdR* m_impl;
18+
19+
public:
20+
~CrdReader();
21+
CrdReader(std::string crdfile, CrdFormat crdformat = CrdFormat::NONE);
22+
int readCurrent();
23+
};
24+
25+
class CrdW;
26+
class CrdWriter
27+
{
28+
protected:
29+
CrdW* m_impl;
30+
const double *qx, *qy, *qz;
31+
32+
public:
33+
~CrdWriter();
34+
CrdWriter(const double* xx, const double* yy, const double* zz, //
35+
std::string crdfile, CrdFormat crdformat = CrdFormat::NONE);
36+
int writeCurrent();
37+
};
38+
}

include/md/misc.h

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

6969
/// \ingroup md
7070
void mdsaveAsync(int istep, time_prec dt);
71-
void mdDebugSaveSync();
7271
/// \ingroup md
7372
void mdsaveSynchronize();
7473
/// \ingroup md

include/tinker9.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// \def TINKER9_VERSION_MINOR
99
/// \def TINKER9_VERSION_PATCH
1010
#define TINKER9_VERSION_MAJOR 1
11-
#define TINKER9_VERSION_MINOR 1
11+
#define TINKER9_VERSION_MINOR 2
1212
#define TINKER9_VERSION_PATCH 0
1313
/// \}
1414

@@ -31,7 +31,7 @@
3131
" ### ### ""\n" \
3232
" ### Tinker9 -- Software Tools for Molecular Design ###""\n" \
3333
" ## ##""\n" \
34-
" ## Version 1.1.0 August 2022 ##""\n" \
34+
" ## Version 1.2.0 september 2022 ##""\n" \
3535
" ## ##""\n" \
3636
" ## Copyright (c) Zhi Wang & the Ponder Lab ##""\n" \
3737
" ### All Rights Reserved ###""\n" \

src/atom.cpp

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -154,167 +154,4 @@ void bounds()
154154
TINKER_FCALL2(acc1, cu1, bounds);
155155
copyPosToXyz();
156156
}
157-
158-
inline namespace v1 {
159-
enum
160-
{
161-
DCD_HEADER = 0,
162-
DCD_TDELTA = 10,
163-
DCD_USEBOX = 11,
164-
DCD_CTRL_LEN = 21,
165-
166-
DCD_TITLE_NCHARS = 80,
167-
168-
DCD_AX = 0,
169-
DCD_COS_G = 1,
170-
DCD_BX = 2,
171-
DCD_COS_B = 3,
172-
DCD_COS_A = 4,
173-
DCD_CX = 5,
174-
DCD_XTAL_LEN = 6,
175-
};
176-
177-
enum class Archive
178-
{
179-
NONE = 0,
180-
XYZ = 1,
181-
DCD = 2,
182-
};
183-
}
184-
185-
static int dcdControl[DCD_CTRL_LEN] = {0};
186-
static std::vector<float> dcdx, dcdy, dcdz;
187-
static Archive archive = Archive::NONE;
188-
189-
static void dcdReadIntoBuffer(void* buffer, int nbyte, std::ifstream& ipt)
190-
{
191-
int size1, size2;
192-
ipt.read((char*)&size1, sizeof(int));
193-
if (nbyte > 0) assert(nbyte == size1);
194-
ipt.read((char*)buffer, size1);
195-
ipt.read((char*)&size2, sizeof(int));
196-
}
197-
198-
void readFrameOpen(const std::string& filename, std::ifstream& ipt)
199-
{
200-
// get file format type by inspection of first character
201-
char a1;
202-
ipt.open(filename);
203-
ipt >> a1;
204-
auto arc = Archive::NONE;
205-
if (a1 == ' ')
206-
arc = Archive::XYZ;
207-
else if ('0' <= a1 and a1 <= '9')
208-
arc = Archive::XYZ;
209-
else
210-
arc = Archive::DCD;
211-
212-
if (arc == Archive::DCD) {
213-
ipt.close();
214-
ipt.open(filename, std::ios::in | std::ios::binary);
215-
216-
// read header info along with title and number of atoms
217-
dcdReadIntoBuffer(dcdControl, sizeof(int) * DCD_CTRL_LEN, ipt);
218-
219-
int dcdTitleRecordLen;
220-
ipt.read((char*)&dcdTitleRecordLen, sizeof(int));
221-
std::vector<char> titlebuf;
222-
titlebuf.resize(dcdTitleRecordLen + sizeof(int));
223-
ipt.read(titlebuf.data(), dcdTitleRecordLen + sizeof(int));
224-
225-
int dcdNAtom;
226-
dcdReadIntoBuffer(&dcdNAtom, sizeof(int), ipt);
227-
assert(n == dcdNAtom);
228-
dcdx.resize(n);
229-
dcdy.resize(n);
230-
dcdz.resize(n);
231-
}
232-
233-
archive = arc;
234-
}
235-
236-
static void readFrameDCD(std::ifstream& ipt)
237-
{
238-
if (dcdControl[DCD_USEBOX]) {
239-
double dcdXtal[DCD_XTAL_LEN];
240-
dcdReadIntoBuffer(dcdXtal, sizeof(double) * DCD_XTAL_LEN, ipt);
241-
double ax = dcdXtal[DCD_AX], bx = dcdXtal[DCD_BX], cx = dcdXtal[DCD_CX];
242-
double al = 90., be = 90., ga = 90.;
243-
if (dcdXtal[DCD_COS_A] != 0.0) al = std::acos(dcdXtal[DCD_COS_A]) * radian;
244-
if (dcdXtal[DCD_COS_B] != 0.0) be = std::acos(dcdXtal[DCD_COS_B]) * radian;
245-
if (dcdXtal[DCD_COS_G] != 0.0) ga = std::acos(dcdXtal[DCD_COS_G]) * radian;
246-
Box p;
247-
boxLattice(p, box_shape, ax, bx, cx, al, be, ga);
248-
boxSetCurrent(p);
249-
}
250-
251-
dcdReadIntoBuffer(dcdx.data(), sizeof(float) * n, ipt);
252-
dcdReadIntoBuffer(dcdy.data(), sizeof(float) * n, ipt);
253-
dcdReadIntoBuffer(dcdz.data(), sizeof(float) * n, ipt);
254-
for (int i = 0; i < n; ++i) {
255-
atoms::x[i] = dcdx[i];
256-
atoms::y[i] = dcdy[i];
257-
atoms::z[i] = dcdz[i];
258-
}
259-
}
260-
261-
static void readFrameXYZ(std::ifstream& ipt)
262-
{
263-
std::string line;
264-
std::getline(ipt, line); // n and title
265-
std::getline(ipt, line); // either box size or first atom
266-
// 18.643000 18.643000 18.643000 90.000000 90.000000 90.000000
267-
// 1 O 8.733783 7.084710 -0.688468 1 2 3
268-
double l1, l2, l3, a1, a2, a3;
269-
int matched = std::sscanf(line.data(), "%lf%lf%lf%lf%lf%lf", &l1, &l2, &l3, &a1, &a2, &a3);
270-
int row = 0;
271-
int index;
272-
char name[32];
273-
double xr, yr, zr;
274-
if (matched == 6) {
275-
Box p;
276-
boxLattice(p, box_shape, l1, l2, l3, a1, a2, a3);
277-
boxSetCurrent(p);
278-
} else {
279-
std::sscanf(line.data(), "%d%s%lf%lf%lf", &index, name, &xr, &yr, &zr);
280-
index -= 1;
281-
atoms::x[index] = xr;
282-
atoms::y[index] = yr;
283-
atoms::z[index] = zr;
284-
row = 1;
285-
}
286-
287-
for (int ir = row; ir < n; ++ir) {
288-
std::getline(ipt, line);
289-
std::sscanf(line.data(), "%d%s%lf%lf%lf", &index, name, &xr, &yr, &zr);
290-
index -= 1;
291-
atoms::x[index] = xr;
292-
atoms::y[index] = yr;
293-
atoms::z[index] = zr;
294-
}
295-
}
296-
297-
void readFrameCopyinToXyz(std::ifstream& ipt, bool& done)
298-
{
299-
if (!ipt) done = true;
300-
if (done) return;
301-
302-
if (archive == Archive::XYZ)
303-
readFrameXYZ(ipt);
304-
else if (archive == Archive::DCD)
305-
readFrameDCD(ipt);
306-
307-
xyzData(RcOp::INIT);
308-
309-
if (!ipt.good() or ipt.peek() == EOF) done = true;
310-
}
311-
312-
void readFrameClose(std::ifstream& ipt)
313-
{
314-
ipt.close();
315-
dcdx.clear();
316-
dcdy.clear();
317-
dcdz.clear();
318-
archive = Archive::NONE;
319-
}
320157
}

src/cmakesrc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pme.cpp
7272
potent.cpp
7373
rattle.cpp
7474
rcman.cpp
75+
rwcrd.cpp
7576
spatial.cpp
7677
switch.cpp
7778
tinkersuppl.cpp

src/mdintg.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1+
#include "ff/rwcrd.h"
12
#include "math/pow2.h"
23
#include "md/integrator.h"
34
#include "md/misc.h"
45
#include "md/pq.h"
6+
#include "tool/argkey.h"
7+
#include "tool/darray.h"
58
#include "tool/error.h"
69
#include "tool/externfunc.h"
710
#include "tool/iofortstr.h"
8-
#include <cassert>
11+
#include "tool/tinkersuppl.h"
12+
#include <tinker/detail/files.hh>
913
#include <tinker/detail/inform.hh>
1014
#include <tinker/detail/mdstuf.hh>
1115
#include <tinker/detail/units.hh>
1216

17+
#include <cassert>
18+
1319
namespace tinker {
1420
void mdData(RcOp op)
1521
{
16-
if (not(calc::md & rc_flag))
17-
return;
22+
if (not(calc::md & rc_flag)) return;
1823

1924
RcMan intg42{mdIntegrateData, op};
2025
RcMan save42{mdsaveData, op};
@@ -147,11 +152,31 @@ void mdrestPrintP1(bool prints, double vtot1, double vtot2, double vtot3, double
147152

148153
void mdPropagate(int nsteps, time_prec dt_ps)
149154
{
155+
bool useDebugArcFile = false;
156+
getKV("T9-DBG-ARCHIVE", useDebugArcFile, false);
157+
std::string dbgfile = "";
158+
std::vector<pos_prec> qx, qy, qz;
159+
if (useDebugArcFile) {
160+
dbgfile = FstrView(files::filename)(1, files::leng).trim() + ".dbg";
161+
dbgfile = tinker_f_version(dbgfile, "old");
162+
qx.resize(n);
163+
qy.resize(n);
164+
qz.resize(n);
165+
}
166+
auto iarcdbg = CrdWriter(qx.data(), qy.data(), qz.data(), dbgfile);
167+
150168
for (int istep = 1; istep <= nsteps; ++istep) {
151169
intg->dynamic(istep, dt_ps);
152170

153171
// mdstat
154172
bool save = (istep % inform::iwrite == 0);
173+
if (save and useDebugArcFile) {
174+
darray::copyout(g::q0, n, qx.data(), xpos);
175+
darray::copyout(g::q0, n, qy.data(), ypos);
176+
darray::copyout(g::q0, n, qz.data(), zpos);
177+
waitFor(g::q0);
178+
iarcdbg.writeCurrent();
179+
}
155180
if (save || (istep % BOUNDS_EVERY_X_STEPS) == 0)
156181
bounds();
157182
if (save) {

0 commit comments

Comments
 (0)