NAMD
Macros | Functions | Variables
Output.C File Reference
#include "largefiles.h"
#include <string.h>
#include <stdlib.h>
#include "InfoStream.h"
#include "IMDOutput.h"
#include "Output.h"
#include "dcdlib.h"
#include "strlib.h"
#include "Molecule.h"
#include "Node.h"
#include "Parameters.h"
#include "PDB.h"
#include "SimParameters.h"
#include "Vector.h"
#include "structures.h"
#include "MStream.h"
#include "Communicate.h"
#include "PatchMap.h"
#include "PatchMap.inl"
#include "ScriptTcl.h"
#include "Lattice.h"
#include "DataExchanger.h"
#include <fcntl.h>
#include <sys/stat.h>
#include "PatchData.h"
#include "Debug.h"

Go to the source code of this file.

Macros

#define PATHSEPSTR   "/"
 
#define MKDIR(X)   mkdir(X,0777)
 
#define NAMD_open   NAMD_open64
 
#define NAMD_write   NAMD_write64
 
#define NAMD_close   NAMD_close64
 
#define O_LARGEFILE   0x0
 
#define MIN_DEBUG_LEVEL   3
 
#define seek_dcdfile   NAMD_seek
 
#define namdMyNode   Node::Object()
 
#define simParams   simParameters
 
#define pdbData   pdb
 
#define RAD2DEG   180.0/3.14159265359
 

Functions

int NAMD_open (const char *fname)
 
void NAMD_write (int fd, const char *buf, size_t count, const char *errmsg="NAMD_write64")
 
void NAMD_close (int fd, const char *fname)
 
static void lattice_to_unitcell (const Lattice *lattice, double *unitcell)
 
template<class xVector , class xDone >
void wrap_coor_int (xVector *coor, Lattice &lattice, xDone *done)
 
template<class xVector , class xDone >
void wrap_coor_int_dcd_selection (xVector *coor, Lattice &lattice, xDone *done, int index)
 
void wrap_coor_dcd_selection (Vector *coor, Lattice &lattice, double *done, int index)
 
void wrap_coor_dcd_selection (FloatVector *coor, Lattice &lattice, float *done, int index)
 
void wrap_coor (Vector *coor, Lattice &lattice, double *done)
 
void wrap_coor (FloatVector *coor, Lattice &lattice, float *done)
 

Variables

static const short maxDCD =257
 

Macro Definition Documentation

◆ MIN_DEBUG_LEVEL

#define MIN_DEBUG_LEVEL   3

Definition at line 58 of file Output.C.

◆ MKDIR

#define MKDIR (   X)    mkdir(X,0777)

Definition at line 48 of file Output.C.

◆ NAMD_close

#define NAMD_close   NAMD_close64

Definition at line 53 of file Output.C.

Referenced by ofstream_namd::close().

◆ NAMD_open

#define NAMD_open   NAMD_open64

Definition at line 51 of file Output.C.

◆ NAMD_write

#define NAMD_write   NAMD_write64

Definition at line 52 of file Output.C.

◆ namdMyNode

#define namdMyNode   Node::Object()

Definition at line 130 of file Output.C.

Referenced by Output::recvReplicaDcdData(), and Output::replicaDcdSelectInit().

◆ O_LARGEFILE

#define O_LARGEFILE   0x0

Definition at line 56 of file Output.C.

Referenced by NAMD_open().

◆ PATHSEPSTR

#define PATHSEPSTR   "/"

Definition at line 47 of file Output.C.

◆ pdbData

#define pdbData   pdb

Definition at line 132 of file Output.C.

◆ RAD2DEG

#define RAD2DEG   180.0/3.14159265359

Definition at line 994 of file Output.C.

◆ seek_dcdfile

#define seek_dcdfile   NAMD_seek

Definition at line 127 of file Output.C.

◆ simParams

#define simParams   simParameters

Definition at line 131 of file Output.C.

