40 #define access(PATH,MODE) _access(PATH,00) 43 #if defined(WIN32) && !defined(__CYGWIN__) 44 #define PATHSEPSTR "\\" 45 #define MKDIR(X) mkdir(X) 47 #define PATHSEPSTR "/" 48 #define MKDIR(X) mkdir(X,0777) 51 #define NAMD_open NAMD_open64 52 #define NAMD_write NAMD_write64 53 #define NAMD_close NAMD_close64 56 #define O_LARGEFILE 0x0 58 #define MIN_DEBUG_LEVEL 3 68 while ( (fd = _open(fname, O_WRONLY|O_CREAT|O_EXCL|O_BINARY|
O_LARGEFILE,_S_IREAD|_S_IWRITE)) < 0) {
71 while ( (fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC|
O_LARGEFILE,
73 while ( (fd = open(fname, O_WRONLY|O_CREAT|O_EXCL|
O_LARGEFILE,
75 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
77 if ( errno != EINTR ) {
79 sprintf(errmsg,
"Unable to open binary file %s", fname);
88 void NAMD_write(
int fd,
const char *buf,
size_t count,
const char *errmsg=
"NAMD_write64") {
89 double firsttime = 0.;
91 #if defined(WIN32) && !defined(__CYGWIN__) 92 long retval = _write(fd,buf,count);
94 ssize_t retval = write(fd,buf,count);
96 if ( retval < 0 && errno == EINTR ) retval = 0;
97 if ( retval < 0 && errno == ENOMEM ) {
98 if ( firsttime == 0. ) firsttime = CmiWallTimer();
99 if ( (CmiWallTimer() - firsttime) < 300. ) retval = 0;
102 if ( retval > count )
NAMD_bug(
"extra bytes written in NAMD_write64()");
106 if ( firsttime != 0. ) {
107 iout <<
iWARN << errmsg <<
": NAMD_write64() retried for " << (CmiWallTimer() - firsttime) <<
" seconds.\n" <<
endi;
114 while ( _close(fd) ) {
116 while ( close(fd) ) {
118 if ( errno != EINTR ) {
120 sprintf(errmsg,
"Error on closing file %s", fname);
127 #define seek_dcdfile NAMD_seek 130 #define namdMyNode Node::Object() 131 #define simParams simParameters 136 unitcell[0] = unitcell[2] = unitcell[5] = 0.0;
137 unitcell[1] = unitcell[3] = unitcell[4] = 0.0;
143 unitcell[0] = (lattice->
a_p()) ? a.
length() : 0.0;
144 unitcell[2] = (lattice->
b_p()) ? b.
length() : 0.0;
145 unitcell[5] = (lattice->
c_p()) ? c.
length() : 0.0;
146 double cosAB = (lattice->
a_p() && lattice->
b_p() ) ?
147 (a*b)/(unitcell[0]*unitcell[2]) : 0.0;
148 double cosAC = (lattice->
a_p() && lattice->
c_p() ) ?
149 (a*c)/(unitcell[0]*unitcell[5]) : 0.0;
150 double cosBC = (lattice->
b_p() && lattice->
c_p() ) ?
151 (b*c)/(unitcell[2]*unitcell[5]) : 0.0;
152 if (cosAB > 1.0) cosAB = 1.0;
else if (cosAB < -1.0) cosAB = -1.0;
153 if (cosAC > 1.0) cosAC = 1.0;
else if (cosAC < -1.0) cosAC = -1.0;
154 if (cosBC > 1.0) cosBC = 1.0;
else if (cosBC < -1.0) cosBC = -1.0;
189 if(
simParams->benchTimestep)
return std::make_pair(0,0);
191 int positionsNeeded = 0;
192 uint16 dcdSelectionTag = 0;
193 if ( timestep >= 0 ) {
197 ((timestep %
simParams->dcdFrequency) == 0) )
198 { positionsNeeded |= 1; }
206 for(
int index=0; index<16;++index)
210 if(frequency && (timestep % frequency) == 0)
214 positionsNeeded |= 4; dcdSelectionTag = tag;
220 ((timestep %
simParams->restartFrequency) == 0) )
221 { positionsNeeded |= 2; }
226 (
simParams->IMDsendsettings.time_switch == 0) && (
simParams->IMDsendsettings.energies_switch == 0)) {
228 #ifdef NODEGROUP_FORCE_REGISTER 230 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
231 imd = cpdata.ckLocalBranch()->imd;
240 if ( (((timestep %
simParams->IMDfreq) == 0) ||
241 (timestep ==
simParams->firstTimestep) ) &&
243 && ((
simParams->IMDsendsettings.box_switch == 1) || (
simParams->IMDsendsettings.fcoords_switch == 1)))) )
244 { positionsNeeded |= 1; }
253 positionsNeeded |= 2;
255 return std::make_pair(positionsNeeded,dcdSelectionTag);
258 template <
class xVector,
class xDone>
264 const int wrapNearest =
simParams->wrapNearest;
269 #ifndef MEM_OPT_VERSION 271 for ( i = 0; i < n; ++i ) {
276 for ( i = 0; i < n; ++i ) {
277 if ( ! wrapAll && ! molecule->
is_water(i) )
continue;
281 Vector trans = ( wrapNearest ?
285 coor[i] = coor[i] + con[ci];
292 template <
class xVector,
class xDone>
298 const int wrapNearest =
simParams->wrapNearest;
303 #ifndef MEM_OPT_VERSION 305 for ( i = 0; i < n; ++i ) {
312 con[dcdci] += coor[i];
314 for ( i = 0; i < n; ++i ) {
316 if ( ! wrapAll && ! molecule->
is_water(molIndex) )
continue;
319 if ( ci == molIndex ) {
321 Vector trans = ( wrapNearest ?
326 coor[i] = coor[i] + con[dcdci];
355 double coor_wrapped = 0;
356 float fcoor_wrapped = 0;
358 if ( timestep >= 0 ) {
362 ((timestep %
simParams->dcdFrequency) == 0) )
365 output_dcdfile(timestep, n, fcoor,
366 simParams->dcdUnitCell ? &lattice : NULL, 0);
372 bool needCleanup =
false;
374 for(
int index=0; index<16;++index)
379 if(frequency>0 && (timestep % frequency) == 0)
382 int dcdSelectionNpoints = n;
388 dcdSelectionNpoints = size;
389 dcdSelectionFcoor =
new FloatVector[dcdSelectionNpoints];
391 for(
int i=0; i<n ;i++)
395 dcdSelectionFcoor[offset] = fcoor[i];
400 dcdSelectionFcoor = fcoor;
403 output_dcdfile(timestep, dcdSelectionNpoints, dcdSelectionFcoor,
404 simParams->dcdUnitCell ? &lattice : NULL, tag);
406 delete [] dcdSelectionFcoor;
414 ((timestep %
simParams->restartFrequency) == 0) )
416 iout <<
"WRITING COORDINATES TO RESTART FILE AT STEP " 417 << timestep <<
"\n" <<
endi;
419 output_restart_coordinates(coor, n, timestep);
420 iout <<
"FINISHED WRITING RESTART COORDINATES\n" <<
endi;
426 ( ((timestep %
simParams->IMDfreq) == 0) ||
427 (timestep ==
simParams->firstTimestep) ) )
431 && ((
simParams->IMDsendsettings.box_switch == 1) || (
simParams->IMDsendsettings.fcoords_switch == 1))))
434 #ifdef NODEGROUP_FORCE_REGISTER 436 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
437 imd = cpdata.ckLocalBranch()->imd;
446 && (
simParams->IMDsendsettings.box_switch == 1))) {
447 IMDBox box = {(float)lattice.
a().
x, (float)lattice.
a().
y, (float)lattice.
a().
z,
448 (float)lattice.
b().
x, (float)lattice.
b().
y, (float)lattice.
b().
z,
449 (float)lattice.
c().
x, (float)lattice.
c().
y, (float)lattice.
c().
z};
451 if (imd != NULL) imd->
gather_box(timestep, &box);
456 && (
simParams->IMDsendsettings.fcoords_switch == 1)))) {
458 && (
simParams->IMDsendsettings.wrap_switch == 1)))
481 iout <<
"WRITING COORDINATES TO OUTPUT FILE AT STEP " 482 << realstep <<
"\n" <<
endi;
485 output_final_coordinates(coor, n, realstep);
493 ? &lattice : NULL, 0);
496 for(
int dcdSelectionIndex=0; dcdSelectionIndex<16;++dcdSelectionIndex)
500 if(dcdSelectionFrequency)
503 ? &lattice : NULL, dcdSelectionTag);
516 int velocitiesNeeded = 0;
518 if ( timestep >= 0 ) {
522 ((timestep %
simParams->velDcdFrequency) == 0) )
523 { velocitiesNeeded |= 1; }
527 ((timestep %
simParams->restartFrequency) == 0) )
528 { velocitiesNeeded |= 2; }
532 ( ((timestep %
simParams->IMDfreq) == 0) ||
533 (timestep ==
simParams->firstTimestep) ) &&
535 && (
simParams->IMDsendsettings.velocities_switch == 1)) )
536 { velocitiesNeeded |= 1; }
543 velocitiesNeeded |= 2;
546 return velocitiesNeeded;
553 if ( timestep >= 0 ) {
557 ((timestep %
simParams->velDcdFrequency) == 0) )
559 output_veldcdfile(timestep, n, fvel);
564 ((timestep %
simParams->restartFrequency) == 0) )
566 iout <<
"WRITING VELOCITIES TO RESTART FILE AT STEP " 567 << timestep <<
"\n" <<
endi;
568 output_restart_velocities(timestep, n, vel);
569 iout <<
"FINISHED WRITING RESTART VELOCITIES\n" <<
endi;
575 ( ((timestep %
simParams->IMDfreq) == 0) ||
576 (timestep ==
simParams->firstTimestep) ) &&
577 (
simParams->IMDsendsettings.velocities_switch == 1) )
580 #ifdef NODEGROUP_FORCE_REGISTER 582 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
583 imd = cpdata.ckLocalBranch()->imd;
603 iout <<
"WRITING VELOCITIES TO OUTPUT FILE AT STEP " 604 << realstep <<
"\n" <<
endi;
606 output_final_velocities(realstep, n, vel);
625 int forcesNeeded = 0;
627 if ( timestep >= 0 ) {
631 ((timestep %
simParams->forceDcdFrequency) == 0) )
632 { forcesNeeded |= 1; }
636 ( ((timestep %
simParams->IMDfreq) == 0) ||
637 (timestep ==
simParams->firstTimestep) ) &&
639 && (
simParams->IMDsendsettings.forces_switch == 1))) )
640 { forcesNeeded |= 1; }
657 if ( timestep >= 0 ) {
661 ((timestep %
simParams->forceDcdFrequency) == 0) )
663 output_forcedcdfile(timestep, n, ffrc);
668 ( ((timestep %
simParams->IMDfreq) == 0) ||
669 (timestep ==
simParams->firstTimestep) ) &&
670 ((
simParams->IMDsendsettings.forces_switch == 1)) )
673 #ifdef NODEGROUP_FORCE_REGISTER 675 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
676 imd = cpdata.ckLocalBranch()->imd;
692 iout <<
"WRITING FORCES TO OUTPUT FILE AT STEP " 693 << realstep <<
"\n" <<
endi;
695 output_forces(realstep, n, frc);
717 void Output::output_restart_coordinates(
Vector *coor,
int n,
int timestep)
721 char timestepstr[20];
723 int baselen = strlen(
namdMyNode->simParams->restartFilename);
724 char *restart_name =
new char[baselen+26];
725 const char *bsuffix =
".old";
727 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
729 sprintf(timestepstr,
".%d",timestep);
730 strcat(restart_name, timestepstr);
733 strcat(restart_name,
".coor");
741 sprintf(comment,
"RESTART COORDINATES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
743 #ifdef NODEGROUP_FORCE_REGISTER 745 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
746 PatchData* pData = cpdata.ckLocalBranch();
747 pData->pdbData->set_all_positions(coor);
748 pData->pdbData->write(restart_name, comment);
754 namdMyNode->pdbData->write(restart_name, comment);
760 write_binary_file(restart_name, n, coor);
763 delete [] restart_name;
765 if (
namdMyNode->simParams->restartSaveDcd ) {
766 if ( ! output_dcdfile(
END_OF_RUN, 0, 0, 0, 0) ) {
767 const char *old_name =
namdMyNode->simParams->dcdFilename;
768 int old_len = strlen(old_name);
769 char *new_name =
new char[old_len+26];
770 strcpy(new_name, old_name);
771 if ( old_len >= 4 && ! strcmp(new_name+old_len-4,
".dcd") ) {
773 new_name[old_len] = 0;
775 sprintf(timestepstr,
".%d",timestep);
776 strcat(new_name, timestepstr);
777 strcat(new_name,
".dcd");
778 iout <<
"RENAMING COORDINATE DCD FILE " << old_name <<
" TO " << new_name <<
"\n" <<
endi;
780 while ( rename(old_name, new_name) ) {
781 if ( errno == EINTR || errno == EXDEV )
continue;
783 sprintf(err_msg,
"Unable to rename DCD file %s to %s", old_name, new_name);
807 void Output::output_restart_velocities(
int timestep,
int n,
Vector *vel)
811 char timestepstr[20];
813 int baselen = strlen(
namdMyNode->simParams->restartFilename);
814 char *restart_name =
new char[baselen+26];
815 const char *bsuffix =
".old";
817 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
819 sprintf(timestepstr,
".%d",timestep);
820 strcat(restart_name, timestepstr);
823 strcat(restart_name,
".vel");
832 sprintf(comment,
"RESTART VELOCITIES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
836 #ifdef NODEGROUP_FORCE_REGISTER 838 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
839 PatchData* pData = cpdata.ckLocalBranch();
840 pData->pdbData->set_all_positions(vel);
841 pData->pdbData->write(restart_name, comment);
847 namdMyNode->pdbData->write(restart_name, comment);
854 write_binary_file(restart_name, n, vel);
857 delete [] restart_name;
867 if ( ! output )
return;
869 output->output_dcdfile(
END_OF_RUN, 0, 0, 0, 0);
871 for(
int dcdSelectionIndex=0; dcdSelectionIndex<16;++dcdSelectionIndex)
875 if(dcdSelectionFrequency)
876 output->output_dcdfile(
END_OF_RUN,0,0,0,dcdSelectionTag);
883 if ( ! output )
return;
890 replicaDcdActive = 1;
891 replicaDcdIndex = index;
895 replicaDcdActive = 1;
896 replicaDcdIndex = index;
899 msg->
srcPart = CmiMyPartition();
902 strcpy(msg->
data, filename);
907 replicaDcdActive = 1;
908 replicaDcdIndex = index;
911 msg->
srcPart = CmiMyPartition();
915 strcpy(msg->
data, filename);
923 iout <<
"CLOSING REPLICA DCD FILE " << msg->
dcdIndex <<
" " << f.filename.c_str() <<
"\n" <<
endi;
927 f.filename = (
const char*) msg->
data;
934 ( ! replicaDcdFiles.count(msg->
dcdIndex) )) {
936 sprintf(err_msg,
"Unknown replicaDcdFile identifier %d\n", msg->
dcdIndex);
943 iout <<
"OPENING REPLICA DCD FILE " << msg->
dcdIndex <<
" " << f.filename.c_str() <<
"\n" <<
endi;
949 sprintf(err_msg,
"DCD file %s already exists!!", f.filename.c_str());
951 }
else if (f.fileid < 0) {
954 sprintf(err_msg,
"Couldn't open DCD Index %d Select Index %d file %s", msg->
dcdIndex, msg->
dcdSelectIndex, f.filename.c_str());
956 sprintf(err_msg,
"Couldn't open DCD Index %d file %s", msg->
dcdIndex, f.filename.c_str());
958 }
else if (! f.fileid) {
959 NAMD_bug(
"Output::recvReplicaDcdData open_dcd_write returned fileid of zero");
968 NAMD_err(
"Writing of DCD header failed!!");
973 iout <<
"WRITING TO REPLICA DCD FILE " << msg->
dcdIndex <<
" " << f.filename.c_str() <<
"\n" <<
endi;
974 float *msgx = (
float*) msg->
data;
979 if (ret_code < 0)
NAMD_err(
"Writing of DCD step failed!!");
1000 #define RAD2DEG 180.0/3.14159265359 1002 int Output::output_dcdfile(
int timestep,
int n,
FloatVector *coor,
1003 const Lattice *lattice,
int dcdSelectTag)
1006 static Bool first[
maxDCD]={
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true,
true};
1007 static int fileid[
maxDCD];
1009 static float *x =
nullptr;
1010 static float *y =
nullptr;
1011 static float *z =
nullptr;
1012 static int n_alloc = 0;
1020 char *dcdFilename =
simParams->dcdFilename;
1021 int dcdSelectIndex=dcdSelectTag-1;
1022 if(dcdSelectTag >0 && dcdSelectTag <= 16)
1027 for ( std::map<int,replicaDcdFile>::iterator it = replicaDcdFiles.begin();
1028 it != replicaDcdFiles.end(); ++it ) {
1029 replicaDcdFile &f = it->second;
1031 iout <<
"CLOSING REPLICA DCD FILE " << it->first <<
" " << f.filename.c_str() <<
"\n" <<
endi;
1036 for ( std::map<std::pair<int,uint16_t>,replicaDcdFile>::iterator it = replicaDcdSelectFiles.begin();
1037 it != replicaDcdSelectFiles.end(); ++it ) {
1038 replicaDcdFile &f = it->second;
1040 iout <<
"CLOSING REPLICA DCD SELECT FILE " << it->first.first <<
" " << f.filename.c_str() <<
"\n" <<
endi;
1047 if ( ! first[dcdSelectTag] ) {
1048 iout <<
"CLOSING COORDINATE DCD FILE " << dcdFilename <<
"\n" <<
endi;
1051 iout <<
"COORDINATE DCD FILE " << dcdFilename <<
" WAS NOT CREATED\n" <<
endi;
1054 first[dcdSelectTag] = 1;
1055 fileid[dcdSelectTag] = 0;
1059 if ( replicaDcdActive ) {
1062 float *msgx = (
float*) msg->
data;
1063 float *msgy = msgx + n;
1064 float *msgz = msgy + n;
1065 for (i=0; i<n; i++) { msgx[i] = coor[i].
x; }
1066 for (i=0; i<n; i++) { msgy[i] = coor[i].
y; }
1067 for (i=0; i<n; i++) { msgz[i] = coor[i].
z; }
1075 msg->
NPRIV = timestep;
1079 msg->
srcPart = CmiMyPartition();
1085 if (first[dcdSelectTag])
1090 if ( n > n_alloc ) {
1099 iout <<
"OPENING COORDINATE DCD FILE\n" <<
endi;
1105 sprintf(err_msg,
"DCD file %s already exists!!",
1110 else if (fileid[dcdSelectTag] < 0)
1114 sprintf(err_msg,
"Couldn't open DCD file %s",
1120 int NSAVC, NFILE, NPRIV, NSTEP;
1126 NSTEP = NPRIV - NSAVC;
1132 n, NFILE, NPRIV, NSAVC, NSTEP,
1137 NAMD_err(
"Writing of DCD header failed!!");
1140 first[dcdSelectTag] =
FALSE;
1153 iout <<
"WRITING COORDINATES TO DCD SELECT FILE " << dcdFilename <<
" AT STEP " 1154 << timestep <<
"\n" <<
endi;
1156 iout <<
"WRITING COORDINATES TO DCD FILE " << dcdFilename <<
" AT STEP " 1157 << timestep <<
"\n" <<
endi;
1162 ret_code =
write_dcdstep(fileid[dcdSelectTag], n, x, y, z, unitcell);
1164 ret_code =
write_dcdstep(fileid[dcdSelectTag], n, x, y, z, NULL);
1168 NAMD_err(
"Writing of DCD step failed!!");
1190 void Output::output_final_coordinates(
Vector *coor,
int n,
int timestep)
1193 char output_name[140];
1197 strcpy(output_name,
namdMyNode->simParams->outputFilename);
1198 strcat(output_name,
".coor");
1206 sprintf(comment,
"FINAL COORDINATES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
1208 #ifdef NODEGROUP_FORCE_REGISTER 1210 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
1211 PatchData* pData = cpdata.ckLocalBranch();
1212 pData->pdbData->set_all_positions(coor);
1213 pData->pdbData->write(output_name, comment);
1218 namdMyNode->pdbData->set_all_positions(coor);
1219 namdMyNode->pdbData->write(output_name, comment);
1225 write_binary_file(output_name, n, coor);
1244 void Output::output_final_velocities(
int timestep,
int n,
Vector *vel)
1247 char output_name[140];
1251 strcpy(output_name,
namdMyNode->simParams->outputFilename);
1252 strcat(output_name,
".vel");
1260 sprintf(comment,
"FINAL VELOCITIES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
1263 #ifdef NODEGROUP_FORCE_REGISTER 1265 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
1266 PatchData* pData = cpdata.ckLocalBranch();
1267 pData->pdbData->set_all_positions(vel);
1268 pData->pdbData->write(output_name, comment);
1274 namdMyNode->pdbData->write(output_name, comment);
1281 write_binary_file(output_name, n, vel);
1302 void Output::output_veldcdfile(
int timestep,
int n,
FloatVector *vel)
1307 static float *x =
nullptr;
1308 static float *y =
nullptr;
1309 static float *z =
nullptr;
1310 static int n_alloc = 0;
1319 iout <<
"CLOSING VELOCITY DCD FILE\n" <<
endi;
1322 iout <<
"VELOCITY DCD FILE WAS NOT CREATED\n" <<
endi;
1334 if ( n > n_alloc ) {
1343 iout <<
"OPENING VELOCITY DCD FILE\n" <<
endi;
1351 sprintf(err_msg,
"Velocity DCD file %s already exists!!",
1356 else if (fileid < 0)
1360 sprintf(err_msg,
"Couldn't open velocity DCD file %s",
1366 int NSAVC, NFILE, NPRIV, NSTEP;
1369 NSTEP = NPRIV - NSAVC;
1373 const int with_unitcell = 0;
1376 n, NFILE, NPRIV, NSAVC, NSTEP,
1382 NAMD_err(
"Writing of velocity DCD header failed!!");
1397 iout <<
"WRITING VELOCITIES TO DCD FILE AT STEP " 1398 << timestep <<
"\n" <<
endi;
1404 NAMD_err(
"Writing of velocity DCD step failed!!");
1424 void Output::output_forces(
int timestep,
int n,
Vector *frc)
1427 char output_name[140];
1431 strcpy(output_name,
namdMyNode->simParams->outputFilename);
1432 strcat(output_name,
".force");
1440 sprintf(comment,
"FORCES WRITTEN BY NAMD AT TIMESTEP %d", timestep);
1441 #ifdef NODEGROUP_FORCE_REGISTER 1443 CProxy_PatchData cpdata(CkpvAccess(BOCclass_group).patchData);
1444 PatchData* pData = cpdata.ckLocalBranch();
1445 pData->pdbData->set_all_positions(frc);
1446 pData->pdbData->write(output_name, comment);
1452 namdMyNode->pdbData->write(output_name, comment);
1458 write_binary_file(output_name, n, frc);
1479 void Output::output_forcedcdfile(
int timestep,
int n,
FloatVector *frc)
1484 static float *x =
nullptr;
1485 static float *y =
nullptr;
1486 static float *z =
nullptr;
1487 static int n_alloc = 0;
1496 iout <<
"CLOSING FORCE DCD FILE\n" <<
endi;
1499 iout <<
"FORCE DCD FILE WAS NOT CREATED\n" <<
endi;
1509 if ( n > n_alloc ) {
1518 iout <<
"OPENING FORCE DCD FILE\n" <<
endi;
1526 sprintf(err_msg,
"Force DCD file %s already exists!!",
1531 else if (fileid < 0)
1535 sprintf(err_msg,
"Couldn't open force DCD file %s",
1541 int NSAVC, NFILE, NPRIV, NSTEP;
1544 NSTEP = NPRIV - NSAVC;
1548 const int with_unitcell = 0;
1551 n, NFILE, NPRIV, NSAVC, NSTEP,
1557 NAMD_err(
"Writing of force DCD header failed!!");
1572 iout <<
"WRITING FORCES TO DCD FILE AT STEP " 1573 << timestep <<
"\n" <<
endi;
1579 NAMD_err(
"Writing of force DCD step failed!!");
1599 void Output::write_binary_file(
char *fname,
int n,
Vector *vecs)
1608 sprintf(errmsg,
"Error on write to binary file %s", fname);
1633 void Output::scale_vels(
Vector *v,
int n,
Real fact)
1677 #ifdef MEM_OPT_VERSION 1678 void ParOutput::velocityMaster(
int timestep,
int n){
1682 if ( timestep >= 0 ) {
1686 ((timestep %
simParams->velDcdFrequency) == 0) )
1688 output_veldcdfile_master(timestep, n);
1693 ((timestep %
simParams->restartFrequency) == 0) )
1695 iout <<
"WRITING VELOCITIES TO RESTART FILE AT STEP " 1696 << timestep <<
"\n" <<
endi;
1697 output_restart_velocities_master(timestep, n);
1698 iout <<
"FINISHED WRITING RESTART VELOCITIES\n" <<
endi;
1709 iout <<
"WRITING VELOCITIES TO OUTPUT FILE AT STEP " 1710 << realstep <<
"\n" <<
endi;
1712 output_final_velocities_master(n);
1725 void ParOutput::velocitySlave(
int timestep,
int fID,
int tID,
Vector *vecs){
1728 if ( timestep >= 0 ) {
1732 ((timestep %
simParams->velDcdFrequency) == 0) )
1734 output_veldcdfile_slave(timestep, fID, tID, vecs);
1739 ((timestep %
simParams->restartFrequency) == 0) )
1742 output_restart_velocities_slave(timestep, fID, tID, vecs, offset);
1751 output_final_velocities_slave(fID, tID, vecs, offset);
1762 void ParOutput::output_veldcdfile_master(
int timestep,
int n){
1769 if ( ! veldcdFirst ) {
1770 iout <<
"CLOSING VELOCITY DCD FILE\n" <<
endi;
1773 iout <<
"VELOCITY DCD FILE WAS NOT CREATED\n" <<
endi;
1781 iout <<
"OPENING VELOCITY DCD FILE\n" <<
endi;
1783 #ifndef OUTPUT_SINGLE_FILE 1784 #error OUTPUT_SINGLE_FILE not defined! 1787 #if OUTPUT_SINGLE_FILE 1788 char *veldcdFilename =
simParams->velDcdFilename;
1790 char *veldcdFilename = buildFileName(
veldcdType);
1798 sprintf(err_msg,
"Velocity DCD file %s already exists!",veldcdFilename);
1801 else if (veldcdFileID < 0)
1804 sprintf(err_msg,
"Couldn't open velocity DCD file %s",veldcdFilename);
1808 #if !OUTPUT_SINGLE_FILE 1813 NAMD_write(veldcdFileID, (
char *) &tmpFlt,
sizeof(
float));
1818 int NSAVC, NFILE, NPRIV, NSTEP;
1821 NSTEP = NPRIV - NSAVC;
1825 const int with_unitcell = 0;
1828 n, NFILE, NPRIV, NSAVC, NSTEP,
1834 NAMD_err(
"Writing of velocity DCD header failed!!");
1837 #if !OUTPUT_SINGLE_FILE 1839 delete [] veldcdFilename;
1842 veldcdFirst =
FALSE;
1846 iout <<
"WRITING VELOCITIES TO DCD FILE AT STEP " 1847 << timestep <<
"\n" <<
endi;
1854 #if OUTPUT_SINGLE_FILE 1856 int totalAtoms =
namdMyNode->molecule->numAtoms;
1865 void ParOutput::output_veldcdfile_slave(
int timestep,
int fID,
int tID,
Vector *vecs){
1872 if ( ! veldcdFirst ) {
1875 #if OUTPUT_SINGLE_FILE 1883 int parN = tID-fID+1;
1888 #if OUTPUT_SINGLE_FILE 1889 char *veldcdFilename =
namdMyNode->simParams->velDcdFilename;
1891 char *veldcdFilename = buildFileName(
veldcdType);
1894 if(veldcdFileID < 0)
1897 sprintf(err_msg,
"Couldn't open velocity DCD file %s",veldcdFilename);
1900 #if OUTPUT_SINGLE_FILE 1905 veldcdX =
new float[parN];
1906 veldcdY =
new float[parN];
1907 veldcdZ =
new float[parN];
1914 #if !OUTPUT_SINGLE_FILE 1915 delete [] veldcdFilename;
1920 NAMD_write(veldcdFileID, (
char *) &tmpFlt,
sizeof(
float));
1921 NAMD_write(veldcdFileID, (
char *) &outputID,
sizeof(
int));
1922 NAMD_write(veldcdFileID, (
char *) &fID,
sizeof(
int));
1923 NAMD_write(veldcdFileID, (
char *) &tID,
sizeof(
int));
1926 veldcdFirst =
FALSE;
1929 #if OUTPUT_SINGLE_FILE 1933 CmiAssert(
sizeof(off_t)==8);
1934 int totalAtoms =
namdMyNode->molecule->numAtoms;
1936 for(
int i=0; i<parN; i++){
1937 veldcdX[i] = vecs[i].
x;
1938 veldcdY[i] = vecs[i].
y;
1939 veldcdZ[i] = vecs[i].
z;
1946 int atomsRemains = (totalAtoms-1)-(tID+1)+1;
1947 off_t offset = ((off_t)atomsRemains)*
sizeof(float)+1*
sizeof(
int);
1952 NAMD_write(veldcdFileID, (
char *)×tep,
sizeof(
int));
1958 void ParOutput::output_restart_velocities_master(
int timestep,
int n){
1959 #if OUTPUT_SINGLE_FILE 1960 char timestepstr[20];
1962 int baselen = strlen(
namdMyNode->simParams->restartFilename);
1963 char *restart_name =
new char[baselen+26];
1965 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
1967 sprintf(timestepstr,
".%d",timestep);
1968 strcat(restart_name, timestepstr);
1970 strcat(restart_name,
".vel");
1972 char *restart_name = NULL;
1974 restart_name = buildFileName(
velType);
1976 restart_name = buildFileName(
velType,timestep);
1982 write_binary_file_master(restart_name, n);
1984 delete [] restart_name;
1987 void ParOutput::output_restart_velocities_slave(
int timestep,
int fID,
int tID,
Vector *vecs,
int64 offset){
1988 #if OUTPUT_SINGLE_FILE 1989 char timestepstr[20];
1991 int baselen = strlen(
namdMyNode->simParams->restartFilename);
1992 char *restart_name =
new char[baselen+26];
1994 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
1996 sprintf(timestepstr,
".%d",timestep);
1997 strcat(restart_name, timestepstr);
1999 strcat(restart_name,
".vel");
2001 char *restart_name = NULL;
2003 restart_name = buildFileName(
velType);
2005 restart_name = buildFileName(
velType,timestep);
2011 write_binary_file_slave(restart_name, fID, tID, vecs, offset);
2013 delete [] restart_name;
2016 void ParOutput::output_final_velocities_master(
int n){
2017 #if OUTPUT_SINGLE_FILE 2018 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2020 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2021 strcat(output_name,
".vel");
2023 char *output_name = buildFileName(
velType);
2029 write_binary_file_master(output_name, n);
2032 void ParOutput::output_final_velocities_slave(
int fID,
int tID,
Vector *vecs,
int64 offset){
2033 #if OUTPUT_SINGLE_FILE 2034 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2036 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2037 strcat(output_name,
".vel");
2039 char *output_name = buildFileName(
velType);
2044 write_binary_file_slave(output_name, fID, tID, vecs, offset);
2046 delete [] output_name;
2049 void ParOutput::write_binary_file_master(
char *fname,
int n){
2053 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::write_binary_file_master\n");
2056 sprintf(errmsg,
"Error on write to binary file %s", fname);
2058 #if !OUTPUT_SINGLE_FILE 2063 NAMD_write(fd, (
char *) &tmpFlt,
sizeof(
float), errmsg);
2064 tmpInt =
namdMyNode->simParams->numoutputprocs;
2074 void ParOutput::write_binary_file_slave(
char *fname,
int fID,
int tID,
Vector *vecs,
int64 offset){
2076 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::write_binary_file_slave\n");
2077 #if OUTPUT_SINGLE_FILE 2079 FILE *ofp = fopen(fname,
"rb+");
2081 sprintf(errmsg,
"Error on opening binary file %s", fname);
2087 if ( _fseeki64(ofp, offset, SEEK_SET) )
2089 if ( fseeko(ofp, offset, SEEK_SET) )
2092 sprintf(errmsg,
"Error on seeking binary file %s", fname);
2097 FILE *ofp = fopen(fname,
"wb+");
2099 sprintf(errmsg,
"Error on opening binary file %s", fname);
2106 fwrite(&tmpInt,
sizeof(
int32), 1, ofp);
2107 fwrite(&tmpFlt,
sizeof(
float), 1, ofp);
2108 fwrite(&outputID,
sizeof(
int), 1, ofp);
2109 fwrite(&fID,
sizeof(
int), 1, ofp);
2110 fwrite(&tID,
sizeof(
int), 1, ofp);
2113 int parN = tID-fID+1;
2114 if ( fwrite(vecs,
sizeof(
Vector), parN, ofp) != parN ) {
2115 sprintf(errmsg,
"Error on writing to binary file %s", fname);
2119 if ( fclose(ofp) ) {
2120 sprintf(errmsg,
"Error on closing binary file %s", fname);
2128 void ParOutput::forceMaster(
int timestep,
int n){
2131 if ( timestep >= 0 ) {
2135 ((timestep %
simParams->forceDcdFrequency) == 0) )
2137 output_forcedcdfile_master(timestep, n);
2145 int realstep =
simParams->firstTimestep;
2146 iout <<
"WRITING FORCES TO OUTPUT FILE AT STEP " 2147 << realstep <<
"\n" <<
endi;
2149 output_forces_master(n);
2156 void ParOutput::forceSlave(
int timestep,
int fID,
int tID,
Vector *vecs){
2159 if ( timestep >= 0 ) {
2163 ((timestep %
simParams->forceDcdFrequency) == 0) )
2165 output_forcedcdfile_slave(timestep, fID, tID, vecs);
2174 output_forces_slave(fID, tID, vecs, offset);
2180 void ParOutput::output_forcedcdfile_master(
int timestep,
int n){
2187 if ( ! forcedcdFirst ) {
2188 iout <<
"CLOSING FORCE DCD FILE\n" <<
endi;
2191 iout <<
"FORCE DCD FILE WAS NOT CREATED\n" <<
endi;
2199 iout <<
"OPENING FORCE DCD FILE\n" <<
endi;
2201 #if OUTPUT_SINGLE_FILE 2202 char *forcedcdFilename =
simParams->forceDcdFilename;
2212 sprintf(err_msg,
"Force DCD file %s already exists!",forcedcdFilename);
2215 else if (forcedcdFileID < 0)
2218 sprintf(err_msg,
"Couldn't open force DCD file %s",forcedcdFilename);
2222 #if !OUTPUT_SINGLE_FILE 2227 NAMD_write(forcedcdFileID, (
char *) &tmpFlt,
sizeof(
float));
2232 int NSAVC, NFILE, NPRIV, NSTEP;
2235 NSTEP = NPRIV - NSAVC;
2239 const int with_unitcell = 0;
2242 n, NFILE, NPRIV, NSAVC, NSTEP,
2248 NAMD_err(
"Writing of force DCD header failed!!");
2251 #if !OUTPUT_SINGLE_FILE 2253 delete [] forcedcdFilename;
2256 forcedcdFirst =
FALSE;
2260 iout <<
"WRITING FORCES TO DCD FILE AT STEP " 2261 << timestep <<
"\n" <<
endi;
2268 #if OUTPUT_SINGLE_FILE 2270 int totalAtoms =
namdMyNode->molecule->numAtoms;
2279 void ParOutput::output_forcedcdfile_slave(
int timestep,
int fID,
int tID,
Vector *vecs){
2286 if ( ! forcedcdFirst ) {
2289 #if OUTPUT_SINGLE_FILE 2290 delete [] forcedcdX;
2291 delete [] forcedcdY;
2292 delete [] forcedcdZ;
2297 int parN = tID-fID+1;
2302 #if OUTPUT_SINGLE_FILE 2303 char *forcedcdFilename =
namdMyNode->simParams->forceDcdFilename;
2308 if(forcedcdFileID < 0)
2311 sprintf(err_msg,
"Couldn't open force DCD file %s",forcedcdFilename);
2314 #if OUTPUT_SINGLE_FILE 2319 forcedcdX =
new float[parN];
2320 forcedcdY =
new float[parN];
2321 forcedcdZ =
new float[parN];
2328 #if !OUTPUT_SINGLE_FILE 2329 delete [] forcedcdFilename;
2334 NAMD_write(forcedcdFileID, (
char *) &tmpFlt,
sizeof(
float));
2335 NAMD_write(forcedcdFileID, (
char *) &outputID,
sizeof(
int));
2336 NAMD_write(forcedcdFileID, (
char *) &fID,
sizeof(
int));
2337 NAMD_write(forcedcdFileID, (
char *) &tID,
sizeof(
int));
2340 forcedcdFirst =
FALSE;
2343 #if OUTPUT_SINGLE_FILE 2347 CmiAssert(
sizeof(off_t)==8);
2348 int totalAtoms =
namdMyNode->molecule->numAtoms;
2350 for(
int i=0; i<parN; i++){
2351 forcedcdX[i] = vecs[i].
x;
2352 forcedcdY[i] = vecs[i].
y;
2353 forcedcdZ[i] = vecs[i].
z;
2359 int atomsRemains = (totalAtoms-1)-(tID+1)+1;
2360 off_t offset = ((off_t)atomsRemains)*
sizeof(float)+1*
sizeof(
int);
2364 NAMD_write(forcedcdFileID, (
char *)×tep,
sizeof(
int));
2370 void ParOutput::output_forces_master(
int n){
2371 #if OUTPUT_SINGLE_FILE 2372 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2374 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2375 strcat(output_name,
".force");
2377 char *output_name = buildFileName(
forceType);
2383 write_binary_file_master(output_name, n);
2386 void ParOutput::output_forces_slave(
int fID,
int tID,
Vector *vecs,
int64 offset){
2387 #if OUTPUT_SINGLE_FILE 2388 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2390 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2391 strcat(output_name,
".force");
2393 char *output_name = buildFileName(
forceType);
2398 write_binary_file_slave(output_name, fID, tID, vecs, offset);
2400 delete [] output_name;
2406 void ParOutput::coordinateMaster(
int timestep,
int n,
Lattice &lat){
2409 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::coordinateMaster n "<< n <<
"\n");
2410 if ( timestep >= 0 ) {
2413 ((timestep %
simParams->dcdFrequency) == 0) )
2415 output_dcdfile_master(timestep, n,
2416 simParams->dcdUnitCell ? &lat : NULL, 0);
2421 for(
int index=0; index<16;++index)
2426 if(frequency>0 && (timestep % frequency) == 0)
2430 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::coordinateMaster index "<< index<<
" numpoints "<<dcdSelectionNpoints <<
"\n");
2431 output_dcdfile_master(timestep, dcdSelectionNpoints,
2432 simParams->dcdUnitCell ? &lat : NULL, tag);
2439 ((timestep %
simParams->restartFrequency) == 0) )
2441 iout <<
"WRITING COORDINATES TO RESTART FILE AT STEP " 2442 << timestep <<
"\n" <<
endi;
2443 output_restart_coordinates_master(timestep, n);
2444 iout <<
"FINISHED WRITING RESTART COORDINATES\n" <<
endi;
2475 iout <<
"WRITING COORDINATES TO OUTPUT FILE AT STEP " 2476 << realstep <<
"\n" <<
endi;
2478 output_final_coordinates_master(n);
2487 for(
int dcdSelectionIndex=0; dcdSelectionIndex<16;++dcdSelectionIndex)
2491 if(dcdSelectionFrequency)
2492 output_dcdfile_master(
END_OF_RUN,0,NULL, dcdSelectionTag);
2498 void ParOutput::coordinateSlave(
int timestep,
int fID,
int tID,
Vector *vecs,
FloatVector *fvecs){
2501 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::coordinateSlave fID "<<fID<<
" tID "<<tID<<
"\n");
2502 if ( timestep >= 0 ) {
2505 ((timestep %
simParams->dcdFrequency) == 0) )
2507 output_dcdfile_slave(timestep, fID, tID, fvecs, 0);
2511 bool needCleanup =
false;
2513 for(
int index=0; index<16;++index)
2517 if(frequency>0 && (timestep % frequency) == 0)
2519 int dcdSelectionNpoints = dcdSelectionLocalSize[index];
2521 if(dcdSelectionNpoints>0)
2525 off_t thisTID = dcdSelectionOffsets[index];
2526 DebugM(3,
"["<<CkMyPe()<<
"]"<<
"ParOutput::coordinateSlave index "<<index <<
" localSize "<<dcdSelectionNpoints<<
" offset "<< thisTID <<
"\n");
2527 for(
int i=0; i< dcdSelectionNpoints; ++i){
2529 dcdSelectionFcoor[i] = fvecs[dcdSelectionMap[index][i]-fID];
2530 DebugM(1,
"["<<CkMyPe()<<
"]"<<
"ParOutput::coordinateSlave index "<<index <<
" atom "<<i<<
" mapto "<< dcdSelectionMap[index][i]<<
" - fID "<< fID<<
" -> "<< dcdSelectionMap[index][i]-fID <<
" coords " << dcdSelectionFcoor[i] <<
"\n");
2532 output_dcdfile_slave(timestep, fID, thisTID+dcdSelectionNpoints-1, dcdSelectionFcoor, tag);
2533 delete [] dcdSelectionFcoor;
2541 ((timestep %
simParams->restartFrequency) == 0) )
2544 output_restart_coordinates_slave(timestep, fID, tID, vecs, offset);
2573 output_final_coordinates_slave(fID, tID, vecs, offset);
2582 for(
int index=0; index<16;++index)
2588 output_dcdfile_slave(
END_OF_RUN,0,0,NULL, tag);
2595 void ParOutput::output_dcdfile_master(
int timestep,
int n,
const Lattice *lattice,
int dcdSelectTag){
2599 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_dcdfile_master n "<< n <<
" tag "<< dcdSelectTag<<
"\n");
2603 if ( ! parFirst[dcdSelectTag] ) {
2604 iout <<
"CLOSING COORDINATE DCD FILE\n" <<
endi;
2607 iout <<
"COORDINATE DCD FILE WAS NOT CREATED\n" <<
endi;
2611 int dcdSelectIndex=dcdSelectTag-1;
2612 if (parFirst[dcdSelectTag])
2615 iout <<
"OPENING COORDINATE DCD FILE\n" <<
endi;
2617 #if OUTPUT_SINGLE_FILE 2618 char *dcdFilename =
simParams->dcdFilename;
2620 char *dcdFilename = buildFileName(
dcdType);
2622 if(dcdSelectTag >0 && dcdSelectTag <= 16)
2624 #ifndef OUTPUT_SINGLE_FILE 2626 NAMD_err(
"DCD selection not supported without OUTPUT_SINGLE_FILE!!");
2630 DebugM(3,
"DCD Selection File " << dcdFilename <<
" tag " << dcdSelectTag<<
"\n");
2637 sprintf(err_msg,
"DCD file %s already exists!!",dcdFilename);
2640 else if (parFileid[dcdSelectTag] < 0)
2643 sprintf(err_msg,
"Couldn't open DCD file %s",dcdFilename);
2647 #if !OUTPUT_SINGLE_FILE 2652 NAMD_write(parFileid[dcdSelectTag], (
char *) &tmpFlt,
sizeof(
float));
2657 int NSAVC, NFILE, NPRIV, NSTEP;
2658 NSAVC = (dcdSelectTag==0) ?
simParams->dcdFrequency :
2661 NSTEP = NPRIV - NSAVC;
2667 n, NFILE, NPRIV, NSAVC, NSTEP,
2673 NAMD_err(
"Writing of DCD header failed!!");
2676 #if !OUTPUT_SINGLE_FILE 2678 delete [] dcdFilename;
2681 parFirst[dcdSelectTag] =
FALSE;
2685 iout <<
"WRITING COORDINATES TO DCD FILE AT STEP " 2686 << timestep <<
"\n" <<
endi;
2701 #if OUTPUT_SINGLE_FILE 2703 int totalAtoms =
namdMyNode->molecule->numAtoms;
2704 if(dcdSelectTag >0 && dcdSelectTag <= 16)
2715 void ParOutput::output_dcdfile_slave(
int timestep,
int fID,
int tID,
FloatVector *fvecs,
int dcdSelectTag){
2718 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_dcdfile_slave fID "<<fID <<
" tID "<<tID <<
" tag "<< dcdSelectTag <<
"\n");
2722 if ( ! parFirst[dcdSelectTag] ) {
2725 #if OUTPUT_SINGLE_FILE 2737 int parN = tID-fID+1;
2738 int dcdSelectIndex=dcdSelectTag-1;
2739 if (parFirst[dcdSelectTag])
2741 #if OUTPUT_SINGLE_FILE 2742 char *dcdFilename =
simParams->dcdFilename;
2744 char *dcdFilename = buildFileName(
dcdType);
2746 if(dcdSelectTag >0 && dcdSelectTag <= 16)
2748 #ifndef OUTPUT_SINGLE_FILE 2750 NAMD_err(
"DCD selection not supported without OUTPUT_SINGLE_FILE!!");
2754 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" DCD Selection File " << dcdFilename <<
" tag " << dcdSelectTag<<
"\n");
2758 if(parFileid[dcdSelectTag] < 0)
2761 sprintf(err_msg,
"Couldn't open DCD file %s", dcdFilename);
2765 #if OUTPUT_SINGLE_FILE 2770 skipbytes +=
sizeof(int)*2 + 6*
sizeof(
double);
2772 seek_dcdfile(parFileid[dcdSelectTag], skipbytes, SEEK_SET);
2775 #if !OUTPUT_SINGLE_FILE 2776 delete [] dcdFilename;
2781 NAMD_write(parFileid[dcdSelectTag], (
char *) &tmpFlt,
sizeof(
float));
2782 NAMD_write(parFileid[dcdSelectTag], (
char *) &outputID,
sizeof(
int));
2783 NAMD_write(parFileid[dcdSelectTag], (
char *) &fID,
sizeof(
int));
2784 NAMD_write(parFileid[dcdSelectTag], (
char *) &tID,
sizeof(
int));
2786 parFirst[dcdSelectTag] =
FALSE;
2789 #if OUTPUT_SINGLE_FILE 2793 CmiAssert(
sizeof(off_t)==8);
2795 int totalAtoms =
namdMyNode->molecule->numAtoms;
2796 if(dcdSelectTag >0 && dcdSelectTag <= 16)
2802 if(parN > dcdAllocSize)
2810 dcdX =
new float[parN];
2811 dcdY =
new float[parN];
2812 dcdZ =
new float[parN];
2813 dcdAllocSize = parN;
2815 for(
int i=0; i<parN; i++){
2816 dcdX[i] = fvecs[i].
x;
2817 dcdY[i] = fvecs[i].
y;
2818 dcdZ[i] = fvecs[i].
z;
2833 int atomsRemains = (totalAtoms-1)-(tID+1)+1;
2834 off_t offset = ((off_t)atomsRemains)*
sizeof(float)+1*
sizeof(
int);
2837 offset +=
sizeof(int)*2 + 6*
sizeof(
double);
2839 seek_dcdfile(parFileid[dcdSelectTag], offset, SEEK_CUR);
2842 NAMD_write(parFileid[dcdSelectTag], (
char *)×tep,
sizeof(
int));
2848 void ParOutput::output_restart_coordinates_master(
int timestep,
int n){
2849 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_restart_coordinates_master\n");
2850 #if OUTPUT_SINGLE_FILE 2851 char timestepstr[20];
2853 int baselen = strlen(
namdMyNode->simParams->restartFilename);
2854 char *restart_name =
new char[baselen+26];
2856 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
2858 sprintf(timestepstr,
".%d",timestep);
2859 strcat(restart_name, timestepstr);
2861 strcat(restart_name,
".coor");
2863 char *restart_name = NULL;
2865 restart_name = buildFileName(
coorType);
2867 restart_name = buildFileName(
coorType,timestep);
2873 write_binary_file_master(restart_name, n);
2875 delete [] restart_name;
2877 void ParOutput::output_restart_coordinates_slave(
int timestep,
int fID,
int tID,
Vector *vecs,
int64 offset){
2878 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_restart_coordinates_slave\n");
2879 #if OUTPUT_SINGLE_FILE 2880 char timestepstr[20];
2882 int baselen = strlen(
namdMyNode->simParams->restartFilename);
2883 char *restart_name =
new char[baselen+26];
2885 strcpy(restart_name,
namdMyNode->simParams->restartFilename);
2887 sprintf(timestepstr,
".%d",timestep);
2888 strcat(restart_name, timestepstr);
2890 strcat(restart_name,
".coor");
2892 char *restart_name = NULL;
2894 restart_name = buildFileName(
coorType);
2896 restart_name = buildFileName(
coorType,timestep);
2902 write_binary_file_slave(restart_name, fID, tID, vecs, offset);
2904 delete [] restart_name;
2907 void ParOutput::output_final_coordinates_master(
int n){
2908 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_final_coordinates_master\n");
2909 #if OUTPUT_SINGLE_FILE 2910 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2913 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2914 strcat(output_name,
".coor");
2916 char *output_name = buildFileName(
coorType);
2922 write_binary_file_master(output_name, n);
2924 delete [] output_name;
2926 void ParOutput::output_final_coordinates_slave(
int fID,
int tID,
Vector *vecs,
int64 offset){
2927 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::output_final_coordinates_slave\n");
2928 #if OUTPUT_SINGLE_FILE 2929 char *output_name =
new char[strlen(
namdMyNode->simParams->outputFilename)+8];
2932 strcpy(output_name,
namdMyNode->simParams->outputFilename);
2933 strcat(output_name,
".coor");
2935 char *output_name = buildFileName(
coorType);
2940 write_binary_file_slave(output_name, fID, tID, vecs, offset);
2942 delete [] output_name;
2947 #if !OUTPUT_SINGLE_FILE 2948 char *ParOutput::buildFileName(
OUTPUTFILETYPE type,
int timestep){
2949 char *filename = NULL;
2950 const char *typeName = NULL;
2956 typeName =
"forcedcd";
2959 typeName =
"veldcd";
2971 typeName =
"invalid";
2974 int baselen = strlen(
namdMyNode->simParams->outputFilename);
2975 filename =
new char[baselen+32];
2976 memset(filename, 0, baselen+32);
2979 strcpy(filename,
namdMyNode->simParams->outputFilename);
2982 if(access(filename, F_OK)!=0) {
2983 int ret =
MKDIR(filename);
2986 sprintf(errmsg,
"Error in creating top-level directory %s!", filename);
2992 strcat(filename, typeName);
2995 if(access(filename, F_OK)!=0) {
2996 int ret =
MKDIR(filename);
2999 sprintf(errmsg,
"Error in creating middle-level directory %s!", filename);
3008 if(outputID == -1) {
3010 if(timestep!=-9999) {
3012 sprintf(tmpstr,
"%smeta.%d",
PATHSEPSTR, timestep);
3018 sprintf(tmpstr,
"%s%d",
PATHSEPSTR, outputID);
3019 strcat(filename, tmpstr);
3021 if(access(filename, F_OK)!=0) {
3022 int ret =
MKDIR(filename);
3025 sprintf(errmsg,
"Error in creating last-level directory %s!", filename);
3030 if(timestep!=-9999) {
3032 sprintf(tmpstr,
"%s%s_%d.%d",
PATHSEPSTR,typeName,outputID,timestep);
3034 sprintf(tmpstr,
"%s%s_%d",
PATHSEPSTR,typeName,outputID);
3038 strcat(filename, tmpstr);
3043 void ParOutput::setDcdSelectionParams(
int index, off_t offset,
size_t size, std::vector<uint32> map )
3045 DebugM(3,
"["<<CkMyPe()<<
"]"<<
" ParOutput::setDcdSelectionParams index "<< index <<
" offset " <<offset <<
" size " << size<<
"\n");
3046 dcdSelectionOffsets[index] = offset;
3047 dcdSelectionLocalSize[index] = size;
3048 dcdSelectionMap[index] = map;
DCDParams dcdSelectionParams[16]
int open_dcd_write_par_slave(char *dcdname)
void gather_velocities(int timestep, int N, FloatVector *velocities)
NAMD_HOST_DEVICE Vector c() const
void NAMD_err(const char *err_msg)
int get_atom_index_from_dcd_selection(const int index, const int atomIndex)
NAMD_HOST_DEVICE int c_p() const
void sendReplicaDcdInit(int dstPart, ReplicaDcdInitMsg *msg, int msgsize)
void setReplicaDcdIndex(int index)
int update_dcdstep_par_header(int fd)
void force(int timestep, int n, Vector *frc, FloatVector *ffrc)
Produce appropriate force for the current timestep.
SimParameters * simParameters
std::ostream & endi(std::ostream &s)
std::ostream & iWARN(std::ostream &s)
int get_clusterSize(int anum) const
void replicaDcdSelectInit(int index, const char *tag, const char *filename)
void gather_coordinates(int timestep, int N, FloatVector *coords)
#define OUTPUT_FILE_VERSION
Molecule stores the structural information for the system.
NAMD_HOST_DEVICE int b_p() const
int open_dcd_write(const char *dcdname)
void wrap_coor_int_dcd_selection(xVector *coor, Lattice &lattice, xDone *done, int index)
uint16_t find_or_create_dcd_selection_index(const char *keystr)
const int get_dcd_selection_size(const int index)
void wrap_coor(Vector *coor, Lattice &lattice, double *done)
void recvReplicaDcdInit(ReplicaDcdInitMsg *msg)
char outFilename[NAMD_FILENAME_BUFFER_SIZE]
int write_dcdstep_par_XYZUnits(int fd, int N)
static std::pair< int, int > coordinateNeeded(int timestep)
Check if the step requires to output the coordinates.
int write_dcdstep_par_cell(int fd, double *cell)
#define OUTPUT_MAGIC_NUMBER
void sendReplicaDcdData(int dstPart, ReplicaDcdDataMsg *msg, int msgsize)
NAMD_HOST_DEVICE BigReal length(void) const
void replicaDcdInit(int index, const char *filename)
void NAMD_bug(const char *err_msg)
void velocity(int timestep, int n, Vector *vel, FloatVector *fvel)
Produce appropriate velocity for the current timestep.
void coordinate(int timestep, int n, Vector *coor, FloatVector *fcoor, Lattice &lattice)
Produce appropriate coordinate output for the current timestep.
int get_dcd_selection_index_from_atom_id(const int index, const int atomIndex)
void recvReplicaDcdData(ReplicaDcdDataMsg *msg)
int write_dcdstep(int fd, int N, float *X, float *Y, float *Z, double *cell)
void wrap_coor_dcd_selection(Vector *coor, Lattice &lattice, double *done, int index)
NAMD_HOST_DEVICE int a_p() const
void NAMD_die(const char *err_msg)
static int forceNeeded(int timestep)
Check if the step requires to output the forces.
NAMD_HOST_DEVICE Vector b() const
int write_dcdheader(int fd, const char *filename, int N, int NFILE, int NPRIV, int NSAVC, int NSTEP, double DELTA, int with_unitcell)
void NAMD_backup_file(const char *filename, const char *extension)
void gather_box(int timestep, IMDBox *box)
void sendReplicaDcdAck(int dstPart, ReplicaDcdAckMsg *msg)
void gather_forces(int timestep, int N, FloatVector *forces)
static const short maxDCD
NAMD_HOST_DEVICE Vector wrap_nearest_delta(Position pos1) const
int write_dcdstep_par_slave(int fd, int parL, int parU, int N, float *X, float *Y, float *Z)
static int velocityNeeded(int timestep)
Check if the step requires to output the velocities.
int get_cluster(int anum) const
NAMD_HOST_DEVICE Vector a() const
void close_dcd_write(int fd)
NAMD_HOST_DEVICE Vector wrap_delta(const Position &pos1) const
void wrap_coor_int(xVector *coor, Lattice &lattice, xDone *done)
static void lattice_to_unitcell(const Lattice *lattice, double *unitcell)