Skip to content

Commit d3f4ea1

Browse files
drroeDaniel R. Roe
andauthored
Change underlying data type in radial action. (#868)
* Use unsigned long instead of int to avoid overflow * Add missing noefile and orderparamfile keywords to help * Fix IRED manual entry * Revision bump for changing radial int to unsigned long * Ensure volume is summed across processes as well * Remove commented out code * Revision bump for changing radial hist type from int to unsigned long Co-authored-by: Daniel R. Roe <daniel.roe@nih.gov>
1 parent c56fd79 commit d3f4ea1

File tree

5 files changed

+102
-88
lines changed

5 files changed

+102
-88
lines changed

doc/cpptraj.lyx

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41458,7 +41458,11 @@ ired
4145841458
\end_layout
4145941459

4146041460
\begin_layout LyX-Code
41461-
ired [relax freq <MHz> [NHdist <distnh>]] [order <order>]
41461+
ired [relax freq <MHz> [NHdist <distnh>] [noefile <noefilename>]]
41462+
\end_layout
41463+
41464+
\begin_layout LyX-Code
41465+
[order <order>] [orderparamfile <orderfilename>]
4146241466
\end_layout
4146341467

4146441468
\begin_layout LyX-Code
@@ -41485,15 +41489,7 @@ freq
4148541489
\begin_inset space ~
4148641490
\end_inset
4148741491

41488-
<MHz>
41489-
\begin_inset space ~
41490-
\end_inset
41491-
41492-
[NHdist
41493-
\begin_inset space ~
41494-
\end_inset
41495-
41496-
<distnh>]]
41492+
<MHz>]
4149741493
\series default
4149841494
Should only be used when ired vectors represent N-H bonds; calculate correlatio
4149941495
n times
@@ -41519,55 +41515,82 @@ n times
4151941515
\noun default
4152041516
\color inherit
4152141517
\lang american
41522-
for each eigenmode and relaxation rates and NOEs for each N-H vector.
41518+
41519+
\lang english
41520+
for each eigenmode and relaxation rates and NOEs for each N-H vector.
4152341521
'freq <MHz>' (required) is the Lamor frequency of the measurement.
41524-
'NHdist <distnh>' specifies the length of the NH bond in Angstroms (default
41525-
is 1.02).
4152641522
\end_layout
4152741523

41524+
\begin_deeper
4152841525
\begin_layout Description
41529-
order
41526+
[NHdist
41527+
\begin_inset space ~
41528+
\end_inset
41529+
41530+
<distnh>] Specifies the length of the NH bond in Angstroms (default is 1.02).
41531+
\end_layout
41532+
41533+
\begin_layout Description
41534+
[noefile
41535+
\begin_inset space ~
41536+
\end_inset
41537+
41538+
<noefilename>] File to write the T1, T2, and NOE data to.
41539+
\end_layout
41540+
41541+
\end_deeper
41542+
\begin_layout Description
41543+
[order
4153041544
\begin_inset space ~
4153141545
\end_inset
4153241546

41533-
<order> Order of the Legendre polynomials to use when calculating spherical
41547+
<order>] Order of the Legendre polynomials to use when calculating spherical
4153441548
harmonics (default 2).
4153541549
\end_layout
4153641550

41551+
\begin_layout Description
41552+
[orderparamfile
41553+
\begin_inset space ~
41554+
\end_inset
41555+
41556+
<orderfilename>] File to write the S2 data to.
41557+
\end_layout
41558+
4153741559
\begin_layout Description
4153841560

4153941561
\series bold
41540-
tstep
41562+
[tstep
4154141563
\begin_inset space ~
4154241564
\end_inset
4154341565

41544-
<tstep>
41566+
<tstep>]
4154541567
\series default
4154641568
Time between snapshots in ps (default 1.0).
4154741569
\end_layout
4154841570

4154941571
\begin_layout Description
4155041572

4155141573
\series bold
41552-
tcorr
41574+
[tcorr
4155341575
\begin_inset space ~
4155441576
\end_inset
4155541577

41556-
<tcorr>
41578+
<tcorr>]
4155741579
\series default
4155841580
Maximum time to calculate correlation functions for in ps (default 10000.0).
4155941581
\end_layout
4156041582

4156141583
\begin_layout Description
4156241584