Referenced by HomePatch::addForceToMomentum(), HomePatch::addForceToMomentum3(), HomePatch::addVelocityToPosition(), LdbCoordinator::barrier(), HomePatch::boxClosed(), Molecule::build_gridforce_params(), HomePatch::buildRattleList(), HomePatch::buildRattleList_SOA(), ComputePmeMgr::chargeGridSubmitted(), CudaPmeOneDevice::checkPatchLevelLatticeCompatibilityAndComputeOffsets(), ComputeCylindricalBC::ComputeCylindricalBC(), OneFourNbTholeElem::computeForce(), AngleElem::computeForce(), CrosstermElem::computeForce(), ImproperElem::computeForce(), DihedralElem::computeForce(), TholeElem::computeForce(), AnisoElem::computeForce(), BondElem::computeForce(), ExclElem::computeForce(), GromacsPairElem::computeForce(), ComputeFullDirect::ComputeFullDirect(), ComputeLCPO::ComputeLCPO(), ComputeMsm::ComputeMsm(), ComputePme::ComputePme(), ComputeRestraints::ComputeRestraints(), ComputeSphericalBC::ComputeSphericalBC(), ComputeStir::ComputeStir(), ComputeTclBC::ComputeTclBC(), Output::coordinate(), Output::coordinateNeeded(), ComputeMgr::createComputes(), ComputeCUDAMgr::createCudaGlobalMaster(), ComputeCUDAMgr::createCudaPmeOneDevice(), LdbCoordinator::createLoadBalancer(), CudaComputeNonbonded::CudaComputeNonbonded(), HomePatch::depositMigration(), CollectionMaster::disposePositions(), ComputeEField::doForce(), ComputeConsTorque::doForce(), ComputeStir::doForce(), ComputeNonbondedPair::doForce(), ComputeNonbondedSelf::doForce(), ComputeGridForce::doForce(), ComputeRestraints::doForce(), HomePatch::doGroupSizeCheck(), HomePatch::doGroupSizeCheck_SOA(), HomePatch::doMarginCheck(), HomePatch::doMarginCheck_SOA(), HomePatch::doPairlistCheck(), ComputeTclBC::doWork(), ComputeGBISser::doWork(), CudaComputeNonbonded::doWork(), dumpbench(), HomePatch::exchangeAtoms(), HomePatch::exchangeCheckpoint(), PmeZPencil::fft_init(), PmeYPencil::fft_init(), PmeXPencil::fft_init(), Output::force(), Output::forceNeeded(), ComputePmeCUDADevice::gatherForce(), HomePatch::gbisComputeAfterP1(), HomePatch::gbisComputeAfterP2(), Molecule::get_fep_bonded_type(), CudaComputeNonbonded::getCurrentReduction(), CudaComputeNonbonded::getDoTable(), ComputeLjPmeSerialMgr::getLJparameters(), CudaComputeNonbonded::getNonbondedCoef(), ComputePmeMgr::gridCalc2(), HomePatch::hardWallDrude(), ComputeCUDAMgr::initialize(), ComputePmeCUDA::initialize(), LjPmeMgr::initialize(), LdbCoordinator::initialize(), GridforceFullMainGrid::initialize(), GridforceFullSubGrid::initialize(), GridforceLiteGrid::initialize(), ComputeMsmMgr::initialize(), ComputePmeMgr::initialize(), ComputePmeCUDADevice::initialize(), ComputePmeMgr::initialize_computes(), ComputePmeMgr::initialize_pencils(), isPmeProcessor(), CudaComputeNonbonded::launchWork(), HomePatch::loweAndersenVelocities(), WorkDistrib::mapComputes(), ComputePmeCUDADevice::mergeForcesOnPatch(), HomePatch::minimize_rattle2(), Molecule::Molecule(), HomePatch::mollyAverage(), HomePatch::mollyMollify(), NamdHybridLB::NamdHybridLB(), GridforceGrid::new_grid(), Molecule::num_deg_freedom(), Molecule::num_fixed_atoms(), Molecule::num_group_deg_freedom(), Parameters::Parameters(), PatchDataSOA_set_buffer(), PatchDataSOA_set_size(), Compute::patchReady(), Patch::positionsReady(), HomePatch::positionsReady(), HomePatch::positionsReady_SOA(), Molecule::print_atoms(), HomePatch::qmSwapAtoms(), HomePatch::rattle1(), HomePatch::rattle1_SOA(), HomePatch::rattle1old(), HomePatch::rattle2(), Parameters::read_ener_table(), Molecule::receive_Molecule(), recursive_bisect_with_curve(), ComputePmeCUDADevice::recvAtoms(), ComputePmeCUDADevice::recvAtomsFromNeighbor(), HomePatch::recvCheckpointLoad(), ComputeExtMgr::recvCoord(), ComputeMsmSerialMgr::recvCoord(), ComputeLjPmeSerialMgr::recvCoord(), ComputeFmmSerialMgr::recvCoord(), ComputeMgr::recvCudaGlobalMasterCreateMsg(), ComputeMgr::recvCudaGlobalMasterRemoveMsg(), ComputeMgr::recvCudaGlobalMasterUpdateMsg(), HomePatch::recvExchangeMsg(), GridforceFullMainGrid::reinitialize(), GridforceLiteGrid::reinitialize(), CudaComputeNonbonded::reSortTileLists(), HomePatch::revert(), ScriptTcl::run(), ComputePmeUtil::select(), ComputeNonbondedUtil::select(), Molecule::send_Molecule(), ComputePmeCUDADevice::sendAtomsToNeighbor(), ComputePmeCUDADevice::sendForcesToNeighbors(), HomePatch::setGBISIntrinsicRadii(), ComputeLjPmeSerialMgr::setLJparameters(), PmeAtomStorage::setupAlch(), ComputePmeCUDAMgr::setupPencils(), NamdHybridLB::splitComputes(), ComputePmeCUDADevice::spreadCharge(), NamdCentLB::Strategy(), CollectionMgr::submitPositions(), PmePencilXYZ::submitReductions(), PmePencilZ::submitReductions(), ComputePmeMgr::submitReductions(), CollectionMgr::submitVelocities(), ComputePme::ungridForces(), ComputeMgr::updateLocalComputes4(), Output::velocity(), Output::velocityNeeded(), ReductionMgr::willRequire(), ReductionMgr::willSubmit(), wrap_coor_int(), wrap_coor_int_dcd_selection(), and Controller::write_accelMDG_rest_file().

