From 35bd6a1e9e95f5f5a3e9ece9684a1d0db25a7d83 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 3 Jun 2020 14:07:51 -0400 Subject: [PATCH 01/87] SPAM shouldn't be hidden. --- src/Action_Spam.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Action_Spam.cpp b/src/Action_Spam.cpp index 47500b9372..2368a3e141 100644 --- a/src/Action_Spam.cpp +++ b/src/Action_Spam.cpp @@ -14,7 +14,7 @@ #include "DataSet_Mesh.h" // CONSTRUCTOR -Action_Spam::Action_Spam() : Action(HIDDEN), +Action_Spam::Action_Spam() : debug_(0), DG_BULK_(-30.3), // Free energy of bulk SPCE water DH_BULK_(-22.2), // Enthalpy of bulk SPCE water From 3eb9f563e010ae409d62d4c42b3aa1e841885259 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 3 Jun 2020 14:56:21 -0400 Subject: [PATCH 02/87] Skip peaks where the bin calculation would potentially overflow --- src/Action_Spam.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Action_Spam.cpp b/src/Action_Spam.cpp index 2368a3e141..f8e6704ac6 100644 --- a/src/Action_Spam.cpp +++ b/src/Action_Spam.cpp @@ -703,6 +703,13 @@ int Action_Spam::Calc_G_Wat(DataSet* dsIn, unsigned int peaknum) //mprintf("DEBUG:\tNvals=%zu min=%g max=%g BWfac=%g\n", enevec.Size(), min, max, BWfac); // Estimate number of bins the same way spamstats.py does. int nbins = (int)(((max - min) / BWfac) + 0.5) + 100; + if (nbins < 0) { + // Probably an overflow due to extremely large energy. + mprintf("Warning: Large magnitude energy observed for peak %u (min=%g max=%g)\n", + peaknum+1, min, max); + mprintf("Warning: Skipping peak.\n"); + return -1; + } HistBin Xdim(nbins, min - (50*BWfac), BWfac, "P(Ewat)"); //Xdim.CalcBinsOrStep(min - Havg.variance(), max + Havg.variance(), 0.0, nbins, "P(Ewat)"); @@ -729,16 +736,17 @@ int Action_Spam::Calc_G_Wat(DataSet* dsIn, unsigned int peaknum) double adjustedDG = DG - DG_BULK_; double adjustedDH = Havg.mean() - DH_BULK_; double ntds = adjustedDG - adjustedDH; + if (ds_dg_ == 0) { - mprintf("\tSPAM bulk energy values:\n"); - mprintf("\t = %g, = %g +/- %g, -TdS= %g\n", adjustedDG, adjustedDH, + mprintf("\tSPAM bulk energy values:\n" + "\t = %g, = %g +/- %g, -TdS= %g\n", adjustedDG, adjustedDH, sqrt(Havg.variance()), ntds); } else { ((DataSet_Mesh*)ds_dg_)->AddXY(peaknum+1, adjustedDG); ((DataSet_Mesh*)ds_dh_)->AddXY(peaknum+1, adjustedDH); ((DataSet_Mesh*)ds_ds_)->AddXY(peaknum+1, ntds); } - + // DEBUG if (debug_ > 1) { FileName rawname("dbgraw." + integerToString(peaknum+1) + ".dat"); @@ -850,7 +858,7 @@ void Action_Spam::Print() { if (err == 1) n_peaks_no_energy++; else if (err == -1) - mprintf("Warning: Error calculating SPAM energies for peak %zu\n", ds - myDSL_.begin()); + mprintf("Warning: Error calculating SPAM energies for peak %u\n", p + 1); } if (n_peaks_no_energy > 0) mprintf("Warning: No energies for %i peaks.\n", n_peaks_no_energy); From 1c59cd14ac2af3cf08538bb700557181c5b5edb2 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 3 Jun 2020 16:37:22 -0400 Subject: [PATCH 03/87] Avoid using zero bandwidth for KDE histogram when only 1 value available --- src/Action_Spam.cpp | 22 ++++++++++++++++++---- src/KDE.cpp | 4 +++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Action_Spam.cpp b/src/Action_Spam.cpp index f8e6704ac6..02bbd92b26 100644 --- a/src/Action_Spam.cpp +++ b/src/Action_Spam.cpp @@ -611,6 +611,8 @@ Action::RetType Action_Spam::DoSPAM(int frameNum, Frame& frameIn) { // provide some time savings. double ene = Calculate_Energy(frameIn, solvent_residues_[i]); myDSL_[peak]->Add(frameNum, &ene); + //mprintf("DEBUG: Frm %6i peak %6i residx %6u solvres %6i ene %g\n", + // frameNum+1, peak+1, i, solvent_residues_[i].OriginalResNum(), ene); break; } } else @@ -700,7 +702,8 @@ int Action_Spam::Calc_G_Wat(DataSet* dsIn, unsigned int peaknum) // Calculate distribution of energy values using KDE. Get the bandwidth // factor here since we already know the SD. double BWfac = KDE::BandwidthFactor( enevec.Size() ); - //mprintf("DEBUG:\tNvals=%zu min=%g max=%g BWfac=%g\n", enevec.Size(), min, max, BWfac); + if (debug_ > 0) + mprintf("DEBUG:\tNvals=%zu min=%g max=%g BWfac=%g\n", enevec.Size(), min, max, BWfac); // Estimate number of bins the same way spamstats.py does. int nbins = (int)(((max - min) / BWfac) + 0.5) + 100; if (nbins < 0) { @@ -713,10 +716,19 @@ int Action_Spam::Calc_G_Wat(DataSet* dsIn, unsigned int peaknum) HistBin Xdim(nbins, min - (50*BWfac), BWfac, "P(Ewat)"); //Xdim.CalcBinsOrStep(min - Havg.variance(), max + Havg.variance(), 0.0, nbins, "P(Ewat)"); - if (debug_ > 0) Xdim.PrintHistBin(); + if (debug_ > 0) { + mprintf("DEBUG:"); + Xdim.PrintHistBin(); + } DataSet_double kde1; KDE gkde; - if (gkde.CalcKDE( kde1, enevec, Xdim, 1.06 * sqrt(Havg.variance()) * BWfac )) { + double bandwidth; + if (enevec.Size() == 1) { + // Special case. Juse use BWfac to avoid a zero bandwidth. + bandwidth = BWfac; + } else + bandwidth = 1.06 * sqrt(Havg.variance()) * BWfac; + if (gkde.CalcKDE( kde1, enevec, Xdim, bandwidth )) { mprinterr("Error: Could not calculate E KDE histogram.\n"); return -1; } @@ -729,8 +741,10 @@ int Action_Spam::Calc_G_Wat(DataSet* dsIn, unsigned int peaknum) double Ewat = kde1.Xcrd(i); double PEwat = kde1.Dval(i); sumQ += (PEwat * exp( -Ewat * KB )); + //mprintf("DEBUG:\t\tEwat %20.10E PEwat %20.10E sumQ %20.10E\n", Ewat, PEwat, sumQ); } - //mprintf("DEBUG: sumQ= %20.10E\n", sumQ); + if (debug_ > 0) + mprintf("DEBUG: peak %6u sumQ= %20.10E\n", peaknum+1, sumQ); double DG = -RT * log(BWfac * sumQ); double adjustedDG = DG - DG_BULK_; diff --git a/src/KDE.cpp b/src/KDE.cpp index cddf7fa21a..33f544ef3f 100644 --- a/src/KDE.cpp +++ b/src/KDE.cpp @@ -179,7 +179,9 @@ int KDE::CalcKDE(DataSet_double& Out, DataSet_1D const& Pdata, omp_set_num_threads( original_num_threads ); # endif // Normalize - for (unsigned int j = 0; j < Out.Size(); j++) + for (unsigned int j = 0; j < Out.Size(); j++) { + //mprintf("DEBUG:\t\t\tkde %g %g %g\n", Out[j], total, bandwidth); Out[j] /= (total * bandwidth); + } return 0; } From ead397e493f4350b08d8b45f4242426fd75e162d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 13:54:20 -0400 Subject: [PATCH 04/87] Start adding dataset that can be used to hold vectors and an associated scalar value. --- src/DataSet.cpp | 3 ++- src/DataSet.h | 2 +- src/DataSet_Vector.cpp | 1 + src/DataSet_Vector_Scalar.cpp | 47 +++++++++++++++++++++++++++++++++++ src/DataSet_Vector_Scalar.h | 36 +++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/DataSet_Vector_Scalar.cpp create mode 100644 src/DataSet_Vector_Scalar.h diff --git a/src/DataSet.cpp b/src/DataSet.cpp index c462a52007..f054fcafd8 100644 --- a/src/DataSet.cpp +++ b/src/DataSet.cpp @@ -30,7 +30,8 @@ const char* DataSet::Descriptions_[] = { "pH REMD (implicit)", // PH_IMPL "parameters", // PARAMETERS "tensor", // TENSOR - "string variable" // STRINGVAR + "string variable", // STRINGVAR + "vector with scalar" // VECTOR_SCALAR }; // CONSTRUCTOR diff --git a/src/DataSet.h b/src/DataSet.h index 152141823d..76a8ec7c0f 100644 --- a/src/DataSet.h +++ b/src/DataSet.h @@ -28,7 +28,7 @@ class DataSet { UNKNOWN_DATA=0, DOUBLE, FLOAT, INTEGER, STRING, MATRIX_DBL, MATRIX_FLT, COORDS, VECTOR, MODES, GRID_FLT, GRID_DBL, REMLOG, XYMESH, TRAJ, REF_FRAME, MAT3X3, TOPOLOGY, CMATRIX, CMATRIX_NOMEM, CMATRIX_DISK, PH, PH_EXPL, PH_IMPL, - PARAMETERS, TENSOR, STRINGVAR + PARAMETERS, TENSOR, STRINGVAR, VECTOR_SCALAR }; /// Group DataSet belongs to. enum DataGroup { diff --git a/src/DataSet_Vector.cpp b/src/DataSet_Vector.cpp index 694649981a..0041b31127 100644 --- a/src/DataSet_Vector.cpp +++ b/src/DataSet_Vector.cpp @@ -68,6 +68,7 @@ void DataSet_Vector::WriteBuffer(CpptrajFile &cbuffer, SizeArray const& pIn) con // DataSet_Vector::Append() int DataSet_Vector::Append(DataSet* dsIn) { + if (dsIn == 0) return 1; if (dsIn->Empty()) return 0; if (dsIn->Type() != VECTOR) return 1; Varray const& vIn = ((DataSet_Vector*)dsIn)->vectors_; diff --git a/src/DataSet_Vector_Scalar.cpp b/src/DataSet_Vector_Scalar.cpp new file mode 100644 index 0000000000..0b4ac48c40 --- /dev/null +++ b/src/DataSet_Vector_Scalar.cpp @@ -0,0 +1,47 @@ +#include "DataSet_Vector_Scalar.h" +#include "CpptrajStdio.h" +#include // std::copy + +/// CONSTRUCTOR TODO should this be in VECTOR_1D group? +DataSet_Vector_Scalar::DataSet_Vector_Scalar() : + DataSet(VECTOR_SCALAR, GENERIC, TextFormat(TextFormat::DOUBLE, 8, 4, 4), 1) +{ } + +/** Reserve space in vector array. */ +int DataSet_Vector_Scalar::Allocate(SizeArray const& Nin) { + if (!Nin.empty()) { + vecs_.reserve( Nin[0] ); + vals_.reserve( Nin[0] ); + } + return 0; +} + +/** Write vector + scalar to output file. */ +void DataSet_Vector_Scalar::WriteBuffer(CpptrajFile& cbuffer, SizeArray const& pIn) const { + if (pIn[0] >= Size()) { + cbuffer.Printf(format_.fmt(), 0.0, 0.0, 0.0, 0.0); /// VXYZ SCALAR + } else { + Vec3 const& vxyz = vecs_[pIn[0]]; + cbuffer.Printf(format_.fmt(), vxyz[0], vxyz[1], vxyz[2], vals_[pIn[0]]); + } +} + +/** Append vector scalar set to this set. */ +int DataSet_Vector_Scalar::Append(DataSet* dsIn) { + if (dsIn == 0) return 1; + if (dsIn->Empty()) return 0; + if (dsIn->Type() != VECTOR_SCALAR) return 1; + Varray const& vIn = ((DataSet_Vector_Scalar*)dsIn)->vecs_; + Darray const& dIn = ((DataSet_Vector_Scalar*)dsIn)->vals_; + size_t oldsize = vecs_.size(); + vecs_.resize( oldsize + vIn.size() ); + std::copy( vIn.begin(), vIn.end(), vecs_.begin() + oldsize ); + vals_.resize( oldsize + dIn.size() ); + std::copy( dIn.begin(), dIn.end(), vals_.begin() + oldsize ); + return 0; +} + +/** \return memory usage of the set in bytes. */ +size_t DataSet_Vector_Scalar::MemUsageInBytes() const { + return ((vecs_.size()*Vec3::DataSize()) + vals_.size()); +} diff --git a/src/DataSet_Vector_Scalar.h b/src/DataSet_Vector_Scalar.h new file mode 100644 index 0000000000..e6b5d494a7 --- /dev/null +++ b/src/DataSet_Vector_Scalar.h @@ -0,0 +1,36 @@ +#ifndef INC_DATASET_VECTOR_SCALAR_H +#define INC_DATASET_VECTOR_SCALAR_H +#include "DataSet.h" +#include "Vec3.h" +/// Hold XYZ value and associated scalar. +class DataSet_Vector_Scalar : public DataSet { + public: + DataSet_Vector_Scalar(); + static DataSet* Alloc() { return (DataSet*)new DataSet_Vector_Scalar(); } + // ----- DataSet functions ------------------- + size_t Size() const { return vecs_.size(); } + void Info() const { return; } + int Allocate(SizeArray const&); + inline void Add(size_t, const void*); + void WriteBuffer(CpptrajFile&, SizeArray const&) const; + int Append(DataSet*); + size_t MemUsageInBytes() const; +# ifdef MPI + int Sync(size_t, std::vector const&, Parallel::Comm const&) { return 1; } +# endif + // ------------------------------------------- + private: + typedef std::vector Varray; + typedef std::vector Darray; + + Varray vecs_; ///< Hold XYZ values. + Darray vals_; ///< Hold scalar values. +}; + +/** Add XYZ scalar to the DataSet */ +void DataSet_Vector_Scalar::Add(size_t idx, const void* ptrIn) { + const double* ptr = (const double*)ptrIn; + vecs_.push_back( Vec3(ptr[0], ptr[1], ptr[2]) ); + vals_.push_back( ptr[3] ); +} +#endif From f326946baa23153716bf4fd4620b36673f3885a8 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 14:01:36 -0400 Subject: [PATCH 05/87] Add Sync() --- src/DataSet_Vector_Scalar.cpp | 30 ++++++++++++++++++++++++++++++ src/DataSet_Vector_Scalar.h | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/DataSet_Vector_Scalar.cpp b/src/DataSet_Vector_Scalar.cpp index 0b4ac48c40..2f94e038c1 100644 --- a/src/DataSet_Vector_Scalar.cpp +++ b/src/DataSet_Vector_Scalar.cpp @@ -45,3 +45,33 @@ int DataSet_Vector_Scalar::Append(DataSet* dsIn) { size_t DataSet_Vector_Scalar::MemUsageInBytes() const { return ((vecs_.size()*Vec3::DataSize()) + vals_.size()); } + +#ifdef MPI +int DataSet_Vector_Scalar::Sync(size_t total, std::vector const& rank_frames, + Parallel::Comm const& commIn) +{ + if (commIn.Size()==1) return 0; + double buf[4]; + if (commIn.Master()) { + // Resize to accept data from other ranks. + vecs_.resize( total ); + vals_.resize( total ); + int vidx = rank_frames[0]; + for (int rank = 1; rank < commIn.Size(); rank++) { + for (int ridx = 0; ridx != rank_frames[rank]; ridx++, vidx++) { + commIn.SendMaster( buf, 4, rank, MPI_DOUBLE ); + std::copy( buf, buf+3, vecs_[vidx].Dptr() ); + vals_[vidx] = buf[3]; + } + } + } else { + // Send data to master + for (unsigned int ridx = 0; ridx != vecs_.size(); ++ridx) { + std::copy( vecs_[ridx].Dptr(), vecs_[ridx].Dptr()+3, buf ); + buf[3] = vals_[ridx]; + commIn.SendMaster( buf, 4, commIn.Rank(), MPI_DOUBLE ); + } + } + return 0; +} +#endif diff --git a/src/DataSet_Vector_Scalar.h b/src/DataSet_Vector_Scalar.h index e6b5d494a7..af2621cf8d 100644 --- a/src/DataSet_Vector_Scalar.h +++ b/src/DataSet_Vector_Scalar.h @@ -16,7 +16,7 @@ class DataSet_Vector_Scalar : public DataSet { int Append(DataSet*); size_t MemUsageInBytes() const; # ifdef MPI - int Sync(size_t, std::vector const&, Parallel::Comm const&) { return 1; } + int Sync(size_t, std::vector const&, Parallel::Comm const&); # endif // ------------------------------------------- private: From be10a3bfdc8f02bf963481fadf1872b3a08741c9 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 14:02:28 -0400 Subject: [PATCH 06/87] Update dependencies --- src/cpptrajdepend | 1 + src/cpptrajfiles | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cpptrajdepend b/src/cpptrajdepend index f84b235a16..d7e0b0131b 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -217,6 +217,7 @@ DataSet_StringVar.o : DataSet_StringVar.cpp AssociatedData.h CpptrajFile.h Cpptr DataSet_Tensor.o : DataSet_Tensor.cpp AssociatedData.h CpptrajFile.h DataSet.h DataSet_Tensor.h Dimension.h FileIO.h FileName.h MetaData.h Parallel.h Range.h SymmetricTensor.h TextFormat.h DataSet_Topology.o : DataSet_Topology.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h BondSearch.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_Topology.h Dimension.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ParmIO.h Range.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Topology.h TypeNameHolder.h Vec3.h DataSet_Vector.o : DataSet_Vector.cpp ArrayIterator.h AssociatedData.h ComplexArray.h Constants.h Corr.h CpptrajFile.h DataSet.h DataSet_1D.h DataSet_Vector.h Dimension.h FileIO.h FileName.h MetaData.h Parallel.h PubFFT.h Range.h SymbolExporting.h TextFormat.h Vec3.h +DataSet_Vector_Scalar.o : DataSet_Vector_Scalar.cpp AssociatedData.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_Vector_Scalar.h Dimension.h FileIO.h FileName.h MetaData.h Parallel.h Range.h TextFormat.h Vec3.h DataSet_double.o : DataSet_double.cpp AssociatedData.h CpptrajFile.h DataSet.h DataSet_1D.h DataSet_double.h Dimension.h FileIO.h FileName.h MetaData.h Parallel.h Range.h TextFormat.h DataSet_float.o : DataSet_float.cpp AssociatedData.h CpptrajFile.h DataSet.h DataSet_1D.h DataSet_float.h Dimension.h FileIO.h FileName.h MetaData.h Parallel.h Range.h TextFormat.h DataSet_integer_disk.o : DataSet_integer_disk.cpp AssociatedData.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_1D.h DataSet_integer.h DataSet_integer_disk.h Dimension.h FileIO.h FileName.h File_TempName.h MetaData.h NC_Routines.h Parallel.h Range.h TextFormat.h diff --git a/src/cpptrajfiles b/src/cpptrajfiles index 0c90d4d5c5..e3e959ff38 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -217,6 +217,7 @@ COMMON_SOURCES= \ DataSet_RemLog.cpp \ DataSet_Topology.cpp \ DataSet_Vector.cpp \ + DataSet_Vector_Scalar.cpp \ DataSet_double.cpp \ DataSet_float.cpp \ DataSet_integer_disk.cpp \ From a35847a9dba2ed65109312097707af7487c16a19 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 14:14:34 -0400 Subject: [PATCH 07/87] Add VECTOR_SCALAR set --- src/DataSetList.cpp | 2 ++ src/cpptrajdepend | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/DataSetList.cpp b/src/DataSetList.cpp index fb1b4507be..267b0bced9 100644 --- a/src/DataSetList.cpp +++ b/src/DataSetList.cpp @@ -33,6 +33,7 @@ #include "DataSet_Parameters.h" #include "DataSet_Tensor.h" #include "DataSet_StringVar.h" +#include "DataSet_Vector_Scalar.h" bool DataSetList::useDiskCache_ = false; @@ -81,6 +82,7 @@ DataSet* DataSetList::NewSet(DataSet::DataType typeIn) { case DataSet::PARAMETERS : ds = DataSet_Parameters::Alloc(); break; case DataSet::TENSOR : ds = DataSet_Tensor::Alloc(); break; case DataSet::STRINGVAR : ds = DataSet_StringVar::Alloc(); break; + case DataSet::VECTOR_SCALAR : ds = DataSet_Vector_Scalar::Alloc(); break; // Sanity check default: mprinterr("Internal Error: No allocator for DataSet type '%s'\n", diff --git a/src/cpptrajdepend b/src/cpptrajdepend index d7e0b0131b..ce24bc5cbd 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -191,7 +191,7 @@ DataIO_VecTraj.o : DataIO_VecTraj.cpp ActionFrameCounter.h ArgList.h ArrayIterat DataIO_XVG.o : DataIO_XVG.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_XVG.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_Xplor.o : DataIO_Xplor.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Xplor.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridFlt.h Dimension.h FileIO.h FileName.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataSet.o : DataSet.cpp AssociatedData.h CpptrajFile.h CpptrajStdio.h DataSet.h Dimension.h FileIO.h FileName.h MetaData.h Parallel.h Range.h TextFormat.h -DataSetList.o : DataSetList.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h Box.h ClusterDist.h ClusterSieve.h ComplexArray.h Constants.h CoordinateInfo.h Cph.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Cmatrix.h DataSet_Cmatrix_DISK.h DataSet_Cmatrix_MEM.h DataSet_Cmatrix_NOMEM.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h DataSet_Coords_TRJ.h DataSet_GridDbl.h DataSet_GridFlt.h DataSet_Mat3x3.h DataSet_MatrixDbl.h DataSet_MatrixFlt.h DataSet_Mesh.h DataSet_Modes.h DataSet_PHREMD.h DataSet_PHREMD_Explicit.h DataSet_PHREMD_Implicit.h DataSet_Parameters.h DataSet_RemLog.h DataSet_StringVar.h DataSet_Tensor.h DataSet_Topology.h DataSet_Vector.h DataSet_double.h DataSet_float.h DataSet_integer.h DataSet_integer_disk.h DataSet_integer_mem.h DataSet_pH.h DataSet_string.h Dimension.h FileIO.h FileName.h Frame.h Grid.h GridBin.h Hungarian.h InputTrajCommon.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Cmatrix.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Spline.h StringRoutines.h SymbolExporting.h SymmetricRmsdCalc.h SymmetricTensor.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h TrajFrameIndex.h Trajin.h TypeNameHolder.h Vec3.h +DataSetList.o : DataSetList.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h Box.h ClusterDist.h ClusterSieve.h ComplexArray.h Constants.h CoordinateInfo.h Cph.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Cmatrix.h DataSet_Cmatrix_DISK.h DataSet_Cmatrix_MEM.h DataSet_Cmatrix_NOMEM.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h DataSet_Coords_TRJ.h DataSet_GridDbl.h DataSet_GridFlt.h DataSet_Mat3x3.h DataSet_MatrixDbl.h DataSet_MatrixFlt.h DataSet_Mesh.h DataSet_Modes.h DataSet_PHREMD.h DataSet_PHREMD_Explicit.h DataSet_PHREMD_Implicit.h DataSet_Parameters.h DataSet_RemLog.h DataSet_StringVar.h DataSet_Tensor.h DataSet_Topology.h DataSet_Vector.h DataSet_Vector_Scalar.h DataSet_double.h DataSet_float.h DataSet_integer.h DataSet_integer_disk.h DataSet_integer_mem.h DataSet_pH.h DataSet_string.h Dimension.h FileIO.h FileName.h Frame.h Grid.h GridBin.h Hungarian.h InputTrajCommon.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Cmatrix.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Spline.h StringRoutines.h SymbolExporting.h SymmetricRmsdCalc.h SymmetricTensor.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h TrajFrameIndex.h Trajin.h TypeNameHolder.h Vec3.h DataSet_1D.o : DataSet_1D.cpp ArrayIterator.h AssociatedData.h ComplexArray.h Constants.h Corr.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_1D.h Dimension.h FileIO.h FileName.h MetaData.h Parallel.h PubFFT.h Range.h TextFormat.h DataSet_3D.o : DataSet_3D.cpp AssociatedData.h Box.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_3D.h Dimension.h FileIO.h FileName.h GridBin.h Matrix_3x3.h MetaData.h Parallel.h Range.h TextFormat.h Vec3.h DataSet_Cmatrix.o : DataSet_Cmatrix.cpp ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h Box.h ClusterDist.h ClusterSieve.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_1D.h DataSet_Cmatrix.h DataSet_Coords.h Dimension.h FileIO.h FileName.h Frame.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Topology.h TypeNameHolder.h Vec3.h From 70fc4d16d8ba3cf2753fa3ecf2b82496e6b69e5c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 14:28:41 -0400 Subject: [PATCH 08/87] Add DataIO class for writing peaks. --- src/DataIO_Peaks.cpp | 85 +++++++++++++++++++++++++++++++++++++ src/DataIO_Peaks.h | 17 ++++++++ src/DataSet_Vector_Scalar.h | 2 + 3 files changed, 104 insertions(+) create mode 100644 src/DataIO_Peaks.cpp create mode 100644 src/DataIO_Peaks.h diff --git a/src/DataIO_Peaks.cpp b/src/DataIO_Peaks.cpp new file mode 100644 index 0000000000..769e594f84 --- /dev/null +++ b/src/DataIO_Peaks.cpp @@ -0,0 +1,85 @@ +#include "DataIO_Peaks.h" +#include "CpptrajStdio.h" +#include "DataSet_Vector_Scalar.h" + +/// CONSTRUCTOR +DataIO_Peaks::DataIO_Peaks() +{ + SetValid( DataSet::VECTOR_SCALAR ); +} + +// DataIO_Peaks::ID_DataFormat() +bool DataIO_Peaks::ID_DataFormat(CpptrajFile& infile) +{ + + return false; +} + +// DataIO_Peaks::ReadHelp() +void DataIO_Peaks::ReadHelp() +{ + +} + +// DataIO_Peaks::processReadArgs() +int DataIO_Peaks::processReadArgs(ArgList& argIn) +{ + + return 0; +} + +// DataIO_Peaks::ReadData() +int DataIO_Peaks::ReadData(FileName const& fname, DataSetList& dsl, std::string const& dsname) +{ + + return 1; +} + +// DataIO_Peaks::WriteHelp() +void DataIO_Peaks::WriteHelp() +{ + +} + +// DataIO_Peaks::processWriteArgs() +int DataIO_Peaks::processWriteArgs(ArgList& argIn) +{ + + return 0; +} + +// DataIO_Peaks::WriteData() +int DataIO_Peaks::WriteData(FileName const& fname, DataSetList const& dsl) +{ + if (dsl.size() > 1) + mprintf("Warning: Writing multiple sets to peak file may result in invalid format.\n"); + CpptrajFile outfile; + // Loop over sets. Only write VECTOR_SCALAR sets. + for (DataSetList::const_iterator it = dsl.begin(); it != dsl.end(); ++it) + { + if ((*it)->Type() != DataSet::VECTOR_SCALAR) { + mprintf("Warning: Set '%s' is not vector with scalar, cannot be used for peaks file.\n", + (*it)->legend()); + } else { + DataSet_Vector_Scalar const& ds = static_cast( *(*it) ); + if (ds.Size() > 0) { + // Only open the file when a valid set is found to match old Action_Volmap behavior. + if (!outfile.IsOpen()) { + if (outfile.OpenWrite( fname )) { + mprinterr("Error: Could not open %s for write.\n", fname.full()); + return 1; + } + } + outfile.Printf("%zu\n\n", ds.Size()); + for (unsigned int i = 0; i < ds.Size(); i++) + { + Vec3 const& vxyz = ds.Vec(i); + outfile.Printf("C %16.8f %16.8f %16.8f %16.8f\n", + vxyz[0], vxyz[1], vxyz[2], ds.Val(i)); + } + } + } + } // END loop over sets. + + return 0; +} diff --git a/src/DataIO_Peaks.h b/src/DataIO_Peaks.h new file mode 100644 index 0000000000..07ecd3ca3a --- /dev/null +++ b/src/DataIO_Peaks.h @@ -0,0 +1,17 @@ +#ifndef INC_DATAIO_PEAKS_H +#define INC_DATAIO_PEAKS_H +#include "DataIO.h" +/// +class DataIO_Peaks : public DataIO { + public: + DataIO_Peaks(); + static void ReadHelp(); + static void WriteHelp(); + static BaseIOtype* Alloc() { return (BaseIOtype*)new DataIO_Peaks(); } + int processReadArgs(ArgList&); + int ReadData(FileName const&, DataSetList&, std::string const&); + int processWriteArgs(ArgList&); + int WriteData(FileName const&, DataSetList const&); + bool ID_DataFormat(CpptrajFile&); +}; +#endif diff --git a/src/DataSet_Vector_Scalar.h b/src/DataSet_Vector_Scalar.h index af2621cf8d..1f56fa9018 100644 --- a/src/DataSet_Vector_Scalar.h +++ b/src/DataSet_Vector_Scalar.h @@ -19,6 +19,8 @@ class DataSet_Vector_Scalar : public DataSet { int Sync(size_t, std::vector const&, Parallel::Comm const&); # endif // ------------------------------------------- + Vec3 const& Vec(unsigned int i) const { return vecs_[i]; } + double Val(unsigned int i) const { return vals_[i]; } private: typedef std::vector Varray; typedef std::vector Darray; From b32d201b105821427cbd48626479ca061a5413d6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 14:32:13 -0400 Subject: [PATCH 09/87] Enable peaks file output --- src/DataFile.cpp | 3 +++ src/DataFile.h | 2 +- src/cpptrajdepend | 3 ++- src/cpptrajfiles | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/DataFile.cpp b/src/DataFile.cpp index 3fefcf445a..d2bc53af56 100644 --- a/src/DataFile.cpp +++ b/src/DataFile.cpp @@ -28,6 +28,7 @@ #include "DataIO_CharmmOutput.h" #include "DataIO_Cpout.h" #include "DataIO_CharmmRtfPrm.h" +#include "DataIO_Peaks.h" // CONSTRUCTOR DataFile::DataFile() : @@ -73,6 +74,7 @@ const FileTypes::AllocToken DataFile::DF_AllocArray[] = { { "CHARMM Output", 0, 0, DataIO_CharmmOutput::Alloc}, { "Amber CPOUT", DataIO_Cpout::ReadHelp, DataIO_Cpout::WriteHelp, DataIO_Cpout::Alloc}, { "CHARMM RTF/PRM", 0, 0, DataIO_CharmmRtfPrm::Alloc }, + { "Peaks", 0, 0, DataIO_Peaks::Alloc }, { "Unknown Data file", 0, 0, 0 } }; @@ -113,6 +115,7 @@ const FileTypes::KeyToken DataFile::DF_WriteKeyArray[] = { { NCCMATRIX, "nccmatrix", ".nccmatrix" }, { CPOUT, "cpout", ".cpout" }, { CHARMMRTFPRM, "charmmrtfprm", ".prm" }, + { PEAKS, "peaks", ".peaks" }, { UNKNOWN_DATA, 0, 0 } }; diff --git a/src/DataFile.h b/src/DataFile.h index 4da2653e06..0517c00774 100644 --- a/src/DataFile.h +++ b/src/DataFile.h @@ -17,7 +17,7 @@ class DataFile { enum DataFormatType { DATAFILE=0, XMGRACE, GNUPLOT, XPLOR, OPENDX, REMLOG, MDOUT, EVECS, VECTRAJ, XVG, CCP4, CMATRIX, NCCMATRIX, CHARMMREPD, CHARMMFASTREP, - CHARMMOUT, CPOUT, CHARMMRTFPRM, UNKNOWN_DATA + CHARMMOUT, CPOUT, CHARMMRTFPRM, PEAKS, UNKNOWN_DATA }; DataFile(); ~DataFile(); diff --git a/src/cpptrajdepend b/src/cpptrajdepend index ce24bc5cbd..e44dfde9f2 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -169,7 +169,7 @@ CpptrajFile.o : CpptrajFile.cpp CpptrajFile.h CpptrajStdio.h FileIO.h FileIO_Bzi CpptrajState.o : CpptrajState.cpp Action.h ActionList.h ActionState.h Action_CreateCrd.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h DataSet_Coords_TRJ.h DataSet_Topology.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleNavigator.h EnsembleOutList.h FileIO.h FileName.h FileTypes.h Frame.h FrameArray.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h TrajFrameIndex.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Vec3.h CpptrajStdio.o : CpptrajStdio.cpp Parallel.h CurveFit.o : CurveFit.cpp CurveFit.h -DataFile.o : DataFile.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h ClusterDist.h ClusterSieve.h Constants.h CoordinateInfo.h Cph.h CpptrajFile.h CpptrajStdio.h DataFile.h DataIO.h DataIO_CCP4.h DataIO_CharmmFastRep.h DataIO_CharmmOutput.h DataIO_CharmmRepLog.h DataIO_CharmmRtfPrm.h DataIO_Cmatrix.h DataIO_Cpout.h DataIO_Evecs.h DataIO_Gnuplot.h DataIO_Grace.h DataIO_Mdout.h DataIO_NC_Cmatrix.h DataIO_OpenDx.h DataIO_RemLog.h DataIO_Std.h DataIO_VecTraj.h DataIO_XVG.h DataIO_Xplor.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Cmatrix.h DataSet_Cmatrix_MEM.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_RemLog.h Dimension.h FileIO.h FileName.h FileTypes.h Frame.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Cmatrix.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TrajectoryFile.h TypeNameHolder.h Vec3.h +DataFile.o : DataFile.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h ClusterDist.h ClusterSieve.h Constants.h CoordinateInfo.h Cph.h CpptrajFile.h CpptrajStdio.h DataFile.h DataIO.h DataIO_CCP4.h DataIO_CharmmFastRep.h DataIO_CharmmOutput.h DataIO_CharmmRepLog.h DataIO_CharmmRtfPrm.h DataIO_Cmatrix.h DataIO_Cpout.h DataIO_Evecs.h DataIO_Gnuplot.h DataIO_Grace.h DataIO_Mdout.h DataIO_NC_Cmatrix.h DataIO_OpenDx.h DataIO_Peaks.h DataIO_RemLog.h DataIO_Std.h DataIO_VecTraj.h DataIO_XVG.h DataIO_Xplor.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Cmatrix.h DataSet_Cmatrix_MEM.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_RemLog.h Dimension.h FileIO.h FileName.h FileTypes.h Frame.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Cmatrix.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TrajectoryFile.h TypeNameHolder.h Vec3.h DataFileList.o : DataFileList.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h PDBfile.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO.o : DataIO.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_CCP4.o : DataIO_CCP4.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h ByteRoutines.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_CCP4.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridFlt.h Dimension.h FileIO.h FileName.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h @@ -185,6 +185,7 @@ DataIO_Grace.o : DataIO_Grace.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h DataIO_Mdout.o : DataIO_Mdout.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Mdout.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_NC_Cmatrix.o : DataIO_NC_Cmatrix.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterDist.h ClusterSieve.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_NC_Cmatrix.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Cmatrix.h DataSet_Cmatrix_MEM.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h FileIO.h FileName.h Frame.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Cmatrix.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_OpenDx.o : DataIO_OpenDx.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_OpenDx.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridFlt.h Dimension.h FileIO.h FileName.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h +DataIO_Peaks.o : DataIO_Peaks.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Peaks.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector_Scalar.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_RemLog.o : DataIO_RemLog.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_RemLog.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_RemLog.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_Std.o : DataIO_Std.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h ClusterDist.h ClusterSieve.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Std.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Cmatrix.h DataSet_Cmatrix_MEM.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Mat3x3.h DataSet_Vector.h DataSet_double.h DataSet_float.h DataSet_integer.h DataSet_string.h Dimension.h FileIO.h FileName.h Frame.h GridBin.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_VecTraj.o : DataIO_VecTraj.cpp ActionFrameCounter.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h BondSearch.h Box.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_VecTraj.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector.h Dimension.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ParmIO.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Vec3.h diff --git a/src/cpptrajfiles b/src/cpptrajfiles index e3e959ff38..f9c9aab161 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -184,6 +184,7 @@ COMMON_SOURCES= \ DataIO_Gnuplot.cpp \ DataIO_Grace.cpp \ DataIO_OpenDx.cpp \ + DataIO_Peaks.cpp \ DataIO_Mdout.cpp \ DataIO_NC_Cmatrix.cpp \ DataIO_RemLog.cpp \ From 3fbd38880f607c4678f5992704b28a90c5be042f Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 14:32:28 -0400 Subject: [PATCH 10/87] Use vector scalar data to store peaks, write to data file. --- src/Action_Volmap.cpp | 46 ++++++++++++++++++++++++++++++------------- src/Action_Volmap.h | 3 ++- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 1aaff46c4b..050ba32f9e 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -8,6 +8,7 @@ #endif const double Action_Volmap::sqrt_8_pi_cubed = sqrt(8.0*Constants::PI*Constants::PI*Constants::PI); + // CONSTRUCTOR Action_Volmap::Action_Volmap() : radiiType_(UNSPECIFIED), @@ -22,6 +23,7 @@ Action_Volmap::Action_Volmap() : spheremode_(false), grid_(0), peakfile_(0), + peakdata_(0), peakcut_(0.05), buffer_(3.0), radscale_(1.0), @@ -58,7 +60,6 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d # endif // Get specific keywords peakcut_ = actionArgs.getKeyDouble("peakcut", 0.05); - peakfile_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("peakfile"), "Volmap Peaks"); spheremode_ = actionArgs.hasKey("sphere"); radscale_ = 1.0; stepfac_ = 4.1; @@ -207,6 +208,25 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d outfilename = actionArgs.GetStringNext(); // Backwards compat. DataFile* outfile = init.DFL().AddDataFile( outfilename, actionArgs ); if (outfile != 0) outfile->AddDataSet( grid_ ); + // See if peaks are being determined + peakfile_ = 0; + std::string pfilename = actionArgs.GetStringKey("peakfile"); + if (!pfilename.empty()) { + peakfile_ = init.DFL().AddDataFile(pfilename, actionArgs); + if (peakfile_ == 0) { + mprinterr("Error: Unable to allocate peak file.\n"); + return Action::ERR; + } + peakdata_ = init.DSL().AddSet(DataSet::VECTOR_SCALAR, MetaData(grid_->Meta().Name(), "peaks")); + if (peakdata_ == 0) { + mprinterr("Error: Unable to allocate peak data set.\n"); + return Action::ERR; + } +# ifdef MPI + peakdata_->SetNeedsSync( false ); +# endif + peakfile_->AddDataSet( peakdata_ ); + } // Create total volume set total_volume_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(grid_->Meta().Name(), "totalvol")); if (total_volume_ == 0) return Action::ERR; @@ -249,8 +269,8 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tGrid dataset name is '%s'\n", grid_->legend()); mprintf("\tTotal grid volume dataset name is '%s'\n", total_volume_->legend()); if (peakfile_ != 0) - mprintf("\tDensity peaks above %.3f will be printed to %s in XYZ-format\n", - peakcut_, peakfile_->Filename().full()); + mprintf("\tDensity peaks above %.3f will be saved to %s and printed to %s in XYZ-format\n", + peakcut_, peakdata_->legend(), peakfile_->DataFilename().full()); # ifdef _OPENMP if (GRID_THREAD_.size() > 1) mprintf("\tParallelizing calculation with %zu threads.\n", GRID_THREAD_.size()); @@ -541,28 +561,26 @@ void Action_Volmap::Print() { } } int npeaks = 0; - std::vector peakdata; + //std::vector peakdata; + double pbuf[4]; for (size_t i = 0; i < peakgrid.NX(); i++) for (size_t j = 0; j < peakgrid.NY(); j++) for (size_t k = 0; k < peakgrid.NZ(); k++) { double gval = peakgrid.element(i, j, k); if (gval > 0) { - npeaks++; - peakdata.push_back(xmin_+dx_*i); - peakdata.push_back(ymin_+dy_*j); - peakdata.push_back(zmin_+dz_*k); - peakdata.push_back(gval); + //npeaks++; + //peakdata.push_back(xmin_+dx_*i); + //peakdata.push_back(ymin_+dy_*j); + //peakdata.push_back(zmin_+dz_*k); + //peakdata.push_back(gval); + peakdata_->Add(npeaks++, pbuf); } } // If we have peaks, open up our peak data and print it if (npeaks > 0) { - peakfile_->Printf("%d\n\n", npeaks); - for (int i = 0; i < npeaks; i++) - peakfile_->Printf("C %16.8f %16.8f %16.8f %16.8f\n", peakdata[4*i], - peakdata[4*i+1], peakdata[4*i+2], peakdata[4*i+3]); mprintf("Volmap: %d density peaks found with higher density than %.4lf\n", npeaks, peakcut_); - }else{ + } else { mprintf("No peaks found with a density greater than %.3lf\n", peakcut_); } } diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index 5103c3c076..de030af4c1 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -32,7 +32,8 @@ class Action_Volmap : public Action { AtomMask densitymask_; ///< Max of atoms to grid. DataSet_GridFlt* grid_; ///< Hold the grid. DataSet* total_volume_; ///< Hold total grid volume. - CpptrajFile* peakfile_; ///< file name with the peak locations as Carbons in XYZ file format + DataFile* peakfile_; ///< file name with the peak locations as Carbons in XYZ file format + DataSet* peakdata_; ///< Data set holding peak locations along with densities double peakcut_; ///< The value below which to ignore all peaks std::vector Atoms_; ///< Atoms with radii > 0.0 std::vector halfradii_; ///< 1/2 the atomic radii of each atom in the gridded selection From e0cd074bce0dfb8969b8c9f555da242431ffa1b1 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 14:41:34 -0400 Subject: [PATCH 11/87] Make the vector scalar set 0 dimension so it is forced to use the DataIO_Peaks format. May want to do this in a less hacky way in the future. --- src/Action_Volmap.cpp | 6 +++++- src/DataSet_Vector_Scalar.cpp | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 050ba32f9e..12ab74efbb 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -573,10 +573,14 @@ void Action_Volmap::Print() { //peakdata.push_back(ymin_+dy_*j); //peakdata.push_back(zmin_+dz_*k); //peakdata.push_back(gval); + pbuf[0] = xmin_+dx_*(double)i; + pbuf[1] = ymin_+dy_*(double)j; + pbuf[2] = zmin_+dz_*(double)k; + pbuf[3] = gval; peakdata_->Add(npeaks++, pbuf); } } - // If we have peaks, open up our peak data and print it + // Report on how many peaks found. if (npeaks > 0) { mprintf("Volmap: %d density peaks found with higher density than %.4lf\n", npeaks, peakcut_); diff --git a/src/DataSet_Vector_Scalar.cpp b/src/DataSet_Vector_Scalar.cpp index 2f94e038c1..351eaf2cec 100644 --- a/src/DataSet_Vector_Scalar.cpp +++ b/src/DataSet_Vector_Scalar.cpp @@ -4,7 +4,10 @@ /// CONSTRUCTOR TODO should this be in VECTOR_1D group? DataSet_Vector_Scalar::DataSet_Vector_Scalar() : - DataSet(VECTOR_SCALAR, GENERIC, TextFormat(TextFormat::DOUBLE, 8, 4, 4), 1) + // TODO marking this as 0-dimension so that it is forced to use + // the DataIO_Peaks format, but may want to change this down the + // road. + DataSet(VECTOR_SCALAR, GENERIC, TextFormat(TextFormat::DOUBLE, 8, 4, 4), 0) { } /** Reserve space in vector array. */ From 5bde717e7290ba89c33fb8e2e6406c9a380bcd2b Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 15:21:38 -0400 Subject: [PATCH 12/87] Re-organize branches in volmap loop to avoid some unnecessary calculation. Slightly more efficient (1-2%) and avoids using a 'continue'. --- src/Action_Volmap.cpp | 82 +++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 12ab74efbb..eba9b5f8bc 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -420,48 +420,52 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { # endif for (midx = 0; midx < maxidx; midx++) { double rhalf = (double)halfradii_[midx]; - double rcut2; - if (spheremode_) - rcut2 = rhalf*rhalf; - else - rcut2 = 99999999.0; - atom = Atoms_[midx]; - Vec3 pt = Vec3(frm.Frm().XYZ(atom)); - int ix = (int) ( floor( (pt[0]-xmin_) / dx_ + 0.5 ) ); + double rcut2; + if (spheremode_) + rcut2 = rhalf*rhalf; + else + rcut2 = 99999999.0; + atom = Atoms_[midx]; + Vec3 pt = Vec3(frm.Frm().XYZ(atom)); + int ix = (int) ( floor( (pt[0]-xmin_) / dx_ + 0.5 ) ); + /* See how many steps in X dimension we smear out our Gaussian. This + * formula is taken to be consistent with VMD's volmap tool. + */ + int nxstep = (int) ceil(stepfac_ * rhalf / dx_); + if (ix >= -nxstep && ix <= nX + nxstep) { int iy = (int) ( floor( (pt[1]-ymin_) / dy_ + 0.5 ) ); - int iz = (int) ( floor( (pt[2]-zmin_) / dz_ + 0.5 ) ); - /* See how many steps in each dimension we smear out our Gaussian. This - * formula is taken to be consistent with VMD's volmap tool - */ - int nxstep = (int) ceil(stepfac_ * rhalf / dx_); + // See how many steps in Y dim we smear out Gaussian. int nystep = (int) ceil(stepfac_ * rhalf / dy_); - int nzstep = (int) ceil(stepfac_ * rhalf / dz_); - if (ix < -nxstep || ix > nX + nxstep || - iy < -nystep || iy > nY + nystep || - iz < -nzstep || iz > nZ + nzstep) - continue; - // Calculate the gaussian normalization factor (in 3 dimensions with the - // given half-radius) - double norm = 1 / (sqrt_8_pi_cubed * rhalf*rhalf*rhalf); - double exfac = -1.0 / (2.0 * rhalf * rhalf); - //mprintf("DBG: Atom %i norm %g exfac %g\n", atom+1, norm, exfac); + if (iy >= -nystep && iy <= nY + nystep) { + int iz = (int) ( floor( (pt[2]-zmin_) / dz_ + 0.5 ) ); + // See how many steps in Z dim we smear out Gaussian. + int nzstep = (int) ceil(stepfac_ * rhalf / dz_); + if (iz >= -nzstep && iz <= nZ + nzstep) { + // Calculate the gaussian normalization factor (in 3 dimensions with the + // given half-radius) + double norm = 1 / (sqrt_8_pi_cubed * rhalf*rhalf*rhalf); + double exfac = -1.0 / (2.0 * rhalf * rhalf); + //mprintf("DBG: Atom %i norm %g exfac %g\n", atom+1, norm, exfac); - int xend = std::min(ix+nxstep, nX); - int yend = std::min(iy+nystep, nY); - int zend = std::min(iz+nzstep, nZ); - for (int xval = std::max(ix-nxstep, 0); xval < xend; xval++) - for (int yval = std::max(iy-nystep, 0); yval < yend; yval++) - for (int zval = std::max(iz-nzstep, 0); zval < zend; zval++) { - Vec3 gridpt = Vec3(xmin_+xval*dx_, ymin_+yval*dy_, zmin_+zval*dz_) - pt; - double dist2 = gridpt.Magnitude2(); - if (dist2 < rcut2) { -# ifdef _OPENMP - GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); -# else - grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); -# endif - } - } + int xend = std::min(ix+nxstep, nX); + int yend = std::min(iy+nystep, nY); + int zend = std::min(iz+nzstep, nZ); + for (int xval = std::max(ix-nxstep, 0); xval < xend; xval++) + for (int yval = std::max(iy-nystep, 0); yval < yend; yval++) + for (int zval = std::max(iz-nzstep, 0); zval < zend; zval++) { + Vec3 gridpt = Vec3(xmin_+xval*dx_, ymin_+yval*dy_, zmin_+zval*dz_) - pt; + double dist2 = gridpt.Magnitude2(); + if (dist2 < rcut2) { +# ifdef _OPENMP + GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); +# else + grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); +# endif + } + } // END loop over zval + } // END z dim is valid + } // END y dim is valid + } // END x dim is valid } // END loop over atoms in densitymask_ # ifdef _OPENMP } // END pragma omp parallel From 9e8ef9c383e9a6acdedc5d08d8d593afc39884d8 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 16:44:49 -0400 Subject: [PATCH 13/87] A line with no elements cannot be a Tinker atom line --- src/TinkerFile.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TinkerFile.cpp b/src/TinkerFile.cpp index ba492cf717..a83ad40cab 100644 --- a/src/TinkerFile.cpp +++ b/src/TinkerFile.cpp @@ -31,6 +31,7 @@ static inline int SetNatomAndTitle(ArgList& lineIn, int& natom, std::string& tit } static inline bool IsAtomLine(ArgList& lineIn) { + if (lineIn.Nargs() < 1) return false; for (int i = 0; i < lineIn.Nargs(); i++) { std::string item = lineIn.GetStringNext(); if (i == 0 || i >= 5) { From 3214e3279d90b2f2fd611ed0747e3ba5f3d9c03c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 16:57:01 -0400 Subject: [PATCH 14/87] Start adding code to read the peaks file. --- src/DataFile.cpp | 1 + src/DataIO_Peaks.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/DataFile.cpp b/src/DataFile.cpp index d2bc53af56..ea66efd685 100644 --- a/src/DataFile.cpp +++ b/src/DataFile.cpp @@ -96,6 +96,7 @@ const FileTypes::KeyToken DataFile::DF_KeyArray[] = { { CHARMMREPD, "charmmrepd",".exch" }, { CHARMMOUT, "charmmout", ".charmmout"}, { CHARMMRTFPRM, "charmmrtfprm", ".rtfprm"}, + { PEAKS, "peaks", ".peaks" }, { UNKNOWN_DATA, 0, 0 } }; diff --git a/src/DataIO_Peaks.cpp b/src/DataIO_Peaks.cpp index 769e594f84..a9e83ab643 100644 --- a/src/DataIO_Peaks.cpp +++ b/src/DataIO_Peaks.cpp @@ -1,6 +1,7 @@ #include "DataIO_Peaks.h" #include "CpptrajStdio.h" #include "DataSet_Vector_Scalar.h" +#include "StringRoutines.h" /// CONSTRUCTOR DataIO_Peaks::DataIO_Peaks() @@ -11,7 +12,30 @@ DataIO_Peaks::DataIO_Peaks() // DataIO_Peaks::ID_DataFormat() bool DataIO_Peaks::ID_DataFormat(CpptrajFile& infile) { - + if (infile.OpenFile()) return false; + std::string firstLine = NoTrailingWhitespace(infile.GetLine()); + std::string secondLine = NoTrailingWhitespace(infile.GetLine()); + std::string thirdLine = infile.GetLine(); + mprintf("DEBUG: ID peaks.\n"); + mprintf("'%s'\n", firstLine.c_str()); + mprintf("'%s'\n", secondLine.c_str()); + mprintf("'%s'\n", thirdLine.c_str()); + infile.CloseFile(); + if (validInteger(firstLine)) { + mprintf("DEBUG: Line 1 int.\n"); + if (secondLine.empty()) { + mprintf("DEBUG: Line 2 empty.\n"); + ArgList line3(thirdLine); + if (line3.Nargs() == 5) { + if (line3[0] == "C") { + for (int col = 1; col < 5; col++) + if (!validDouble(line3[col])) return false; + mprintf("DEBUG: Line 3 C and 4 doubles.\n"); + return true; + } + } + } + } return false; } From 7cf6a975f0f66bb01201be608fcfde8bb905d5da Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 4 Jun 2020 16:58:03 -0400 Subject: [PATCH 15/87] Remove some debug info --- src/DataIO_Peaks.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/DataIO_Peaks.cpp b/src/DataIO_Peaks.cpp index a9e83ab643..c6f325ef14 100644 --- a/src/DataIO_Peaks.cpp +++ b/src/DataIO_Peaks.cpp @@ -16,21 +16,21 @@ bool DataIO_Peaks::ID_DataFormat(CpptrajFile& infile) std::string firstLine = NoTrailingWhitespace(infile.GetLine()); std::string secondLine = NoTrailingWhitespace(infile.GetLine()); std::string thirdLine = infile.GetLine(); - mprintf("DEBUG: ID peaks.\n"); - mprintf("'%s'\n", firstLine.c_str()); - mprintf("'%s'\n", secondLine.c_str()); - mprintf("'%s'\n", thirdLine.c_str()); + //mprintf("DEBUG: ID peaks.\n"); + //mprintf("'%s'\n", firstLine.c_str()); + //mprintf("'%s'\n", secondLine.c_str()); + //mprintf("'%s'\n", thirdLine.c_str()); infile.CloseFile(); if (validInteger(firstLine)) { - mprintf("DEBUG: Line 1 int.\n"); + //mprintf("DEBUG: Line 1 int.\n"); if (secondLine.empty()) { - mprintf("DEBUG: Line 2 empty.\n"); + //mprintf("DEBUG: Line 2 empty.\n"); ArgList line3(thirdLine); if (line3.Nargs() == 5) { if (line3[0] == "C") { for (int col = 1; col < 5; col++) if (!validDouble(line3[col])) return false; - mprintf("DEBUG: Line 3 C and 4 doubles.\n"); + //mprintf("DEBUG: Line 3 C and 4 doubles.\n"); return true; } } From c82f3f7034c41335d5b97ddab6fd2134f0c82822 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 13:48:26 -0400 Subject: [PATCH 16/87] Add peaks read. --- src/DataIO_Peaks.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/DataIO_Peaks.cpp b/src/DataIO_Peaks.cpp index c6f325ef14..38b4f78cdf 100644 --- a/src/DataIO_Peaks.cpp +++ b/src/DataIO_Peaks.cpp @@ -55,8 +55,53 @@ int DataIO_Peaks::processReadArgs(ArgList& argIn) // DataIO_Peaks::ReadData() int DataIO_Peaks::ReadData(FileName const& fname, DataSetList& dsl, std::string const& dsname) { + // Figure out the data set + unsigned int npeaks = 0; + DataSet* ds = dsl.CheckForSet( dsname ); + if (ds == 0) { + // New set + ds = dsl.AddSet( DataSet::VECTOR_SCALAR, dsname, "peaks" ); + if (ds == 0) return 1; + } else { + // Appending. + if (ds->Type() != DataSet::VECTOR_SCALAR) { + mprinterr("Error: Set '%s' is not vector with scalar, cannot append peaks to it.\n", + ds->legend()); + return 1; + } + npeaks = ds->Size(); + mprintf("\tAppending peaks to set '%s', offset %u\n", ds->legend(), npeaks); + } + // Parse through the peaks file and extract the peaks + CpptrajFile peakfile; + if (peakfile.OpenRead(fname)) { + mprinterr("Error: Could not open %s for reading!\n", fname.full()); + return 1; + } + std::string line = peakfile.GetLine(); + int peaknum = 0; + while (!line.empty()) { + if (sscanf(line.c_str(), "%d", &peaknum) != 1) { + line = peakfile.GetLine(); + continue; + } + line = peakfile.GetLine(); + break; + } + while (!line.empty()) { + double pbuf[4]; + if (sscanf(line.c_str(), "C %lg %lg %lg %lg", pbuf, pbuf+1, pbuf+2, pbuf+3) != 4) { + mprintf("Warning: Unexpected format for line, skipping: '%s'\n", + NoTrailingWhitespace(line).c_str()); + line = peakfile.GetLine(); + continue; + } + line = peakfile.GetLine(); + ds->Add(npeaks++, pbuf); + } + peakfile.CloseFile(); - return 1; + return 0; } // DataIO_Peaks::WriteHelp() From cfb6abffb517d6f43d74d81779b838a9a9984ebe Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 13:58:21 -0400 Subject: [PATCH 17/87] Rewrite peaks read to make it more strict. Must conform to what ID_DataFormat expects. --- src/DataIO_Peaks.cpp | 52 +++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/DataIO_Peaks.cpp b/src/DataIO_Peaks.cpp index 38b4f78cdf..3bf7c5eabc 100644 --- a/src/DataIO_Peaks.cpp +++ b/src/DataIO_Peaks.cpp @@ -2,6 +2,7 @@ #include "CpptrajStdio.h" #include "DataSet_Vector_Scalar.h" #include "StringRoutines.h" +#include // sscanf /// CONSTRUCTOR DataIO_Peaks::DataIO_Peaks() @@ -56,7 +57,7 @@ int DataIO_Peaks::processReadArgs(ArgList& argIn) int DataIO_Peaks::ReadData(FileName const& fname, DataSetList& dsl, std::string const& dsname) { // Figure out the data set - unsigned int npeaks = 0; + unsigned int peakidx = 0; DataSet* ds = dsl.CheckForSet( dsname ); if (ds == 0) { // New set @@ -69,8 +70,8 @@ int DataIO_Peaks::ReadData(FileName const& fname, DataSetList& dsl, std::string ds->legend()); return 1; } - npeaks = ds->Size(); - mprintf("\tAppending peaks to set '%s', offset %u\n", ds->legend(), npeaks); + peakidx = ds->Size(); + mprintf("\tAppending peaks to set '%s', offset %u\n", ds->legend(), peakidx); } // Parse through the peaks file and extract the peaks CpptrajFile peakfile; @@ -78,28 +79,39 @@ int DataIO_Peaks::ReadData(FileName const& fname, DataSetList& dsl, std::string mprinterr("Error: Could not open %s for reading!\n", fname.full()); return 1; } - std::string line = peakfile.GetLine(); - int peaknum = 0; - while (!line.empty()) { - if (sscanf(line.c_str(), "%d", &peaknum) != 1) { - line = peakfile.GetLine(); - continue; - } - line = peakfile.GetLine(); - break; + // FORMAT: + // Line 1 : # peaks + int npeaks_in_file = 0; + const char* ptr = peakfile.NextLine(); + if (ptr == 0) { + mprinterr("Error: Unexpected EOF when reading # peaks..\n"); + return 1; } - while (!line.empty()) { - double pbuf[4]; - if (sscanf(line.c_str(), "C %lg %lg %lg %lg", pbuf, pbuf+1, pbuf+2, pbuf+3) != 4) { + if (sscanf(ptr, "%i", &npeaks_in_file) != 1) { + mprinterr("Error: Could not read number of peaks in file.\n"); + return 1; + } + mprintf("\tAttempting to read %i peaks.\n", npeaks_in_file); + // Line 2 : Blank + ptr = peakfile.NextLine(); + // Line 3-X : C + int npeaks_read = 0; + ptr = peakfile.NextLine(); + double pbuf[4]; + while (ptr != 0) { + if (sscanf(ptr, "C %lg %lg %lg %lg", pbuf, pbuf+1, pbuf+2, pbuf+3) != 4) { mprintf("Warning: Unexpected format for line, skipping: '%s'\n", - NoTrailingWhitespace(line).c_str()); - line = peakfile.GetLine(); - continue; + NoTrailingWhitespace(std::string(ptr)).c_str()); + } else { + npeaks_read++; + ds->Add(peakidx++, pbuf); } - line = peakfile.GetLine(); - ds->Add(npeaks++, pbuf); + ptr = peakfile.NextLine(); } peakfile.CloseFile(); + mprintf("\tRead %i peaks.\n", npeaks_read); + if (npeaks_read != npeaks_in_file) + mprintf("Warning: Expected %i peaks, actually got %i peaks.\n", npeaks_in_file, npeaks_read); return 0; } From 08dc480ae18eac4c5c2f6fbf66e7a2ccedef5783 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 14:31:26 -0400 Subject: [PATCH 18/87] Use DataSet/DataFile framework for peaks in SPAM --- src/Action_Spam.cpp | 119 +++++++++++++++++++++++--------------------- src/Action_Spam.h | 6 ++- src/cpptrajdepend | 4 +- 3 files changed, 69 insertions(+), 60 deletions(-) diff --git a/src/Action_Spam.cpp b/src/Action_Spam.cpp index 02bbd92b26..5b70ceb99c 100644 --- a/src/Action_Spam.cpp +++ b/src/Action_Spam.cpp @@ -12,6 +12,8 @@ #include "KDE.h" #include "OnlineVarT.h" // Stats #include "DataSet_Mesh.h" +#include "DataSet_Vector_Scalar.h" +#include "DataIO_Peaks.h" // CONSTRUCTOR Action_Spam::Action_Spam() : @@ -32,9 +34,43 @@ Action_Spam::Action_Spam() : ds_dh_(0), ds_ds_(0), Nframes_(0), - overflow_(false) + overflow_(false), + peaksData_(0) { } +/** Search for DataSet with peaks data. If that fails, try to load peaks + * from a file. + */ +int Action_Spam::GetPeaks(std::string const& name, DataSetList const& dsl) +{ + // Check for peaks DataSet. + DataSet* ds = dsl.FindSetOfType(name, DataSet::VECTOR_SCALAR); + if (ds == 0) { + // No set found. See if file exists. + FileName fname(name); + if (!File::Exists(fname)) { + File::ErrorMsg( fname.full() ); + mprinterr("Error: No peak data or file with name '%s'.\n", name.c_str()); + return 1; + } + // Try to load peaks from file. + DataIO_Peaks infile; + if (infile.ReadData(fname, peaksdsl_, fname.Base())) { + mprinterr("Error: Could not load peaks data from %s\n", fname.full()); + return 1; + } + // Sanity check + if (peaksdsl_.size() < 1 || peaksdsl_[0]->Type() != DataSet::VECTOR_SCALAR) { + mprinterr("Error: Could not allocate peaks data set for file.\n"); + return 1; + } + peaksData_ = (DataSet_Vector_Scalar*)peaksdsl_[0]; + } else { + peaksData_ = (DataSet_Vector_Scalar*)ds; + } + return 0; +} + void Action_Spam::Help() const { mprintf("\t[name ] [out ] [cut ] [solv ]\n" "\t{ purewater |\n" @@ -71,7 +107,7 @@ Action::RetType Action_Spam::Init(ArgList& actionArgs, ActionInit& init, int deb // Always use imaged distances image_.InitImaging(true); // This is needed everywhere in this function scope - FileName filename; + std::string peaksname; // See if we're doing pure water. If so, we don't need a peak file purewater_ = actionArgs.hasKey("purewater"); @@ -109,13 +145,10 @@ Action::RetType Action_Spam::Init(ArgList& actionArgs, ActionInit& init, int deb DG_BULK_ = 0.0; DH_BULK_ = 0.0; } else { - // Get the file name with the peaks defined in it - filename.SetFileName( actionArgs.GetStringNext() ); - if (filename.empty()) { - mprinterr("Error: No Peak file specified.\n"); - return Action::ERR; - } else if (!File::Exists(filename)) { - File::ErrorMsg( filename.full() ); + // Get the file/dataset name with the peaks defined in it + peaksname = actionArgs.GetStringNext(); + if (peaksname.empty()) { + mprinterr("Error: No Peak dataset/file specified.\n"); return Action::ERR; } // Get the remaining optional arguments @@ -139,39 +172,13 @@ Action::RetType Action_Spam::Init(ArgList& actionArgs, ActionInit& init, int deb // If it's a sphere, square the radius to compare with if (sphere_) site_size_ *= site_size_; - // Parse through the peaks file and extract the peaks - CpptrajFile peakfile; - if (peakfile.OpenRead(filename)) { - mprinterr("SPAM: Error: Could not open %s for reading!\n", filename.full()); + // Get or load the peaks data + if (GetPeaks(peaksname, init.DSL())) { + mprinterr("Error: Could not get peaks.\n"); return Action::ERR; } - std::string line = peakfile.GetLine(); - int npeaks = 0; - while (!line.empty()) { - if (sscanf(line.c_str(), "%d", &npeaks) != 1) { - line = peakfile.GetLine(); - continue; - } - line = peakfile.GetLine(); - break; - } - while (!line.empty()) { - double x, y, z, dens; - if (sscanf(line.c_str(), "C %lg %lg %lg %lg", &x, &y, &z, &dens) != 4) { - line = peakfile.GetLine(); - continue; - } - line = peakfile.GetLine(); - peaks_.push_back(Vec3(x, y, z)); - } - peakfile.CloseFile(); - // Check that our initial number of peaks matches our parsed peaks. Warn - // otherwise - if (npeaks != (int)peaks_.size()) - mprinterr("SPAM: Warning: %s claims to have %d peaks, but really has %zu!\n", - filename.full(), npeaks, peaks_.size()); // Now add all of the individual peak energy data sets - for (int i = 0; i < (int)peaks_.size(); i++) { + for (unsigned int i = 0; i < peaksData_->Size(); i++) { DataSet* ds = init.DSL().AddSet(DataSet::DOUBLE, MetaData(ds_name,i+1)); if (ds == 0) return Action::ERR; myDSL_.push_back( ds ); @@ -198,7 +205,7 @@ Action::RetType Action_Spam::Init(ArgList& actionArgs, ActionInit& init, int deb # endif // peakFrameData will keep track of omitted frames for each peak. peakFrameData_.clear(); - peakFrameData_.resize( peaks_.size() ); + peakFrameData_.resize( peaksData_->Size() ); } // Determine if energy calculation needs to happen calcEnergy_ = (summaryfile != 0 || datafile != 0); @@ -223,10 +230,8 @@ Action::RetType Action_Spam::Init(ArgList& actionArgs, ActionInit& init, int deb mprintf("\tPrinting solvent SPAM summary to %s\n", summaryfile->DataFilename().full()); } else { - mprintf("\tSolvent [%s] density peaks taken from %s.\n", - solvname_.c_str(), filename.base()); - mprintf("\t%zu density peaks will be analyzed from %s.\n", - peaks_.size(), filename.base()); + mprintf("\tSolvent [%s], %zu density peaks taken from %s.\n", + solvname_.c_str(), peaksData_->Size(), peaksData_->legend()); mprintf("\tOccupation information printed to %s.\n", infofile_->Filename().full()); mprintf("\tSites are "); if (sphere_) @@ -536,17 +541,17 @@ Action::RetType Action_Spam::DoSPAM(int frameNum, Frame& frameIn) { t_assign_.Start(); // Loop through each peak and then scan through every residue, and assign a // solvent residue to each peak - int pknum = 0; - for (Varray::const_iterator pk = peaks_.begin(); pk != peaks_.end(); ++pk, ++pknum) + for (unsigned int pknum = 0; pknum < peaksData_->Size(); pknum++) { + Vec3 const& pk = peaksData_->Vec( pknum ); for (unsigned int resnum = 0; resnum != comlist_.size(); resnum++) { // If we're inside, make sure this residue is not already `claimed'. If it // is, assign it to the closer peak center - if ((this->*Inside_)(*pk, comlist_[resnum], site_size_)) { + if ((this->*Inside_)(pk, comlist_[resnum], site_size_)) { if (resPeakNum_[resnum] > 0) { - Vec3 diff1 = comlist_[resnum] - *pk; - Vec3 diff2 = comlist_[resnum] - peaks_[ resPeakNum_[resnum] ]; + Vec3 diff1 = comlist_[resnum] - pk; + Vec3 diff2 = comlist_[resnum] - peaksData_->Vec( resPeakNum_[resnum] ); // If we are closer, update. Otherwise do nothing if (diff1.Magnitude2() < diff2.Magnitude2()) resPeakNum_[resnum] = pknum; @@ -563,8 +568,8 @@ Action::RetType Action_Spam::DoSPAM(int frameNum, Frame& frameIn) { * -frameNum to this peak's data set in peakFrameData_. */ typedef std::vector Barray; - Barray occupied(peaks_.size(), false); - Barray doubled(peaks_.size(), false); // to avoid double-additions + Barray occupied(peaksData_->Size(), false); + Barray doubled(peaksData_->Size(), false); // to avoid double-additions for (Iarray::const_iterator it = resPeakNum_.begin(); it != resPeakNum_.end(); it++) { @@ -578,12 +583,12 @@ Action::RetType Action_Spam::DoSPAM(int frameNum, Frame& frameIn) { } } // Now loop through and add all non-occupied sites - for (unsigned int i = 0; i < peaks_.size(); i++) + for (unsigned int i = 0; i < peaksData_->Size(); i++) if (!occupied[i]) peakFrameData_[i].push_back(frameNum); // Now adjust the occupied vectors to only contain 'true' for sites we need to // analyze (i.e., make all doubled points 'unoccupied') - for (unsigned int i = 0; i < peaks_.size(); i++) + for (unsigned int i = 0; i < peaksData_->Size(); i++) if (doubled[i]) occupied[i] = false; t_occupy_.Stop(); @@ -591,7 +596,7 @@ Action::RetType Action_Spam::DoSPAM(int frameNum, Frame& frameIn) { // If we have to calculate energies, do that here if (calcEnergy_) { int peak; - int npeaks = (int)peaks_.size(); + int npeaks = (int)peaksData_->Size(); const double ZERO = 0.0; // Loop through every peak, then loop through the water molecules to find // which one is in that site, and calculate the LJ and EEL energies for that @@ -630,7 +635,7 @@ Action::RetType Action_Spam::DoSPAM(int frameNum, Frame& frameIn) { /* Loop over every occupied site and swap the atoms so the same solvent * residue is always in the same site */ - for (int i = 0; i < (int)peaks_.size(); i++) { + for (int i = 0; i < (int)peaksData_->Size(); i++) { // Skip unoccupied sites if (!occupied[i]) continue; for (unsigned int j = 0; j < solvent_residues_.size(); j++) { @@ -841,8 +846,8 @@ void Action_Spam::Print() { mprinterr("Warning: SPAM: Some frames had a box too small for the cutoff.\n"); // Print information about each missing peak - infofile_->Printf("# There are %d density peaks and %d frames\n\n", - (int)peaks_.size(), Nframes_); + infofile_->Printf("# There are %zu density peaks and %d frames\n\n", + peaksData_->Size(), Nframes_); // Loop over every Data set for (unsigned int i = 0; i < peakFrameData_.size(); i++) { // Skip peaks with 0 unoccupied sites diff --git a/src/Action_Spam.h b/src/Action_Spam.h index 491e9574f1..ffbc5a7758 100644 --- a/src/Action_Spam.h +++ b/src/Action_Spam.h @@ -5,6 +5,8 @@ #include "Vec3.h" #include "Timer.h" #include "PairList.h" +// Forward declares +class DataSet_Vector_Scalar; /** SPAM is a water profiling technique developed by Guanglei Cui at GlaxoSmithKline (GSK). The original implementation involved a set of specialized @@ -52,6 +54,7 @@ class Action_Spam: public Action { Action::RetType DoPureWater(int, Frame const&); Action::RetType DoSPAM(int, Frame&); + int GetPeaks(std::string const&, DataSetList const&); typedef bool (Action_Spam::*FxnType)(Vec3, Vec3, double) const; bool inside_box(Vec3, Vec3, double) const; bool inside_sphere(Vec3, Vec3, double) const; @@ -86,11 +89,12 @@ class Action_Spam: public Action { DataSet* ds_ds_; ///< Hold final -T*S values for each peak Parray peakFrameData_; ///< A list of all omitted frames for each peak DSarray myDSL_; ///< Hold energy data sets - Varray peaks_; ///< List of each peak location Varray comlist_; ///< For given frame, each residue C.O.M. coords. Rarray solvent_residues_; ///< List of each solvent residue int Nframes_; ///< Total number of frames bool overflow_; ///< True if cutoff overflowed our box coordinates + DataSetList peaksdsl_; ///< Will allocate DataSet for peaks data if loading from a file. + DataSet_Vector_Scalar* peaksData_; ///< Hold peaks DataSet // Timers Timer t_action_; Timer t_resCom_; diff --git a/src/cpptrajdepend b/src/cpptrajdepend index e44dfde9f2..f1d3dea4f5 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -72,7 +72,7 @@ Action_RunningAvg.o : Action_RunningAvg.cpp Action.h ActionState.h Action_Runnin Action_STFC_Diffusion.o : Action_STFC_Diffusion.cpp Action.h ActionState.h Action_STFC_Diffusion.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImagedAction.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_Scale.o : Action_Scale.cpp Action.h ActionState.h Action_Scale.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_SetVelocity.o : Action_SetVelocity.cpp Action.h ActionState.h Action_SetVelocity.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h Constraints.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Random.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h -Action_Spam.o : Action_Spam.cpp Action.h ActionState.h Action_Spam.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Mesh.h DataSet_double.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h HistBin.h ImagedAction.h KDE.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OnlineVarT.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h +Action_Spam.o : Action_Spam.cpp Action.h ActionState.h Action_Spam.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataIO.h DataIO_Peaks.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Mesh.h DataSet_Vector_Scalar.h DataSet_double.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h HistBin.h ImagedAction.h KDE.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OnlineVarT.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_Strip.o : Action_Strip.cpp Action.h ActionState.h Action_Strip.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h BondSearch.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ParmIO.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_Surf.o : Action_Surf.cpp Action.h ActionState.h Action_Surf.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_SymmetricRmsd.o : Action_SymmetricRmsd.cpp Action.h ActionState.h Action_SymmetricRmsd.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceAction.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h @@ -185,7 +185,7 @@ DataIO_Grace.o : DataIO_Grace.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h DataIO_Mdout.o : DataIO_Mdout.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Mdout.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_NC_Cmatrix.o : DataIO_NC_Cmatrix.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterDist.h ClusterSieve.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_NC_Cmatrix.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Cmatrix.h DataSet_Cmatrix_MEM.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h FileIO.h FileName.h Frame.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Cmatrix.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_OpenDx.o : DataIO_OpenDx.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_OpenDx.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridFlt.h Dimension.h FileIO.h FileName.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h -DataIO_Peaks.o : DataIO_Peaks.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Peaks.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector_Scalar.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h +DataIO_Peaks.o : DataIO_Peaks.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Peaks.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector_Scalar.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_RemLog.o : DataIO_RemLog.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_RemLog.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_RemLog.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_Std.o : DataIO_Std.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h ClusterDist.h ClusterSieve.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Std.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Cmatrix.h DataSet_Cmatrix_MEM.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Mat3x3.h DataSet_Vector.h DataSet_double.h DataSet_float.h DataSet_integer.h DataSet_string.h Dimension.h FileIO.h FileName.h Frame.h GridBin.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_VecTraj.o : DataIO_VecTraj.cpp ActionFrameCounter.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h BondSearch.h Box.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_VecTraj.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector.h Dimension.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ParmIO.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Vec3.h From 84288a092e2d0e097922d376b477af658ccf4969 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 14:43:15 -0400 Subject: [PATCH 19/87] Ensure that the GetNextString for output file is the last possible thing parsed from the argument list --- src/Action_Volmap.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index eba9b5f8bc..9aaed7f3b7 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -202,12 +202,6 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d return Action::ERR; } if (densitymask_.SetMaskString(reqmask)) return Action::ERR; - // Get output filename - std::string outfilename = actionArgs.GetStringKey("out"); - if (outfilename.empty()) - outfilename = actionArgs.GetStringNext(); // Backwards compat. - DataFile* outfile = init.DFL().AddDataFile( outfilename, actionArgs ); - if (outfile != 0) outfile->AddDataSet( grid_ ); // See if peaks are being determined peakfile_ = 0; std::string pfilename = actionArgs.GetStringKey("peakfile"); @@ -227,6 +221,13 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d # endif peakfile_->AddDataSet( peakdata_ ); } + // Get output filename (newer syntax) + std::string outfilename = actionArgs.GetStringKey("out"); + if (outfilename.empty()) + outfilename = actionArgs.GetStringNext(); // Backwards compat. + DataFile* outfile = init.DFL().AddDataFile( outfilename, actionArgs ); + if (outfile != 0) outfile->AddDataSet( grid_ ); + // Create total volume set total_volume_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(grid_->Meta().Name(), "totalvol")); if (total_volume_ == 0) return Action::ERR; From 6b18ed880fd6f83042bb5f7b87bfd6911dd34a68 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 14:45:53 -0400 Subject: [PATCH 20/87] Fix class const variable name --- src/Action_Volmap.cpp | 4 ++-- src/Action_Volmap.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 9aaed7f3b7..ddee4fce4c 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -7,7 +7,7 @@ # include #endif -const double Action_Volmap::sqrt_8_pi_cubed = sqrt(8.0*Constants::PI*Constants::PI*Constants::PI); +const double Action_Volmap::sqrt_8_pi_cubed_ = sqrt(8.0*Constants::PI*Constants::PI*Constants::PI); // CONSTRUCTOR Action_Volmap::Action_Volmap() : @@ -444,7 +444,7 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { if (iz >= -nzstep && iz <= nZ + nzstep) { // Calculate the gaussian normalization factor (in 3 dimensions with the // given half-radius) - double norm = 1 / (sqrt_8_pi_cubed * rhalf*rhalf*rhalf); + double norm = 1 / (sqrt_8_pi_cubed_ * rhalf*rhalf*rhalf); double exfac = -1.0 / (2.0 * rhalf * rhalf); //mprintf("DBG: Atom %i norm %g exfac %g\n", atom+1, norm, exfac); diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index de030af4c1..db1620c9ce 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -40,7 +40,7 @@ class Action_Volmap : public Action { double buffer_; ///< Clearance between the edges of our grid and centermask_ double radscale_; ///< The scaling factor to divide all radii by double stepfac_; ///< Factor for determining how many steps to smear Gaussian - static const double sqrt_8_pi_cubed; + static const double sqrt_8_pi_cubed_; # ifdef _OPENMP typedef std::vector< Grid > Garray; Garray GRID_THREAD_; From 8e49b7ef9614aa4a44893b32ea35fd34336d71d8 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 14:52:47 -0400 Subject: [PATCH 21/87] Make it so that you can calculate peaks without having to write them to a file. --- src/Action_Volmap.cpp | 21 +++++++++++++++------ src/Action_Volmap.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index ddee4fce4c..bb40e8f00d 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -22,6 +22,8 @@ Action_Volmap::Action_Volmap() : setupGridOnMask_(false), spheremode_(false), grid_(0), + total_volume_(0), + calcpeaks_(false), peakfile_(0), peakdata_(0), peakcut_(0.05), @@ -49,7 +51,7 @@ void Action_Volmap::RawHelp() const { "\t centermask [buffer ] |\n" "\t boxref }\n" "\t}\n" - "\t[radii {vdw | element}] [peakcut ] [peakfile ]\n"); + "\t[radii {vdw | element}] [calcpeaks] [peakcut ] [peakfile ]\n"); } // Action_Volmap::Init() @@ -203,6 +205,7 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d } if (densitymask_.SetMaskString(reqmask)) return Action::ERR; // See if peaks are being determined + calcpeaks_ = actionArgs.hasKey("calcpeaks"); peakfile_ = 0; std::string pfilename = actionArgs.GetStringKey("peakfile"); if (!pfilename.empty()) { @@ -211,6 +214,9 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprinterr("Error: Unable to allocate peak file.\n"); return Action::ERR; } + calcpeaks_ = true; + } + if (calcpeaks_) { peakdata_ = init.DSL().AddSet(DataSet::VECTOR_SCALAR, MetaData(grid_->Meta().Name(), "peaks")); if (peakdata_ == 0) { mprinterr("Error: Unable to allocate peak data set.\n"); @@ -219,7 +225,7 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d # ifdef MPI peakdata_->SetNeedsSync( false ); # endif - peakfile_->AddDataSet( peakdata_ ); + if (peakfile_ != 0) peakfile_->AddDataSet( peakdata_ ); } // Get output filename (newer syntax) std::string outfilename = actionArgs.GetStringKey("out"); @@ -269,9 +275,12 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tDensity will wrtten to '%s'\n", outfile->DataFilename().full()); mprintf("\tGrid dataset name is '%s'\n", grid_->legend()); mprintf("\tTotal grid volume dataset name is '%s'\n", total_volume_->legend()); - if (peakfile_ != 0) - mprintf("\tDensity peaks above %.3f will be saved to %s and printed to %s in XYZ-format\n", - peakcut_, peakdata_->legend(), peakfile_->DataFilename().full()); + if (calcpeaks_) { + mprintf("\tDensity peaks above %.3f will be saved to %s\n", peakcut_, peakdata_->legend()); + if (peakfile_ != 0) + mprintf("\tDensity peaks will be printed to %s in XYZ format.\n", + peakfile_->DataFilename().full()); + } # ifdef _OPENMP if (GRID_THREAD_.size() > 1) mprintf("\tParallelizing calculation with %zu threads.\n", GRID_THREAD_.size()); @@ -537,7 +546,7 @@ void Action_Volmap::Print() { // "rdparm generated grid density" ); // See if we need to write the peaks out somewhere - if (peakfile_ != 0) { + if (calcpeaks_) { // Extract peaks from the current grid, setup another Grid instance. This // works by taking every grid point and analyzing all grid points adjacent // to it (including diagonals). If any of those grid points have a higher diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index db1620c9ce..540c032f5b 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -32,6 +32,7 @@ class Action_Volmap : public Action { AtomMask densitymask_; ///< Max of atoms to grid. DataSet_GridFlt* grid_; ///< Hold the grid. DataSet* total_volume_; ///< Hold total grid volume. + bool calcpeaks_; ///< If true, calculate peaks DataFile* peakfile_; ///< file name with the peak locations as Carbons in XYZ file format DataSet* peakdata_; ///< Data set holding peak locations along with densities double peakcut_; ///< The value below which to ignore all peaks From 8168539b29a4ed475b43d7f74712bdaa70447001 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 15:49:08 -0400 Subject: [PATCH 22/87] Fix code comment --- src/Action_Volmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index 540c032f5b..da537f1510 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -33,7 +33,7 @@ class Action_Volmap : public Action { DataSet_GridFlt* grid_; ///< Hold the grid. DataSet* total_volume_; ///< Hold total grid volume. bool calcpeaks_; ///< If true, calculate peaks - DataFile* peakfile_; ///< file name with the peak locations as Carbons in XYZ file format + DataFile* peakfile_; ///< Optional file to write peak data to as Carbons in XYZ file format DataSet* peakdata_; ///< Data set holding peak locations along with densities double peakcut_; ///< The value below which to ignore all peaks std::vector Atoms_; ///< Atoms with radii > 0.0 From d80196d7e9b028da1aa54ae39fed8820ec228aa4 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 15:52:20 -0400 Subject: [PATCH 23/87] Fix up dependencies --- src/Action_Volmap.cpp | 1 + src/Action_Volmap.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index bb40e8f00d..f1f877bf3f 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -3,6 +3,7 @@ #include "Action_Volmap.h" #include "Constants.h" // PI #include "CpptrajStdio.h" +#include "DataSet_GridFlt.h" #ifdef _OPENMP # include #endif diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index da537f1510..d51130c914 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -1,7 +1,8 @@ #ifndef INC_ACTION_VOLMAP_H #define INC_ACTION_VOLMAP_H #include "Action.h" -#include "DataSet_GridFlt.h" +#include "Grid.h" +class DataSet_GridFlt; class Action_Volmap : public Action { public: Action_Volmap(); From fdc7029706fe0b91716b546be9ef2fc646e7ab24 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 16:14:32 -0400 Subject: [PATCH 24/87] Add class for approximating functions with splines --- src/SplineFxnTable.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++ src/SplineFxnTable.h | 30 ++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/SplineFxnTable.cpp create mode 100644 src/SplineFxnTable.h diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp new file mode 100644 index 0000000000..c2e4e1b056 --- /dev/null +++ b/src/SplineFxnTable.cpp @@ -0,0 +1,62 @@ +#include "SplineFxnTable.h" +#include "CpptrajStdio.h" +#include "Constants.h" +#include "Spline.h" +#include "StringRoutines.h" + +/** CONSTRUCTOR */ +SplineFxnTable::SplineFxnTable() : + Dx_(0), + one_over_Dx_(0), + Xmin_(0), + Xmax_(0) +{} + +/** Fill the spline function table with values from the given function. */ +int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double maxIn) +{ + Dx_ = dxIn; + if (Dx_ < Constants::SMALL) { + mprinterr("Error: Spacing for spline table too small or negative.\n"); + return 1; + } + one_over_Dx_ = 1.0 / Dx_; + + Xmax_ = maxIn; + Xmin_ = minIn; + double width = Xmax_ - Xmin_; + if (width < Constants::SMALL) { + mprinterr("Error: Max %g is not larger than min %g\n", Xmax_, Xmin_); + return 1; + } + + // Give the width a 1.5x cushion + unsigned int TableSize = (unsigned int)(one_over_Dx_ * width * 1.5); + + Darray Xvals, Yvals; + Xvals.reserve( TableSize ); + Yvals.reserve( TableSize ); + // Save X and Y values so we can calc the spline coefficients + double xval = 0.0; + for (unsigned int i = 0; i != TableSize; i++) { + double yval = fxnIn( xval ); + Xvals.push_back( xval ); + Yvals.push_back( yval ); + xval += Dx_; + } + Spline cspline; + cspline.CubicSpline_Coeff(Xvals, Yvals); + //Xvals.clear(); + // Store values in Spline table + table_.reserve( TableSize * 4 ); // Y B C D + for (unsigned int i = 0; i != TableSize; i++) { + table_.push_back( Yvals[i] ); + table_.push_back( cspline.B_coeff()[i] ); + table_.push_back( cspline.C_coeff()[i] ); + table_.push_back( cspline.D_coeff()[i] ); + } + // Memory saved Y values plus spline B, C, and D coefficient arrays. + mprintf("\tMemory used by table and splines: %s\n", + ByteString(table_.size() * sizeof(double), BYTE_DECIMAL).c_str()); + return 0; +} diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h new file mode 100644 index 0000000000..8376456789 --- /dev/null +++ b/src/SplineFxnTable.h @@ -0,0 +1,30 @@ +#ifndef INC_SPLINEFXNTABLE_H +#define INC_SPLINEFXNTABLE_H +#include +/// Can be used to approximate a function using cubic splines. +class SplineFxnTable { + public: + /// CONSTRUCTOR + SplineFxnTable(); + /// Generic form of the function to approximate. + typedef double (*FxnType)(double); + /// Fill the table using given function and spacing from given min to max. + int FillTable(FxnType, double, double, double); + /// \return Approximated Y value from given X value. + double Yval(double xIn) const { + int xidx = ((int)(one_over_Dx_ * xIn)); + double dx = xIn - ((double)xidx * Dx_); + xidx *= 4; + return table_[xidx] + + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); + } + private: + typedef std::vector Darray; + + double Dx_; ///< Spacing + double one_over_Dx_; ///< 1 over spacing + double Xmin_; ///< Minimum value for which function can be approximated + double Xmax_; ///< Maximum value for which function can be approximated + Darray table_; ///< Hold Y followed by spline B C D coefficients +}; +#endif From 8fd85f087856135b409590987c085613ad444dea Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 16:23:56 -0400 Subject: [PATCH 25/87] Ensure table is cleared when fill is called. --- src/SplineFxnTable.cpp | 1 + src/cpptrajdepend | 1 + src/cpptrajfiles | 1 + 3 files changed, 3 insertions(+) diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index c2e4e1b056..1f3e96f855 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -48,6 +48,7 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m cspline.CubicSpline_Coeff(Xvals, Yvals); //Xvals.clear(); // Store values in Spline table + table_.clear(); table_.reserve( TableSize * 4 ); // Y B C D for (unsigned int i = 0; i != TableSize; i++) { table_.push_back( Yvals[i] ); diff --git a/src/cpptrajdepend b/src/cpptrajdepend index f1d3dea4f5..f7d59bef4f 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -351,6 +351,7 @@ SDFfile.o : SDFfile.cpp Atom.h CpptrajFile.h FileIO.h FileName.h NameType.h Para SimplexMin.o : SimplexMin.cpp AssociatedData.h CpptrajFile.h CpptrajStdio.h DataSet.h Dimension.h FileIO.h FileName.h MetaData.h Parallel.h Random.h Range.h SimplexMin.h TextFormat.h SpaceGroup.o : SpaceGroup.cpp Matrix_3x3.h SpaceGroup.h Vec3.h Spline.o : Spline.cpp CpptrajStdio.h Spline.h +SplineFxnTable.o : SplineFxnTable.cpp Constants.h CpptrajStdio.h Spline.h SplineFxnTable.h StringRoutines.h StringRoutines.o : StringRoutines.cpp CpptrajStdio.h StringRoutines.h StructureCheck.o : StructureCheck.cpp Atom.h AtomExtra.h AtomMask.h AtomType.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajStdio.h DistRoutines.h FileName.h Frame.h ImagedAction.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h StructureCheck.h SymbolExporting.h Timer.h Topology.h TypeNameHolder.h Vec3.h StructureMapper.o : StructureMapper.cpp AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h FileIO.h FileName.h Frame.h MapAtom.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h StructureMapper.h SymbolExporting.h TextFormat.h Topology.h TorsionRoutines.h TypeNameHolder.h Vec3.h diff --git a/src/cpptrajfiles b/src/cpptrajfiles index f9c9aab161..2753fdbb28 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -349,6 +349,7 @@ COMMON_SOURCES= \ SDFfile.cpp \ SimplexMin.cpp \ Spline.cpp \ + SplineFxnTable.cpp \ StringRoutines.cpp \ StructureCheck.cpp \ StructureMapper.cpp \ From 1658b99e7d12c260dcaa6f114b1e95f1b58acfc2 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 17:13:24 -0400 Subject: [PATCH 26/87] Use the splines. 36% speed increase! --- src/Action_Volmap.cpp | 26 ++++++++++++++++++++++++-- src/Action_Volmap.h | 2 ++ src/SplineFxnTable.cpp | 2 +- src/SplineFxnTable.h | 9 +++++++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index f1f877bf3f..ba401fee1b 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -330,6 +330,7 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { else radiiToUse = ELEMENT; } + double maxRad = 0; for (AtomMask::const_iterator atom = densitymask_.begin(); atom != densitymask_.end(); ++atom) { double rad = 0.0; @@ -340,8 +341,26 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { if (rad > 0.0) { halfradii_.push_back( (float)(rad * radscale_ / 2) ); Atoms_.push_back( *atom ); + // For determining function range. + if (halfradii_.back() > maxRad) maxRad = halfradii_.back(); } } + mprintf("\tMax observed radius: %g Ang\n", maxRad); + int nxstep = (int) ceil(stepfac_ * maxRad / dx_)+1; + int nystep = (int) ceil(stepfac_ * maxRad / dy_)+1; + int nzstep = (int) ceil(stepfac_ * maxRad / dz_)+1; + double maxx = (double)nxstep * dx_; + double maxy = (double)nystep * dy_; + double maxz = (double)nzstep * dz_; + double maxDist = maxx*maxx + maxy*maxy + maxz*maxz; + mprintf("DEBUG: nx= %i ny= %i nz= %i\n", nxstep, nystep, nzstep); + mprintf("DEBUG: %g %g %g %g\n", maxx, maxy, maxz, maxDist); + double exfac = -1.0 / (2.0 * maxRad * maxRad); + maxDist *= exfac; + mprintf("DEBUG: max= %g\n", maxDist); + + + table_.FillTable( exp, 1.0/5000.0, maxDist, 0 ); if ((int)Atoms_.size() < densitymask_.Nselected()) mprintf("Warning: %i atoms have 0.0 radii and will be skipped.\n", densitymask_.Nselected() - (int)Atoms_.size()); @@ -467,10 +486,13 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { Vec3 gridpt = Vec3(xmin_+xval*dx_, ymin_+yval*dy_, zmin_+zval*dz_) - pt; double dist2 = gridpt.Magnitude2(); if (dist2 < rcut2) { + //mprintf("DEBUG: rhalf= %g dist2= %g exfac= %g exp= %g\n", rhalf, dist2, exfac, exfac*dist2); # ifdef _OPENMP - GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); + //GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); + GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval(exfac * dist2)); # else - grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); + //grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); + grid_->Increment(xval, yval, zval, norm * table_.Yval(exfac * dist2)); # endif } } // END loop over zval diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index d51130c914..4569864dd2 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -2,6 +2,7 @@ #define INC_ACTION_VOLMAP_H #include "Action.h" #include "Grid.h" +#include "SplineFxnTable.h" class DataSet_GridFlt; class Action_Volmap : public Action { public: @@ -43,6 +44,7 @@ class Action_Volmap : public Action { double radscale_; ///< The scaling factor to divide all radii by double stepfac_; ///< Factor for determining how many steps to smear Gaussian static const double sqrt_8_pi_cubed_; + SplineFxnTable table_; # ifdef _OPENMP typedef std::vector< Grid > Garray; Garray GRID_THREAD_; diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index 1f3e96f855..fadd73fe1c 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -37,7 +37,7 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m Xvals.reserve( TableSize ); Yvals.reserve( TableSize ); // Save X and Y values so we can calc the spline coefficients - double xval = 0.0; + double xval = Xmin_; for (unsigned int i = 0; i != TableSize; i++) { double yval = fxnIn( xval ); Xvals.push_back( xval ); diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index 8376456789..a6f5113c65 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -1,6 +1,7 @@ #ifndef INC_SPLINEFXNTABLE_H #define INC_SPLINEFXNTABLE_H #include +#include "CpptrajStdio.h" // DEBUG /// Can be used to approximate a function using cubic splines. class SplineFxnTable { public: @@ -12,9 +13,13 @@ class SplineFxnTable { int FillTable(FxnType, double, double, double); /// \return Approximated Y value from given X value. double Yval(double xIn) const { - int xidx = ((int)(one_over_Dx_ * xIn)); - double dx = xIn - ((double)xidx * Dx_); + double Xval = xIn - Xmin_; + int xidx = ((int)(one_over_Dx_ * Xval)); + double dx = Xval - ((double)xidx * Dx_); xidx *= 4; + // DEBUG + if (xidx < 0 || xidx >= (int)table_.size()) + mprinterr("Error: index %i out of range for X val %g\n", xidx, xIn); return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } From e34b7f1c857cd4b151b7106bb94606ebc1540737 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 22:26:12 -0400 Subject: [PATCH 27/87] Disable some debug checking --- src/SplineFxnTable.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index a6f5113c65..6ee3bd5e2f 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -1,7 +1,7 @@ #ifndef INC_SPLINEFXNTABLE_H #define INC_SPLINEFXNTABLE_H #include -#include "CpptrajStdio.h" // DEBUG +//#inc lude "CpptrajStdio.h" // DEBUG /// Can be used to approximate a function using cubic splines. class SplineFxnTable { public: @@ -18,10 +18,10 @@ class SplineFxnTable { double dx = Xval - ((double)xidx * Dx_); xidx *= 4; // DEBUG - if (xidx < 0 || xidx >= (int)table_.size()) - mprinterr("Error: index %i out of range for X val %g\n", xidx, xIn); - return table_[xidx] + - dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); + //if (xidx < 0 || xidx >= (int)table_.size()) + // mprinterr("Error: index %i out of range for X val %g\n", xidx, xIn); + //return table_[xidx] + + // dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } private: typedef std::vector Darray; From 496449d307eef914584ee985ccb0efd7770113bc Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 22:26:40 -0400 Subject: [PATCH 28/87] Woops, bring back return statement --- src/SplineFxnTable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index 6ee3bd5e2f..3749d26bb3 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -20,8 +20,8 @@ class SplineFxnTable { // DEBUG //if (xidx < 0 || xidx >= (int)table_.size()) // mprinterr("Error: index %i out of range for X val %g\n", xidx, xIn); - //return table_[xidx] + - // dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); + return table_[xidx] + + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } private: typedef std::vector Darray; From f69f587c28d7314e5c51e664c8dec609fa68b133 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Jun 2020 23:59:03 -0400 Subject: [PATCH 29/87] Remove some debug info. Add scaling factor argument. --- src/Action_Volmap.cpp | 16 +++++++--------- src/SplineFxnTable.cpp | 6 +++--- src/SplineFxnTable.h | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index ba401fee1b..b6754d3542 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -345,7 +345,8 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { if (halfradii_.back() > maxRad) maxRad = halfradii_.back(); } } - mprintf("\tMax observed radius: %g Ang\n", maxRad); + // Try to determine the max value we may encounter. + //mprintf("\tMax observed radius: %g Ang\n", maxRad); int nxstep = (int) ceil(stepfac_ * maxRad / dx_)+1; int nystep = (int) ceil(stepfac_ * maxRad / dy_)+1; int nzstep = (int) ceil(stepfac_ * maxRad / dz_)+1; @@ -353,14 +354,11 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { double maxy = (double)nystep * dy_; double maxz = (double)nzstep * dz_; double maxDist = maxx*maxx + maxy*maxy + maxz*maxz; - mprintf("DEBUG: nx= %i ny= %i nz= %i\n", nxstep, nystep, nzstep); - mprintf("DEBUG: %g %g %g %g\n", maxx, maxy, maxz, maxDist); - double exfac = -1.0 / (2.0 * maxRad * maxRad); - maxDist *= exfac; - mprintf("DEBUG: max= %g\n", maxDist); - - - table_.FillTable( exp, 1.0/5000.0, maxDist, 0 ); + //mprintf("DEBUG: nx= %i ny= %i nz= %i\n", nxstep, nystep, nzstep); + //mprintf("DEBUG: %g %g %g %g\n", maxx, maxy, maxz, maxDist); + maxDist *= (-1.0 / (2.0 * maxRad * maxRad)); + //mprintf("DEBUG: max= %g\n", maxDist); + table_.FillTable( exp, 1.0/5000.0, maxDist, 0, 1.1 ); if ((int)Atoms_.size() < densitymask_.Nselected()) mprintf("Warning: %i atoms have 0.0 radii and will be skipped.\n", densitymask_.Nselected() - (int)Atoms_.size()); diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index fadd73fe1c..50db5b3c09 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -13,7 +13,7 @@ SplineFxnTable::SplineFxnTable() : {} /** Fill the spline function table with values from the given function. */ -int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double maxIn) +int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double maxIn, double scale) { Dx_ = dxIn; if (Dx_ < Constants::SMALL) { @@ -30,8 +30,8 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m return 1; } - // Give the width a 1.5x cushion - unsigned int TableSize = (unsigned int)(one_over_Dx_ * width * 1.5); + // Calculate table size + unsigned int TableSize = (unsigned int)(one_over_Dx_ * width * scale); Darray Xvals, Yvals; Xvals.reserve( TableSize ); diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index 3749d26bb3..7c9f50bf8a 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -9,8 +9,8 @@ class SplineFxnTable { SplineFxnTable(); /// Generic form of the function to approximate. typedef double (*FxnType)(double); - /// Fill the table using given function and spacing from given min to max. - int FillTable(FxnType, double, double, double); + /// Fill the table using given function and spacing, from given min to max with given scale. + int FillTable(FxnType, double, double, double, double); /// \return Approximated Y value from given X value. double Yval(double xIn) const { double Xval = xIn - Xmin_; From 7dce82584964026cfad82934efe3d349a7a31b28 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Sun, 7 Jun 2020 15:23:38 -0400 Subject: [PATCH 30/87] Add splinedx keyword --- src/Action_Volmap.cpp | 9 ++++++--- src/Action_Volmap.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index b6754d3542..57102f33ef 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -30,7 +30,8 @@ Action_Volmap::Action_Volmap() : peakcut_(0.05), buffer_(3.0), radscale_(1.0), - stepfac_(4.1) + stepfac_(4.1), + splineDx_(0) {} void Action_Volmap::Help() const { @@ -70,6 +71,7 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d radscale_ = 0.5; stepfac_ = 1.0; } + splineDx_ = actionArgs.getKeyDouble("splinedx", 1.0/5000.0); radscale_ = 1.0 / actionArgs.getKeyDouble("radscale", radscale_); stepfac_ = actionArgs.getKeyDouble("stepfac", stepfac_); std::string radarg = actionArgs.GetStringKey("radii"); @@ -272,6 +274,7 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tWhen smearing Gaussian, voxels farther than radii/2 will be skipped.\n"); mprintf("\tDividing radii by %f\n", 1.0/radscale_); mprintf("\tFactor for determining number of bins to smear Gaussian is %f\n", stepfac_); + mprintf("\tExponential will be approximated using cubic splines with a spacing of %g\n", splineDx_); if (outfile != 0) mprintf("\tDensity will wrtten to '%s'\n", outfile->DataFilename().full()); mprintf("\tGrid dataset name is '%s'\n", grid_->legend()); @@ -345,7 +348,7 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { if (halfradii_.back() > maxRad) maxRad = halfradii_.back(); } } - // Try to determine the max value we may encounter. + // Try to determine the max value we may encounter for the exponential. //mprintf("\tMax observed radius: %g Ang\n", maxRad); int nxstep = (int) ceil(stepfac_ * maxRad / dx_)+1; int nystep = (int) ceil(stepfac_ * maxRad / dy_)+1; @@ -358,7 +361,7 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { //mprintf("DEBUG: %g %g %g %g\n", maxx, maxy, maxz, maxDist); maxDist *= (-1.0 / (2.0 * maxRad * maxRad)); //mprintf("DEBUG: max= %g\n", maxDist); - table_.FillTable( exp, 1.0/5000.0, maxDist, 0, 1.1 ); + table_.FillTable( exp, splineDx_, maxDist, 0, 1.1 ); if ((int)Atoms_.size() < densitymask_.Nselected()) mprintf("Warning: %i atoms have 0.0 radii and will be skipped.\n", densitymask_.Nselected() - (int)Atoms_.size()); diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index 4569864dd2..70349a078e 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -45,6 +45,7 @@ class Action_Volmap : public Action { double stepfac_; ///< Factor for determining how many steps to smear Gaussian static const double sqrt_8_pi_cubed_; SplineFxnTable table_; + double splineDx_; # ifdef _OPENMP typedef std::vector< Grid > Garray; Garray GRID_THREAD_; From d6519cc8ae44bc0c10a1b6ffd0b8ef43579be52d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 8 Jun 2020 14:14:04 -0400 Subject: [PATCH 31/87] Add code note about function calls in openmp parallel regions --- src/Action_Volmap.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 57102f33ef..84899962d6 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -489,6 +489,8 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { if (dist2 < rcut2) { //mprintf("DEBUG: rhalf= %g dist2= %g exfac= %g exp= %g\n", rhalf, dist2, exfac, exfac*dist2); # ifdef _OPENMP + // NOTE: It is OK to call table_.Yval() here because in OpenMP + // local variables of called functions are private. //GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval(exfac * dist2)); # else From 6cd73724b31f864881283673e549b48e3402ba81 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 8 Jun 2020 14:25:13 -0400 Subject: [PATCH 32/87] Fix up help. --- src/Action_Spam.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Action_Spam.cpp b/src/Action_Spam.cpp index 5b70ceb99c..8d8e5d0dbf 100644 --- a/src/Action_Spam.cpp +++ b/src/Action_Spam.cpp @@ -74,27 +74,27 @@ int Action_Spam::GetPeaks(std::string const& name, DataSetList const& dsl) void Action_Spam::Help() const { mprintf("\t[name ] [out ] [cut ] [solv ]\n" "\t{ purewater |\n" - "\t [reorder] [info ] [summary ]\n" + "\t [reorder] [info ] [summary ]\n" "\t [site_size ] [sphere] [temperature ]\n" "\t [dgbulk ] [dhbulk ] }\n" " Perform SPAM water analysis. If 'purewater' is specified calculate\n" " bulk energy values for a pure water system. Otherwise determine SPAM\n" " energies from peaks previously identified from the 'volmap' action.\n" - " : Output data set name.\n" - " : Data file with all SPAM energies for each snapshot.\n" - " : Non-bonded cutoff for energy evaluation\n" - " : Name of the solvent residues\n" - " [purewater]: The system is pure water---used to parametrize the bulk values.\n" - " : File with the peak locations present (XYZ- format)\n" - " [reorder] : The solvent should be re-ordered so the same solvent molecule\n" - " is always in the same site.\n" - " : File with stats about which sites are occupied when.\n" - " : File with the summary of all SPAM results.\n" - " : Size of the water site around each density peak.\n" - " [sphere] : Treat each site like a sphere.\n" - " : Temperature at which SPAM calculation was run.\n" - " : SPAM free energy of the bulk solvent in kcal/mol\n" - " : SPAM enthalpy of the bulk solvent in kcal/mol\n"); + " : Output data set name.\n" + " : Data file with all SPAM energies for each snapshot.\n" + " : Non-bonded cutoff for energy evaluation\n" + " : Name of the solvent residues\n" + " [purewater] : The system is pure water---used to parametrize the bulk values.\n" + " : Dataset/File (XYZ format) with the peak locations present.\n" + " [reorder] : The solvent should be re-ordered so the same solvent molecule\n" + " is always in the same site.\n" + " : File with stats about which sites are occupied when.\n" + " : File with the summary of all SPAM results.\n" + " : Size of the water site around each density peak.\n" + " [sphere] : Treat each site like a sphere.\n" + " : Temperature at which SPAM calculation was run.\n" + " : SPAM free energy of the bulk solvent in kcal/mol\n" + " : SPAM enthalpy of the bulk solvent in kcal/mol\n"); } // Action_Spam::Init() From f8761632ea3491db69d758dc31651f0345f7e051 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 8 Jun 2020 14:33:37 -0400 Subject: [PATCH 33/87] Warn if extra arguments remain after 'purewater' specified for SPAM --- src/Action_Spam.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Action_Spam.cpp b/src/Action_Spam.cpp index 8d8e5d0dbf..47e6163972 100644 --- a/src/Action_Spam.cpp +++ b/src/Action_Spam.cpp @@ -144,6 +144,9 @@ Action::RetType Action_Spam::Init(ArgList& actionArgs, ActionInit& init, int deb myDSL_.push_back( ds ); DG_BULK_ = 0.0; DH_BULK_ = 0.0; + // Shouldn't need any more arguments. + if (actionArgs.NremainingArgs() > 0) + mprintf("Warning: 'purewater' specified but more arguments remain.\n"); } else { // Get the file/dataset name with the peaks defined in it peaksname = actionArgs.GetStringNext(); From f39708fb98f624107cd77d8f1922a1096a33e464 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 8 Jun 2020 14:39:00 -0400 Subject: [PATCH 34/87] Fix up SPAM documentation. --- doc/cpptraj.lyx | 94 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 21 deletions(-) diff --git a/doc/cpptraj.lyx b/doc/cpptraj.lyx index 50cddeb57d..ac77e840ef 100644 --- a/doc/cpptraj.lyx +++ b/doc/cpptraj.lyx @@ -32703,78 +32703,130 @@ spam \end_layout \begin_layout LyX-Code -spam [solv ] [reorder] [name ] +spam [name ] [out ] [cut ] [solv ] \end_layout \begin_layout LyX-Code - [purewater] [cut ] [info ] [summary ] + { purewater | \end_layout \begin_layout LyX-Code - [site_size ] [sphere] [out ] + [reorder] [info ] [summary ] \end_layout \begin_layout LyX-Code - [dgbulk ] [dhbulk ] [temperature ] + [site_size ] [sphere] [temperature ] +\end_layout + +\begin_layout LyX-Code + [dgbulk ] [dhbulk ] } \end_layout \begin_deeper \begin_layout Description - File with the peak locations present (XYZ- format) +name +\begin_inset space ~ +\end_inset + + Output data set name. \end_layout \begin_layout Description - Name of the solvent residues +out +\begin_inset space ~ +\end_inset + + Data file with all SPAM energies for each snapshot. \end_layout \begin_layout Description - Non-bonded cutoff for energy evaluation +cut +\begin_inset space ~ +\end_inset + + Non-bonded cutoff in Ang. + for energy evaluation (default 12). \end_layout \begin_layout Description - SPAM free energy of the bulk solvent in kcal/mol; default is -30.3 - kcal/mol (SPC/E water). +solv +\begin_inset space ~ +\end_inset + + Name of the solvent residues (default +\begin_inset Quotes eld +\end_inset + +WAT +\begin_inset Quotes erd +\end_inset + +). + \end_layout \begin_layout Description - SPAM enthalpy of the bulk solvent in kcal/mol; default is -22.2 - kcal/mol (SPC/E water). +[purewater] The system is pure water---used to parametrize the bulk values. + Not compatible with ''. +\end_layout + +\begin_layout Description + If specified, the dataset or file containing peak locations + to analyze. + Not compatible with 'purewater'. \end_layout +\begin_deeper \begin_layout Description - Temperature at which SPAM calculation was run. +[reorder] The solvent should be re-ordered so the same solvent molecule + is always in the same site. \end_layout \begin_layout Description +info +\begin_inset space ~ +\end_inset + File with stats about which sites are occupied when. \end_layout \begin_layout Description - Size of the water site around each density peak. +summary +\begin_inset space ~ +\end_inset + + File with the summary of all SPAM results. + If not specified, no SPAM energies will be calculated. \end_layout \begin_layout Description -[sphere] Treat each site like a sphere. +site_size +\begin_inset space ~ +\end_inset + + Size of the solvent site around each density peak in Ang. + (default 2.5). \end_layout \begin_layout Description -[purewater] The system is pure water---used to parametrize the bulk values. +[sphere] Treat each site like a sphere instead of a box. \end_layout \begin_layout Description -[reorder] The solvent should be re-ordered so the same solvent molecule - is always in the same site. + Temperature at which SPAM calculation was run in K (default 300). \end_layout \begin_layout Description - File with the summary of all SPAM results. - If not specified, no SPAM energies will be calculated. + SPAM free energy of the bulk solvent in kcal/mol; default is -30.3 + kcal/mol (SPC/E water). \end_layout \begin_layout Description - Data file with all SPAM energies for each snapshot. + SPAM enthalpy of the bulk solvent in kcal/mol; default is -22.2 + kcal/mol (SPC/E water). \end_layout +\end_deeper \end_deeper \begin_layout Standard Perform profiling of bound water molecules via SPAM analysis @@ -32811,7 +32863,7 @@ reference "subsec:cpptraj_volmap" \end_inset -) to generate the peaks file. +) to generate the peaks file/dataset. If not using peaks from the \series bold \emph on From eba593b01ece95b4ab5450babe0643e18001d47f Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 8 Jun 2020 14:59:38 -0400 Subject: [PATCH 35/87] Update the volmap manual entry. --- doc/cpptraj.lyx | 183 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 157 insertions(+), 26 deletions(-) diff --git a/doc/cpptraj.lyx b/doc/cpptraj.lyx index ac77e840ef..b03847fd20 100644 --- a/doc/cpptraj.lyx +++ b/doc/cpptraj.lyx @@ -32700,6 +32700,13 @@ xmgrace dssp.agr \begin_layout Subsection spam +\begin_inset CommandInset label +LatexCommand label +name "subsec:cpptraj-spam" + +\end_inset + + \end_layout \begin_layout LyX-Code @@ -32805,7 +32812,7 @@ site_size \end_inset Size of the solvent site around each density peak in Ang. - (default 2.5). + (default 2.5, suitable for water). \end_layout \begin_layout Description @@ -34466,52 +34473,52 @@ name "subsec:cpptraj_volmap" \end_layout \begin_layout LyX-Code -volmap filename dx dy dz [radscale ] +volmap [out [radscale ] [stepfac ] [sphere] \end_layout \begin_layout LyX-Code - { data | + { data | \end_layout \begin_layout LyX-Code - name { size [center ] | + name [ ] \end_layout \begin_layout LyX-Code - centermask [buffer ] } } + { size [center ] | \end_layout \begin_layout LyX-Code - [peakcut ] [peakfile ] -\begin_inset Separator latexpar -\end_inset + centermask [buffer ] | +\end_layout +\begin_layout LyX-Code + boxref } +\end_layout +\begin_layout LyX-Code + } \end_layout -\begin_deeper -\begin_layout Description +\begin_layout LyX-Code + [radii {vdw | element}] [calcpeaks] [peakcut ] [peakfile ] +\begin_inset Separator latexpar +\end_inset + -\family roman -filename -\family default -The name of the output file with the grid density. \end_layout +\begin_deeper \begin_layout Description \family roman -dx, -\begin_inset space ~ -\end_inset - -dy, +out \begin_inset space ~ \end_inset -dz + \family default -The grid spacing (Angstroms) in the X-, Y-, and Z-dimensions, respectively +The name of the output file with the grid density. \end_layout \begin_layout Description @@ -34534,7 +34541,29 @@ radscale Factor by which to scale radii (by division). To match the atomic radius of Oxygen used by the VMD volmap tool, a scaling factor of 1.36 should be used. - Default 1.0. + Default 0.5 if +\series bold +sphere +\series default +, 1.0 otherwise. +\end_layout + +\begin_layout Description +stepfac +\begin_inset space ~ +\end_inset + + Factor for determining number of bins to smear Gaussian. + Default 1.0 if +\series bold +sphere +\series default +, 4.1 otherwise. +\end_layout + +\begin_layout Description +sphere Smear Gaussian as a sphere, i.e. + when smearing Gaussian, voxels farther than radii/2 will be skipped. \end_layout \begin_layout Description @@ -34550,7 +34579,7 @@ name \begin_inset space ~ \end_inset - Name of grid set that will be created ( + Name for new grid data set ( \series bold size/center \series default @@ -34561,6 +34590,36 @@ centermask/buffer keywords). \end_layout +\begin_deeper +\begin_layout Description + +\family roman + +\begin_inset space ~ +\end_inset + +[dy +\begin_inset space ~ +\end_inset + +dz] +\family default +The grid spacing (Angstroms) in the X-, Y-, and Z-dimensions, respectively. + If +\series bold + +\series default +/ +\series bold + +\series default + not specified, use +\series bold + +\series default +. +\end_layout + \begin_layout Description \family roman @@ -34570,8 +34629,13 @@ size \family default -Specify the size of the grid in the X-, Y-, and Z-dimensions. - Must be used alongside the center argument. +Comma-separated list specifying the size of the grid in the X-, Y-, and + Z-dimensions. + Must be used alongside the +\series bold +center +\series default + argument. \end_layout \begin_layout Description @@ -34618,6 +34682,40 @@ A buffer distance, in Angstroms, by which the edges of the grid should clear The buffer is ignored if the center and size are specified (see below). \end_layout +\end_deeper +\begin_layout Description +radii +\begin_inset space ~ +\end_inset + +{vdw +\begin_inset space ~ +\end_inset + +| +\begin_inset space ~ +\end_inset + +element} Specify radii to use (van der Waals or elemental respectively). + If not specified, van der Waals will be used if present, elemental radii + otherwise. +\end_layout + +\begin_layout Description +calcpeaks Specify that density peaks should be determined. + Useful for the SPAM action ( +\begin_inset CommandInset ref +LatexCommand vref +reference "subsec:cpptraj-spam" +plural "false" +caps "false" +noprefix "false" + +\end_inset + +). +\end_layout + \begin_layout Description \family roman @@ -34642,7 +34740,40 @@ peakfile \family default A file in XYZ-format that contains a carbon atom centered at the grid point of every local density maximum. - This file is necessary input to the spam action command. + Implies +\series bold +calcpeaks +\series default +. +\end_layout + +\begin_layout Standard +Data sets created: +\end_layout + +\begin_layout Description + The 3D grid containing density. +\end_layout + +\begin_layout Description +[peaks] A vector/scalar set containing the XYZ coordinates of each + peak (the vector part) and the density of that peak (the scalar part). + Can be used in the SPAM action ( +\begin_inset CommandInset ref +LatexCommand vref +reference "subsec:cpptraj-spam" +plural "false" +caps "false" +noprefix "false" + +\end_inset + +). +\end_layout + +\begin_layout Description +[totalvol] A set containing the total volume estimate of atoms + in based on summing up the volume of all occupied voxels. \end_layout \end_deeper From 8975be6400255bae260c524dd7dbc3e08798ea2e Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 8 Jun 2020 15:09:35 -0400 Subject: [PATCH 36/87] More manual updates for volmap. Fix up help. --- doc/cpptraj.lyx | 164 +++++++++++++++++++++++------------------- src/Action_Volmap.cpp | 6 +- 2 files changed, 95 insertions(+), 75 deletions(-) diff --git a/doc/cpptraj.lyx b/doc/cpptraj.lyx index b03847fd20..9cf28e6763 100644 --- a/doc/cpptraj.lyx +++ b/doc/cpptraj.lyx @@ -34473,41 +34473,45 @@ name "subsec:cpptraj_volmap" \end_layout \begin_layout LyX-Code -volmap [out [radscale ] [stepfac ] [sphere] +volmap [out ] [radscale ] [stepfac ] \end_layout \begin_layout LyX-Code - { data | + [sphere] [radii {vdw | element}] [splinedx ] \end_layout \begin_layout LyX-Code - name [ ] + [calcpeaks] [peakcut ] [peakfile ] \end_layout \begin_layout LyX-Code - { size [center ] | + { data | \end_layout \begin_layout LyX-Code - centermask [buffer ] | + name [ ] \end_layout \begin_layout LyX-Code - boxref } + { size [center ] | \end_layout \begin_layout LyX-Code - } + centermask [buffer ] | \end_layout \begin_layout LyX-Code - [radii {vdw | element}] [calcpeaks] [peakcut ] [peakfile ] + boxref } \begin_inset Separator latexpar \end_inset \end_layout +\begin_layout LyX-Code + } +\end_layout + \begin_deeper \begin_layout Description @@ -34566,6 +34570,79 @@ sphere Smear Gaussian as a sphere, i.e. when smearing Gaussian, voxels farther than radii/2 will be skipped. \end_layout +\begin_layout Description +radii +\begin_inset space ~ +\end_inset + +{vdw +\begin_inset space ~ +\end_inset + +| +\begin_inset space ~ +\end_inset + +element} Specify radii to use (van der Waals or elemental respectively). + If not specified, van der Waals will be used if present, elemental radii + otherwise. +\end_layout + +\begin_layout Description +splinedx +\begin_inset space ~ +\end_inset + + Spacing used for cubic spline function approximating exponential + (default 0.0002 Ang). +\end_layout + +\begin_layout Description +calcpeaks Specify that density peaks should be determined. + Useful for the SPAM action ( +\begin_inset CommandInset ref +LatexCommand vref +reference "subsec:cpptraj-spam" +plural "false" +caps "false" +noprefix "false" + +\end_inset + +). +\end_layout + +\begin_layout Description + +\family roman +peakcut +\begin_inset space ~ +\end_inset + + +\family default +The minimum density required to consider a local maximum a 'density peak' + in the outputted peak file (default 0.05). +\end_layout + +\begin_layout Description + +\family roman +peakfile +\begin_inset space ~ +\end_inset + + +\family default +A file in XYZ-format that contains a carbon atom centered at the grid point + of every local density maximum. + Implies +\series bold +calcpeaks +\series default +. +\end_layout + \begin_layout Description data \begin_inset space ~ @@ -34683,70 +34760,6 @@ A buffer distance, in Angstroms, by which the edges of the grid should clear \end_layout \end_deeper -\begin_layout Description -radii -\begin_inset space ~ -\end_inset - -{vdw -\begin_inset space ~ -\end_inset - -| -\begin_inset space ~ -\end_inset - -element} Specify radii to use (van der Waals or elemental respectively). - If not specified, van der Waals will be used if present, elemental radii - otherwise. -\end_layout - -\begin_layout Description -calcpeaks Specify that density peaks should be determined. - Useful for the SPAM action ( -\begin_inset CommandInset ref -LatexCommand vref -reference "subsec:cpptraj-spam" -plural "false" -caps "false" -noprefix "false" - -\end_inset - -). -\end_layout - -\begin_layout Description - -\family roman -peakcut -\begin_inset space ~ -\end_inset - - -\family default -The minimum density required to consider a local maximum a 'density peak' - in the outputted peak file (default 0.05). -\end_layout - -\begin_layout Description - -\family roman -peakfile -\begin_inset space ~ -\end_inset - - -\family default -A file in XYZ-format that contains a carbon atom centered at the grid point - of every local density maximum. - Implies -\series bold -calcpeaks -\series default -. -\end_layout - \begin_layout Standard Data sets created: \end_layout @@ -34783,7 +34796,12 @@ Grid data as a volumetric map, similar to the 'volmap' command in VMD. function whose standard deviation is equal to the van der Waals radius. The density calculated is the number density averaged over the entire simulatio n. - The grid can be specified in one of three ways: + In order to speed up the calculation, the exponential used to calculate + the Gaussian is approximated by cubic splines. +\end_layout + +\begin_layout Standard +The grid can be specified in one of three ways: \end_layout \begin_layout Enumerate diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 84899962d6..bd57f1c543 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -46,14 +46,16 @@ void Action_Volmap::Help() const { } void Action_Volmap::RawHelp() const { - mprintf("\t[out ] [radscale ] [stepfac ] [sphere]\n" + mprintf("\t[out ] [radscale ] [stepfac ]\n" + "\t[sphere] [radii {vdw | element}] [splinedx ]\n" + "\t[calcpeaks] [peakcut ] [peakfile ]\n" "\t{ data |\n" "\t name [ ]\n" "\t { size [center ] |\n" "\t centermask [buffer ] |\n" "\t boxref }\n" "\t}\n" - "\t[radii {vdw | element}] [calcpeaks] [peakcut ] [peakfile ]\n"); + ); } // Action_Volmap::Init() From 771f40949f951def9684767c1ab150efe523f35e Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 2 Jul 2020 14:29:16 -0400 Subject: [PATCH 37/87] Fix up some dependencies --- src/DataSet_3D.h | 3 +-- src/GridBin.h | 1 + src/cpptrajdepend | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DataSet_3D.h b/src/DataSet_3D.h index 0070a4840a..324236ed3e 100644 --- a/src/DataSet_3D.h +++ b/src/DataSet_3D.h @@ -1,9 +1,8 @@ #ifndef INC_DATASET_3D_H #define INC_DATASET_3D_H #include "DataSet.h" -#include "CpptrajFile.h" -#include "Box.h" #include "GridBin.h" +class Box; /// Interface for 3D DataSets. // FIXME: Use DataSet Dims? class DataSet_3D : public DataSet { diff --git a/src/GridBin.h b/src/GridBin.h index 93ae7b66ff..5e4307ef43 100644 --- a/src/GridBin.h +++ b/src/GridBin.h @@ -1,6 +1,7 @@ #ifndef INC_GRIDBIN_H #define INC_GRIDBIN_H #include "Matrix_3x3.h" +#include "Box.h" /// Class used to perform binning on/get voxel coords of 3D grids. class GridBin { public: diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 75837a947b..3ef5965869 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -83,7 +83,7 @@ Action_Unstrip.o : Action_Unstrip.cpp Action.h ActionState.h Action_Unstrip.h Ar Action_Unwrap.o : Action_Unwrap.cpp Action.h ActionState.h Action_Unwrap.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h ImageRoutines.h ImageTypes.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_Vector.o : Action_Vector.cpp Action.h ActionState.h Action_Vector.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_VelocityAutoCorr.o : Action_VelocityAutoCorr.cpp Action.h ActionState.h Action_VelocityAutoCorr.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h ComplexArray.h Constants.h CoordinateInfo.h Corr.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector.h DataSet_double.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h PubFFT.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h -Action_Volmap.o : Action_Volmap.cpp Action.h ActionState.h Action_Volmap.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridFlt.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h +Action_Volmap.o : Action_Volmap.cpp Action.h ActionState.h Action_Volmap.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridFlt.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SplineFxnTable.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_Volume.o : Action_Volume.cpp Action.h ActionState.h Action_Volume.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImagedAction.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_Watershell.o : Action_Watershell.cpp Action.h ActionState.h Action_Watershell.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageRoutines.h ImageTypes.h ImagedAction.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_XtalSymm.o : Action_XtalSymm.cpp Action.h ActionState.h Action_XtalSymm.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SpaceGroup.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h @@ -158,7 +158,7 @@ Cluster_ReadInfo.o : Cluster_ReadInfo.cpp ArgList.h ArrayIterator.h AssociatedDa Cmd.o : Cmd.cpp Cmd.h DispatchObject.h CmdInput.o : CmdInput.cpp CmdInput.h StringRoutines.h CmdList.o : CmdList.cpp Cmd.h CmdList.h DispatchObject.h -Command.o : Command.cpp Action.h ActionFrameCounter.h ActionList.h ActionState.h Action_Align.h Action_Angle.h Action_AreaPerMol.h Action_AtomMap.h Action_AtomicCorr.h Action_AtomicFluct.h Action_AutoImage.h Action_Average.h Action_Bounds.h Action_Box.h Action_Center.h Action_Channel.h Action_CheckChirality.h Action_CheckStructure.h Action_Closest.h Action_ClusterDihedral.h Action_Contacts.h Action_CreateCrd.h Action_CreateReservoir.h Action_DNAionTracker.h Action_DSSP.h Action_Density.h Action_Diffusion.h Action_Dihedral.h Action_DihedralRMS.h Action_Dipole.h Action_DistRmsd.h Action_Distance.h Action_Energy.h Action_Esander.h Action_FilterByData.h Action_FixAtomOrder.h Action_FixImagedBonds.h Action_GIST.h Action_Grid.h Action_GridFreeEnergy.h Action_HydrogenBond.h Action_Image.h Action_InfraredSpectrum.h Action_Jcoupling.h Action_LESsplit.h Action_LIE.h Action_LipidOrder.h Action_MakeStructure.h Action_Mask.h Action_Matrix.h Action_MinImage.h Action_Molsurf.h Action_MultiDihedral.h Action_MultiVector.h Action_NAstruct.h Action_NMRrst.h Action_NativeContacts.h Action_OrderParameter.h Action_Outtraj.h Action_PairDist.h Action_Pairwise.h Action_Principal.h Action_Projection.h Action_Pucker.h Action_Radgyr.h Action_Radial.h Action_RandomizeIons.h Action_Remap.h Action_ReplicateCell.h Action_Rmsd.h Action_Rotate.h Action_RunningAvg.h Action_STFC_Diffusion.h Action_Scale.h Action_SetVelocity.h Action_Spam.h Action_Strip.h Action_Surf.h Action_SymmetricRmsd.h Action_Temperature.h Action_Time.h Action_Translate.h Action_Unstrip.h Action_Unwrap.h Action_Vector.h Action_VelocityAutoCorr.h Action_Volmap.h Action_Volume.h Action_Watershell.h Action_XtalSymm.h Analysis.h AnalysisList.h AnalysisState.h Analysis_AmdBias.h Analysis_AutoCorr.h Analysis_Average.h Analysis_Clustering.h Analysis_ConstantPHStats.h Analysis_Corr.h Analysis_CrankShaft.h Analysis_CrdFluct.h Analysis_CrossCorr.h Analysis_CurveFit.h Analysis_Divergence.h Analysis_EvalPlateau.h Analysis_FFT.h Analysis_HausdorffDistance.h Analysis_Hist.h Analysis_IRED.h Analysis_Integrate.h Analysis_KDE.h Analysis_Lifetime.h Analysis_LowestCurve.h Analysis_Matrix.h Analysis_MeltCurve.h Analysis_Modes.h Analysis_MultiHist.h Analysis_Multicurve.h Analysis_Overlap.h Analysis_PhiPsi.h Analysis_Regression.h Analysis_RemLog.h Analysis_Rms2d.h Analysis_RmsAvgCorr.h Analysis_Rotdif.h Analysis_RunningAvg.h Analysis_Slope.h Analysis_Spline.h Analysis_State.h Analysis_Statistics.h Analysis_TI.h Analysis_Timecorr.h Analysis_VectorMath.h Analysis_Wavelet.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h AxisType.h BaseIOtype.h Box.h BufferedLine.h CharMask.h ClusterDist.h ClusterList.h ClusterMap.h ClusterNode.h ClusterSieve.h Cmd.h CmdInput.h CmdList.h Command.h ComplexArray.h Constants.h Constraints.h ControlBlock.h ControlBlock_For.h CoordinateInfo.h Corr.h Cph.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Cmatrix.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h DataSet_GridFlt.h DataSet_Mat3x3.h DataSet_MatrixDbl.h DataSet_MatrixFlt.h DataSet_Mesh.h DataSet_Modes.h DataSet_RemLog.h DataSet_Vector.h DataSet_double.h DataSet_float.h DataSet_integer.h DataSet_integer_mem.h DataSet_pH.h DataSet_string.h Deprecated.h DihedralSearch.h Dimension.h DispatchObject.h DistRoutines.h Energy.h Energy_Sander.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_Analyze.h Exec_Calc.h Exec_CatCrd.h Exec_Change.h Exec_ClusterMap.h Exec_CombineCoords.h Exec_Commands.h Exec_CompareTop.h Exec_CrdAction.h Exec_CrdOut.h Exec_CreateSet.h Exec_DataFile.h Exec_DataFilter.h Exec_DataSetCmd.h Exec_Emin.h Exec_GenerateAmberRst.h Exec_Help.h Exec_LoadCrd.h Exec_LoadTraj.h Exec_ParallelAnalysis.h Exec_ParmBox.h Exec_ParmSolvent.h Exec_ParmStrip.h Exec_ParmWrite.h Exec_PermuteDihedrals.h Exec_Precision.h Exec_PrepareForLeap.h Exec_PrintData.h Exec_ReadData.h Exec_ReadEnsembleData.h Exec_ReadInput.h Exec_RotateDihedral.h Exec_RunAnalysis.h Exec_ScaleDihedralK.h Exec_SequenceAlign.h Exec_Set.h Exec_Show.h Exec_SortEnsembleData.h Exec_SplitCoords.h Exec_System.h Exec_Top.h Exec_Traj.h Exec_UpdateParameters.h Exec_ViewRst.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h Grid.h GridAction.h GridBin.h HistBin.h Hungarian.h ImageTypes.h ImagedAction.h InputTrajCommon.h MapAtom.h MaskArray.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h NetcdfFile.h OnlineVarT.h OutputTrajCommon.h PDBfile.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h PubFFT.h RPNcalc.h Random.h Range.h ReferenceAction.h ReferenceFrame.h RemdReservoirNC.h ReplicaDimArray.h ReplicaInfo.h Residue.h Spline.h StructureCheck.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h TrajectoryFile.h Trajin.h TrajinList.h TrajoutList.h Trajout_Single.h TypeNameHolder.h Vec3.h cuda_kernels/GistCudaSetup.cuh molsurf.h +Command.o : Command.cpp Action.h ActionFrameCounter.h ActionList.h ActionState.h Action_Align.h Action_Angle.h Action_AreaPerMol.h Action_AtomMap.h Action_AtomicCorr.h Action_AtomicFluct.h Action_AutoImage.h Action_Average.h Action_Bounds.h Action_Box.h Action_Center.h Action_Channel.h Action_CheckChirality.h Action_CheckStructure.h Action_Closest.h Action_ClusterDihedral.h Action_Contacts.h Action_CreateCrd.h Action_CreateReservoir.h Action_DNAionTracker.h Action_DSSP.h Action_Density.h Action_Diffusion.h Action_Dihedral.h Action_DihedralRMS.h Action_Dipole.h Action_DistRmsd.h Action_Distance.h Action_Energy.h Action_Esander.h Action_FilterByData.h Action_FixAtomOrder.h Action_FixImagedBonds.h Action_GIST.h Action_Grid.h Action_GridFreeEnergy.h Action_HydrogenBond.h Action_Image.h Action_InfraredSpectrum.h Action_Jcoupling.h Action_LESsplit.h Action_LIE.h Action_LipidOrder.h Action_MakeStructure.h Action_Mask.h Action_Matrix.h Action_MinImage.h Action_Molsurf.h Action_MultiDihedral.h Action_MultiVector.h Action_NAstruct.h Action_NMRrst.h Action_NativeContacts.h Action_OrderParameter.h Action_Outtraj.h Action_PairDist.h Action_Pairwise.h Action_Principal.h Action_Projection.h Action_Pucker.h Action_Radgyr.h Action_Radial.h Action_RandomizeIons.h Action_Remap.h Action_ReplicateCell.h Action_Rmsd.h Action_Rotate.h Action_RunningAvg.h Action_STFC_Diffusion.h Action_Scale.h Action_SetVelocity.h Action_Spam.h Action_Strip.h Action_Surf.h Action_SymmetricRmsd.h Action_Temperature.h Action_Time.h Action_Translate.h Action_Unstrip.h Action_Unwrap.h Action_Vector.h Action_VelocityAutoCorr.h Action_Volmap.h Action_Volume.h Action_Watershell.h Action_XtalSymm.h Analysis.h AnalysisList.h AnalysisState.h Analysis_AmdBias.h Analysis_AutoCorr.h Analysis_Average.h Analysis_Clustering.h Analysis_ConstantPHStats.h Analysis_Corr.h Analysis_CrankShaft.h Analysis_CrdFluct.h Analysis_CrossCorr.h Analysis_CurveFit.h Analysis_Divergence.h Analysis_EvalPlateau.h Analysis_FFT.h Analysis_HausdorffDistance.h Analysis_Hist.h Analysis_IRED.h Analysis_Integrate.h Analysis_KDE.h Analysis_Lifetime.h Analysis_LowestCurve.h Analysis_Matrix.h Analysis_MeltCurve.h Analysis_Modes.h Analysis_MultiHist.h Analysis_Multicurve.h Analysis_Overlap.h Analysis_PhiPsi.h Analysis_Regression.h Analysis_RemLog.h Analysis_Rms2d.h Analysis_RmsAvgCorr.h Analysis_Rotdif.h Analysis_RunningAvg.h Analysis_Slope.h Analysis_Spline.h Analysis_State.h Analysis_Statistics.h Analysis_TI.h Analysis_Timecorr.h Analysis_VectorMath.h Analysis_Wavelet.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h AxisType.h BaseIOtype.h Box.h BufferedLine.h CharMask.h ClusterDist.h ClusterList.h ClusterMap.h ClusterNode.h ClusterSieve.h Cmd.h CmdInput.h CmdList.h Command.h ComplexArray.h Constants.h Constraints.h ControlBlock.h ControlBlock_For.h CoordinateInfo.h Corr.h Cph.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Cmatrix.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h DataSet_GridFlt.h DataSet_Mat3x3.h DataSet_MatrixDbl.h DataSet_MatrixFlt.h DataSet_Mesh.h DataSet_Modes.h DataSet_RemLog.h DataSet_Vector.h DataSet_double.h DataSet_float.h DataSet_integer.h DataSet_integer_mem.h DataSet_pH.h DataSet_string.h Deprecated.h DihedralSearch.h Dimension.h DispatchObject.h DistRoutines.h Energy.h Energy_Sander.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_Analyze.h Exec_Calc.h Exec_CatCrd.h Exec_Change.h Exec_ClusterMap.h Exec_CombineCoords.h Exec_Commands.h Exec_CompareTop.h Exec_CrdAction.h Exec_CrdOut.h Exec_CreateSet.h Exec_DataFile.h Exec_DataFilter.h Exec_DataSetCmd.h Exec_Emin.h Exec_GenerateAmberRst.h Exec_Help.h Exec_LoadCrd.h Exec_LoadTraj.h Exec_ParallelAnalysis.h Exec_ParmBox.h Exec_ParmSolvent.h Exec_ParmStrip.h Exec_ParmWrite.h Exec_PermuteDihedrals.h Exec_Precision.h Exec_PrepareForLeap.h Exec_PrintData.h Exec_ReadData.h Exec_ReadEnsembleData.h Exec_ReadInput.h Exec_RotateDihedral.h Exec_RunAnalysis.h Exec_ScaleDihedralK.h Exec_SequenceAlign.h Exec_Set.h Exec_Show.h Exec_SortEnsembleData.h Exec_SplitCoords.h Exec_System.h Exec_Top.h Exec_Traj.h Exec_UpdateParameters.h Exec_ViewRst.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h Grid.h GridAction.h GridBin.h HistBin.h Hungarian.h ImageTypes.h ImagedAction.h InputTrajCommon.h MapAtom.h MaskArray.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h NetcdfFile.h OnlineVarT.h OutputTrajCommon.h PDBfile.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h PubFFT.h RPNcalc.h Random.h Range.h ReferenceAction.h ReferenceFrame.h RemdReservoirNC.h ReplicaDimArray.h ReplicaInfo.h Residue.h Spline.h SplineFxnTable.h StructureCheck.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h TrajectoryFile.h Trajin.h TrajinList.h TrajoutList.h Trajout_Single.h TypeNameHolder.h Vec3.h cuda_kernels/GistCudaSetup.cuh molsurf.h ComplexArray.o : ComplexArray.cpp ArrayIterator.h ComplexArray.h Constraints.o : Constraints.cpp ArgList.h Atom.h AtomExtra.h AtomMask.h AtomType.h Box.h CharMask.h Constants.h Constraints.h CoordinateInfo.h CpptrajStdio.h FileName.h Frame.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h SymbolExporting.h Topology.h TypeNameHolder.h Vec3.h ControlBlock_For.o : ControlBlock_For.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h ControlBlock.h ControlBlock_For.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h FileIO.h FileName.h FileTypes.h ForLoop.h ForLoop_dataSetBlocks.h ForLoop_integer.h ForLoop_list.h ForLoop_mask.h ForLoop_overSets.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Vec3.h From 0d6a2c4ca4841d88dd891c2406844ed4c753b63c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 2 Jul 2020 14:38:00 -0400 Subject: [PATCH 38/87] Add /= operator --- src/DataSet_3D.h | 2 ++ src/DataSet_GridDbl.h | 5 +++++ src/DataSet_GridFlt.h | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/src/DataSet_3D.h b/src/DataSet_3D.h index 324236ed3e..0310fa0a16 100644 --- a/src/DataSet_3D.h +++ b/src/DataSet_3D.h @@ -32,6 +32,8 @@ class DataSet_3D : public DataSet { virtual void ReverseIndex(long int, size_t&, size_t&, size_t&) const = 0; /// Increment specified voxel by given amount. virtual void UpdateVoxel(long int, double) = 0; + /// Divide all elements by the given scalar + virtual void operator/=(double) = 0; // ------------------------------------------- // TODO: Remove this. Only needed by DataSet_1D.h void Add(size_t,const void*) { } diff --git a/src/DataSet_GridDbl.h b/src/DataSet_GridDbl.h index 3fb10cd26a..4c8dce7d1e 100644 --- a/src/DataSet_GridDbl.h +++ b/src/DataSet_GridDbl.h @@ -32,6 +32,11 @@ class DataSet_GridDbl : public DataSet_3D { void ReverseIndex(long int n, size_t& i, size_t& j, size_t& k) const { return grid_.ReverseIndex(n,i,j,k); } void UpdateVoxel(long int i, double val) { grid_[i] += val; } + /// Divide all elements by val + void operator/=(double val) { + for (Grid::iterator it = grid_.begin(); it != grid_.end(); ++it) + (*it) /= val; + } // ------------------------------------------- void SetElement(size_t x,size_t y,size_t z,double v) { grid_.setGrid(x,y,z,v); } /// Type definition of iterator over grid elements. diff --git a/src/DataSet_GridFlt.h b/src/DataSet_GridFlt.h index 4f8ca9aedf..d59ae70465 100644 --- a/src/DataSet_GridFlt.h +++ b/src/DataSet_GridFlt.h @@ -32,6 +32,12 @@ class DataSet_GridFlt : public DataSet_3D { void ReverseIndex(long int n, size_t& i, size_t& j, size_t& k) const { return grid_.ReverseIndex(n,i,j,k); } void UpdateVoxel(long int i, double val) { grid_[i] += (float)val; } + /// Divide all elements by val + void operator/=(double val) { + float fval = (float)val; + for (Grid::iterator it = grid_.begin(); it != grid_.end(); ++it) + (*it) /= fval; + } // ------------------------------------------- void SetElement(size_t x,size_t y,size_t z,float v) { grid_.setGrid(x,y,z,v); } /// Type definition of iterator over grid elements. From b2bb4ac4e60617bbc523b7895f97594a0473c4df Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 2 Jul 2020 15:00:54 -0400 Subject: [PATCH 39/87] Add IncrementElement() function --- src/DataSet_3D.h | 2 ++ src/DataSet_GridDbl.h | 26 +++++++++++++------------- src/DataSet_GridFlt.h | 27 ++++++++++++++------------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/DataSet_3D.h b/src/DataSet_3D.h index 0310fa0a16..78a0668239 100644 --- a/src/DataSet_3D.h +++ b/src/DataSet_3D.h @@ -18,6 +18,8 @@ class DataSet_3D : public DataSet { int Allocate(SizeArray const&) { return 1; } // TODO enable? /// \return Data from grid at x/y/z point. virtual double GetElement(size_t, size_t, size_t) const = 0; + /// Increment the specified grid point by value + virtual void IncrementElement(size_t, size_t, size_t, double) = 0; /// \return Data from grid. virtual double operator[](size_t) const = 0; /// \return size of X dimension. diff --git a/src/DataSet_GridDbl.h b/src/DataSet_GridDbl.h index 4c8dce7d1e..4d8f61481e 100644 --- a/src/DataSet_GridDbl.h +++ b/src/DataSet_GridDbl.h @@ -11,6 +11,18 @@ class DataSet_GridDbl : public DataSet_3D { double& operator[](size_t idx) { return grid_[idx]; } static DataSet* Alloc() { return (DataSet*)new DataSet_GridDbl(); } Grid const& InternalGrid() const { return grid_; } + void SetElement(size_t x,size_t y,size_t z,double v) { grid_.setGrid(x,y,z,v); } + /// Type definition of iterator over grid elements. + typedef Grid::iterator iterator; + iterator begin() { return grid_.begin(); } + iterator end() { return grid_.end(); } + /// Increment grid bin corresponding to point by given value. + inline long int Increment(Vec3 const&, double); + inline long int Increment(const double*, double); + /// Increment grid bin by given value. + inline long int Increment(size_t,size_t,size_t,double); + /// \return grid value at specified bin. + double GridVal(size_t x,size_t y,size_t z) const { return grid_.element(x,y,z); } // ----- DataSet functions ------------------- size_t Size() const { return grid_.size(); } # ifdef MPI @@ -23,6 +35,7 @@ class DataSet_GridDbl : public DataSet_3D { // ----- DataSet_3D functions ---------------- int Allocate3D(size_t x,size_t y,size_t z) { return grid_.resize(x,y,z); } double GetElement(size_t x,size_t y,size_t z) const { return grid_.element(x,y,z); } + void IncrementElement(size_t x, size_t y, size_t z, double val) { Increment(x,y,z,val); } double operator[](size_t idx) const { return grid_[idx]; } size_t NX() const { return grid_.NX(); } size_t NY() const { return grid_.NY(); } @@ -37,19 +50,6 @@ class DataSet_GridDbl : public DataSet_3D { for (Grid::iterator it = grid_.begin(); it != grid_.end(); ++it) (*it) /= val; } - // ------------------------------------------- - void SetElement(size_t x,size_t y,size_t z,double v) { grid_.setGrid(x,y,z,v); } - /// Type definition of iterator over grid elements. - typedef Grid::iterator iterator; - iterator begin() { return grid_.begin(); } - iterator end() { return grid_.end(); } - /// Increment grid bin corresponding to point by given value. - inline long int Increment(Vec3 const&, double); - inline long int Increment(const double*, double); - /// Increment grid bin by given value. - inline long int Increment(size_t,size_t,size_t,double); - /// \return grid value at specified bin. - double GridVal(size_t x,size_t y,size_t z) const { return grid_.element(x,y,z); } private: Grid grid_; }; diff --git a/src/DataSet_GridFlt.h b/src/DataSet_GridFlt.h index d59ae70465..5babcc5bf2 100644 --- a/src/DataSet_GridFlt.h +++ b/src/DataSet_GridFlt.h @@ -11,6 +11,18 @@ class DataSet_GridFlt : public DataSet_3D { float& operator[](size_t idx) { return grid_[idx]; } static DataSet* Alloc() { return (DataSet*)new DataSet_GridFlt(); } Grid const& InternalGrid() const { return grid_; } + void SetElement(size_t x,size_t y,size_t z,float v) { grid_.setGrid(x,y,z,v); } + /// Type definition of iterator over grid elements. + typedef Grid::iterator iterator; + iterator begin() { return grid_.begin(); } + iterator end() { return grid_.end(); } + /// Increment grid bin corresponding to point by given value. + inline long int Increment(Vec3 const&, float); + inline long int Increment(const double*, float); + /// Increment grid bin by given value. + inline long int Increment(size_t,size_t,size_t,float); + /// \return grid value at specified bin. + float GridVal(size_t x,size_t y,size_t z) const { return grid_.element(x,y,z); } // ----- DataSet functions ------------------- size_t Size() const { return grid_.size(); } # ifdef MPI @@ -23,6 +35,7 @@ class DataSet_GridFlt : public DataSet_3D { // ----- DataSet_3D functions ---------------- int Allocate3D(size_t x, size_t y, size_t z) { return grid_.resize(x,y,z); } double GetElement(size_t x, size_t y, size_t z) const { return (double)grid_.element(x,y,z); } + void IncrementElement(size_t x, size_t y, size_t z, double val) { Increment(x, y, z, (float)val); } double operator[](size_t idx) const { return (double)grid_[idx]; } size_t NX() const { return grid_.NX(); } size_t NY() const { return grid_.NY(); } @@ -38,19 +51,7 @@ class DataSet_GridFlt : public DataSet_3D { for (Grid::iterator it = grid_.begin(); it != grid_.end(); ++it) (*it) /= fval; } - // ------------------------------------------- - void SetElement(size_t x,size_t y,size_t z,float v) { grid_.setGrid(x,y,z,v); } - /// Type definition of iterator over grid elements. - typedef Grid::iterator iterator; - iterator begin() { return grid_.begin(); } - iterator end() { return grid_.end(); } - /// Increment grid bin corresponding to point by given value. - inline long int Increment(Vec3 const&, float); - inline long int Increment(const double*, float); - /// Increment grid bin by given value. - inline long int Increment(size_t,size_t,size_t,float); - /// \return grid value at specified bin. - float GridVal(size_t x,size_t y,size_t z) const { return grid_.element(x,y,z); } + private: Grid grid_; }; From 3b02f60d5234484d43845965774f18d67ce23805 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 2 Jul 2020 15:37:06 -0400 Subject: [PATCH 40/87] Add SetGrid function --- src/DataSet_3D.h | 2 ++ src/DataSet_GridDbl.h | 1 + src/DataSet_GridFlt.h | 1 + 3 files changed, 4 insertions(+) diff --git a/src/DataSet_3D.h b/src/DataSet_3D.h index 78a0668239..8fd26d3130 100644 --- a/src/DataSet_3D.h +++ b/src/DataSet_3D.h @@ -18,6 +18,8 @@ class DataSet_3D : public DataSet { int Allocate(SizeArray const&) { return 1; } // TODO enable? /// \return Data from grid at x/y/z point. virtual double GetElement(size_t, size_t, size_t) const = 0; + /// Set grid to value + virtual void SetGrid(size_t, size_t, size_t, double) = 0; /// Increment the specified grid point by value virtual void IncrementElement(size_t, size_t, size_t, double) = 0; /// \return Data from grid. diff --git a/src/DataSet_GridDbl.h b/src/DataSet_GridDbl.h index 4d8f61481e..ab471a1ea5 100644 --- a/src/DataSet_GridDbl.h +++ b/src/DataSet_GridDbl.h @@ -35,6 +35,7 @@ class DataSet_GridDbl : public DataSet_3D { // ----- DataSet_3D functions ---------------- int Allocate3D(size_t x,size_t y,size_t z) { return grid_.resize(x,y,z); } double GetElement(size_t x,size_t y,size_t z) const { return grid_.element(x,y,z); } + void SetGrid(size_t x, size_t y, size_t z, double d) { grid_.setGrid(x,y,z,d); } void IncrementElement(size_t x, size_t y, size_t z, double val) { Increment(x,y,z,val); } double operator[](size_t idx) const { return grid_[idx]; } size_t NX() const { return grid_.NX(); } diff --git a/src/DataSet_GridFlt.h b/src/DataSet_GridFlt.h index 5babcc5bf2..a4bc23051a 100644 --- a/src/DataSet_GridFlt.h +++ b/src/DataSet_GridFlt.h @@ -35,6 +35,7 @@ class DataSet_GridFlt : public DataSet_3D { // ----- DataSet_3D functions ---------------- int Allocate3D(size_t x, size_t y, size_t z) { return grid_.resize(x,y,z); } double GetElement(size_t x, size_t y, size_t z) const { return (double)grid_.element(x,y,z); } + void SetGrid(size_t x, size_t y, size_t z, double d) { grid_.setGrid(x,y,z,d); } void IncrementElement(size_t x, size_t y, size_t z, double val) { Increment(x, y, z, (float)val); } double operator[](size_t idx) const { return (double)grid_[idx]; } size_t NX() const { return grid_.NX(); } From 64572020d017eabb20116c6236d6336eeec6e9d6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 2 Jul 2020 15:38:47 -0400 Subject: [PATCH 41/87] Change SetGrid to accept index instead --- src/DataSet_3D.h | 2 +- src/DataSet_GridDbl.h | 2 +- src/DataSet_GridFlt.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DataSet_3D.h b/src/DataSet_3D.h index 8fd26d3130..7967f48772 100644 --- a/src/DataSet_3D.h +++ b/src/DataSet_3D.h @@ -19,7 +19,7 @@ class DataSet_3D : public DataSet { /// \return Data from grid at x/y/z point. virtual double GetElement(size_t, size_t, size_t) const = 0; /// Set grid to value - virtual void SetGrid(size_t, size_t, size_t, double) = 0; + virtual void SetGrid(size_t, double) = 0; /// Increment the specified grid point by value virtual void IncrementElement(size_t, size_t, size_t, double) = 0; /// \return Data from grid. diff --git a/src/DataSet_GridDbl.h b/src/DataSet_GridDbl.h index ab471a1ea5..4ebe9614d3 100644 --- a/src/DataSet_GridDbl.h +++ b/src/DataSet_GridDbl.h @@ -35,7 +35,7 @@ class DataSet_GridDbl : public DataSet_3D { // ----- DataSet_3D functions ---------------- int Allocate3D(size_t x,size_t y,size_t z) { return grid_.resize(x,y,z); } double GetElement(size_t x,size_t y,size_t z) const { return grid_.element(x,y,z); } - void SetGrid(size_t x, size_t y, size_t z, double d) { grid_.setGrid(x,y,z,d); } + void SetGrid(size_t idx, double d) { grid_[idx] = d; } void IncrementElement(size_t x, size_t y, size_t z, double val) { Increment(x,y,z,val); } double operator[](size_t idx) const { return grid_[idx]; } size_t NX() const { return grid_.NX(); } diff --git a/src/DataSet_GridFlt.h b/src/DataSet_GridFlt.h index a4bc23051a..cb7169b364 100644 --- a/src/DataSet_GridFlt.h +++ b/src/DataSet_GridFlt.h @@ -35,7 +35,7 @@ class DataSet_GridFlt : public DataSet_3D { // ----- DataSet_3D functions ---------------- int Allocate3D(size_t x, size_t y, size_t z) { return grid_.resize(x,y,z); } double GetElement(size_t x, size_t y, size_t z) const { return (double)grid_.element(x,y,z); } - void SetGrid(size_t x, size_t y, size_t z, double d) { grid_.setGrid(x,y,z,d); } + void SetGrid(size_t idx, double d) { grid_[idx] = d; } void IncrementElement(size_t x, size_t y, size_t z, double val) { Increment(x, y, z, (float)val); } double operator[](size_t idx) const { return (double)grid_[idx]; } size_t NX() const { return grid_.NX(); } From c7801e32e86cbfbdb4f212dc8f81f1066b58462b Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 2 Jul 2020 15:47:40 -0400 Subject: [PATCH 42/87] Enable DIV and MULT for grids --- src/RPNcalc.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/RPNcalc.cpp b/src/RPNcalc.cpp index 9fe5d3b061..d591a6022a 100644 --- a/src/RPNcalc.cpp +++ b/src/RPNcalc.cpp @@ -763,7 +763,11 @@ int RPNcalc::TokenLoop(DataSetList& DSL) const { { DataSet_3D const& G1 = static_cast( *ds1 ); DataSet_3D const& G2 = static_cast( *ds2 ); - if (T->Type() == OP_MINUS || T->Type() == OP_PLUS) { + if (T->Type() == OP_MINUS || + T->Type() == OP_PLUS || + T->Type() == OP_DIV || + T->Type() == OP_MULT) + { if (G1.NX() != G2.NX() || G1.NY() != G2.NY() || G1.NZ() != G2.NZ()) { mprinterr("Error: Grid operation '%s' requires both grids have" " same dimensions.\n", T->Description()); From cc3c0bf9671c0c84745662dca1592d7c71b00289 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 2 Jul 2020 15:48:08 -0400 Subject: [PATCH 43/87] Add option to read grids in as double precision --- src/DataIO_OpenDx.cpp | 29 +++++++++++++++++++++++++---- src/DataIO_OpenDx.h | 5 +++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/DataIO_OpenDx.cpp b/src/DataIO_OpenDx.cpp index bbbd63662b..5d6020511e 100644 --- a/src/DataIO_OpenDx.cpp +++ b/src/DataIO_OpenDx.cpp @@ -6,6 +6,12 @@ #include "BufferedLine.h" #include "ProgressBar.h" +DataIO_OpenDx::DataIO_OpenDx() : + DataIO(false, false, true), // Valid for 3D only + gridWriteMode_(BIN_CORNER), + gridReadType_(DataSet::GRID_FLT) +{} + bool DataIO_OpenDx::ID_DataFormat( CpptrajFile& infile ) { bool isDX = false; if (!infile.OpenFile()) { @@ -17,13 +23,29 @@ bool DataIO_OpenDx::ID_DataFormat( CpptrajFile& infile ) { return isDX; } +/** Process read options. */ +int DataIO_OpenDx::processReadArgs(ArgList& argIn) { + std::string typestr = argIn.GetStringKey("type"); + if (!typestr.empty()) { + if (typestr == "float") + gridReadType_ = DataSet::GRID_FLT; + else if (typestr == "double") + gridReadType_ = DataSet::GRID_DBL; + else { + mprinterr("Error: Unrecognized grid type: %s\n", typestr.c_str()); + return 1; + } + } + return 0; +} + // DataIO_OpenDx::ReadData() int DataIO_OpenDx::ReadData(FileName const& fname, DataSetList& datasetlist, std::string const& dsname) { // TODO append? // Add grid data set. Default to float for now. - DataSet* ds = datasetlist.AddSet( DataSet::GRID_FLT, dsname, "GRID" ); + DataSet* ds = datasetlist.AddSet( gridReadType_, dsname, "GRID" ); if (ds==0) return 1; if (LoadGrid(fname.full(), *ds)) { // Load failed. Erase grid data set. @@ -36,8 +58,7 @@ int DataIO_OpenDx::ReadData(FileName const& fname, // DataIO_OpenDx::LoadGrid() int DataIO_OpenDx::LoadGrid(const char* filename, DataSet& ds) { - // TODO: This may need to be changed if new 3D types introduced. - DataSet_GridFlt& grid = static_cast( ds ); + DataSet_3D& grid = static_cast( ds ); // Open file BufferedLine infile; if (infile.OpenFileRead(filename)) return 1; @@ -145,7 +166,7 @@ int DataIO_OpenDx::LoadGrid(const char* filename, DataSet& ds) mprintf("Warning: Check that data region ends with a newline.\n"); break; } - grid[ndata++] = (float)atof(infile.NextToken()); + grid.SetGrid(ndata++, atof(infile.NextToken())); } progress.Update( ndata ); } diff --git a/src/DataIO_OpenDx.h b/src/DataIO_OpenDx.h index 306b50dd6a..66bea80ef3 100644 --- a/src/DataIO_OpenDx.h +++ b/src/DataIO_OpenDx.h @@ -4,9 +4,9 @@ /// Write OpenDx format data files. class DataIO_OpenDx : public DataIO { public: - DataIO_OpenDx() : DataIO(false, false, true), gridWriteMode_(BIN_CORNER) {} // Valid for 3D only + DataIO_OpenDx(); static BaseIOtype* Alloc() { return (BaseIOtype*)new DataIO_OpenDx(); } - int processReadArgs(ArgList&) { return 0; } + int processReadArgs(ArgList&); int ReadData(FileName const&, DataSetList&, std::string const&); static void WriteHelp(); int processWriteArgs(ArgList&); @@ -22,5 +22,6 @@ class DataIO_OpenDx : public DataIO { int WriteGrid(DataSet const&, CpptrajFile&) const; GridWriteType gridWriteMode_; + DataSet::DataType gridReadType_; }; #endif From d671a35759601dc8b4343d3b2806268f08dbfd92 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 7 Jul 2020 08:56:16 -0400 Subject: [PATCH 44/87] Add function to return format type --- src/TextFormat.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TextFormat.h b/src/TextFormat.h index 6fa91eb521..8c3c6cd49e 100644 --- a/src/TextFormat.h +++ b/src/TextFormat.h @@ -51,6 +51,7 @@ class TextFormat { /// \return pointer to format string. const char* fmt() const { return fmt_.c_str(); } std::string const& Fmt() const { return fmt_; } + FmtType FormatType() const { return type_; } int Width() const { return width_; } int Precision() const { return precision_; } int ColumnWidth() const { return colwidth_; } From 7b792ce9b088e40eba9daa923d35ffe2004825d8 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 7 Jul 2020 09:22:52 -0400 Subject: [PATCH 45/87] Add == operator for TextFormat --- src/TextFormat.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/TextFormat.h b/src/TextFormat.h index 8c3c6cd49e..b665021b93 100644 --- a/src/TextFormat.h +++ b/src/TextFormat.h @@ -55,6 +55,11 @@ class TextFormat { int Width() const { return width_; } int Precision() const { return precision_; } int ColumnWidth() const { return colwidth_; } + /// \return True if given TextFormat matches this format type, width, and precision. + bool operator=(TextFormat const& rhs) { + return ( (type_ == rhs.type_) && (width_ == rhs.width_) && (precision_ == rhs.precision_) ); + } + /// \return Description of the given format type. static const char* typeDescription(FmtType f) { return TypeDesc_[f]; } private: static inline bool IsDoubleType(FmtType); From e892edb2fe2c2b767861c3f67eb00a12abd260d8 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 7 Jul 2020 09:32:08 -0400 Subject: [PATCH 46/87] Fix the operator --- src/TextFormat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TextFormat.h b/src/TextFormat.h index b665021b93..7998b3624a 100644 --- a/src/TextFormat.h +++ b/src/TextFormat.h @@ -56,7 +56,7 @@ class TextFormat { int Precision() const { return precision_; } int ColumnWidth() const { return colwidth_; } /// \return True if given TextFormat matches this format type, width, and precision. - bool operator=(TextFormat const& rhs) { + bool operator==(TextFormat const& rhs) const { return ( (type_ == rhs.type_) && (width_ == rhs.width_) && (precision_ == rhs.precision_) ); } /// \return Description of the given format type. From 1f0dd511423809d36b755a1df503f16127a3a375 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 7 Jul 2020 09:40:05 -0400 Subject: [PATCH 47/87] Ensure debug level is set for files being written --- src/DataFile.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DataFile.cpp b/src/DataFile.cpp index ea66efd685..6074f00472 100644 --- a/src/DataFile.cpp +++ b/src/DataFile.cpp @@ -272,6 +272,7 @@ int DataFile::SetupDatafile(FileName const& fnameIn, ArgList& argIn, // Set up DataIO based on format. dataio_ = (DataIO*)FileTypes::AllocIO( DF_AllocArray, dfType_, false ); if (dataio_ == 0) return Error("Error: Data file allocation failed.\n"); + dataio_->SetDebug( debug_ ); # ifdef MPI // Default to TrajComm master can write. threadCanWrite_ = Parallel::TrajComm().Master(); From e1802255da988dcba51fc7dd499a79085888c1cc Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 7 Jul 2020 09:49:03 -0400 Subject: [PATCH 48/87] When writing opendx files, if the format is still the default for grids, use general format (matches previous behavior). However, if another format has been set use that instead. --- src/DataIO_OpenDx.cpp | 70 +++++++++++++++++++++++++++++++++++++------ src/DataIO_OpenDx.h | 3 ++ src/cpptrajdepend | 4 +-- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/DataIO_OpenDx.cpp b/src/DataIO_OpenDx.cpp index 5d6020511e..74d4b0d973 100644 --- a/src/DataIO_OpenDx.cpp +++ b/src/DataIO_OpenDx.cpp @@ -2,7 +2,8 @@ #include // atof #include "DataIO_OpenDx.h" #include "CpptrajStdio.h" -#include "DataSet_GridFlt.h" +#include "DataSet_GridFlt.h" // Included to get default format +#include "DataSet_GridDbl.h" // Included to get default format #include "BufferedLine.h" #include "ProgressBar.h" @@ -10,7 +11,15 @@ DataIO_OpenDx::DataIO_OpenDx() : DataIO(false, false, true), // Valid for 3D only gridWriteMode_(BIN_CORNER), gridReadType_(DataSet::GRID_FLT) -{} +{ + // Get the default formats for float/double grid datasets + DataSet* ds = new DataSet_GridFlt(); + fmt_gridFlt_ = ds->Format(); + delete ds; + ds = new DataSet_GridDbl(); + fmt_gridDbl_ = ds->Format(); + delete ds; +} bool DataIO_OpenDx::ID_DataFormat( CpptrajFile& infile ) { bool isDX = false; @@ -181,6 +190,7 @@ void DataIO_OpenDx::WriteHelp() { "\tgridext: Like 'bincenter', but also print extra layer of empty bins.\n"); } +/** Process opendx write options. */ int DataIO_OpenDx::processWriteArgs(ArgList& argIn) { if (argIn.hasKey("bincenter")) gridWriteMode_ = BIN_CENTER; else if (argIn.hasKey("gridwrap")) gridWriteMode_ = WRAP; @@ -240,6 +250,7 @@ int DataIO_OpenDx::WriteSet3D(DataSet const& setIn, CpptrajFile& outfile) const return err; } +/** Write the header for an OpenDX file. */ void DataIO_OpenDx::WriteDxHeader(CpptrajFile& outfile, size_t NX, size_t NY, size_t NZ, double LX, double LY, double LZ, @@ -256,8 +267,36 @@ void DataIO_OpenDx::WriteDxHeader(CpptrajFile& outfile, NX, NY, NZ, NX*NY*NZ); } +/** Create a text format string using the given TextFormat. If the default + * %12.4f is in use, upgrade it to a general format. + */ +std::string DataIO_OpenDx::CreateFmtString(DataSet::DataType typeIn, + TextFormat const& fmtIn) const +{ + TextFormat fmtOut; + bool usingDefaultFmt = false; + if ( typeIn == DataSet::GRID_FLT ) { + usingDefaultFmt = (fmtIn == fmt_gridFlt_); + } else if ( typeIn == DataSet::GRID_DBL ) { + usingDefaultFmt = (fmtIn == fmt_gridDbl_); + } else { + mprinterr("Internal Error: Unhandled type in CreateFmtString(): %s\n", + DataSet::description(typeIn)); + return std::string(); + } + if (usingDefaultFmt) + fmtOut = TextFormat(TextFormat::GDOUBLE, -1, -1); + else + fmtOut = TextFormat(fmtIn.FormatType(), fmtIn.Width(), fmtIn.Precision()); + return fmtOut.Fmt(); +} + +/** Write the grid wrapped. */ int DataIO_OpenDx::WriteGridWrap(DataSet const& setIn, CpptrajFile& outfile) const { DataSet_3D const& set = static_cast( setIn ); + std::string myFmt = CreateFmtString( setIn.Type(), setIn.Format() ); + if (myFmt.empty()) return 1; + myFmt = " " + myFmt; // Need to construct a grid mesh around bins, with points centered on the bins. int mesh_x = set.NX(); int mesh_y = set.NY(); @@ -284,7 +323,7 @@ int DataIO_OpenDx::WriteGridWrap(DataSet const& setIn, CpptrajFile& outfile) con if (ik < 0 ) bk = mesh_z - 1; else if (ik == mesh_z) bk = 0; else bk = ik; - outfile.Printf(" %g", set.GetElement(bi, bj, bk)); + outfile.Printf(myFmt.c_str(), set.GetElement(bi, bj, bk)); ++nvals; if (nvals == 5) { outfile.Printf("\n"); @@ -302,7 +341,7 @@ int DataIO_OpenDx::WriteGridWrap(DataSet const& setIn, CpptrajFile& outfile) con if (zero_x || zero_y || ik < 0 || ik == mesh_z) outfile.Printf(" 0"); else - outfile.Printf(" %g", set.GetElement(ii, ij, ik)); + outfile.Printf(myFmt.c_str(), set.GetElement(ii, ij, ik)); ++nvals; if (nvals == 5) { outfile.Printf("\n"); @@ -316,8 +355,21 @@ int DataIO_OpenDx::WriteGridWrap(DataSet const& setIn, CpptrajFile& outfile) con return 0; } +/** Write the grid normally. */ int DataIO_OpenDx::WriteGrid(DataSet const& setIn, CpptrajFile& outfile) const { DataSet_3D const& set = static_cast( setIn ); + std::string myFmt = CreateFmtString( setIn.Type(), setIn.Format() ); + if (myFmt.empty()) return 1; + std::string myFmt2 = myFmt + " " + myFmt; + std::string myFmt3 = myFmt + " " + myFmt + " " + myFmt; + if (debug_ > 0) { + mprintf("DEBUG: Grid data %s format is \"%s\"\n", set.legend(), set.Format().fmt()); + mprintf("DEBUG: New formats are \"%s\" \"%s\" \"%s\"\n", + myFmt.c_str(), myFmt2.c_str(), myFmt3.c_str()); + } + myFmt.append("\n"); + myFmt2.append("\n"); + myFmt3.append("\n"); Vec3 oxyz = set.Bin().GridOrigin(); if (gridWriteMode_ == BIN_CENTER) // Origin needs to be shifted to center of bin located at 0,0,0 @@ -328,18 +380,18 @@ int DataIO_OpenDx::WriteGrid(DataSet const& setIn, CpptrajFile& outfile) const { // Now print out the data. size_t gridsize = set.Size(); if (gridsize == 1) - outfile.Printf("%g\n", set[0]); + outfile.Printf(myFmt.c_str(), set[0]); else if (gridsize == 2) - outfile.Printf("%g %g\n", set[0], set[1]); + outfile.Printf(myFmt2.c_str(), set[0], set[1]); else if (gridsize > 2) { // Data is already in row-major form (z-axis changes // fastest), so no need to do any kind of data adjustment for (size_t i = 0UL; i < gridsize - 2UL; i += 3UL) - outfile.Printf("%g %g %g\n", set[i], set[i+1], set[i+2]); + outfile.Printf(myFmt3.c_str(), set[i], set[i+1], set[i+2]); // Print out any points we may have missed switch (gridsize % 3) { - case 2: outfile.Printf("%g %g\n", set[gridsize-2], set[gridsize-1]); break; - case 1: outfile.Printf("%g\n", set[gridsize-1]); break; + case 2: outfile.Printf(myFmt2.c_str(), set[gridsize-2], set[gridsize-1]); break; + case 1: outfile.Printf(myFmt.c_str(), set[gridsize-1]); break; } } return 0; diff --git a/src/DataIO_OpenDx.h b/src/DataIO_OpenDx.h index 66bea80ef3..cae0cfcf00 100644 --- a/src/DataIO_OpenDx.h +++ b/src/DataIO_OpenDx.h @@ -18,10 +18,13 @@ class DataIO_OpenDx : public DataIO { int WriteSet3D(DataSet const&, CpptrajFile&) const; void WriteDxHeader(CpptrajFile&, size_t, size_t, size_t, double, double, double, Matrix_3x3 const&, Vec3 const&) const; + std::string CreateFmtString(DataSet::DataType, TextFormat const&) const; int WriteGridWrap(DataSet const&, CpptrajFile&) const; int WriteGrid(DataSet const&, CpptrajFile&) const; GridWriteType gridWriteMode_; DataSet::DataType gridReadType_; + TextFormat fmt_gridFlt_; ///< Format for DataSet_GridFlt + TextFormat fmt_gridDbl_; ///< Format for DataSet_GridDbl }; #endif diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 3ef5965869..37536ca8d5 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -83,7 +83,7 @@ Action_Unstrip.o : Action_Unstrip.cpp Action.h ActionState.h Action_Unstrip.h Ar Action_Unwrap.o : Action_Unwrap.cpp Action.h ActionState.h Action_Unwrap.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h ImageRoutines.h ImageTypes.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_Vector.o : Action_Vector.cpp Action.h ActionState.h Action_Vector.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_VelocityAutoCorr.o : Action_VelocityAutoCorr.cpp Action.h ActionState.h Action_VelocityAutoCorr.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h ComplexArray.h Constants.h CoordinateInfo.h Corr.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector.h DataSet_double.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h PubFFT.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h -Action_Volmap.o : Action_Volmap.cpp Action.h ActionState.h Action_Volmap.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridFlt.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SplineFxnTable.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h +Action_Volmap.o : Action_Volmap.cpp Action.h ActionState.h Action_Volmap.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridDbl.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SplineFxnTable.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_Volume.o : Action_Volume.cpp Action.h ActionState.h Action_Volume.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImagedAction.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_Watershell.o : Action_Watershell.cpp Action.h ActionState.h Action_Watershell.h ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageRoutines.h ImageTypes.h ImagedAction.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h Action_XtalSymm.o : Action_XtalSymm.cpp Action.h ActionState.h Action_XtalSymm.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SpaceGroup.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h @@ -185,7 +185,7 @@ DataIO_Gnuplot.o : DataIO_Gnuplot.cpp ArgList.h Array1D.h AssociatedData.h Atom. DataIO_Grace.o : DataIO_Grace.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Grace.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h DataSet_string.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_Mdout.o : DataIO_Mdout.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Mdout.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_NC_Cmatrix.o : DataIO_NC_Cmatrix.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterDist.h ClusterSieve.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_NC_Cmatrix.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Cmatrix.h DataSet_Cmatrix_MEM.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h FileIO.h FileName.h Frame.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Cmatrix.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h -DataIO_OpenDx.o : DataIO_OpenDx.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_OpenDx.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridFlt.h Dimension.h FileIO.h FileName.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h +DataIO_OpenDx.o : DataIO_OpenDx.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_OpenDx.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridDbl.h DataSet_GridFlt.h Dimension.h FileIO.h FileName.h Frame.h Grid.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_Peaks.o : DataIO_Peaks.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Peaks.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Vector_Scalar.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_RemLog.o : DataIO_RemLog.cpp ArgList.h AssociatedData.h Atom.h AtomExtra.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_RemLog.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_RemLog.h Dimension.h FileIO.h FileName.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ProgressBar.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h DataIO_Std.o : DataIO_Std.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomExtra.h AtomMap.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h ClusterDist.h ClusterSieve.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Std.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Cmatrix.h DataSet_Cmatrix_MEM.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Mat3x3.h DataSet_Vector.h DataSet_double.h DataSet_float.h DataSet_integer.h DataSet_string.h Dimension.h FileIO.h FileName.h Frame.h GridBin.h Hungarian.h MapAtom.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h StringRoutines.h SymbolExporting.h SymmetricRmsdCalc.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Vec3.h From 912fd05e217647bacdff83eba1ffbab15a270394 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 9 Jul 2020 13:31:48 -0400 Subject: [PATCH 49/87] Add check for out of range value in Yval(). Save input X values for use in a more accurate function, Yval_accurate(). --- src/SplineFxnTable.cpp | 46 +++++++++++++++++++++++++++++++++++++----- src/SplineFxnTable.h | 24 +++++++++++++++++----- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index 50db5b3c09..b93fd1ff4e 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -29,23 +29,24 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m mprinterr("Error: Max %g is not larger than min %g\n", Xmax_, Xmin_); return 1; } - // Calculate table size unsigned int TableSize = (unsigned int)(one_over_Dx_ * width * scale); + mprintf("DEBUG: Table from %g to %g (%gx), width is %g table size %u\n", minIn, maxIn, scale, width, TableSize); - Darray Xvals, Yvals; - Xvals.reserve( TableSize ); + Xvals_.clear(); + Darray Yvals; + Xvals_.reserve( TableSize ); Yvals.reserve( TableSize ); // Save X and Y values so we can calc the spline coefficients double xval = Xmin_; for (unsigned int i = 0; i != TableSize; i++) { double yval = fxnIn( xval ); - Xvals.push_back( xval ); + Xvals_.push_back( xval ); Yvals.push_back( yval ); xval += Dx_; } Spline cspline; - cspline.CubicSpline_Coeff(Xvals, Yvals); + cspline.CubicSpline_Coeff(Xvals_, Yvals); //Xvals.clear(); // Store values in Spline table table_.clear(); @@ -61,3 +62,38 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m ByteString(table_.size() * sizeof(double), BYTE_DECIMAL).c_str()); return 0; } + +double SplineFxnTable::Yval_accurate(double xIn) const { + // Find X value + int ind = 0; + int low = 0; + int high = Xvals_.size() - 1; + + // Assumptions for Xvals_: > 1 value, monotonic, ascending order + if (xIn < Xvals_.front()) + ind = -1; + else if (xIn > Xvals_.back()) + ind = high; + else { + while (low <= high) { + ind = (low + high) / 2; + if (xIn < Xvals_[ind]) { + high = ind - 1; + } else if (xIn > Xvals_[ind + 1]) { + low = ind + 1; + } else { + //return ind; + break; + } + } + } + + if (ind < 0) { + ind = 0; + } else if ((unsigned int)ind > Xvals_.size() - 2) { + ind = Xvals_.size() - 1; + } + double dx = xIn - Xvals_[ind]; + int xidx = ind * 4; + return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); +} diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index 7c9f50bf8a..fbd9b707c4 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -1,7 +1,7 @@ #ifndef INC_SPLINEFXNTABLE_H #define INC_SPLINEFXNTABLE_H #include -//#inc lude "CpptrajStdio.h" // DEBUG +//#incl ude "CpptrajStdio.h" // DEBUG /// Can be used to approximate a function using cubic splines. class SplineFxnTable { public: @@ -13,16 +13,29 @@ class SplineFxnTable { int FillTable(FxnType, double, double, double, double); /// \return Approximated Y value from given X value. double Yval(double xIn) const { - double Xval = xIn - Xmin_; - int xidx = ((int)(one_over_Dx_ * Xval)); - double dx = Xval - ((double)xidx * Dx_); + double xval = xIn - Xmin_; + long int xidx = ((long int)(one_over_Dx_ * xval)); + // Delta from index + double dx = xval - ((double)xidx * Dx_); + // Index into the table xidx *= 4; // DEBUG //if (xidx < 0 || xidx >= (int)table_.size()) - // mprinterr("Error: index %i out of range for X val %g\n", xidx, xIn); + // mprinterr("Error: index %li out of range (%zu) for X val %g (Xmin= %g 1/dx= %g)\n", xidx, table_.size(), xIn, Xmin_, one_over_Dx_); + // Protect against out of range values + if (xidx >= (long int)table_.size()) + xidx = table_.size() - 4; + else if (xidx < 0) + xidx = 0; + return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } + + double Yval_accurate(double) const; + + // DEBUG Access to internal table + std::vector const& InternalTable() const { return table_; } private: typedef std::vector Darray; @@ -31,5 +44,6 @@ class SplineFxnTable { double Xmin_; ///< Minimum value for which function can be approximated double Xmax_; ///< Maximum value for which function can be approximated Darray table_; ///< Hold Y followed by spline B C D coefficients + Darray Xvals_; ///< Hold X values }; #endif From a9579950742dfb283baddd2fe0216aaf53a576a0 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 9 Jul 2020 15:41:06 -0400 Subject: [PATCH 50/87] Add another way of filling the table; can give better results with Yvals_accurate() --- src/SplineFxnTable.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++ src/SplineFxnTable.h | 4 +++ 2 files changed, 62 insertions(+) diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index b93fd1ff4e..9b85e919e4 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -63,6 +63,64 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m return 0; } +/** Fill the spline function table with values from the given function. */ +int SplineFxnTable::FillTable(FxnType fxnIn, int mesh_size, double minIn, double maxIn) +{ + if (mesh_size < 2) { + mprinterr("Error: Invalid mesh size: %i\n", mesh_size); + return 1; + } + Xmax_ = maxIn; + Xmin_ = minIn; + double width = Xmax_ - Xmin_; + if (width < Constants::SMALL) { + mprinterr("Error: Max %g is not larger than min %g\n", Xmax_, Xmin_); + return 1; + } + + + Dx_ = (maxIn - minIn) / (double)mesh_size; + if (Dx_ < Constants::SMALL) { + mprinterr("Error: Spacing for spline table too small or negative.\n"); + return 1; + } + one_over_Dx_ = 1.0 / Dx_; + + // Save X and Y values so we can calc the spline coefficients + Xvals_.clear(); + Xvals_.reserve( mesh_size ); + Darray Yvals; + Yvals.reserve( mesh_size ); + double s = (minIn + maxIn)/2; + double d = (maxIn - minIn)/2; + for (int i = 0; i < mesh_size; i++) { + Xvals_.push_back( s + d*((double) (2*i + 1 - mesh_size)/(mesh_size - 1)) ); + double yval = fxnIn( Xvals_.back() ); + Yvals.push_back( yval ); + } + + // Calculate table size + //unsigned int TableSize = (unsigned int)(one_over_Dx_ * width * scale); + mprintf("DEBUG: Table from %g to %g, width is %g table size %i\n", minIn, maxIn, width, mesh_size); + + Spline cspline; + cspline.CubicSpline_Coeff(Xvals_, Yvals); + + // Store values in Spline table + table_.clear(); + table_.reserve( mesh_size * 4 ); // Y B C D + for (int i = 0; i != mesh_size; i++) { + table_.push_back( Yvals[i] ); + table_.push_back( cspline.B_coeff()[i] ); + table_.push_back( cspline.C_coeff()[i] ); + table_.push_back( cspline.D_coeff()[i] ); + } + // Memory saved Y values plus spline B, C, and D coefficient arrays. + mprintf("\tMemory used by table and splines: %s\n", + ByteString(table_.size() * sizeof(double), BYTE_DECIMAL).c_str()); + return 0; +} + double SplineFxnTable::Yval_accurate(double xIn) const { // Find X value int ind = 0; diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index fbd9b707c4..3c366514e6 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -11,6 +11,8 @@ class SplineFxnTable { typedef double (*FxnType)(double); /// Fill the table using given function and spacing, from given min to max with given scale. int FillTable(FxnType, double, double, double, double); + /// Fill the table using given function, mesh size, min, max + int FillTable(FxnType, int, double, double); /// \return Approximated Y value from given X value. double Yval(double xIn) const { double xval = xIn - Xmin_; @@ -34,6 +36,8 @@ class SplineFxnTable { double Yval_accurate(double) const; + unsigned int Nvals() const { return Xvals_.size(); } + // DEBUG Access to internal table std::vector const& InternalTable() const { return table_; } private: From 1df6e4b06fafae1ffa32a7fdbdec16f880975f88 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 10 Jul 2020 09:10:26 -0400 Subject: [PATCH 51/87] DRR - Omit out of bounds check, rely on args being reasonable. Results in minor speedup (e.g. 5.4 fps to 6.4 fps). --- src/SplineFxnTable.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index 3c366514e6..7f82f50452 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -17,6 +17,7 @@ class SplineFxnTable { double Yval(double xIn) const { double xval = xIn - Xmin_; long int xidx = ((long int)(one_over_Dx_ * xval)); + //mprintf("SPLINEFXNTBL: idx= %li\n", xidx); // DEBUG // Delta from index double dx = xval - ((double)xidx * Dx_); // Index into the table @@ -25,10 +26,11 @@ class SplineFxnTable { //if (xidx < 0 || xidx >= (int)table_.size()) // mprinterr("Error: index %li out of range (%zu) for X val %g (Xmin= %g 1/dx= %g)\n", xidx, table_.size(), xIn, Xmin_, one_over_Dx_); // Protect against out of range values - if (xidx >= (long int)table_.size()) - xidx = table_.size() - 4; - else if (xidx < 0) - xidx = 0; + // NOTE - If args to Yval are chosen carefully, omitting this check speeds things up. + //if (xidx >= (long int)table_.size()) + // xidx = table_.size() - 4; + //else if (xidx < 0) + // xidx = 0; return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); From 29c7e0b51a9f769d854fba6e27181a5a0e6b6982 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 10 Jul 2020 13:14:31 -0400 Subject: [PATCH 52/87] Put the range check behind a define. --- src/SplineFxnTable.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index 7f82f50452..681e443e06 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -25,13 +25,14 @@ class SplineFxnTable { // DEBUG //if (xidx < 0 || xidx >= (int)table_.size()) // mprinterr("Error: index %li out of range (%zu) for X val %g (Xmin= %g 1/dx= %g)\n", xidx, table_.size(), xIn, Xmin_, one_over_Dx_); +# ifdef SPLINEFXNTABLE_CHECK_RANGE // Protect against out of range values // NOTE - If args to Yval are chosen carefully, omitting this check speeds things up. - //if (xidx >= (long int)table_.size()) - // xidx = table_.size() - 4; - //else if (xidx < 0) - // xidx = 0; - + if (xidx >= (long int)table_.size()) + xidx = table_.size() - 4; + else if (xidx < 0) + xidx = 0; +# endif return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } From 86af9766009a9df43cfed077e706f9010f08421f Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 13 Jul 2020 11:43:04 -0400 Subject: [PATCH 53/87] Allow volmap to be compiled for either single or double precision grid --- src/Action_Volmap.cpp | 48 ++++++++++++++++++++++++++++++++++--------- src/Action_Volmap.h | 17 +++++++++++---- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index bd57f1c543..f310f5e172 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -3,7 +3,15 @@ #include "Action_Volmap.h" #include "Constants.h" // PI #include "CpptrajStdio.h" -#include "DataSet_GridFlt.h" +#ifdef VOLMAP_DOUBLE +# include "DataSet_GridDbl.h" +# define VOLMAP_DS_T DataSet_GridDbl +# define VOLMAP_T double +#else +# include "DataSet_GridFlt.h" +# define VOLMAP_DS_T DataSet_GridFlt +# define VOLMAP_T float +#endif #ifdef _OPENMP # include #endif @@ -109,6 +117,12 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d return Action::ERR; } +# ifdef VOLMAP_DOUBLE + static const DataSet::DataType GridDataType = DataSet::GRID_DBL; +# else + static const DataSet::DataType GridDataType = DataSet::GRID_FLT; +# endif + if (mode != DATASET) { Vec3 Sizes(0.0); Vec3 Center(0.0); @@ -162,7 +176,7 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d return Action::ERR; } // Allocate grid dataset - grid_ = (DataSet_GridFlt*)init.DSL().AddSet(DataSet::GRID_FLT, setname, "VOLMAP"); + grid_ = (VOLMAP_DS_T*)init.DSL().AddSet(GridDataType, setname, "VOLMAP"); if (grid_ == 0) { mprinterr("Error: Could not create grid dataset '%s'\n", setname.c_str()); return Action::ERR; @@ -182,7 +196,7 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d } } else { // Get existing grid dataset - grid_ = (DataSet_GridFlt*)init.DSL().FindSetOfType( setup_arg, DataSet::GRID_FLT ); + grid_ = (VOLMAP_DS_T*)init.DSL().FindSetOfType( setup_arg, GridDataType ); if (grid_ == 0) { mprinterr("Error: Could not find grid data set with name '%s'\n", setup_arg.c_str()); @@ -260,6 +274,11 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d // Info mprintf(" VOLMAP: Grid spacing will be %.2fx%.2fx%.2f Angstroms\n", dx_, dy_, dz_); +# ifdef VOLMAP_DOUBLE + mprintf("\tUsing double precision grid.\n"); +# else + mprintf("\tUsing single precision grid.\n"); +# endif if (setupGridOnMask_) mprintf("\tGrid centered around mask %s with %.2f Ang. clearance\n", centermask_.MaskExpression().c_str(), buffer_); @@ -344,7 +363,7 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { else if (radiiToUse == ELEMENT) rad = setup.Top()[*atom].ElementRadius(); if (rad > 0.0) { - halfradii_.push_back( (float)(rad * radscale_ / 2) ); + halfradii_.push_back( (double)(rad * radscale_ / 2) ); Atoms_.push_back( *atom ); // For determining function range. if (halfradii_.back() > maxRad) maxRad = halfradii_.back(); @@ -363,7 +382,12 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { //mprintf("DEBUG: %g %g %g %g\n", maxx, maxy, maxz, maxDist); maxDist *= (-1.0 / (2.0 * maxRad * maxRad)); //mprintf("DEBUG: max= %g\n", maxDist); - table_.FillTable( exp, splineDx_, maxDist, 0, 1.1 ); + + if (table_.FillTable( exp, splineDx_, maxDist, 0, 1.1 )) return Action::ERR; + //table_.FillTable( exp, splineDx_, maxDist, 0, 1.0 ); + //double width = (0.0 - maxDist) * 1.1; + //if (table_.FillTable( exp, (int)(width / splineDx_), maxDist, 0.0 ) ) return Action::ERR; + if ((int)Atoms_.size() < densitymask_.Nselected()) mprintf("Warning: %i atoms have 0.0 radii and will be skipped.\n", densitymask_.Nselected() - (int)Atoms_.size()); @@ -495,9 +519,11 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { // local variables of called functions are private. //GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval(exfac * dist2)); + //GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # else //grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); grid_->Increment(xval, yval, zval, norm * table_.Yval(exfac * dist2)); + //grid_->Increment(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # endif } } // END loop over zval @@ -554,12 +580,12 @@ void Action_Volmap::Print() { CombineGridThreads(); # endif // Divide our grid by the number of frames - float nf = (float)Nframes_; - for (DataSet_GridFlt::iterator gval = grid_->begin(); gval != grid_->end(); ++gval) + VOLMAP_T nf = (VOLMAP_T)Nframes_; + for (VOLMAP_DS_T::iterator gval = grid_->begin(); gval != grid_->end(); ++gval) *gval /= nf; // Print volume estimate unsigned int nOccupiedVoxels = 0; - for (DataSet_GridFlt::iterator gval = grid_->begin(); gval != grid_->end(); ++gval) { + for (VOLMAP_DS_T::iterator gval = grid_->begin(); gval != grid_->end(); ++gval) { if (*gval > 0.0) { ++nOccupiedVoxels; //mprintf("DBG: %16.8e\n", *gval); @@ -582,11 +608,11 @@ void Action_Volmap::Print() { // that value is _not_ a maximum. Any density peaks less than the minimum // filter are discarded. The result is a Grid instance with all non-peak // grid points zeroed-out. - Grid peakgrid = grid_->InternalGrid(); + Grid peakgrid = grid_->InternalGrid(); for (size_t i = 0; i < grid_->NX(); i++) for (size_t j = 0; j < grid_->NY(); j++) for (size_t k = 0; k < grid_->NZ(); k++) { - float val = grid_->GridVal(i, j, k); + VOLMAP_T val = grid_->GridVal(i, j, k); if (val < peakcut_) { peakgrid.setGrid(i, j, k, 0.0f); continue; @@ -631,3 +657,5 @@ void Action_Volmap::Print() { } } } +#undef VOLMAP_DS_T +#undef VOLMAP_T diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index 70349a078e..89f59d42b3 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -3,7 +3,14 @@ #include "Action.h" #include "Grid.h" #include "SplineFxnTable.h" -class DataSet_GridFlt; +#ifdef VOLMAP_DOUBLE +# define VOLMAP_DS_T DataSet_GridDbl +# define VOLMAP_T double +#else +# define VOLMAP_DS_T DataSet_GridFlt +# define VOLMAP_T float +#endif +class VOLMAP_DS_T; class Action_Volmap : public Action { public: Action_Volmap(); @@ -32,14 +39,14 @@ class Action_Volmap : public Action { bool spheremode_; ///< If true, grid points farther than rhalf^2 will be skipped AtomMask centermask_; ///< Mask to center the grid on AtomMask densitymask_; ///< Max of atoms to grid. - DataSet_GridFlt* grid_; ///< Hold the grid. + VOLMAP_DS_T* grid_; ///< Hold the grid. DataSet* total_volume_; ///< Hold total grid volume. bool calcpeaks_; ///< If true, calculate peaks DataFile* peakfile_; ///< Optional file to write peak data to as Carbons in XYZ file format DataSet* peakdata_; ///< Data set holding peak locations along with densities double peakcut_; ///< The value below which to ignore all peaks std::vector Atoms_; ///< Atoms with radii > 0.0 - std::vector halfradii_; ///< 1/2 the atomic radii of each atom in the gridded selection + std::vector halfradii_; ///< 1/2 the atomic radii of each atom in the gridded selection double buffer_; ///< Clearance between the edges of our grid and centermask_ double radscale_; ///< The scaling factor to divide all radii by double stepfac_; ///< Factor for determining how many steps to smear Gaussian @@ -47,9 +54,11 @@ class Action_Volmap : public Action { SplineFxnTable table_; double splineDx_; # ifdef _OPENMP - typedef std::vector< Grid > Garray; + typedef std::vector< Grid > Garray; Garray GRID_THREAD_; void CombineGridThreads(); # endif }; +#undef VOLMAP_DS_T +#undef VOLMAP_T #endif From 8cc85e7dd0c6a91e725568e1485e3ee0d5ea49da Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 14 Jul 2020 13:30:56 -0400 Subject: [PATCH 54/87] Add ability to compile and use exponential function. --- src/Action_Volmap.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index f310f5e172..85d78cfe5e 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -295,7 +295,9 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tWhen smearing Gaussian, voxels farther than radii/2 will be skipped.\n"); mprintf("\tDividing radii by %f\n", 1.0/radscale_); mprintf("\tFactor for determining number of bins to smear Gaussian is %f\n", stepfac_); +# ifndef VOLMAP_USEEXP mprintf("\tExponential will be approximated using cubic splines with a spacing of %g\n", splineDx_); +# endif if (outfile != 0) mprintf("\tDensity will wrtten to '%s'\n", outfile->DataFilename().full()); mprintf("\tGrid dataset name is '%s'\n", grid_->legend()); @@ -517,12 +519,18 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { # ifdef _OPENMP // NOTE: It is OK to call table_.Yval() here because in OpenMP // local variables of called functions are private. - //GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); +# ifdef VOLMAP_USEEXP + GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); +# else GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval(exfac * dist2)); +# endif //GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # else - //grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); +# ifdef VOLMAP_USEEXP + grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); +# else grid_->Increment(xval, yval, zval, norm * table_.Yval(exfac * dist2)); +# endif //grid_->Increment(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # endif } From b2a7cb04af1cacfc4ad654f74dc9670d589a8776 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 16 Jul 2020 10:18:16 -0400 Subject: [PATCH 55/87] Add define for using the more accurate but slower table lookup --- src/Action_Volmap.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 85d78cfe5e..ab5a357028 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -297,6 +297,9 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tFactor for determining number of bins to smear Gaussian is %f\n", stepfac_); # ifndef VOLMAP_USEEXP mprintf("\tExponential will be approximated using cubic splines with a spacing of %g\n", splineDx_); +# ifdef VOLMAP_USEACCURATE + mprintf("\tSplines using more accurate but slower table lookup.\n"); +# endif # endif if (outfile != 0) mprintf("\tDensity will wrtten to '%s'\n", outfile->DataFilename().full()); @@ -519,20 +522,22 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { # ifdef _OPENMP // NOTE: It is OK to call table_.Yval() here because in OpenMP // local variables of called functions are private. -# ifdef VOLMAP_USEEXP +# if defined(VOLMAP_USEEXP) GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); +# elif defined(VOLMAP_USEACCURATE) + GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # else GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval(exfac * dist2)); # endif - //GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); -# else -# ifdef VOLMAP_USEEXP +# else /* OPENMP */ +# if defined(VOLMAP_USEEXP) grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); +# elif defined(VOLMAP_USEACCURATE) + grid_->Increment(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # else grid_->Increment(xval, yval, zval, norm * table_.Yval(exfac * dist2)); # endif - //grid_->Increment(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); -# endif +# endif /* OPENMP */ } } // END loop over zval } // END z dim is valid From fb5b82fa27b0b0587a0476b70d9418843799bdc5 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 17 Jul 2020 11:35:10 -0400 Subject: [PATCH 56/87] Add some debug --- src/SplineFxnTable.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index 9b85e919e4..628e46bcd5 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -152,6 +152,7 @@ double SplineFxnTable::Yval_accurate(double xIn) const { ind = Xvals_.size() - 1; } double dx = xIn - Xvals_[ind]; + //mprintf("DEBUG: ind= %8i x=%20.10E dx= %20.10E\n", ind, xIn, dx); int xidx = ind * 4; return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } From e3278a072ed88acfdfbc4ab8edcea2c7217c23a3 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 17 Jul 2020 11:35:43 -0400 Subject: [PATCH 57/87] Add some debug info and a new function that uses the internal X table. --- src/SplineFxnTable.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index 681e443e06..368fecef8d 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -20,6 +20,9 @@ class SplineFxnTable { //mprintf("SPLINEFXNTBL: idx= %li\n", xidx); // DEBUG // Delta from index double dx = xval - ((double)xidx * Dx_); + //double newDx = xIn - Xvals_[xidx]; + //mprintf("DEBUG: xidx= %8li x=%20.10E x*dx= %20.10E xval= %20.10E dx= %20.10E newDx= %20.10E\n", + // xidx, xIn, (double)xidx*Dx_, Xvals_[xidx], dx, newDx); // Index into the table xidx *= 4; // DEBUG @@ -36,7 +39,15 @@ class SplineFxnTable { return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } - + /// \return Approximated Y value, use internal X table + double Yval_xtable(double xIn) const { + long int xidx = (long int)(one_over_Dx_ * (xIn - Xmin_)); + double dx = xIn - Xvals_[xidx]; + xidx *= 4; + return table_[xidx] + + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); + } + /// \return More accurate X value via search of internal X table double Yval_accurate(double) const; unsigned int Nvals() const { return Xvals_.size(); } From d14d392a89f8559668cee1526bbd047bf8ab5c6e Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 17 Jul 2020 11:36:34 -0400 Subject: [PATCH 58/87] Add spline function table check for Yval_xtable --- src/SplineFxnTable.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index 368fecef8d..f04e5c6fc2 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -44,6 +44,14 @@ class SplineFxnTable { long int xidx = (long int)(one_over_Dx_ * (xIn - Xmin_)); double dx = xIn - Xvals_[xidx]; xidx *= 4; +# ifdef SPLINEFXNTABLE_CHECK_RANGE + // Protect against out of range values + // NOTE - If args to Yval are chosen carefully, omitting this check speeds things up. + if (xidx >= (long int)table_.size()) + xidx = table_.size() - 4; + else if (xidx < 0) + xidx = 0; +# endif return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } From f077c3c03c665801b78edf9b7578e674dcd00131 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 17 Jul 2020 11:41:38 -0400 Subject: [PATCH 59/87] Add VOLMAP_USEXTABLE --- src/Action_Volmap.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index ab5a357028..727a41fc24 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -297,8 +297,10 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tFactor for determining number of bins to smear Gaussian is %f\n", stepfac_); # ifndef VOLMAP_USEEXP mprintf("\tExponential will be approximated using cubic splines with a spacing of %g\n", splineDx_); -# ifdef VOLMAP_USEACCURATE +# if defined(VOLMAP_USEACCURATE) mprintf("\tSplines using more accurate but slower table lookup.\n"); +# elif defined(VOLMAP_USEXTABLE) + mprintf("\tSplines using less accurate lookup with tabled X values.\n"); # endif # endif if (outfile != 0) @@ -526,6 +528,8 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); +# elif defined(VOLMAP_USEXTABLE) + GRID_THREAD_[mythread].incrementBy(xval, yval, xval, norm * table_.Yval_xtable(exfac * dist2)); # else GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval(exfac * dist2)); # endif @@ -534,6 +538,8 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) grid_->Increment(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); +# elif defined(VOLMAP_USEXTABLE) + grid_->Increment(xval, yval, zval, norm * table_.Yval_xtable(exfac * dist2)); # else grid_->Increment(xval, yval, zval, norm * table_.Yval(exfac * dist2)); # endif From 066179efd21601454ead68be755cd4b32029e3db Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 20 Jul 2020 15:09:43 -0400 Subject: [PATCH 60/87] Ensure the xvalues used in the mesh are generated in the same way as during the Y eval step. Round-off makes the addition method prone to errors for small table spacings --- src/SplineFxnTable.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index 628e46bcd5..072f4a51ff 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -38,12 +38,13 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m Xvals_.reserve( TableSize ); Yvals.reserve( TableSize ); // Save X and Y values so we can calc the spline coefficients - double xval = Xmin_; + //double xval = Xmin_; for (unsigned int i = 0; i != TableSize; i++) { + double xval = Xmin_ + ((double)i * Dx_); double yval = fxnIn( xval ); Xvals_.push_back( xval ); Yvals.push_back( yval ); - xval += Dx_; + //xval += Dx_; } Spline cspline; cspline.CubicSpline_Coeff(Xvals_, Yvals); From 542a6571ff72ff313bc16774da5487106d1c5291 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 21 Jul 2020 10:46:03 -0400 Subject: [PATCH 61/87] When enabled, make sure the out of range check happens before dx calculation so it actually takes effect --- src/SplineFxnTable.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index f04e5c6fc2..f9dd698c41 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -18,40 +18,42 @@ class SplineFxnTable { double xval = xIn - Xmin_; long int xidx = ((long int)(one_over_Dx_ * xval)); //mprintf("SPLINEFXNTBL: idx= %li\n", xidx); // DEBUG +# ifdef SPLINEFXNTABLE_CHECK_RANGE + // Protect against out of range values + // NOTE - If args to Yval are chosen carefully, omitting this check speeds things up. + if (xidx >= (long int)Xvals_.size()) + xidx = Xvals_.size() - 1; + else if (xidx < 0) + xidx = 0; +# endif // Delta from index double dx = xval - ((double)xidx * Dx_); - //double newDx = xIn - Xvals_[xidx]; + // DEBUG //mprintf("DEBUG: xidx= %8li x=%20.10E x*dx= %20.10E xval= %20.10E dx= %20.10E newDx= %20.10E\n", - // xidx, xIn, (double)xidx*Dx_, Xvals_[xidx], dx, newDx); + // xidx, xIn, (double)(xidx)*Dx_, Xvals_[xidx], dx, xIn - Xvals_[xidx]); // Index into the table xidx *= 4; // DEBUG //if (xidx < 0 || xidx >= (int)table_.size()) // mprinterr("Error: index %li out of range (%zu) for X val %g (Xmin= %g 1/dx= %g)\n", xidx, table_.size(), xIn, Xmin_, one_over_Dx_); -# ifdef SPLINEFXNTABLE_CHECK_RANGE - // Protect against out of range values - // NOTE - If args to Yval are chosen carefully, omitting this check speeds things up. - if (xidx >= (long int)table_.size()) - xidx = table_.size() - 4; - else if (xidx < 0) - xidx = 0; -# endif return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } /// \return Approximated Y value, use internal X table double Yval_xtable(double xIn) const { long int xidx = (long int)(one_over_Dx_ * (xIn - Xmin_)); - double dx = xIn - Xvals_[xidx]; - xidx *= 4; # ifdef SPLINEFXNTABLE_CHECK_RANGE // Protect against out of range values // NOTE - If args to Yval are chosen carefully, omitting this check speeds things up. - if (xidx >= (long int)table_.size()) - xidx = table_.size() - 4; + if (xidx >= (long int)Xvals_.size()) + xidx = Xvals_.size() - 1; else if (xidx < 0) xidx = 0; # endif + // Delta from index + double dx = xIn - Xvals_[xidx]; + // Index into the table + xidx *= 4; return table_[xidx] + dx*(table_[xidx+1] + dx*(table_[xidx+2] + dx*table_[xidx+3])); } From 66d69cee9d836ec548dc4a3e47d314d84bb9cf40 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 31 Jul 2020 14:48:03 -0400 Subject: [PATCH 62/87] Add splinescale arg, improve output --- src/Action_Volmap.cpp | 14 ++++++++++---- src/Action_Volmap.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 727a41fc24..5c6111d0ef 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -38,6 +38,7 @@ Action_Volmap::Action_Volmap() : peakcut_(0.05), buffer_(3.0), radscale_(1.0), + splineScale_(1.1), stepfac_(4.1), splineDx_(0) {} @@ -56,6 +57,7 @@ void Action_Volmap::Help() const { void Action_Volmap::RawHelp() const { mprintf("\t[out ] [radscale ] [stepfac ]\n" "\t[sphere] [radii {vdw | element}] [splinedx ]\n" + "\t[splinescale ]\n" "\t[calcpeaks] [peakcut ] [peakfile ]\n" "\t{ data |\n" "\t name [ ]\n" @@ -82,6 +84,7 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d stepfac_ = 1.0; } splineDx_ = actionArgs.getKeyDouble("splinedx", 1.0/5000.0); + splineScale_ = actionArgs.getKeyDouble("splinescale", 1.1); radscale_ = 1.0 / actionArgs.getKeyDouble("radscale", radscale_); stepfac_ = actionArgs.getKeyDouble("stepfac", stepfac_); std::string radarg = actionArgs.GetStringKey("radii"); @@ -295,14 +298,17 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tWhen smearing Gaussian, voxels farther than radii/2 will be skipped.\n"); mprintf("\tDividing radii by %f\n", 1.0/radscale_); mprintf("\tFactor for determining number of bins to smear Gaussian is %f\n", stepfac_); -# ifndef VOLMAP_USEEXP - mprintf("\tExponential will be approximated using cubic splines with a spacing of %g\n", splineDx_); +# ifdef VOLMAP_USEEXP + mprintf("\tUsing system exp() function for evaluating Gaussians.\n"); +# else /* VOLMAP_USEEXP */ + mprintf("\tExponential for Gaussians will be approximated using cubic splines with a spacing of %g\n", splineDx_); # if defined(VOLMAP_USEACCURATE) mprintf("\tSplines using more accurate but slower table lookup.\n"); # elif defined(VOLMAP_USEXTABLE) mprintf("\tSplines using less accurate lookup with tabled X values.\n"); # endif -# endif + mprintf("\tWidth of the spline table will be scaled by %gx\n", splineScale_); +# endif /* VOLMAP_USEEXP */ if (outfile != 0) mprintf("\tDensity will wrtten to '%s'\n", outfile->DataFilename().full()); mprintf("\tGrid dataset name is '%s'\n", grid_->legend()); @@ -390,7 +396,7 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { maxDist *= (-1.0 / (2.0 * maxRad * maxRad)); //mprintf("DEBUG: max= %g\n", maxDist); - if (table_.FillTable( exp, splineDx_, maxDist, 0, 1.1 )) return Action::ERR; + if (table_.FillTable( exp, splineDx_, maxDist, 0, splineScale_ )) return Action::ERR; //table_.FillTable( exp, splineDx_, maxDist, 0, 1.0 ); //double width = (0.0 - maxDist) * 1.1; //if (table_.FillTable( exp, (int)(width / splineDx_), maxDist, 0.0 ) ) return Action::ERR; diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index 89f59d42b3..12407209c4 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -49,6 +49,7 @@ class Action_Volmap : public Action { std::vector halfradii_; ///< 1/2 the atomic radii of each atom in the gridded selection double buffer_; ///< Clearance between the edges of our grid and centermask_ double radscale_; ///< The scaling factor to divide all radii by + double splineScale_; ///< Factor to scale spline table width by double stepfac_; ///< Factor for determining how many steps to smear Gaussian static const double sqrt_8_pi_cubed_; SplineFxnTable table_; From 54ccf293363df592d20bd1e73b6d7072af4844f2 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 24 Aug 2020 09:29:52 -0400 Subject: [PATCH 63/87] Add back the ReadHelp function. --- src/DataIO_OpenDx.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/DataIO_OpenDx.cpp b/src/DataIO_OpenDx.cpp index 74d4b0d973..33de0ad57f 100644 --- a/src/DataIO_OpenDx.cpp +++ b/src/DataIO_OpenDx.cpp @@ -32,6 +32,11 @@ bool DataIO_OpenDx::ID_DataFormat( CpptrajFile& infile ) { return isDX; } +/** Read help options. */ +void DataIO_OpenDx::ReadHelp() { + mprintf("\ttype {float|double} : Precision to read grid (default float).\n"); +} + /** Process read options. */ int DataIO_OpenDx::processReadArgs(ArgList& argIn) { std::string typestr = argIn.GetStringKey("type"); From fc77c614c6c13f53b7054d8df6c48a534f10eaa2 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 16 Oct 2020 08:49:46 -0400 Subject: [PATCH 64/87] Remove scaling argument from spline table setup. Instead, have volmap add 1.0 to the max expected value to avoid Runges phenomenon. --- src/Action_Volmap.cpp | 3 ++- src/SplineFxnTable.cpp | 53 ++++++++++++++++++++++++++++++++++-------- src/SplineFxnTable.h | 4 +++- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index b0c343244c..55417cf32c 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -397,7 +397,8 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { maxDist *= (-1.0 / (2.0 * maxRad * maxRad)); //mprintf("DEBUG: max= %g\n", maxDist); - if (table_.FillTable( exp, splineDx_, maxDist, 0, splineScale_ )) return Action::ERR; + //if (table_.FillTable( exp, splineDx_, maxDist, 1.0, splineScale_ )) return Action::ERR; + if (table_.FillTable( exp, splineDx_, maxDist, 1.0 )) return Action::ERR; //table_.FillTable( exp, splineDx_, maxDist, 0, 1.0 ); //double width = (0.0 - maxDist) * 1.1; //if (table_.FillTable( exp, (int)(width / splineDx_), maxDist, 0.0 ) ) return Action::ERR; diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index 072f4a51ff..0881992c19 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -3,6 +3,7 @@ #include "Constants.h" #include "Spline.h" #include "StringRoutines.h" +#include /** CONSTRUCTOR */ SplineFxnTable::SplineFxnTable() : @@ -13,8 +14,15 @@ SplineFxnTable::SplineFxnTable() : {} /** Fill the spline function table with values from the given function. */ -int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double maxIn, double scale) +//int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double maxIn, double scale) +int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double maxIn) { +/* + if (scale < 1.0) { + mprinterr("Error: Scaling for spline table width %g cannot be less than 1.0x\n", scale); + return 1; + } +*/ Dx_ = dxIn; if (Dx_ < Constants::SMALL) { mprinterr("Error: Spacing for spline table too small or negative.\n"); @@ -30,29 +38,54 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m return 1; } // Calculate table size - unsigned int TableSize = (unsigned int)(one_over_Dx_ * width * scale); - mprintf("DEBUG: Table from %g to %g (%gx), width is %g table size %u\n", minIn, maxIn, scale, width, TableSize); - + int TableSize = ((int)ceil(one_over_Dx_ * width)) + 1; + mprintf("DEBUG: Table from %g to %g, width is %g table size %i\n", minIn, maxIn, width, TableSize); + int ArraySize = TableSize; + int minIdx = 0; + //unsigned int TableSize = (unsigned int)(one_over_Dx_ * width * scale); + //mprintf("DEBUG: Table from %g to %g (%gx), width is %g table size %u\n", minIn, maxIn, scale, width, TableSize); +/* + int ScaledSize = (int)((double)TableSize * scale); + mprintf("DEBUG: Scaled size = %i\n", ScaledSize); +*/ +/* + int ArraySize = ScaledSize; +*/ +/* + int Delta = ScaledSize - TableSize; + //if (Delta < 1) Delta = 1; + mprintf("DEBUG: Delta = %i\n", Delta); + // Round up + Delta += (Delta % 2); + mprintf("DEBUG: Rounded Delta = %i\n", Delta); + int HalfDelta = Delta / 2; + mprintf("DEBUG: Half Delta = %i\n", HalfDelta); + int ArraySize = TableSize + Delta; + mprintf("DEBUG: Scaled table size = %i\n", ArraySize); + int minIdx = -HalfDelta; +*/ Xvals_.clear(); Darray Yvals; - Xvals_.reserve( TableSize ); - Yvals.reserve( TableSize ); + Xvals_.reserve( ArraySize ); + Yvals.reserve( ArraySize ); // Save X and Y values so we can calc the spline coefficients //double xval = Xmin_; - for (unsigned int i = 0; i != TableSize; i++) { + for (int i = minIdx; i != ArraySize; i++) + { double xval = Xmin_ + ((double)i * Dx_); double yval = fxnIn( xval ); Xvals_.push_back( xval ); Yvals.push_back( yval ); - //xval += Dx_; } + Xmin_ = Xvals_.front(); + mprintf("DEBUG: Spline table X range is %g to %g\n", Xvals_.front(), Xvals_.back()); Spline cspline; cspline.CubicSpline_Coeff(Xvals_, Yvals); //Xvals.clear(); // Store values in Spline table table_.clear(); - table_.reserve( TableSize * 4 ); // Y B C D - for (unsigned int i = 0; i != TableSize; i++) { + table_.reserve( Yvals.size() * 4 ); // Y B C D + for (unsigned int i = 0; i != Yvals.size(); i++) { table_.push_back( Yvals[i] ); table_.push_back( cspline.B_coeff()[i] ); table_.push_back( cspline.C_coeff()[i] ); diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index f9dd698c41..016e948152 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -10,7 +10,9 @@ class SplineFxnTable { /// Generic form of the function to approximate. typedef double (*FxnType)(double); /// Fill the table using given function and spacing, from given min to max with given scale. - int FillTable(FxnType, double, double, double, double); + //int FillTable(FxnType, double, double, double, double); + /// Fill the ftable using given function and spacing, from given min to max. + int FillTable(FxnType, double, double, double); /// Fill the table using given function, mesh size, min, max int FillTable(FxnType, int, double, double); /// \return Approximated Y value from given X value. From abfd1eed0d413e5116c6871cf7bc9579680952cd Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 10 Dec 2020 09:57:53 -0500 Subject: [PATCH 65/87] =?UTF-8?q?Add=20fast=20exponential=20from=20N.=20N.?= =?UTF-8?q?=20Schraudolph,=20Neural=20Computation=2011,=20853=E2=80=93862?= =?UTF-8?q?=20(1999)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/FastExp_Schraudolph.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/FastExp_Schraudolph.h diff --git a/src/FastExp_Schraudolph.h b/src/FastExp_Schraudolph.h new file mode 100644 index 0000000000..d12a892e79 --- /dev/null +++ b/src/FastExp_Schraudolph.h @@ -0,0 +1,19 @@ +/*! \file FastExp_Schraudolph.h + \brief Implementation of fast exponential by Nicol N. Schraudolph, Neural Computation 11, 853–862 (1999) + */ +#include +static union +{ +double d; +struct +{ +//#ifdef LITTLE_ENDIAN +int j, i; +//#else +//int i, j; +//#endif +} n; +} _eco; +#define EXP_A (1048576/M_LN2) /* use 1512775 for integer version */ +#define EXP_C 60801 /* see text for choice of c values */ +#define FASTEXPS(y) (_eco.n.i = EXP_A*(y) + (1072693248 - EXP_C), _eco.d) From ea5ceb6f9b49dfac889b5c58c36dd77a19d8b829 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 10 Dec 2020 10:06:59 -0500 Subject: [PATCH 66/87] Add define for using fast exp from Schraudolph --- src/Action_Volmap.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 55417cf32c..802d8ac0e1 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -15,6 +15,9 @@ #ifdef _OPENMP # include #endif +#ifdef VOLMAP_USEFASTEXPS +# include "FastExp_Schraudolph.h" +#endif const double Action_Volmap::sqrt_8_pi_cubed_ = sqrt(8.0*Constants::PI*Constants::PI*Constants::PI); @@ -299,8 +302,10 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tWhen smearing Gaussian, voxels farther than radii/2 will be skipped.\n"); mprintf("\tDividing radii by %f\n", 1.0/radscale_); mprintf("\tFactor for determining number of bins to smear Gaussian is %f\n", stepfac_); -# ifdef VOLMAP_USEEXP +# if defined(VOLMAP_USEEXP) mprintf("\tUsing system exp() function for evaluating Gaussians.\n"); +# elif defined(VOLMAP_USEFASTEXPS) + mprintf("\tUsing exp() from N. Schraudolph, Neural Computation 11, 853–862 (1999).\n"); # else /* VOLMAP_USEEXP */ mprintf("\tExponential for Gaussians will be approximated using cubic splines with a spacing of %g\n", splineDx_); # if defined(VOLMAP_USEACCURATE) @@ -534,6 +539,8 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { // local variables of called functions are private. # if defined(VOLMAP_USEEXP) GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); +# elif defined(VOLMAP_USEFASTEXPS) + GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # elif defined(VOLMAP_USEXTABLE) @@ -544,6 +551,8 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { # else /* OPENMP */ # if defined(VOLMAP_USEEXP) grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); +# elif defined(VOLMAP_USEFASTEXPS) + grid_->Increment(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) grid_->Increment(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # elif defined(VOLMAP_USEXTABLE) From fdf5b97378e9137ffec869584d066a05cec713dc Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 10 Dec 2020 11:04:54 -0500 Subject: [PATCH 67/87] Add 64 bit version and header protection --- src/FastExp_Schraudolph.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/FastExp_Schraudolph.h b/src/FastExp_Schraudolph.h index d12a892e79..6a61104f49 100644 --- a/src/FastExp_Schraudolph.h +++ b/src/FastExp_Schraudolph.h @@ -1,7 +1,9 @@ +#ifndef INC_FASTEXP_SCHRAUDOLPH_H +#define INC_FASTEXP_SCHRAUDOLPH_H /*! \file FastExp_Schraudolph.h - \brief Implementation of fast exponential by Nicol N. Schraudolph, Neural Computation 11, 853–862 (1999) + \brief Implementations of fast exponential by Nicol N. Schraudolph, Neural Computation 11, 853–862 (1999) */ -#include +#include // M_LN2 static union { double d; @@ -17,3 +19,17 @@ int j, i; #define EXP_A (1048576/M_LN2) /* use 1512775 for integer version */ #define EXP_C 60801 /* see text for choice of c values */ #define FASTEXPS(y) (_eco.n.i = EXP_A*(y) + (1072693248 - EXP_C), _eco.d) + +/// Approximate exp adapted from Schraudolph, 1999 - double precision floating point version. +/** \sa https://bduvenhage.me/performance/machine_learning/2019/06/04/fast-exp.html + */ +ALWAYS_INLINE double fast_exps_64(const double x) noexcept { + // Based on Schraudolph 1999, A Fast, Compact Approximation of the Exponential Function. + // - Adapted to use 64-bit integer; reduces staircase effect. + // - Valid for x in approx range (-700, 700). + union{double d_; int64_t i_;} uid; //This could be moved to the thread scope. + //BBBD(sizeof(uid)!=8) + uid.i_ = int64_t(double((int64_t(1) << 52) / log(2.0)) * x + double((int64_t(1) << 52) * 1023 - 0)); //c=0 for 1.0 at zero. + return uid.d_; +} +#endif From f2e25bbfb522525c772ee2d06612db910c4f4d07 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 10 Dec 2020 11:12:41 -0500 Subject: [PATCH 68/87] Fix the always inline attribute; add volmap define for using 64 bit fast exps --- src/Action_Volmap.cpp | 8 +++++++- src/FastExp_Schraudolph.h | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 802d8ac0e1..c6b133c390 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -15,7 +15,7 @@ #ifdef _OPENMP # include #endif -#ifdef VOLMAP_USEFASTEXPS +#if defined(VOLMAP_USEFASTEXPS) || defined(VOLMAP_USEFASTEXP64) # include "FastExp_Schraudolph.h" #endif @@ -306,6 +306,8 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tUsing system exp() function for evaluating Gaussians.\n"); # elif defined(VOLMAP_USEFASTEXPS) mprintf("\tUsing exp() from N. Schraudolph, Neural Computation 11, 853–862 (1999).\n"); +# elif defined(VOLMAP_USEFASTEXP64) + mprintf("\tUsing 64 bit version of exp() from N. Schraudolph, Neural Computation 11, 853–862 (1999).\n"); # else /* VOLMAP_USEEXP */ mprintf("\tExponential for Gaussians will be approximated using cubic splines with a spacing of %g\n", splineDx_); # if defined(VOLMAP_USEACCURATE) @@ -541,6 +543,8 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); # elif defined(VOLMAP_USEFASTEXPS) GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); +# elif defined(VOLMAP_USEFASTEXP64) + GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * fast_exps_64(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # elif defined(VOLMAP_USEXTABLE) @@ -553,6 +557,8 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); # elif defined(VOLMAP_USEFASTEXPS) grid_->Increment(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); +# elif defined(VOLMAP_USEFASTEXP64) + grid_->Increment(xval, yval, zval, norm * fast_exps_64(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) grid_->Increment(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # elif defined(VOLMAP_USEXTABLE) diff --git a/src/FastExp_Schraudolph.h b/src/FastExp_Schraudolph.h index 6a61104f49..8f3b6ec9cc 100644 --- a/src/FastExp_Schraudolph.h +++ b/src/FastExp_Schraudolph.h @@ -23,7 +23,7 @@ int j, i; /// Approximate exp adapted from Schraudolph, 1999 - double precision floating point version. /** \sa https://bduvenhage.me/performance/machine_learning/2019/06/04/fast-exp.html */ -ALWAYS_INLINE double fast_exps_64(const double x) noexcept { +inline __attribute__((always_inline)) double fast_exps_64(const double x) noexcept { // Based on Schraudolph 1999, A Fast, Compact Approximation of the Exponential Function. // - Adapted to use 64-bit integer; reduces staircase effect. // - Valid for x in approx range (-700, 700). From 6c6644489b9ec4b9cda7db6eeef5be338b33670d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 14 Dec 2020 10:23:26 -0500 Subject: [PATCH 69/87] Add library from https://github.com/simonpf/fastexp for testing --- src/FastExp_fastexp.h | 91 +++++++++++++++++++++++ src/FastExp_ieee.h | 164 ++++++++++++++++++++++++++++++++++++++++++ src/FastExp_product.h | 33 +++++++++ 3 files changed, 288 insertions(+) create mode 100644 src/FastExp_fastexp.h create mode 100644 src/FastExp_ieee.h create mode 100644 src/FastExp_product.h diff --git a/src/FastExp_fastexp.h b/src/FastExp_fastexp.h new file mode 100644 index 0000000000..a188239708 --- /dev/null +++ b/src/FastExp_fastexp.h @@ -0,0 +1,91 @@ +#ifndef FASTEXP_FASTEXP_H +#define FASTEXP_FASTEXP_H + +#include "math.h" +#include +#include +#include +#include "FastExp_product.h" +#include "FastExp_ieee.h" + +namespace fastexp +{ + +enum class Approximation {IEEE, PRODUCT}; + +/** \brief Fast approximate exponential. + * + * This function implements a fast, vectorizable approximation + * of the exponential function based on the following two articles: + * + * - Malossi, A. Cristiano I. & Ineichen, Yves & Bekas, Costas & Curioni, + * Alessandro. "Fast Exponential Computation on SIMD Architectures." (2015) + * 10.13140/2.1.4362.3207. + * - IEEE, Nicol N. "A fast, compact approximation of the exponential + * function." Neural Computation 11.4 (1999): 853-862. + * + * The approximation interpolates linearly between points on the curve of + * the exponential function that can be expressed as 2^i where i is an + * a signed integer. So yes, that is very approximate ... + * + * \tparam Real The floating point type of the arguments. + * \param x The argument of the exponential function. + * \return The approximated value of the exponential function. + */ +#pragma omp declare simd notinbranch +template +< + typename Real, + template class Approximation = IEEE, + size_t degree = 2 +> +inline Real exp(const Real &x) +{ + return Approximation::evaluate(x); +} + +/** \brief Fast approximate array exponential. + * + * Applies the fast exponential to an array of given length making + * use of SIMD instructions if available. To enable vectorization + * the code needs to be compiled with OpenMP support. + * + * \tparam Real The floating point type of the arguments. + * \param x The array to which apply the exponential function. + * \return n The number of elements in the array. + */ +template +< +typename Real, +template class Approximation = IEEE, +size_t degree = 2 +> +inline void exp(Real *x, size_t n) { + // Vectorized part. + #pragma omp simd + for (size_t i = 0; i < n; ++i) { + Real e = fastexp::exp(x[i]); + x[i] = e; + } +} + +template +< +typename Real, +template class Approximation = IEEE, +size_t degree = 2 +> +inline void exp(std::vector x) { + // Vectorized part. + size_t n = x.size(); + Real * x_ptr = &x[0]; + + #pragma omp simd + for (size_t i = 0; i < n; ++i) { + Real e = fastexp::exp(x_ptr[i]); + x_ptr[i] = e; + } +} + +} // fastexp +#endif // FASTEXP_H diff --git a/src/FastExp_ieee.h b/src/FastExp_ieee.h new file mode 100644 index 0000000000..fd2a97649a --- /dev/null +++ b/src/FastExp_ieee.h @@ -0,0 +1,164 @@ +#ifndef FASTEXP_IEEE_H +#define FASTEXP_IEEE_H + +namespace fastexp +{ + template struct PolynomialFit; + template struct Info; + + template + struct IEEE { + static Real evaluate(Real x) { + using unsigned_t = typename Info::unsigned_t; + constexpr unsigned_t shift = static_cast(1) << Info::shift; + + x *= Info::log2e; + Real xi = floor(x); + Real xf = x - xi; + + Real k = PolynomialFit::evaluate(xf) + 1.0; + unsigned_t e = reinterpret_cast(k); + e += shift * static_cast(xi); + return reinterpret_cast(e); + } + }; + + //////////////////////////////////////////////////////////////////////////////// + // Polynomial coefficients for error function fit. + //////////////////////////////////////////////////////////////////////////////// + + + template<> struct Info { + using unsigned_t = uint32_t; + static constexpr uint32_t shift = 23; + static constexpr float log2e = 1.442695040; + }; + + template<> struct Info { + using unsigned_t = uint64_t; + static constexpr uint64_t shift = 52; + static constexpr double log2e = 1.442695040; + }; + + template + struct Data; + + template + struct Data { + static constexpr Real coefficients[2] = {-0.05288671, + 0.99232129}; + }; + template constexpr Real Data::coefficients[2]; + + template + struct Data { + static constexpr Real coefficients[3] = {0.00365539, + 0.64960693, + 0.34271434}; + }; + template constexpr Real Data::coefficients[3]; + + template + struct Data { + static constexpr Real coefficients[4] = {-1.77187919e-04, + 6.96787180e-01, + 2.24169036e-01, + 7.90302044e-02}; + }; + template constexpr Real Data::coefficients[4]; + + template + struct Data { + static constexpr Real coefficients[5] = { 6.58721338e-06, + 6.92937406e-01, + 2.41696769e-01, + 5.16742848e-02, + 1.36779598e-02}; + }; + template constexpr Real Data::coefficients[5]; + + template + struct Data { + static constexpr Real coefficients[6] = {6.58721338e-06, + 6.92937406e-01, + 2.41696769e-01, + 5.16742848e-02, + 1.36779598e-02}; + }; + template constexpr Real Data::coefficients[6]; + + template + struct Data { + static constexpr Real coefficients[7] = {-1.97880719e-07, + 6.93156327e-01, + 2.40133447e-01, + 5.58740717e-02, + 8.94160147e-03, + 1.89454334e-03}; + }; + template constexpr Real Data::coefficients[7]; + + template + struct Data { + static constexpr Real coefficients[8] = {4.97074799e-09, + 6.93146861e-01, + 2.40230956e-01, + 5.54792541e-02, + 9.68583180e-03, + 1.23835751e-03, + 2.18728611e-04}; + }; + template constexpr Real Data::coefficients[8]; + + template + struct Data { + static constexpr Real coefficients[9] = {-1.06974751e-10, + 6.93147190e-01, + 2.40226337e-01, + 5.55053726e-02, + 9.61338873e-03, + 1.34310382e-03, + 1.42959529e-04, + 2.16483090e-05}; + }; + template constexpr Real Data::coefficients[9]; + + template + struct Data { + static constexpr Real coefficients[10] = {2.00811867e-12, + 6.93147180e-01, + 2.40226512e-01, + 5.55040573e-02, + 9.61838113e-03, + 1.33265219e-03, + 1.55193275e-04, + 1.41484217e-05, + 1.87497191e-06}; + }; + template Real constexpr Data::coefficients[10]; + + template + struct PolynomialFit { + inline static Real evaluate(Real x) { + Real p = PolynomialFit::evaluate(x) * x; + p += Data::coefficients[i]; + return p; + } + }; + + template + struct PolynomialFit { + inline static Real evaluate(Real x) { + return Data::coefficients[degree]; + } + }; + + template + struct PolynomialFit { + inline static Real evaluate(Real x) { + return x; + } + }; + +} // fastexp +#endif // FASTEXP_IEEE_H diff --git a/src/FastExp_product.h b/src/FastExp_product.h new file mode 100644 index 0000000000..a5cef4eb8b --- /dev/null +++ b/src/FastExp_product.h @@ -0,0 +1,33 @@ +#ifndef FASTEXP_PRODUCT_H +#define FASTEXP_PRODUCT_H + +namespace fastexp { + +template + struct Recursion { + static Real evaluate(Real x) { + constexpr Real c = 1.0 / static_cast(1u << degree); + x = Recursion::evaluate(x); + return x * x; + } + }; + +template + struct Recursion { + static Real evaluate(Real x) { + constexpr Real c = 1.0 / static_cast(1u << degree); + x = 1.0 + c * x; + return x; + } +}; + +template +struct Product { + static Real evaluate(Real x) { + return Recursion::evaluate(x); + } +}; + + +} // fastexp +#endif // FASTEXP_PRODUCT_H From 2f4736fcabe05516549930e7b31451ee42feee30 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 14 Dec 2020 10:37:38 -0500 Subject: [PATCH 70/87] Add ability to test the fast exp code from https://github.com/simonpf/fastexp --- src/Action_Volmap.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index c6b133c390..d634d8a55f 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -17,6 +17,8 @@ #endif #if defined(VOLMAP_USEFASTEXPS) || defined(VOLMAP_USEFASTEXP64) # include "FastExp_Schraudolph.h" +#elif defined(VOLMAP_USEFASTEXPIEEE) +# include "FastExp_fastexp.h" #endif const double Action_Volmap::sqrt_8_pi_cubed_ = sqrt(8.0*Constants::PI*Constants::PI*Constants::PI); @@ -308,6 +310,8 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tUsing exp() from N. Schraudolph, Neural Computation 11, 853–862 (1999).\n"); # elif defined(VOLMAP_USEFASTEXP64) mprintf("\tUsing 64 bit version of exp() from N. Schraudolph, Neural Computation 11, 853–862 (1999).\n"); +# elif defined(VOLMAP_USEFASTEXPIEEE) + mprintf("\tUsing exp() from Schraudolph & Malossi et al.\n"); # else /* VOLMAP_USEEXP */ mprintf("\tExponential for Gaussians will be approximated using cubic splines with a spacing of %g\n", splineDx_); # if defined(VOLMAP_USEACCURATE) @@ -545,6 +549,8 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); # elif defined(VOLMAP_USEFASTEXP64) GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * fast_exps_64(exfac * dist2)); +# elif defined(VOLMAP_USEFASTEXPIEEE) + GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * fastexp::exp(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # elif defined(VOLMAP_USEXTABLE) @@ -559,6 +565,8 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { grid_->Increment(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); # elif defined(VOLMAP_USEFASTEXP64) grid_->Increment(xval, yval, zval, norm * fast_exps_64(exfac * dist2)); +# elif defined(VOLMAP_USEFASTEXPIEEE) + grid_->Increment(xval, yval, zval, norm * fastexp::exp(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) grid_->Increment(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # elif defined(VOLMAP_USEXTABLE) From b4ab39d77f8ba33817360c914bbf314c105fd750 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 09:30:57 -0500 Subject: [PATCH 71/87] Remove the "fast" exponential code. Was only for testing. Leave the hooks in, just in case we ever need to test it again. Fast exponential code will be kept in a separate repository. --- src/Action_Volmap.cpp | 49 ++++++------ src/Action_Volmap.h | 8 ++ src/FastExp_Schraudolph.h | 35 -------- src/FastExp_fastexp.h | 91 --------------------- src/FastExp_ieee.h | 164 -------------------------------------- src/FastExp_product.h | 33 -------- 6 files changed, 34 insertions(+), 346 deletions(-) delete mode 100644 src/FastExp_Schraudolph.h delete mode 100644 src/FastExp_fastexp.h delete mode 100644 src/FastExp_ieee.h delete mode 100644 src/FastExp_product.h diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index d634d8a55f..045a3b78e2 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -15,11 +15,11 @@ #ifdef _OPENMP # include #endif -#if defined(VOLMAP_USEFASTEXPS) || defined(VOLMAP_USEFASTEXP64) -# include "FastExp_Schraudolph.h" -#elif defined(VOLMAP_USEFASTEXPIEEE) -# include "FastExp_fastexp.h" -#endif +//#if defined(VOLMAP_USEFASTEXPS) || defined(VOLMAP_USEFASTEXP64) +//# incl ude "FastExp_Schraudolph.h" +//#elif defined(VOLMAP_USEFASTEXPIEEE) +//# incl ude "FastExp_fastexp.h" +//#endif const double Action_Volmap::sqrt_8_pi_cubed_ = sqrt(8.0*Constants::PI*Constants::PI*Constants::PI); @@ -306,14 +306,17 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d mprintf("\tFactor for determining number of bins to smear Gaussian is %f\n", stepfac_); # if defined(VOLMAP_USEEXP) mprintf("\tUsing system exp() function for evaluating Gaussians.\n"); -# elif defined(VOLMAP_USEFASTEXPS) - mprintf("\tUsing exp() from N. Schraudolph, Neural Computation 11, 853–862 (1999).\n"); -# elif defined(VOLMAP_USEFASTEXP64) - mprintf("\tUsing 64 bit version of exp() from N. Schraudolph, Neural Computation 11, 853–862 (1999).\n"); -# elif defined(VOLMAP_USEFASTEXPIEEE) - mprintf("\tUsing exp() from Schraudolph & Malossi et al.\n"); +//# elif defined(VOLMAP_USEFASTEXPS) +// mprintf("\tUsing exp() from N. Schraudolph, Neural Computation 11, 853–862 (1999).\n"); +//# elif defined(VOLMAP_USEFASTEXP64) +// mprintf("\tUsing 64 bit version of exp() from N. Schraudolph, Neural Computation 11, 853–862 (1999).\n"); +//# elif defined(VOLMAP_USEFASTEXPIEEE) +// mprintf("\tUsing exp() from Schraudolph & Malossi et al.\n"); # else /* VOLMAP_USEEXP */ mprintf("\tExponential for Gaussians will be approximated using cubic splines with a spacing of %g\n", splineDx_); + mprintf("# Citation: Roe, D. R.; Brooks, B. R.; \"Improving the Speed of Volumetric\n" + "# Density Map Generation via Cubic Spline Interpolation\".\n" + "# Journal of Molecular Graphics and Modelling (2021).\n"); # if defined(VOLMAP_USEACCURATE) mprintf("\tSplines using more accurate but slower table lookup.\n"); # elif defined(VOLMAP_USEXTABLE) @@ -545,12 +548,12 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { // local variables of called functions are private. # if defined(VOLMAP_USEEXP) GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * exp(exfac * dist2)); -# elif defined(VOLMAP_USEFASTEXPS) - GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); -# elif defined(VOLMAP_USEFASTEXP64) - GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * fast_exps_64(exfac * dist2)); -# elif defined(VOLMAP_USEFASTEXPIEEE) - GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * fastexp::exp(exfac * dist2)); +//# elif defined(VOLMAP_USEFASTEXPS) +// GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); +//# elif defined(VOLMAP_USEFASTEXP64) +// GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * fast_exps_64(exfac * dist2)); +//# elif defined(VOLMAP_USEFASTEXPIEEE) +// GRID_THREAD[mythread].incrementBy(xval, yval, zval, norm * fastexp::exp(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) GRID_THREAD_[mythread].incrementBy(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # elif defined(VOLMAP_USEXTABLE) @@ -561,12 +564,12 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { # else /* OPENMP */ # if defined(VOLMAP_USEEXP) grid_->Increment(xval, yval, zval, norm * exp(exfac * dist2)); -# elif defined(VOLMAP_USEFASTEXPS) - grid_->Increment(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); -# elif defined(VOLMAP_USEFASTEXP64) - grid_->Increment(xval, yval, zval, norm * fast_exps_64(exfac * dist2)); -# elif defined(VOLMAP_USEFASTEXPIEEE) - grid_->Increment(xval, yval, zval, norm * fastexp::exp(exfac * dist2)); +//# elif defined(VOLMAP_USEFASTEXPS) +// grid_->Increment(xval, yval, zval, norm * FASTEXPS(exfac * dist2)); +//# elif defined(VOLMAP_USEFASTEXP64) +// grid_->Increment(xval, yval, zval, norm * fast_exps_64(exfac * dist2)); +//# elif defined(VOLMAP_USEFASTEXPIEEE) +// grid_->Increment(xval, yval, zval, norm * fastexp::exp(exfac * dist2)); # elif defined(VOLMAP_USEACCURATE) grid_->Increment(xval, yval, zval, norm * table_.Yval_accurate(exfac * dist2)); # elif defined(VOLMAP_USEXTABLE) diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index 78b89e229b..be51783b80 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -11,6 +11,14 @@ # define VOLMAP_T float #endif class VOLMAP_DS_T; +/// Calculate atomic volumetric density maps from trajectory data. +/** By default the grid type used is single-precision, mostly to save space. + * A double-precision grid can be used by compiling with the + * VOLMAP_DOUBLE define. + * Also by default the exp() function will be approximated with cubic spline + * interpolation. To use the system exp() function, compile with the + * VOLMAP_USEEXP define. + */ class Action_Volmap : public Action { public: Action_Volmap(); diff --git a/src/FastExp_Schraudolph.h b/src/FastExp_Schraudolph.h deleted file mode 100644 index 8f3b6ec9cc..0000000000 --- a/src/FastExp_Schraudolph.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef INC_FASTEXP_SCHRAUDOLPH_H -#define INC_FASTEXP_SCHRAUDOLPH_H -/*! \file FastExp_Schraudolph.h - \brief Implementations of fast exponential by Nicol N. Schraudolph, Neural Computation 11, 853–862 (1999) - */ -#include // M_LN2 -static union -{ -double d; -struct -{ -//#ifdef LITTLE_ENDIAN -int j, i; -//#else -//int i, j; -//#endif -} n; -} _eco; -#define EXP_A (1048576/M_LN2) /* use 1512775 for integer version */ -#define EXP_C 60801 /* see text for choice of c values */ -#define FASTEXPS(y) (_eco.n.i = EXP_A*(y) + (1072693248 - EXP_C), _eco.d) - -/// Approximate exp adapted from Schraudolph, 1999 - double precision floating point version. -/** \sa https://bduvenhage.me/performance/machine_learning/2019/06/04/fast-exp.html - */ -inline __attribute__((always_inline)) double fast_exps_64(const double x) noexcept { - // Based on Schraudolph 1999, A Fast, Compact Approximation of the Exponential Function. - // - Adapted to use 64-bit integer; reduces staircase effect. - // - Valid for x in approx range (-700, 700). - union{double d_; int64_t i_;} uid; //This could be moved to the thread scope. - //BBBD(sizeof(uid)!=8) - uid.i_ = int64_t(double((int64_t(1) << 52) / log(2.0)) * x + double((int64_t(1) << 52) * 1023 - 0)); //c=0 for 1.0 at zero. - return uid.d_; -} -#endif diff --git a/src/FastExp_fastexp.h b/src/FastExp_fastexp.h deleted file mode 100644 index a188239708..0000000000 --- a/src/FastExp_fastexp.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef FASTEXP_FASTEXP_H -#define FASTEXP_FASTEXP_H - -#include "math.h" -#include -#include -#include -#include "FastExp_product.h" -#include "FastExp_ieee.h" - -namespace fastexp -{ - -enum class Approximation {IEEE, PRODUCT}; - -/** \brief Fast approximate exponential. - * - * This function implements a fast, vectorizable approximation - * of the exponential function based on the following two articles: - * - * - Malossi, A. Cristiano I. & Ineichen, Yves & Bekas, Costas & Curioni, - * Alessandro. "Fast Exponential Computation on SIMD Architectures." (2015) - * 10.13140/2.1.4362.3207. - * - IEEE, Nicol N. "A fast, compact approximation of the exponential - * function." Neural Computation 11.4 (1999): 853-862. - * - * The approximation interpolates linearly between points on the curve of - * the exponential function that can be expressed as 2^i where i is an - * a signed integer. So yes, that is very approximate ... - * - * \tparam Real The floating point type of the arguments. - * \param x The argument of the exponential function. - * \return The approximated value of the exponential function. - */ -#pragma omp declare simd notinbranch -template -< - typename Real, - template class Approximation = IEEE, - size_t degree = 2 -> -inline Real exp(const Real &x) -{ - return Approximation::evaluate(x); -} - -/** \brief Fast approximate array exponential. - * - * Applies the fast exponential to an array of given length making - * use of SIMD instructions if available. To enable vectorization - * the code needs to be compiled with OpenMP support. - * - * \tparam Real The floating point type of the arguments. - * \param x The array to which apply the exponential function. - * \return n The number of elements in the array. - */ -template -< -typename Real, -template class Approximation = IEEE, -size_t degree = 2 -> -inline void exp(Real *x, size_t n) { - // Vectorized part. - #pragma omp simd - for (size_t i = 0; i < n; ++i) { - Real e = fastexp::exp(x[i]); - x[i] = e; - } -} - -template -< -typename Real, -template class Approximation = IEEE, -size_t degree = 2 -> -inline void exp(std::vector x) { - // Vectorized part. - size_t n = x.size(); - Real * x_ptr = &x[0]; - - #pragma omp simd - for (size_t i = 0; i < n; ++i) { - Real e = fastexp::exp(x_ptr[i]); - x_ptr[i] = e; - } -} - -} // fastexp -#endif // FASTEXP_H diff --git a/src/FastExp_ieee.h b/src/FastExp_ieee.h deleted file mode 100644 index fd2a97649a..0000000000 --- a/src/FastExp_ieee.h +++ /dev/null @@ -1,164 +0,0 @@ -#ifndef FASTEXP_IEEE_H -#define FASTEXP_IEEE_H - -namespace fastexp -{ - template struct PolynomialFit; - template struct Info; - - template - struct IEEE { - static Real evaluate(Real x) { - using unsigned_t = typename Info::unsigned_t; - constexpr unsigned_t shift = static_cast(1) << Info::shift; - - x *= Info::log2e; - Real xi = floor(x); - Real xf = x - xi; - - Real k = PolynomialFit::evaluate(xf) + 1.0; - unsigned_t e = reinterpret_cast(k); - e += shift * static_cast(xi); - return reinterpret_cast(e); - } - }; - - //////////////////////////////////////////////////////////////////////////////// - // Polynomial coefficients for error function fit. - //////////////////////////////////////////////////////////////////////////////// - - - template<> struct Info { - using unsigned_t = uint32_t; - static constexpr uint32_t shift = 23; - static constexpr float log2e = 1.442695040; - }; - - template<> struct Info { - using unsigned_t = uint64_t; - static constexpr uint64_t shift = 52; - static constexpr double log2e = 1.442695040; - }; - - template - struct Data; - - template - struct Data { - static constexpr Real coefficients[2] = {-0.05288671, - 0.99232129}; - }; - template constexpr Real Data::coefficients[2]; - - template - struct Data { - static constexpr Real coefficients[3] = {0.00365539, - 0.64960693, - 0.34271434}; - }; - template constexpr Real Data::coefficients[3]; - - template - struct Data { - static constexpr Real coefficients[4] = {-1.77187919e-04, - 6.96787180e-01, - 2.24169036e-01, - 7.90302044e-02}; - }; - template constexpr Real Data::coefficients[4]; - - template - struct Data { - static constexpr Real coefficients[5] = { 6.58721338e-06, - 6.92937406e-01, - 2.41696769e-01, - 5.16742848e-02, - 1.36779598e-02}; - }; - template constexpr Real Data::coefficients[5]; - - template - struct Data { - static constexpr Real coefficients[6] = {6.58721338e-06, - 6.92937406e-01, - 2.41696769e-01, - 5.16742848e-02, - 1.36779598e-02}; - }; - template constexpr Real Data::coefficients[6]; - - template - struct Data { - static constexpr Real coefficients[7] = {-1.97880719e-07, - 6.93156327e-01, - 2.40133447e-01, - 5.58740717e-02, - 8.94160147e-03, - 1.89454334e-03}; - }; - template constexpr Real Data::coefficients[7]; - - template - struct Data { - static constexpr Real coefficients[8] = {4.97074799e-09, - 6.93146861e-01, - 2.40230956e-01, - 5.54792541e-02, - 9.68583180e-03, - 1.23835751e-03, - 2.18728611e-04}; - }; - template constexpr Real Data::coefficients[8]; - - template - struct Data { - static constexpr Real coefficients[9] = {-1.06974751e-10, - 6.93147190e-01, - 2.40226337e-01, - 5.55053726e-02, - 9.61338873e-03, - 1.34310382e-03, - 1.42959529e-04, - 2.16483090e-05}; - }; - template constexpr Real Data::coefficients[9]; - - template - struct Data { - static constexpr Real coefficients[10] = {2.00811867e-12, - 6.93147180e-01, - 2.40226512e-01, - 5.55040573e-02, - 9.61838113e-03, - 1.33265219e-03, - 1.55193275e-04, - 1.41484217e-05, - 1.87497191e-06}; - }; - template Real constexpr Data::coefficients[10]; - - template - struct PolynomialFit { - inline static Real evaluate(Real x) { - Real p = PolynomialFit::evaluate(x) * x; - p += Data::coefficients[i]; - return p; - } - }; - - template - struct PolynomialFit { - inline static Real evaluate(Real x) { - return Data::coefficients[degree]; - } - }; - - template - struct PolynomialFit { - inline static Real evaluate(Real x) { - return x; - } - }; - -} // fastexp -#endif // FASTEXP_IEEE_H diff --git a/src/FastExp_product.h b/src/FastExp_product.h deleted file mode 100644 index a5cef4eb8b..0000000000 --- a/src/FastExp_product.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef FASTEXP_PRODUCT_H -#define FASTEXP_PRODUCT_H - -namespace fastexp { - -template - struct Recursion { - static Real evaluate(Real x) { - constexpr Real c = 1.0 / static_cast(1u << degree); - x = Recursion::evaluate(x); - return x * x; - } - }; - -template - struct Recursion { - static Real evaluate(Real x) { - constexpr Real c = 1.0 / static_cast(1u << degree); - x = 1.0 + c * x; - return x; - } -}; - -template -struct Product { - static Real evaluate(Real x) { - return Recursion::evaluate(x); - } -}; - - -} // fastexp -#endif // FASTEXP_PRODUCT_H From b2ba300b5f6862267b6b73288a55b814b08f1dc3 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 09:36:19 -0500 Subject: [PATCH 72/87] Remove obsolete splinescale argument --- src/Action_Volmap.cpp | 18 ++++++------------ src/Action_Volmap.h | 1 - 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 045a3b78e2..c85afaccbe 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -44,9 +44,8 @@ Action_Volmap::Action_Volmap() : peakcut_(0.05), buffer_(3.0), radscale_(1.0), - splineScale_(1.1), stepfac_(4.1), - splineDx_(0) + splineDx_(0.01) // Recommendation from Roe & Brooks JMGM 2021 {} void Action_Volmap::Help() const { @@ -63,7 +62,6 @@ void Action_Volmap::Help() const { void Action_Volmap::RawHelp() const { mprintf("\t[out ] [radscale ] [stepfac ]\n" "\t[sphere] [radii {vdw | element}] [splinedx ]\n" - "\t[splinescale ]\n" "\t[calcpeaks] [peakcut ] [peakfile ]\n" "\t{ data |\n" "\t name [ ]\n" @@ -89,8 +87,8 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d radscale_ = 0.5; stepfac_ = 1.0; } - splineDx_ = actionArgs.getKeyDouble("splinedx", 1.0/5000.0); - splineScale_ = actionArgs.getKeyDouble("splinescale", 1.1); + //splineDx_ = actionArgs.getKeyDouble("splinedx", 1.0/5000.0); + splineDx_ = actionArgs.getKeyDouble("splinedx", 0.01); radscale_ = 1.0 / actionArgs.getKeyDouble("radscale", radscale_); stepfac_ = actionArgs.getKeyDouble("stepfac", stepfac_); std::string radarg = actionArgs.GetStringKey("radii"); @@ -313,7 +311,7 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d //# elif defined(VOLMAP_USEFASTEXPIEEE) // mprintf("\tUsing exp() from Schraudolph & Malossi et al.\n"); # else /* VOLMAP_USEEXP */ - mprintf("\tExponential for Gaussians will be approximated using cubic splines with a spacing of %g\n", splineDx_); + mprintf("\tExponential for Gaussians will be approximated using cubic splines with a spacing of %g Ang.\n", splineDx_); mprintf("# Citation: Roe, D. R.; Brooks, B. R.; \"Improving the Speed of Volumetric\n" "# Density Map Generation via Cubic Spline Interpolation\".\n" "# Journal of Molecular Graphics and Modelling (2021).\n"); @@ -322,7 +320,6 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d # elif defined(VOLMAP_USEXTABLE) mprintf("\tSplines using less accurate lookup with tabled X values.\n"); # endif - mprintf("\tWidth of the spline table will be scaled by %gx\n", splineScale_); # endif /* VOLMAP_USEEXP */ if (outfile != 0) mprintf("\tDensity will wrtten to '%s'\n", outfile->DataFilename().full()); @@ -410,12 +407,8 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { //mprintf("DEBUG: %g %g %g %g\n", maxx, maxy, maxz, maxDist); maxDist *= (-1.0 / (2.0 * maxRad * maxRad)); //mprintf("DEBUG: max= %g\n", maxDist); - - //if (table_.FillTable( exp, splineDx_, maxDist, 1.0, splineScale_ )) return Action::ERR; + // Set up the interpolation table if (table_.FillTable( exp, splineDx_, maxDist, 1.0 )) return Action::ERR; - //table_.FillTable( exp, splineDx_, maxDist, 0, 1.0 ); - //double width = (0.0 - maxDist) * 1.1; - //if (table_.FillTable( exp, (int)(width / splineDx_), maxDist, 0.0 ) ) return Action::ERR; if ((int)Atoms_.size() < densitymask_.Nselected()) mprintf("Warning: %i atoms have 0.0 radii and will be skipped.\n", @@ -594,6 +587,7 @@ Action::RetType Action_Volmap::DoAction(int frameNum, ActionFrame& frm) { } #ifdef MPI +/** Sync grid to the master process. */ int Action_Volmap::SyncAction() { # ifdef _OPENMP CombineGridThreads(); diff --git a/src/Action_Volmap.h b/src/Action_Volmap.h index be51783b80..5f84c8e8ed 100644 --- a/src/Action_Volmap.h +++ b/src/Action_Volmap.h @@ -58,7 +58,6 @@ class Action_Volmap : public Action { std::vector halfradii_; ///< 1/2 the atomic radii of each atom in the gridded selection double buffer_; ///< Clearance between the edges of our grid and centermask_ double radscale_; ///< The scaling factor to divide all radii by - double splineScale_; ///< Factor to scale spline table width by double stepfac_; ///< Factor for determining how many steps to smear Gaussian static const double sqrt_8_pi_cubed_; SplineFxnTable table_; From ca172f486e1d9da3f615448f217830bc5ee7f913 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 09:55:32 -0500 Subject: [PATCH 73/87] Clean up output --- src/Action_Volmap.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index c85afaccbe..f8695d1835 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -311,7 +311,8 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d //# elif defined(VOLMAP_USEFASTEXPIEEE) // mprintf("\tUsing exp() from Schraudolph & Malossi et al.\n"); # else /* VOLMAP_USEEXP */ - mprintf("\tExponential for Gaussians will be approximated using cubic splines with a spacing of %g Ang.\n", splineDx_); + mprintf("\tExponential for Gaussians will be approximated using cubic splines\n" + "\t with a spacing of %g Ang.\n", splineDx_); mprintf("# Citation: Roe, D. R.; Brooks, B. R.; \"Improving the Speed of Volumetric\n" "# Density Map Generation via Cubic Spline Interpolation\".\n" "# Journal of Molecular Graphics and Modelling (2021).\n"); From d4e29350348bf87f82ae3de3c07966f4065b4da7 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 10:03:08 -0500 Subject: [PATCH 74/87] Remove old code, improve code documentation. --- src/SplineFxnTable.cpp | 32 ++++++-------------------------- src/SplineFxnTable.h | 6 ++---- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index 0881992c19..d8df5a32a1 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -38,32 +38,10 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m return 1; } // Calculate table size - int TableSize = ((int)ceil(one_over_Dx_ * width)) + 1; - mprintf("DEBUG: Table from %g to %g, width is %g table size %i\n", minIn, maxIn, width, TableSize); - int ArraySize = TableSize; + int ArraySize = ((int)ceil(one_over_Dx_ * width)) + 1; + mprintf("DEBUG: Table from %g to %g, width is %g table size %i\n", minIn, maxIn, width, ArraySize); int minIdx = 0; - //unsigned int TableSize = (unsigned int)(one_over_Dx_ * width * scale); - //mprintf("DEBUG: Table from %g to %g (%gx), width is %g table size %u\n", minIn, maxIn, scale, width, TableSize); -/* - int ScaledSize = (int)((double)TableSize * scale); - mprintf("DEBUG: Scaled size = %i\n", ScaledSize); -*/ -/* - int ArraySize = ScaledSize; -*/ -/* - int Delta = ScaledSize - TableSize; - //if (Delta < 1) Delta = 1; - mprintf("DEBUG: Delta = %i\n", Delta); - // Round up - Delta += (Delta % 2); - mprintf("DEBUG: Rounded Delta = %i\n", Delta); - int HalfDelta = Delta / 2; - mprintf("DEBUG: Half Delta = %i\n", HalfDelta); - int ArraySize = TableSize + Delta; - mprintf("DEBUG: Scaled table size = %i\n", ArraySize); - int minIdx = -HalfDelta; -*/ + Xvals_.clear(); Darray Yvals; Xvals_.reserve( ArraySize ); @@ -134,7 +112,6 @@ int SplineFxnTable::FillTable(FxnType fxnIn, int mesh_size, double minIn, double } // Calculate table size - //unsigned int TableSize = (unsigned int)(one_over_Dx_ * width * scale); mprintf("DEBUG: Table from %g to %g, width is %g table size %i\n", minIn, maxIn, width, mesh_size); Spline cspline; @@ -155,6 +132,9 @@ int SplineFxnTable::FillTable(FxnType fxnIn, int mesh_size, double minIn, double return 0; } +/** Use a binary search to find the nearest x value; will not suffer from + * round-off issues but is very slow. + */ double SplineFxnTable::Yval_accurate(double xIn) const { // Find X value int ind = 0; diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index 016e948152..cc3313c5a7 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -9,11 +9,9 @@ class SplineFxnTable { SplineFxnTable(); /// Generic form of the function to approximate. typedef double (*FxnType)(double); - /// Fill the table using given function and spacing, from given min to max with given scale. - //int FillTable(FxnType, double, double, double, double); /// Fill the ftable using given function and spacing, from given min to max. int FillTable(FxnType, double, double, double); - /// Fill the table using given function, mesh size, min, max + /// Fill the table using given function, mesh size, from given min to max. int FillTable(FxnType, int, double, double); /// \return Approximated Y value from given X value. double Yval(double xIn) const { @@ -61,7 +59,7 @@ class SplineFxnTable { } /// \return More accurate X value via search of internal X table double Yval_accurate(double) const; - + /// \return Number of values in the table unsigned int Nvals() const { return Xvals_.size(); } // DEBUG Access to internal table From c48986aba872675eb296f1307849f6753c31b80a Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 10:12:12 -0500 Subject: [PATCH 75/87] Put spline info print into separate functions. --- src/SplineFxnTable.cpp | 26 +++++++++++++++----------- src/SplineFxnTable.h | 5 ++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/SplineFxnTable.cpp b/src/SplineFxnTable.cpp index d8df5a32a1..0f4d1a1f5a 100644 --- a/src/SplineFxnTable.cpp +++ b/src/SplineFxnTable.cpp @@ -13,6 +13,19 @@ SplineFxnTable::SplineFxnTable() : Xmax_(0) {} +/** Print table info to STDOUT. */ +void SplineFxnTable::PrintTableInfo(const char* header) const { + mprintf("%sTable from %g to %g, width is %g table size %zu\n", header, Xmin_, Xmax_, Xmax_-Xmin_, Xvals_.size()); + mprintf("%sSpline table X range is %g to %g\n", header, Xvals_.front(), Xvals_.back()); +} + +/** Print memory usage to STDOUT. */ +void SplineFxnTable::PrintMemUsage(const char* header) const { + // Memory saved Y values plus spline B, C, and D coefficient arrays. + mprintf("%sMemory used by table and splines: %s\n", header, + ByteString((table_.size()+Xvals_.size()+4) * sizeof(double), BYTE_DECIMAL).c_str()); +} + /** Fill the spline function table with values from the given function. */ //int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double maxIn, double scale) int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double maxIn) @@ -39,7 +52,6 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m } // Calculate table size int ArraySize = ((int)ceil(one_over_Dx_ * width)) + 1; - mprintf("DEBUG: Table from %g to %g, width is %g table size %i\n", minIn, maxIn, width, ArraySize); int minIdx = 0; Xvals_.clear(); @@ -56,7 +68,6 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m Yvals.push_back( yval ); } Xmin_ = Xvals_.front(); - mprintf("DEBUG: Spline table X range is %g to %g\n", Xvals_.front(), Xvals_.back()); Spline cspline; cspline.CubicSpline_Coeff(Xvals_, Yvals); //Xvals.clear(); @@ -69,9 +80,7 @@ int SplineFxnTable::FillTable(FxnType fxnIn, double dxIn, double minIn, double m table_.push_back( cspline.C_coeff()[i] ); table_.push_back( cspline.D_coeff()[i] ); } - // Memory saved Y values plus spline B, C, and D coefficient arrays. - mprintf("\tMemory used by table and splines: %s\n", - ByteString(table_.size() * sizeof(double), BYTE_DECIMAL).c_str()); + return 0; } @@ -111,9 +120,6 @@ int SplineFxnTable::FillTable(FxnType fxnIn, int mesh_size, double minIn, double Yvals.push_back( yval ); } - // Calculate table size - mprintf("DEBUG: Table from %g to %g, width is %g table size %i\n", minIn, maxIn, width, mesh_size); - Spline cspline; cspline.CubicSpline_Coeff(Xvals_, Yvals); @@ -126,9 +132,7 @@ int SplineFxnTable::FillTable(FxnType fxnIn, int mesh_size, double minIn, double table_.push_back( cspline.C_coeff()[i] ); table_.push_back( cspline.D_coeff()[i] ); } - // Memory saved Y values plus spline B, C, and D coefficient arrays. - mprintf("\tMemory used by table and splines: %s\n", - ByteString(table_.size() * sizeof(double), BYTE_DECIMAL).c_str()); + return 0; } diff --git a/src/SplineFxnTable.h b/src/SplineFxnTable.h index cc3313c5a7..80a986d83d 100644 --- a/src/SplineFxnTable.h +++ b/src/SplineFxnTable.h @@ -61,7 +61,10 @@ class SplineFxnTable { double Yval_accurate(double) const; /// \return Number of values in the table unsigned int Nvals() const { return Xvals_.size(); } - + /// Print table details to STDOUT + void PrintTableInfo(const char*) const; + /// Print memory usage to STDOUT + void PrintMemUsage(const char*) const; // DEBUG Access to internal table std::vector const& InternalTable() const { return table_; } private: From 1f973785d11a666bff2bc1ad3065944f989508c2 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 10:17:53 -0500 Subject: [PATCH 76/87] Add debug info. Do not set up spline table if using system exp() --- src/Action_Volmap.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index f8695d1835..34de5ed9ad 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -75,6 +75,7 @@ void Action_Volmap::RawHelp() const { // Action_Volmap::Init() Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { + debug_ = debugIn; # ifdef MPI trajComm_ = init.TrajComm(); # endif @@ -408,8 +409,13 @@ Action::RetType Action_Volmap::Setup(ActionSetup& setup) { //mprintf("DEBUG: %g %g %g %g\n", maxx, maxy, maxz, maxDist); maxDist *= (-1.0 / (2.0 * maxRad * maxRad)); //mprintf("DEBUG: max= %g\n", maxDist); +# ifndef VOLMAP_USEEXP // Set up the interpolation table if (table_.FillTable( exp, splineDx_, maxDist, 1.0 )) return Action::ERR; + table_.PrintMemUsage("\t"); + if (debug_ > 0) + table_.PrintTableInfo("DEBUG: "); +# endif if ((int)Atoms_.size() < densitymask_.Nselected()) mprintf("Warning: %i atoms have 0.0 radii and will be skipped.\n", From 8fdcc625cac62d1efe52dd01c792bde58be85549 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 10:23:27 -0500 Subject: [PATCH 77/87] Add a warning if any grid spacings are smaller than 0.4 --- src/Action_Volmap.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Action_Volmap.cpp b/src/Action_Volmap.cpp index 34de5ed9ad..bde15ec75e 100644 --- a/src/Action_Volmap.cpp +++ b/src/Action_Volmap.cpp @@ -222,7 +222,11 @@ Action::RetType Action_Volmap::Init(ArgList& actionArgs, ActionInit& init, int d xmin_ = oxyz[0]; ymin_ = oxyz[1]; zmin_ = oxyz[2]; - } + } + // Warn for small grid spacing + if (dx_ < 0.4 || dy_ < 0.4 || dz_ < 0.4) + mprintf("Warning: Grid spacings smaller than 0.4 Ang. may be very slow;\n" + "Warning: consider using larger grid spacings.\n"); //std::string density = actionArgs.GetStringKey("density"); // FIXME obsolete? // Get the required mask std::string reqmask = actionArgs.GetMaskNext(); From 7f35b88576f928d6ef45dfb7514bee6def448c38 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 13:22:12 -0500 Subject: [PATCH 78/87] Use SplineFxnTable for erfc --- src/Ewald.cpp | 24 ++++++++++++++++-------- src/Ewald.h | 10 ++++++---- src/Ewald_ParticleMesh.cpp | 2 +- src/Ewald_Regular.cpp | 2 +- src/cpptrajdepend | 8 ++++---- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/Ewald.cpp b/src/Ewald.cpp index 2c860a11e0..a055f77195 100644 --- a/src/Ewald.cpp +++ b/src/Ewald.cpp @@ -22,8 +22,8 @@ Ewald::Ewald() : cut2_(0.0), cut2_0_(0.0), dsumTol_(0.0), - erfcTableDx_(0.0), - one_over_Dx_(0.0), +// erfcTableDx_(0.0), +// one_over_Dx_(0.0), debug_(0) { # ifdef DEBUG_EWALD @@ -92,6 +92,7 @@ double Ewald::erfc_func(double xIn) { } // Ewald::FillErfcTable() +/* void Ewald::FillErfcTable(double cutoffIn, double dxdr) { one_over_Dx_ = 1.0 / erfcTableDx_; unsigned int erfcTableSize = (unsigned int)(dxdr * one_over_Dx_ * cutoffIn * 1.5); @@ -120,15 +121,16 @@ void Ewald::FillErfcTable(double cutoffIn, double dxdr) { // Memory saved Y values plus spline B, C, and D coefficient arrays. mprintf("\tMemory used by Erfc table and splines: %s\n", ByteString(erfc_table_.size() * sizeof(double), BYTE_DECIMAL).c_str()); -} +}*/ // Ewald::ERFC() double Ewald::ERFC(double xIn) const { - int xidx = ((int)(one_over_Dx_ * xIn)); + return table_.Yval( xIn); +/* int xidx = ((int)(one_over_Dx_ * xIn)); double dx = xIn - ((double)xidx * erfcTableDx_); xidx *= 4; return erfc_table_[xidx] + - dx*(erfc_table_[xidx+1] + dx*(erfc_table_[xidx+2] + dx*erfc_table_[xidx+3])); + dx*(erfc_table_[xidx+1] + dx*(erfc_table_[xidx+2] + dx*erfc_table_[xidx+3]));*/ } /** Determine Ewald coefficient from cutoff and direct sum tolerance. @@ -223,7 +225,7 @@ int Ewald::CheckInput(Box const& boxIn, int debugIn, double cutoffIn, double dsu ew_coeff_ = ew_coeffIn; lw_coeff_ = lw_coeffIn; switch_width_ = switch_widthIn; - erfcTableDx_ = erfcTableDxIn; + double erfcTableDx = erfcTableDxIn; // Check input if (cutoff_ < Constants::SMALL) { mprinterr("Error: Direct space cutoff (%g) is too small.\n", cutoff_); @@ -252,9 +254,15 @@ int Ewald::CheckInput(Box const& boxIn, int debugIn, double cutoffIn, double dsu dsumTol_ = 1E-5; if (DABS(ew_coeff_) < Constants::SMALL) ew_coeff_ = FindEwaldCoefficient( cutoff_, dsumTol_ ); - if (erfcTableDx_ <= 0.0) erfcTableDx_ = 1.0 / 5000; + if (erfcTableDx <= 0.0) erfcTableDx = 1.0 / 5000; // TODO make this optional - FillErfcTable( cutoff_, ew_coeff_ ); + //FillErfcTable( cutoff_, ew_coeff_ ); + if (table_.FillTable( erfc_func, erfcTableDx, 0.0, cutoff_*ew_coeff_*1.5 )) { + mprinterr("Error: Could not set up spline table for ERFC\n"); + return 1; + } + table_.PrintMemUsage("\t"); + table_.PrintTableInfo("\t"); // TODO do for C6 as well // TODO for C6 correction term if (lw_coeff_ < 0.0) diff --git a/src/Ewald.h b/src/Ewald.h index 68e847220a..6138f38008 100644 --- a/src/Ewald.h +++ b/src/Ewald.h @@ -7,6 +7,7 @@ class NonbondParmType; #include "Timer.h" #include "PairList.h" #include "ExclusionArray.h" +#include "SplineFxnTable.h" /// Base class for calculating non-bonded energy using Ewald methods. class Ewald { public: @@ -35,7 +36,7 @@ class Ewald { static double FindEwaldCoefficient(double,double); /// Fill erfc lookup table using cubic spline interpolation. - void FillErfcTable(double,double); + //void FillErfcTable(double,double); /// \return erfc value from erfc lookup table. inline double ERFC(double) const; /// Ewald "self" energy @@ -77,11 +78,12 @@ class Ewald { Darray Charge_; ///< Hold selected atomic charges converted to Amber units. Darray Cparam_; ///< Hold selected atomic C6 coefficients for LJ PME PairList pairList_; ///< Atom pair list for direct sum. - Darray erfc_table_; ///< Hold Erfc cubic spline Y values and coefficients (Y B C D). +// Darray erfc_table_; ///< Hold Erfc cubic spline Y values and coefficients (Y B C D). // TODO should Exlcusions be passed in? ExclusionArray Excluded_; ///< Full exclusion list for each selected atom. Iarray TypeIndices_; ///< Hold atom type indices for selected atoms NonbondParmType const* NB_; ///< Pointer to nonbonded parameters + SplineFxnTable table_; ///< Hold spline interpolation for erfc static const double INVSQRTPI_; double sumq_; ///< Sum of charges @@ -93,8 +95,8 @@ class Ewald { double cut2_; ///< Direct space cutoff squared. double cut2_0_; ///< Direct space cutoff minus switch width, squared. double dsumTol_; ///< Direct space sum tolerance. - double erfcTableDx_; ///< Spacing of X values in Erfc table. - double one_over_Dx_; ///< One over erfcTableDx_. +// double erfcTableDx_; ///< Spacing of X values in Erfc table. +// double one_over_Dx_; ///< One over erfcTableDx_. double Vdw_Recip_term_; ///< VDW recip correction term from # types and B parameters int debug_; Timer t_total_; // TODO make timing external diff --git a/src/Ewald_ParticleMesh.cpp b/src/Ewald_ParticleMesh.cpp index be1645f441..8b07a9db74 100644 --- a/src/Ewald_ParticleMesh.cpp +++ b/src/Ewald_ParticleMesh.cpp @@ -113,7 +113,7 @@ int Ewald_ParticleMesh::Init(Box const& boxIn, double cutoffIn, double dsumTolIn if (switch_width_ > 0.0) mprintf("\t LJ switch width= %g\n", switch_width_); mprintf("\t Bspline order= %i\n", order_); - mprintf("\t Erfc table dx= %g, size= %zu\n", erfcTableDx_, erfc_table_.size()/4); + //mprintf("\t Erfc table dx= %g, size= %zu\n", erfcTableDx_, erfc_table_.size()/4); mprintf("\t "); for (int i = 0; i != 3; i++) if (nfft_[i] == -1) diff --git a/src/Ewald_Regular.cpp b/src/Ewald_Regular.cpp index fc064fd89b..b58aa26e93 100644 --- a/src/Ewald_Regular.cpp +++ b/src/Ewald_Regular.cpp @@ -149,7 +149,7 @@ int Ewald_Regular::Init(Box const& boxIn, double cutoffIn, double dsumTolIn, dou cutoff_, dsumTol_, ew_coeff_); mprintf("\t MaxExp= %g Recip. Sum Tol= %g NB skin= %g\n", maxexp_, rsumTol_, skinnbIn); - mprintf("\t Erfc table dx= %g, size= %zu\n", erfcTableDx_, erfc_table_.size()/4); + //mprintf("\t Erfc table dx= %g, size= %zu\n", erfcTableDx_, erfc_table_.size()/4); mprintf("\t mlimits= {%i,%i,%i} Max=%i\n", mlimit_[0], mlimit_[1], mlimit_[2], maxmlim_); // Set up pair list if (Setup_Pairlist(boxIn, recipLengths, skinnbIn)) return 1; diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 22b76e4799..5201b3ab3c 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -30,7 +30,7 @@ Action_DihedralRMS.o : Action_DihedralRMS.cpp Action.h ActionState.h Action_Dihe Action_Dipole.o : Action_Dipole.cpp Action.h ActionState.h Action_Dipole.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_GridFlt.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h Grid.h GridAction.h GridBin.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_DistRmsd.o : Action_DistRmsd.cpp Action.h ActionState.h Action_DistRmsd.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceAction.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_Distance.o : Action_Distance.cpp Action.h ActionState.h Action_Distance.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImagedAction.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Action_Energy.o : Action_Energy.cpp Action.h ActionState.h Action_Energy.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h Energy.h Ewald.h Ewald_ParticleMesh.h Ewald_Regular.h ExclusionArray.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h helpme_standalone.h +Action_Energy.o : Action_Energy.cpp Action.h ActionState.h Action_Energy.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h Energy.h Ewald.h Ewald_ParticleMesh.h Ewald_Regular.h ExclusionArray.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SplineFxnTable.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h helpme_standalone.h Action_Esander.o : Action_Esander.cpp Action.h ActionState.h Action_Esander.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h Energy_Sander.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_FilterByData.o : Action_FilterByData.cpp Action.h ActionState.h Action_FilterByData.h ArgList.h Array1D.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_FixAtomOrder.o : Action_FixAtomOrder.cpp Action.h ActionState.h ActionTopWriter.h Action_FixAtomOrder.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomTopType.h AtomType.h BaseIOtype.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h @@ -241,9 +241,9 @@ EnsembleOut.o : EnsembleOut.cpp ActionFrameCounter.h BaseIOtype.h Box.h Coordina EnsembleOutList.o : EnsembleOutList.cpp ActionFrameCounter.h ArgList.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajStdio.h EnsembleOut.h EnsembleOutList.h EnsembleOut_Multi.h EnsembleOut_Single.h FileName.h FileTypes.h Frame.h FramePtrArray.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Topology.h TrajectoryFile.h TypeNameHolder.h Unit.h Vec3.h EnsembleOut_Multi.o : EnsembleOut_Multi.cpp ActionFrameCounter.h ArgList.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajStdio.h EnsembleOut.h EnsembleOut_Multi.h FileName.h FileTypes.h Frame.h FramePtrArray.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h Topology.h TrajectoryFile.h TrajectoryIO.h TypeNameHolder.h Unit.h Vec3.h EnsembleOut_Single.o : EnsembleOut_Single.cpp ActionFrameCounter.h ArgList.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajStdio.h EnsembleOut.h EnsembleOut_Single.h FileName.h FileTypes.h Frame.h FramePtrArray.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Topology.h TrajectoryFile.h TrajectoryIO.h TypeNameHolder.h Unit.h Vec3.h -Ewald.o : Ewald.cpp Atom.h AtomMask.h AtomType.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajStdio.h EnergyKernel_Adjust.h EnergyKernel_Nonbond.h Ewald.h ExclusionArray.h FileName.h Frame.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h PairList.h PairListLoop.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h Spline.h StringRoutines.h SymbolExporting.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Ewald_ParticleMesh.o : Ewald_ParticleMesh.cpp Atom.h AtomMask.h Box.h CoordinateInfo.h CpptrajStdio.h Ewald.h Ewald_ParticleMesh.h ExclusionArray.h Frame.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h PairList.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Timer.h Unit.h Vec3.h helpme_standalone.h -Ewald_Regular.o : Ewald_Regular.cpp Atom.h AtomMask.h Box.h Constants.h CoordinateInfo.h CpptrajStdio.h Ewald.h Ewald_Regular.h ExclusionArray.h Frame.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h PairList.h Parallel.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h Timer.h Unit.h Vec3.h +Ewald.o : Ewald.cpp Atom.h AtomMask.h AtomType.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajStdio.h EnergyKernel_Adjust.h EnergyKernel_Nonbond.h Ewald.h ExclusionArray.h FileName.h Frame.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h PairList.h PairListLoop.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h Spline.h SplineFxnTable.h StringRoutines.h SymbolExporting.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Ewald_ParticleMesh.o : Ewald_ParticleMesh.cpp Atom.h AtomMask.h Box.h CoordinateInfo.h CpptrajStdio.h Ewald.h Ewald_ParticleMesh.h ExclusionArray.h Frame.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h PairList.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SplineFxnTable.h SymbolExporting.h Timer.h Unit.h Vec3.h helpme_standalone.h +Ewald_Regular.o : Ewald_Regular.cpp Atom.h AtomMask.h Box.h Constants.h CoordinateInfo.h CpptrajStdio.h Ewald.h Ewald_Regular.h ExclusionArray.h Frame.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h PairList.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SplineFxnTable.h StringRoutines.h SymbolExporting.h Timer.h Unit.h Vec3.h ExclusionArray.o : ExclusionArray.cpp Atom.h AtomMask.h CharMask.h CpptrajStdio.h ExclusionArray.h MaskToken.h Molecule.h NameType.h Residue.h Segment.h StringRoutines.h SymbolExporting.h Unit.h Exec_AddMissingRes.o : Exec_AddMissingRes.cpp Action.h ActionFrameCounter.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnergyArray.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_AddMissingRes.h Exec_AddMissingRes_Pres.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Minimize_SteepestDescent.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h PotentialFunction.h PotentialTerm.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h TrajectoryFile.h Trajin.h TrajinList.h Trajin_Single.h TrajoutList.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h Exec_Analyze.o : Exec_Analyze.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Cmd.h CmdList.h Command.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_Analyze.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h From 019ea07a729f4ca28ce408a5035c8f66b068601c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 13:24:23 -0500 Subject: [PATCH 79/87] Make erfc things private --- src/Ewald.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Ewald.h b/src/Ewald.h index 6138f38008..30a4955c30 100644 --- a/src/Ewald.h +++ b/src/Ewald.h @@ -35,10 +35,6 @@ class Ewald { /// Determine Ewald coefficient from cutoff and direct sum tolerance. static double FindEwaldCoefficient(double,double); - /// Fill erfc lookup table using cubic spline interpolation. - //void FillErfcTable(double,double); - /// \return erfc value from erfc lookup table. - inline double ERFC(double) const; /// Ewald "self" energy double Self(double); /// Ewald "self" energy for C6 term @@ -83,7 +79,6 @@ class Ewald { ExclusionArray Excluded_; ///< Full exclusion list for each selected atom. Iarray TypeIndices_; ///< Hold atom type indices for selected atoms NonbondParmType const* NB_; ///< Pointer to nonbonded parameters - SplineFxnTable table_; ///< Hold spline interpolation for erfc static const double INVSQRTPI_; double sumq_; ///< Sum of charges @@ -107,7 +102,12 @@ class Ewald { Timer t_erfc_; Timer t_adjust_; private: + /// \return erfc value from erfc lookup table. + inline double ERFC(double) const; + double Direct_VDW_LongRangeCorrection(PairList const&, double&); double Direct_VDW_LJPME(PairList const&, double&); + + SplineFxnTable table_; ///< Hold spline interpolation for erfc }; #endif From cf151899f3297b27b91199cea7f2573026f79452 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 13:29:01 -0500 Subject: [PATCH 80/87] Make function private --- src/Ewald.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ewald.h b/src/Ewald.h index 30a4955c30..d49dd276b3 100644 --- a/src/Ewald.h +++ b/src/Ewald.h @@ -32,8 +32,6 @@ class Ewald { static inline double DABS(double xIn) { if (xIn < 0.0) return -xIn; else return xIn; } /// Complimentary error function, erfc. static double erfc_func(double); - /// Determine Ewald coefficient from cutoff and direct sum tolerance. - static double FindEwaldCoefficient(double,double); /// Ewald "self" energy double Self(double); @@ -104,6 +102,8 @@ class Ewald { private: /// \return erfc value from erfc lookup table. inline double ERFC(double) const; + /// Determine Ewald coefficient from cutoff and direct sum tolerance. + static double FindEwaldCoefficient(double,double); double Direct_VDW_LongRangeCorrection(PairList const&, double&); double Direct_VDW_LJPME(PairList const&, double&); From d21affd421f17afddfb35bafe2848a165b1ba1bc Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 13:30:23 -0500 Subject: [PATCH 81/87] Rename function to avoid confusion --- src/Ewald.cpp | 2 +- src/Ewald.h | 2 +- src/Ewald_ParticleMesh.cpp | 2 +- src/Ewald_Regular.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Ewald.cpp b/src/Ewald.cpp index a055f77195..fd9ca12506 100644 --- a/src/Ewald.cpp +++ b/src/Ewald.cpp @@ -202,7 +202,7 @@ void Ewald::CalculateC6params(Topology const& topIn, AtomMask const& maskIn) { } /** Set up exclusion lists for selected atoms. */ -void Ewald::SetupExcluded(Topology const& topIn, AtomMask const& maskIn) +void Ewald::SetupExclusionList(Topology const& topIn, AtomMask const& maskIn) { // Use distance of 4 (up to dihedrals) if (Excluded_.SetupExcluded(topIn.Atoms(), maskIn, 4, diff --git a/src/Ewald.h b/src/Ewald.h index d49dd276b3..3e252e49b2 100644 --- a/src/Ewald.h +++ b/src/Ewald.h @@ -48,7 +48,7 @@ class Ewald { /// Calculate VDW C6 parameters for LJ PME void CalculateC6params(Topology const&, AtomMask const&); /// Setup main excluded atom list - void SetupExcluded(Topology const&, AtomMask const&); + void SetupExclusionList(Topology const&, AtomMask const&); /// Setup VDW correction for selected atom types void Setup_VDW_Correction(Topology const&, AtomMask const&); diff --git a/src/Ewald_ParticleMesh.cpp b/src/Ewald_ParticleMesh.cpp index 8b07a9db74..5786c2d113 100644 --- a/src/Ewald_ParticleMesh.cpp +++ b/src/Ewald_ParticleMesh.cpp @@ -139,7 +139,7 @@ int Ewald_ParticleMesh::Setup(Topology const& topIn, AtomMask const& maskIn) { CalculateC6params( topIn, maskIn ); coordsD_.clear(); coordsD_.reserve( maskIn.Nselected() * 3); - SetupExcluded(topIn, maskIn); + SetupExclusionList(topIn, maskIn); return 0; } diff --git a/src/Ewald_Regular.cpp b/src/Ewald_Regular.cpp index b58aa26e93..3a4a45e94c 100644 --- a/src/Ewald_Regular.cpp +++ b/src/Ewald_Regular.cpp @@ -187,7 +187,7 @@ int Ewald_Regular::Setup(Topology const& topIn, AtomMask const& maskIn) { // sinf3_.push_back( 0.0 ); // } - SetupExcluded(topIn, maskIn); + SetupExclusionList(topIn, maskIn); # ifdef _OPENMP // Pre-calculate m1 and m2 indices From c7c4756a28b9a8c032112987f7a0a582d3685d97 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 13:31:59 -0500 Subject: [PATCH 82/87] Make function private. Add some code docs --- src/Ewald.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Ewald.h b/src/Ewald.h index 3e252e49b2..694d59afca 100644 --- a/src/Ewald.h +++ b/src/Ewald.h @@ -49,8 +49,6 @@ class Ewald { void CalculateC6params(Topology const&, AtomMask const&); /// Setup main excluded atom list void SetupExclusionList(Topology const&, AtomMask const&); - /// Setup VDW correction for selected atom types - void Setup_VDW_Correction(Topology const&, AtomMask const&); # ifdef DEBUG_EWALD /// Slow version of direct space energy, no pairlist. @@ -105,7 +103,11 @@ class Ewald { /// Determine Ewald coefficient from cutoff and direct sum tolerance. static double FindEwaldCoefficient(double,double); + /// Setup VDW correction for selected atom types + void Setup_VDW_Correction(Topology const&, AtomMask const&); + /// Direct-space energy with VDW long range corrected energy double Direct_VDW_LongRangeCorrection(PairList const&, double&); + /// Direct-space energy with VDW handled via PME double Direct_VDW_LJPME(PairList const&, double&); SplineFxnTable table_; ///< Hold spline interpolation for erfc From 17377733d339545e7941d3e159377df338d7296f Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 13:40:37 -0500 Subject: [PATCH 83/87] Make more vars private --- src/Ewald.cpp | 9 ++++----- src/Ewald.h | 15 +++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Ewald.cpp b/src/Ewald.cpp index fd9ca12506..71f53fda31 100644 --- a/src/Ewald.cpp +++ b/src/Ewald.cpp @@ -13,8 +13,6 @@ /// CONSTRUCTOR Ewald::Ewald() : - sumq_(0.0), - sumq2_(0.0), ew_coeff_(0.0), lw_coeff_(0.0), switch_width_(0.0), @@ -22,9 +20,10 @@ Ewald::Ewald() : cut2_(0.0), cut2_0_(0.0), dsumTol_(0.0), -// erfcTableDx_(0.0), -// one_over_Dx_(0.0), - debug_(0) + debug_(0), + sumq_(0.0), + sumq2_(0.0), + Vdw_Recip_term_(0) { # ifdef DEBUG_EWALD // Save fractional translations for 1 cell in each direction (and primary cell). diff --git a/src/Ewald.h b/src/Ewald.h index 694d59afca..598e6b6c1b 100644 --- a/src/Ewald.h +++ b/src/Ewald.h @@ -64,9 +64,6 @@ class Ewald { # endif // TODO make variables private -# ifdef DEBUG_EWALD - Varray Cells_; ///< Hold fractional translations to neighbor cells (non-pairlist only) -# endif Darray Charge_; ///< Hold selected atomic charges converted to Amber units. Darray Cparam_; ///< Hold selected atomic C6 coefficients for LJ PME PairList pairList_; ///< Atom pair list for direct sum. @@ -77,8 +74,6 @@ class Ewald { NonbondParmType const* NB_; ///< Pointer to nonbonded parameters static const double INVSQRTPI_; - double sumq_; ///< Sum of charges - double sumq2_; ///< Sum of charges squared double ew_coeff_; ///< Ewald coefficient for electrostatics double lw_coeff_; ///< Ewald coefficient for LJ double switch_width_; ///< Switching window size for LJ switch if active @@ -86,9 +81,6 @@ class Ewald { double cut2_; ///< Direct space cutoff squared. double cut2_0_; ///< Direct space cutoff minus switch width, squared. double dsumTol_; ///< Direct space sum tolerance. -// double erfcTableDx_; ///< Spacing of X values in Erfc table. -// double one_over_Dx_; ///< One over erfcTableDx_. - double Vdw_Recip_term_; ///< VDW recip correction term from # types and B parameters int debug_; Timer t_total_; // TODO make timing external Timer t_self_; @@ -111,5 +103,12 @@ class Ewald { double Direct_VDW_LJPME(PairList const&, double&); SplineFxnTable table_; ///< Hold spline interpolation for erfc +# ifdef DEBUG_EWALD + Varray Cells_; ///< Hold fractional translations to neighbor cells (non-pairlist only) +# endif + double sumq_; ///< Sum of charges + double sumq2_; ///< Sum of charges squared + double Vdw_Recip_term_; ///< VDW recip correction term from # types and B parameters + }; #endif From 21cb551e9f9374e9a9bbd286bfc14ec2248bb7c2 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 13:42:11 -0500 Subject: [PATCH 84/87] Remove obsolete code --- src/Ewald.cpp | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/src/Ewald.cpp b/src/Ewald.cpp index 71f53fda31..07c44b9a03 100644 --- a/src/Ewald.cpp +++ b/src/Ewald.cpp @@ -90,46 +90,9 @@ double Ewald::erfc_func(double xIn) { return erfc; } -// Ewald::FillErfcTable() -/* -void Ewald::FillErfcTable(double cutoffIn, double dxdr) { - one_over_Dx_ = 1.0 / erfcTableDx_; - unsigned int erfcTableSize = (unsigned int)(dxdr * one_over_Dx_ * cutoffIn * 1.5); - Darray erfc_X, erfc_Y; - erfc_X.reserve( erfcTableSize ); - erfc_Y.reserve( erfcTableSize ); - // Save X and Y values so we can calc the spline coefficients - double xval = 0.0; - for (unsigned int i = 0; i != erfcTableSize; i++) { - double yval = erfc_func( xval ); - erfc_X.push_back( xval ); - erfc_Y.push_back( yval ); - xval += erfcTableDx_; - } - Spline cspline; - cspline.CubicSpline_Coeff(erfc_X, erfc_Y); - erfc_X.clear(); - // Store values in Spline table - erfc_table_.reserve( erfcTableSize * 4 ); // Y B C D - for (unsigned int i = 0; i != erfcTableSize; i++) { - erfc_table_.push_back( erfc_Y[i] ); - erfc_table_.push_back( cspline.B_coeff()[i] ); - erfc_table_.push_back( cspline.C_coeff()[i] ); - erfc_table_.push_back( cspline.D_coeff()[i] ); - } - // Memory saved Y values plus spline B, C, and D coefficient arrays. - mprintf("\tMemory used by Erfc table and splines: %s\n", - ByteString(erfc_table_.size() * sizeof(double), BYTE_DECIMAL).c_str()); -}*/ - // Ewald::ERFC() double Ewald::ERFC(double xIn) const { return table_.Yval( xIn); -/* int xidx = ((int)(one_over_Dx_ * xIn)); - double dx = xIn - ((double)xidx * erfcTableDx_); - xidx *= 4; - return erfc_table_[xidx] + - dx*(erfc_table_[xidx+1] + dx*(erfc_table_[xidx+2] + dx*erfc_table_[xidx+3]));*/ } /** Determine Ewald coefficient from cutoff and direct sum tolerance. @@ -255,7 +218,6 @@ int Ewald::CheckInput(Box const& boxIn, int debugIn, double cutoffIn, double dsu ew_coeff_ = FindEwaldCoefficient( cutoff_, dsumTol_ ); if (erfcTableDx <= 0.0) erfcTableDx = 1.0 / 5000; // TODO make this optional - //FillErfcTable( cutoff_, ew_coeff_ ); if (table_.FillTable( erfc_func, erfcTableDx, 0.0, cutoff_*ew_coeff_*1.5 )) { mprinterr("Error: Could not set up spline table for ERFC\n"); return 1; From 5e1df6f8b14974a2a430adc9d24f0061ce1db092 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 13:50:58 -0500 Subject: [PATCH 85/87] Make more variables private --- src/Ewald.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Ewald.h b/src/Ewald.h index 598e6b6c1b..7b6f6b1204 100644 --- a/src/Ewald.h +++ b/src/Ewald.h @@ -67,11 +67,6 @@ class Ewald { Darray Charge_; ///< Hold selected atomic charges converted to Amber units. Darray Cparam_; ///< Hold selected atomic C6 coefficients for LJ PME PairList pairList_; ///< Atom pair list for direct sum. -// Darray erfc_table_; ///< Hold Erfc cubic spline Y values and coefficients (Y B C D). - // TODO should Exlcusions be passed in? - ExclusionArray Excluded_; ///< Full exclusion list for each selected atom. - Iarray TypeIndices_; ///< Hold atom type indices for selected atoms - NonbondParmType const* NB_; ///< Pointer to nonbonded parameters static const double INVSQRTPI_; double ew_coeff_; ///< Ewald coefficient for electrostatics @@ -109,6 +104,10 @@ class Ewald { double sumq_; ///< Sum of charges double sumq2_; ///< Sum of charges squared double Vdw_Recip_term_; ///< VDW recip correction term from # types and B parameters + // TODO should Exlcusions be passed in? + ExclusionArray Excluded_; ///< Full exclusion list for each selected atom. + Iarray TypeIndices_; ///< Hold atom type indices for selected atoms + NonbondParmType const* NB_; ///< Pointer to nonbonded parameters }; #endif From b652f6add46be02e3a0c794f07ce0877f382aac6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 13:59:18 -0500 Subject: [PATCH 86/87] Minor version bump for using splines to speed up volmap. In principle the defaults chosen should make it so that the results are exactly the same as with system exp(); however there is the potential for some differences, so bump the minor version instead of revision. --- src/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Version.h b/src/Version.h index e09a559403..125cff020a 100644 --- a/src/Version.h +++ b/src/Version.h @@ -12,7 +12,7 @@ * Whenever a number that precedes is incremented, all subsequent * numbers should be reset to 0. */ -#define CPPTRAJ_INTERNAL_VERSION "V4.32.3" +#define CPPTRAJ_INTERNAL_VERSION "V4.33.0" /// PYTRAJ relies on this #define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION #endif From 3e22bb94f28e16c40224153e32af61a434704a51 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 30 Dec 2020 14:09:25 -0500 Subject: [PATCH 87/87] Add 'splinedx' to volmap help --- doc/cpptraj.lyx | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/cpptraj.lyx b/doc/cpptraj.lyx index 9eacbfd5dd..bfc1e487dd 100644 --- a/doc/cpptraj.lyx +++ b/doc/cpptraj.lyx @@ -35435,7 +35435,7 @@ volmap [out ] [radscale ] [stepfac ] \end_layout \begin_layout LyX-Code - [sphere] [radii {vdw | element}] + [sphere] [radii {vdw | element}] [splinedx ] \end_layout \begin_layout LyX-Code @@ -35528,6 +35528,14 @@ radii radii. \end_layout +\begin_layout Description +splinedx +\begin_inset space ~ +\end_inset + + Spacing to use for cubic spline interpolation (default 0.01 Ang.). +\end_layout + \begin_layout Description calcpeaks If specified, peaks in the grid density will be calculated and saved to set with aspect @@ -35737,6 +35745,25 @@ buffer . \end_layout +\begin_layout Standard +The calculation is sped up by using cubic splines to interpolate the exponential + function when calculating the Gaussians. + The details are in Roe & Brooks, +\begin_inset Quotes eld +\end_inset + +Improving the Speed of Volumetric Density Map Generation via Cubic Spline + Interpolation +\begin_inset Quotes erd +\end_inset + +, J. + Mol. + Graph. + Model. + (2021). +\end_layout + \begin_layout Subsection volume \end_layout