4156341585
\series bold
41564-
out
41586+
[out
4156541587
\begin_inset space ~
4156641588
\end_inset
4156741589

4156841590
<filename>
4156941591
\series default
41570-
Name of file to write output to.
41592+
Name of file to write plateau and TauM data.
41593+
Also the prefix for the .cmt and .cjt files (see below).
4157141594
\end_layout
4157241595

4157341596
\begin_layout Description
@@ -41698,19 +41721,15 @@ literal "true"
4169841721
\noun default
4169941722
\color inherit
4170041723
\lang american
41701-
will be written to
41702-
\shape italic
41703-
filename.cmt
41704-
\shape default
41705-
.
41706-
Autocorrelation functions for each vector will be written to
41707-
\shape italic
41708-
filename.cjt
41709-
\shape default
41710-
.
41724+
41725+
\lang english
41726+
will be written to <filename>.cmt.
41727+
Autocorrelation functions for each vector will be written to <filename>.cjt.
4171141728
Relaxation rates and NOEs for each N-H vector will be written to <filename>
4171241729
or added to the the end of the standard output.
41713-
For the calculation of
41730+
For the calculation of
41731+
\lang american
41732+
4171441733
\family roman
4171541734
\series medium
4171641735
\shape up
@@ -41734,16 +41753,18 @@ filename.cjt
4173441753
\noun default
4173541754
\color inherit
4173641755
\lang american
41737-
the normalized correlation functions and only the first third of the analyzed
41756+
41757+
\lang english
41758+
the normalized correlation functions and only the first third of the analyzed
4173841759
time steps will be used.
4173941760
For further information on the convergence of correlation functions see
4174041761
[Schneider, Brünger, Nilges,
41741-
\shape italic
41762+
\emph on
4174241763
J.
4174341764
Mol.
4174441765
Biol.
4174541766

41746-
\shape default
41767+
\emph default
4174741768

4174841769
\series bold
4174941770
285

src/Action_Radial.cpp

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
// CONSTRUCTOR
1111
Action_Radial::Action_Radial() :
12-
RDF_(0),
13-
rdf_thread_(0),
12+
# ifdef _OPENMP
13+
threadsCombined_(false),
14+
# endif
1415
rmode_(NORMAL),
1516
currentParm_(0),
1617
intramol_distances_(0),
@@ -43,18 +44,7 @@ void Action_Radial::Help() const {
4344
" of residues/molecules selected by mask1 or mask2.\n");
4445
}
4546

46-
// DESTRUCTOR
47-
Action_Radial::~Action_Radial() {
48-
//fprintf(stderr,"Radial Destructor.\n");
49-
if (RDF_!=0) delete[] RDF_;
50-
if (rdf_thread_!=0) {
51-
for (int i=0; i < numthreads_; i++)
52-
delete[] rdf_thread_[i];
53-
delete[] rdf_thread_;
54-
}
55-
}
56-
57-
inline Action::RetType RDF_ERR(const char* msg) {
47+
inline Action::RetType Rdf_Err(const char* msg) {
5848
mprinterr("Error: %s\n", msg);
5949
return Action::ERR;
6050
}
@@ -136,7 +126,7 @@ Action::RetType Action_Radial::Init(ArgList& actionArgs, ActionInit& init, int d
136126
// Set up output dataset.
137127
Dset_ = init.DSL().AddSet( DataSet::DOUBLE, MetaData(actionArgs.GetStringNext(), "",
138128
MetaData::NOT_TS), "g(r)");
139-
if (Dset_ == 0) return RDF_ERR("Could not allocate RDF data set.");
129+
if (Dset_ == 0) return Rdf_Err("Could not allocate RDF data set.");
140130
DataFile* outfile = init.DFL().AddDataFile(outfilename, actionArgs);
141131
if (outfile != 0) outfile->AddDataSet( Dset_ );
142132
// Make default precision a little higher than normal
@@ -157,7 +147,7 @@ Action::RetType Action_Radial::Init(ArgList& actionArgs, ActionInit& init, int d
157147
if (intrdfFile != 0) {
158148
intrdf_ = init.DSL().AddSet( DataSet::DOUBLE, MetaData(Dset_->Meta().Name(), "int",
159149
MetaData::NOT_TS) );
160-
if (intrdf_ == 0) return RDF_ERR("Could not allocate RDF integral data set.");
150+
if (intrdf_ == 0) return Rdf_Err("Could not allocate RDF integral data set.");
161151
intrdf_->SetupFormat().SetFormatWidthPrecision(12,6);
162152
intrdf_->SetLegend("Int[" + Mask2_.MaskExpression() + "]");
163153
intrdf_->SetDim(Dimension::X, Rdim);
@@ -168,7 +158,7 @@ Action::RetType Action_Radial::Init(ArgList& actionArgs, ActionInit& init, int d
168158
if (rawrdfFile != 0) {
169159
rawrdf_ = init.DSL().AddSet( DataSet::DOUBLE, MetaData(Dset_->Meta().Name(), "raw",
170160
MetaData::NOT_TS) );
171-
if (rawrdf_ == 0) return RDF_ERR("Could not allocate raw RDF data set.");
161+
if (rawrdf_ == 0) return Rdf_Err("Could not allocate raw RDF data set.");
172162
rawrdf_->SetupFormat().SetFormatWidthPrecision(12,6);
173163
rawrdf_->SetLegend("Raw[" + Dset_->Meta().Legend() + "]");
174164
rawrdf_->SetDim(Dimension::X, Rdim);
@@ -182,9 +172,9 @@ Action::RetType Action_Radial::Init(ArgList& actionArgs, ActionInit& init, int d
182172
if (rawrdf_ != 0) rawrdf_->SetNeedsSync( false );
183173
# endif
184174
// Set up histogram
185-
RDF_ = new int[ numBins_ ];
186-
std::fill(RDF_, RDF_ + numBins_, 0);
175+
RDF_.assign( numBins_, 0 );
187176
# ifdef _OPENMP
177+
threadsCombined_ = false;
188178
// Since RDF is shared by all threads and we cant guarantee that a given
189179
// bin in RDF wont be accessed at the same time by the same thread,
190180
// each thread needs its own bin space.
@@ -193,12 +183,10 @@ Action::RetType Action_Radial::Init(ArgList& actionArgs, ActionInit& init, int d
193183
if (omp_get_thread_num()==0)
194184
numthreads_ = omp_get_num_threads();
195185
}
196-
rdf_thread_ = new int*[ numthreads_ ];
197-
for (int i=0; i < numthreads_; i++) {
198-
rdf_thread_[i] = new int[ numBins_ ];
199-
std::fill(rdf_thread_[i], rdf_thread_[i] + numBins_, 0);
200-
}
201-
# endif
186+
rdf_thread_.resize( numthreads_ );
187+
for (int i=0; i < numthreads_; i++)
188+
rdf_thread_[i].assign( numBins_, 0 );
189+
# endif /* _OPENMP */
202190

203191
mprintf(" RADIAL: Calculating RDF for atoms in mask [%s]",Mask1_.MaskString());
204192
if (!mask2.empty())
@@ -590,31 +578,31 @@ int Action_Radial::SyncAction() {
590578
# ifdef _OPENMP
591579
CombineRdfThreads();
592580
# endif
593-
int total_frames = 0;
594-
trajComm_.ReduceMaster( &total_frames, &numFrames_, 1, MPI_INT, MPI_SUM );
581+
double total_volume = 0;
582+
trajComm_.ReduceMaster( &total_volume, &volume_, 1, MPI_DOUBLE, MPI_SUM );
583+
unsigned long total_frames = 0;
584+
trajComm_.ReduceMaster( &total_frames, &numFrames_, 1, MPI_UNSIGNED_LONG, MPI_SUM );
595585
if (trajComm_.Master()) {
586+
volume_ = total_volume;
596587
numFrames_ = total_frames;
597-
int* sum_bins = new int[ numBins_ ];
598-
trajComm_.ReduceMaster( sum_bins, RDF_, numBins_, MPI_INT, MPI_SUM );
599-
std::copy( sum_bins, sum_bins + numBins_, RDF_ );
600-
delete[] sum_bins;
588+
Iarray sum_bins( numBins_ );
589+
trajComm_.ReduceMaster( &sum_bins[0], &RDF_[0], numBins_, MPI_UNSIGNED_LONG, MPI_SUM );
590+
RDF_ = sum_bins;
601591
} else
602-
trajComm_.ReduceMaster( 0, RDF_, numBins_, MPI_INT, MPI_SUM );
592+
trajComm_.ReduceMaster( 0, &RDF_[0], numBins_, MPI_UNSIGNED_LONG, MPI_SUM );
603593
return 0;
604594
}
605595
#endif
606596

607597
#ifdef _OPENMP
608598
/** Combine results from each rdf_thread into rdf. */
609599
void Action_Radial::CombineRdfThreads() {
610-
if (rdf_thread_ == 0) return;
600+
if (threadsCombined_) return;
611601
for (int thread = 0; thread < numthreads_; thread++) {
612602
for (int bin = 0; bin < numBins_; bin++)
613603
RDF_[bin] += rdf_thread_[thread][bin];
614-
delete[] rdf_thread_[thread];
615604
}
616-
delete[] rdf_thread_;
617-
rdf_thread_ = 0;
605+
threadsCombined_ = true;
618606
}
619607
#endif
620608

@@ -629,7 +617,7 @@ void Action_Radial::Print() {
629617
# ifdef _OPENMP
630618
CombineRdfThreads();
631619
# endif
632-
mprintf(" RADIAL: %i frames,", numFrames_);
620+
mprintf(" RADIAL: %lu frames,", numFrames_);
633621
double nmask1 = (double)Mask1_.Nselected();
634622
double nmask2 = (double)Mask2_.Nselected();
635623
int numSameAtoms = 0;
@@ -666,7 +654,7 @@ void Action_Radial::Print() {
666654

667655
// If useVolume, calculate the density from the average volume
668656
if (useVolume_) {
669-
double avgVol = volume_ / numFrames_;
657+
double avgVol = volume_ / (double)numFrames_;
670658
mprintf("\tAverage volume is %f Ang^3.\n",avgVol);
671659
density_ = (nmask1 * nmask2 - (double)numSameAtoms) / avgVol;
672660
mprintf("\tAverage density is %f distances / Ang^3.\n",density_);
@@ -684,7 +672,7 @@ void Action_Radial::Print() {
684672
for (int bin = 0; bin < numBins_; bin++) {
685673
//mprintf("DBG:\tNumBins= %i\n",rdf[bin]);
686674
// Number of particles in this volume slice over all frames.
687-
double N = (double) RDF_[bin];
675+
double N = (double)RDF_[bin];
688676
if (rawrdf_ != 0)
689677
rawrdf_->Add(bin, &N);
690678
// r, r + dr
@@ -696,7 +684,7 @@ void Action_Radial::Print() {
696684
double expectedD = dv * density_;
697685
if (debug_>0)
698686
mprintf(" \tBin %f->%f <Pop>=%f, V=%f, D=%f, norm %f distances.\n",
699-
R,Rdr,N/numFrames_,dv,density_,expectedD);
687+
R,Rdr,N/(double)numFrames_,dv,density_,expectedD);
700688
// Divide by # frames
701689
double norm = expectedD * (double)numFrames_;
702690
N /= norm;

src/Action_Radial.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
class Action_Radial: public Action {
77
public:
88
Action_Radial();
9-
~Action_Radial();
109
DispatchObject* Alloc() const { return (DispatchObject*)new Action_Radial(); }
1110
void Help() const;
1211
private:
@@ -21,18 +20,23 @@ class Action_Radial: public Action {
2120
# ifdef _OPENMP
2221
void CombineRdfThreads();
2322
# endif
24-
ImagedAction image_; ///< Image routines.
25-
int* RDF_; ///< Hold bin counts.
26-
int** rdf_thread_; ///< Hold bin count on each thread.
27-
AtomMask Mask1_; ///< Atoms to calculate RDF for.
28-
AtomMask Mask2_; ///< Optional mask to calc RDF to atoms in Mask1.
29-
AtomMask OuterMask_; ///< Mask with the most atoms.
30-
AtomMask InnerMask_; ///< Mask with the fewest atoms.
23+
typedef std::vector<unsigned long> Iarray;
24+
25+
# ifdef _OPENMP
26+
bool threadsCombined_; ///< True if CombineRdfThreads() has been called.
27+
# endif
28+
ImagedAction image_; ///< Image routines.
29+
Iarray RDF_; ///< Hold bin counts.
30+
std::vector<Iarray> rdf_thread_; ///< Hold bin count on each thread.
31+
AtomMask Mask1_; ///< Atoms to calculate RDF for.
32+
AtomMask Mask2_; ///< Optional mask to calc RDF to atoms in Mask1.
33+
AtomMask OuterMask_; ///< Mask with the most atoms.
34+
AtomMask InnerMask_; ///< Mask with the fewest atoms.
3135
typedef std::vector<AtomMask> Marray;
3236
Marray Sites1_;
3337
Marray Sites2_;
3438
enum RmodeType { NORMAL=0, NO_INTRAMOL, CENTER1, CENTER2, BYSITE };
35-
RmodeType rmode_; ///< Type of calculation to perform.
39+
RmodeType rmode_; ///< Type of calculation to perform.
3640
enum SmodeType { OFF = 0, BYRES, BYMOL };
3741
SmodeType siteMode1_;
3842
SmodeType siteMode2_;
@@ -45,7 +49,7 @@ class Action_Radial: public Action {
4549
double one_over_spacing_; ///< 1/spacing, used to avoid man division ops.
4650
int numBins_; ///< The number of bins.
4751
int numthreads_; ///< Number of threads.
48-
int numFrames_; ///< Number of frames for which RDF is calcd.
52+
unsigned long numFrames_; ///< Number of frames for which RDF is calcd.
4953
double density_; ///< Particle density (molecules/Ang^3).
5054
DataSet* Dset_;
5155
DataSet* intrdf_;

0 commit comments

Comments
 (0)