Function Documentation

◆ lattice_to_unitcell()

static void lattice_to_unitcell ( const Lattice lattice,
double *  unitcell 
)
static

Definition at line 134 of file Output.C.

References Lattice::a(), Lattice::a_p(), Lattice::b(), Lattice::b_p(), Lattice::c(), Lattice::c_p(), and Vector::length().

134  {
135 
136  unitcell[0] = unitcell[2] = unitcell[5] = 0.0;
137  unitcell[1] = unitcell[3] = unitcell[4] = 0.0;
138 
139  if (lattice) {
140  const Vector &a=lattice->a();
141  const Vector &b=lattice->b();
142  const Vector &c=lattice->c();
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;
155  unitcell[1] = cosAB;
156  unitcell[3] = cosAC;
157  unitcell[4] = cosBC;
158  }
159 }
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
NAMD_HOST_DEVICE int c_p() const
Definition: Lattice.h:291
Definition: Vector.h:72
NAMD_HOST_DEVICE int b_p() const
Definition: Lattice.h:290
NAMD_HOST_DEVICE BigReal length(void) const
Definition: Vector.h:202
NAMD_HOST_DEVICE int a_p() const
Definition: Lattice.h:289
NAMD_HOST_DEVICE Vector b() const
Definition: Lattice.h:269
NAMD_HOST_DEVICE Vector a() const
Definition: Lattice.h:268

◆ NAMD_close()

void NAMD_close ( int  fd,
const char *  fname 
)

Definition at line 112 of file Output.C.

References NAMD_err().

112  {
113 #ifdef WIN32
114  while ( _close(fd) ) {
115 #else
116  while ( close(fd) ) {
117 #endif
118  if ( errno != EINTR ) {
119  char errmsg[1024];
120  sprintf(errmsg, "Error on closing file %s", fname);
121  NAMD_err(errmsg);
122  }
123  }
124 }
void NAMD_err(const char *err_msg)
Definition: common.C:170

◆ NAMD_open()

int NAMD_open ( const char *  fname)

Definition at line 63 of file Output.C.

References NAMD_err(), and O_LARGEFILE.

63  {
64  int fd;
65 
66  // open the file and die if the open fails
67 #ifdef WIN32
68  while ( (fd = _open(fname, O_WRONLY|O_CREAT|O_EXCL|O_BINARY|O_LARGEFILE,_S_IREAD|_S_IWRITE)) < 0) {
69 #else
70 #ifdef NAMD_NO_O_EXCL
71  while ( (fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE,
72 #else
73  while ( (fd = open(fname, O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE,
74 #endif
75  S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) {
76 #endif
77  if ( errno != EINTR ) {
78  char errmsg[1024];
79  sprintf(errmsg, "Unable to open binary file %s", fname);
80  NAMD_err(errmsg);
81  }
82  }
83 
84  return fd;
85 }
void NAMD_err(const char *err_msg)
Definition: common.C:170
#define O_LARGEFILE
Definition: Output.C:56

◆ NAMD_write()

void NAMD_write ( int  fd,
const char *  buf,
size_t  count,
const char *  errmsg = "NAMD_write64" 
)

Definition at line 88 of file Output.C.

References endi(), iout, iWARN(), NAMD_bug(), and NAMD_err().

88  {
89  double firsttime = 0.;
90  while ( count ) {
91 #if defined(WIN32) && !defined(__CYGWIN__)
92  long retval = _write(fd,buf,count);
93 #else
94  ssize_t retval = write(fd,buf,count);
95 #endif
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;
100  }
101  if ( retval < 0 ) NAMD_err(errmsg);
102  if ( retval > count ) NAMD_bug("extra bytes written in NAMD_write64()");
103  buf += retval;
104  count -= retval;
105  }
106  if ( firsttime != 0. ) {
107  iout << iWARN << errmsg << ": NAMD_write64() retried for " << (CmiWallTimer() - firsttime) << " seconds.\n" << endi;
108  }
109 }
void NAMD_err(const char *err_msg)
Definition: common.C:170
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
void NAMD_bug(const char *err_msg)
Definition: common.C:195

◆ wrap_coor() [1/2]

void wrap_coor ( Vector coor,
Lattice lattice,
double *  done 
)

Definition at line 326 of file Output.C.

References wrap_coor_int().

Referenced by Output::coordinate().

326  {
327  wrap_coor_int(coor,lattice,done);
328 };
void wrap_coor_int(xVector *coor, Lattice &lattice, xDone *done)
Definition: Output.C:243

◆ wrap_coor() [2/2]

void wrap_coor ( FloatVector coor,
Lattice lattice,
float *  done 
)

Definition at line 330 of file Output.C.

References wrap_coor_int().

330  {
331  wrap_coor_int(coor,lattice,done);
332 };
void wrap_coor_int(xVector *coor, Lattice &lattice, xDone *done)
Definition: Output.C:243

◆ wrap_coor_dcd_selection() [1/2]

void wrap_coor_dcd_selection ( Vector coor,
Lattice lattice,
double *  done,
int  index 
)

Definition at line 318 of file Output.C.

References wrap_coor_int_dcd_selection().

Referenced by Output::coordinate().

318  {
319  wrap_coor_int_dcd_selection(coor,lattice,done, index);
320 };
void wrap_coor_int_dcd_selection(xVector *coor, Lattice &lattice, xDone *done, int index)
Definition: Output.C:277

◆ wrap_coor_dcd_selection() [2/2]

void wrap_coor_dcd_selection ( FloatVector coor,
Lattice lattice,
float *  done,
int  index 
)

Definition at line 322 of file Output.C.

References wrap_coor_int_dcd_selection().

322  {
323  wrap_coor_int_dcd_selection(coor,lattice,done, index);
324 };
void wrap_coor_int_dcd_selection(xVector *coor, Lattice &lattice, xDone *done, int index)
Definition: Output.C:277

◆ wrap_coor_int()

template<class xVector , class xDone >
void wrap_coor_int ( xVector *  coor,
Lattice lattice,
xDone *  done 
)

Definition at line 243 of file Output.C.

References Molecule::get_cluster(), Molecule::get_clusterSize(), Molecule::is_water(), Node::molecule, Molecule::numAtoms, Node::Object(), Node::simParameters, simParams, Lattice::wrap_delta(), and Lattice::wrap_nearest_delta().

Referenced by wrap_coor().

243  {
245  if ( *done ) return;
246  *done = 1;
247  if ( ! ( simParams->wrapAll || simParams->wrapWater ) ) return;
248  const int wrapNearest = simParams->wrapNearest;
249  const int wrapAll = simParams->wrapAll;
250  Molecule *molecule = Node::Object()->molecule;
251  int n = molecule->numAtoms;
252  int i;
253 #ifndef MEM_OPT_VERSION
254  Position *con = new Position[n];
255  for ( i = 0; i < n; ++i ) {
256  con[i] = 0;
257  int ci = molecule->get_cluster(i);
258  con[ci] += coor[i];
259  }
260  for ( i = 0; i < n; ++i ) {
261  if ( ! wrapAll && ! molecule->is_water(i) ) continue;
262  int ci = molecule->get_cluster(i);
263  if ( ci == i ) {
264  Vector coni = con[i] / molecule->get_clusterSize(i);
265  Vector trans = ( wrapNearest ?
266  lattice.wrap_nearest_delta(coni) : lattice.wrap_delta(coni) );
267  con[i] = trans;
268  }
269  coor[i] = coor[i] + con[ci];
270  }
271  delete [] con;
272 #endif
273 }
static Node * Object()
Definition: Node.h:86
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
int get_clusterSize(int anum) const
Definition: Molecule.h:1100
Molecule stores the structural information for the system.
Definition: Molecule.h:174
int numAtoms
Definition: Molecule.h:586
#define simParams
Definition: Output.C:131
NAMD_HOST_DEVICE Vector wrap_nearest_delta(Position pos1) const
Definition: Lattice.h:233
int get_cluster(int anum) const
Definition: Molecule.h:1099
Bool is_water(int)
NAMD_HOST_DEVICE Vector wrap_delta(const Position &pos1) const
Definition: Lattice.h:222
Molecule * molecule
Definition: Node.h:179

◆ wrap_coor_int_dcd_selection()

template<class xVector , class xDone >
void wrap_coor_int_dcd_selection ( xVector *  coor,
Lattice lattice,
xDone *  done,
int  index 
)

Definition at line 277 of file Output.C.

References Molecule::get_atom_index_from_dcd_selection(), Molecule::get_cluster(), Molecule::get_clusterSize(), Molecule::get_dcd_selection_index_from_atom_id(), Molecule::get_dcd_selection_size(), Molecule::is_water(), Node::molecule, Node::Object(), Node::simParameters, simParams, Lattice::wrap_delta(), and Lattice::wrap_nearest_delta().

Referenced by wrap_coor_dcd_selection().

277  {
279  if ( *done ) return;
280  *done = 1;
281  if ( ! ( simParams->wrapAll || simParams->wrapWater ) ) return;
282  const int wrapNearest = simParams->wrapNearest;
283  const int wrapAll = simParams->wrapAll;
284  Molecule *molecule = Node::Object()->molecule;
285  const int n = molecule->get_dcd_selection_size(index);
286  int i;
287 #ifndef MEM_OPT_VERSION
288  Position *con = new Position[n];
289  for ( i = 0; i < n; ++i ) {
290  int molIndex = molecule->get_atom_index_from_dcd_selection(index, i);
291  con[i] = 0;
292  int ci = molecule->get_cluster(molIndex);
293  int dcdci = molecule->get_dcd_selection_index_from_atom_id(index, ci);
294  // the cluster index might not be in the selection
295  if(dcdci>=0)
296  con[dcdci] += coor[i];
297  }
298  for ( i = 0; i < n; ++i ) {
299  int molIndex = molecule->get_atom_index_from_dcd_selection(index, i);
300  if ( ! wrapAll && ! molecule->is_water(molIndex) ) continue;
301  int ci = molecule->get_cluster(molIndex);
302  int dcdci = molecule->get_dcd_selection_index_from_atom_id(index, ci);
303  if ( ci == molIndex ) {
304  Vector coni = con[i] / molecule->get_clusterSize(molIndex);
305  Vector trans = ( wrapNearest ?
306  lattice.wrap_nearest_delta(coni) : lattice.wrap_delta(coni) );
307  con[i] = trans;
308  }
309  if(dcdci>0)
310  coor[i] = coor[i] + con[dcdci];
311  else
312  coor[i] = coor[i];
313  }
314  delete [] con;
315 #endif
316 }
static Node * Object()
Definition: Node.h:86
int get_atom_index_from_dcd_selection(const int index, const int atomIndex)
Definition: Molecule.h:884
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
int get_clusterSize(int anum) const
Definition: Molecule.h:1100
Molecule stores the structural information for the system.
Definition: Molecule.h:174
const int get_dcd_selection_size(const int index)
Definition: Molecule.h:893
int get_dcd_selection_index_from_atom_id(const int index, const int atomIndex)
Definition: Molecule.h:888
#define simParams
Definition: Output.C:131
NAMD_HOST_DEVICE Vector wrap_nearest_delta(Position pos1) const
Definition: Lattice.h:233
int get_cluster(int anum) const
Definition: Molecule.h:1099
Bool is_water(int)
NAMD_HOST_DEVICE Vector wrap_delta(const Position &pos1) const
Definition: Lattice.h:222
Molecule * molecule
Definition: Node.h:179

Variable Documentation

◆ maxDCD

const short maxDCD =257
static

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 42 of file Output.C.