From 5527b0cf4b0815516cd9a681c1929f347e29732c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 22 Mar 2024 11:06:53 -0400 Subject: [PATCH 001/200] Start adding CoordCovarMatrix class --- src/CoordCovarMatrix.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ src/CoordCovarMatrix.h | 25 +++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/CoordCovarMatrix.cpp create mode 100644 src/CoordCovarMatrix.h diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp new file mode 100644 index 0000000000..f7c0873a74 --- /dev/null +++ b/src/CoordCovarMatrix.cpp @@ -0,0 +1,43 @@ +#include "CoordCovarMatrix.h" +#include "AtomMask.h" +#include "Frame.h" + +/** CONSTRUCTOR */ +CoordCovarMatrix::CoordCovarMatrix() : + nframes_(0) +{} + +/** Clear the matrix */ +void CoordCovarMatrix::Clear() { + covarMatrix_.clear(); + vect_.clear(); + nframes_ = 0; +} + +/** Add given Frame to the matrix. */ +void CoordCovarMatrix::AddFrame(Frame const& frameIn, AtomMask const& maskIn) +{ + // Covariance + MatType::iterator mat = covarMatrix_.begin(); + for (int idx1 = 0; idx1 < maskIn.Nselected(); idx1++) { + Vec3 XYZi( frameIn.XYZ(idx1) ); + // Store veci and veci^2 + vect_[idx1] += XYZi; + //vect2[idx1] += XYZi.Squared(); + // Loop over X, Y, and Z of veci + for (int iidx = 0; iidx < 3; iidx++) { + double Vi = XYZi[iidx]; + // Diagonal + for (int jidx = iidx; jidx < 3; jidx++) + *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} + // Inner loop + for (int idx2 = idx1 + 1; idx2 < maskIn.Nselected(); idx2++) { + Vec3 XYZj( frameIn.XYZ(idx2) ); + *(mat++) += Vi * XYZj[0]; + *(mat++) += Vi * XYZj[1]; + *(mat++) += Vi * XYZj[2]; + } // END inner loop over idx2 + } // END loop over x y z of veci + } // END outer loop over idx1 + nframes_++; +} diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h new file mode 100644 index 0000000000..32f84ba66c --- /dev/null +++ b/src/CoordCovarMatrix.h @@ -0,0 +1,25 @@ +#ifndef INC_COORDCOVARMATRIX_H +#define INC_COORDCOVARMATRIX_H +#include "Matrix.h" +#include "Vec3.h" +#include +class AtomMask; +class Frame; +/// Coordinate covariance matrix +class CoordCovarMatrix { + public: + /// CONSTRUCTOR + CoordCovarMatrix(); + /// Clear the matrix + void Clear(); + /// Add Frame to matrix + void AddFrame(Frame const&, AtomMask const&); + private: + typedef Matrix MatType; + typedef std::vector Varray; + + MatType covarMatrix_; ///< Coordinate covariance matrix + Varray vect_; ///< Store average coordinates along the diagonal + unsigned int nframes_; ///< Number of frames added to the matrix +}; +#endif From 16474c65a680cd0ae3b59e12894f025351373a74 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 22 Mar 2024 11:22:42 -0400 Subject: [PATCH 002/200] Fix mask issues. Add setup and finish routines --- src/CoordCovarMatrix.cpp | 81 ++++++++++++++++++++++++++++++++++++++-- src/CoordCovarMatrix.h | 9 ++++- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index f7c0873a74..aa9c2b3caa 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -1,26 +1,52 @@ #include "CoordCovarMatrix.h" #include "AtomMask.h" +#include "CpptrajStdio.h" #include "Frame.h" /** CONSTRUCTOR */ CoordCovarMatrix::CoordCovarMatrix() : - nframes_(0) + nframes_(0), + useMass_(false) {} /** Clear the matrix */ void CoordCovarMatrix::Clear() { covarMatrix_.clear(); vect_.clear(); + mass_.clear(); nframes_ = 0; } +/** Set up array sizess and masses. */ +int CoordCovarMatrix::SetupMatrix(Frame const& frameIn, AtomMask const& maskIn, bool useMassIn) +{ + useMass_ = useMassIn; + // TODO more size error checking + nframes_ = 0; + vect_.assign(maskIn.Nselected(), Vec3(0.0)); + //Varray vect2(mask1_.Nselected(), Vec3(0.0)); + // Matrix - half + covarMatrix_.resize( maskIn.Nselected()*3, 0 ); + // Masses + mass_.clear(); + if (useMassIn) { + for (AtomMask::const_iterator at = maskIn.begin(); at != maskIn.end(); ++at) + mass_.push_back( frameIn.Mass( *at ) ); + } else { + for (int idx = 0; idx < maskIn.Nselected(); idx++) + mass_.push_back( 1.0 ); + } + return 0; +} + /** Add given Frame to the matrix. */ -void CoordCovarMatrix::AddFrame(Frame const& frameIn, AtomMask const& maskIn) +void CoordCovarMatrix::AddFrameToMatrix(Frame const& frameIn, AtomMask const& maskIn) { // Covariance MatType::iterator mat = covarMatrix_.begin(); for (int idx1 = 0; idx1 < maskIn.Nselected(); idx1++) { - Vec3 XYZi( frameIn.XYZ(idx1) ); + int at1 = maskIn[idx1]; + Vec3 XYZi( frameIn.XYZ(at1) ); // Store veci and veci^2 vect_[idx1] += XYZi; //vect2[idx1] += XYZi.Squared(); @@ -32,7 +58,8 @@ void CoordCovarMatrix::AddFrame(Frame const& frameIn, AtomMask const& maskIn) *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} // Inner loop for (int idx2 = idx1 + 1; idx2 < maskIn.Nselected(); idx2++) { - Vec3 XYZj( frameIn.XYZ(idx2) ); + int at2 = maskIn[idx2]; + Vec3 XYZj( frameIn.XYZ(at2) ); *(mat++) += Vi * XYZj[0]; *(mat++) += Vi * XYZj[1]; *(mat++) += Vi * XYZj[2]; @@ -41,3 +68,49 @@ void CoordCovarMatrix::AddFrame(Frame const& frameIn, AtomMask const& maskIn) } // END outer loop over idx1 nframes_++; } + +/** Finish the matrix. */ +int CoordCovarMatrix::FinishMatrix() { + if (nframes_ < 1) { + mprinterr("Error: No frames in coordinate covariance matrix.\n"); + return 1; + } + // Normalize + double norm = 1.0 / (double)nframes_; + for (Varray::iterator it = vect_.begin(); it != vect_.end(); ++it) + *it *= norm; + for (MatType::iterator it = covarMatrix_.begin(); it != covarMatrix_.end(); ++it) + *it *= norm; + // Calc - + //for (int k = 0; k < mask1_.Nselected(); k++) { + // vect2[k][0] -= (vect[k][0] * vect[k][0]); + // vect2[k][1] -= (vect[k][1] * vect[k][1]); + // vect2[k][2] -= (vect[k][2] * vect[k][2]); + //} + // Calc - + double Mass = 1.0; + double mass1 = 1.0; + MatType::iterator mat = covarMatrix_.begin(); + for (unsigned int idx1 = 0; idx1 < mass_.size(); idx1++) { + mass1 = mass_[idx1]; + for (int iidx = 0; iidx < 3; iidx++) { + double Vi = vect_[idx1][iidx]; + for (unsigned int idx2 = idx1; idx2 < mass_.size(); idx2++) { + Mass = sqrt( mass1 * mass_[idx2] ); + if (idx1 == idx2) { + // Self + for (int jidx = iidx; jidx < 3; jidx++) { + *mat = (*mat - (Vi * vect_[idx2][jidx])) * Mass; + ++mat; + } + } else { + for (int jidx = 0; jidx < 3; jidx++) { + *mat = (*mat - (Vi * vect_[idx2][jidx])) * Mass; + ++mat; + } + } + } // END inner loop over idx2 + } // END loop over elements of vect_[idx1] + } // END outer loop over idx1 + return 0; +} diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 32f84ba66c..4414727f6e 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -12,14 +12,21 @@ class CoordCovarMatrix { CoordCovarMatrix(); /// Clear the matrix void Clear(); + /// Set up the covariance matrix for selected atoms + int SetupMatrix(Frame const&, AtomMask const&, bool); /// Add Frame to matrix - void AddFrame(Frame const&, AtomMask const&); + void AddFrameToMatrix(Frame const&, AtomMask const&); + /// Finish calculating the matrix (normalize, calc - ) + int FinishMatrix(); private: typedef Matrix MatType; + typedef std::vector Darray; typedef std::vector Varray; MatType covarMatrix_; ///< Coordinate covariance matrix Varray vect_; ///< Store average coordinates along the diagonal + Darray mass_; ///< Store selected atoms masses unsigned int nframes_; ///< Number of frames added to the matrix + bool useMass_; ///< If true use mass weighting }; #endif From e1f3572e4dc9e2971ac1a153e9dde92a8858655c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 22 Mar 2024 11:23:39 -0400 Subject: [PATCH 003/200] Add CoordCovarMatrix --- src/cpptrajdepend | 1 + src/cpptrajfiles | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 024bbea344..3c9173d3cf 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -191,6 +191,7 @@ CompactFrameArray.o : CompactFrameArray.cpp Box.h CompactFrameArray.h Coordinate ComplexArray.o : ComplexArray.cpp ArrayIterator.h ComplexArray.h Constraints.o : Constraints.cpp ArgList.h Atom.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 Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.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 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_inData.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h +CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordinateInfo.h CpptrajStdio.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h CoordinateInfo.o : CoordinateInfo.cpp Box.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h Corr.o : Corr.cpp ArrayIterator.h ComplexArray.h Corr.h PubFFT.h Cph.o : Cph.cpp Cph.h NameType.h diff --git a/src/cpptrajfiles b/src/cpptrajfiles index a5b3bb4419..0002bc43c6 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -163,6 +163,7 @@ COMMON_SOURCES= \ ComplexArray.cpp \ Constraints.cpp \ ControlBlock_For.cpp \ + CoordCovarMatrix.cpp \ CoordinateInfo.cpp \ Corr.cpp \ Cph.cpp \ From 3fcc710ee6fec297810b2f805d851a5d31edf002 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 22 Mar 2024 11:32:58 -0400 Subject: [PATCH 004/200] Add debug print --- src/CoordCovarMatrix.cpp | 18 ++++++++++++++++-- src/CoordCovarMatrix.h | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index aa9c2b3caa..929a3a9f9e 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -1,4 +1,5 @@ #include "CoordCovarMatrix.h" +#include "Atom.h" #include "AtomMask.h" #include "CpptrajStdio.h" #include "Frame.h" @@ -18,7 +19,8 @@ void CoordCovarMatrix::Clear() { } /** Set up array sizess and masses. */ -int CoordCovarMatrix::SetupMatrix(Frame const& frameIn, AtomMask const& maskIn, bool useMassIn) +int CoordCovarMatrix::SetupMatrix(std::vector const& atoms, + AtomMask const& maskIn, bool useMassIn) { useMass_ = useMassIn; // TODO more size error checking @@ -31,7 +33,7 @@ int CoordCovarMatrix::SetupMatrix(Frame const& frameIn, AtomMask const& maskIn, mass_.clear(); if (useMassIn) { for (AtomMask::const_iterator at = maskIn.begin(); at != maskIn.end(); ++at) - mass_.push_back( frameIn.Mass( *at ) ); + mass_.push_back( atoms[*at].Mass() ); } else { for (int idx = 0; idx < maskIn.Nselected(); idx++) mass_.push_back( 1.0 ); @@ -114,3 +116,15 @@ int CoordCovarMatrix::FinishMatrix() { } // END outer loop over idx1 return 0; } + +/** Debug print to STDOUT */ +void CoordCovarMatrix::DebugPrint(const char* desc) const { + if (desc != 0) + mprintf("DEBUG: CoordCovarMatrix: %s\n", desc); + for (unsigned int row = 0; row < covarMatrix_.Nrows(); row++) { + for (unsigned int col = 0; col < covarMatrix_.Ncols(); col++) { + mprintf(" %6.3f", covarMatrix_.element(col, row)); + } + mprintf("\n"); + } +} diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 4414727f6e..2ae57a349f 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -3,6 +3,7 @@ #include "Matrix.h" #include "Vec3.h" #include +class Atom; class AtomMask; class Frame; /// Coordinate covariance matrix @@ -13,11 +14,14 @@ class CoordCovarMatrix { /// Clear the matrix void Clear(); /// Set up the covariance matrix for selected atoms - int SetupMatrix(Frame const&, AtomMask const&, bool); + int SetupMatrix(std::vector const&, AtomMask const&, bool); /// Add Frame to matrix void AddFrameToMatrix(Frame const&, AtomMask const&); /// Finish calculating the matrix (normalize, calc - ) int FinishMatrix(); + + /// Print matrix elements to STDOUT for debug + void DebugPrint(const char*) const; private: typedef Matrix MatType; typedef std::vector Darray; From c0e85f2e59fd1c81a9433dbb5afa1a79aad12359 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 22 Mar 2024 11:49:12 -0400 Subject: [PATCH 005/200] Print to debug file for easier comparison --- src/Analysis_TICA.cpp | 37 +++++++++++++++++++++----------- src/Analysis_TICA.h | 1 + src/CoordCovarMatrix.cpp | 44 +++++++++++++++++++++++++++++++++------ src/CoordCovarMatrix.h | 7 +++++-- src/cpptrajdepend | 4 ++-- test/Test_TICA/RunTest.sh | 4 ++-- 6 files changed, 73 insertions(+), 24 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index a7204be90f..02020c2c41 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -1,13 +1,13 @@ #include "Analysis_TICA.h" +#include "CoordCovarMatrix.h" #include "CpptrajStdio.h" -#include "Matrix.h" // TODO DataSet? -#include // sqrt /** CONSTRUCTOR */ Analysis_TICA::Analysis_TICA() : TgtTraj_(0), lag_(0), - useMass_(false) + useMass_(false), + debugFile_(0) { SetHidden(true); } @@ -37,6 +37,12 @@ Analysis::RetType Analysis_TICA::Setup(ArgList& analyzeArgs, AnalysisSetup& setu return Analysis::ERR; } useMass_ = analyzeArgs.hasKey("mass"); + debugFile_ = setup.DFL().AddCpptrajFile(analyzeArgs.GetStringKey("debugfile"), "TICA debug", + DataFileList::TEXT, true); + if (debugFile_ == 0) { + mprinterr("Error: Could not open debug file.\n"); + return Analysis::ERR; + } // Print analysis info mprintf(" TICA: Time independent correlation analysis.\n"); @@ -47,6 +53,8 @@ Analysis::RetType Analysis_TICA::Setup(ArgList& analyzeArgs, AnalysisSetup& setu mprintf("\tMass-weighted.\n"); else mprintf("\tNot mass-weighted.\n"); + if (debugFile_ != 0) + mprintf("\tDebug output to %s\n", debugFile_->Filename().full()); return Analysis::OK; } @@ -72,18 +80,16 @@ Analysis::RetType Analysis_TICA::Analyze() { Frame coords0; coords0.SetupFrameFromMask( mask1_, TgtTraj_->Top().Atoms(), TgtTraj_->CoordsInfo() ); Frame coords1 = coords0; - // Diagonal vectors - typedef std::vector Varray; - Varray vect(mask1_.Nselected(), Vec3(0.0)); - //Varray vect2(mask1_.Nselected(), Vec3(0.0)); // Matrix - half - Matrix covarMatrix; - covarMatrix.resize( mask1_.Nselected()*3, 0 ); + CoordCovarMatrix covarMatrix; + covarMatrix.SetupMatrix(TgtTraj_->Top().Atoms(), mask1_, useMass_ ); // Loop over frames for (unsigned int frm0 = 0; frm0 < Nframes; frm0++) { mprintf("DEBUG: Frame %i\n", frm0); TgtTraj_->GetFrame(frm0, coords0, mask1_); // Covariance + covarMatrix.AddFrameToMatrix( coords0 ); +/* Matrix::iterator mat = covarMatrix.begin(); for (int idx1 = 0; idx1 < mask1_.Nselected(); idx1++) { Vec3 XYZi( coords0.XYZ(idx1) ); @@ -104,10 +110,15 @@ Analysis::RetType Analysis_TICA::Analyze() { *(mat++) += Vi * XYZj[2]; } // END inner loop over idx2 } // END loop over x y z of veci - } // END outer loop over idx1 + } // END outer loop over idx1*/ } // END loop over frames // Normalize + if (covarMatrix.FinishMatrix()) { + mprinterr("Error: Could not normalize coordinate covariance matrix for C0.\n"); + return Analysis::ERR; + } +/* double norm = 1.0 / (double)TgtTraj_->Size(); for (Varray::iterator it = vect.begin(); it != vect.end(); ++it) *it *= norm; @@ -145,13 +156,15 @@ Analysis::RetType Analysis_TICA::Analyze() { } } // END inner loop over idx2 } // END loop over elements of vect[idx1] - } // END outer loop over idx1 + } // END outer loop over idx1*/ // DEBUG PRINT + covarMatrix.DebugPrint("C0", *debugFile_); +/* for (int row = 0; row < mask1_.Nselected()*3; row++) { for (int col = 0; col < mask1_.Nselected()*3; col++) { mprintf(" %6.3f", covarMatrix.element(col, row)); } mprintf("\n"); - } + }*/ return Analysis::OK; } diff --git a/src/Analysis_TICA.h b/src/Analysis_TICA.h index fe44df32af..fc91115c59 100644 --- a/src/Analysis_TICA.h +++ b/src/Analysis_TICA.h @@ -15,5 +15,6 @@ class Analysis_TICA : public Analysis { int lag_; ///< TICA time lag AtomMask mask1_; ///< Atoms to use in matrix calc bool useMass_; ///< Control whether to mass-weight + CpptrajFile* debugFile_; ///< Debug output }; #endif diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index 929a3a9f9e..41d3aebcdb 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -1,8 +1,10 @@ #include "CoordCovarMatrix.h" #include "Atom.h" #include "AtomMask.h" +#include "CpptrajFile.h" #include "CpptrajStdio.h" #include "Frame.h" +#include // sqrt /** CONSTRUCTOR */ CoordCovarMatrix::CoordCovarMatrix() : @@ -41,7 +43,7 @@ int CoordCovarMatrix::SetupMatrix(std::vector const& atoms, return 0; } -/** Add given Frame to the matrix. */ +/** Add selected atoms in given Frame to the matrix. */ void CoordCovarMatrix::AddFrameToMatrix(Frame const& frameIn, AtomMask const& maskIn) { // Covariance @@ -51,6 +53,7 @@ void CoordCovarMatrix::AddFrameToMatrix(Frame const& frameIn, AtomMask const& ma Vec3 XYZi( frameIn.XYZ(at1) ); // Store veci and veci^2 vect_[idx1] += XYZi; + XYZi.Print("XYZi"); //vect2[idx1] += XYZi.Squared(); // Loop over X, Y, and Z of veci for (int iidx = 0; iidx < 3; iidx++) { @@ -71,6 +74,35 @@ void CoordCovarMatrix::AddFrameToMatrix(Frame const& frameIn, AtomMask const& ma nframes_++; } +/** Add given Frame to the matrix. */ +void CoordCovarMatrix::AddFrameToMatrix(Frame const& frameIn) +{ + // Covariance + MatType::iterator mat = covarMatrix_.begin(); + for (int idx1 = 0; idx1 < frameIn.Natom(); idx1++) { + Vec3 XYZi( frameIn.XYZ(idx1) ); + // Store veci and veci^2 + vect_[idx1] += XYZi; + XYZi.Print("XYZi"); + //vect2[idx1] += XYZi.Squared(); + // Loop over X, Y, and Z of veci + for (int iidx = 0; iidx < 3; iidx++) { + double Vi = XYZi[iidx]; + // Diagonal + for (int jidx = iidx; jidx < 3; jidx++) + *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} + // Inner loop + for (int idx2 = idx1 + 1; idx2 < frameIn.Natom(); idx2++) { + Vec3 XYZj( frameIn.XYZ(idx2) ); + *(mat++) += Vi * XYZj[0]; + *(mat++) += Vi * XYZj[1]; + *(mat++) += Vi * XYZj[2]; + } // END inner loop over idx2 + } // END loop over x y z of veci + } // END outer loop over idx1 + nframes_++; +} + /** Finish the matrix. */ int CoordCovarMatrix::FinishMatrix() { if (nframes_ < 1) { @@ -117,14 +149,14 @@ int CoordCovarMatrix::FinishMatrix() { return 0; } -/** Debug print to STDOUT */ -void CoordCovarMatrix::DebugPrint(const char* desc) const { +/** Debug print to file */ +void CoordCovarMatrix::DebugPrint(const char* desc, CpptrajFile& outfile) const { if (desc != 0) - mprintf("DEBUG: CoordCovarMatrix: %s\n", desc); + outfile.Printf("DEBUG: CoordCovarMatrix: %s\n", desc); for (unsigned int row = 0; row < covarMatrix_.Nrows(); row++) { for (unsigned int col = 0; col < covarMatrix_.Ncols(); col++) { - mprintf(" %6.3f", covarMatrix_.element(col, row)); + outfile.Printf(" %6.3f", covarMatrix_.element(col, row)); } - mprintf("\n"); + outfile.Printf("\n"); } } diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 2ae57a349f..1e00b0d556 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -5,6 +5,7 @@ #include class Atom; class AtomMask; +class CpptrajFile; class Frame; /// Coordinate covariance matrix class CoordCovarMatrix { @@ -15,13 +16,15 @@ class CoordCovarMatrix { void Clear(); /// Set up the covariance matrix for selected atoms int SetupMatrix(std::vector const&, AtomMask const&, bool); - /// Add Frame to matrix + /// Add selected atoms in Frame to matrix void AddFrameToMatrix(Frame const&, AtomMask const&); + /// Add Frame to matrix + void AddFrameToMatrix(Frame const&); /// Finish calculating the matrix (normalize, calc - ) int FinishMatrix(); /// Print matrix elements to STDOUT for debug - void DebugPrint(const char*) const; + void DebugPrint(const char*, CpptrajFile&) const; private: typedef Matrix MatType; typedef std::vector Darray; diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 3c9173d3cf..db8fbd4a02 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -131,7 +131,7 @@ Analysis_Spline.o : Analysis_Spline.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.o : Analysis_State.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Statistics.o : Analysis_Statistics.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Statistics.h ArgList.h Array1D.h AssociatedData.h AssociatedData_NOE.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 DataSet_float.h DataSet_integer.h DataSet_string.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 Analysis_TI.o : Analysis_TI.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TI.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 DataSet_Mesh.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 Segment.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h ArrayIterator.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.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 +Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Timecorr.o : Analysis_Timecorr.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Timecorr.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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 PubFFT.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 Analysis_VectorMath.o : Analysis_VectorMath.cpp ActionState.h Analysis.h AnalysisState.h Analysis_VectorMath.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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_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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Wavelet.o : Analysis_Wavelet.cpp ActionFrameCounter.h ActionState.h Analysis.h AnalysisState.h Analysis_Wavelet.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterMap.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixFlt.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ProgressBar.h ProgressTimer.h PubFFT.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h @@ -191,7 +191,7 @@ CompactFrameArray.o : CompactFrameArray.cpp Box.h CompactFrameArray.h Coordinate ComplexArray.o : ComplexArray.cpp ArrayIterator.h ComplexArray.h Constraints.o : Constraints.cpp ArgList.h Atom.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 Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.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 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_inData.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h -CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordinateInfo.h CpptrajStdio.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h +CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h CoordinateInfo.o : CoordinateInfo.cpp Box.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h Corr.o : Corr.cpp ArrayIterator.h ComplexArray.h Corr.h PubFFT.h Cph.o : Cph.cpp Cph.h NameType.h diff --git a/test/Test_TICA/RunTest.sh b/test/Test_TICA/RunTest.sh index f6b16f9227..d3cfbfc9e1 100755 --- a/test/Test_TICA/RunTest.sh +++ b/test/Test_TICA/RunTest.sh @@ -2,7 +2,7 @@ . ../MasterTest.sh -CleanFiles tica.in +CleanFiles tica.in ticadebug.dat INPUT='-i tica.in' @@ -14,7 +14,7 @@ set MASK = :1-3@CA crdaction TZ2 matrix name M1 mwcovar out M1.dat \$MASK -runanalysis tica crdset TZ2 mask \$MASK lag 1 mass +runanalysis tica crdset TZ2 mask \$MASK lag 1 mass debugfile ticadebug.dat list dataset EOF From 4bba295f7db479a5bfcc84339524056f292370a5 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 22 Mar 2024 11:50:53 -0400 Subject: [PATCH 006/200] Put mass arg in a variable --- test/Test_TICA/RunTest.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Test_TICA/RunTest.sh b/test/Test_TICA/RunTest.sh index d3cfbfc9e1..6b9b323ea3 100755 --- a/test/Test_TICA/RunTest.sh +++ b/test/Test_TICA/RunTest.sh @@ -6,15 +6,16 @@ CleanFiles tica.in ticadebug.dat INPUT='-i tica.in' +MASS=mass cat > tica.in < Date: Fri, 22 Mar 2024 11:51:15 -0400 Subject: [PATCH 007/200] Slightly more complex test --- test/Test_TICA/RunTest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Test_TICA/RunTest.sh b/test/Test_TICA/RunTest.sh index 6b9b323ea3..8ff57755cd 100755 --- a/test/Test_TICA/RunTest.sh +++ b/test/Test_TICA/RunTest.sh @@ -11,7 +11,7 @@ cat > tica.in < Date: Fri, 22 Mar 2024 13:00:01 -0400 Subject: [PATCH 008/200] Remove old code --- src/Analysis_TICA.cpp | 70 ++----------------------------------------- 1 file changed, 2 insertions(+), 68 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 02020c2c41..1ca81b2252 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -89,28 +89,6 @@ Analysis::RetType Analysis_TICA::Analyze() { TgtTraj_->GetFrame(frm0, coords0, mask1_); // Covariance covarMatrix.AddFrameToMatrix( coords0 ); -/* - Matrix::iterator mat = covarMatrix.begin(); - for (int idx1 = 0; idx1 < mask1_.Nselected(); idx1++) { - Vec3 XYZi( coords0.XYZ(idx1) ); - // Store veci and veci^2 - vect[idx1] += XYZi; - //vect2[idx1] += XYZi.Squared(); - // Loop over X, Y, and Z of veci - for (int iidx = 0; iidx < 3; iidx++) { - double Vi = XYZi[iidx]; - // Diagonal - for (int jidx = iidx; jidx < 3; jidx++) - *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} - // Inner loop - for (int idx2 = idx1 + 1; idx2 < mask1_.Nselected(); idx2++) { - Vec3 XYZj( coords0.XYZ(idx2) ); - *(mat++) += Vi * XYZj[0]; - *(mat++) += Vi * XYZj[1]; - *(mat++) += Vi * XYZj[2]; - } // END inner loop over idx2 - } // END loop over x y z of veci - } // END outer loop over idx1*/ } // END loop over frames // Normalize @@ -118,53 +96,9 @@ Analysis::RetType Analysis_TICA::Analyze() { mprinterr("Error: Could not normalize coordinate covariance matrix for C0.\n"); return Analysis::ERR; } -/* - double norm = 1.0 / (double)TgtTraj_->Size(); - for (Varray::iterator it = vect.begin(); it != vect.end(); ++it) - *it *= norm; - for (Matrix::iterator it = covarMatrix.begin(); it != covarMatrix.end(); ++it) - *it *= norm; - // Calc - - //for (int k = 0; k < mask1_.Nselected(); k++) { - // vect2[k][0] -= (vect[k][0] * vect[k][0]); - // vect2[k][1] -= (vect[k][1] * vect[k][1]); - // vect2[k][2] -= (vect[k][2] * vect[k][2]); - //} - // Calc - - double Mass = 1.0; - double mass1 = 1.0; - Matrix::iterator mat = covarMatrix.begin(); - for (int idx1 = 0; idx1 < mask1_.Nselected(); idx1++) { - if (useMass_) - mass1 = coords0.Mass(idx1); - for (int iidx = 0; iidx < 3; iidx++) { - double Vi = vect[idx1][iidx]; - for (int idx2 = idx1; idx2 < mask1_.Nselected(); idx2++) { - if (useMass_) - Mass = sqrt( mass1 * coords0.Mass(idx2) ); - if (idx1 == idx2) { - // Self - for (int jidx = iidx; jidx < 3; jidx++) { - *mat = (*mat - (Vi * vect[idx2][jidx])) * Mass; - ++mat; - } - } else { - for (int jidx = 0; jidx < 3; jidx++) { - *mat = (*mat - (Vi * vect[idx2][jidx])) * Mass; - ++mat; - } - } - } // END inner loop over idx2 - } // END loop over elements of vect[idx1] - } // END outer loop over idx1*/ + // DEBUG PRINT covarMatrix.DebugPrint("C0", *debugFile_); -/* - for (int row = 0; row < mask1_.Nselected()*3; row++) { - for (int col = 0; col < mask1_.Nselected()*3; col++) { - mprintf(" %6.3f", covarMatrix.element(col, row)); - } - mprintf("\n"); - }*/ + return Analysis::OK; } From 17c1c44d3bca2e53298694aae19ebebef85bbf70 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 22 Mar 2024 14:39:34 -0400 Subject: [PATCH 009/200] Use mask form --- src/Analysis_TICA.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 1ca81b2252..83fa7a46ca 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -77,18 +77,19 @@ Analysis::RetType Analysis_TICA::Analyze() { return Analysis::ERR; } // Allocate frames - Frame coords0; - coords0.SetupFrameFromMask( mask1_, TgtTraj_->Top().Atoms(), TgtTraj_->CoordsInfo() ); - Frame coords1 = coords0; + Frame coords0 = TgtTraj_->AllocateFrame(); + //coords0.SetupFrameFromMask( mask1_, TgtTraj_->Top().Atoms(), TgtTraj_->CoordsInfo() ); + //Frame coords1 = coords0; // Matrix - half CoordCovarMatrix covarMatrix; covarMatrix.SetupMatrix(TgtTraj_->Top().Atoms(), mask1_, useMass_ ); // Loop over frames for (unsigned int frm0 = 0; frm0 < Nframes; frm0++) { mprintf("DEBUG: Frame %i\n", frm0); - TgtTraj_->GetFrame(frm0, coords0, mask1_); + //TgtTraj_->GetFrame(frm0, coords0, mask1_); + TgtTraj_->GetFrame(frm0, coords0); // Covariance - covarMatrix.AddFrameToMatrix( coords0 ); + covarMatrix.AddFrameToMatrix( coords0, mask1_ ); } // END loop over frames // Normalize From 3d49ea91fd11917dc0219436d2acf4de3518bda8 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 22 Mar 2024 15:03:25 -0400 Subject: [PATCH 010/200] Turn into ABC in anticipation of adding full matrix --- src/CoordCovarMatrix.cpp | 114 ++---------------------------- src/CoordCovarMatrix.h | 26 ++++--- src/CoordCovarMatrix_Half.cpp | 127 ++++++++++++++++++++++++++++++++++ src/CoordCovarMatrix_Half.h | 25 +++++++ 4 files changed, 171 insertions(+), 121 deletions(-) create mode 100644 src/CoordCovarMatrix_Half.cpp create mode 100644 src/CoordCovarMatrix_Half.h diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index 41d3aebcdb..903dc5c036 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -3,8 +3,6 @@ #include "AtomMask.h" #include "CpptrajFile.h" #include "CpptrajStdio.h" -#include "Frame.h" -#include // sqrt /** CONSTRUCTOR */ CoordCovarMatrix::CoordCovarMatrix() : @@ -18,9 +16,10 @@ void CoordCovarMatrix::Clear() { vect_.clear(); mass_.clear(); nframes_ = 0; + clearMat(); } -/** Set up array sizess and masses. */ +/** Set up array sizes and masses. */ int CoordCovarMatrix::SetupMatrix(std::vector const& atoms, AtomMask const& maskIn, bool useMassIn) { @@ -40,113 +39,8 @@ int CoordCovarMatrix::SetupMatrix(std::vector const& atoms, for (int idx = 0; idx < maskIn.Nselected(); idx++) mass_.push_back( 1.0 ); } - return 0; -} - -/** Add selected atoms in given Frame to the matrix. */ -void CoordCovarMatrix::AddFrameToMatrix(Frame const& frameIn, AtomMask const& maskIn) -{ - // Covariance - MatType::iterator mat = covarMatrix_.begin(); - for (int idx1 = 0; idx1 < maskIn.Nselected(); idx1++) { - int at1 = maskIn[idx1]; - Vec3 XYZi( frameIn.XYZ(at1) ); - // Store veci and veci^2 - vect_[idx1] += XYZi; - XYZi.Print("XYZi"); - //vect2[idx1] += XYZi.Squared(); - // Loop over X, Y, and Z of veci - for (int iidx = 0; iidx < 3; iidx++) { - double Vi = XYZi[iidx]; - // Diagonal - for (int jidx = iidx; jidx < 3; jidx++) - *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} - // Inner loop - for (int idx2 = idx1 + 1; idx2 < maskIn.Nselected(); idx2++) { - int at2 = maskIn[idx2]; - Vec3 XYZj( frameIn.XYZ(at2) ); - *(mat++) += Vi * XYZj[0]; - *(mat++) += Vi * XYZj[1]; - *(mat++) += Vi * XYZj[2]; - } // END inner loop over idx2 - } // END loop over x y z of veci - } // END outer loop over idx1 - nframes_++; -} - -/** Add given Frame to the matrix. */ -void CoordCovarMatrix::AddFrameToMatrix(Frame const& frameIn) -{ - // Covariance - MatType::iterator mat = covarMatrix_.begin(); - for (int idx1 = 0; idx1 < frameIn.Natom(); idx1++) { - Vec3 XYZi( frameIn.XYZ(idx1) ); - // Store veci and veci^2 - vect_[idx1] += XYZi; - XYZi.Print("XYZi"); - //vect2[idx1] += XYZi.Squared(); - // Loop over X, Y, and Z of veci - for (int iidx = 0; iidx < 3; iidx++) { - double Vi = XYZi[iidx]; - // Diagonal - for (int jidx = iidx; jidx < 3; jidx++) - *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} - // Inner loop - for (int idx2 = idx1 + 1; idx2 < frameIn.Natom(); idx2++) { - Vec3 XYZj( frameIn.XYZ(idx2) ); - *(mat++) += Vi * XYZj[0]; - *(mat++) += Vi * XYZj[1]; - *(mat++) += Vi * XYZj[2]; - } // END inner loop over idx2 - } // END loop over x y z of veci - } // END outer loop over idx1 - nframes_++; -} - -/** Finish the matrix. */ -int CoordCovarMatrix::FinishMatrix() { - if (nframes_ < 1) { - mprinterr("Error: No frames in coordinate covariance matrix.\n"); - return 1; - } - // Normalize - double norm = 1.0 / (double)nframes_; - for (Varray::iterator it = vect_.begin(); it != vect_.end(); ++it) - *it *= norm; - for (MatType::iterator it = covarMatrix_.begin(); it != covarMatrix_.end(); ++it) - *it *= norm; - // Calc - - //for (int k = 0; k < mask1_.Nselected(); k++) { - // vect2[k][0] -= (vect[k][0] * vect[k][0]); - // vect2[k][1] -= (vect[k][1] * vect[k][1]); - // vect2[k][2] -= (vect[k][2] * vect[k][2]); - //} - // Calc - - double Mass = 1.0; - double mass1 = 1.0; - MatType::iterator mat = covarMatrix_.begin(); - for (unsigned int idx1 = 0; idx1 < mass_.size(); idx1++) { - mass1 = mass_[idx1]; - for (int iidx = 0; iidx < 3; iidx++) { - double Vi = vect_[idx1][iidx]; - for (unsigned int idx2 = idx1; idx2 < mass_.size(); idx2++) { - Mass = sqrt( mass1 * mass_[idx2] ); - if (idx1 == idx2) { - // Self - for (int jidx = iidx; jidx < 3; jidx++) { - *mat = (*mat - (Vi * vect_[idx2][jidx])) * Mass; - ++mat; - } - } else { - for (int jidx = 0; jidx < 3; jidx++) { - *mat = (*mat - (Vi * vect_[idx2][jidx])) * Mass; - ++mat; - } - } - } // END inner loop over idx2 - } // END loop over elements of vect_[idx1] - } // END outer loop over idx1 - return 0; + + return setupMat(atoms, maskIn);; } /** Debug print to file */ diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 1e00b0d556..107b3b23a6 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -6,26 +6,30 @@ class Atom; class AtomMask; class CpptrajFile; -class Frame; -/// Coordinate covariance matrix +/// Coordinate covariance matrix abstract base class class CoordCovarMatrix { public: /// CONSTRUCTOR CoordCovarMatrix(); - /// Clear the matrix - void Clear(); + /// DESTRUCTOR - virtual since inherited + virtual ~CoordCovarMatrix() {} + // --------------------------------- + /// Finish calculating the matrix (normalize, calc - ) + virtual int FinishMatrix() = 0; + // --------------------------------- /// Set up the covariance matrix for selected atoms int SetupMatrix(std::vector const&, AtomMask const&, bool); - /// Add selected atoms in Frame to matrix - void AddFrameToMatrix(Frame const&, AtomMask const&); - /// Add Frame to matrix - void AddFrameToMatrix(Frame const&); - /// Finish calculating the matrix (normalize, calc - ) - int FinishMatrix(); + /// Clear the matrix + void Clear(); /// Print matrix elements to STDOUT for debug void DebugPrint(const char*, CpptrajFile&) const; - private: + protected: + /// clear internal variables + virtual void clearMat() = 0; + /// set internal variables + virtual int setupMat(std::vector const&, AtomMask const&) = 0; + //private: // TODO all private typedef Matrix MatType; typedef std::vector Darray; typedef std::vector Varray; diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp new file mode 100644 index 0000000000..9e5cc0462b --- /dev/null +++ b/src/CoordCovarMatrix_Half.cpp @@ -0,0 +1,127 @@ +#include "CoordCovarMatrix_Half.h" +#include "AtomMask.h" +#include "CpptrajFile.h" +#include "CpptrajStdio.h" +#include "Frame.h" +#include // sqrt + +/** CONSTRUCTOR */ +CoordCovarMatrix_Half::CoordCovarMatrix_Half() +{} + +/** Clear the matrix */ +void CoordCovarMatrix_Half::clearMat() { +} + +/** Set up array sizess and masses. */ +int CoordCovarMatrix_Half::setupMat(std::vector const& atoms, + AtomMask const& maskIn) +{ + return 0; +} + +/** Add selected atoms in given Frame to the matrix. */ +void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask const& maskIn) +{ + // Covariance + MatType::iterator mat = covarMatrix_.begin(); + for (int idx1 = 0; idx1 < maskIn.Nselected(); idx1++) { + int at1 = maskIn[idx1]; + Vec3 XYZi( frameIn.XYZ(at1) ); + // Store veci and veci^2 + vect_[idx1] += XYZi; + XYZi.Print("XYZi"); + //vect2[idx1] += XYZi.Squared(); + // Loop over X, Y, and Z of veci + for (int iidx = 0; iidx < 3; iidx++) { + double Vi = XYZi[iidx]; + // Diagonal + for (int jidx = iidx; jidx < 3; jidx++) + *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} + // Inner loop + for (int idx2 = idx1 + 1; idx2 < maskIn.Nselected(); idx2++) { + int at2 = maskIn[idx2]; + Vec3 XYZj( frameIn.XYZ(at2) ); + *(mat++) += Vi * XYZj[0]; + *(mat++) += Vi * XYZj[1]; + *(mat++) += Vi * XYZj[2]; + } // END inner loop over idx2 + } // END loop over x y z of veci + } // END outer loop over idx1 + nframes_++; +} + +/** Add given Frame to the matrix. */ +void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn) +{ + // Covariance + MatType::iterator mat = covarMatrix_.begin(); + for (int idx1 = 0; idx1 < frameIn.Natom(); idx1++) { + Vec3 XYZi( frameIn.XYZ(idx1) ); + // Store veci and veci^2 + vect_[idx1] += XYZi; + XYZi.Print("XYZi"); + //vect2[idx1] += XYZi.Squared(); + // Loop over X, Y, and Z of veci + for (int iidx = 0; iidx < 3; iidx++) { + double Vi = XYZi[iidx]; + // Diagonal + for (int jidx = iidx; jidx < 3; jidx++) + *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} + // Inner loop + for (int idx2 = idx1 + 1; idx2 < frameIn.Natom(); idx2++) { + Vec3 XYZj( frameIn.XYZ(idx2) ); + *(mat++) += Vi * XYZj[0]; + *(mat++) += Vi * XYZj[1]; + *(mat++) += Vi * XYZj[2]; + } // END inner loop over idx2 + } // END loop over x y z of veci + } // END outer loop over idx1 + nframes_++; +} + +/** Finish the matrix. */ +int CoordCovarMatrix_Half::FinishMatrix() { + if (nframes_ < 1) { + mprinterr("Error: No frames in coordinate covariance matrix.\n"); + return 1; + } + // Normalize + double norm = 1.0 / (double)nframes_; + for (Varray::iterator it = vect_.begin(); it != vect_.end(); ++it) + *it *= norm; + for (MatType::iterator it = covarMatrix_.begin(); it != covarMatrix_.end(); ++it) + *it *= norm; + // Calc - + //for (int k = 0; k < mask1_.Nselected(); k++) { + // vect2[k][0] -= (vect[k][0] * vect[k][0]); + // vect2[k][1] -= (vect[k][1] * vect[k][1]); + // vect2[k][2] -= (vect[k][2] * vect[k][2]); + //} + // Calc - + double Mass = 1.0; + double mass1 = 1.0; + MatType::iterator mat = covarMatrix_.begin(); + for (unsigned int idx1 = 0; idx1 < mass_.size(); idx1++) { + mass1 = mass_[idx1]; + for (int iidx = 0; iidx < 3; iidx++) { + double Vi = vect_[idx1][iidx]; + for (unsigned int idx2 = idx1; idx2 < mass_.size(); idx2++) { + Mass = sqrt( mass1 * mass_[idx2] ); + if (idx1 == idx2) { + // Self + for (int jidx = iidx; jidx < 3; jidx++) { + *mat = (*mat - (Vi * vect_[idx2][jidx])) * Mass; + ++mat; + } + } else { + for (int jidx = 0; jidx < 3; jidx++) { + *mat = (*mat - (Vi * vect_[idx2][jidx])) * Mass; + ++mat; + } + } + } // END inner loop over idx2 + } // END loop over elements of vect_[idx1] + } // END outer loop over idx1 + return 0; +} diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h new file mode 100644 index 0000000000..b014b21aed --- /dev/null +++ b/src/CoordCovarMatrix_Half.h @@ -0,0 +1,25 @@ +#ifndef INC_COORDCOVARMATRIX_HALF_H +#define INC_COORDCOVARMATRIX_HALF_H +#include "CoordCovarMatrix.h" +class Frame; +/// Coordinate covariance half (self) matrix +class CoordCovarMatrix_Half : public CoordCovarMatrix { + public: + /// CONSTRUCTOR + CoordCovarMatrix_Half(); + // --------------------------------- + /// Finish calculating the matrix (normalize, calc - ) + int FinishMatrix(); + // --------------------------------- + /// Add selected atoms in Frame to matrix + void AddFrameToMatrix(Frame const&, AtomMask const&); + /// Add Frame to matrix + void AddFrameToMatrix(Frame const&); + private: + /// Clear the matrix + void clearMat(); + /// Set up the covariance matrix for selected atoms + int setupMat(std::vector const&, AtomMask const&); + +}; +#endif From ecdd8290cf84888c5a53b718e52080f399aaba60 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 22 Mar 2024 15:17:47 -0400 Subject: [PATCH 011/200] Slight reorganization --- src/Analysis_TICA.cpp | 4 ++-- src/CoordCovarMatrix.cpp | 8 +++----- src/CoordCovarMatrix.h | 6 +++--- src/CoordCovarMatrix_Half.cpp | 9 ++++++--- src/CoordCovarMatrix_Half.h | 4 ++-- src/cpptrajdepend | 5 +++-- src/cpptrajfiles | 1 + 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 83fa7a46ca..7bfaca8ca8 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -1,5 +1,5 @@ #include "Analysis_TICA.h" -#include "CoordCovarMatrix.h" +#include "CoordCovarMatrix_Half.h" #include "CpptrajStdio.h" /** CONSTRUCTOR */ @@ -81,7 +81,7 @@ Analysis::RetType Analysis_TICA::Analyze() { //coords0.SetupFrameFromMask( mask1_, TgtTraj_->Top().Atoms(), TgtTraj_->CoordsInfo() ); //Frame coords1 = coords0; // Matrix - half - CoordCovarMatrix covarMatrix; + CoordCovarMatrix_Half covarMatrix; covarMatrix.SetupMatrix(TgtTraj_->Top().Atoms(), mask1_, useMass_ ); // Loop over frames for (unsigned int frm0 = 0; frm0 < Nframes; frm0++) { diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index 903dc5c036..e71fadcf43 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -20,16 +20,14 @@ void CoordCovarMatrix::Clear() { } /** Set up array sizes and masses. */ -int CoordCovarMatrix::SetupMatrix(std::vector const& atoms, - AtomMask const& maskIn, bool useMassIn) +int CoordCovarMatrix::setupMat(std::vector const& atoms, + AtomMask const& maskIn, bool useMassIn) { useMass_ = useMassIn; // TODO more size error checking nframes_ = 0; vect_.assign(maskIn.Nselected(), Vec3(0.0)); //Varray vect2(mask1_.Nselected(), Vec3(0.0)); - // Matrix - half - covarMatrix_.resize( maskIn.Nselected()*3, 0 ); // Masses mass_.clear(); if (useMassIn) { @@ -40,7 +38,7 @@ int CoordCovarMatrix::SetupMatrix(std::vector const& atoms, mass_.push_back( 1.0 ); } - return setupMat(atoms, maskIn);; + return 0; } /** Debug print to file */ diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 107b3b23a6..683ad911db 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -17,8 +17,6 @@ class CoordCovarMatrix { /// Finish calculating the matrix (normalize, calc - ) virtual int FinishMatrix() = 0; // --------------------------------- - /// Set up the covariance matrix for selected atoms - int SetupMatrix(std::vector const&, AtomMask const&, bool); /// Clear the matrix void Clear(); @@ -27,8 +25,10 @@ class CoordCovarMatrix { protected: /// clear internal variables virtual void clearMat() = 0; + /// set internal variables - virtual int setupMat(std::vector const&, AtomMask const&) = 0; + int setupMat(std::vector const&, AtomMask const&, bool); + //private: // TODO all private typedef Matrix MatType; typedef std::vector Darray; diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 9e5cc0462b..e427e5a6ae 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -14,10 +14,13 @@ void CoordCovarMatrix_Half::clearMat() { } /** Set up array sizess and masses. */ -int CoordCovarMatrix_Half::setupMat(std::vector const& atoms, - AtomMask const& maskIn) +int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, + AtomMask const& maskIn, bool useMassIn) { - return 0; + // Matrix - half + covarMatrix_.resize( maskIn.Nselected()*3, 0 ); + + return setupMat(atoms, maskIn, useMassIn); } /** Add selected atoms in given Frame to the matrix. */ diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index b014b21aed..fe44e0b71a 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -11,6 +11,8 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { /// Finish calculating the matrix (normalize, calc - ) int FinishMatrix(); // --------------------------------- + /// Set up half matrix + int SetupMatrix(std::vector const&, AtomMask const&, bool); /// Add selected atoms in Frame to matrix void AddFrameToMatrix(Frame const&, AtomMask const&); /// Add Frame to matrix @@ -18,8 +20,6 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { private: /// Clear the matrix void clearMat(); - /// Set up the covariance matrix for selected atoms - int setupMat(std::vector const&, AtomMask const&); }; #endif diff --git a/src/cpptrajdepend b/src/cpptrajdepend index db8fbd4a02..6b80109573 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -131,7 +131,7 @@ Analysis_Spline.o : Analysis_Spline.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.o : Analysis_State.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Statistics.o : Analysis_Statistics.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Statistics.h ArgList.h Array1D.h AssociatedData.h AssociatedData_NOE.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 DataSet_float.h DataSet_integer.h DataSet_string.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 Analysis_TI.o : Analysis_TI.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TI.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 DataSet_Mesh.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 Segment.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Half.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Timecorr.o : Analysis_Timecorr.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Timecorr.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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 PubFFT.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 Analysis_VectorMath.o : Analysis_VectorMath.cpp ActionState.h Analysis.h AnalysisState.h Analysis_VectorMath.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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_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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Wavelet.o : Analysis_Wavelet.cpp ActionFrameCounter.h ActionState.h Analysis.h AnalysisState.h Analysis_Wavelet.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterMap.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixFlt.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ProgressBar.h ProgressTimer.h PubFFT.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h @@ -191,7 +191,8 @@ CompactFrameArray.o : CompactFrameArray.cpp Box.h CompactFrameArray.h Coordinate ComplexArray.o : ComplexArray.cpp ArrayIterator.h ComplexArray.h Constraints.o : Constraints.cpp ArgList.h Atom.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 Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.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 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_inData.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h -CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h +CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h MaskToken.h Matrix.h Molecule.h NameType.h Parallel.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h +CoordCovarMatrix_Half.o : CoordCovarMatrix_Half.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordCovarMatrix_Half.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h CoordinateInfo.o : CoordinateInfo.cpp Box.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h Corr.o : Corr.cpp ArrayIterator.h ComplexArray.h Corr.h PubFFT.h Cph.o : Cph.cpp Cph.h NameType.h diff --git a/src/cpptrajfiles b/src/cpptrajfiles index 0002bc43c6..ff5ca9817f 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -164,6 +164,7 @@ COMMON_SOURCES= \ Constraints.cpp \ ControlBlock_For.cpp \ CoordCovarMatrix.cpp \ + CoordCovarMatrix_Half.cpp \ CoordinateInfo.cpp \ Corr.cpp \ Cph.cpp \ From 261fabe101c33726a0255c99d8d86d3a5fdef1c1 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 26 Mar 2024 15:01:42 -0400 Subject: [PATCH 012/200] Another reorganization since full covar array needs separate vect/vect2/mass arrays for each mask --- src/CoordCovarMatrix.cpp | 23 ++++++++--------------- src/CoordCovarMatrix.h | 13 ++++++------- src/CoordCovarMatrix_Half.cpp | 8 +++++++- src/CoordCovarMatrix_Half.h | 3 +++ 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index e71fadcf43..acbc744014 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -13,32 +13,25 @@ CoordCovarMatrix::CoordCovarMatrix() : /** Clear the matrix */ void CoordCovarMatrix::Clear() { covarMatrix_.clear(); - vect_.clear(); - mass_.clear(); nframes_ = 0; clearMat(); } -/** Set up array sizes and masses. */ -int CoordCovarMatrix::setupMat(std::vector const& atoms, - AtomMask const& maskIn, bool useMassIn) +/** Setup mass array */ +void CoordCovarMatrix::set_mass_array(Darray& mass, std::vector const& atoms, + AtomMask const& maskIn, bool useMassIn) { - useMass_ = useMassIn; - // TODO more size error checking nframes_ = 0; - vect_.assign(maskIn.Nselected(), Vec3(0.0)); - //Varray vect2(mask1_.Nselected(), Vec3(0.0)); - // Masses - mass_.clear(); + useMass_ = useMassIn; + mass.clear(); + mass.reserve( maskIn.Nselected() ); if (useMassIn) { for (AtomMask::const_iterator at = maskIn.begin(); at != maskIn.end(); ++at) - mass_.push_back( atoms[*at].Mass() ); + mass.push_back( atoms[*at].Mass() ); } else { for (int idx = 0; idx < maskIn.Nselected(); idx++) - mass_.push_back( 1.0 ); + mass.push_back( 1.0 ); } - - return 0; } /** Debug print to file */ diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 683ad911db..bcaa1a8086 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -23,20 +23,19 @@ class CoordCovarMatrix { /// Print matrix elements to STDOUT for debug void DebugPrint(const char*, CpptrajFile&) const; protected: + typedef Matrix MatType; + typedef std::vector Darray; + typedef std::vector Varray; + /// clear internal variables virtual void clearMat() = 0; - /// set internal variables - int setupMat(std::vector const&, AtomMask const&, bool); + /// set mass array + void set_mass_array(Darray&, std::vector const&, AtomMask const&, bool); //private: // TODO all private - typedef Matrix MatType; - typedef std::vector Darray; - typedef std::vector Varray; MatType covarMatrix_; ///< Coordinate covariance matrix - Varray vect_; ///< Store average coordinates along the diagonal - Darray mass_; ///< Store selected atoms masses unsigned int nframes_; ///< Number of frames added to the matrix bool useMass_; ///< If true use mass weighting }; diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index e427e5a6ae..88d7c07117 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -11,6 +11,8 @@ CoordCovarMatrix_Half::CoordCovarMatrix_Half() /** Clear the matrix */ void CoordCovarMatrix_Half::clearMat() { + vect_.clear(); + mass_.clear(); } /** Set up array sizess and masses. */ @@ -20,7 +22,11 @@ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, // Matrix - half covarMatrix_.resize( maskIn.Nselected()*3, 0 ); - return setupMat(atoms, maskIn, useMassIn); + vect_.assign(maskIn.Nselected(), Vec3(0.0)); + + set_mass_array(mass_, atoms, maskIn, useMassIn); + + return 0; } /** Add selected atoms in given Frame to the matrix. */ diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index fe44e0b71a..1c8897812e 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -21,5 +21,8 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { /// Clear the matrix void clearMat(); + Varray vect_; + Darray mass_; + }; #endif From 1d1c7668d555e299c38222606a2d4b04bd933695 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 27 Mar 2024 09:21:54 -0400 Subject: [PATCH 013/200] Add full covar matrix class --- src/CoordCovarMatrix_Full.cpp | 136 ++++++++++++++++++++++++++++++++++ src/CoordCovarMatrix_Full.h | 30 ++++++++ 2 files changed, 166 insertions(+) create mode 100644 src/CoordCovarMatrix_Full.cpp create mode 100644 src/CoordCovarMatrix_Full.h diff --git a/src/CoordCovarMatrix_Full.cpp b/src/CoordCovarMatrix_Full.cpp new file mode 100644 index 0000000000..185e367f46 --- /dev/null +++ b/src/CoordCovarMatrix_Full.cpp @@ -0,0 +1,136 @@ +#include "CoordCovarMatrix_Full.h" +#include "AtomMask.h" +#include "CpptrajStdio.h" +#include "Frame.h" + +/** CONSTRUCTOR */ +CoordCovarMatrix_Full::CoordCovarMatrix_Full() +{} + +/** Clear the matrix */ +void CoordCovarMatrix_Full::clearMat() { + vect2_1_.clear(); + vect2_2_.clear(); + vect_1_.clear(); + vect_2_.clear(); + mass1_.clear(); + mass2_.clear(); +} + +/** Set up array sizess and masses. */ +int CoordCovarMatrix_Full::SetupMatrix(std::vector const& atoms1, + AtomMask const& maskIn1, + std::vector const& atoms2, + AtomMask const& maskIn2, bool useMassIn) +{ + // Matrix - full + covarMatrix_.resize( maskIn1.Nselected()*3, maskIn2.Nselected()*3 ); + + vect_1_.assign(maskIn1.Nselected(), Vec3(0.0)); + vect2_1_.assign(maskIn1.Nselected(), Vec3(0.0)); + vect_2_.assign(maskIn2.Nselected(), Vec3(0.0)); + vect2_2_.assign(maskIn2.Nselected(), Vec3(0.0)); + set_mass_array( mass1_, atoms1, maskIn1, useMassIn ); + set_mass_array( mass2_, atoms2, maskIn2, useMassIn ); + + return 0; +} + +/** Store diagonal (average and average^2) */ +static inline void store_diagonal(std::vector& vect, + std::vector& vect2, + Frame const& frameIn, + AtomMask const& maskIn) +{ + for (int idx = 0; idx < maskIn.Nselected(); idx++) + { + const double* XYZ = frameIn.XYZ( maskIn[idx] ); + for (int ii = 0; ii < 3; ii++) { + vect[ii] += XYZ[ii]; + vect2[ii] += (XYZ[ii] * XYZ[ii]); + } + } +} + +/** Add selected atoms in given Frames to the matrix. */ +void CoordCovarMatrix_Full::AddFrameToMatrix(Frame const& frameIn1, AtomMask const& maskIn1, + Frame const& frameIn2, AtomMask const& maskIn2) +{ + //MatType::iterator mat = covarMatrix_.begin(); + for (int idx2 = 0; idx2 < maskIn2.Nselected(); idx2++) + { + Matrix::iterator mat = covarMatrix_.begin() + ((idx2*3)*covarMatrix_.Ncols()); // NX + const double* XYZj = frameIn2.XYZ( maskIn2[idx2] ); + for (int ny = 0; ny < 3; ny++) { + double Vj = XYZj[ny]; + for (int idx1 = 0; idx1 < maskIn1.Nselected(); idx1++) + { + const double* XYZi = frameIn1.XYZ( maskIn1[idx1] ); + *(mat++) += Vj * XYZi[0]; + *(mat++) += Vj * XYZi[1]; + *(mat++) += Vj * XYZi[2]; + } + } + } + // Mask1/mask2 diagonal + store_diagonal(vect_1_, vect2_1_, frameIn1, maskIn1); + store_diagonal(vect_2_, vect2_2_, frameIn2, maskIn2); + nframes_++; +} + +/** Calculate - */ +static inline void vect2_minus_vect(std::vector& vect2, std::vector const& vect) +{ + // Sanity check + if (vect2.size() != vect.size()) { + mprinterr("Internal Error: CoordCovarMatrix_Full: Vect2 size (%zu) != Vect size (%zu)\n", + vect2.size(), vect.size()); + return; + } + for (unsigned int idx = 0; idx != vect2.size(); idx++) { + Vec3& V2 = vect2[idx]; + Vec3 const& V1 = vect[idx]; + for (int ny = 0; ny < 3; ny++) + V2[ny] -= (V1[ny] * V1[ny]); + } +} + +/** Finish processing covariance matrix */ +int CoordCovarMatrix_Full::FinishMatrix() { + if (nframes_ < 1) { + mprinterr("Error: No frames in coordinate covariance matrix.\n"); + return 1; + } + // Normalize + double norm = 1.0 / (double)nframes_; + for (Varray::iterator it = vect_1_.begin(); it != vect_1_.end(); ++it) + *it *= norm; + for (Varray::iterator it = vect_2_.begin(); it != vect_2_.end(); ++it) + *it *= norm; + for (Varray::iterator it = vect2_1_.begin(); it != vect2_1_.end(); ++it) + *it *= norm; + for (Varray::iterator it = vect2_2_.begin(); it != vect2_2_.end(); ++it) + *it *= norm; + for (MatType::iterator it = covarMatrix_.begin(); it != covarMatrix_.end(); ++it) + *it *= norm; + // Calc - + vect2_minus_vect(vect2_1_, vect_1_); + vect2_minus_vect(vect2_2_, vect_2_); + // Calc - + Matrix::iterator mat = covarMatrix_.begin(); + for (unsigned int idx2 = 0; idx2 < vect_2_.size(); idx2++) + { + double mass2 = mass2_[idx2]; + Vec3 const& V2 = vect_2_[idx2]; + for (int ny = 0; ny < 3; ny++) { + for (unsigned int idx1 = 0; idx1 < vect_1_.size(); idx1++) { + double Mass = sqrt(mass2 * mass1_[idx1]); + for (int nx = 0; nx < 3; nx++) { + *mat = (*mat - (V2[ny] * vect_1_[idx1][nx])) * Mass; + ++mat; + } + } // END loop over vect_1_ + } + } // END loop over vect_2_ + return 0; +} diff --git a/src/CoordCovarMatrix_Full.h b/src/CoordCovarMatrix_Full.h new file mode 100644 index 0000000000..e0dac18889 --- /dev/null +++ b/src/CoordCovarMatrix_Full.h @@ -0,0 +1,30 @@ +#ifndef INC_COORDCOVARMATRIX_FULL_H +#define INC_COORDCOVARMATRIX_FULL_H +#include "CoordCovarMatrix.h" +class Frame; +/// Coordinate covanriance full matrix +class CoordCovarMatrix_Full : public CoordCovarMatrix { + public: + CoordCovarMatrix_Full(); + /// Finish calculating the matrix (normalize, calc - ) + int FinishMatrix(); + // --------------------------------- + int SetupMatrix(std::vector const&, AtomMask const&, + std::vector const&, AtomMask const&, bool); + /// Add selected atoms in Frame to matrix + void AddFrameToMatrix(Frame const&, AtomMask const&, + Frame const&, AtomMask const&); + private: + /// Clear the matrix + void clearMat(); + /// Set up the covariance matrix for selected atoms + int setupMat(std::vector const&, AtomMask const&); + + Varray vect_1_; + Varray vect_2_; + Varray vect2_1_; ///< Array of average diagonal elements squared + Varray vect2_2_; + Darray mass1_; + Darray mass2_; +}; +#endif From dcb943d0787afb5ad0f12f2c8b9e7ecd65ae189d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 27 Mar 2024 10:11:24 -0400 Subject: [PATCH 014/200] Fix averaging --- src/CoordCovarMatrix_Full.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/CoordCovarMatrix_Full.cpp b/src/CoordCovarMatrix_Full.cpp index 185e367f46..cb770f07bf 100644 --- a/src/CoordCovarMatrix_Full.cpp +++ b/src/CoordCovarMatrix_Full.cpp @@ -46,8 +46,8 @@ static inline void store_diagonal(std::vector& vect, { const double* XYZ = frameIn.XYZ( maskIn[idx] ); for (int ii = 0; ii < 3; ii++) { - vect[ii] += XYZ[ii]; - vect2[ii] += (XYZ[ii] * XYZ[ii]); + vect[idx][ii] += XYZ[ii]; + vect2[idx][ii] += (XYZ[ii] * XYZ[ii]); } } } @@ -113,6 +113,18 @@ int CoordCovarMatrix_Full::FinishMatrix() { *it *= norm; for (MatType::iterator it = covarMatrix_.begin(); it != covarMatrix_.end(); ++it) *it *= norm; + mprintf("DEBUG: First 3 elements: %f %f %f\n", + covarMatrix_.element(0, 0), + covarMatrix_.element(1, 0), + covarMatrix_.element(2, 0)); + mprintf("DEBUG: First 3 elements of V1: %f %f %f\n", + vect_1_[0][0], + vect_1_[0][1], + vect_1_[0][2]); + mprintf("DEBUG: First 3 elements of V2: %f %f %f\n", + vect_2_[0][0], + vect_2_[0][1], + vect_2_[0][2]); // Calc - vect2_minus_vect(vect2_1_, vect_1_); vect2_minus_vect(vect2_2_, vect_2_); @@ -126,6 +138,7 @@ int CoordCovarMatrix_Full::FinishMatrix() { for (unsigned int idx1 = 0; idx1 < vect_1_.size(); idx1++) { double Mass = sqrt(mass2 * mass1_[idx1]); for (int nx = 0; nx < 3; nx++) { + mprintf("mat = (%f - (%f * %f)) * %f\n", *mat, V2[ny], vect_1_[idx1][nx], Mass); *mat = (*mat - (V2[ny] * vect_1_[idx1][nx])) * Mass; ++mat; } From 8c52441d5d4678960db5e48b260017a336415935 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 27 Mar 2024 10:11:51 -0400 Subject: [PATCH 015/200] Hide debug info --- src/CoordCovarMatrix_Half.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 88d7c07117..5d2a1af439 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -39,7 +39,7 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask cons Vec3 XYZi( frameIn.XYZ(at1) ); // Store veci and veci^2 vect_[idx1] += XYZi; - XYZi.Print("XYZi"); + //XYZi.Print("XYZi"); //vect2[idx1] += XYZi.Squared(); // Loop over X, Y, and Z of veci for (int iidx = 0; iidx < 3; iidx++) { @@ -69,7 +69,7 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn) Vec3 XYZi( frameIn.XYZ(idx1) ); // Store veci and veci^2 vect_[idx1] += XYZi; - XYZi.Print("XYZi"); + //XYZi.Print("XYZi"); //vect2[idx1] += XYZi.Squared(); // Loop over X, Y, and Z of veci for (int iidx = 0; iidx < 3; iidx++) { From a4b0e9be39803e03dc6d743bdf40a0a16840d000 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 27 Mar 2024 10:12:03 -0400 Subject: [PATCH 016/200] Update dependencies --- src/cpptrajdepend | 1 + src/cpptrajfiles | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 6b80109573..573e521c0e 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -192,6 +192,7 @@ ComplexArray.o : ComplexArray.cpp ArrayIterator.h ComplexArray.h Constraints.o : Constraints.cpp ArgList.h Atom.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 Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.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 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_inData.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h MaskToken.h Matrix.h Molecule.h NameType.h Parallel.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h +CoordCovarMatrix_Full.o : CoordCovarMatrix_Full.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordinateInfo.h CpptrajStdio.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h CoordCovarMatrix_Half.o : CoordCovarMatrix_Half.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordCovarMatrix_Half.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h CoordinateInfo.o : CoordinateInfo.cpp Box.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h Corr.o : Corr.cpp ArrayIterator.h ComplexArray.h Corr.h PubFFT.h diff --git a/src/cpptrajfiles b/src/cpptrajfiles index ff5ca9817f..e23ae3783c 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -164,6 +164,7 @@ COMMON_SOURCES= \ Constraints.cpp \ ControlBlock_For.cpp \ CoordCovarMatrix.cpp \ + CoordCovarMatrix_Full.cpp \ CoordCovarMatrix_Half.cpp \ CoordinateInfo.cpp \ Corr.cpp \ From 7150cbb98c5db829320a1f16e5bb8398f6ae328b Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 27 Mar 2024 10:12:20 -0400 Subject: [PATCH 017/200] Test that full covar matrix is working --- src/Analysis_TICA.cpp | 50 +++++++++++++++++++++++++++++++++++++++++-- src/Analysis_TICA.h | 1 + 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 7bfaca8ca8..93990005d5 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -1,4 +1,5 @@ #include "Analysis_TICA.h" +#include "CoordCovarMatrix_Full.h" #include "CoordCovarMatrix_Half.h" #include "CpptrajStdio.h" @@ -36,6 +37,15 @@ Analysis::RetType Analysis_TICA::Setup(ArgList& analyzeArgs, AnalysisSetup& setu mprinterr("Error: Could not set atom mask string '%s'\n", maskstr.c_str()); return Analysis::ERR; } + maskstr = analyzeArgs.GetStringKey("mask2"); + if (!maskstr.empty()) { + mprintf("DEBUG: Second mask detected.\n"); + if (mask2_.SetMaskString( maskstr )) { + mprinterr("Error: Could not set second atom mask string '%s'\n", maskstr.c_str()); + return Analysis::ERR; + } + } + useMass_ = analyzeArgs.hasKey("mass"); debugFile_ = setup.DFL().AddCpptrajFile(analyzeArgs.GetStringKey("debugfile"), "TICA debug", DataFileList::TEXT, true); @@ -76,6 +86,17 @@ Analysis::RetType Analysis_TICA::Analyze() { mprinterr("Error: No atoms selected by mask '%s'\n", mask1_.MaskString()); return Analysis::ERR; } + if (mask2_.MaskStringSet()) { + if ( TgtTraj_->Top().SetupIntegerMask( mask2_ ) ) { + mprinterr("Error: Could not evaluate second atom mask '%s'\n", mask2_.MaskString()); + return Analysis::ERR; + } + mask2_.MaskInfo(); + if (mask2_.None()) { + mprinterr("Error: No atoms selected by second mask '%s'\n", mask2_.MaskString()); + return Analysis::ERR; + } + } // Allocate frames Frame coords0 = TgtTraj_->AllocateFrame(); //coords0.SetupFrameFromMask( mask1_, TgtTraj_->Top().Atoms(), TgtTraj_->CoordsInfo() ); @@ -85,7 +106,7 @@ Analysis::RetType Analysis_TICA::Analyze() { covarMatrix.SetupMatrix(TgtTraj_->Top().Atoms(), mask1_, useMass_ ); // Loop over frames for (unsigned int frm0 = 0; frm0 < Nframes; frm0++) { - mprintf("DEBUG: Frame %i\n", frm0); + //mprintf("DEBUG: Frame %i\n", frm0); //TgtTraj_->GetFrame(frm0, coords0, mask1_); TgtTraj_->GetFrame(frm0, coords0); // Covariance @@ -99,7 +120,32 @@ Analysis::RetType Analysis_TICA::Analyze() { } // DEBUG PRINT - covarMatrix.DebugPrint("C0", *debugFile_); + //covarMatrix.DebugPrint("C0", *debugFile_); + + if (mask2_.MaskStringSet()) { + // DEBUG + // Matrix - full + CoordCovarMatrix_Full CT; + CT.SetupMatrix(TgtTraj_->Top().Atoms(), mask1_, + TgtTraj_->Top().Atoms(), mask2_, useMass_); + // Loop over frames + for (unsigned int frm0 = 0; frm0 < Nframes; frm0++) { + //mprintf("DEBUG: Frame %i\n", frm0); + //TgtTraj_->GetFrame(frm0, coords0, mask1_); + TgtTraj_->GetFrame(frm0, coords0); + // Covariance + CT.AddFrameToMatrix( coords0, mask1_, coords0, mask2_ ); + } // END loop over frames + + // Normalize + if (CT.FinishMatrix()) { + mprinterr("Error: Could not normalize coordinate covariance matrix for CT.\n"); + return Analysis::ERR; + } + + // DEBUG PRINT + CT.DebugPrint("CT", *debugFile_); + } return Analysis::OK; } diff --git a/src/Analysis_TICA.h b/src/Analysis_TICA.h index fc91115c59..fd1a3a8fc3 100644 --- a/src/Analysis_TICA.h +++ b/src/Analysis_TICA.h @@ -14,6 +14,7 @@ class Analysis_TICA : public Analysis { DataSet_Coords* TgtTraj_; ///< Input trajectory int lag_; ///< TICA time lag AtomMask mask1_; ///< Atoms to use in matrix calc + AtomMask mask2_; ///< Second atom mask for debugging full covar matrix bool useMass_; ///< Control whether to mass-weight CpptrajFile* debugFile_; ///< Debug output }; From 624fdc5b91a181fbbe64ea7acc3d97472d2b5a01 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 27 Mar 2024 10:16:32 -0400 Subject: [PATCH 018/200] Vect2 is actually already in matrix --- src/CoordCovarMatrix_Full.cpp | 34 ++++++++++++++++++---------------- src/CoordCovarMatrix_Full.h | 4 ++-- src/cpptrajdepend | 2 +- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/CoordCovarMatrix_Full.cpp b/src/CoordCovarMatrix_Full.cpp index cb770f07bf..210dfb7c5a 100644 --- a/src/CoordCovarMatrix_Full.cpp +++ b/src/CoordCovarMatrix_Full.cpp @@ -9,8 +9,8 @@ CoordCovarMatrix_Full::CoordCovarMatrix_Full() /** Clear the matrix */ void CoordCovarMatrix_Full::clearMat() { - vect2_1_.clear(); - vect2_2_.clear(); +// vect2_1_.clear(); +// vect2_2_.clear(); vect_1_.clear(); vect_2_.clear(); mass1_.clear(); @@ -27,9 +27,9 @@ int CoordCovarMatrix_Full::SetupMatrix(std::vector const& atoms1, covarMatrix_.resize( maskIn1.Nselected()*3, maskIn2.Nselected()*3 ); vect_1_.assign(maskIn1.Nselected(), Vec3(0.0)); - vect2_1_.assign(maskIn1.Nselected(), Vec3(0.0)); +// vect2_1_.assign(maskIn1.Nselected(), Vec3(0.0)); vect_2_.assign(maskIn2.Nselected(), Vec3(0.0)); - vect2_2_.assign(maskIn2.Nselected(), Vec3(0.0)); +// vect2_2_.assign(maskIn2.Nselected(), Vec3(0.0)); set_mass_array( mass1_, atoms1, maskIn1, useMassIn ); set_mass_array( mass2_, atoms2, maskIn2, useMassIn ); @@ -38,7 +38,7 @@ int CoordCovarMatrix_Full::SetupMatrix(std::vector const& atoms1, /** Store diagonal (average and average^2) */ static inline void store_diagonal(std::vector& vect, - std::vector& vect2, +// std::vector& vect2, Frame const& frameIn, AtomMask const& maskIn) { @@ -47,7 +47,7 @@ static inline void store_diagonal(std::vector& vect, const double* XYZ = frameIn.XYZ( maskIn[idx] ); for (int ii = 0; ii < 3; ii++) { vect[idx][ii] += XYZ[ii]; - vect2[idx][ii] += (XYZ[ii] * XYZ[ii]); +// vect2[idx][ii] += (XYZ[ii] * XYZ[ii]); } } } @@ -73,13 +73,15 @@ void CoordCovarMatrix_Full::AddFrameToMatrix(Frame const& frameIn1, AtomMask con } } // Mask1/mask2 diagonal - store_diagonal(vect_1_, vect2_1_, frameIn1, maskIn1); - store_diagonal(vect_2_, vect2_2_, frameIn2, maskIn2); +// store_diagonal(vect_1_, vect2_1_, frameIn1, maskIn1); +// store_diagonal(vect_2_, vect2_2_, frameIn2, maskIn2); + store_diagonal(vect_1_, frameIn1, maskIn1); + store_diagonal(vect_2_, frameIn2, maskIn2); nframes_++; } /** Calculate - */ -static inline void vect2_minus_vect(std::vector& vect2, std::vector const& vect) +/*static inline void vect2_minus_vect(std::vector& vect2, std::vector const& vect) { // Sanity check if (vect2.size() != vect.size()) { @@ -93,7 +95,7 @@ static inline void vect2_minus_vect(std::vector& vect2, std::vector for (int ny = 0; ny < 3; ny++) V2[ny] -= (V1[ny] * V1[ny]); } -} +}*/ /** Finish processing covariance matrix */ int CoordCovarMatrix_Full::FinishMatrix() { @@ -107,10 +109,10 @@ int CoordCovarMatrix_Full::FinishMatrix() { *it *= norm; for (Varray::iterator it = vect_2_.begin(); it != vect_2_.end(); ++it) *it *= norm; - for (Varray::iterator it = vect2_1_.begin(); it != vect2_1_.end(); ++it) - *it *= norm; - for (Varray::iterator it = vect2_2_.begin(); it != vect2_2_.end(); ++it) - *it *= norm; +// for (Varray::iterator it = vect2_1_.begin(); it != vect2_1_.end(); ++it) +// *it *= norm; +// for (Varray::iterator it = vect2_2_.begin(); it != vect2_2_.end(); ++it) +// *it *= norm; for (MatType::iterator it = covarMatrix_.begin(); it != covarMatrix_.end(); ++it) *it *= norm; mprintf("DEBUG: First 3 elements: %f %f %f\n", @@ -126,8 +128,8 @@ int CoordCovarMatrix_Full::FinishMatrix() { vect_2_[0][1], vect_2_[0][2]); // Calc - - vect2_minus_vect(vect2_1_, vect_1_); - vect2_minus_vect(vect2_2_, vect_2_); +// vect2_minus_vect(vect2_1_, vect_1_); +// vect2_minus_vect(vect2_2_, vect_2_); // Calc - Matrix::iterator mat = covarMatrix_.begin(); for (unsigned int idx2 = 0; idx2 < vect_2_.size(); idx2++) diff --git a/src/CoordCovarMatrix_Full.h b/src/CoordCovarMatrix_Full.h index e0dac18889..a691daea8e 100644 --- a/src/CoordCovarMatrix_Full.h +++ b/src/CoordCovarMatrix_Full.h @@ -22,8 +22,8 @@ class CoordCovarMatrix_Full : public CoordCovarMatrix { Varray vect_1_; Varray vect_2_; - Varray vect2_1_; ///< Array of average diagonal elements squared - Varray vect2_2_; +// Varray vect2_1_; ///< Array of average diagonal elements squared +// Varray vect2_2_; Darray mass1_; Darray mass2_; }; diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 573e521c0e..6a72ac7737 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -131,7 +131,7 @@ Analysis_Spline.o : Analysis_Spline.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.o : Analysis_State.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Statistics.o : Analysis_Statistics.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Statistics.h ArgList.h Array1D.h AssociatedData.h AssociatedData_NOE.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 DataSet_float.h DataSet_integer.h DataSet_string.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 Analysis_TI.o : Analysis_TI.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TI.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 DataSet_Mesh.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 Segment.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Half.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordCovarMatrix_Half.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Timecorr.o : Analysis_Timecorr.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Timecorr.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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 PubFFT.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 Analysis_VectorMath.o : Analysis_VectorMath.cpp ActionState.h Analysis.h AnalysisState.h Analysis_VectorMath.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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_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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Wavelet.o : Analysis_Wavelet.cpp ActionFrameCounter.h ActionState.h Analysis.h AnalysisState.h Analysis_Wavelet.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterMap.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixFlt.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ProgressBar.h ProgressTimer.h PubFFT.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h From 2cbeb3ef381a11ab2667d965eae71d4c91d7ca2e Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 27 Mar 2024 10:18:32 -0400 Subject: [PATCH 019/200] Update docs --- src/CoordCovarMatrix_Full.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/CoordCovarMatrix_Full.h b/src/CoordCovarMatrix_Full.h index a691daea8e..f8903d811b 100644 --- a/src/CoordCovarMatrix_Full.h +++ b/src/CoordCovarMatrix_Full.h @@ -9,6 +9,7 @@ class CoordCovarMatrix_Full : public CoordCovarMatrix { /// Finish calculating the matrix (normalize, calc - ) int FinishMatrix(); // --------------------------------- + /// Set up matrix for 2 masks int SetupMatrix(std::vector const&, AtomMask const&, std::vector const&, AtomMask const&, bool); /// Add selected atoms in Frame to matrix @@ -20,11 +21,11 @@ class CoordCovarMatrix_Full : public CoordCovarMatrix { /// Set up the covariance matrix for selected atoms int setupMat(std::vector const&, AtomMask const&); - Varray vect_1_; - Varray vect_2_; + Varray vect_1_; ///< Hold average of elements in mask1 + Varray vect_2_; ///< Hold average of elements in mask2 // Varray vect2_1_; ///< Array of average diagonal elements squared // Varray vect2_2_; - Darray mass1_; - Darray mass2_; + Darray mass1_; ///< Hold masses of atoms in mask1 + Darray mass2_; ///< Hold masses of atoms in mask2 }; #endif From 3d62a137eab32a260f274f3cb2673ea620c8de6c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 27 Mar 2024 11:42:31 -0400 Subject: [PATCH 020/200] Declare inside loops --- src/CoordCovarMatrix_Half.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 5d2a1af439..09f762ea6e 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -108,15 +108,13 @@ int CoordCovarMatrix_Half::FinishMatrix() { // vect2[k][2] -= (vect[k][2] * vect[k][2]); //} // Calc - - double Mass = 1.0; - double mass1 = 1.0; MatType::iterator mat = covarMatrix_.begin(); for (unsigned int idx1 = 0; idx1 < mass_.size(); idx1++) { - mass1 = mass_[idx1]; + double mass1 = mass_[idx1]; for (int iidx = 0; iidx < 3; iidx++) { double Vi = vect_[idx1][iidx]; for (unsigned int idx2 = idx1; idx2 < mass_.size(); idx2++) { - Mass = sqrt( mass1 * mass_[idx2] ); + double Mass = sqrt( mass1 * mass_[idx2] ); if (idx1 == idx2) { // Self for (int jidx = iidx; jidx < 3; jidx++) { From faad48298696fe6acf0bb0969c4954e6a311d492 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 27 Mar 2024 16:19:10 -0400 Subject: [PATCH 021/200] Debug test for full covar matrix. --- test/Test_TICA/RunTest.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/Test_TICA/RunTest.sh b/test/Test_TICA/RunTest.sh index 8ff57755cd..a5e93c0d52 100755 --- a/test/Test_TICA/RunTest.sh +++ b/test/Test_TICA/RunTest.sh @@ -2,7 +2,7 @@ . ../MasterTest.sh -CleanFiles tica.in ticadebug.dat +CleanFiles tica.in ticadebug.dat M1.dat INPUT='-i tica.in' @@ -13,9 +13,13 @@ loadcrd ../tz2.crd name TZ2 set MASK = :1-3@N,CA,C -crdaction TZ2 matrix name M1 mwcovar out M1.dat \$MASK $MASS +#crdaction TZ2 matrix name M1 mwcovar out M1.dat \$MASK $MASS -runanalysis tica crdset TZ2 mask \$MASK lag 1 debugfile ticadebug.dat $MASS +#runanalysis tica crdset TZ2 mask \$MASK lag 1 debugfile ticadebug.dat $MASS + +crdaction TZ2 matrix name M1 mwcovar out M1.dat :1-3@N,CA :1-3@C,O $MASS + +runanalysis tica crdset TZ2 mask :1-3@N,CA mask2 :1-3@C,O lag 1 debugfile ticadebug.dat $MASS list dataset EOF From 543a1533e7c6db643c8283e52b22d0d84b0a76cc Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 28 Mar 2024 09:58:06 -0400 Subject: [PATCH 022/200] Add clear function --- src/DataSet_2D.h | 2 ++ src/DataSet_MatrixDbl.cpp | 9 +++++++++ src/DataSet_MatrixDbl.h | 1 + src/DataSet_MatrixFlt.cpp | 7 +++++++ src/DataSet_MatrixFlt.h | 1 + 5 files changed, 20 insertions(+) diff --git a/src/DataSet_2D.h b/src/DataSet_2D.h index f14bd61c5d..b1618fe77d 100644 --- a/src/DataSet_2D.h +++ b/src/DataSet_2D.h @@ -43,6 +43,8 @@ class DataSet_2D : public DataSet { virtual const void* MatrixPtr() const = 0; /// \return pointer to underlying matrix. virtual void* MatrixPtr() = 0; + /// Clear matrix + virtual void Clear() = 0; // ------------------------------------------- // TODO: Remove this. Only needed by DataSet_1D.h void Add(size_t,const void*) { } diff --git a/src/DataSet_MatrixDbl.cpp b/src/DataSet_MatrixDbl.cpp index 122ae55794..9aaa1dae7d 100644 --- a/src/DataSet_MatrixDbl.cpp +++ b/src/DataSet_MatrixDbl.cpp @@ -14,6 +14,15 @@ double* DataSet_MatrixDbl::MatrixArray() const { return matOut; } +/** Clear the matrix. */ +void DataSet_MatrixDbl::Clear() { + mat_.clear(); + vect_.clear(); + mass_.clear(); + //kind_; + snap_ = 0; +} + #ifdef MPI int DataSet_MatrixDbl::Sync(size_t total, std::vector const& rank_frames, Parallel::Comm const& commIn) diff --git a/src/DataSet_MatrixDbl.h b/src/DataSet_MatrixDbl.h index f8fca7f711..b0014ad2d7 100644 --- a/src/DataSet_MatrixDbl.h +++ b/src/DataSet_MatrixDbl.h @@ -34,6 +34,7 @@ class DataSet_MatrixDbl : public DataSet_2D { MatrixKindType MatrixKind() const { return kind_; } const void* MatrixPtr() const { return mat_.Ptr(); } void* MatrixPtr() { return mat_.Ptr(); } + void Clear(); // ------------------------------------------- unsigned int Nsnapshots() const { return snap_; } void IncrementSnapshots() { ++snap_; } diff --git a/src/DataSet_MatrixFlt.cpp b/src/DataSet_MatrixFlt.cpp index 9eabeeac10..482f15d362 100644 --- a/src/DataSet_MatrixFlt.cpp +++ b/src/DataSet_MatrixFlt.cpp @@ -14,6 +14,13 @@ double* DataSet_MatrixFlt::MatrixArray() const { matOut[i] = (double)mat_[i]; return matOut; } + +/** Clear the matrix */ +void DataSet_MatrixFlt::Clear() { + mat_.clear(); + // kind_; +} + #ifdef MPI int DataSet_MatrixFlt::Sync(size_t total, std::vector const& rank_frames, Parallel::Comm const& commIn) diff --git a/src/DataSet_MatrixFlt.h b/src/DataSet_MatrixFlt.h index 7a0cf6f01c..352d3a2927 100644 --- a/src/DataSet_MatrixFlt.h +++ b/src/DataSet_MatrixFlt.h @@ -33,6 +33,7 @@ class DataSet_MatrixFlt : public DataSet_2D { MatrixKindType MatrixKind() const { return kind_; } const void* MatrixPtr() const { return mat_.Ptr(); } void* MatrixPtr() { return mat_.Ptr(); } + void Clear(); // ------------------------------------------- int AddElement(float d) { return mat_.addElement(d); } /// Type definition of iterator over matrix elements. From 77641a09a058a82332aebaa7a4504ab5ccb8c79a Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 28 Mar 2024 10:01:53 -0400 Subject: [PATCH 023/200] Start generalizing the covar matrix --- src/CovarMatrix.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ src/CovarMatrix.h | 43 +++++++++++++++++++++++++++++++++++ src/cpptrajfiles | 6 ++--- 3 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/CovarMatrix.cpp create mode 100644 src/CovarMatrix.h diff --git a/src/CovarMatrix.cpp b/src/CovarMatrix.cpp new file mode 100644 index 0000000000..ae9f66f66f --- /dev/null +++ b/src/CovarMatrix.cpp @@ -0,0 +1,55 @@ +#include "CovarMatrix.h" +#include "Atom.h" +#include "AtomMask.h" +#include "CpptrajFile.h" +#include "CpptrajStdio.h" +#include "DataSet_2D.h" + +/** CONSTRUCTOR */ +CovarMatrix::CovarMatrix(unsigned int n) : + covarMatrix_(0), + nelt_(n), + useMass_(false) +{} + +/** Clear the matrix */ +void CovarMatrix::Clear() { + if (covarMatrix_ != 0) covarMatrix_->Clear(); + nframes_ = 0; + clearMat(); +} + +/** Setup mass array */ +void CovarMatrix::set_mass_array(Darray& mass, std::vector const& atoms, + AtomMask const& maskIn, bool useMassIn) +{ + nframes_ = 0; + useMass_ = useMassIn; + mass.clear(); + mass.reserve( maskIn.Nselected() ); + if (useMassIn) { + for (AtomMask::const_iterator at = maskIn.begin(); at != maskIn.end(); ++at) + mass.push_back( atoms[*at].Mass() ); + } else { + for (int idx = 0; idx < maskIn.Nselected(); idx++) + mass.push_back( 1.0 ); + } +} + +/** Debug print to file */ +void CovarMatrix::DebugPrint(const char* desc, CpptrajFile& outfile) const { + if (desc != 0) + outfile.Printf("DEBUG: CoordCovarMatrix: %s\n", desc); + if (covarMatrix_ == 0) { + mprintf("Warning: No covar matrix allocated.\n"); + outfile.Printf("No covar matrix allocated.\n"); + return; + } + + for (unsigned int row = 0; row < covarMatrix_->Nrows(); row++) { + for (unsigned int col = 0; col < covarMatrix_->Ncols(); col++) { + outfile.Printf(" %6.3f", covarMatrix_->GetElement(col, row)); + } + outfile.Printf("\n"); + } +} diff --git a/src/CovarMatrix.h b/src/CovarMatrix.h new file mode 100644 index 0000000000..18cfb8201f --- /dev/null +++ b/src/CovarMatrix.h @@ -0,0 +1,43 @@ +#ifndef INC_COVARMATRIX_H +#define INC_COVARMATRIX_H +#include "Matrix.h" +#include "Vec3.h" +#include +class Atom; +class AtomMask; +class CpptrajFile; +class DataSet_2D; +/// Coordinate covariance matrix abstract base class +class CovarMatrix { + public: + /// CONSTRUCTOR - Number of elements + CovarMatrix(unsigned int); + /// DESTRUCTOR - virtual since inherited + virtual ~CovarMatrix() {} + // --------------------------------- + /// Finish calculating the matrix (normalize, calc - ) + virtual int FinishMatrix() = 0; + // --------------------------------- + /// Clear the matrix + void Clear(); + + /// Print matrix elements to STDOUT for debug + void DebugPrint(const char*, CpptrajFile&) const; + protected: + typedef DataSet_2D* MatType; + typedef std::vector Darray; + + /// clear internal variables + virtual void clearMat() = 0; + + /// set mass array + void set_mass_array(Darray&, std::vector const&, AtomMask const&, bool); + + //private: // TODO all private + + MatType covarMatrix_; ///< Covariance matrix + unsigned int nelt_; ///< Number of elements per atom + unsigned int nframes_; ///< Number of frames added to the matrix + bool useMass_; ///< If true use mass weighting +}; +#endif diff --git a/src/cpptrajfiles b/src/cpptrajfiles index e23ae3783c..e9defb1c1f 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -163,9 +163,9 @@ COMMON_SOURCES= \ ComplexArray.cpp \ Constraints.cpp \ ControlBlock_For.cpp \ - CoordCovarMatrix.cpp \ - CoordCovarMatrix_Full.cpp \ - CoordCovarMatrix_Half.cpp \ + CovarMatrix.cpp \ + CovarMatrix_Full.cpp \ + CovarMatrix_Half.cpp \ CoordinateInfo.cpp \ Corr.cpp \ Cph.cpp \ From 6b2af23bb7d28e730b2d2679ebad038a84674050 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 28 Mar 2024 10:41:41 -0400 Subject: [PATCH 024/200] Add normalize --- src/DataSet_2D.h | 2 ++ src/DataSet_MatrixDbl.cpp | 6 ++++++ src/DataSet_MatrixDbl.h | 1 + src/DataSet_MatrixFlt.cpp | 9 +++++++++ src/DataSet_MatrixFlt.h | 1 + 5 files changed, 19 insertions(+) diff --git a/src/DataSet_2D.h b/src/DataSet_2D.h index b1618fe77d..299d568cbe 100644 --- a/src/DataSet_2D.h +++ b/src/DataSet_2D.h @@ -45,6 +45,8 @@ class DataSet_2D : public DataSet { virtual void* MatrixPtr() = 0; /// Clear matrix virtual void Clear() = 0; + /// Normalize matrix + virtual void Normalize(double) = 0; // ------------------------------------------- // TODO: Remove this. Only needed by DataSet_1D.h void Add(size_t,const void*) { } diff --git a/src/DataSet_MatrixDbl.cpp b/src/DataSet_MatrixDbl.cpp index 9aaa1dae7d..d6553a2fb4 100644 --- a/src/DataSet_MatrixDbl.cpp +++ b/src/DataSet_MatrixDbl.cpp @@ -23,6 +23,12 @@ void DataSet_MatrixDbl::Clear() { snap_ = 0; } +/** Normalize the matrix. */ +void DataSet_MatrixDbl::Normalize(double norm) { + for (Matrix::iterator it = mat_.begin(); it != mat_.end(); ++it) + *it *= norm; +} + #ifdef MPI int DataSet_MatrixDbl::Sync(size_t total, std::vector const& rank_frames, Parallel::Comm const& commIn) diff --git a/src/DataSet_MatrixDbl.h b/src/DataSet_MatrixDbl.h index b0014ad2d7..5cd1f4e237 100644 --- a/src/DataSet_MatrixDbl.h +++ b/src/DataSet_MatrixDbl.h @@ -35,6 +35,7 @@ class DataSet_MatrixDbl : public DataSet_2D { const void* MatrixPtr() const { return mat_.Ptr(); } void* MatrixPtr() { return mat_.Ptr(); } void Clear(); + void Normalize(double); // ------------------------------------------- unsigned int Nsnapshots() const { return snap_; } void IncrementSnapshots() { ++snap_; } diff --git a/src/DataSet_MatrixFlt.cpp b/src/DataSet_MatrixFlt.cpp index 482f15d362..d2ae8fecc8 100644 --- a/src/DataSet_MatrixFlt.cpp +++ b/src/DataSet_MatrixFlt.cpp @@ -21,6 +21,15 @@ void DataSet_MatrixFlt::Clear() { // kind_; } +/** Normalize the matrix */ +void DataSet_MatrixFlt::Normalize(double norm) { + for (Matrix::iterator it = mat_.begin(); it != mat_.end(); ++it) + { + double newElt = ((double)*it) * norm; + *it = (float)newElt; + } +} + #ifdef MPI int DataSet_MatrixFlt::Sync(size_t total, std::vector const& rank_frames, Parallel::Comm const& commIn) diff --git a/src/DataSet_MatrixFlt.h b/src/DataSet_MatrixFlt.h index 352d3a2927..671707e605 100644 --- a/src/DataSet_MatrixFlt.h +++ b/src/DataSet_MatrixFlt.h @@ -34,6 +34,7 @@ class DataSet_MatrixFlt : public DataSet_2D { const void* MatrixPtr() const { return mat_.Ptr(); } void* MatrixPtr() { return mat_.Ptr(); } void Clear(); + void Normalize(double); // ------------------------------------------- int AddElement(float d) { return mat_.addElement(d); } /// Type definition of iterator over matrix elements. From 774a1acef2be2d4e2544d37d64344890466c18bf Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 28 Mar 2024 11:30:01 -0400 Subject: [PATCH 025/200] Have half and full debug go to separate files for easier comparing --- src/Analysis_TICA.cpp | 27 +++++++++++++++++++-------- src/Analysis_TICA.h | 3 ++- test/Test_TICA/RunTest.sh | 10 +++++----- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 93990005d5..987e4e0d99 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -8,7 +8,8 @@ Analysis_TICA::Analysis_TICA() : TgtTraj_(0), lag_(0), useMass_(false), - debugFile_(0) + debugC0_(0), + debugCT_(0) { SetHidden(true); } @@ -47,10 +48,17 @@ Analysis::RetType Analysis_TICA::Setup(ArgList& analyzeArgs, AnalysisSetup& setu } useMass_ = analyzeArgs.hasKey("mass"); - debugFile_ = setup.DFL().AddCpptrajFile(analyzeArgs.GetStringKey("debugfile"), "TICA debug", + + debugC0_ = setup.DFL().AddCpptrajFile(analyzeArgs.GetStringKey("debugc0"), "TICA C0 debug", + DataFileList::TEXT, true); + if (debugC0_ == 0) { + mprinterr("Error: Could not open C0 debug file.\n"); + return Analysis::ERR; + } + debugCT_ = setup.DFL().AddCpptrajFile(analyzeArgs.GetStringKey("debugct"), "TICA CT debug", DataFileList::TEXT, true); - if (debugFile_ == 0) { - mprinterr("Error: Could not open debug file.\n"); + if (debugCT_ == 0) { + mprinterr("Error: Could not open CT debug file.\n"); return Analysis::ERR; } @@ -63,8 +71,10 @@ Analysis::RetType Analysis_TICA::Setup(ArgList& analyzeArgs, AnalysisSetup& setu mprintf("\tMass-weighted.\n"); else mprintf("\tNot mass-weighted.\n"); - if (debugFile_ != 0) - mprintf("\tDebug output to %s\n", debugFile_->Filename().full()); + if (debugC0_ != 0) + mprintf("\tDebug C0 output to %s\n", debugC0_->Filename().full()); + if (debugCT_ != 0) + mprintf("\tDebug CT output to %s\n", debugCT_->Filename().full()); return Analysis::OK; } @@ -86,6 +96,7 @@ Analysis::RetType Analysis_TICA::Analyze() { mprinterr("Error: No atoms selected by mask '%s'\n", mask1_.MaskString()); return Analysis::ERR; } + // DEBUG if (mask2_.MaskStringSet()) { if ( TgtTraj_->Top().SetupIntegerMask( mask2_ ) ) { mprinterr("Error: Could not evaluate second atom mask '%s'\n", mask2_.MaskString()); @@ -120,7 +131,7 @@ Analysis::RetType Analysis_TICA::Analyze() { } // DEBUG PRINT - //covarMatrix.DebugPrint("C0", *debugFile_); + covarMatrix.DebugPrint("C0", *debugC0_); if (mask2_.MaskStringSet()) { // DEBUG @@ -144,7 +155,7 @@ Analysis::RetType Analysis_TICA::Analyze() { } // DEBUG PRINT - CT.DebugPrint("CT", *debugFile_); + CT.DebugPrint("CT", *debugCT_); } return Analysis::OK; diff --git a/src/Analysis_TICA.h b/src/Analysis_TICA.h index fd1a3a8fc3..2d8af02246 100644 --- a/src/Analysis_TICA.h +++ b/src/Analysis_TICA.h @@ -16,6 +16,7 @@ class Analysis_TICA : public Analysis { AtomMask mask1_; ///< Atoms to use in matrix calc AtomMask mask2_; ///< Second atom mask for debugging full covar matrix bool useMass_; ///< Control whether to mass-weight - CpptrajFile* debugFile_; ///< Debug output + CpptrajFile* debugC0_; ///< Debug output for C0 + CpptrajFile* debugCT_; ///< Debug output for CT }; #endif diff --git a/test/Test_TICA/RunTest.sh b/test/Test_TICA/RunTest.sh index a5e93c0d52..8290840b36 100755 --- a/test/Test_TICA/RunTest.sh +++ b/test/Test_TICA/RunTest.sh @@ -2,7 +2,7 @@ . ../MasterTest.sh -CleanFiles tica.in ticadebug.dat M1.dat +CleanFiles tica.in ticadebug.dat M?.dat ticadebug.m?.dat INPUT='-i tica.in' @@ -13,13 +13,13 @@ loadcrd ../tz2.crd name TZ2 set MASK = :1-3@N,CA,C -#crdaction TZ2 matrix name M1 mwcovar out M1.dat \$MASK $MASS +crdaction TZ2 matrix name M1 mwcovar out M1.dat \$MASK $MASS -#runanalysis tica crdset TZ2 mask \$MASK lag 1 debugfile ticadebug.dat $MASS +runanalysis tica crdset TZ2 mask \$MASK lag 1 debugc0 ticadebug.m1.dat $MASS -crdaction TZ2 matrix name M1 mwcovar out M1.dat :1-3@N,CA :1-3@C,O $MASS +crdaction TZ2 matrix name M2 mwcovar out M2.dat :1-3@N,CA :1-3@C,O $MASS -runanalysis tica crdset TZ2 mask :1-3@N,CA mask2 :1-3@C,O lag 1 debugfile ticadebug.dat $MASS +runanalysis tica crdset TZ2 mask :1-3@N,CA mask2 :1-3@C,O lag 1 debugct ticadebug.m2.dat $MASS list dataset EOF From 831d93ec7f50e4b9ca12911297e8ddd7f97d103a Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 28 Mar 2024 12:19:11 -0400 Subject: [PATCH 026/200] CovarMatrix nowhere near ready --- src/CovarMatrix.cpp | 55 --------------------------------------------- src/CovarMatrix.h | 43 ----------------------------------- src/cpptrajfiles | 6 ++--- 3 files changed, 3 insertions(+), 101 deletions(-) delete mode 100644 src/CovarMatrix.cpp delete mode 100644 src/CovarMatrix.h diff --git a/src/CovarMatrix.cpp b/src/CovarMatrix.cpp deleted file mode 100644 index ae9f66f66f..0000000000 --- a/src/CovarMatrix.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "CovarMatrix.h" -#include "Atom.h" -#include "AtomMask.h" -#include "CpptrajFile.h" -#include "CpptrajStdio.h" -#include "DataSet_2D.h" - -/** CONSTRUCTOR */ -CovarMatrix::CovarMatrix(unsigned int n) : - covarMatrix_(0), - nelt_(n), - useMass_(false) -{} - -/** Clear the matrix */ -void CovarMatrix::Clear() { - if (covarMatrix_ != 0) covarMatrix_->Clear(); - nframes_ = 0; - clearMat(); -} - -/** Setup mass array */ -void CovarMatrix::set_mass_array(Darray& mass, std::vector const& atoms, - AtomMask const& maskIn, bool useMassIn) -{ - nframes_ = 0; - useMass_ = useMassIn; - mass.clear(); - mass.reserve( maskIn.Nselected() ); - if (useMassIn) { - for (AtomMask::const_iterator at = maskIn.begin(); at != maskIn.end(); ++at) - mass.push_back( atoms[*at].Mass() ); - } else { - for (int idx = 0; idx < maskIn.Nselected(); idx++) - mass.push_back( 1.0 ); - } -} - -/** Debug print to file */ -void CovarMatrix::DebugPrint(const char* desc, CpptrajFile& outfile) const { - if (desc != 0) - outfile.Printf("DEBUG: CoordCovarMatrix: %s\n", desc); - if (covarMatrix_ == 0) { - mprintf("Warning: No covar matrix allocated.\n"); - outfile.Printf("No covar matrix allocated.\n"); - return; - } - - for (unsigned int row = 0; row < covarMatrix_->Nrows(); row++) { - for (unsigned int col = 0; col < covarMatrix_->Ncols(); col++) { - outfile.Printf(" %6.3f", covarMatrix_->GetElement(col, row)); - } - outfile.Printf("\n"); - } -} diff --git a/src/CovarMatrix.h b/src/CovarMatrix.h deleted file mode 100644 index 18cfb8201f..0000000000 --- a/src/CovarMatrix.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef INC_COVARMATRIX_H -#define INC_COVARMATRIX_H -#include "Matrix.h" -#include "Vec3.h" -#include -class Atom; -class AtomMask; -class CpptrajFile; -class DataSet_2D; -/// Coordinate covariance matrix abstract base class -class CovarMatrix { - public: - /// CONSTRUCTOR - Number of elements - CovarMatrix(unsigned int); - /// DESTRUCTOR - virtual since inherited - virtual ~CovarMatrix() {} - // --------------------------------- - /// Finish calculating the matrix (normalize, calc - ) - virtual int FinishMatrix() = 0; - // --------------------------------- - /// Clear the matrix - void Clear(); - - /// Print matrix elements to STDOUT for debug - void DebugPrint(const char*, CpptrajFile&) const; - protected: - typedef DataSet_2D* MatType; - typedef std::vector Darray; - - /// clear internal variables - virtual void clearMat() = 0; - - /// set mass array - void set_mass_array(Darray&, std::vector const&, AtomMask const&, bool); - - //private: // TODO all private - - MatType covarMatrix_; ///< Covariance matrix - unsigned int nelt_; ///< Number of elements per atom - unsigned int nframes_; ///< Number of frames added to the matrix - bool useMass_; ///< If true use mass weighting -}; -#endif diff --git a/src/cpptrajfiles b/src/cpptrajfiles index e9defb1c1f..e23ae3783c 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -163,9 +163,9 @@ COMMON_SOURCES= \ ComplexArray.cpp \ Constraints.cpp \ ControlBlock_For.cpp \ - CovarMatrix.cpp \ - CovarMatrix_Full.cpp \ - CovarMatrix_Half.cpp \ + CoordCovarMatrix.cpp \ + CoordCovarMatrix_Full.cpp \ + CoordCovarMatrix_Half.cpp \ CoordinateInfo.cpp \ Corr.cpp \ Cph.cpp \ From 8eff2da52c6d935548eb496bd7ab8c02098ba736 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 10:24:58 -0400 Subject: [PATCH 027/200] Start generalizing the covar matrices for other types besides coordinate vectors --- src/CoordCovarMatrix.cpp | 5 +++-- src/CoordCovarMatrix.h | 6 +++--- src/CoordCovarMatrix_Full.cpp | 3 ++- src/CoordCovarMatrix_Full.h | 1 + src/CoordCovarMatrix_Half.cpp | 38 +++++++++++++++++++---------------- src/CoordCovarMatrix_Half.h | 6 +++--- 6 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index acbc744014..af60fdf508 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -4,9 +4,10 @@ #include "CpptrajFile.h" #include "CpptrajStdio.h" -/** CONSTRUCTOR */ -CoordCovarMatrix::CoordCovarMatrix() : +/** CONSTRUCTOR - number of elements */ +CoordCovarMatrix::CoordCovarMatrix(unsigned int nelt) : nframes_(0), + nelt_(nelt), useMass_(false) {} diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index bcaa1a8086..c6d8d308a5 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -9,8 +9,8 @@ class CpptrajFile; /// Coordinate covariance matrix abstract base class class CoordCovarMatrix { public: - /// CONSTRUCTOR - CoordCovarMatrix(); + /// CONSTRUCTOR - number of elements + CoordCovarMatrix(unsigned int); /// DESTRUCTOR - virtual since inherited virtual ~CoordCovarMatrix() {} // --------------------------------- @@ -25,7 +25,6 @@ class CoordCovarMatrix { protected: typedef Matrix MatType; typedef std::vector Darray; - typedef std::vector Varray; /// clear internal variables virtual void clearMat() = 0; @@ -37,6 +36,7 @@ class CoordCovarMatrix { MatType covarMatrix_; ///< Coordinate covariance matrix unsigned int nframes_; ///< Number of frames added to the matrix + unsigned int nelt_; ///< Number of elements per i,j entry bool useMass_; ///< If true use mass weighting }; #endif diff --git a/src/CoordCovarMatrix_Full.cpp b/src/CoordCovarMatrix_Full.cpp index 210dfb7c5a..43d992a4bb 100644 --- a/src/CoordCovarMatrix_Full.cpp +++ b/src/CoordCovarMatrix_Full.cpp @@ -4,7 +4,8 @@ #include "Frame.h" /** CONSTRUCTOR */ -CoordCovarMatrix_Full::CoordCovarMatrix_Full() +CoordCovarMatrix_Full::CoordCovarMatrix_Full() : + CoordCovarMatrix(3) {} /** Clear the matrix */ diff --git a/src/CoordCovarMatrix_Full.h b/src/CoordCovarMatrix_Full.h index f8903d811b..0a7fc936e7 100644 --- a/src/CoordCovarMatrix_Full.h +++ b/src/CoordCovarMatrix_Full.h @@ -16,6 +16,7 @@ class CoordCovarMatrix_Full : public CoordCovarMatrix { void AddFrameToMatrix(Frame const&, AtomMask const&, Frame const&, AtomMask const&); private: + typedef std::vector Varray; /// Clear the matrix void clearMat(); /// Set up the covariance matrix for selected atoms diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 09f762ea6e..07dcf3e122 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -6,7 +6,8 @@ #include // sqrt /** CONSTRUCTOR */ -CoordCovarMatrix_Half::CoordCovarMatrix_Half() +CoordCovarMatrix_Half::CoordCovarMatrix_Half() : + CoordCovarMatrix(3) {} /** Clear the matrix */ @@ -20,9 +21,9 @@ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, AtomMask const& maskIn, bool useMassIn) { // Matrix - half - covarMatrix_.resize( maskIn.Nselected()*3, 0 ); + covarMatrix_.resize( maskIn.Nselected()*nelt_, 0 ); - vect_.assign(maskIn.Nselected(), Vec3(0.0)); + vect_.assign( maskIn.Nselected()*nelt_, 0 ); set_mass_array(mass_, atoms, maskIn, useMassIn); @@ -37,15 +38,16 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask cons for (int idx1 = 0; idx1 < maskIn.Nselected(); idx1++) { int at1 = maskIn[idx1]; Vec3 XYZi( frameIn.XYZ(at1) ); - // Store veci and veci^2 - vect_[idx1] += XYZi; + unsigned int eidx1 = idx1 * nelt_; + // Store average + for (unsigned int ei = 0; ei < nelt_; ei++) + vect_[eidx1+ei] += XYZi[ei]; //XYZi.Print("XYZi"); - //vect2[idx1] += XYZi.Squared(); // Loop over X, Y, and Z of veci - for (int iidx = 0; iidx < 3; iidx++) { + for (unsigned int iidx = 0; iidx < nelt_; iidx++) { double Vi = XYZi[iidx]; // Diagonal - for (int jidx = iidx; jidx < 3; jidx++) + for (unsigned int jidx = iidx; jidx < nelt_; jidx++) *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} // Inner loop for (int idx2 = idx1 + 1; idx2 < maskIn.Nselected(); idx2++) { @@ -61,7 +63,7 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask cons } /** Add given Frame to the matrix. */ -void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn) +/*void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn) { // Covariance MatType::iterator mat = covarMatrix_.begin(); @@ -87,7 +89,7 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn) } // END loop over x y z of veci } // END outer loop over idx1 nframes_++; -} +}*/ /** Finish the matrix. */ int CoordCovarMatrix_Half::FinishMatrix() { @@ -97,7 +99,7 @@ int CoordCovarMatrix_Half::FinishMatrix() { } // Normalize double norm = 1.0 / (double)nframes_; - for (Varray::iterator it = vect_.begin(); it != vect_.end(); ++it) + for (Darray::iterator it = vect_.begin(); it != vect_.end(); ++it) *it *= norm; for (MatType::iterator it = covarMatrix_.begin(); it != covarMatrix_.end(); ++it) *it *= norm; @@ -111,19 +113,21 @@ int CoordCovarMatrix_Half::FinishMatrix() { MatType::iterator mat = covarMatrix_.begin(); for (unsigned int idx1 = 0; idx1 < mass_.size(); idx1++) { double mass1 = mass_[idx1]; - for (int iidx = 0; iidx < 3; iidx++) { - double Vi = vect_[idx1][iidx]; + for (unsigned int iidx = 0; iidx < nelt_; iidx++) { + unsigned int eidx1 = idx1*nelt_; + double Vi = vect_[eidx1 + iidx]; for (unsigned int idx2 = idx1; idx2 < mass_.size(); idx2++) { double Mass = sqrt( mass1 * mass_[idx2] ); if (idx1 == idx2) { // Self - for (int jidx = iidx; jidx < 3; jidx++) { - *mat = (*mat - (Vi * vect_[idx2][jidx])) * Mass; + for (unsigned int jidx = iidx; jidx < nelt_; jidx++) { + *mat = (*mat - (Vi * vect_[eidx1 + jidx])) * Mass; ++mat; } } else { - for (int jidx = 0; jidx < 3; jidx++) { - *mat = (*mat - (Vi * vect_[idx2][jidx])) * Mass; + unsigned int eidx2 = idx2*nelt_; + for (unsigned int jidx = 0; jidx < nelt_; jidx++) { + *mat = (*mat - (Vi * vect_[eidx2 + jidx])) * Mass; ++mat; } } diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index 1c8897812e..976cdccb91 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -5,7 +5,7 @@ class Frame; /// Coordinate covariance half (self) matrix class CoordCovarMatrix_Half : public CoordCovarMatrix { public: - /// CONSTRUCTOR + /// CONSTRUCTOR CoordCovarMatrix_Half(); // --------------------------------- /// Finish calculating the matrix (normalize, calc - ) @@ -16,12 +16,12 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { /// Add selected atoms in Frame to matrix void AddFrameToMatrix(Frame const&, AtomMask const&); /// Add Frame to matrix - void AddFrameToMatrix(Frame const&); + //void AddFrameToMatrix(Frame const&); private: /// Clear the matrix void clearMat(); - Varray vect_; + Darray vect_; Darray mass_; }; From 829f89bc6fbb104dc6af4f06f9517f068cd4fd50 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 13:19:43 -0400 Subject: [PATCH 028/200] Start generalizing full --- src/CoordCovarMatrix.h | 1 - src/CoordCovarMatrix_Full.cpp | 65 ++++++++++++++++++----------------- src/CoordCovarMatrix_Full.h | 7 ++-- src/cpptrajdepend | 2 +- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index c6d8d308a5..0fd46affe1 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -1,7 +1,6 @@ #ifndef INC_COORDCOVARMATRIX_H #define INC_COORDCOVARMATRIX_H #include "Matrix.h" -#include "Vec3.h" #include class Atom; class AtomMask; diff --git a/src/CoordCovarMatrix_Full.cpp b/src/CoordCovarMatrix_Full.cpp index 43d992a4bb..1cffd04907 100644 --- a/src/CoordCovarMatrix_Full.cpp +++ b/src/CoordCovarMatrix_Full.cpp @@ -10,8 +10,6 @@ CoordCovarMatrix_Full::CoordCovarMatrix_Full() : /** Clear the matrix */ void CoordCovarMatrix_Full::clearMat() { -// vect2_1_.clear(); -// vect2_2_.clear(); vect_1_.clear(); vect_2_.clear(); mass1_.clear(); @@ -25,12 +23,10 @@ int CoordCovarMatrix_Full::SetupMatrix(std::vector const& atoms1, AtomMask const& maskIn2, bool useMassIn) { // Matrix - full - covarMatrix_.resize( maskIn1.Nselected()*3, maskIn2.Nselected()*3 ); + covarMatrix_.resize( maskIn1.Nselected()*nelt_, maskIn2.Nselected()*nelt_ ); - vect_1_.assign(maskIn1.Nselected(), Vec3(0.0)); -// vect2_1_.assign(maskIn1.Nselected(), Vec3(0.0)); - vect_2_.assign(maskIn2.Nselected(), Vec3(0.0)); -// vect2_2_.assign(maskIn2.Nselected(), Vec3(0.0)); + vect_1_.assign(maskIn1.Nselected()*nelt_, 0); + vect_2_.assign(maskIn2.Nselected()*nelt_, 0); set_mass_array( mass1_, atoms1, maskIn1, useMassIn ); set_mass_array( mass2_, atoms2, maskIn2, useMassIn ); @@ -38,16 +34,18 @@ int CoordCovarMatrix_Full::SetupMatrix(std::vector const& atoms1, } /** Store diagonal (average and average^2) */ -static inline void store_diagonal(std::vector& vect, +static inline void store_diagonal(std::vector& vect, // std::vector& vect2, + unsigned int nelt, Frame const& frameIn, AtomMask const& maskIn) { for (int idx = 0; idx < maskIn.Nselected(); idx++) { const double* XYZ = frameIn.XYZ( maskIn[idx] ); - for (int ii = 0; ii < 3; ii++) { - vect[idx][ii] += XYZ[ii]; + int eidx = idx * nelt; + for (unsigned int ii = 0; ii < nelt; ii++) { + vect[eidx+ii] += XYZ[ii]; // vect2[idx][ii] += (XYZ[ii] * XYZ[ii]); } } @@ -60,24 +58,24 @@ void CoordCovarMatrix_Full::AddFrameToMatrix(Frame const& frameIn1, AtomMask con //MatType::iterator mat = covarMatrix_.begin(); for (int idx2 = 0; idx2 < maskIn2.Nselected(); idx2++) { - Matrix::iterator mat = covarMatrix_.begin() + ((idx2*3)*covarMatrix_.Ncols()); // NX + Matrix::iterator mat = covarMatrix_.begin() + ((idx2*nelt_)*covarMatrix_.Ncols()); // NX const double* XYZj = frameIn2.XYZ( maskIn2[idx2] ); - for (int ny = 0; ny < 3; ny++) { + for (unsigned int ny = 0; ny < nelt_; ny++) { double Vj = XYZj[ny]; for (int idx1 = 0; idx1 < maskIn1.Nselected(); idx1++) { const double* XYZi = frameIn1.XYZ( maskIn1[idx1] ); - *(mat++) += Vj * XYZi[0]; - *(mat++) += Vj * XYZi[1]; - *(mat++) += Vj * XYZi[2]; + for (unsigned int nx = 0; nx < nelt_; nx++) { + *(mat++) += Vj * XYZi[nx]; + } } } } // Mask1/mask2 diagonal // store_diagonal(vect_1_, vect2_1_, frameIn1, maskIn1); // store_diagonal(vect_2_, vect2_2_, frameIn2, maskIn2); - store_diagonal(vect_1_, frameIn1, maskIn1); - store_diagonal(vect_2_, frameIn2, maskIn2); + store_diagonal(vect_1_, nelt_, frameIn1, maskIn1); + store_diagonal(vect_2_, nelt_, frameIn2, maskIn2); nframes_++; } @@ -106,9 +104,9 @@ int CoordCovarMatrix_Full::FinishMatrix() { } // Normalize double norm = 1.0 / (double)nframes_; - for (Varray::iterator it = vect_1_.begin(); it != vect_1_.end(); ++it) + for (Darray::iterator it = vect_1_.begin(); it != vect_1_.end(); ++it) *it *= norm; - for (Varray::iterator it = vect_2_.begin(); it != vect_2_.end(); ++it) + for (Darray::iterator it = vect_2_.begin(); it != vect_2_.end(); ++it) *it *= norm; // for (Varray::iterator it = vect2_1_.begin(); it != vect2_1_.end(); ++it) // *it *= norm; @@ -121,28 +119,31 @@ int CoordCovarMatrix_Full::FinishMatrix() { covarMatrix_.element(1, 0), covarMatrix_.element(2, 0)); mprintf("DEBUG: First 3 elements of V1: %f %f %f\n", - vect_1_[0][0], - vect_1_[0][1], - vect_1_[0][2]); + vect_1_[0], + vect_1_[1], + vect_1_[2]); mprintf("DEBUG: First 3 elements of V2: %f %f %f\n", - vect_2_[0][0], - vect_2_[0][1], - vect_2_[0][2]); + vect_2_[0], + vect_2_[1], + vect_2_[2]); // Calc - // vect2_minus_vect(vect2_1_, vect_1_); // vect2_minus_vect(vect2_2_, vect_2_); // Calc - Matrix::iterator mat = covarMatrix_.begin(); - for (unsigned int idx2 = 0; idx2 < vect_2_.size(); idx2++) + for (unsigned int idx2 = 0; idx2 < mass2_.size(); idx2++) { double mass2 = mass2_[idx2]; - Vec3 const& V2 = vect_2_[idx2]; - for (int ny = 0; ny < 3; ny++) { - for (unsigned int idx1 = 0; idx1 < vect_1_.size(); idx1++) { + unsigned int eidx2 = idx2 * nelt_; + for (unsigned int ny = 0; ny < nelt_; ny++) { + double V2 = vect_2_[eidx2+ny]; + for (unsigned int idx1 = 0; idx1 < mass1_.size(); idx1++) { double Mass = sqrt(mass2 * mass1_[idx1]); - for (int nx = 0; nx < 3; nx++) { - mprintf("mat = (%f - (%f * %f)) * %f\n", *mat, V2[ny], vect_1_[idx1][nx], Mass); - *mat = (*mat - (V2[ny] * vect_1_[idx1][nx])) * Mass; + unsigned int eidx1 = idx1 * nelt_; + for (unsigned int nx = 0; nx < nelt_; nx++) { + double V1 = vect_1_[eidx1+nx]; + mprintf("mat = (%f - (%f * %f)) * %f\n", *mat, V2, V1, Mass); + *mat = (*mat - (V2 * V1)) * Mass; ++mat; } } // END loop over vect_1_ diff --git a/src/CoordCovarMatrix_Full.h b/src/CoordCovarMatrix_Full.h index 0a7fc936e7..9e829fc7c8 100644 --- a/src/CoordCovarMatrix_Full.h +++ b/src/CoordCovarMatrix_Full.h @@ -16,16 +16,13 @@ class CoordCovarMatrix_Full : public CoordCovarMatrix { void AddFrameToMatrix(Frame const&, AtomMask const&, Frame const&, AtomMask const&); private: - typedef std::vector Varray; /// Clear the matrix void clearMat(); /// Set up the covariance matrix for selected atoms int setupMat(std::vector const&, AtomMask const&); - Varray vect_1_; ///< Hold average of elements in mask1 - Varray vect_2_; ///< Hold average of elements in mask2 -// Varray vect2_1_; ///< Array of average diagonal elements squared -// Varray vect2_2_; + Darray vect_1_; ///< Hold average of elements in mask1 + Darray vect_2_; ///< Hold average of elements in mask2 Darray mass1_; ///< Hold masses of atoms in mask1 Darray mass2_; ///< Hold masses of atoms in mask2 }; diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 6a72ac7737..83e69fe84c 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -191,7 +191,7 @@ CompactFrameArray.o : CompactFrameArray.cpp Box.h CompactFrameArray.h Coordinate ComplexArray.o : ComplexArray.cpp ArrayIterator.h ComplexArray.h Constraints.o : Constraints.cpp ArgList.h Atom.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 Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.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 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_inData.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h -CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h MaskToken.h Matrix.h Molecule.h NameType.h Parallel.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h +CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h MaskToken.h Matrix.h Molecule.h NameType.h Parallel.h Residue.h Segment.h SymbolExporting.h Unit.h CoordCovarMatrix_Full.o : CoordCovarMatrix_Full.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordinateInfo.h CpptrajStdio.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h CoordCovarMatrix_Half.o : CoordCovarMatrix_Half.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordCovarMatrix_Half.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h CoordinateInfo.o : CoordinateInfo.cpp Box.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h From 46eff187e0d742d25831e29712263387fe46bb67 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 13:30:51 -0400 Subject: [PATCH 029/200] Flip indices to make it more consistent with how the full matrix is processed --- src/Action_Matrix.cpp | 13 ++++++++++++ src/CoordCovarMatrix_Half.cpp | 38 +++++++++++++++++------------------ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/Action_Matrix.cpp b/src/Action_Matrix.cpp index e4192516aa..c074023b85 100644 --- a/src/Action_Matrix.cpp +++ b/src/Action_Matrix.cpp @@ -853,6 +853,10 @@ void Action_Matrix::FinishCovariance(size_t element_size) { double Mass = 1.0; double mass2 = 1.0; + mprintf("DEBUG: First 3 elements: %f %f %f\n", + Mat_->GetElement(0, 0), + Mat_->GetElement(1, 0), + Mat_->GetElement(2, 0)); DataSet_MatrixDbl::iterator mat = Mat_->begin(); // Calc - Vect2MinusVect(); // Is vect2 used? @@ -862,6 +866,14 @@ void Action_Matrix::FinishCovariance(size_t element_size) { M_iterator m2 = mass2_.begin(); // Position for mask2 halfway through vect/vect2 v_iterator v1idx2begin = Mat_->v1begin() + Mat_->Ncols(); + mprintf("DEBUG: First 3 elements of V1: %f %f %f\n", + *(Mat_->v1begin()), + *(Mat_->v1begin() + 1), + *(Mat_->v1begin() + 2)); + mprintf("DEBUG: First 3 elements of V2: %f %f %f\n", + *(v1idx2begin), + *(v1idx2begin + 1), + *(v1idx2begin + 2)); for (v_iterator v1idx2 = v1idx2begin; v1idx2 != Mat_->v1end(); v1idx2 += element_size) { if (Mat_->Meta().ScalarType() == MetaData::MWCOVAR) @@ -874,6 +886,7 @@ void Action_Matrix::FinishCovariance(size_t element_size) { if (Mat_->Meta().ScalarType() == MetaData::MWCOVAR) Mass = sqrt( mass2 * *(m1++) ); for (unsigned int idx = 0; idx < element_size; ++idx) { + mprintf("mat = (%f - (%f * %f)) * %f\n", *mat, Vi, *(v1idx1+idx), Mass); *mat = (*mat - (Vi * *(v1idx1+idx))) * Mass; ++mat; } diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 07dcf3e122..e85210536c 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -35,30 +35,30 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask cons { // Covariance MatType::iterator mat = covarMatrix_.begin(); - for (int idx1 = 0; idx1 < maskIn.Nselected(); idx1++) { - int at1 = maskIn[idx1]; - Vec3 XYZi( frameIn.XYZ(at1) ); - unsigned int eidx1 = idx1 * nelt_; + for (int idx2 = 0; idx2 < maskIn.Nselected(); idx2++) { + int at2 = maskIn[idx2]; + Vec3 XYZj( frameIn.XYZ(at2) ); + unsigned int eidx2 = idx2 * nelt_; // Store average - for (unsigned int ei = 0; ei < nelt_; ei++) - vect_[eidx1+ei] += XYZi[ei]; - //XYZi.Print("XYZi"); + for (unsigned int ej = 0; ej < nelt_; ej++) + vect_[eidx2+ej] += XYZj[ej]; + //XYZj.Print("XYZj"); // Loop over X, Y, and Z of veci - for (unsigned int iidx = 0; iidx < nelt_; iidx++) { - double Vi = XYZi[iidx]; + for (unsigned int jidx = 0; jidx < nelt_; jidx++) { + double Vj = XYZj[jidx]; // Diagonal - for (unsigned int jidx = iidx; jidx < nelt_; jidx++) - *(mat++) += Vi * XYZi[jidx]; // Vi * j{0,1,2}, Vi * j{1,2}, Vi * j{2} + for (unsigned int ej = jidx; ej < nelt_; ej++) + *(mat++) += Vj * XYZj[ej]; // Vj * j{0,1,2}, Vj * j{1,2}, Vj * j{2} // Inner loop - for (int idx2 = idx1 + 1; idx2 < maskIn.Nselected(); idx2++) { - int at2 = maskIn[idx2]; - Vec3 XYZj( frameIn.XYZ(at2) ); - *(mat++) += Vi * XYZj[0]; - *(mat++) += Vi * XYZj[1]; - *(mat++) += Vi * XYZj[2]; - } // END inner loop over idx2 + for (int idx1 = idx2 + 1; idx1 < maskIn.Nselected(); idx1++) { + int at1 = maskIn[idx1]; + Vec3 XYZi( frameIn.XYZ(at1) ); + *(mat++) += Vj * XYZi[0]; + *(mat++) += Vj * XYZi[1]; + *(mat++) += Vj * XYZi[2]; + } // END inner loop over idx1 } // END loop over x y z of veci - } // END outer loop over idx1 + } // END outer loop over idx2 nframes_++; } From 5f9c1f0c164a68e201759eaefbb718e2fa388fed Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 13:37:52 -0400 Subject: [PATCH 030/200] Flip indices --- src/CoordCovarMatrix_Half.cpp | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index e85210536c..6266d36311 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -43,7 +43,7 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask cons for (unsigned int ej = 0; ej < nelt_; ej++) vect_[eidx2+ej] += XYZj[ej]; //XYZj.Print("XYZj"); - // Loop over X, Y, and Z of veci + // Loop over X, Y, and Z of vecj for (unsigned int jidx = 0; jidx < nelt_; jidx++) { double Vj = XYZj[jidx]; // Diagonal @@ -57,7 +57,7 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask cons *(mat++) += Vj * XYZi[1]; *(mat++) += Vj * XYZi[2]; } // END inner loop over idx1 - } // END loop over x y z of veci + } // END loop over x y z of vecj } // END outer loop over idx2 nframes_++; } @@ -111,28 +111,28 @@ int CoordCovarMatrix_Half::FinishMatrix() { //} // Calc - MatType::iterator mat = covarMatrix_.begin(); - for (unsigned int idx1 = 0; idx1 < mass_.size(); idx1++) { - double mass1 = mass_[idx1]; - for (unsigned int iidx = 0; iidx < nelt_; iidx++) { - unsigned int eidx1 = idx1*nelt_; - double Vi = vect_[eidx1 + iidx]; - for (unsigned int idx2 = idx1; idx2 < mass_.size(); idx2++) { - double Mass = sqrt( mass1 * mass_[idx2] ); - if (idx1 == idx2) { + for (unsigned int idx2 = 0; idx2 < mass_.size(); idx2++) { + double mass2 = mass_[idx2]; + for (unsigned int jidx = 0; jidx < nelt_; jidx++) { + unsigned int eidx2 = idx2*nelt_; + double Vj = vect_[eidx2 + jidx]; + for (unsigned int idx1 = idx2; idx1 < mass_.size(); idx1++) { + double Mass = sqrt( mass2 * mass_[idx1] ); + if (idx2 == idx1) { // Self - for (unsigned int jidx = iidx; jidx < nelt_; jidx++) { - *mat = (*mat - (Vi * vect_[eidx1 + jidx])) * Mass; + for (unsigned int ej = jidx; ej < nelt_; ej++) { + *mat = (*mat - (Vj * vect_[eidx2 + ej])) * Mass; ++mat; } } else { - unsigned int eidx2 = idx2*nelt_; - for (unsigned int jidx = 0; jidx < nelt_; jidx++) { - *mat = (*mat - (Vi * vect_[eidx2 + jidx])) * Mass; + unsigned int eidx1 = idx1*nelt_; + for (unsigned int iidx = 0; iidx < nelt_; iidx++) { + *mat = (*mat - (Vj * vect_[eidx1 + iidx])) * Mass; ++mat; } } - } // END inner loop over idx2 - } // END loop over elements of vect_[idx1] - } // END outer loop over idx1 + } // END inner loop over idx1 + } // END loop over elements of vect_[idx2] + } // END outer loop over idx2 return 0; } From 3db5ec6e458f04dae706a6383be53f9b8b0b56d5 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 13:39:59 -0400 Subject: [PATCH 031/200] Use loop over nelt --- src/CoordCovarMatrix_Half.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 6266d36311..aee418bb7f 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -53,9 +53,9 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask cons for (int idx1 = idx2 + 1; idx1 < maskIn.Nselected(); idx1++) { int at1 = maskIn[idx1]; Vec3 XYZi( frameIn.XYZ(at1) ); - *(mat++) += Vj * XYZi[0]; - *(mat++) += Vj * XYZi[1]; - *(mat++) += Vj * XYZi[2]; + for (unsigned int ei = 0; ei < nelt_; ei++) { + *(mat++) += Vj * XYZi[ei]; + } } // END inner loop over idx1 } // END loop over x y z of vecj } // END outer loop over idx2 From 23d8262aab6a4eb35c3bf89b2b2d3744e6ed89dd Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 13:47:22 -0400 Subject: [PATCH 032/200] Put in code for OpenMP indexing but dont enable yet --- src/CoordCovarMatrix_Half.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index aee418bb7f..56ddcdcc2e 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -111,10 +111,13 @@ int CoordCovarMatrix_Half::FinishMatrix() { //} // Calc - MatType::iterator mat = covarMatrix_.begin(); +// double TwoN = (double)( covarMatrix_->Ncols() * 2 ); for (unsigned int idx2 = 0; idx2 < mass_.size(); idx2++) { double mass2 = mass_[idx2]; for (unsigned int jidx = 0; jidx < nelt_; jidx++) { unsigned int eidx2 = idx2*nelt_; +// d_m2_idx = (double)eidx2; +// mat = Mat_->begin() + (int)(0.5*d_m2_idx*(TwoN-d_m2_idx-1.0)+d_m2_idx); double Vj = vect_[eidx2 + jidx]; for (unsigned int idx1 = idx2; idx1 < mass_.size(); idx1++) { double Mass = sqrt( mass2 * mass_[idx1] ); From a6a4d172ab83db1c70a122ac3b2926a755d78201 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 13:52:49 -0400 Subject: [PATCH 033/200] Add function for determining valid array size --- src/CoordCovarMatrix.cpp | 5 +++++ src/CoordCovarMatrix.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index af60fdf508..48dfb1e646 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -46,3 +46,8 @@ void CoordCovarMatrix::DebugPrint(const char* desc, CpptrajFile& outfile) const outfile.Printf("\n"); } } + +/** \return True if incoming array size is divisible by nelt_ */ +bool CoordCovarMatrix::has_valid_size(Darray const& arrayIn) const { + return ( (arrayIn.size() % nelt_) == 0); +} diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 0fd46affe1..d1f2ef8eab 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -31,6 +31,9 @@ class CoordCovarMatrix { /// set mass array void set_mass_array(Darray&, std::vector const&, AtomMask const&, bool); + /// \return True if incoming Darray size is divisible by nelt_ + bool has_valid_size(Darray const&) const; + //private: // TODO all private MatType covarMatrix_; ///< Coordinate covariance matrix From 803d98b579a20bf66eb9f47b87a4a926675d0662 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 14:05:27 -0400 Subject: [PATCH 034/200] Generalize the add elements to matrix routine --- src/CoordCovarMatrix_Half.cpp | 30 ++++++++++++++++++++++++------ src/CoordCovarMatrix_Half.h | 2 ++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 56ddcdcc2e..a906e7a7f3 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -33,12 +33,30 @@ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, /** Add selected atoms in given Frame to the matrix. */ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask const& maskIn) { + Darray arrayIn; // TODO class array? + arrayIn.reserve( maskIn.Nselected() * nelt_ ); + for (AtomMask::const_iterator at = maskIn.begin(); at != maskIn.end(); ++at) { + const double* XYZ = frameIn.XYZ(*at); + arrayIn.push_back( XYZ[0] ); + arrayIn.push_back( XYZ[1] ); + arrayIn.push_back( XYZ[2] ); + } + AddToMatrix(arrayIn); +} + +/** Add elements to the matrix. */ +void CoordCovarMatrix_Half::AddToMatrix(Darray const& arrayIn) { + // sanity check + if (!has_valid_size(arrayIn)) { + mprinterr("Internal Error: CoordCovarMatrix_Half::AddToMatrix(): Incoming array size %zu not divisible by %u\n", + arrayIn.size(), nelt_); + return; + } // Covariance MatType::iterator mat = covarMatrix_.begin(); - for (int idx2 = 0; idx2 < maskIn.Nselected(); idx2++) { - int at2 = maskIn[idx2]; - Vec3 XYZj( frameIn.XYZ(at2) ); + for (unsigned int idx2 = 0; idx2 < mass_.size(); idx2++) { unsigned int eidx2 = idx2 * nelt_; + const double* XYZj = (&arrayIn[0]) + eidx2; // Store average for (unsigned int ej = 0; ej < nelt_; ej++) vect_[eidx2+ej] += XYZj[ej]; @@ -50,9 +68,9 @@ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask cons for (unsigned int ej = jidx; ej < nelt_; ej++) *(mat++) += Vj * XYZj[ej]; // Vj * j{0,1,2}, Vj * j{1,2}, Vj * j{2} // Inner loop - for (int idx1 = idx2 + 1; idx1 < maskIn.Nselected(); idx1++) { - int at1 = maskIn[idx1]; - Vec3 XYZi( frameIn.XYZ(at1) ); + for (unsigned int idx1 = idx2 + 1; idx1 < mass_.size(); idx1++) { + unsigned int eidx1 = idx1 * nelt_; + const double* XYZi = (&arrayIn[0]) + eidx1; for (unsigned int ei = 0; ei < nelt_; ei++) { *(mat++) += Vj * XYZi[ei]; } diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index 976cdccb91..0bd6f90cfd 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -18,6 +18,8 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { /// Add Frame to matrix //void AddFrameToMatrix(Frame const&); private: + /// Add elements to the matrix + void AddToMatrix(Darray const&); /// Clear the matrix void clearMat(); From 74836ec6b852eaca7e0627ea65bfa7ed60f006cf Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 14:37:45 -0400 Subject: [PATCH 035/200] Generalize the full matrix. Fix up depends. Put common functionality in CoordCovarMatrix. --- src/CoordCovarMatrix.cpp | 15 +++++++++++ src/CoordCovarMatrix.h | 3 +++ src/CoordCovarMatrix_Full.cpp | 49 ++++++++++++++++++++++++++++------- src/CoordCovarMatrix_Full.h | 3 ++- src/CoordCovarMatrix_Half.cpp | 10 +------ src/CoordCovarMatrix_Half.h | 1 - src/cpptrajdepend | 6 ++--- 7 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index 48dfb1e646..6fdc3c8252 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -3,6 +3,7 @@ #include "AtomMask.h" #include "CpptrajFile.h" #include "CpptrajStdio.h" +#include "Frame.h" /** CONSTRUCTOR - number of elements */ CoordCovarMatrix::CoordCovarMatrix(unsigned int nelt) : @@ -51,3 +52,17 @@ void CoordCovarMatrix::DebugPrint(const char* desc, CpptrajFile& outfile) const bool CoordCovarMatrix::has_valid_size(Darray const& arrayIn) const { return ( (arrayIn.size() % nelt_) == 0); } + +/** Extract coordinates from given Frame into specified array. */ +void CoordCovarMatrix::get_frame_coords(Darray& arrayIn, Frame const& frameIn, AtomMask const& maskIn) +const +{ + arrayIn.clear(); + arrayIn.reserve( maskIn.Nselected() * nelt_ ); + for (AtomMask::const_iterator at = maskIn.begin(); at != maskIn.end(); ++at) { + const double* XYZ = frameIn.XYZ(*at); + arrayIn.push_back( XYZ[0] ); + arrayIn.push_back( XYZ[1] ); + arrayIn.push_back( XYZ[2] ); + } +} diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index d1f2ef8eab..7dc275b75b 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -5,6 +5,7 @@ class Atom; class AtomMask; class CpptrajFile; +class Frame; /// Coordinate covariance matrix abstract base class class CoordCovarMatrix { public: @@ -34,6 +35,8 @@ class CoordCovarMatrix { /// \return True if incoming Darray size is divisible by nelt_ bool has_valid_size(Darray const&) const; + /// Place coordinates from selected atoms in Frame into an array + void get_frame_coords(Darray&, Frame const&, AtomMask const&) const; //private: // TODO all private MatType covarMatrix_; ///< Coordinate covariance matrix diff --git a/src/CoordCovarMatrix_Full.cpp b/src/CoordCovarMatrix_Full.cpp index 1cffd04907..b74abf97ac 100644 --- a/src/CoordCovarMatrix_Full.cpp +++ b/src/CoordCovarMatrix_Full.cpp @@ -1,7 +1,7 @@ #include "CoordCovarMatrix_Full.h" #include "AtomMask.h" #include "CpptrajStdio.h" -#include "Frame.h" +#include //sqrt /** CONSTRUCTOR */ CoordCovarMatrix_Full::CoordCovarMatrix_Full() : @@ -34,7 +34,7 @@ int CoordCovarMatrix_Full::SetupMatrix(std::vector const& atoms1, } /** Store diagonal (average and average^2) */ -static inline void store_diagonal(std::vector& vect, +/*static inline void store_diagonal(std::vector& vect, // std::vector& vect2, unsigned int nelt, Frame const& frameIn, @@ -49,22 +49,51 @@ static inline void store_diagonal(std::vector& vect, // vect2[idx][ii] += (XYZ[ii] * XYZ[ii]); } } +}*/ + +/** Store average */ +static inline void store_diagonal(std::vector& vect, std::vector const& arrayIn) +{ + for (unsigned int idx = 0; idx < arrayIn.size(); ++idx) + vect[idx] += arrayIn[idx]; } /** Add selected atoms in given Frames to the matrix. */ void CoordCovarMatrix_Full::AddFrameToMatrix(Frame const& frameIn1, AtomMask const& maskIn1, Frame const& frameIn2, AtomMask const& maskIn2) { + Darray array1, array2; + get_frame_coords(array1, frameIn1, maskIn1); + get_frame_coords(array2, frameIn2, maskIn2); + AddToMatrix(array1, array2); +} + +/** Add elements to the matrix. */ +void CoordCovarMatrix_Full::AddToMatrix(Darray const& array1, Darray const& array2) { + // sanity checks + if (!has_valid_size(array1)) { + mprinterr("Internal Error: CoordCovarMatrix_Full::AddToMatrix(): Incoming array1 size %zu not divisible by %u\n", + array1.size(), nelt_); + return; + } + if (!has_valid_size(array2)) { + mprinterr("Internal Error: CoordCovarMatrix_Full::AddToMatrix(): Incoming array2 size %zu not divisible by %u\n", + array2.size(), nelt_); + return; + } + //MatType::iterator mat = covarMatrix_.begin(); - for (int idx2 = 0; idx2 < maskIn2.Nselected(); idx2++) + for (unsigned int idx2 = 0; idx2 < mass2_.size(); idx2++) { - Matrix::iterator mat = covarMatrix_.begin() + ((idx2*nelt_)*covarMatrix_.Ncols()); // NX - const double* XYZj = frameIn2.XYZ( maskIn2[idx2] ); + unsigned int eidx2 = idx2 * nelt_; + Matrix::iterator mat = covarMatrix_.begin() + (eidx2*covarMatrix_.Ncols()); // NX + const double* XYZj = (&array2[0]) + eidx2; for (unsigned int ny = 0; ny < nelt_; ny++) { double Vj = XYZj[ny]; - for (int idx1 = 0; idx1 < maskIn1.Nselected(); idx1++) + for (unsigned int idx1 = 0; idx1 < mass1_.size(); idx1++) { - const double* XYZi = frameIn1.XYZ( maskIn1[idx1] ); + unsigned int eidx1 = idx1 * nelt_; + const double* XYZi = (&array1[0]) + eidx1; for (unsigned int nx = 0; nx < nelt_; nx++) { *(mat++) += Vj * XYZi[nx]; } @@ -74,8 +103,10 @@ void CoordCovarMatrix_Full::AddFrameToMatrix(Frame const& frameIn1, AtomMask con // Mask1/mask2 diagonal // store_diagonal(vect_1_, vect2_1_, frameIn1, maskIn1); // store_diagonal(vect_2_, vect2_2_, frameIn2, maskIn2); - store_diagonal(vect_1_, nelt_, frameIn1, maskIn1); - store_diagonal(vect_2_, nelt_, frameIn2, maskIn2); +// store_diagonal(vect_1_, nelt_, frameIn1, maskIn1); +// store_diagonal(vect_2_, nelt_, frameIn2, maskIn2); + store_diagonal(vect_1_, array1); + store_diagonal(vect_2_, array2); nframes_++; } diff --git a/src/CoordCovarMatrix_Full.h b/src/CoordCovarMatrix_Full.h index 9e829fc7c8..f115a07034 100644 --- a/src/CoordCovarMatrix_Full.h +++ b/src/CoordCovarMatrix_Full.h @@ -1,7 +1,6 @@ #ifndef INC_COORDCOVARMATRIX_FULL_H #define INC_COORDCOVARMATRIX_FULL_H #include "CoordCovarMatrix.h" -class Frame; /// Coordinate covanriance full matrix class CoordCovarMatrix_Full : public CoordCovarMatrix { public: @@ -20,6 +19,8 @@ class CoordCovarMatrix_Full : public CoordCovarMatrix { void clearMat(); /// Set up the covariance matrix for selected atoms int setupMat(std::vector const&, AtomMask const&); + /// Add elements to the matrix + void AddToMatrix(Darray const&, Darray const&); Darray vect_1_; ///< Hold average of elements in mask1 Darray vect_2_; ///< Hold average of elements in mask2 diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index a906e7a7f3..f8998ab5d0 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -1,8 +1,6 @@ #include "CoordCovarMatrix_Half.h" #include "AtomMask.h" -#include "CpptrajFile.h" #include "CpptrajStdio.h" -#include "Frame.h" #include // sqrt /** CONSTRUCTOR */ @@ -34,13 +32,7 @@ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask const& maskIn) { Darray arrayIn; // TODO class array? - arrayIn.reserve( maskIn.Nselected() * nelt_ ); - for (AtomMask::const_iterator at = maskIn.begin(); at != maskIn.end(); ++at) { - const double* XYZ = frameIn.XYZ(*at); - arrayIn.push_back( XYZ[0] ); - arrayIn.push_back( XYZ[1] ); - arrayIn.push_back( XYZ[2] ); - } + get_frame_coords(arrayIn, frameIn, maskIn); AddToMatrix(arrayIn); } diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index 0bd6f90cfd..556e7ed7f8 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -1,7 +1,6 @@ #ifndef INC_COORDCOVARMATRIX_HALF_H #define INC_COORDCOVARMATRIX_HALF_H #include "CoordCovarMatrix.h" -class Frame; /// Coordinate covariance half (self) matrix class CoordCovarMatrix_Half : public CoordCovarMatrix { public: diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 83e69fe84c..d7f95cbf58 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -191,9 +191,9 @@ CompactFrameArray.o : CompactFrameArray.cpp Box.h CompactFrameArray.h Coordinate ComplexArray.o : ComplexArray.cpp ArrayIterator.h ComplexArray.h Constraints.o : Constraints.cpp ArgList.h Atom.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 Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.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 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_inData.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h -CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h MaskToken.h Matrix.h Molecule.h NameType.h Parallel.h Residue.h Segment.h SymbolExporting.h Unit.h -CoordCovarMatrix_Full.o : CoordCovarMatrix_Full.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordinateInfo.h CpptrajStdio.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h -CoordCovarMatrix_Half.o : CoordCovarMatrix_Half.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordCovarMatrix_Half.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h +CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h +CoordCovarMatrix_Full.o : CoordCovarMatrix_Full.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CpptrajStdio.h MaskToken.h Matrix.h Molecule.h NameType.h Residue.h Segment.h SymbolExporting.h Unit.h +CoordCovarMatrix_Half.o : CoordCovarMatrix_Half.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CoordCovarMatrix_Half.h CpptrajStdio.h MaskToken.h Matrix.h Molecule.h NameType.h Residue.h Segment.h SymbolExporting.h Unit.h CoordinateInfo.o : CoordinateInfo.cpp Box.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h Corr.o : Corr.cpp ArrayIterator.h ComplexArray.h Corr.h PubFFT.h Cph.o : Cph.cpp Cph.h NameType.h From 0b2aa6b49c57287f287ecdf2f00ba5e28eced625 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 14:39:05 -0400 Subject: [PATCH 036/200] Add note --- src/CoordCovarMatrix_Full.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CoordCovarMatrix_Full.cpp b/src/CoordCovarMatrix_Full.cpp index b74abf97ac..4fcbcfaa90 100644 --- a/src/CoordCovarMatrix_Full.cpp +++ b/src/CoordCovarMatrix_Full.cpp @@ -62,7 +62,7 @@ static inline void store_diagonal(std::vector& vect, std::vector void CoordCovarMatrix_Full::AddFrameToMatrix(Frame const& frameIn1, AtomMask const& maskIn1, Frame const& frameIn2, AtomMask const& maskIn2) { - Darray array1, array2; + Darray array1, array2; // TODO make class vars get_frame_coords(array1, frameIn1, maskIn1); get_frame_coords(array2, frameIn2, maskIn2); AddToMatrix(array1, array2); From 64fc6b0b065ba1613549e2217b50fff912c2d9f2 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 14:42:00 -0400 Subject: [PATCH 037/200] Have setup routine set nelt --- src/CoordCovarMatrix.cpp | 4 ++-- src/CoordCovarMatrix.h | 4 ++-- src/CoordCovarMatrix_Full.cpp | 4 ++-- src/CoordCovarMatrix_Half.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index 6fdc3c8252..d9b051d0d8 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -6,9 +6,9 @@ #include "Frame.h" /** CONSTRUCTOR - number of elements */ -CoordCovarMatrix::CoordCovarMatrix(unsigned int nelt) : +CoordCovarMatrix::CoordCovarMatrix() : nframes_(0), - nelt_(nelt), + nelt_(0), useMass_(false) {} diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 7dc275b75b..0a3c5a381e 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -9,8 +9,8 @@ class Frame; /// Coordinate covariance matrix abstract base class class CoordCovarMatrix { public: - /// CONSTRUCTOR - number of elements - CoordCovarMatrix(unsigned int); + /// CONSTRUCTOR + CoordCovarMatrix(); /// DESTRUCTOR - virtual since inherited virtual ~CoordCovarMatrix() {} // --------------------------------- diff --git a/src/CoordCovarMatrix_Full.cpp b/src/CoordCovarMatrix_Full.cpp index 4fcbcfaa90..51e4ac0bb8 100644 --- a/src/CoordCovarMatrix_Full.cpp +++ b/src/CoordCovarMatrix_Full.cpp @@ -4,8 +4,7 @@ #include //sqrt /** CONSTRUCTOR */ -CoordCovarMatrix_Full::CoordCovarMatrix_Full() : - CoordCovarMatrix(3) +CoordCovarMatrix_Full::CoordCovarMatrix_Full() {} /** Clear the matrix */ @@ -22,6 +21,7 @@ int CoordCovarMatrix_Full::SetupMatrix(std::vector const& atoms1, std::vector const& atoms2, AtomMask const& maskIn2, bool useMassIn) { + nelt_ = 3; // xyz // Matrix - full covarMatrix_.resize( maskIn1.Nselected()*nelt_, maskIn2.Nselected()*nelt_ ); diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index f8998ab5d0..b586c817f9 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -4,8 +4,7 @@ #include // sqrt /** CONSTRUCTOR */ -CoordCovarMatrix_Half::CoordCovarMatrix_Half() : - CoordCovarMatrix(3) +CoordCovarMatrix_Half::CoordCovarMatrix_Half() {} /** Clear the matrix */ @@ -18,6 +17,7 @@ void CoordCovarMatrix_Half::clearMat() { int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, AtomMask const& maskIn, bool useMassIn) { + nelt_ = 3; // xyz // Matrix - half covarMatrix_.resize( maskIn.Nselected()*nelt_, 0 ); From ec633ba86059159f1afad698ac9e44c22f4829f5 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 29 Mar 2024 14:45:45 -0400 Subject: [PATCH 038/200] Add note about debug info --- src/Action_Matrix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Action_Matrix.cpp b/src/Action_Matrix.cpp index c074023b85..aa9c9e4a87 100644 --- a/src/Action_Matrix.cpp +++ b/src/Action_Matrix.cpp @@ -886,7 +886,7 @@ void Action_Matrix::FinishCovariance(size_t element_size) { if (Mat_->Meta().ScalarType() == MetaData::MWCOVAR) Mass = sqrt( mass2 * *(m1++) ); for (unsigned int idx = 0; idx < element_size; ++idx) { - mprintf("mat = (%f - (%f * %f)) * %f\n", *mat, Vi, *(v1idx1+idx), Mass); + mprintf("mat = (%f - (%f * %f)) * %f\n", *mat, Vi, *(v1idx1+idx), Mass); // DEBUG *mat = (*mat - (Vi * *(v1idx1+idx))) * Mass; ++mat; } From 759a220ba505b727a282d448d2875d871356f4f3 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 14:19:06 -0400 Subject: [PATCH 039/200] Start new function --- src/CoordCovarMatrix_Half.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index b586c817f9..f424c1adaf 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -13,6 +13,8 @@ void CoordCovarMatrix_Half::clearMat() { mass_.clear(); } +/** Set up array for incoming data sets. */ + /** Set up array sizess and masses. */ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, AtomMask const& maskIn, bool useMassIn) From b1c00d45d9abc0eb8c5e201ad8a647cc5298e124 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 14:30:54 -0400 Subject: [PATCH 040/200] Start minmaxdist action --- src/Action_MinMaxDist.cpp | 50 +++++++++++++++++++++++++++++++++++++++ src/Action_MinMaxDist.h | 19 +++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/Action_MinMaxDist.cpp create mode 100644 src/Action_MinMaxDist.h diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp new file mode 100644 index 0000000000..4539f67630 --- /dev/null +++ b/src/Action_MinMaxDist.cpp @@ -0,0 +1,50 @@ +#include "Action_MinMaxDist.h" +#include "CpptrajStdio.h" + +// Action_MinMaxDist::Help() +void Action_MinMaxDist::Help() const { + mprintf("mask1 [mask2 ]\n" + " Record the min/max distance between atoms/residues/molecules.\n" + ); +} + +// Action_MinMaxDist::Init() +Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, int debugIn) +{ + std::string mask1str = actionArgs.GetStringKey("mask1"); + if (mask1str.empty()) { + mprinterr("Error: Must specify at least 'mask1'\n"); + return Action::ERR; + } + if (mask1_.SetMaskString( mask1str )) { + mprinterr("Error: Could not set mask1 '%s'\n", mask1str._c_str()); + return Action::ERR; + } + std::string mask2str = actionArgs.GetStringKey("mask2"); + if (!mask2str.empty()) { + if (mask2_.SetMaskString( mask2str )) { + mprinterr("Error: Could not set mask2 '%s'\n", mask2str.c_str()); + return Action::ERR; + } + } + + mprintf(" MINMAXDIST:\n"); + mprintf("\tMask1: %s\n", mask1_.MaskString()); + if (mask2_.MaskStringSet()) { + mprintf("\tMask2: %s\n", mask2_.MaskString()); + } + + return Action::OK; +} + +// Action_MinMaxDist::Setup() +Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) +{ + +} + +// Action_MinMaxDist::DoAction() +Action::RetType Action_MinMaxDist::DoAction(int frameNum, ActionFrame& frm) +{ + +} diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h new file mode 100644 index 0000000000..9dd22f1ca2 --- /dev/null +++ b/src/Action_MinMaxDist.h @@ -0,0 +1,19 @@ +#ifndef INC_ACTION_MINMAXDIST_H +#define INC_ACTION_MINMAXDIST_H +#include "Action.h" +/// Record the min/max distance between atoms/residues/molecules +class Action_MinMaxDist : public Action { + public: + Action_MinMaxDist() {} + DispatchObject* Alloc() const { return (DispatchObject*)new Action_MinMaxDist(); } + void Help() const; + private: + Action::RetType Init(ArgList&, ActionInit&, int); + Action::RetType Setup(ActionSetup&); + Action::RetType DoAction(int, ActionFrame&); + void Print() {} + + AtomMask mask1_; + AtomMask mask2_; +}; +#endif From c0041cff43ac28283b2074ed868a0c1bc5ec4780 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 14:41:18 -0400 Subject: [PATCH 041/200] Add mode and distance type --- src/Action_MinMaxDist.cpp | 43 +++++++++++++++++++++++++++++++++++---- src/Action_MinMaxDist.h | 13 +++++++++++- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 4539f67630..24646647b8 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -1,6 +1,26 @@ #include "Action_MinMaxDist.h" #include "CpptrajStdio.h" +/** CONSTRUCTOR */ +Action_MinMaxDist::Action_MinMaxDist() : + mode_(NO_MODE), + distType_(NO_DIST) +{} + +const char* Action_MinMaxDist::modeStr_[] = { + "atoms", + "residues", + "molecules", + 0 +}; + +const char* Action_MinMaxDist::distTypeStr_[] = { + "minimum", + "maximum", + "minimum and maximum", + 0 +}; + // Action_MinMaxDist::Help() void Action_MinMaxDist::Help() const { mprintf("mask1 [mask2 ]\n" @@ -17,7 +37,7 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i return Action::ERR; } if (mask1_.SetMaskString( mask1str )) { - mprinterr("Error: Could not set mask1 '%s'\n", mask1str._c_str()); + mprinterr("Error: Could not set mask1 '%s'\n", mask1str.c_str()); return Action::ERR; } std::string mask2str = actionArgs.GetStringKey("mask2"); @@ -27,8 +47,22 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i return Action::ERR; } } + // Default mode and distance + if (mode_ == NO_MODE) + mode_ = BY_ATOM; + if (distType_ == NO_DIST) { + if (actionArgs[0] == "mindist") + distType_ = MIN_DIST; + else if (actionArgs[0] == "maxdist") + distType_ = MAX_DIST; + else { + mprintf("Warning: No distance type specified and command name '%s' unrecognized. Using default.\n"); + distType_ = MIN_DIST; + } + } - mprintf(" MINMAXDIST:\n"); + mprintf(" MINMAXDIST: Calculating %s distance for selected %s\n", + distTypeStr_[distType_], modeStr_[mode_]); mprintf("\tMask1: %s\n", mask1_.MaskString()); if (mask2_.MaskStringSet()) { mprintf("\tMask2: %s\n", mask2_.MaskString()); @@ -40,11 +74,12 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i // Action_MinMaxDist::Setup() Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) { - + + return Action::OK; } // Action_MinMaxDist::DoAction() Action::RetType Action_MinMaxDist::DoAction(int frameNum, ActionFrame& frm) { - + return Action::OK; } diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index 9dd22f1ca2..6e107a27ce 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -4,10 +4,19 @@ /// Record the min/max distance between atoms/residues/molecules class Action_MinMaxDist : public Action { public: - Action_MinMaxDist() {} + /// CONSTRUCTOR + Action_MinMaxDist(); + /// ALLOCATOR DispatchObject* Alloc() const { return (DispatchObject*)new Action_MinMaxDist(); } + /// HELP void Help() const; private: + enum ModeType {BY_ATOM = 0, BY_RES, BY_MOL, NO_MODE}; + enum DistType { MIN_DIST = 0, MAX_DIST, BOTH_DIST, NO_DIST }; + + static const char* modeStr_[]; + static const char* distTypeStr_[]; + Action::RetType Init(ArgList&, ActionInit&, int); Action::RetType Setup(ActionSetup&); Action::RetType DoAction(int, ActionFrame&); @@ -15,5 +24,7 @@ class Action_MinMaxDist : public Action { AtomMask mask1_; AtomMask mask2_; + ModeType mode_; + DistType distType_; }; #endif From eb9359c5899bcfdabdfa97d68a8066f685c01045 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 14:51:31 -0400 Subject: [PATCH 042/200] Enable command, remove mindist from deprecated. Add distance and mode args. --- src/Action_MinMaxDist.cpp | 26 +++++++++++++++++++++----- src/Command.cpp | 3 ++- src/Deprecated.cpp | 4 ---- src/Deprecated.h | 1 - src/cpptrajdepend | 3 ++- src/cpptrajfiles | 1 + 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 24646647b8..aa09b83c81 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -23,7 +23,8 @@ const char* Action_MinMaxDist::distTypeStr_[] = { // Action_MinMaxDist::Help() void Action_MinMaxDist::Help() const { - mprintf("mask1 [mask2 ]\n" + mprintf("\tmask1 [mask2 ] [{byatom|byres|bymol}]\n" + "\t[mindist] [maxdist] [bothdist]\n" " Record the min/max distance between atoms/residues/molecules.\n" ); } @@ -47,13 +48,28 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i return Action::ERR; } } - // Default mode and distance + // Mode args + if (actionArgs.hasKey("byatom")) + mode_ = BY_ATOM; + else if (actionArgs.hasKey("byres")) + mode_ = BY_RES; + else if (actionArgs.hasKey("bymol")) + mode_ = BY_MOL; + // Distance calc type args + bool calc_mindist = (actionArgs.hasKey("mindist") || (actionArgs[0] == "mindist")); + bool calc_maxdist = (actionArgs.hasKey("maxdist") || (actionArgs[0] == "maxdist")); + if (actionArgs.hasKey("bothdist")) + distType_ = BOTH_DIST; + // Default mode if (mode_ == NO_MODE) mode_ = BY_ATOM; + // Default distance calc type if (distType_ == NO_DIST) { - if (actionArgs[0] == "mindist") + if (calc_mindist && calc_maxdist) + distType_ = BOTH_DIST; + else if (calc_mindist) distType_ = MIN_DIST; - else if (actionArgs[0] == "maxdist") + else if (calc_maxdist) distType_ = MAX_DIST; else { mprintf("Warning: No distance type specified and command name '%s' unrecognized. Using default.\n"); @@ -61,7 +77,7 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i } } - mprintf(" MINMAXDIST: Calculating %s distance for selected %s\n", + mprintf(" MINMAXDIST: Calculating %s distance for selected %s.\n", distTypeStr_[distType_], modeStr_[mode_]); mprintf("\tMask1: %s\n", mask1_.MaskString()); if (mask2_.MaskStringSet()) { diff --git a/src/Command.cpp b/src/Command.cpp index e098f8c9bd..34833a9a1d 100644 --- a/src/Command.cpp +++ b/src/Command.cpp @@ -162,6 +162,7 @@ #include "Action_Keep.h" #include "Action_AvgBox.h" #include "Action_ToroidalDiffusion.h" +#include "Action_MinMaxDist.h" // ----- ANALYSIS -------------------------------------------------------------- #include "Analysis_Hist.h" #include "Analysis_Corr.h" @@ -362,6 +363,7 @@ void Command::Init() { Command::AddCmd( new Action_MakeStructure(), Cmd::ACT, 1, "makestructure" ); Command::AddCmd( new Action_Mask(), Cmd::ACT, 1, "mask" ); Command::AddCmd( new Action_Matrix(), Cmd::ACT, 1, "matrix" ); + Command::AddCmd( new Action_MinMaxDist(), Cmd::ACT, 2, "mindist", "maxdist" ); Command::AddCmd( new Action_MinImage(), Cmd::ACT, 1, "minimage" ); Command::AddCmd( new Action_Molsurf(), Cmd::ACT, 1, "molsurf" ); Command::AddCmd( new Action_MultiDihedral(), Cmd::ACT, 1, "multidihedral" ); @@ -455,7 +457,6 @@ void Command::Init() { Command::AddCmd( new Deprecated_AvgCoord(), Cmd::DEP, 1, "avgcoord" ); Command::AddCmd( new Deprecated_DihScan(), Cmd::DEP, 1, "dihedralscan" ); Command::AddCmd( new Deprecated_Hbond(), Cmd::DEP, 2, "acceptor", "donor" ); - Command::AddCmd( new Deprecated_MinDist(), Cmd::DEP, 2, "mindist", "maxdist" ); Command::AddCmd( new Deprecated_ParmBondInfo(),Cmd::DEP, 1, "parmbondinfo" ); Command::AddCmd( new Deprecated_ParmMolInfo(), Cmd::DEP, 1, "parmmolinfo" ); Command::AddCmd( new Deprecated_ParmResInfo(), Cmd::DEP, 1, "parmresinfo" ); diff --git a/src/Deprecated.cpp b/src/Deprecated.cpp index 012f810b56..fa8496e006 100644 --- a/src/Deprecated.cpp +++ b/src/Deprecated.cpp @@ -1,10 +1,6 @@ #include "Deprecated.h" #include "CpptrajStdio.h" -void Deprecated_MinDist::Help() const { - mprinterr(" Use the 'nativecontacts' action instead.\n"); -} - void Deprecated_Hbond::Help() const { mprinterr(" Hydrogen bond acceptors and donors are defined within the 'hbond' action.\n"); } diff --git a/src/Deprecated.h b/src/Deprecated.h index 9d8dab7732..a0cce51ba9 100644 --- a/src/Deprecated.h +++ b/src/Deprecated.h @@ -8,7 +8,6 @@ class Deprecated : public DispatchObject { DispatchObject* Alloc() const { return 0; } }; -class Deprecated_MinDist : public Deprecated { public: void Help() const; }; class Deprecated_Hbond : public Deprecated { public: void Help() const; }; class Deprecated_TopSearch : public Deprecated { public: void Help() const; }; class Deprecated_ParmBondInfo : public Deprecated { public: void Help() const; }; diff --git a/src/cpptrajdepend b/src/cpptrajdepend index d7f95cbf58..2543115f19 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -50,6 +50,7 @@ Action_MakeStructure.o : Action_MakeStructure.cpp Action.h ActionState.h Action_ Action_Mask.o : Action_Mask.cpp Action.h ActionFrameCounter.h ActionState.h Action_Mask.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h Action_Matrix.o : Action_Matrix.cpp Action.h ActionFrameCounter.h ActionState.h Action_Matrix.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.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_1D.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Vector.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_MinImage.o : Action_MinImage.cpp Action.h ActionState.h Action_MinImage.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Action_MinMaxDist.o : Action_MinMaxDist.cpp Action.h ActionState.h Action_MinMaxDist.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_Molsurf.o : Action_Molsurf.cpp Action.h ActionState.h Action_Molsurf.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h molsurf.h Action_MultiDihedral.o : Action_MultiDihedral.cpp Action.h ActionState.h Action_MultiDihedral.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_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h DihedralSearch.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 StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h Action_MultiPucker.o : Action_MultiPucker.cpp Action.h ActionState.h Action_MultiPucker.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 Pucker.h Pucker_PuckerMask.h Pucker_PuckerSearch.h Pucker_PuckerToken.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h @@ -186,7 +187,7 @@ ClusterMap.o : ClusterMap.cpp AssociatedData.h ClusterMap.h Constants.h CpptrajF 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 ActionTopWriter.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_AvgBox.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_Keep.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_MultiPucker.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_ToroidalDiffusion.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_CalcDiffusion.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_TICA.h Analysis_Timecorr.h Analysis_VectorMath.h Analysis_Wavelet.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMap.h AtomMask.h AtomType.h AxisType.h BaseIOtype.h Box.h BoxArgs.h BufferedLine.h CharMask.h Cluster/Algorithm.h Cluster/BestReps.h Cluster/CentroidArray.h Cluster/Cframes.h Cluster/Control.h Cluster/DrawGraph.h Cluster/List.h Cluster/Metric.h Cluster/MetricArray.h Cluster/Node.h Cluster/Sieve.h Cluster/Silhouette.h ClusterMap.h Cmd.h CmdInput.h CmdList.h Command.h CompactFrameArray.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 DataFilter.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h DataSet_GridFlt.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 DiffusionResults.h DihedralSearch.h Dimension.h DispatchObject.h Energy.h Energy_Sander.h EnsembleIn.h EnsembleOutList.h Ewald.h EwaldOptions.h Ewald_ParticleMesh.h ExclusionArray.h Exec.h Exec_AddMissingRes.h Exec_Analyze.h Exec_Calc.h Exec_CatCrd.h Exec_Change.h Exec_ClusterMap.h Exec_CombineCoords.h Exec_Commands.h Exec_CompareClusters.h Exec_CompareEnergy.h Exec_CompareTop.h Exec_CrdAction.h Exec_CrdOut.h Exec_CrdTransform.h Exec_CreateSet.h Exec_DataFile.h Exec_DataFilter.h Exec_DataSetCmd.h Exec_Emin.h Exec_ExtendedComparison.h Exec_Flatten.h Exec_GenerateAmberRst.h Exec_Graft.h Exec_Help.h Exec_HmassRepartition.h Exec_LoadCrd.h Exec_LoadTraj.h Exec_ParallelAnalysis.h Exec_ParmBox.h Exec_ParmSolvent.h Exec_ParmStrip.h Exec_ParmWrite.h Exec_ParseTiming.h Exec_PermuteDihedrals.h Exec_Precision.h Exec_PrepareForLeap.h Exec_PrintData.h Exec_Random.h Exec_ReadData.h Exec_ReadEnsembleData.h Exec_ReadInput.h Exec_RotateDihedral.h Exec_RunAnalysis.h Exec_ScaleDihedralK.h Exec_Sequence.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 Exec_Zmatrix.h ExtendedSimilarity.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h GIST_PME.h Grid.h GridAction.h GridBin.h GridMover.h HistBin.h Hungarian.h ImageOption.h ImageTypes.h InputTrajCommon.h MapAtom.h MaskArray.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Routines.h NameType.h NetcdfFile.h OnlineVarT.h OutputTrajCommon.h PDBfile.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h PubFFT.h Pucker.h Pucker_PuckerMask.h Pucker_PuckerSearch.h Pucker_PuckerToken.h RPNcalc.h Random.h Range.h ReferenceAction.h ReferenceFrame.h RemdReservoirNC.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.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 Unit.h Vec3.h cuda_kernels/GistCudaSetup.cuh helpme_standalone.h molsurf.h +Command.o : Command.cpp Action.h ActionFrameCounter.h ActionList.h ActionState.h ActionTopWriter.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_AvgBox.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_Keep.h Action_LESsplit.h Action_LIE.h Action_LipidOrder.h Action_MakeStructure.h Action_Mask.h Action_Matrix.h Action_MinImage.h Action_MinMaxDist.h Action_Molsurf.h Action_MultiDihedral.h Action_MultiPucker.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_ToroidalDiffusion.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_CalcDiffusion.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_TICA.h Analysis_Timecorr.h Analysis_VectorMath.h Analysis_Wavelet.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMap.h AtomMask.h AtomType.h AxisType.h BaseIOtype.h Box.h BoxArgs.h BufferedLine.h CharMask.h Cluster/Algorithm.h Cluster/BestReps.h Cluster/CentroidArray.h Cluster/Cframes.h Cluster/Control.h Cluster/DrawGraph.h Cluster/List.h Cluster/Metric.h Cluster/MetricArray.h Cluster/Node.h Cluster/Sieve.h Cluster/Silhouette.h ClusterMap.h Cmd.h CmdInput.h CmdList.h Command.h CompactFrameArray.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 DataFilter.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h DataSet_GridFlt.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 DiffusionResults.h DihedralSearch.h Dimension.h DispatchObject.h Energy.h Energy_Sander.h EnsembleIn.h EnsembleOutList.h Ewald.h EwaldOptions.h Ewald_ParticleMesh.h ExclusionArray.h Exec.h Exec_AddMissingRes.h Exec_Analyze.h Exec_Calc.h Exec_CatCrd.h Exec_Change.h Exec_ClusterMap.h Exec_CombineCoords.h Exec_Commands.h Exec_CompareClusters.h Exec_CompareEnergy.h Exec_CompareTop.h Exec_CrdAction.h Exec_CrdOut.h Exec_CrdTransform.h Exec_CreateSet.h Exec_DataFile.h Exec_DataFilter.h Exec_DataSetCmd.h Exec_Emin.h Exec_ExtendedComparison.h Exec_Flatten.h Exec_GenerateAmberRst.h Exec_Graft.h Exec_Help.h Exec_HmassRepartition.h Exec_LoadCrd.h Exec_LoadTraj.h Exec_ParallelAnalysis.h Exec_ParmBox.h Exec_ParmSolvent.h Exec_ParmStrip.h Exec_ParmWrite.h Exec_ParseTiming.h Exec_PermuteDihedrals.h Exec_Precision.h Exec_PrepareForLeap.h Exec_PrintData.h Exec_Random.h Exec_ReadData.h Exec_ReadEnsembleData.h Exec_ReadInput.h Exec_RotateDihedral.h Exec_RunAnalysis.h Exec_ScaleDihedralK.h Exec_Sequence.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 Exec_Zmatrix.h ExtendedSimilarity.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h GIST_PME.h Grid.h GridAction.h GridBin.h GridMover.h HistBin.h Hungarian.h ImageOption.h ImageTypes.h InputTrajCommon.h MapAtom.h MaskArray.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Routines.h NameType.h NetcdfFile.h OnlineVarT.h OutputTrajCommon.h PDBfile.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h PubFFT.h Pucker.h Pucker_PuckerMask.h Pucker_PuckerSearch.h Pucker_PuckerToken.h RPNcalc.h Random.h Range.h ReferenceAction.h ReferenceFrame.h RemdReservoirNC.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.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 Unit.h Vec3.h cuda_kernels/GistCudaSetup.cuh helpme_standalone.h molsurf.h CompactFrameArray.o : CompactFrameArray.cpp Box.h CompactFrameArray.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h ComplexArray.o : ComplexArray.cpp ArrayIterator.h ComplexArray.h Constraints.o : Constraints.cpp ArgList.h Atom.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 Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.h Vec3.h diff --git a/src/cpptrajfiles b/src/cpptrajfiles index e23ae3783c..6699545b9b 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -52,6 +52,7 @@ COMMON_SOURCES= \ Action_MakeStructure.cpp \ Action_Mask.cpp \ Action_Matrix.cpp \ + Action_MinMaxDist.cpp \ Action_MinImage.cpp \ Action_Molsurf.cpp \ Action_MultiDihedral.cpp \ From e99ee24a58f28cd6b151a7a506cda48c63074669 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 14:54:25 -0400 Subject: [PATCH 043/200] Mask setup --- src/Action_MinMaxDist.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index aa09b83c81..c96360e3dd 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -90,7 +90,20 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i // Action_MinMaxDist::Setup() Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) { - + // Set up masks + if (setup.Top().SetupIntegerMask( mask1_ )) { + mprinterr("Error: Could not set up mask '%s'\n", mask1_.MaskString()); + return Action::OK; + } + mask1_.MaskInfo(); + if (mask2_.MaskStringSet()) { + if (setup.Top().SetupIntegerMask( mask2_ )) { + mprinterr("Error: Could not set up mask '%s'\n", mask2_.MaskString()); + return Action::OK; + } + mask2_.MaskInfo(); + } + return Action::OK; } From 6762c48514bbcbffe3104939c4d784b316a85927 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 14:58:20 -0400 Subject: [PATCH 044/200] Add imaging --- src/Action_MinMaxDist.cpp | 15 ++++++++++++++- src/Action_MinMaxDist.h | 2 ++ src/cpptrajdepend | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index c96360e3dd..64a1447253 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -24,7 +24,7 @@ const char* Action_MinMaxDist::distTypeStr_[] = { // Action_MinMaxDist::Help() void Action_MinMaxDist::Help() const { mprintf("\tmask1 [mask2 ] [{byatom|byres|bymol}]\n" - "\t[mindist] [maxdist] [bothdist]\n" + "\t[mindist] [maxdist] [bothdist] [noimage]\n" " Record the min/max distance between atoms/residues/molecules.\n" ); } @@ -32,6 +32,9 @@ void Action_MinMaxDist::Help() const { // Action_MinMaxDist::Init() Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { + // Get Keywords + imageOpt_.InitImaging( !(actionArgs.hasKey("noimage")) ); + // Mask Keywords std::string mask1str = actionArgs.GetStringKey("mask1"); if (mask1str.empty()) { mprinterr("Error: Must specify at least 'mask1'\n"); @@ -83,6 +86,10 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i if (mask2_.MaskStringSet()) { mprintf("\tMask2: %s\n", mask2_.MaskString()); } + if (imageOpt_.UseImage()) + mprintf("\tDistances will use minimum image convention if box info present.\n"); + else + mprintf("\tDistances will not be imaged.\n"); return Action::OK; } @@ -90,6 +97,12 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i // Action_MinMaxDist::Setup() Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) { + // Set up imaging info for this topology + imageOpt_.SetupImaging( setup.CoordInfo().TrajBox().HasBox() ); + if (imageOpt_.ImagingEnabled()) + mprintf("\tDistance imaging on.\n"); + else + mprintf("\tDistance imaging off.\n"); // Set up masks if (setup.Top().SetupIntegerMask( mask1_ )) { mprinterr("Error: Could not set up mask '%s'\n", mask1_.MaskString()); diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index 6e107a27ce..454fc48c89 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -1,6 +1,7 @@ #ifndef INC_ACTION_MINMAXDIST_H #define INC_ACTION_MINMAXDIST_H #include "Action.h" +#include "ImageOption.h" /// Record the min/max distance between atoms/residues/molecules class Action_MinMaxDist : public Action { public: @@ -26,5 +27,6 @@ class Action_MinMaxDist : public Action { AtomMask mask2_; ModeType mode_; DistType distType_; + ImageOption imageOpt_; ///< Used to determine if imaging should be used. }; #endif diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 2543115f19..3d9b155bd9 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -50,7 +50,7 @@ Action_MakeStructure.o : Action_MakeStructure.cpp Action.h ActionState.h Action_ Action_Mask.o : Action_Mask.cpp Action.h ActionFrameCounter.h ActionState.h Action_Mask.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h Action_Matrix.o : Action_Matrix.cpp Action.h ActionFrameCounter.h ActionState.h Action_Matrix.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.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_1D.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Vector.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_MinImage.o : Action_MinImage.cpp Action.h ActionState.h Action_MinImage.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Action_MinMaxDist.o : Action_MinMaxDist.cpp Action.h ActionState.h Action_MinMaxDist.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Action_MinMaxDist.o : Action_MinMaxDist.cpp Action.h ActionState.h Action_MinMaxDist.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 ImageOption.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_Molsurf.o : Action_Molsurf.cpp Action.h ActionState.h Action_Molsurf.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h molsurf.h Action_MultiDihedral.o : Action_MultiDihedral.cpp Action.h ActionState.h Action_MultiDihedral.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_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h DihedralSearch.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 StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h Action_MultiPucker.o : Action_MultiPucker.cpp Action.h ActionState.h Action_MultiPucker.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 Pucker.h Pucker_PuckerMask.h Pucker_PuckerSearch.h Pucker_PuckerToken.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h From dd72d3ae4ee3729edc5007ab3c5d8e9845d7af61 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 18:47:20 -0400 Subject: [PATCH 045/200] Start setting up entities --- src/Action_MinMaxDist.cpp | 73 +++++++++++++++++++++++++++++++++++++++ src/Action_MinMaxDist.h | 16 +++++++++ src/cpptrajdepend | 2 +- 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 64a1447253..6e0121efde 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -1,4 +1,5 @@ #include "Action_MinMaxDist.h" +#include "CharMask.h" #include "CpptrajStdio.h" /** CONSTRUCTOR */ @@ -94,6 +95,56 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i return Action::OK; } +/** For DEBUG, print selected atoms in entity array., */ +void Action_MinMaxDist::printEntities(Earray const& entities, AtomMask const& maskIn) const { + mprintf("DEBUG: Selected %s in mask %s\n", + modeStr_[mode_], maskIn.MaskString()); + for (Earray::const_iterator it = entities.begin(); it != entities.end(); ++it) { + if (!it->name_.empty()) { + mprintf("\t%s :", it->name_.c_str()); + for (AtomMask::const_iterator at = it->emask_.begin(); at != it->emask_.end(); ++at) + mprintf(" %i", *at + 1); + mprintf("\n"); + } + } +} + +/** Set up entities for atoms selected in given mask. */ +int Action_MinMaxDist::setupEntityArray(Earray& entities, AtomMask const& maskIn, + Topology const& topIn) +const +{ + entities.clear(); + CharMask cmask(maskIn.ConvertToCharMask(), maskIn.Nselected()); + + if (mode_ == BY_RES) { + entities.reserve(topIn.Nres()); + for (unsigned int ires = 0; ires < (unsigned int)topIn.Nres(); ires++) { + Residue const& Res = topIn.Res(ires); + if (ires >= entities.size()) { + entities.resize(ires+1); + } + Entity& currentEntity = entities[ires]; + for (int at = Res.FirstAtom(); at != Res.LastAtom(); at++) { + if (cmask.AtomInCharMask( at )) { + if (currentEntity.name_.empty()) { + currentEntity.name_ = Res.Name().Truncated(); + mprintf("NAME %s\n", currentEntity.name_.c_str()); + } + currentEntity.emask_.AddSelectedAtom( at ); + } + } + } // END loop over residues + } else { + mprinterr("Internal Error: Action_MinMaxDist::setupEntityArray() Unhandled mode\n"); + return 1; + } + // DEBUG - print entities + printEntities(entities, maskIn); + return 0; +} + + // Action_MinMaxDist::Setup() Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) { @@ -109,12 +160,34 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) return Action::OK; } mask1_.MaskInfo(); + if (mask1_.None()) { + mprintf("Warning: Nothing selected by mask '%s'\n", mask1_.MaskString()); + return Action::SKIP; + } if (mask2_.MaskStringSet()) { if (setup.Top().SetupIntegerMask( mask2_ )) { mprinterr("Error: Could not set up mask '%s'\n", mask2_.MaskString()); return Action::OK; } mask2_.MaskInfo(); + if (mask2_.None()) { + mprintf("Warning: Nothing selected by mask '%s'\n", mask2_.MaskString()); + return Action::SKIP; + } + } + if (mode_ != BY_ATOM) { + if (setupEntityArray(entities1_, mask1_, setup.Top())) { + mprinterr("Error: Could not set up %s for mask '%s'\n", + modeStr_[mode_], mask1_.MaskString()); + return Action::ERR; + } + if (mask2_.MaskStringSet()) { + if (setupEntityArray(entities2_, mask2_, setup.Top())) { + mprinterr("Error: Could not set up %s for mask '%s'\n", + modeStr_[mode_], mask2_.MaskString()); + return Action::ERR; + } + } } return Action::OK; diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index 454fc48c89..21794a46a6 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -18,15 +18,31 @@ class Action_MinMaxDist : public Action { static const char* modeStr_[]; static const char* distTypeStr_[]; + /// Used to track residues/molecules + class Entity { + public: + AtomMask emask_; ///< Selected atoms in entity. + std::string name_; ///< residue/molecule name + }; + + typedef std::vector Earray; + Action::RetType Init(ArgList&, ActionInit&, int); Action::RetType Setup(ActionSetup&); Action::RetType DoAction(int, ActionFrame&); void Print() {} + /// For debug, print entities to STDOUT + void printEntities(Earray const&, AtomMask const&) const; + /// Set up entity array for current mode + int setupEntityArray(Earray&, AtomMask const&, Topology const&) const; + AtomMask mask1_; AtomMask mask2_; ModeType mode_; DistType distType_; ImageOption imageOpt_; ///< Used to determine if imaging should be used. + Earray entities1_; ///< Entities corresponding to mask1_ + Earray entities2_; ///< Entities corresponding to mask2_ }; #endif diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 3d9b155bd9..5fd7b8b748 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -50,7 +50,7 @@ Action_MakeStructure.o : Action_MakeStructure.cpp Action.h ActionState.h Action_ Action_Mask.o : Action_Mask.cpp Action.h ActionFrameCounter.h ActionState.h Action_Mask.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h Action_Matrix.o : Action_Matrix.cpp Action.h ActionFrameCounter.h ActionState.h Action_Matrix.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.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_1D.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Vector.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_MinImage.o : Action_MinImage.cpp Action.h ActionState.h Action_MinImage.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Action_MinMaxDist.o : Action_MinMaxDist.cpp Action.h ActionState.h Action_MinMaxDist.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 ImageOption.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_MinMaxDist.o : Action_MinMaxDist.cpp Action.h ActionState.h Action_MinMaxDist.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 FileIO.h FileName.h FileTypes.h Frame.h ImageOption.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_Molsurf.o : Action_Molsurf.cpp Action.h ActionState.h Action_Molsurf.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h molsurf.h Action_MultiDihedral.o : Action_MultiDihedral.cpp Action.h ActionState.h Action_MultiDihedral.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_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h DihedralSearch.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 StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h Action_MultiPucker.o : Action_MultiPucker.cpp Action.h ActionState.h Action_MultiPucker.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 Pucker.h Pucker_PuckerMask.h Pucker_PuckerSearch.h Pucker_PuckerToken.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h From 3952d726d6560dde6ba74cb62b0c40563422d0d9 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 19:03:13 -0400 Subject: [PATCH 046/200] Save residue/molecule number --- src/Action_MinMaxDist.cpp | 8 +++++--- src/Action_MinMaxDist.h | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 6e0121efde..be45dfdeb3 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -100,8 +100,8 @@ void Action_MinMaxDist::printEntities(Earray const& entities, AtomMask const& ma mprintf("DEBUG: Selected %s in mask %s\n", modeStr_[mode_], maskIn.MaskString()); for (Earray::const_iterator it = entities.begin(); it != entities.end(); ++it) { - if (!it->name_.empty()) { - mprintf("\t%s :", it->name_.c_str()); + if (it->IsSet()) { + mprintf("\t%s %i :", it->name_.c_str(), it->num_ + 1); for (AtomMask::const_iterator at = it->emask_.begin(); at != it->emask_.end(); ++at) mprintf(" %i", *at + 1); mprintf("\n"); @@ -128,8 +128,9 @@ const for (int at = Res.FirstAtom(); at != Res.LastAtom(); at++) { if (cmask.AtomInCharMask( at )) { if (currentEntity.name_.empty()) { + currentEntity.num_ = ires; currentEntity.name_ = Res.Name().Truncated(); - mprintf("NAME %s\n", currentEntity.name_.c_str()); + //mprintf("NAME %s\n", currentEntity.name_.c_str()); } currentEntity.emask_.AddSelectedAtom( at ); } @@ -188,6 +189,7 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) return Action::ERR; } } + // Set up DataSets for each entity pair } return Action::OK; diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index 21794a46a6..310ae1dbb8 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -21,8 +21,11 @@ class Action_MinMaxDist : public Action { /// Used to track residues/molecules class Entity { public: + Entity() : num_(-1) {} + bool IsSet() const { return (num_ > -1); } AtomMask emask_; ///< Selected atoms in entity. std::string name_; ///< residue/molecule name + int num_; ///< residue/molecule number }; typedef std::vector Earray; From 59cfc7d36c8b5c037eb92acca55137405577a6ef Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 19:17:05 -0400 Subject: [PATCH 047/200] Change it so an entity is only allocated for things with at least 1 atom selected --- src/Action_MinMaxDist.cpp | 45 +++++++++++++++++++++++++-------------- src/Action_MinMaxDist.h | 3 +-- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index be45dfdeb3..9056e651e2 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -100,12 +100,10 @@ void Action_MinMaxDist::printEntities(Earray const& entities, AtomMask const& ma mprintf("DEBUG: Selected %s in mask %s\n", modeStr_[mode_], maskIn.MaskString()); for (Earray::const_iterator it = entities.begin(); it != entities.end(); ++it) { - if (it->IsSet()) { - mprintf("\t%s %i :", it->name_.c_str(), it->num_ + 1); - for (AtomMask::const_iterator at = it->emask_.begin(); at != it->emask_.end(); ++at) - mprintf(" %i", *at + 1); - mprintf("\n"); - } + mprintf("\t%s %i :", it->name_.c_str(), it->num_ + 1); + for (AtomMask::const_iterator at = it->emask_.begin(); at != it->emask_.end(); ++at) + mprintf(" %i", *at + 1); + mprintf("\n"); } } @@ -121,17 +119,14 @@ const entities.reserve(topIn.Nres()); for (unsigned int ires = 0; ires < (unsigned int)topIn.Nres(); ires++) { Residue const& Res = topIn.Res(ires); - if (ires >= entities.size()) { - entities.resize(ires+1); - } - Entity& currentEntity = entities[ires]; + bool needs_alloc = true; for (int at = Res.FirstAtom(); at != Res.LastAtom(); at++) { if (cmask.AtomInCharMask( at )) { - if (currentEntity.name_.empty()) { - currentEntity.num_ = ires; - currentEntity.name_ = Res.Name().Truncated(); - //mprintf("NAME %s\n", currentEntity.name_.c_str()); + if (needs_alloc) { + entities.push_back( Entity(Res.Name().Truncated(), ires) ); + needs_alloc = false; } + Entity& currentEntity = entities.back(); currentEntity.emask_.AddSelectedAtom( at ); } } @@ -188,9 +183,27 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) modeStr_[mode_], mask2_.MaskString()); return Action::ERR; } + // Set up DataSets for each entity pair + for (Earray::const_iterator it1 = entities1_.begin(); it1 != entities1_.end(); ++it1) + { + for (Earray::const_iterator it2 = entities2_.begin(); it2 != entities2_.end(); ++it2) + { + if (it1->num_ > it2->num_) { // TODO at least 2 res gap? + mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); + } + } + } + } else { + // Set up DataSets for each entity pair + for (Earray::const_iterator it1 = entities1_.begin(); it1 != entities1_.end(); ++it1) + { + for (Earray::const_iterator it2 = it1 + 1; it2 != entities1_.end(); ++it2) + { + mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); + } + } } - // Set up DataSets for each entity pair - } + } // END BY_RES, BY_MOL return Action::OK; } diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index 310ae1dbb8..d533d5b1b4 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -21,8 +21,7 @@ class Action_MinMaxDist : public Action { /// Used to track residues/molecules class Entity { public: - Entity() : num_(-1) {} - bool IsSet() const { return (num_ > -1); } + Entity(std::string const& na, int nu) : name_(na), num_(nu) {} AtomMask emask_; ///< Selected atoms in entity. std::string name_; ///< residue/molecule name int num_; ///< residue/molecule number From 4ace22c6105055933b3b835c5c9e9d3571bcafc6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 1 Apr 2024 19:31:04 -0400 Subject: [PATCH 048/200] Start allocating sets --- src/Action_MinMaxDist.cpp | 34 +++++++++++++++++++++++++++++++--- src/Action_MinMaxDist.h | 2 ++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 9056e651e2..8c7cc73bf8 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -1,11 +1,13 @@ #include "Action_MinMaxDist.h" #include "CharMask.h" #include "CpptrajStdio.h" +#include "StringRoutines.h" // integerToString /** CONSTRUCTOR */ Action_MinMaxDist::Action_MinMaxDist() : mode_(NO_MODE), - distType_(NO_DIST) + distType_(NO_DIST), + masterDSL_(0) {} const char* Action_MinMaxDist::modeStr_[] = { @@ -25,7 +27,7 @@ const char* Action_MinMaxDist::distTypeStr_[] = { // Action_MinMaxDist::Help() void Action_MinMaxDist::Help() const { mprintf("\tmask1 [mask2 ] [{byatom|byres|bymol}]\n" - "\t[mindist] [maxdist] [bothdist] [noimage]\n" + "\t[mindist] [maxdist] [bothdist] [noimage] [name ]\n" " Record the min/max distance between atoms/residues/molecules.\n" ); } @@ -64,6 +66,11 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i bool calc_maxdist = (actionArgs.hasKey("maxdist") || (actionArgs[0] == "maxdist")); if (actionArgs.hasKey("bothdist")) distType_ = BOTH_DIST; + // DataSet Name + dsname_ = actionArgs.GetStringKey("name"); + // Default name + if (dsname_.empty()) + dsname_ = init.DSL().GenerateDefaultName("MINMAXDIST"); // Default mode if (mode_ == NO_MODE) mode_ = BY_ATOM; @@ -80,6 +87,7 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i distType_ = MIN_DIST; } } + masterDSL_ = init.DslPtr(); mprintf(" MINMAXDIST: Calculating %s distance for selected %s.\n", distTypeStr_[distType_], modeStr_[mode_]); @@ -91,6 +99,7 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i mprintf("\tDistances will use minimum image convention if box info present.\n"); else mprintf("\tDistances will not be imaged.\n"); + mprintf("\tData set name: %s\n", dsname_.c_str()); return Action::OK; } @@ -139,7 +148,12 @@ const printEntities(entities, maskIn); return 0; } - + +/// Aspect for BY_RES +inline static std::string res_aspect(int r0, int r1, Topology const& topIn) +{ + return std::string( integerToString(r0+1) + "_" + integerToString(r1+1) ); +} // Action_MinMaxDist::Setup() Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) @@ -190,6 +204,13 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) { if (it1->num_ > it2->num_) { // TODO at least 2 res gap? mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); + MetaData meta(dsname_, res_aspect(it2->num_, it1->num_, setup.Top())); + DataSet* ds = masterDSL_->AddSet(DataSet::FLOAT, meta); + if (ds == 0) { + mprinterr("Error: Could not allocate data set %s[%s]\n", + meta.Name().c_str(), meta.Aspect().c_str()); + return Action::ERR; + } } } } @@ -200,6 +221,13 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) for (Earray::const_iterator it2 = it1 + 1; it2 != entities1_.end(); ++it2) { mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); + MetaData meta(dsname_, res_aspect(it2->num_, it1->num_, setup.Top())); + DataSet* ds = masterDSL_->AddSet(DataSet::FLOAT, meta); + if (ds == 0) { + mprinterr("Error: Could not allocate data set %s[%s]\n", + meta.Name().c_str(), meta.Aspect().c_str()); + return Action::ERR; + } } } } diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index d533d5b1b4..57c0a3c233 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -46,5 +46,7 @@ class Action_MinMaxDist : public Action { ImageOption imageOpt_; ///< Used to determine if imaging should be used. Earray entities1_; ///< Entities corresponding to mask1_ Earray entities2_; ///< Entities corresponding to mask2_ + std::string dsname_; ///< Data set name + DataSetList* masterDSL_; ///< Pointer to master data set list }; #endif From 2d313dda3c27474dee6d72ab49fcb39e72d30b9e Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 2 Apr 2024 08:39:48 -0400 Subject: [PATCH 049/200] Fix up dataset aspect --- src/Action_MinMaxDist.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 8c7cc73bf8..bc096ffa1d 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -149,8 +149,8 @@ const return 0; } -/// Aspect for BY_RES -inline static std::string res_aspect(int r0, int r1, Topology const& topIn) +/// Aspect for BY_RES/BY_MOL +inline static std::string entity_aspect(int r0, int r1) { return std::string( integerToString(r0+1) + "_" + integerToString(r1+1) ); } @@ -204,7 +204,7 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) { if (it1->num_ > it2->num_) { // TODO at least 2 res gap? mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); - MetaData meta(dsname_, res_aspect(it2->num_, it1->num_, setup.Top())); + MetaData meta(dsname_, entity_aspect(it2->num_, it1->num_)); DataSet* ds = masterDSL_->AddSet(DataSet::FLOAT, meta); if (ds == 0) { mprinterr("Error: Could not allocate data set %s[%s]\n", @@ -221,7 +221,7 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) for (Earray::const_iterator it2 = it1 + 1; it2 != entities1_.end(); ++it2) { mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); - MetaData meta(dsname_, res_aspect(it2->num_, it1->num_, setup.Top())); + MetaData meta(dsname_, entity_aspect(it2->num_, it1->num_)); DataSet* ds = masterDSL_->AddSet(DataSet::FLOAT, meta); if (ds == 0) { mprinterr("Error: Could not allocate data set %s[%s]\n", From f4a39ceb7bfb7a4a492fd9b419f287f61ca3386d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 2 Apr 2024 08:57:43 -0400 Subject: [PATCH 050/200] Start InteractionData class --- src/Action_MinMaxDist.h | 2 ++ src/InteractionData.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/InteractionData.h | 23 +++++++++++++++++++++++ src/cpptrajdepend | 5 +++-- src/cpptrajfiles | 1 + 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/InteractionData.cpp create mode 100644 src/InteractionData.h diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index 57c0a3c233..1ed4d21fba 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -2,6 +2,7 @@ #define INC_ACTION_MINMAXDIST_H #include "Action.h" #include "ImageOption.h" +#include "InteractionData.h" /// Record the min/max distance between atoms/residues/molecules class Action_MinMaxDist : public Action { public: @@ -48,5 +49,6 @@ class Action_MinMaxDist : public Action { Earray entities2_; ///< Entities corresponding to mask2_ std::string dsname_; ///< Data set name DataSetList* masterDSL_; ///< Pointer to master data set list + Cpptraj::InteractionData interactionSets_; ///< Hold interaction sets }; #endif diff --git a/src/InteractionData.cpp b/src/InteractionData.cpp new file mode 100644 index 0000000000..04f4ef177f --- /dev/null +++ b/src/InteractionData.cpp @@ -0,0 +1,37 @@ +#include "InteractionData.h" +#include "CpptrajStdio.h" +#include "DataSetList.h" + +using namespace Cpptraj; + +/** CONSTRUCTOR */ +InteractionData::InteractionData() +{} + +/** Add set tracking interaction between the two given indices. */ +DataSet* InteractionData::AddInteractionSet(DataSetList& dsl, DataSet::DataType typeIn, + MetaData const& metaIn, int i0, int i1) +{ + // Check for existing interaction + Ipair interaction; + if (i1 < i0) { + interaction.first = i1; + interaction.second = i0; + } else { + interaction.first = i0; + interaction.second = i1; + } + MapType::const_iterator it = setMap_.lower_bound(interaction); + if (it == setMap_.end() || it->first != interaction) + { + // New interaction + DataSet* ds = dsl.AddSet(typeIn, metaIn); + if (ds == 0) { + mprinterr("Error: Could not allocate data set %s\n", metaIn.PrintName().c_str()); + return 0; + } + it = setMap_.insert(it, PairType(interaction, ds)); + } + // TODO check existing set for issues? + return it->second; +} diff --git a/src/InteractionData.h b/src/InteractionData.h new file mode 100644 index 0000000000..269d9148d4 --- /dev/null +++ b/src/InteractionData.h @@ -0,0 +1,23 @@ +#ifndef INC_INTERACTIONDATA_H +#define INC_INTERACTIONDATA_H +#include "DataSet.h" // DataType +#include +class DataSetList; +class MetaData; +namespace Cpptraj { +/// Hold data sets corresponding to interactions between entities. +class InteractionData { + public: + InteractionData(); + + /// Add interaction pair data set + DataSet* AddInteractionSet(DataSetList&, DataSet::DataType, MetaData const&, int, int); + private: + typedef std::pair Ipair; + typedef std::pair PairType; + typedef std::map MapType; + + MapType setMap_; ///< Hold map of interaction #s to data sets +}; +} +#endif diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 5fd7b8b748..ed999e5b7b 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -50,7 +50,7 @@ Action_MakeStructure.o : Action_MakeStructure.cpp Action.h ActionState.h Action_ Action_Mask.o : Action_Mask.cpp Action.h ActionFrameCounter.h ActionState.h Action_Mask.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h Action_Matrix.o : Action_Matrix.cpp Action.h ActionFrameCounter.h ActionState.h Action_Matrix.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.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_1D.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Vector.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_MinImage.o : Action_MinImage.cpp Action.h ActionState.h Action_MinImage.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Action_MinMaxDist.o : Action_MinMaxDist.cpp Action.h ActionState.h Action_MinMaxDist.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 FileIO.h FileName.h FileTypes.h Frame.h ImageOption.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_MinMaxDist.o : Action_MinMaxDist.cpp Action.h ActionState.h Action_MinMaxDist.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 FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h InteractionData.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 StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_Molsurf.o : Action_Molsurf.cpp Action.h ActionState.h Action_Molsurf.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h molsurf.h Action_MultiDihedral.o : Action_MultiDihedral.cpp Action.h ActionState.h Action_MultiDihedral.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_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h DihedralSearch.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 StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h Action_MultiPucker.o : Action_MultiPucker.cpp Action.h ActionState.h Action_MultiPucker.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 Pucker.h Pucker_PuckerMask.h Pucker_PuckerSearch.h Pucker_PuckerToken.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h @@ -187,7 +187,7 @@ ClusterMap.o : ClusterMap.cpp AssociatedData.h ClusterMap.h Constants.h CpptrajF 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 ActionTopWriter.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_AvgBox.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_Keep.h Action_LESsplit.h Action_LIE.h Action_LipidOrder.h Action_MakeStructure.h Action_Mask.h Action_Matrix.h Action_MinImage.h Action_MinMaxDist.h Action_Molsurf.h Action_MultiDihedral.h Action_MultiPucker.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_ToroidalDiffusion.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_CalcDiffusion.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_TICA.h Analysis_Timecorr.h Analysis_VectorMath.h Analysis_Wavelet.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMap.h AtomMask.h AtomType.h AxisType.h BaseIOtype.h Box.h BoxArgs.h BufferedLine.h CharMask.h Cluster/Algorithm.h Cluster/BestReps.h Cluster/CentroidArray.h Cluster/Cframes.h Cluster/Control.h Cluster/DrawGraph.h Cluster/List.h Cluster/Metric.h Cluster/MetricArray.h Cluster/Node.h Cluster/Sieve.h Cluster/Silhouette.h ClusterMap.h Cmd.h CmdInput.h CmdList.h Command.h CompactFrameArray.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 DataFilter.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h DataSet_GridFlt.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 DiffusionResults.h DihedralSearch.h Dimension.h DispatchObject.h Energy.h Energy_Sander.h EnsembleIn.h EnsembleOutList.h Ewald.h EwaldOptions.h Ewald_ParticleMesh.h ExclusionArray.h Exec.h Exec_AddMissingRes.h Exec_Analyze.h Exec_Calc.h Exec_CatCrd.h Exec_Change.h Exec_ClusterMap.h Exec_CombineCoords.h Exec_Commands.h Exec_CompareClusters.h Exec_CompareEnergy.h Exec_CompareTop.h Exec_CrdAction.h Exec_CrdOut.h Exec_CrdTransform.h Exec_CreateSet.h Exec_DataFile.h Exec_DataFilter.h Exec_DataSetCmd.h Exec_Emin.h Exec_ExtendedComparison.h Exec_Flatten.h Exec_GenerateAmberRst.h Exec_Graft.h Exec_Help.h Exec_HmassRepartition.h Exec_LoadCrd.h Exec_LoadTraj.h Exec_ParallelAnalysis.h Exec_ParmBox.h Exec_ParmSolvent.h Exec_ParmStrip.h Exec_ParmWrite.h Exec_ParseTiming.h Exec_PermuteDihedrals.h Exec_Precision.h Exec_PrepareForLeap.h Exec_PrintData.h Exec_Random.h Exec_ReadData.h Exec_ReadEnsembleData.h Exec_ReadInput.h Exec_RotateDihedral.h Exec_RunAnalysis.h Exec_ScaleDihedralK.h Exec_Sequence.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 Exec_Zmatrix.h ExtendedSimilarity.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h GIST_PME.h Grid.h GridAction.h GridBin.h GridMover.h HistBin.h Hungarian.h ImageOption.h ImageTypes.h InputTrajCommon.h MapAtom.h MaskArray.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Routines.h NameType.h NetcdfFile.h OnlineVarT.h OutputTrajCommon.h PDBfile.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h PubFFT.h Pucker.h Pucker_PuckerMask.h Pucker_PuckerSearch.h Pucker_PuckerToken.h RPNcalc.h Random.h Range.h ReferenceAction.h ReferenceFrame.h RemdReservoirNC.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.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 Unit.h Vec3.h cuda_kernels/GistCudaSetup.cuh helpme_standalone.h molsurf.h +Command.o : Command.cpp Action.h ActionFrameCounter.h ActionList.h ActionState.h ActionTopWriter.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_AvgBox.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_Keep.h Action_LESsplit.h Action_LIE.h Action_LipidOrder.h Action_MakeStructure.h Action_Mask.h Action_Matrix.h Action_MinImage.h Action_MinMaxDist.h Action_Molsurf.h Action_MultiDihedral.h Action_MultiPucker.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_ToroidalDiffusion.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_CalcDiffusion.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_TICA.h Analysis_Timecorr.h Analysis_VectorMath.h Analysis_Wavelet.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMap.h AtomMask.h AtomType.h AxisType.h BaseIOtype.h Box.h BoxArgs.h BufferedLine.h CharMask.h Cluster/Algorithm.h Cluster/BestReps.h Cluster/CentroidArray.h Cluster/Cframes.h Cluster/Control.h Cluster/DrawGraph.h Cluster/List.h Cluster/Metric.h Cluster/MetricArray.h Cluster/Node.h Cluster/Sieve.h Cluster/Silhouette.h ClusterMap.h Cmd.h CmdInput.h CmdList.h Command.h CompactFrameArray.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 DataFilter.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_3D.h DataSet_Coords.h DataSet_Coords_CRD.h DataSet_Coords_REF.h DataSet_GridFlt.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 DiffusionResults.h DihedralSearch.h Dimension.h DispatchObject.h Energy.h Energy_Sander.h EnsembleIn.h EnsembleOutList.h Ewald.h EwaldOptions.h Ewald_ParticleMesh.h ExclusionArray.h Exec.h Exec_AddMissingRes.h Exec_Analyze.h Exec_Calc.h Exec_CatCrd.h Exec_Change.h Exec_ClusterMap.h Exec_CombineCoords.h Exec_Commands.h Exec_CompareClusters.h Exec_CompareEnergy.h Exec_CompareTop.h Exec_CrdAction.h Exec_CrdOut.h Exec_CrdTransform.h Exec_CreateSet.h Exec_DataFile.h Exec_DataFilter.h Exec_DataSetCmd.h Exec_Emin.h Exec_ExtendedComparison.h Exec_Flatten.h Exec_GenerateAmberRst.h Exec_Graft.h Exec_Help.h Exec_HmassRepartition.h Exec_LoadCrd.h Exec_LoadTraj.h Exec_ParallelAnalysis.h Exec_ParmBox.h Exec_ParmSolvent.h Exec_ParmStrip.h Exec_ParmWrite.h Exec_ParseTiming.h Exec_PermuteDihedrals.h Exec_Precision.h Exec_PrepareForLeap.h Exec_PrintData.h Exec_Random.h Exec_ReadData.h Exec_ReadEnsembleData.h Exec_ReadInput.h Exec_RotateDihedral.h Exec_RunAnalysis.h Exec_ScaleDihedralK.h Exec_Sequence.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 Exec_Zmatrix.h ExtendedSimilarity.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h GIST_PME.h Grid.h GridAction.h GridBin.h GridMover.h HistBin.h Hungarian.h ImageOption.h ImageTypes.h InputTrajCommon.h InteractionData.h MapAtom.h MaskArray.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NC_Routines.h NameType.h NetcdfFile.h OnlineVarT.h OutputTrajCommon.h PDBfile.h PairList.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h PubFFT.h Pucker.h Pucker_PuckerMask.h Pucker_PuckerSearch.h Pucker_PuckerToken.h RPNcalc.h Random.h Range.h ReferenceAction.h ReferenceFrame.h RemdReservoirNC.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.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 Unit.h Vec3.h cuda_kernels/GistCudaSetup.cuh helpme_standalone.h molsurf.h CompactFrameArray.o : CompactFrameArray.cpp Box.h CompactFrameArray.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h ComplexArray.o : ComplexArray.cpp ArrayIterator.h ComplexArray.h Constraints.o : Constraints.cpp ArgList.h Atom.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 Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.h Vec3.h @@ -375,6 +375,7 @@ Image_List_Mask.o : Image_List_Mask.cpp Atom.h AtomMask.h AtomType.h Box.h Const Image_List_Pair.o : Image_List_Pair.cpp Atom.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajStdio.h FileName.h Frame.h Image_List.h Image_List_Pair.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.h Vec3.h Image_List_Unit.o : Image_List_Unit.cpp Atom.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajStdio.h FileName.h Frame.h Image_List.h Image_List_Unit.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.h Vec3.h InputTrajCommon.o : InputTrajCommon.cpp CpptrajStdio.h FileName.h InputTrajCommon.h TrajFrameCounter.h +InteractionData.o : InteractionData.cpp AssociatedData.h Atom.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h FileIO.h FileName.h Frame.h InteractionData.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 KDE.o : KDE.cpp AssociatedData.h Constants.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_1D.h DataSet_double.h Dimension.h FileIO.h FileName.h HistBin.h KDE.h MetaData.h Parallel.h Range.h TextFormat.h LeapInterface.o : LeapInterface.cpp ArgList.h Atom.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h File_TempName.h Frame.h LeapInterface.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.h Vec3.h MapAtom.o : MapAtom.cpp Atom.h MapAtom.h NameType.h SymbolExporting.h diff --git a/src/cpptrajfiles b/src/cpptrajfiles index 6699545b9b..688fe361e5 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -343,6 +343,7 @@ COMMON_SOURCES= \ Image_List_Mask.cpp \ Image_List_Pair.cpp \ Image_List_Unit.cpp \ + InteractionData.cpp \ InputTrajCommon.cpp \ KDE.cpp \ LeapInterface.cpp \ From 42ff4e487d6f9020199f4cfb5d96bfb48eff6cd2 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 2 Apr 2024 09:16:22 -0400 Subject: [PATCH 051/200] Add molecule entities --- src/Action_MinMaxDist.cpp | 34 ++++++++++++++++++++++++++++++---- src/Action_MinMaxDist.h | 2 ++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index bc096ffa1d..693269c456 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -125,8 +125,8 @@ const CharMask cmask(maskIn.ConvertToCharMask(), maskIn.Nselected()); if (mode_ == BY_RES) { - entities.reserve(topIn.Nres()); - for (unsigned int ires = 0; ires < (unsigned int)topIn.Nres(); ires++) { + //entities.reserve(topIn.Nres()); + for (int ires = 0; ires < topIn.Nres(); ires++) { Residue const& Res = topIn.Res(ires); bool needs_alloc = true; for (int at = Res.FirstAtom(); at != Res.LastAtom(); at++) { @@ -140,6 +140,26 @@ const } } } // END loop over residues + } else if (mode_ == BY_MOL) { + for (int imol = 0; imol < topIn.Nmol(); imol++) { + Molecule const& Mol = topIn.Mol(imol); + bool needs_alloc = true; + for (Unit::const_iterator seg = Mol.MolUnit().segBegin(); + seg != Mol.MolUnit().segEnd(); ++seg) + { + for (int at = seg->Begin(); at < seg->End(); ++at) { + if (cmask.AtomInCharMask( at )) { + if (needs_alloc) { + int rnum = topIn[at].ResNum(); + entities.push_back( Entity(topIn.Res(rnum).Name().Truncated(), imol) ); + needs_alloc = false; + } + Entity& currentEntity = entities.back(); + currentEntity.emask_.AddSelectedAtom( at ); + } + } + } // END loop over molecule segments + } // END loop over molecules } else { mprinterr("Internal Error: Action_MinMaxDist::setupEntityArray() Unhandled mode\n"); return 1; @@ -191,6 +211,7 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) modeStr_[mode_], mask1_.MaskString()); return Action::ERR; } + activeSets_.clear(); if (mask2_.MaskStringSet()) { if (setupEntityArray(entities2_, mask2_, setup.Top())) { mprinterr("Error: Could not set up %s for mask '%s'\n", @@ -205,12 +226,13 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) if (it1->num_ > it2->num_) { // TODO at least 2 res gap? mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); MetaData meta(dsname_, entity_aspect(it2->num_, it1->num_)); - DataSet* ds = masterDSL_->AddSet(DataSet::FLOAT, meta); + DataSet* ds = interactionSets_.AddInteractionSet(*masterDSL_, DataSet::FLOAT, meta, it2->num_, it1->num_); if (ds == 0) { mprinterr("Error: Could not allocate data set %s[%s]\n", meta.Name().c_str(), meta.Aspect().c_str()); return Action::ERR; } + activeSets_.push_back( ds ); } } } @@ -222,15 +244,19 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) { mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); MetaData meta(dsname_, entity_aspect(it2->num_, it1->num_)); - DataSet* ds = masterDSL_->AddSet(DataSet::FLOAT, meta); + DataSet* ds = interactionSets_.AddInteractionSet(*masterDSL_, DataSet::FLOAT, meta, it2->num_, it1->num_); if (ds == 0) { mprinterr("Error: Could not allocate data set %s[%s]\n", meta.Name().c_str(), meta.Aspect().c_str()); return Action::ERR; } + activeSets_.push_back( ds ); } } } + mprintf("DEBUG: Active sets:\n"); + for (DSarray::const_iterator it = activeSets_.begin(); it != activeSets_.end(); ++it) + mprintf("\t%s\n", (*it)->legend()); } // END BY_RES, BY_MOL return Action::OK; diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index 1ed4d21fba..c2cdd00839 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -29,6 +29,7 @@ class Action_MinMaxDist : public Action { }; typedef std::vector Earray; + typedef std::vector DSarray; Action::RetType Init(ArgList&, ActionInit&, int); Action::RetType Setup(ActionSetup&); @@ -50,5 +51,6 @@ class Action_MinMaxDist : public Action { std::string dsname_; ///< Data set name DataSetList* masterDSL_; ///< Pointer to master data set list Cpptraj::InteractionData interactionSets_; ///< Hold interaction sets + DSarray activeSets_; ///< Hold active interaction sets }; #endif From 549371978059a484a36d8a65bc3224121250d38d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 2 Apr 2024 09:20:28 -0400 Subject: [PATCH 052/200] Data set for by atom --- src/Action_MinMaxDist.cpp | 13 +++++++++++++ src/Action_MinMaxDist.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 693269c456..48b67a92c9 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -7,6 +7,7 @@ Action_MinMaxDist::Action_MinMaxDist() : mode_(NO_MODE), distType_(NO_DIST), + byAtomSet_(0), masterDSL_(0) {} @@ -88,6 +89,14 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i } } masterDSL_ = init.DslPtr(); + // Allocate by atom set + if (mode_ == BY_ATOM) { + byAtomSet_ = init.DSL().AddSet(DataSet::FLOAT, MetaData(dsname_)); + if (byAtomSet_ == 0) { + mprinterr("Error: Could not allocate set '%s'\n", dsname_.c_str()); + return Action::ERR; + } + } mprintf(" MINMAXDIST: Calculating %s distance for selected %s.\n", distTypeStr_[distType_], modeStr_[mode_]); @@ -257,6 +266,10 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) mprintf("DEBUG: Active sets:\n"); for (DSarray::const_iterator it = activeSets_.begin(); it != activeSets_.end(); ++it) mprintf("\t%s\n", (*it)->legend()); + if (activeSets_.empty()) { + mprintf("Warning: No active interaction pairs. Skipping.\n"); + return Action::SKIP; + } } // END BY_RES, BY_MOL return Action::OK; diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index c2cdd00839..ea77c23639 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -49,6 +49,7 @@ class Action_MinMaxDist : public Action { Earray entities1_; ///< Entities corresponding to mask1_ Earray entities2_; ///< Entities corresponding to mask2_ std::string dsname_; ///< Data set name + DataSet* byAtomSet_; ///< By atom output data set DataSetList* masterDSL_; ///< Pointer to master data set list Cpptraj::InteractionData interactionSets_; ///< Hold interaction sets DSarray activeSets_; ///< Hold active interaction sets From 004edf64ab415cf8ec2cf97aad282ace11694e7c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 2 Apr 2024 09:53:31 -0400 Subject: [PATCH 053/200] Start adding routines to calculate distance --- src/Action_MinMaxDist.cpp | 51 ++++++++++++++++++++++++++++++++++++--- src/Action_MinMaxDist.h | 17 +++++++++++-- src/cpptrajdepend | 2 +- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 48b67a92c9..a70a3becbc 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -1,7 +1,10 @@ #include "Action_MinMaxDist.h" #include "CharMask.h" #include "CpptrajStdio.h" +#include "DistRoutines.h" #include "StringRoutines.h" // integerToString +#include // Max double +#include // sqrt /** CONSTRUCTOR */ Action_MinMaxDist::Action_MinMaxDist() : @@ -214,13 +217,14 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) return Action::SKIP; } } + // By residue/molecule interaction pair data set setup + activeSets_.clear(); if (mode_ != BY_ATOM) { if (setupEntityArray(entities1_, mask1_, setup.Top())) { mprinterr("Error: Could not set up %s for mask '%s'\n", modeStr_[mode_], mask1_.MaskString()); return Action::ERR; } - activeSets_.clear(); if (mask2_.MaskStringSet()) { if (setupEntityArray(entities2_, mask2_, setup.Top())) { mprinterr("Error: Could not set up %s for mask '%s'\n", @@ -241,7 +245,7 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) meta.Name().c_str(), meta.Aspect().c_str()); return Action::ERR; } - activeSets_.push_back( ds ); + activeSets_.push_back( ActiveSet(ds, it1, it2) ); } } } @@ -259,13 +263,13 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) meta.Name().c_str(), meta.Aspect().c_str()); return Action::ERR; } - activeSets_.push_back( ds ); + activeSets_.push_back( ActiveSet(ds, it1, it2) ); } } } mprintf("DEBUG: Active sets:\n"); for (DSarray::const_iterator it = activeSets_.begin(); it != activeSets_.end(); ++it) - mprintf("\t%s\n", (*it)->legend()); + mprintf("\t%s\n", it->ds_->legend()); if (activeSets_.empty()) { mprintf("Warning: No active interaction pairs. Skipping.\n"); return Action::SKIP; @@ -275,8 +279,47 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) return Action::OK; } +/** Get min distance between all atom pairs */ +double Action_MinMaxDist::get_min_dist(AtomMask const& mask1, AtomMask const& mask2, Frame const& frameIn) +const +{ + double min_dist2 = std::numeric_limits::max(); + for (AtomMask::const_iterator at1 = mask1.begin(); at1 != mask1.end(); ++at1) { + const double* XYZ1 = frameIn.XYZ(*at1); + for (AtomMask::const_iterator at2 = mask2.begin(); at2 != mask2.end(); ++at2) { + if (*at1 != *at2) { + const double* XYZ2 = frameIn.XYZ(*at2); + double dist2 = DIST2(imageOpt_.ImagingType(), XYZ1, XYZ2, frameIn.BoxCrd()); + if (dist2 < min_dist2) + min_dist2 = dist2; + } + } + } + return sqrt(min_dist2); +} + +/** Get min distance between all atoms pairs */ +double Action_MinMaxDist::get_min_dist(AtomMask const& mask1, Frame const& frameIn) +const +{ + double min_dist2 = std::numeric_limits::max(); + for (AtomMask::const_iterator at1 = mask1.begin(); at1 != mask1.end(); ++at1) { + const double* XYZ1 = frameIn.XYZ(*at1); + for (AtomMask::const_iterator at2 = at1 + 1; at2 != mask1.end(); ++at2) { + const double* XYZ2 = frameIn.XYZ(*at2); + double dist2 = DIST2(imageOpt_.ImagingType(), XYZ1, XYZ2, frameIn.BoxCrd()); + if (dist2 < min_dist2) + min_dist2 = dist2; + } + } + return sqrt(min_dist2); +} + // Action_MinMaxDist::DoAction() Action::RetType Action_MinMaxDist::DoAction(int frameNum, ActionFrame& frm) { + if (imageOpt_.ImagingEnabled()) + imageOpt_.SetImageType( frm.Frm().BoxCrd().Is_X_Aligned_Ortho() ); + return Action::OK; } diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index ea77c23639..a2da7f38e0 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -27,9 +27,18 @@ class Action_MinMaxDist : public Action { std::string name_; ///< residue/molecule name int num_; ///< residue/molecule number }; - typedef std::vector Earray; - typedef std::vector DSarray; + + /// Used to track active sets and corresponding entities + class ActiveSet { + public: + ActiveSet(DataSet* ds, Earray::const_iterator const& it1, Earray::const_iterator const& it2) : + ds_(ds), it1_(it1), it2_(it2) {} + DataSet* ds_; + Earray::const_iterator it1_; + Earray::const_iterator it2_; + }; + typedef std::vector DSarray; Action::RetType Init(ArgList&, ActionInit&, int); Action::RetType Setup(ActionSetup&); @@ -40,6 +49,10 @@ class Action_MinMaxDist : public Action { void printEntities(Earray const&, AtomMask const&) const; /// Set up entity array for current mode int setupEntityArray(Earray&, AtomMask const&, Topology const&) const; + /// Get minimum distance between atoms in masks + double get_min_dist(AtomMask const&, AtomMask const&, Frame const&) const; + /// Get minimum distance between atoms in mask + double get_min_dist(AtomMask const&, Frame const&) const; AtomMask mask1_; AtomMask mask2_; diff --git a/src/cpptrajdepend b/src/cpptrajdepend index ed999e5b7b..5ecc034536 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -50,7 +50,7 @@ Action_MakeStructure.o : Action_MakeStructure.cpp Action.h ActionState.h Action_ Action_Mask.o : Action_Mask.cpp Action.h ActionFrameCounter.h ActionState.h Action_Mask.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h Action_Matrix.o : Action_Matrix.cpp Action.h ActionFrameCounter.h ActionState.h Action_Matrix.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.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_1D.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Vector.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_MinImage.o : Action_MinImage.cpp Action.h ActionState.h Action_MinImage.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Action_MinMaxDist.o : Action_MinMaxDist.cpp Action.h ActionState.h Action_MinMaxDist.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 FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h InteractionData.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 StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Action_MinMaxDist.o : Action_MinMaxDist.cpp Action.h ActionState.h Action_MinMaxDist.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 DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h InteractionData.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 StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_Molsurf.o : Action_Molsurf.cpp Action.h ActionState.h Action_Molsurf.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h molsurf.h Action_MultiDihedral.o : Action_MultiDihedral.cpp Action.h ActionState.h Action_MultiDihedral.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_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_double.h DihedralSearch.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 StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h Action_MultiPucker.o : Action_MultiPucker.cpp Action.h ActionState.h Action_MultiPucker.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 Pucker.h Pucker_PuckerMask.h Pucker_PuckerSearch.h Pucker_PuckerToken.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h From 99b376396911814c3ff2f6fccc3ea4c6553f1566 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 2 Apr 2024 10:02:01 -0400 Subject: [PATCH 054/200] Make bothdist an error --- src/Action_MinMaxDist.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index a70a3becbc..b08f74b4d7 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -31,7 +31,7 @@ const char* Action_MinMaxDist::distTypeStr_[] = { // Action_MinMaxDist::Help() void Action_MinMaxDist::Help() const { mprintf("\tmask1 [mask2 ] [{byatom|byres|bymol}]\n" - "\t[mindist] [maxdist] [bothdist] [noimage] [name ]\n" + "\t[mindist] [maxdist] [noimage] [name ]\n" " Record the min/max distance between atoms/residues/molecules.\n" ); } @@ -68,8 +68,8 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i // Distance calc type args bool calc_mindist = (actionArgs.hasKey("mindist") || (actionArgs[0] == "mindist")); bool calc_maxdist = (actionArgs.hasKey("maxdist") || (actionArgs[0] == "maxdist")); - if (actionArgs.hasKey("bothdist")) - distType_ = BOTH_DIST; + //if (actionArgs.hasKey("bothdist")) + // distType_ = BOTH_DIST; // DataSet Name dsname_ = actionArgs.GetStringKey("name"); // Default name @@ -80,9 +80,11 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i mode_ = BY_ATOM; // Default distance calc type if (distType_ == NO_DIST) { - if (calc_mindist && calc_maxdist) - distType_ = BOTH_DIST; - else if (calc_mindist) + if (calc_mindist && calc_maxdist) { + //distType_ = BOTH_DIST; + mprinterr("Error: Can only have 'mindist' or 'maxdist', not both.\n"); + return Action::ERR; + } else if (calc_mindist) distType_ = MIN_DIST; else if (calc_maxdist) distType_ = MAX_DIST; @@ -321,5 +323,7 @@ Action::RetType Action_MinMaxDist::DoAction(int frameNum, ActionFrame& frm) if (imageOpt_.ImagingEnabled()) imageOpt_.SetImageType( frm.Frm().BoxCrd().Is_X_Aligned_Ortho() ); + if ( + return Action::OK; } From 5ae73ed50e0d9e23b5a426e6e14ec017c37db6d6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 2 Apr 2024 10:03:43 -0400 Subject: [PATCH 055/200] Add max dist functions --- src/Action_MinMaxDist.cpp | 37 ++++++++++++++++++++++++++++++++++++- src/Action_MinMaxDist.h | 4 ++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index b08f74b4d7..615c8ca661 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -317,13 +317,48 @@ const return sqrt(min_dist2); } +/** Get max distance between all atom pairs */ +double Action_MinMaxDist::get_max_dist(AtomMask const& mask1, AtomMask const& mask2, Frame const& frameIn) +const +{ + double max_dist2 = 0; + for (AtomMask::const_iterator at1 = mask1.begin(); at1 != mask1.end(); ++at1) { + const double* XYZ1 = frameIn.XYZ(*at1); + for (AtomMask::const_iterator at2 = mask2.begin(); at2 != mask2.end(); ++at2) { + if (*at1 != *at2) { + const double* XYZ2 = frameIn.XYZ(*at2); + double dist2 = DIST2(imageOpt_.ImagingType(), XYZ1, XYZ2, frameIn.BoxCrd()); + if (dist2 > max_dist2) + max_dist2 = dist2; + } + } + } + return sqrt(max_dist2); +} + +/** Get max distance between all atoms pairs */ +double Action_MinMaxDist::get_max_dist(AtomMask const& mask1, Frame const& frameIn) +const +{ + double max_dist2 = 0; + for (AtomMask::const_iterator at1 = mask1.begin(); at1 != mask1.end(); ++at1) { + const double* XYZ1 = frameIn.XYZ(*at1); + for (AtomMask::const_iterator at2 = at1 + 1; at2 != mask1.end(); ++at2) { + const double* XYZ2 = frameIn.XYZ(*at2); + double dist2 = DIST2(imageOpt_.ImagingType(), XYZ1, XYZ2, frameIn.BoxCrd()); + if (dist2 > max_dist2) + max_dist2 = dist2; + } + } + return sqrt(max_dist2); +} + // Action_MinMaxDist::DoAction() Action::RetType Action_MinMaxDist::DoAction(int frameNum, ActionFrame& frm) { if (imageOpt_.ImagingEnabled()) imageOpt_.SetImageType( frm.Frm().BoxCrd().Is_X_Aligned_Ortho() ); - if ( return Action::OK; } diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index a2da7f38e0..91c5e13539 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -53,6 +53,10 @@ class Action_MinMaxDist : public Action { double get_min_dist(AtomMask const&, AtomMask const&, Frame const&) const; /// Get minimum distance between atoms in mask double get_min_dist(AtomMask const&, Frame const&) const; + /// Get maximum distance between atoms in masks + double get_max_dist(AtomMask const&, AtomMask const&, Frame const&) const; + /// Get maximum distance between atoms in mask + double get_max_dist(AtomMask const&, Frame const&) const; AtomMask mask1_; AtomMask mask2_; From 52753d12118bc3017356db49a45116e45f1697b2 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 2 Apr 2024 10:13:36 -0400 Subject: [PATCH 056/200] Add calculation --- src/Action_MinMaxDist.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 615c8ca661..87244f875e 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -359,6 +359,32 @@ Action::RetType Action_MinMaxDist::DoAction(int frameNum, ActionFrame& frm) if (imageOpt_.ImagingEnabled()) imageOpt_.SetImageType( frm.Frm().BoxCrd().Is_X_Aligned_Ortho() ); - + if (mode_ == BY_ATOM) { + float dist; + if (mask2_.MaskStringSet()) { + if (distType_ == MIN_DIST) + dist = get_min_dist(mask1_, mask2_, frm.Frm()); + else if (distType_ == MAX_DIST) + dist = get_max_dist(mask1_, mask2_, frm.Frm()); + } else { + if (distType_ == MIN_DIST) + dist = get_min_dist(mask1_, frm.Frm()); + else if (distType_ == MAX_DIST) + dist = get_max_dist(mask1_, frm.Frm()); + } + byAtomSet_->Add( frameNum, &dist ); + } else { + // BY_RES / BY_MOL + for (DSarray::const_iterator set = activeSets_.begin(); set != activeSets_.end(); ++set) { + float dist; + if (distType_ == MIN_DIST) + dist = get_min_dist(set->it1_->emask_, set->it2_->emask_, frm.Frm()); + else if (distType_ == MAX_DIST) + dist = get_max_dist(set->it1_->emask_, set->it2_->emask_, frm.Frm()); + + set->ds_->Add( frameNum, &dist ); + } + } + return Action::OK; } From f72f2db8931a25fe6c621d1822dbcde9daf59b25 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 2 Apr 2024 10:46:57 -0400 Subject: [PATCH 057/200] Add out keyword --- src/Action_MinMaxDist.cpp | 13 +++++++++++-- src/Action_MinMaxDist.h | 1 + src/InteractionData.cpp | 5 ++++- src/InteractionData.h | 3 ++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Action_MinMaxDist.cpp b/src/Action_MinMaxDist.cpp index 87244f875e..6b2814ba45 100644 --- a/src/Action_MinMaxDist.cpp +++ b/src/Action_MinMaxDist.cpp @@ -10,6 +10,7 @@ Action_MinMaxDist::Action_MinMaxDist() : mode_(NO_MODE), distType_(NO_DIST), + outfile_(0), byAtomSet_(0), masterDSL_(0) {} @@ -32,6 +33,7 @@ const char* Action_MinMaxDist::distTypeStr_[] = { void Action_MinMaxDist::Help() const { mprintf("\tmask1 [mask2 ] [{byatom|byres|bymol}]\n" "\t[mindist] [maxdist] [noimage] [name ]\n" + "\t[out ]\n" " Record the min/max distance between atoms/residues/molecules.\n" ); } @@ -58,6 +60,8 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i return Action::ERR; } } + // File args + outfile_ = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs ); // Mode args if (actionArgs.hasKey("byatom")) mode_ = BY_ATOM; @@ -101,6 +105,8 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i mprinterr("Error: Could not allocate set '%s'\n", dsname_.c_str()); return Action::ERR; } + if (outfile_ != 0) + outfile_->AddDataSet( byAtomSet_ ); } mprintf(" MINMAXDIST: Calculating %s distance for selected %s.\n", @@ -114,6 +120,8 @@ Action::RetType Action_MinMaxDist::Init(ArgList& actionArgs, ActionInit& init, i else mprintf("\tDistances will not be imaged.\n"); mprintf("\tData set name: %s\n", dsname_.c_str()); + if (outfile_ != 0) + mprintf("Data file name: %s\n", outfile_->DataFilename().full()); return Action::OK; } @@ -241,7 +249,7 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) if (it1->num_ > it2->num_) { // TODO at least 2 res gap? mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); MetaData meta(dsname_, entity_aspect(it2->num_, it1->num_)); - DataSet* ds = interactionSets_.AddInteractionSet(*masterDSL_, DataSet::FLOAT, meta, it2->num_, it1->num_); + DataSet* ds = interactionSets_.AddInteractionSet(*masterDSL_, DataSet::FLOAT, meta, it2->num_, it1->num_, outfile_); if (ds == 0) { mprinterr("Error: Could not allocate data set %s[%s]\n", meta.Name().c_str(), meta.Aspect().c_str()); @@ -259,7 +267,7 @@ Action::RetType Action_MinMaxDist::Setup(ActionSetup& setup) { mprintf("DEBUG: Pair %i - %i\n", it1->num_ + 1, it2->num_ + 1); MetaData meta(dsname_, entity_aspect(it2->num_, it1->num_)); - DataSet* ds = interactionSets_.AddInteractionSet(*masterDSL_, DataSet::FLOAT, meta, it2->num_, it1->num_); + DataSet* ds = interactionSets_.AddInteractionSet(*masterDSL_, DataSet::FLOAT, meta, it2->num_, it1->num_, outfile_); if (ds == 0) { mprinterr("Error: Could not allocate data set %s[%s]\n", meta.Name().c_str(), meta.Aspect().c_str()); @@ -292,6 +300,7 @@ const if (*at1 != *at2) { const double* XYZ2 = frameIn.XYZ(*at2); double dist2 = DIST2(imageOpt_.ImagingType(), XYZ1, XYZ2, frameIn.BoxCrd()); + //mprintf("DEBUG: get_min_dist(m1,m2) %i %i = %f\n", *at1 + 1, *at2 + 1, sqrt(dist2)); if (dist2 < min_dist2) min_dist2 = dist2; } diff --git a/src/Action_MinMaxDist.h b/src/Action_MinMaxDist.h index 91c5e13539..cf31b2896f 100644 --- a/src/Action_MinMaxDist.h +++ b/src/Action_MinMaxDist.h @@ -66,6 +66,7 @@ class Action_MinMaxDist : public Action { Earray entities1_; ///< Entities corresponding to mask1_ Earray entities2_; ///< Entities corresponding to mask2_ std::string dsname_; ///< Data set name + DataFile* outfile_; ///< Output data file DataSet* byAtomSet_; ///< By atom output data set DataSetList* masterDSL_; ///< Pointer to master data set list Cpptraj::InteractionData interactionSets_; ///< Hold interaction sets diff --git a/src/InteractionData.cpp b/src/InteractionData.cpp index 04f4ef177f..85dc65fbdb 100644 --- a/src/InteractionData.cpp +++ b/src/InteractionData.cpp @@ -1,5 +1,6 @@ #include "InteractionData.h" #include "CpptrajStdio.h" +#include "DataFile.h" #include "DataSetList.h" using namespace Cpptraj; @@ -10,7 +11,8 @@ InteractionData::InteractionData() /** Add set tracking interaction between the two given indices. */ DataSet* InteractionData::AddInteractionSet(DataSetList& dsl, DataSet::DataType typeIn, - MetaData const& metaIn, int i0, int i1) + MetaData const& metaIn, int i0, int i1, + DataFile* outfile) { // Check for existing interaction Ipair interaction; @@ -30,6 +32,7 @@ DataSet* InteractionData::AddInteractionSet(DataSetList& dsl, DataSet::DataType mprinterr("Error: Could not allocate data set %s\n", metaIn.PrintName().c_str()); return 0; } + if (outfile != 0) outfile->AddDataSet( ds ); it = setMap_.insert(it, PairType(interaction, ds)); } // TODO check existing set for issues? diff --git a/src/InteractionData.h b/src/InteractionData.h index 269d9148d4..087e00d07f 100644 --- a/src/InteractionData.h +++ b/src/InteractionData.h @@ -2,6 +2,7 @@ #define INC_INTERACTIONDATA_H #include "DataSet.h" // DataType #include +class DataFile; class DataSetList; class MetaData; namespace Cpptraj { @@ -11,7 +12,7 @@ class InteractionData { InteractionData(); /// Add interaction pair data set - DataSet* AddInteractionSet(DataSetList&, DataSet::DataType, MetaData const&, int, int); + DataSet* AddInteractionSet(DataSetList&, DataSet::DataType, MetaData const&, int, int, DataFile*); private: typedef std::pair Ipair; typedef std::pair PairType; From 2f9df3783111313080c8590936329b698e49ce86 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 3 Apr 2024 11:11:35 -0400 Subject: [PATCH 058/200] Start routine for setting up for data sets --- src/CoordCovarMatrix_Half.cpp | 42 +++++++++++++++++++++++++++++++++++ src/CoordCovarMatrix_Half.h | 5 ++++- src/cpptrajdepend | 4 ++-- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index f424c1adaf..a7c02641f3 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -1,6 +1,7 @@ #include "CoordCovarMatrix_Half.h" #include "AtomMask.h" #include "CpptrajStdio.h" +#include "DataSet_1D.h" #include // sqrt /** CONSTRUCTOR */ @@ -14,6 +15,47 @@ void CoordCovarMatrix_Half::clearMat() { } /** Set up array for incoming data sets. */ +int CoordCovarMatrix_Half::SetupMatrix(std::vector const& sets) +{ + int is_periodic = -1; + + for (std::vector::const_iterator it = sets.begin(); it != sets.end(); ++it) + { + if ((*it)->Meta().IsTorsionArray()) { + if (is_periodic == -1) + is_periodic = 1; + else if (is_periodic != 1) { + mprinterr("Error: If one set is not periodic all must be. Set '%s' is periodic.\n", + (*it)->legend()); + return 1; + } + } else { + if (is_periodic == -1) + is_periodic = 0; + else if (is_periodic != 0) { + mprinterr("Error: If one set is periodic all must be. Set '%'s is not periodic.\n", + (*it)->legend()); + return 1; + } + } + } + if (is_periodic) { + mprintf("\tPeriodic data sets detected.\n"); + nelt_ = 2; + } else { + mprintf("\tNon-periodic data sets detected.\n"); + nelt_ = 1; + } + unsigned int matSize = sets.size() * nelt_; + // Matrix - half + covarMatrix_.resize( matSize, 0 ); + + vect_.assign( matSize, 0 ); + + mass_.resize( sets.size(), 1.0 ); + + return 0; +} /** Set up array sizess and masses. */ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index 556e7ed7f8..711238cdba 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -1,6 +1,7 @@ #ifndef INC_COORDCOVARMATRIX_HALF_H #define INC_COORDCOVARMATRIX_HALF_H #include "CoordCovarMatrix.h" +class DataSet_1D; /// Coordinate covariance half (self) matrix class CoordCovarMatrix_Half : public CoordCovarMatrix { public: @@ -10,8 +11,10 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { /// Finish calculating the matrix (normalize, calc - ) int FinishMatrix(); // --------------------------------- - /// Set up half matrix + /// Set up half matrix for coordinates int SetupMatrix(std::vector const&, AtomMask const&, bool); + /// Set up half matrix for data sets + int SetupMatrix(std::vector const&); /// Add selected atoms in Frame to matrix void AddFrameToMatrix(Frame const&, AtomMask const&); /// Add Frame to matrix diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 5ecc034536..79b85bb769 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -194,7 +194,7 @@ Constraints.o : Constraints.cpp ArgList.h Atom.h AtomMask.h AtomType.h Box.h Cha ControlBlock_For.o : ControlBlock_For.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 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_inData.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h CoordCovarMatrix_Full.o : CoordCovarMatrix_Full.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CpptrajStdio.h MaskToken.h Matrix.h Molecule.h NameType.h Residue.h Segment.h SymbolExporting.h Unit.h -CoordCovarMatrix_Half.o : CoordCovarMatrix_Half.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CoordCovarMatrix_Half.h CpptrajStdio.h MaskToken.h Matrix.h Molecule.h NameType.h Residue.h Segment.h SymbolExporting.h Unit.h +CoordCovarMatrix_Half.o : CoordCovarMatrix_Half.cpp ArrayIterator.h AssociatedData.h Atom.h AtomMask.h CoordCovarMatrix.h CoordCovarMatrix_Half.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_1D.h Dimension.h FileIO.h FileName.h MaskToken.h Matrix.h MetaData.h Molecule.h NameType.h Parallel.h Range.h Residue.h Segment.h SymbolExporting.h TextFormat.h Unit.h CoordinateInfo.o : CoordinateInfo.cpp Box.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h Corr.o : Corr.cpp ArrayIterator.h ComplexArray.h Corr.h PubFFT.h Cph.o : Cph.cpp Cph.h NameType.h @@ -375,7 +375,7 @@ Image_List_Mask.o : Image_List_Mask.cpp Atom.h AtomMask.h AtomType.h Box.h Const Image_List_Pair.o : Image_List_Pair.cpp Atom.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajStdio.h FileName.h Frame.h Image_List.h Image_List_Pair.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.h Vec3.h Image_List_Unit.o : Image_List_Unit.cpp Atom.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajStdio.h FileName.h Frame.h Image_List.h Image_List_Unit.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.h Vec3.h InputTrajCommon.o : InputTrajCommon.cpp CpptrajStdio.h FileName.h InputTrajCommon.h TrajFrameCounter.h -InteractionData.o : InteractionData.cpp AssociatedData.h Atom.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h FileIO.h FileName.h Frame.h InteractionData.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 +InteractionData.o : InteractionData.cpp AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h FileIO.h FileName.h FileTypes.h Frame.h InteractionData.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 KDE.o : KDE.cpp AssociatedData.h Constants.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_1D.h DataSet_double.h Dimension.h FileIO.h FileName.h HistBin.h KDE.h MetaData.h Parallel.h Range.h TextFormat.h LeapInterface.o : LeapInterface.cpp ArgList.h Atom.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h File_TempName.h Frame.h LeapInterface.h MaskToken.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h Topology.h TypeNameHolder.h Unit.h Vec3.h MapAtom.o : MapAtom.cpp Atom.h MapAtom.h NameType.h SymbolExporting.h From c4d3e6dceed776d0385f294980f384c5adf4c475 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 3 Apr 2024 11:23:26 -0400 Subject: [PATCH 059/200] Add data from data sets --- src/CoordCovarMatrix_Half.cpp | 40 +++++++++++++++++++++++++++++++++++ src/CoordCovarMatrix_Half.h | 2 ++ src/cpptrajdepend | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index a7c02641f3..9551692917 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -1,5 +1,6 @@ #include "CoordCovarMatrix_Half.h" #include "AtomMask.h" +#include "Constants.h" #include "CpptrajStdio.h" #include "DataSet_1D.h" #include // sqrt @@ -72,6 +73,45 @@ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, return 0; } +/** Add data from sets to the matrix. */ +void CoordCovarMatrix_Half::AddDataToMatrix(std::vector const& sets) +{ + // TODO check empty input array + // Check that sets have same size + unsigned int maxFrames = sets.front()->Size(); + for (std::vector::const_iterator it = sets.begin(); it != sets.end(); ++it) + { + if ((*it)->Size() != maxFrames) { + mprinterr("Error: Set '%s' does not have same size (%zu) as first set (%u)\n", + (*it)->legend(), (*it)->Size(), maxFrames); + return; + } + } + Darray arrayIn; + arrayIn.resize( sets.size() * nelt_ ); + if (nelt_ == 2) { + for (unsigned int idx = 0; idx < maxFrames; idx++) { + unsigned int jdx = 0; + for (std::vector::const_iterator it = sets.begin(); it != sets.end(); ++it, jdx += 2) + { + double dval = (*it)->Dval(idx) * Constants::DEGRAD; + arrayIn[jdx ] = cos( dval ); + arrayIn[jdx+1] = sin( dval ); + } + AddToMatrix(arrayIn); + } + } else if (nelt_ == 1) { + for (unsigned int idx = 0; idx < maxFrames; idx++) { + for (unsigned int jdx = 0; jdx < sets.size(); jdx++) { + arrayIn[jdx] = sets[jdx]->Dval(idx); + } + } + } else { + // Sanity check + mprinterr("Internal Error: CoordCovarMatrix_Half::AddDataToMatrix(): Unsupported nelt %u\n", nelt_); + } +} + /** Add selected atoms in given Frame to the matrix. */ void CoordCovarMatrix_Half::AddFrameToMatrix(Frame const& frameIn, AtomMask const& maskIn) { diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index 711238cdba..48c11e3692 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -19,6 +19,8 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { void AddFrameToMatrix(Frame const&, AtomMask const&); /// Add Frame to matrix //void AddFrameToMatrix(Frame const&); + /// Add data in sets to matrix + void AddDataToMatrix(std::vector const&); private: /// Add elements to the matrix void AddToMatrix(Darray const&); diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 79b85bb769..18cb9457c9 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -194,7 +194,7 @@ Constraints.o : Constraints.cpp ArgList.h Atom.h AtomMask.h AtomType.h Box.h Cha ControlBlock_For.o : ControlBlock_For.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 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_inData.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h CoordCovarMatrix.o : CoordCovarMatrix.cpp ArrayIterator.h Atom.h AtomMask.h Box.h CoordCovarMatrix.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h FileIO.h FileName.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h Molecule.h NameType.h Parallel.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h Unit.h Vec3.h CoordCovarMatrix_Full.o : CoordCovarMatrix_Full.cpp ArrayIterator.h Atom.h AtomMask.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CpptrajStdio.h MaskToken.h Matrix.h Molecule.h NameType.h Residue.h Segment.h SymbolExporting.h Unit.h -CoordCovarMatrix_Half.o : CoordCovarMatrix_Half.cpp ArrayIterator.h AssociatedData.h Atom.h AtomMask.h CoordCovarMatrix.h CoordCovarMatrix_Half.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_1D.h Dimension.h FileIO.h FileName.h MaskToken.h Matrix.h MetaData.h Molecule.h NameType.h Parallel.h Range.h Residue.h Segment.h SymbolExporting.h TextFormat.h Unit.h +CoordCovarMatrix_Half.o : CoordCovarMatrix_Half.cpp ArrayIterator.h AssociatedData.h Atom.h AtomMask.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Half.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_1D.h Dimension.h FileIO.h FileName.h MaskToken.h Matrix.h MetaData.h Molecule.h NameType.h Parallel.h Range.h Residue.h Segment.h SymbolExporting.h TextFormat.h Unit.h CoordinateInfo.o : CoordinateInfo.cpp Box.h CoordinateInfo.h CpptrajStdio.h Matrix_3x3.h Parallel.h ReplicaDimArray.h Vec3.h Corr.o : Corr.cpp ArrayIterator.h ComplexArray.h Corr.h PubFFT.h Cph.o : Cph.cpp Cph.h NameType.h From 7cd9e14851576d1ca093d08ed16d15d8c86adb54 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 3 Apr 2024 14:32:19 -0400 Subject: [PATCH 060/200] Test using data sets --- src/Analysis_TICA.cpp | 77 +++++++++++++++++++++++++++++++++++----- src/Analysis_TICA.h | 9 ++++- src/Array1D.h | 2 ++ src/CoordCovarMatrix.cpp | 9 +++-- src/CoordCovarMatrix.h | 4 ++- src/cpptrajdepend | 2 +- 6 files changed, 90 insertions(+), 13 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 987e4e0d99..939e0cccaa 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -2,6 +2,7 @@ #include "CoordCovarMatrix_Full.h" #include "CoordCovarMatrix_Half.h" #include "CpptrajStdio.h" +#include "DataSet_1D.h" /** CONSTRUCTOR */ Analysis_TICA::Analysis_TICA() : @@ -22,13 +23,33 @@ void Analysis_TICA::Help() const { // Analysis_TICA::Setup() Analysis::RetType Analysis_TICA::Setup(ArgList& analyzeArgs, AnalysisSetup& setup, int debugIn) { - // Attempt to get coords dataset from datasetlist + // Attempt to get coords dataset or datasets from datasetlist + TgtTraj_ = 0; + sets_.clear(); std::string setname = analyzeArgs.GetStringKey("crdset"); - TgtTraj_ = (DataSet_Coords*)setup.DSL().FindCoordsSet( setname ); - if (TgtTraj_ == 0) { - mprinterr("Error: Could not locate COORDS set corresponding to %s\n", - setname.c_str()); - Help(); + std::string dataarg = analyzeArgs.GetStringKey("data"); + if (!setname.empty() && !dataarg.empty()) { + mprinterr("Error: Specify either 'crdset' or 'data', not both.\n"); + return Analysis::ERR; + } + if (!setname.empty()) { + TgtTraj_ = (DataSet_Coords*)setup.DSL().FindCoordsSet( setname ); + if (TgtTraj_ == 0) { + mprinterr("Error: Could not locate COORDS set corresponding to %s\n", + setname.c_str()); + Help(); + return Analysis::ERR; + } + } else if (!dataarg.empty()) { + while (!dataarg.empty()) { + if (sets_.AddSetsFromArgs( ArgList(dataarg), setup.DSL() )) { + mprinterr("Error: Could not add data sets using argument '%s'\n", dataarg.c_str()); + return Analysis::ERR; + } + dataarg = analyzeArgs.GetStringKey("data"); + } + } else { + mprinterr("Error: Must specify either 'crdset' or 'data'.\n"); return Analysis::ERR; } // Other keywords @@ -64,7 +85,14 @@ Analysis::RetType Analysis_TICA::Setup(ArgList& analyzeArgs, AnalysisSetup& setu // Print analysis info mprintf(" TICA: Time independent correlation analysis.\n"); - mprintf("\tUsing coordinates from set '%s'\n", TgtTraj_->legend()); + if (TgtTraj_ != 0) + mprintf("\tUsing coordinates from set '%s'\n", TgtTraj_->legend()); + if (!sets_.empty()) { + mprintf("\tUsing %zu data sets:", sets_.size()); + for (Array1D::const_iterator it = sets_.begin(); it != sets_.end(); ++it) + mprintf(" %s", (*it)->legend()); + mprintf("\n"); + } mprintf("\tUsing atoms selected by mask '%s'\n", mask1_.MaskString()); mprintf("\tTime lag: %i frames.\n", lag_); if (useMass_) @@ -81,6 +109,36 @@ Analysis::RetType Analysis_TICA::Setup(ArgList& analyzeArgs, AnalysisSetup& setu // Analysis_TICA::Analyze() Analysis::RetType Analysis_TICA::Analyze() { + if (TgtTraj_ != 0) + return analyze_crdset(); + else if (!sets_.empty()) + return analyze_datasets(); + + return Analysis::ERR; +} + +/** Analyze multiple 1D data sets. */ +Analysis::RetType Analysis_TICA::analyze_datasets() { + // Matrix - half + CoordCovarMatrix_Half covarMatrix; + if (covarMatrix.SetupMatrix( sets_.Array() )) { + mprinterr("Error: Could not set up C0 matrix for data sets.\n"); + return Analysis::ERR; + } + covarMatrix.AddDataToMatrix( sets_.Array() ); + // Normalize + if (covarMatrix.FinishMatrix()) { + mprinterr("Error: Could not normalize coordinate covariance matrix for C0.\n"); + return Analysis::ERR; + } + // DEBUG PRINT + covarMatrix.DebugPrint("C0", *debugC0_, " %12.6f"); + + return Analysis::OK; +} + +/** Analyze coordinates data set. */ +Analysis::RetType Analysis_TICA::analyze_crdset() { unsigned int Nframes = TgtTraj_->Size(); if (Nframes < 1) { mprinterr("Error: No frames to analyze.\n"); @@ -114,7 +172,10 @@ Analysis::RetType Analysis_TICA::Analyze() { //Frame coords1 = coords0; // Matrix - half CoordCovarMatrix_Half covarMatrix; - covarMatrix.SetupMatrix(TgtTraj_->Top().Atoms(), mask1_, useMass_ ); + if (covarMatrix.SetupMatrix(TgtTraj_->Top().Atoms(), mask1_, useMass_ )) { + mprinterr("Error: Could not set up C0 matrix for '%s'.\n", TgtTraj_->legend()); + return Analysis::ERR; + } // Loop over frames for (unsigned int frm0 = 0; frm0 < Nframes; frm0++) { //mprintf("DEBUG: Frame %i\n", frm0); diff --git a/src/Analysis_TICA.h b/src/Analysis_TICA.h index 2d8af02246..179796a964 100644 --- a/src/Analysis_TICA.h +++ b/src/Analysis_TICA.h @@ -1,6 +1,7 @@ #ifndef INC_ANALYSIS_TICA_H #define INC_ANALYSIS_TICA_H #include "Analysis.h" +#include "Array1D.h" /// class Analysis_TICA : public Analysis { public: @@ -11,12 +12,18 @@ class Analysis_TICA : public Analysis { Analysis::RetType Setup(ArgList&, AnalysisSetup&, int); Analysis::RetType Analyze(); private: - DataSet_Coords* TgtTraj_; ///< Input trajectory + /// Analyze using coordinates data set (TgtTraj_) + Analysis::RetType analyze_crdset(); + /// Analyze using 1D data sets (sets_) + Analysis::RetType analyze_datasets(); + + DataSet_Coords* TgtTraj_; ///< Input trajectory (crdset) int lag_; ///< TICA time lag AtomMask mask1_; ///< Atoms to use in matrix calc AtomMask mask2_; ///< Second atom mask for debugging full covar matrix bool useMass_; ///< Control whether to mass-weight CpptrajFile* debugC0_; ///< Debug output for C0 CpptrajFile* debugCT_; ///< Debug output for CT + Array1D sets_; ///< 1D data sets (data) }; #endif diff --git a/src/Array1D.h b/src/Array1D.h index e3da93a8d2..84a531fe24 100644 --- a/src/Array1D.h +++ b/src/Array1D.h @@ -25,6 +25,8 @@ class Array1D { int AddDataSets(DataSetList const&); int AddTorsionSets(DataSetList const&); int AddSetsFromArgs(ArgList const&, DataSetList const&); + /// \return the internal array + std::vector const& Array() const { return array_; } private: std::vector array_; }; diff --git a/src/CoordCovarMatrix.cpp b/src/CoordCovarMatrix.cpp index d9b051d0d8..9cdf2404a1 100644 --- a/src/CoordCovarMatrix.cpp +++ b/src/CoordCovarMatrix.cpp @@ -36,13 +36,18 @@ void CoordCovarMatrix::set_mass_array(Darray& mass, std::vector const& ato } } -/** Debug print to file */ +/** Debug print to file with default format. */ void CoordCovarMatrix::DebugPrint(const char* desc, CpptrajFile& outfile) const { + DebugPrint(desc, outfile, " %6.3f"); +} + +/** Debug print to file */ +void CoordCovarMatrix::DebugPrint(const char* desc, CpptrajFile& outfile, const char* fmt) const { if (desc != 0) outfile.Printf("DEBUG: CoordCovarMatrix: %s\n", desc); for (unsigned int row = 0; row < covarMatrix_.Nrows(); row++) { for (unsigned int col = 0; col < covarMatrix_.Ncols(); col++) { - outfile.Printf(" %6.3f", covarMatrix_.element(col, row)); + outfile.Printf(fmt, covarMatrix_.element(col, row)); } outfile.Printf("\n"); } diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 0a3c5a381e..277fc71b8a 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -20,8 +20,10 @@ class CoordCovarMatrix { /// Clear the matrix void Clear(); - /// Print matrix elements to STDOUT for debug + /// Print matrix elements to STDOUT for debug with default format void DebugPrint(const char*, CpptrajFile&) const; + /// Print matrix elements to STDOUT for debug with given format + void DebugPrint(const char*, CpptrajFile&, const char*) const; protected: typedef Matrix MatType; typedef std::vector Darray; diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 18cb9457c9..b0da504eae 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -132,7 +132,7 @@ Analysis_Spline.o : Analysis_Spline.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.o : Analysis_State.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Statistics.o : Analysis_Statistics.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Statistics.h ArgList.h Array1D.h AssociatedData.h AssociatedData_NOE.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 DataSet_float.h DataSet_integer.h DataSet_string.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 Analysis_TI.o : Analysis_TI.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TI.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 DataSet_Mesh.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 Segment.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordCovarMatrix_Half.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordCovarMatrix_Half.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.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 Analysis_Timecorr.o : Analysis_Timecorr.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Timecorr.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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 PubFFT.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 Analysis_VectorMath.o : Analysis_VectorMath.cpp ActionState.h Analysis.h AnalysisState.h Analysis_VectorMath.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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_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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Wavelet.o : Analysis_Wavelet.cpp ActionFrameCounter.h ActionState.h Analysis.h AnalysisState.h Analysis_Wavelet.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterMap.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixFlt.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ProgressBar.h ProgressTimer.h PubFFT.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h From ec91068a9f249dc9c9647007b9f5837647c4b1ef Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 3 Apr 2024 14:33:47 -0400 Subject: [PATCH 061/200] Fix output --- src/Analysis_TICA.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 939e0cccaa..f042286eec 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -85,20 +85,21 @@ Analysis::RetType Analysis_TICA::Setup(ArgList& analyzeArgs, AnalysisSetup& setu // Print analysis info mprintf(" TICA: Time independent correlation analysis.\n"); - if (TgtTraj_ != 0) + if (TgtTraj_ != 0) { mprintf("\tUsing coordinates from set '%s'\n", TgtTraj_->legend()); + mprintf("\tUsing atoms selected by mask '%s'\n", mask1_.MaskString()); + if (useMass_) + mprintf("\tMass-weighted.\n"); + else + mprintf("\tNot mass-weighted.\n"); + } if (!sets_.empty()) { mprintf("\tUsing %zu data sets:", sets_.size()); for (Array1D::const_iterator it = sets_.begin(); it != sets_.end(); ++it) mprintf(" %s", (*it)->legend()); mprintf("\n"); } - mprintf("\tUsing atoms selected by mask '%s'\n", mask1_.MaskString()); mprintf("\tTime lag: %i frames.\n", lag_); - if (useMass_) - mprintf("\tMass-weighted.\n"); - else - mprintf("\tNot mass-weighted.\n"); if (debugC0_ != 0) mprintf("\tDebug C0 output to %s\n", debugC0_->Filename().full()); if (debugCT_ != 0) From ed29d097cc5e72fa807df48cc4b40832f0523373 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 3 Apr 2024 14:44:26 -0400 Subject: [PATCH 062/200] Actually add to the matrix --- src/CoordCovarMatrix_Half.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 9551692917..c4b3e838b2 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -105,6 +105,7 @@ void CoordCovarMatrix_Half::AddDataToMatrix(std::vector const& sets for (unsigned int jdx = 0; jdx < sets.size(); jdx++) { arrayIn[jdx] = sets[jdx]->Dval(idx); } + AddToMatrix(arrayIn); } } else { // Sanity check From 41ebe075d30133bfd5a250d1660d38859e10a958 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 3 Apr 2024 16:07:49 -0400 Subject: [PATCH 063/200] Add mean debug --- src/CoordCovarMatrix_Half.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index c4b3e838b2..908f0e1d68 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -198,6 +198,12 @@ int CoordCovarMatrix_Half::FinishMatrix() { *it *= norm; for (MatType::iterator it = covarMatrix_.begin(); it != covarMatrix_.end(); ++it) *it *= norm; + // DEBUG print mean + CpptrajFile outfile; + outfile.OpenWrite("debug.mean.dat"); + for (Darray::iterator it = vect_.begin(); it != vect_.end(); ++it) + outfile.Printf("%12.6f\n", *it); + outfile.CloseFile(); // Calc - //for (int k = 0; k < mask1_.Nselected(); k++) { // vect2[k][0] -= (vect[k][0] * vect[k][0]); From 726c93b33a2a479c978d4dfecad8f0b4d9b1ad68 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 5 Apr 2024 09:35:08 -0400 Subject: [PATCH 064/200] Use typedef --- src/CoordCovarMatrix.h | 2 ++ src/CoordCovarMatrix_Half.cpp | 10 +++++----- src/CoordCovarMatrix_Half.h | 5 ++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/CoordCovarMatrix.h b/src/CoordCovarMatrix.h index 277fc71b8a..29bbee3bf5 100644 --- a/src/CoordCovarMatrix.h +++ b/src/CoordCovarMatrix.h @@ -5,6 +5,7 @@ class Atom; class AtomMask; class CpptrajFile; +class DataSet_1D; class Frame; /// Coordinate covariance matrix abstract base class class CoordCovarMatrix { @@ -27,6 +28,7 @@ class CoordCovarMatrix { protected: typedef Matrix MatType; typedef std::vector Darray; + typedef std::vector DSarray; /// clear internal variables virtual void clearMat() = 0; diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 908f0e1d68..4bace8b6b2 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -16,11 +16,11 @@ void CoordCovarMatrix_Half::clearMat() { } /** Set up array for incoming data sets. */ -int CoordCovarMatrix_Half::SetupMatrix(std::vector const& sets) +int CoordCovarMatrix_Half::SetupMatrix(DSarray const& sets) { int is_periodic = -1; - for (std::vector::const_iterator it = sets.begin(); it != sets.end(); ++it) + for (DSarray::const_iterator it = sets.begin(); it != sets.end(); ++it) { if ((*it)->Meta().IsTorsionArray()) { if (is_periodic == -1) @@ -74,12 +74,12 @@ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, } /** Add data from sets to the matrix. */ -void CoordCovarMatrix_Half::AddDataToMatrix(std::vector const& sets) +void CoordCovarMatrix_Half::AddDataToMatrix(DSarray const& sets) { // TODO check empty input array // Check that sets have same size unsigned int maxFrames = sets.front()->Size(); - for (std::vector::const_iterator it = sets.begin(); it != sets.end(); ++it) + for (DSarray::const_iterator it = sets.begin(); it != sets.end(); ++it) { if ((*it)->Size() != maxFrames) { mprinterr("Error: Set '%s' does not have same size (%zu) as first set (%u)\n", @@ -92,7 +92,7 @@ void CoordCovarMatrix_Half::AddDataToMatrix(std::vector const& sets if (nelt_ == 2) { for (unsigned int idx = 0; idx < maxFrames; idx++) { unsigned int jdx = 0; - for (std::vector::const_iterator it = sets.begin(); it != sets.end(); ++it, jdx += 2) + for (DSarray::const_iterator it = sets.begin(); it != sets.end(); ++it, jdx += 2) { double dval = (*it)->Dval(idx) * Constants::DEGRAD; arrayIn[jdx ] = cos( dval ); diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index 48c11e3692..a63d412509 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -1,7 +1,6 @@ #ifndef INC_COORDCOVARMATRIX_HALF_H #define INC_COORDCOVARMATRIX_HALF_H #include "CoordCovarMatrix.h" -class DataSet_1D; /// Coordinate covariance half (self) matrix class CoordCovarMatrix_Half : public CoordCovarMatrix { public: @@ -14,13 +13,13 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { /// Set up half matrix for coordinates int SetupMatrix(std::vector const&, AtomMask const&, bool); /// Set up half matrix for data sets - int SetupMatrix(std::vector const&); + int SetupMatrix(DSarray const&); /// Add selected atoms in Frame to matrix void AddFrameToMatrix(Frame const&, AtomMask const&); /// Add Frame to matrix //void AddFrameToMatrix(Frame const&); /// Add data in sets to matrix - void AddDataToMatrix(std::vector const&); + void AddDataToMatrix(DSarray const&); private: /// Add elements to the matrix void AddToMatrix(Darray const&); From d6e9edb8a0f785e9a52c60fc386a5564890e5ffc Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 8 Apr 2024 08:54:04 -0400 Subject: [PATCH 065/200] Add temporary checks --- test/Test_TICA/RunTest.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Test_TICA/RunTest.sh b/test/Test_TICA/RunTest.sh index 8290840b36..e085e76d12 100755 --- a/test/Test_TICA/RunTest.sh +++ b/test/Test_TICA/RunTest.sh @@ -24,6 +24,8 @@ runanalysis tica crdset TZ2 mask :1-3@N,CA mask2 :1-3@C,O lag 1 debugct ticadebu list dataset EOF RunCpptraj "TICA test." +diff M1.dat ticadebug.m1.dat +diff M2.dat ticadebug.m2.dat EndTest exit 0 From 54f6eeb486cec2301617f5fd7de17bcd1838f0bf Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 8 Apr 2024 09:24:32 -0400 Subject: [PATCH 066/200] Start a test function to try and directly mimic moment_XXXY --- src/CoordCovarMatrix_Half.cpp | 48 +++++++++++++++++++++++++++++++++++ src/CoordCovarMatrix_Half.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 4bace8b6b2..5066526830 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -73,9 +73,57 @@ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, return 0; } +/// FOR DEBUG +static inline void printDarray(const char* desc, std::vector const& arrayIn) +{ + static const char* fmt = "%15.8f"; + mprintf("DEBUG: %s: [", desc); + int col = 0; + for (std::vector::const_iterator it = arrayIn.begin(); it != arrayIn.end(); ++it) + { + mprintf(fmt, *it); + if ( (it+1) == arrayIn.end() ) mprintf("]"); + col++; + if (col==4) { + mprintf("\n"); + col = 0; + } + } + if (col != 0) + mprintf("\n"); +} + +/** Add data for instantaneous covariance and lagged covariance arrays */ +void CoordCovarMatrix_Half::AddDataToMatrix_C0CT(DSarray const& sets) +{ + // Check that sets have same size + unsigned int maxFrames = sets.front()->Size(); + for (DSarray::const_iterator it = sets.begin(); it != sets.end(); ++it) + { + if ((*it)->Size() != maxFrames) { + mprinterr("Error: Set '%s' does not have same size (%zu) as first set (%u)\n", + (*it)->legend(), (*it)->Size(), maxFrames); + return; + } + } + Darray sumX( sets.size() * nelt_, 0 ); + if (nelt_ == 2) { + mprinterr("Internal Error: CoordCovarMatrix_Half::AddDataToMatrix_C0CT(): Not implemented.\n"); + return; + } else if (nelt_ == 1) { + for (unsigned int idx = 0; idx < maxFrames; idx++) { + for (unsigned int jdx = 0; jdx < sets.size(); jdx++) { + sumX[jdx] += sets[jdx]->Dval(idx); + } + } + printDarray("sx_raw", sumX); + } +} + /** Add data from sets to the matrix. */ void CoordCovarMatrix_Half::AddDataToMatrix(DSarray const& sets) { + AddDataToMatrix_C0CT(sets); // FIXME // TODO check empty input array // Check that sets have same size unsigned int maxFrames = sets.front()->Size(); diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index a63d412509..e79c7c831c 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -20,6 +20,8 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { //void AddFrameToMatrix(Frame const&); /// Add data in sets to matrix void AddDataToMatrix(DSarray const&); + /// Add data in sets to instantaneous and time-lagged matrices + void AddDataToMatrix_C0CT(DSarray const&); private: /// Add elements to the matrix void AddToMatrix(Darray const&); From 7e71371b87a220c77389fdcfce731d1783e84179 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 8 Apr 2024 09:56:44 -0400 Subject: [PATCH 067/200] Move C0CT routine to into TICA itself --- src/Analysis_TICA.cpp | 76 +++++++++++++++++++++++++++++++++++ src/Analysis_TICA.h | 5 +++ src/CoordCovarMatrix_Half.cpp | 48 ---------------------- src/CoordCovarMatrix_Half.h | 2 - 4 files changed, 81 insertions(+), 50 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index f042286eec..5ca451ef97 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -118,8 +118,84 @@ Analysis::RetType Analysis_TICA::Analyze() { return Analysis::ERR; } +/// FOR DEBUG +static inline void printDarray(const char* desc, std::vector const& arrayIn) +{ + static const char* fmt = "%15.8f"; + mprintf("DEBUG: %s: [", desc); + int col = 0; + for (std::vector::const_iterator it = arrayIn.begin(); it != arrayIn.end(); ++it) + { + mprintf(fmt, *it); + if ( (it+1) == arrayIn.end() ) mprintf("]"); + col++; + if (col==4) { + mprintf("\n"); + col = 0; + } + } + if (col != 0) + mprintf("\n"); +} + +/// Calculate sum over sets +static inline void calculate_sum(std::vector& sumX, std::vector const& sets, unsigned int nelt_, + unsigned int startFrame, unsigned int endFrame) +{ + sumX.assign( sets.size() * nelt_, 0 ); + + if (nelt_ == 2) { + mprinterr("Internal Error: CoordCovarMatrix_Half::AddDataToMatrix_C0CT(): Not implemented.\n"); + return; + } else if (nelt_ == 1) { + for (unsigned int idx = startFrame; idx < endFrame; idx++) { + for (unsigned int jdx = 0; jdx < sets.size(); jdx++) { + sumX[jdx] += sets[jdx]->Dval(idx); + } + } + } +} + +/** Calculate instantaneous covariance and lagged covariance arrays */ +int Analysis_TICA::calculateCovariance_C0CT(DSarray const& sets) +const +{ + static unsigned int nelt_ = 1; // FIXME + // Check that sets have same size + unsigned int maxFrames = sets.front()->Size(); + for (DSarray::const_iterator it = sets.begin(); it != sets.end(); ++it) + { + if ((*it)->Size() != maxFrames) { + mprinterr("Error: Set '%s' does not have same size (%zu) as first set (%u)\n", + (*it)->legend(), (*it)->Size(), maxFrames); + return 1; + } + } + // Calculate start and end times for C0 and CT + if ( (unsigned int)lag_ >= maxFrames ) { + mprinterr("Error: lag %i >= max frames %u\n", lag_, maxFrames); + return 1; + } + unsigned int c0end = maxFrames - (unsigned int)lag_; + mprintf("DEBUG: C0 start = %u end = %u\n", 0, c0end); + unsigned int ctstart = (unsigned int)lag_; + mprintf("DEBUG: CT start = %u end = %u\n", ctstart, maxFrames); + + Darray sumX; + calculate_sum(sumX, sets, nelt_, 0, c0end); + printDarray("sx_raw", sumX); + + Darray sumY; + calculate_sum(sumY, sets, nelt_, ctstart, maxFrames); + printDarray("sy_raw", sumY); + + return 0; +} + /** Analyze multiple 1D data sets. */ Analysis::RetType Analysis_TICA::analyze_datasets() { + calculateCovariance_C0CT( sets_.Array() ); + // Matrix - half CoordCovarMatrix_Half covarMatrix; if (covarMatrix.SetupMatrix( sets_.Array() )) { diff --git a/src/Analysis_TICA.h b/src/Analysis_TICA.h index 179796a964..08e1f369a6 100644 --- a/src/Analysis_TICA.h +++ b/src/Analysis_TICA.h @@ -12,10 +12,15 @@ class Analysis_TICA : public Analysis { Analysis::RetType Setup(ArgList&, AnalysisSetup&, int); Analysis::RetType Analyze(); private: + typedef std::vector DSarray; + typedef std::vector Darray; + /// Analyze using coordinates data set (TgtTraj_) Analysis::RetType analyze_crdset(); /// Analyze using 1D data sets (sets_) Analysis::RetType analyze_datasets(); + /// Calculate instantaneous and lagged covariance matrices + int calculateCovariance_C0CT(DSarray const&) const; DataSet_Coords* TgtTraj_; ///< Input trajectory (crdset) int lag_; ///< TICA time lag diff --git a/src/CoordCovarMatrix_Half.cpp b/src/CoordCovarMatrix_Half.cpp index 5066526830..4bace8b6b2 100644 --- a/src/CoordCovarMatrix_Half.cpp +++ b/src/CoordCovarMatrix_Half.cpp @@ -73,57 +73,9 @@ int CoordCovarMatrix_Half::SetupMatrix(std::vector const& atoms, return 0; } -/// FOR DEBUG -static inline void printDarray(const char* desc, std::vector const& arrayIn) -{ - static const char* fmt = "%15.8f"; - mprintf("DEBUG: %s: [", desc); - int col = 0; - for (std::vector::const_iterator it = arrayIn.begin(); it != arrayIn.end(); ++it) - { - mprintf(fmt, *it); - if ( (it+1) == arrayIn.end() ) mprintf("]"); - col++; - if (col==4) { - mprintf("\n"); - col = 0; - } - } - if (col != 0) - mprintf("\n"); -} - -/** Add data for instantaneous covariance and lagged covariance arrays */ -void CoordCovarMatrix_Half::AddDataToMatrix_C0CT(DSarray const& sets) -{ - // Check that sets have same size - unsigned int maxFrames = sets.front()->Size(); - for (DSarray::const_iterator it = sets.begin(); it != sets.end(); ++it) - { - if ((*it)->Size() != maxFrames) { - mprinterr("Error: Set '%s' does not have same size (%zu) as first set (%u)\n", - (*it)->legend(), (*it)->Size(), maxFrames); - return; - } - } - Darray sumX( sets.size() * nelt_, 0 ); - if (nelt_ == 2) { - mprinterr("Internal Error: CoordCovarMatrix_Half::AddDataToMatrix_C0CT(): Not implemented.\n"); - return; - } else if (nelt_ == 1) { - for (unsigned int idx = 0; idx < maxFrames; idx++) { - for (unsigned int jdx = 0; jdx < sets.size(); jdx++) { - sumX[jdx] += sets[jdx]->Dval(idx); - } - } - printDarray("sx_raw", sumX); - } -} - /** Add data from sets to the matrix. */ void CoordCovarMatrix_Half::AddDataToMatrix(DSarray const& sets) { - AddDataToMatrix_C0CT(sets); // FIXME // TODO check empty input array // Check that sets have same size unsigned int maxFrames = sets.front()->Size(); diff --git a/src/CoordCovarMatrix_Half.h b/src/CoordCovarMatrix_Half.h index e79c7c831c..a63d412509 100644 --- a/src/CoordCovarMatrix_Half.h +++ b/src/CoordCovarMatrix_Half.h @@ -20,8 +20,6 @@ class CoordCovarMatrix_Half : public CoordCovarMatrix { //void AddFrameToMatrix(Frame const&); /// Add data in sets to matrix void AddDataToMatrix(DSarray const&); - /// Add data in sets to instantaneous and time-lagged matrices - void AddDataToMatrix_C0CT(DSarray const&); private: /// Add elements to the matrix void AddToMatrix(Darray const&); From 3a58272a218df5b9361d86d20c0bf66cf81e473d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 9 Apr 2024 09:18:29 -0400 Subject: [PATCH 068/200] Implement centering --- src/Analysis_TICA.cpp | 81 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 5ca451ef97..0525bd45ea 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -119,9 +119,9 @@ Analysis::RetType Analysis_TICA::Analyze() { } /// FOR DEBUG -static inline void printDarray(const char* desc, std::vector const& arrayIn) +static inline void printDarray(const char* desc, std::vector const& arrayIn, const char* fmt) { - static const char* fmt = "%15.8f"; + //static const char* fmt = "%15.8f"; mprintf("DEBUG: %s: [", desc); int col = 0; for (std::vector::const_iterator it = arrayIn.begin(); it != arrayIn.end(); ++it) @@ -138,8 +138,10 @@ static inline void printDarray(const char* desc, std::vector const& arra mprintf("\n"); } -/// Calculate sum over sets -static inline void calculate_sum(std::vector& sumX, std::vector const& sets, unsigned int nelt_, +/// Calculate sum over each set TODO weights +static inline void calculate_sum(std::vector& sumX, + std::vector const& sets, + unsigned int nelt_, unsigned int startFrame, unsigned int endFrame) { sumX.assign( sets.size() * nelt_, 0 ); @@ -148,14 +150,29 @@ static inline void calculate_sum(std::vector& sumX, std::vectorDval(idx); } } } } +/// Subtract the set mean from every element of the set +static inline void subtract_mean(std::vector& out, + DataSet_1D* in, + unsigned int nelt_, + double total_weight, + double sumX, + unsigned int startFrame, unsigned int endFrame) +{ + out.clear(); + out.reserve(endFrame - startFrame); + double mean = sumX / total_weight; + for (unsigned int idx = startFrame; idx != endFrame; idx++) + out.push_back( in->Dval(idx) - mean ); +} + /** Calculate instantaneous covariance and lagged covariance arrays */ int Analysis_TICA::calculateCovariance_C0CT(DSarray const& sets) const @@ -183,11 +200,59 @@ const Darray sumX; calculate_sum(sumX, sets, nelt_, 0, c0end); - printDarray("sx_raw", sumX); + printDarray("sx_raw", sumX, "%15.8f"); Darray sumY; calculate_sum(sumY, sets, nelt_, ctstart, maxFrames); - printDarray("sy_raw", sumY); + printDarray("sy_raw", sumY, "%15.8f"); + + // Sanity check + if (sumX.size() != sumY.size()) { + mprinterr("Internal Error: Analysis_TICA::calculateCovariance_C0CT(): sumX size != sumY size\n"); + return 1; + } + + // Calculate effective sum (symmetric) + Darray sx; + sx.reserve( sumX.size() ); + for (unsigned int jdx = 0; jdx != sumX.size(); jdx++) + sx.push_back( sumX[jdx] + sumY[jdx] ); + + // Total weight is times 2 because symmetric + //double total_weight = 0; + //for (Darray::const_iterator it = weights.begin(); it != weights.end(); ++it) + // total_weight += *it; + //total_weight *= 2; + double total_weight = c0end * 2; + mprintf("DEBUG: Total weight= %f\n", total_weight); + + // Center + Darray sx_centered, sy_centered; + sx_centered.reserve( sumX.size() ); + sy_centered.reserve( sumY.size() ); + for (unsigned int idx = 0; idx != sumX.size(); idx++) + { + sx_centered.push_back( sumX[idx] - (0.5 * sx[idx]) ); + sy_centered.push_back( sumY[idx] - (0.5 * sx[idx]) ); + } + printDarray("sx_raw_centered", sx_centered, "%16.8e"); + printDarray("sy_raw_centered", sy_centered, "%16.8e"); + + // Remove mean + typedef std::vector DDArray; + DDArray CenteredX(sets.size()); + DDArray CenteredY(sets.size()); + Darray tmpx, tmpy; // DEBUG FIXME + // Because symmetric, sy = sx + Darray const& sy = sx; + for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { + subtract_mean(CenteredX[jdx], sets[jdx], nelt_, total_weight, sx[jdx], 0, c0end); + subtract_mean(CenteredY[jdx], sets[jdx], nelt_, total_weight, sy[jdx], ctstart, maxFrames); + tmpx.push_back( CenteredX[jdx][0] ); // DEBUG FIXME + tmpy.push_back( CenteredY[jdx][0] ); // DEBUG FIXME + } + printDarray("X0", tmpx, "%16.8e"); + printDarray("Y0", tmpy, "%16.8e"); return 0; } From 4aeb35f50de7d50366faddb93e9d83eeda40046c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 9 Apr 2024 12:38:23 -0400 Subject: [PATCH 069/200] Start calculating the XXYY matrix --- src/Analysis_TICA.cpp | 113 ++++++++++++++++++++++++++++++++++++++---- src/cpptrajdepend | 2 +- 2 files changed, 105 insertions(+), 10 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 0525bd45ea..fa595c287c 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -3,6 +3,7 @@ #include "CoordCovarMatrix_Half.h" #include "CpptrajStdio.h" #include "DataSet_1D.h" +#include "DataSet_double.h" /** CONSTRUCTOR */ Analysis_TICA::Analysis_TICA() : @@ -159,18 +160,73 @@ static inline void calculate_sum(std::vector& sumX, } /// Subtract the set mean from every element of the set -static inline void subtract_mean(std::vector& out, - DataSet_1D* in, +static inline void subtract_mean(DataSet_1D* outPtr, + DataSet_1D const* in, unsigned int nelt_, double total_weight, double sumX, unsigned int startFrame, unsigned int endFrame) { - out.clear(); - out.reserve(endFrame - startFrame); + DataSet_double& out = static_cast( *outPtr ); + //out.clear(); + out.Allocate(DataSet::SizeArray(1, endFrame - startFrame)); + //out.reserve(endFrame - startFrame); double mean = sumX / total_weight; - for (unsigned int idx = startFrame; idx != endFrame; idx++) - out.push_back( in->Dval(idx) - mean ); + for (unsigned int idx = startFrame; idx != endFrame; idx++) { + out.AddElement( in->Dval(idx) - mean ); + //out.push_back( in->Dval(idx) - mean ); + } +} + +/// Multiply transpose of matrix by matrix +static void matT_times_mat( std::vector const& M1, + std::vector const& M2) +{ + for (unsigned int row = 0; row < M1.size(); row++) { + DataSet_1D* seti = M1[row]; + for (unsigned int col = 0; col < M2.size(); col++) { + DataSet_1D* setj = M2[col]; + //mprintf("%u %u (%zu %zu)", row, col, seti->Size(), setj->Size()); + // seti->Size() must equal setj->Size() + double sum = 0; + for (unsigned int k = 0; k < seti->Size(); k++) { + sum += (seti->Dval(k) * setj->Dval(k)); + // for (unsigned int j = 0; j < M2[col]->Size(); j++) + // sum += M1[row]->Dval(i) * M2[col]->Dval(j); + } + mprintf(" %12.4f", sum); + } + mprintf("\n"); + } +} + +/// For eaach matrix, Multiply transpose of matrix by matrix, then sum +static void matT_times_mat_symmetric( std::vector const& M1, + std::vector const& M2 ) +{ + if (M1.size() != M2.size()) { + mprinterr("Internal Error: matT_times_mat_symmetric: Different # of sets.\n"); + return; + } + unsigned int Nrows = M1.size(); + unsigned int Ncols = Nrows; + for (unsigned int row = 0; row < Nrows; row++) { + DataSet_1D* seti1 = M1[row]; + DataSet_1D* seti2 = M2[row]; + for (unsigned int col = row; col < Ncols; col++) { + DataSet_1D* setj1 = M1[col]; + DataSet_1D* setj2 = M2[col]; + double sum = 0; + // ALL SETS MUST HAVE SAME SIZE + unsigned int nframes = seti1->Size(); + for (unsigned int k = 0; k < nframes; k++) { + sum += (seti1->Dval(k) * setj1->Dval(k)); + sum += (seti2->Dval(k) * setj2->Dval(k)); + } + mprintf(" %12.4f", sum); + } + mprintf("\n"); + } } /** Calculate instantaneous covariance and lagged covariance arrays */ @@ -239,21 +295,60 @@ const printDarray("sy_raw_centered", sy_centered, "%16.8e"); // Remove mean - typedef std::vector DDArray; + typedef std::vector DDArray; DDArray CenteredX(sets.size()); DDArray CenteredY(sets.size()); + for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { + CenteredX[jdx] = (DataSet_1D*)new DataSet_double(); + CenteredY[jdx] = (DataSet_1D*)new DataSet_double(); + } Darray tmpx, tmpy; // DEBUG FIXME // Because symmetric, sy = sx Darray const& sy = sx; for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { subtract_mean(CenteredX[jdx], sets[jdx], nelt_, total_weight, sx[jdx], 0, c0end); subtract_mean(CenteredY[jdx], sets[jdx], nelt_, total_weight, sy[jdx], ctstart, maxFrames); - tmpx.push_back( CenteredX[jdx][0] ); // DEBUG FIXME - tmpy.push_back( CenteredY[jdx][0] ); // DEBUG FIXME + tmpx.push_back( CenteredX[jdx]->Dval(0) ); + tmpy.push_back( CenteredY[jdx]->Dval(0) ); + //tmpx.push_back( CenteredX[jdx][0] ); // DEBUG FIXME + //tmpy.push_back( CenteredY[jdx][0] ); // DEBUG FIXME } printDarray("X0", tmpx, "%16.8e"); printDarray("Y0", tmpy, "%16.8e"); + // Calculate Cxxyy + mprintf("CXXYY\n"); + matT_times_mat_symmetric(CenteredX, CenteredY); + //matT_times_mat(CenteredX, CenteredX); + //mprintf("CYY\n"); + //matT_times_mat(CenteredY); + //matT_times_mat(CenteredY, CenteredY); +/* CoordCovarMatrix_Half Cxx; + if (Cxx.SetupMatrix( CenteredX )) { + mprinterr("Error: Could not set up Cxx matrix.\n"); + return 1; + } + Cxx.AddDataToMatrix( CenteredX ); + CpptrajFile cxxfile; + cxxfile.OpenWrite("cxx.dat"); + Cxx.DebugPrint("Cxx", cxxfile, " %12.6f"); + CoordCovarMatrix_Half Cyy; + if (Cyy.SetupMatrix( CenteredY )) { + mprinterr("Error: Could not set up Cyy matrix.\n"); + return 1; + } + Cyy.AddDataToMatrix( CenteredY ); + CpptrajFile cyyfile; + cyyfile.OpenWrite("cyy.dat"); + Cyy.DebugPrint("Cyy", cyyfile, " %12.6f");*/ + + + // Free memory + for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { + delete CenteredX[jdx]; + delete CenteredY[jdx]; + } + return 0; } diff --git a/src/cpptrajdepend b/src/cpptrajdepend index b0da504eae..71a97b9659 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -132,7 +132,7 @@ Analysis_Spline.o : Analysis_Spline.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.o : Analysis_State.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Statistics.o : Analysis_Statistics.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Statistics.h ArgList.h Array1D.h AssociatedData.h AssociatedData_NOE.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 DataSet_float.h DataSet_integer.h DataSet_string.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 Analysis_TI.o : Analysis_TI.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TI.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 DataSet_Mesh.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 Segment.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordCovarMatrix_Half.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.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 +Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordCovarMatrix_Half.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_double.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Timecorr.o : Analysis_Timecorr.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Timecorr.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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 PubFFT.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 Analysis_VectorMath.o : Analysis_VectorMath.cpp ActionState.h Analysis.h AnalysisState.h Analysis_VectorMath.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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_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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Wavelet.o : Analysis_Wavelet.cpp ActionFrameCounter.h ActionState.h Analysis.h AnalysisState.h Analysis_Wavelet.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterMap.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixFlt.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ProgressBar.h ProgressTimer.h PubFFT.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h From abb4b1be7f8be5de56b8c427226ec1a73db29d7b Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 9 Apr 2024 14:23:25 -0400 Subject: [PATCH 070/200] Save in DataSet_2D --- src/Analysis_TICA.cpp | 21 ++++++++++++++++----- src/DataSet_2D.h | 2 ++ src/DataSet_MatrixDbl.h | 1 + src/DataSet_MatrixFlt.h | 1 + src/cpptrajdepend | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index fa595c287c..7b1e19c4a0 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -4,6 +4,7 @@ #include "CpptrajStdio.h" #include "DataSet_1D.h" #include "DataSet_double.h" +#include "DataSet_MatrixDbl.h" // TODO remove? /** CONSTRUCTOR */ Analysis_TICA::Analysis_TICA() : @@ -201,15 +202,18 @@ static void matT_times_mat( std::vector const& M1, } /// For eaach matrix, Multiply transpose of matrix by matrix, then sum -static void matT_times_mat_symmetric( std::vector const& M1, +static void matT_times_mat_symmetric( DataSet_2D* out, + std::vector const& M1, std::vector const& M2 ) { if (M1.size() != M2.size()) { mprinterr("Internal Error: matT_times_mat_symmetric: Different # of sets.\n"); return; } + out->AllocateHalf( M1.size() ); unsigned int Nrows = M1.size(); unsigned int Ncols = Nrows; + unsigned int idx = 0; for (unsigned int row = 0; row < Nrows; row++) { DataSet_1D* seti1 = M1[row]; DataSet_1D* seti2 = M2[row]; @@ -223,9 +227,10 @@ static void matT_times_mat_symmetric( std::vector const& M1, sum += (seti1->Dval(k) * setj1->Dval(k)); sum += (seti2->Dval(k) * setj2->Dval(k)); } - mprintf(" %12.4f", sum); + out->SetElement(idx++, sum); + //mprintf(" %12.4f", sum); } - mprintf("\n"); + //mprintf("\n"); } } @@ -294,7 +299,7 @@ const printDarray("sx_raw_centered", sx_centered, "%16.8e"); printDarray("sy_raw_centered", sy_centered, "%16.8e"); - // Remove mean + // Remove mean // FIXME do without new typedef std::vector DDArray; DDArray CenteredX(sets.size()); DDArray CenteredY(sets.size()); @@ -317,8 +322,14 @@ const printDarray("Y0", tmpy, "%16.8e"); // Calculate Cxxyy + DataSet_MatrixDbl CXXYY;// = (DataSet_2D*)new DataSet_MatrixDbl(); mprintf("CXXYY\n"); - matT_times_mat_symmetric(CenteredX, CenteredY); + matT_times_mat_symmetric(static_cast(&CXXYY), CenteredX, CenteredY); + DataFile outfile1; + outfile1.SetupDatafile("cxxyy.dat", 0); + outfile1.AddDataSet( &CXXYY ); + outfile1.WriteDataOut(); + //matT_times_mat(CenteredX, CenteredX); //mprintf("CYY\n"); //matT_times_mat(CenteredY); diff --git a/src/DataSet_2D.h b/src/DataSet_2D.h index 299d568cbe..512cda6a65 100644 --- a/src/DataSet_2D.h +++ b/src/DataSet_2D.h @@ -26,6 +26,8 @@ class DataSet_2D : public DataSet { virtual void UpdateElement(size_t, size_t, double) = 0; /// Set element at specified col/row to given value virtual void SetElement(size_t, size_t, double) = 0; + /// Set element at specified 1D index to given value + virtual void SetElement(size_t, double) = 0; /// \return Data from matrix at col/row virtual double GetElement(size_t, size_t) const = 0; diff --git a/src/DataSet_MatrixDbl.h b/src/DataSet_MatrixDbl.h index 5cd1f4e237..1007c95378 100644 --- a/src/DataSet_MatrixDbl.h +++ b/src/DataSet_MatrixDbl.h @@ -26,6 +26,7 @@ class DataSet_MatrixDbl : public DataSet_2D { int AllocateTriangle(size_t x) { kind_=TRI; return mat_.resize(0,x); } void UpdateElement(size_t x,size_t y,double v) { mat_.updateElement(x,y,v); } void SetElement(size_t x,size_t y,double d) { mat_.setElement(x,y,d); } + void SetElement(size_t i, double d) { mat_[i] = d; } double GetElement(size_t x,size_t y) const { return mat_.element(x,y); } double GetElement(size_t i) const { return mat_[i]; } size_t Nrows() const { return mat_.Nrows(); } diff --git a/src/DataSet_MatrixFlt.h b/src/DataSet_MatrixFlt.h index 671707e605..cc41ebaadc 100644 --- a/src/DataSet_MatrixFlt.h +++ b/src/DataSet_MatrixFlt.h @@ -25,6 +25,7 @@ class DataSet_MatrixFlt : public DataSet_2D { int AllocateTriangle(size_t x) { kind_=TRI; return mat_.resize(0,x); } void UpdateElement(size_t x,size_t y,double v) { mat_.updateElement(x,y,v); } void SetElement(size_t x,size_t y,double d) { mat_.setElement(x,y,d); } + void SetElement(size_t i, double d) { mat_[i] = d; } double GetElement(size_t x,size_t y) const { return (double)mat_.element(x,y); } double GetElement(size_t i) const { return (double)mat_[i]; } size_t Nrows() const { return mat_.Nrows(); } diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 71a97b9659..d76df2ba65 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -132,7 +132,7 @@ Analysis_Spline.o : Analysis_Spline.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.o : Analysis_State.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Statistics.o : Analysis_Statistics.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Statistics.h ArgList.h Array1D.h AssociatedData.h AssociatedData_NOE.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 DataSet_float.h DataSet_integer.h DataSet_string.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 Analysis_TI.o : Analysis_TI.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TI.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 DataSet_Mesh.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 Segment.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordCovarMatrix_Half.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_double.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordCovarMatrix_Half.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_double.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Timecorr.o : Analysis_Timecorr.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Timecorr.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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 PubFFT.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 Analysis_VectorMath.o : Analysis_VectorMath.cpp ActionState.h Analysis.h AnalysisState.h Analysis_VectorMath.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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_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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Wavelet.o : Analysis_Wavelet.cpp ActionFrameCounter.h ActionState.h Analysis.h AnalysisState.h Analysis_Wavelet.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterMap.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixFlt.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ProgressBar.h ProgressTimer.h PubFFT.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h From ee913bd7a3a922f229d04d345016d30db27c8043 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 9 Apr 2024 14:34:24 -0400 Subject: [PATCH 071/200] Calculate cxyyx --- src/Analysis_TICA.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 7b1e19c4a0..8f3307ac42 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -180,24 +180,27 @@ static inline void subtract_mean(DataSet_1D* outPtr, } /// Multiply transpose of matrix by matrix -static void matT_times_mat( std::vector const& M1, +static void matT_times_mat( DataSet_2D* out, + std::vector const& M1, std::vector const& M2) { - for (unsigned int row = 0; row < M1.size(); row++) { + unsigned int Nrows = M1.size(); + unsigned int Ncols = M2.size(); + out->Allocate2D( Ncols, Nrows ); + unsigned int idx = 0; + for (unsigned int row = 0; row < Nrows; row++) { DataSet_1D* seti = M1[row]; - for (unsigned int col = 0; col < M2.size(); col++) { + for (unsigned int col = 0; col < Ncols; col++) { DataSet_1D* setj = M2[col]; - //mprintf("%u %u (%zu %zu)", row, col, seti->Size(), setj->Size()); // seti->Size() must equal setj->Size() double sum = 0; for (unsigned int k = 0; k < seti->Size(); k++) { sum += (seti->Dval(k) * setj->Dval(k)); - // for (unsigned int j = 0; j < M2[col]->Size(); j++) - // sum += M1[row]->Dval(i) * M2[col]->Dval(j); } - mprintf(" %12.4f", sum); + out->SetElement(idx++, sum); + //mprintf(" %12.4f", sum); } - mprintf("\n"); + //mprintf("\n"); } } @@ -329,7 +332,20 @@ const outfile1.SetupDatafile("cxxyy.dat", 0); outfile1.AddDataSet( &CXXYY ); outfile1.WriteDataOut(); - + + // Calculate Cxyyx + DataSet_MatrixDbl Cxy, Cyx; + matT_times_mat(static_cast(&Cxy), CenteredX, CenteredY); + matT_times_mat(static_cast(&Cyx), CenteredY, CenteredX); + for (unsigned int idx = 0; idx != Cxy.Size(); idx++) { + double sum = Cxy.GetElement(idx) + Cyx.GetElement(idx); + Cxy.SetElement(idx, sum); + } + DataFile outfile2; + outfile2.SetupDatafile("cxyyx.dat", 0); + outfile2.AddDataSet( &Cxy ); + outfile2.WriteDataOut(); + //matT_times_mat(CenteredX, CenteredX); //mprintf("CYY\n"); //matT_times_mat(CenteredY); From d10cc04f501eab1df19cbea1e56c64e2321e6f30 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 9 Apr 2024 14:37:24 -0400 Subject: [PATCH 072/200] Add note --- src/Analysis_TICA.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 8f3307ac42..33d04c912b 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -179,7 +179,7 @@ static inline void subtract_mean(DataSet_1D* outPtr, } } -/// Multiply transpose of matrix by matrix +/// Multiply transpose of matrix by matrix TODO since the resulting matrix is supposed to be symmetric we can speed this up static void matT_times_mat( DataSet_2D* out, std::vector const& M1, std::vector const& M2) From aa5fdc8bb128f898f0197e023781934092632f0f Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 9 Apr 2024 15:47:11 -0400 Subject: [PATCH 073/200] If dataio is already allocated make sure it is freed before being set up again --- src/DataFile.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DataFile.cpp b/src/DataFile.cpp index b215286b34..86dc80d7eb 100644 --- a/src/DataFile.cpp +++ b/src/DataFile.cpp @@ -292,6 +292,7 @@ int DataFile::SetupDatafile(FileName const& fnameIn, ArgList& argIn, dfType_ = (DataFormatType)FileTypes::GetTypeFromExtension(DF_WriteKeyArray, filename_.Ext(), DATAFILE); // Set up DataIO based on format. + if (dataio_ != 0) delete dataio_; dataio_ = (DataIO*)FileTypes::AllocIO( DF_AllocArray, dfType_, false ); if (dataio_ == 0) return Error("Error: Data file allocation failed.\n"); dataio_->SetDebug( debug_ ); From c1a212fd8031bfb41ed0ca5eff6c267ebbc33e41 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 9 Apr 2024 16:01:17 -0400 Subject: [PATCH 074/200] If DataFile is being reused, make sure sets get readded --- src/DataFile.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/DataFile.cpp b/src/DataFile.cpp index 86dc80d7eb..fd50353b20 100644 --- a/src/DataFile.cpp +++ b/src/DataFile.cpp @@ -292,7 +292,16 @@ int DataFile::SetupDatafile(FileName const& fnameIn, ArgList& argIn, dfType_ = (DataFormatType)FileTypes::GetTypeFromExtension(DF_WriteKeyArray, filename_.Ext(), DATAFILE); // Set up DataIO based on format. - if (dataio_ != 0) delete dataio_; + std::vector previousSets; + if (dataio_ != 0) { + delete dataio_; + if (!SetList_.empty()) { + // Save current sets so they can be re-added with the new DataIO object + for (DataSetList::const_iterator it = SetList_.begin(); it != SetList_.end(); ++it) + previousSets.push_back( *it ); + } + SetList_.ClearAll(); + } dataio_ = (DataIO*)FileTypes::AllocIO( DF_AllocArray, dfType_, false ); if (dataio_ == 0) return Error("Error: Data file allocation failed.\n"); dataio_->SetDebug( debug_ ); @@ -302,6 +311,15 @@ int DataFile::SetupDatafile(FileName const& fnameIn, ArgList& argIn, # endif if (!argIn.empty()) ProcessArgs( argIn ); + // Re-add sets if necessary + if (!previousSets.empty()) { + for (std::vector::const_iterator it = previousSets.begin(); it != previousSets.end(); ++it) { + if ( AddDataSet( *it ) ) { + mprinterr("Error: Could not add set '%s' to file '%s'\n", (*it)->legend(), filename_.full()); + return 1; + } + } + } return 0; } From 2f6514f4feb5284f58f618c44b5af178748976ea Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Tue, 9 Apr 2024 16:01:36 -0400 Subject: [PATCH 075/200] Do matrix normalization --- src/Analysis_TICA.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 33d04c912b..92106f8361 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -326,6 +326,8 @@ const // Calculate Cxxyy DataSet_MatrixDbl CXXYY;// = (DataSet_2D*)new DataSet_MatrixDbl(); + CXXYY.SetupFormat().SetFormatWidthPrecision(16,8); + CXXYY.SetupFormat().SetFormatType(TextFormat::SCIENTIFIC); mprintf("CXXYY\n"); matT_times_mat_symmetric(static_cast(&CXXYY), CenteredX, CenteredY); DataFile outfile1; @@ -335,6 +337,8 @@ const // Calculate Cxyyx DataSet_MatrixDbl Cxy, Cyx; + Cxy.SetupFormat().SetFormatWidthPrecision(16,8); + Cxy.SetupFormat().SetFormatType(TextFormat::SCIENTIFIC); matT_times_mat(static_cast(&Cxy), CenteredX, CenteredY); matT_times_mat(static_cast(&Cyx), CenteredY, CenteredX); for (unsigned int idx = 0; idx != Cxy.Size(); idx++) { @@ -346,6 +350,14 @@ const outfile2.AddDataSet( &Cxy ); outfile2.WriteDataOut(); + // Normalize + CXXYY.Normalize( 1.0 / total_weight ); + Cxy.Normalize( 1.0 / total_weight ); + outfile1.SetupDatafile("cxxyy.norm.dat", 0); + outfile1.WriteDataOut(); + outfile2.SetupDatafile("cxyyx.norm.dat", 0); + outfile2.WriteDataOut(); + //matT_times_mat(CenteredX, CenteredX); //mprintf("CYY\n"); //matT_times_mat(CenteredY); From 251dc929f93d85c0dc8653ffa187cc725578303e Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 09:18:30 -0400 Subject: [PATCH 076/200] Add function to set all arguments as unmarked so the ArgList can be reused. --- src/ArgList.cpp | 5 +++++ src/ArgList.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/ArgList.cpp b/src/ArgList.cpp index 873259ea0f..14ae587156 100644 --- a/src/ArgList.cpp +++ b/src/ArgList.cpp @@ -494,3 +494,8 @@ bool ArgList::Contains(const char *key) const { } return false; } + +/** Make all arguments unmarked. */ +void ArgList::SetAllUnmarked() { + marked_.assign( marked_.size(), false ); +} diff --git a/src/ArgList.h b/src/ArgList.h index f05b7dda26..9f2fe9421e 100644 --- a/src/ArgList.h +++ b/src/ArgList.h @@ -59,6 +59,8 @@ class ArgList { void AddArg(std::string const&); /// Mark given argument void MarkArg(int); + /// Set all arguments as unmarked + void SetAllUnmarked(); /// Print a warning if not all arguments are marked bool CheckForMoreArgs() const; /// Print the argument list From 13b0c373e37648522ae20a526d6f8cda836fc6e1 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 09:37:31 -0400 Subject: [PATCH 077/200] Set output format args --- src/Analysis_TICA.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 92106f8361..5f51ac4e86 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -324,21 +324,23 @@ const printDarray("X0", tmpx, "%16.8e"); printDarray("Y0", tmpy, "%16.8e"); + ArgList tmpArgs("square2d noheader"); // Calculate Cxxyy DataSet_MatrixDbl CXXYY;// = (DataSet_2D*)new DataSet_MatrixDbl(); - CXXYY.SetupFormat().SetFormatWidthPrecision(16,8); - CXXYY.SetupFormat().SetFormatType(TextFormat::SCIENTIFIC); + CXXYY.SetupFormat().SetFormatWidthPrecision(12,6); + CXXYY.SetupFormat().SetFormatType(TextFormat::DOUBLE); mprintf("CXXYY\n"); matT_times_mat_symmetric(static_cast(&CXXYY), CenteredX, CenteredY); DataFile outfile1; - outfile1.SetupDatafile("cxxyy.dat", 0); + outfile1.SetupDatafile("cxxyy.dat", tmpArgs, 0); outfile1.AddDataSet( &CXXYY ); outfile1.WriteDataOut(); + tmpArgs.SetAllUnmarked(); // Calculate Cxyyx DataSet_MatrixDbl Cxy, Cyx; - Cxy.SetupFormat().SetFormatWidthPrecision(16,8); - Cxy.SetupFormat().SetFormatType(TextFormat::SCIENTIFIC); + Cxy.SetupFormat().SetFormatWidthPrecision(12,6); + Cxy.SetupFormat().SetFormatType(TextFormat::DOUBLE); matT_times_mat(static_cast(&Cxy), CenteredX, CenteredY); matT_times_mat(static_cast(&Cyx), CenteredY, CenteredX); for (unsigned int idx = 0; idx != Cxy.Size(); idx++) { @@ -346,17 +348,20 @@ const Cxy.SetElement(idx, sum); } DataFile outfile2; - outfile2.SetupDatafile("cxyyx.dat", 0); + outfile2.SetupDatafile("cxyyx.dat", tmpArgs, 0); outfile2.AddDataSet( &Cxy ); outfile2.WriteDataOut(); + tmpArgs.SetAllUnmarked(); // Normalize CXXYY.Normalize( 1.0 / total_weight ); Cxy.Normalize( 1.0 / total_weight ); - outfile1.SetupDatafile("cxxyy.norm.dat", 0); + outfile1.SetupDatafile("cxxyy.norm.dat", tmpArgs, 0); outfile1.WriteDataOut(); - outfile2.SetupDatafile("cxyyx.norm.dat", 0); + tmpArgs.SetAllUnmarked(); + outfile2.SetupDatafile("cxyyx.norm.dat", tmpArgs, 0); outfile2.WriteDataOut(); + tmpArgs.SetAllUnmarked(); //matT_times_mat(CenteredX, CenteredX); //mprintf("CYY\n"); From 7ad2f1e2fb09b64c8c494ca14f67b072c9f0b1bd Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 09:47:38 -0400 Subject: [PATCH 078/200] Add some notes, remove old code --- src/Analysis_TICA.cpp | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 5f51ac4e86..aa40e00801 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -261,7 +261,7 @@ const mprintf("DEBUG: C0 start = %u end = %u\n", 0, c0end); unsigned int ctstart = (unsigned int)lag_; mprintf("DEBUG: CT start = %u end = %u\n", ctstart, maxFrames); - + // Calculate sum over each set Darray sumX; calculate_sum(sumX, sets, nelt_, 0, c0end); printDarray("sx_raw", sumX, "%15.8f"); @@ -290,7 +290,7 @@ const double total_weight = c0end * 2; mprintf("DEBUG: Total weight= %f\n", total_weight); - // Center + // Center TODO sx_centered and sy_centered may not need to be calced Darray sx_centered, sy_centered; sx_centered.reserve( sumX.size() ); sy_centered.reserve( sumY.size() ); @@ -327,10 +327,11 @@ const ArgList tmpArgs("square2d noheader"); // Calculate Cxxyy DataSet_MatrixDbl CXXYY;// = (DataSet_2D*)new DataSet_MatrixDbl(); - CXXYY.SetupFormat().SetFormatWidthPrecision(12,6); - CXXYY.SetupFormat().SetFormatType(TextFormat::DOUBLE); + CXXYY.SetupFormat().SetFormatWidthPrecision(12,6); // DEBUG + CXXYY.SetupFormat().SetFormatType(TextFormat::DOUBLE); // DEBUG mprintf("CXXYY\n"); matT_times_mat_symmetric(static_cast(&CXXYY), CenteredX, CenteredY); + // DEBUG - write unnormalized matrix DataFile outfile1; outfile1.SetupDatafile("cxxyy.dat", tmpArgs, 0); outfile1.AddDataSet( &CXXYY ); @@ -339,14 +340,15 @@ const // Calculate Cxyyx DataSet_MatrixDbl Cxy, Cyx; - Cxy.SetupFormat().SetFormatWidthPrecision(12,6); - Cxy.SetupFormat().SetFormatType(TextFormat::DOUBLE); + Cxy.SetupFormat().SetFormatWidthPrecision(12,6); // DEBUG + Cxy.SetupFormat().SetFormatType(TextFormat::DOUBLE); // DEBUG matT_times_mat(static_cast(&Cxy), CenteredX, CenteredY); matT_times_mat(static_cast(&Cyx), CenteredY, CenteredX); for (unsigned int idx = 0; idx != Cxy.Size(); idx++) { double sum = Cxy.GetElement(idx) + Cyx.GetElement(idx); Cxy.SetElement(idx, sum); } +  // DEBUG - write unnormalized matrix DataFile outfile2; outfile2.SetupDatafile("cxyyx.dat", tmpArgs, 0); outfile2.AddDataSet( &Cxy ); @@ -356,6 +358,7 @@ const // Normalize CXXYY.Normalize( 1.0 / total_weight ); Cxy.Normalize( 1.0 / total_weight ); + // DEBUG - write normalized matrices outfile1.SetupDatafile("cxxyy.norm.dat", tmpArgs, 0); outfile1.WriteDataOut(); tmpArgs.SetAllUnmarked(); @@ -363,30 +366,6 @@ const outfile2.WriteDataOut(); tmpArgs.SetAllUnmarked(); - //matT_times_mat(CenteredX, CenteredX); - //mprintf("CYY\n"); - //matT_times_mat(CenteredY); - //matT_times_mat(CenteredY, CenteredY); -/* CoordCovarMatrix_Half Cxx; - if (Cxx.SetupMatrix( CenteredX )) { - mprinterr("Error: Could not set up Cxx matrix.\n"); - return 1; - } - Cxx.AddDataToMatrix( CenteredX ); - CpptrajFile cxxfile; - cxxfile.OpenWrite("cxx.dat"); - Cxx.DebugPrint("Cxx", cxxfile, " %12.6f"); - CoordCovarMatrix_Half Cyy; - if (Cyy.SetupMatrix( CenteredY )) { - mprinterr("Error: Could not set up Cyy matrix.\n"); - return 1; - } - Cyy.AddDataToMatrix( CenteredY ); - CpptrajFile cyyfile; - cyyfile.OpenWrite("cyy.dat"); - Cyy.DebugPrint("Cyy", cyyfile, " %12.6f");*/ - - // Free memory for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { delete CenteredX[jdx]; From 02e4490fe1dc4487b4508557ae5e38f761368a84 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 09:48:14 -0400 Subject: [PATCH 079/200] Remove extended char --- src/Analysis_TICA.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index aa40e00801..7e148626c8 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -348,7 +348,7 @@ const double sum = Cxy.GetElement(idx) + Cyx.GetElement(idx); Cxy.SetElement(idx, sum); } -  // DEBUG - write unnormalized matrix + // DEBUG - write unnormalized matrix DataFile outfile2; outfile2.SetupDatafile("cxyyx.dat", tmpArgs, 0); outfile2.AddDataSet( &Cxy ); From 0021942e7a40e93b66cbe47bc1de8a26d944aa08 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 09:53:58 -0400 Subject: [PATCH 080/200] Remove old code --- src/Analysis_TICA.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 7e148626c8..ab8829ddcb 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -316,10 +316,8 @@ const for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { subtract_mean(CenteredX[jdx], sets[jdx], nelt_, total_weight, sx[jdx], 0, c0end); subtract_mean(CenteredY[jdx], sets[jdx], nelt_, total_weight, sy[jdx], ctstart, maxFrames); - tmpx.push_back( CenteredX[jdx]->Dval(0) ); - tmpy.push_back( CenteredY[jdx]->Dval(0) ); - //tmpx.push_back( CenteredX[jdx][0] ); // DEBUG FIXME - //tmpy.push_back( CenteredY[jdx][0] ); // DEBUG FIXME + tmpx.push_back( CenteredX[jdx]->Dval(0) ); // DEBUG + tmpy.push_back( CenteredY[jdx]->Dval(0) ); // DEBUG } printDarray("X0", tmpx, "%16.8e"); printDarray("Y0", tmpy, "%16.8e"); From ce602aaf4248b946edf3a8fc8ef5ed713ab7142e Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 10:12:49 -0400 Subject: [PATCH 081/200] Add mean printout --- src/Analysis_TICA.cpp | 14 ++++++++++++++ src/cpptrajdepend | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index ab8829ddcb..bdba125f4d 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -5,6 +5,7 @@ #include "DataSet_1D.h" #include "DataSet_double.h" #include "DataSet_MatrixDbl.h" // TODO remove? +#include "DataSet_Modes.h" /** CONSTRUCTOR */ Analysis_TICA::Analysis_TICA() : @@ -289,6 +290,15 @@ const //total_weight *= 2; double total_weight = c0end * 2; mprintf("DEBUG: Total weight= %f\n", total_weight); + // DEBUG - print mean + CpptrajFile meanout; + if (meanout.OpenWrite("debug.mean.dat")) { + mprinterr("Error: Could not open debug.mean.dat\n"); + return 1; + } + for (Darray::const_iterator it = sx.begin(); it != sx.end(); ++it) + meanout.Printf("%12.6f\n", *it / total_weight); + meanout.CloseFile(); // Center TODO sx_centered and sy_centered may not need to be calced Darray sx_centered, sy_centered; @@ -370,6 +380,10 @@ const delete CenteredY[jdx]; } + // Get C0 eigenvectors/eigenvalues + DataSet_Modes C0_Modes; + + return 0; } diff --git a/src/cpptrajdepend b/src/cpptrajdepend index d76df2ba65..082d57cc5c 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -132,7 +132,7 @@ Analysis_Spline.o : Analysis_Spline.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.o : Analysis_State.cpp ActionState.h Analysis.h AnalysisState.h Analysis_State.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 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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Statistics.o : Analysis_Statistics.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Statistics.h ArgList.h Array1D.h AssociatedData.h AssociatedData_NOE.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 DataSet_float.h DataSet_integer.h DataSet_string.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 Analysis_TI.o : Analysis_TI.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TI.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 DataSet_Mesh.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 Segment.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordCovarMatrix_Half.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_double.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Analysis_TICA.o : Analysis_TICA.cpp ActionState.h Analysis.h AnalysisState.h Analysis_TICA.h ArgList.h Array1D.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordCovarMatrix.h CoordCovarMatrix_Full.h CoordCovarMatrix_Half.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Modes.h DataSet_double.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Timecorr.o : Analysis_Timecorr.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Timecorr.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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 PubFFT.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 Analysis_VectorMath.o : Analysis_VectorMath.cpp ActionState.h Analysis.h AnalysisState.h Analysis_VectorMath.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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_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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_Wavelet.o : Analysis_Wavelet.cpp ActionFrameCounter.h ActionState.h Analysis.h AnalysisState.h Analysis_Wavelet.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterMap.h ComplexArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixFlt.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h ParmFile.h ProgressBar.h ProgressTimer.h PubFFT.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h From bb28d9250b34d4ae468753c1d6b4f1827469100b Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 10:34:38 -0400 Subject: [PATCH 082/200] Calculate mean and eigenvalues of C0 --- src/Analysis_TICA.cpp | 27 ++++++++++++++++++++++----- src/DataSet_Modes.cpp | 6 ++++++ src/DataSet_Modes.h | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index bdba125f4d..461547116c 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -296,8 +296,12 @@ const mprinterr("Error: Could not open debug.mean.dat\n"); return 1; } - for (Darray::const_iterator it = sx.begin(); it != sx.end(); ++it) - meanout.Printf("%12.6f\n", *it / total_weight); + Darray meanX; + meanX.reserve( sx.size() ); + for (Darray::const_iterator it = sx.begin(); it != sx.end(); ++it) { + meanX.push_back( *it / total_weight); + meanout.Printf("%12.6f\n", meanX.back()); // DEBUG + } meanout.CloseFile(); // Center TODO sx_centered and sy_centered may not need to be calced @@ -321,7 +325,7 @@ const CenteredY[jdx] = (DataSet_1D*)new DataSet_double(); } Darray tmpx, tmpy; // DEBUG FIXME - // Because symmetric, sy = sx + // Because symmetric, sy = sx //TODO use meanX set Darray const& sy = sx; for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { subtract_mean(CenteredX[jdx], sets[jdx], nelt_, total_weight, sx[jdx], 0, c0end); @@ -382,6 +386,19 @@ const // Get C0 eigenvectors/eigenvalues DataSet_Modes C0_Modes; + C0_Modes.SetAvgCoords( meanX ); + // Want all eigenvectors + if (C0_Modes.CalcEigen( CXXYY, CXXYY.Ncols() )) { + mprinterr("Error: Could not calculate eigenvectors and eigenvales for C0 matrix.\n"); + return 1; + } + // TODO remove negative eigenvalues + + // DEBUG - print eigenvalues + Darray tmpevals; + for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) + tmpevals.push_back( C0_Modes.Eigenvalue(ii) ); + printDarray("C0evals", tmpevals, "%16.8e"); return 0; @@ -391,7 +408,7 @@ const Analysis::RetType Analysis_TICA::analyze_datasets() { calculateCovariance_C0CT( sets_.Array() ); - // Matrix - half +/* // Matrix - half CoordCovarMatrix_Half covarMatrix; if (covarMatrix.SetupMatrix( sets_.Array() )) { mprinterr("Error: Could not set up C0 matrix for data sets.\n"); @@ -404,7 +421,7 @@ Analysis::RetType Analysis_TICA::analyze_datasets() { return Analysis::ERR; } // DEBUG PRINT - covarMatrix.DebugPrint("C0", *debugC0_, " %12.6f"); + covarMatrix.DebugPrint("C0", *debugC0_, " %12.6f");*/ return Analysis::OK; } diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index 96eb490aaa..8aba0138ac 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -56,6 +56,12 @@ size_t DataSet_Modes::MemUsageInBytes() const { return mySize; } +/** Set average coords */ +int DataSet_Modes::SetAvgCoords(std::vector const& avgIn) { + avgcrd_ = avgIn; + return 0; +} + // DataSet_Modes::SetAvgCoords() int DataSet_Modes::SetAvgCoords(DataSet_2D const& mIn) { avgcrd_.clear(); diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index 06b842dc55..46b5efd245 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -38,6 +38,7 @@ class DataSet_Modes : public DataSet { double* EvectPtr() { return evectors_; } int SetAvgCoords(DataSet_2D const&); + int SetAvgCoords(std::vector const&); // TODO deprecate above version for this one int SetModes(bool, int, int, const double*, const double*); /// Allocate memory for modes data int AllocateModes(unsigned int, unsigned int, unsigned int, unsigned int); From e8c6b1ad82e8beb47a25e5e5f74ca29b3a343b88 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 11:41:06 -0400 Subject: [PATCH 083/200] Create matrix L --- src/Analysis_TICA.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 461547116c..68562a447c 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -238,6 +238,8 @@ static void matT_times_mat_symmetric( DataSet_2D* out, } } +/** Calculate matrix times diagonal */ + /** Calculate instantaneous covariance and lagged covariance arrays */ int Analysis_TICA::calculateCovariance_C0CT(DSarray const& sets) const @@ -399,7 +401,30 @@ const for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) tmpevals.push_back( C0_Modes.Eigenvalue(ii) ); printDarray("C0evals", tmpevals, "%16.8e"); - + // DEBUG - print first 3 values of each eigenvector + for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { + const double* evec = C0_Modes.Eigenvector(ii); + for (int jj = 0; jj < 3; jj++) + mprintf("%12.8f", evec[jj]); + mprintf("\n"); + } + + // Create matrix L, where rows are eigenvectors of C0 times eigenvalues of C0 + DataSet_MatrixDbl matL; + matL.Allocate2D( C0_Modes.VectorSize(), C0_Modes.Nmodes() ); + unsigned int idx = 0; + for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { + double fac = 1.0 / sqrt(C0_Modes.Eigenvalue(ii)); + const double* evec = C0_Modes.Eigenvector(ii); + for (int jj = 0; jj < C0_Modes.VectorSize(); ++jj) + matL.SetElement(idx++, evec[jj] * fac); + } + // DEBUG - write unnormalized matrix + DataFile outfile3; + outfile3.SetupDatafile("matL.dat", tmpArgs, 0); + outfile3.AddDataSet( &matL ); + outfile3.WriteDataOut(); + tmpArgs.SetAllUnmarked(); return 0; } From f76e7a475111f916b28cae0e8bb78acc254cb923 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 12:46:24 -0400 Subject: [PATCH 084/200] Implement DataSet_2D matrix multiply. Calc L^t x Ct --- src/Analysis_TICA.cpp | 16 ++++++++++++++++ src/DataSet_2D.h | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 68562a447c..4f102ab248 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -426,6 +426,22 @@ const outfile3.WriteDataOut(); tmpArgs.SetAllUnmarked(); + // L is transposed already (eigenvectors are in rows) + DataSet_MatrixDbl matLCt; + matLCt.SetupFormat().SetFormatWidthPrecision(15,8); // DEBUG + matLCt.SetupFormat().SetFormatType(TextFormat::SCIENTIFIC); // DEBUG + DataSet_2D::RetType ret = matLCt.Multiply(matL, Cxy); + if (ret != DataSet_2D::OK) { + mprinterr("Error: Could not multiply L^T x Ct\n"); + return 1; + } + // DEBUG - write unnormalized matrix + DataFile outfile4; + outfile4.SetupDatafile("matLCt.dat", tmpArgs, 0); + outfile4.AddDataSet( &matLCt ); + outfile4.WriteDataOut(); + tmpArgs.SetAllUnmarked(); + return 0; } diff --git a/src/DataSet_2D.h b/src/DataSet_2D.h index 512cda6a65..7196807333 100644 --- a/src/DataSet_2D.h +++ b/src/DataSet_2D.h @@ -50,6 +50,24 @@ class DataSet_2D : public DataSet { /// Normalize matrix virtual void Normalize(double) = 0; // ------------------------------------------- + enum RetType { OK = 0, DIM_MISMATCH, ALLOC_ERR, ERR }; + /// Set this matrix with the result of M1 x M2 + RetType Multiply(DataSet_2D const& M1, DataSet_2D const& M2) { + if (M1.Ncols() != M2.Nrows()) return DIM_MISMATCH; + unsigned int len = M1.Ncols(); + if (Allocate2D( M2.Ncols(), M1.Nrows() )) return ALLOC_ERR; + unsigned int idx = 0; + for (unsigned int row = 0; row != Nrows(); row++) { + for (unsigned int col = 0; col != Ncols(); col++) { + double sum = 0; + for (unsigned int k = 0; k != len; k++) + sum += M1.GetElement(k, row) * M2.GetElement(col, k); + SetElement(idx++, sum); + } + } + return OK; + } + // ------------------------------------------- // TODO: Remove this. Only needed by DataSet_1D.h void Add(size_t,const void*) { } }; From a8cd4a818097e321c3f7ce0c902cfb8813314501 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 13:40:29 -0400 Subject: [PATCH 085/200] More correctly referred to as Ltrans --- src/Analysis_TICA.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 4f102ab248..ece2fe52af 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -409,28 +409,28 @@ const mprintf("\n"); } - // Create matrix L, where rows are eigenvectors of C0 times eigenvalues of C0 - DataSet_MatrixDbl matL; - matL.Allocate2D( C0_Modes.VectorSize(), C0_Modes.Nmodes() ); + // Create matrix Ltrans, where rows are eigenvectors of C0 times eigenvalues of C0 + DataSet_MatrixDbl matLtrans; + matLtrans.Allocate2D( C0_Modes.VectorSize(), C0_Modes.Nmodes() ); unsigned int idx = 0; for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { double fac = 1.0 / sqrt(C0_Modes.Eigenvalue(ii)); const double* evec = C0_Modes.Eigenvector(ii); for (int jj = 0; jj < C0_Modes.VectorSize(); ++jj) - matL.SetElement(idx++, evec[jj] * fac); + matLtrans.SetElement(idx++, evec[jj] * fac); } // DEBUG - write unnormalized matrix DataFile outfile3; outfile3.SetupDatafile("matL.dat", tmpArgs, 0); - outfile3.AddDataSet( &matL ); + outfile3.AddDataSet( &matLtrans ); outfile3.WriteDataOut(); tmpArgs.SetAllUnmarked(); // L is transposed already (eigenvectors are in rows) - DataSet_MatrixDbl matLCt; - matLCt.SetupFormat().SetFormatWidthPrecision(15,8); // DEBUG - matLCt.SetupFormat().SetFormatType(TextFormat::SCIENTIFIC); // DEBUG - DataSet_2D::RetType ret = matLCt.Multiply(matL, Cxy); + DataSet_MatrixDbl matLtransCt; + matLtransCt.SetupFormat().SetFormatWidthPrecision(15,8); // DEBUG + matLtransCt.SetupFormat().SetFormatType(TextFormat::SCIENTIFIC); // DEBUG + DataSet_2D::RetType ret = matLtransCt.Multiply(matLtrans, Cxy); if (ret != DataSet_2D::OK) { mprinterr("Error: Could not multiply L^T x Ct\n"); return 1; @@ -438,7 +438,7 @@ const // DEBUG - write unnormalized matrix DataFile outfile4; outfile4.SetupDatafile("matLCt.dat", tmpArgs, 0); - outfile4.AddDataSet( &matLCt ); + outfile4.AddDataSet( &matLtransCt ); outfile4.WriteDataOut(); tmpArgs.SetAllUnmarked(); From d637375ac6df59a9b9d3046f3a0677222d6e9b37 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 13:50:56 -0400 Subject: [PATCH 086/200] Calculate (L^T * Ct) * L --- src/Analysis_TICA.cpp | 18 ++++++++++++++++++ src/DataSet_2D.h | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index ece2fe52af..3788a69dfa 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -427,6 +427,7 @@ const tmpArgs.SetAllUnmarked(); // L is transposed already (eigenvectors are in rows) + // Calculate L^T * Ct DataSet_MatrixDbl matLtransCt; matLtransCt.SetupFormat().SetFormatWidthPrecision(15,8); // DEBUG matLtransCt.SetupFormat().SetFormatType(TextFormat::SCIENTIFIC); // DEBUG @@ -442,6 +443,23 @@ const outfile4.WriteDataOut(); tmpArgs.SetAllUnmarked(); + // Calculate (L^T * Ct) * L + // Need to use transpose of Ltrans to get L + DataSet_MatrixDbl Ct_trans; + Ct_trans.SetupFormat().SetFormatWidthPrecision(12,8); // DEBUG + Ct_trans.SetupFormat().SetFormatType(TextFormat::DOUBLE); // DEBUG + ret = Ct_trans.Multiply_M2transpose(matLtransCt, matLtrans); + if (ret != DataSet_2D::OK) { + mprinterr("Error: Could not multiply (L^T x Ct) x L\n"); + return 1; + } + // DEBUG - write unnormalized matrix + DataFile outfile5; + outfile5.SetupDatafile("Ct_trans.dat", tmpArgs, 0); + outfile5.AddDataSet( &Ct_trans ); + outfile5.WriteDataOut(); + tmpArgs.SetAllUnmarked(); + return 0; } diff --git a/src/DataSet_2D.h b/src/DataSet_2D.h index 7196807333..b86a34cb08 100644 --- a/src/DataSet_2D.h +++ b/src/DataSet_2D.h @@ -67,6 +67,23 @@ class DataSet_2D : public DataSet { } return OK; } + /// Set this matrix with the result of M1 x M2^T + RetType Multiply_M2transpose(DataSet_2D const& M1, DataSet_2D const& M2) { + if (M1.Ncols() != M2.Ncols()) return DIM_MISMATCH; + unsigned int len = M1.Ncols(); + if (Allocate2D( M2.Nrows(), M1.Nrows() )) return ALLOC_ERR; + unsigned int idx = 0; + for (unsigned int row = 0; row != Nrows(); row++) { + for (unsigned int col = 0; col != Ncols(); col++) { + double sum = 0; + for (unsigned int k = 0; k != len; k++) + sum += M1.GetElement(k, row) * M2.GetElement(k, col); + SetElement(idx++, sum); + } + } + return OK; + } + // ------------------------------------------- // TODO: Remove this. Only needed by DataSet_1D.h void Add(size_t,const void*) { } From e1c0a376471de266d88f8119a94aae9db4d49918 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 14:14:05 -0400 Subject: [PATCH 087/200] Add symmetric check in same manner as numpy.allclose --- src/Analysis_TICA.cpp | 28 +++++++++++++++++++++++++++- src/Analysis_TICA.h | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 3788a69dfa..1c8b4dcb70 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -6,6 +6,7 @@ #include "DataSet_double.h" #include "DataSet_MatrixDbl.h" // TODO remove? #include "DataSet_Modes.h" +#include //sqrt, fabs /** CONSTRUCTOR */ Analysis_TICA::Analysis_TICA() : @@ -238,7 +239,26 @@ static void matT_times_mat_symmetric( DataSet_2D* out, } } -/** Calculate matrix times diagonal */ +/** Check that the given matrix is symmetric. + * This will work similar to numpy.allclose. + * https://numpy.org/doc/stable/reference/generated/numpy.allclose.html + */ +bool Analysis_TICA::check_symmetric(DataSet_2D const& mat) { + if (mat.Ncols() != mat.Nrows()) return false; + + static const double rtol = 1e-5; + static const double atol = 1e-8; + + for (unsigned int row = 0; row != mat.Nrows(); row++) { + for (unsigned int col = row+1; col < mat.Ncols(); col++) { + double a = mat.GetElement(col, row); + double b = mat.GetElement(row, col); + bool is_equiv = ((fabs(a - b) <= (atol + rtol * fabs(b)))); + if (!is_equiv) return false; + } + } + return true; +} /** Calculate instantaneous covariance and lagged covariance arrays */ int Analysis_TICA::calculateCovariance_C0CT(DSarray const& sets) @@ -460,6 +480,12 @@ const outfile5.WriteDataOut(); tmpArgs.SetAllUnmarked(); + if (check_symmetric( Cxy )) { + mprintf("\tCt is symmetric.\n"); + } else { + mprintf("\tCt is not symmetric.\n"); + } + return 0; } diff --git a/src/Analysis_TICA.h b/src/Analysis_TICA.h index 08e1f369a6..e02587ed89 100644 --- a/src/Analysis_TICA.h +++ b/src/Analysis_TICA.h @@ -2,6 +2,7 @@ #define INC_ANALYSIS_TICA_H #include "Analysis.h" #include "Array1D.h" +class DataSet_2D; /// class Analysis_TICA : public Analysis { public: @@ -21,6 +22,8 @@ class Analysis_TICA : public Analysis { Analysis::RetType analyze_datasets(); /// Calculate instantaneous and lagged covariance matrices int calculateCovariance_C0CT(DSarray const&) const; + /// Check if given matrix is symmetric TODO move to DataSet_2D? + static bool check_symmetric(DataSet_2D const&); DataSet_Coords* TgtTraj_; ///< Input trajectory (crdset) int lag_; ///< TICA time lag From 1991aa4e160744592a7fd02b902213b03fe9e446 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 14:42:18 -0400 Subject: [PATCH 088/200] Move matrix symmetric check into DataSet_2D --- src/Analysis_TICA.cpp | 25 ++----------------------- src/Analysis_TICA.h | 2 -- src/DataSet_2D.cpp | 24 ++++++++++++++++++++++++ src/DataSet_2D.h | 3 ++- src/DataSet_Modes.cpp | 3 +++ src/cpptrajdepend | 1 + src/cpptrajfiles | 1 + 7 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 src/DataSet_2D.cpp diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 1c8b4dcb70..c1a675caa4 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -6,7 +6,7 @@ #include "DataSet_double.h" #include "DataSet_MatrixDbl.h" // TODO remove? #include "DataSet_Modes.h" -#include //sqrt, fabs +#include //sqrt /** CONSTRUCTOR */ Analysis_TICA::Analysis_TICA() : @@ -239,27 +239,6 @@ static void matT_times_mat_symmetric( DataSet_2D* out, } } -/** Check that the given matrix is symmetric. - * This will work similar to numpy.allclose. - * https://numpy.org/doc/stable/reference/generated/numpy.allclose.html - */ -bool Analysis_TICA::check_symmetric(DataSet_2D const& mat) { - if (mat.Ncols() != mat.Nrows()) return false; - - static const double rtol = 1e-5; - static const double atol = 1e-8; - - for (unsigned int row = 0; row != mat.Nrows(); row++) { - for (unsigned int col = row+1; col < mat.Ncols(); col++) { - double a = mat.GetElement(col, row); - double b = mat.GetElement(row, col); - bool is_equiv = ((fabs(a - b) <= (atol + rtol * fabs(b)))); - if (!is_equiv) return false; - } - } - return true; -} - /** Calculate instantaneous covariance and lagged covariance arrays */ int Analysis_TICA::calculateCovariance_C0CT(DSarray const& sets) const @@ -480,7 +459,7 @@ const outfile5.WriteDataOut(); tmpArgs.SetAllUnmarked(); - if (check_symmetric( Cxy )) { + if (Cxy.IsSymmetric()) { mprintf("\tCt is symmetric.\n"); } else { mprintf("\tCt is not symmetric.\n"); diff --git a/src/Analysis_TICA.h b/src/Analysis_TICA.h index e02587ed89..b4abe69c5c 100644 --- a/src/Analysis_TICA.h +++ b/src/Analysis_TICA.h @@ -22,8 +22,6 @@ class Analysis_TICA : public Analysis { Analysis::RetType analyze_datasets(); /// Calculate instantaneous and lagged covariance matrices int calculateCovariance_C0CT(DSarray const&) const; - /// Check if given matrix is symmetric TODO move to DataSet_2D? - static bool check_symmetric(DataSet_2D const&); DataSet_Coords* TgtTraj_; ///< Input trajectory (crdset) int lag_; ///< TICA time lag diff --git a/src/DataSet_2D.cpp b/src/DataSet_2D.cpp new file mode 100644 index 0000000000..67e839e30a --- /dev/null +++ b/src/DataSet_2D.cpp @@ -0,0 +1,24 @@ +#include "DataSet_2D.h" +#include // fabs + +/** Check that the given matrix is symmetric. + * This will work similar to numpy.allclose. + * https://numpy.org/doc/stable/reference/generated/numpy.allclose.html + */ +bool DataSet_2D::IsSymmetric() const { + if (MatrixKind() == HALF || MatrixKind() == TRI) return true; + if (Ncols() != Nrows()) return false; + + static const double rtol = 1e-5; + static const double atol = 1e-8; + + for (unsigned int row = 0; row != Nrows(); row++) { + for (unsigned int col = row+1; col < Ncols(); col++) { + double a = GetElement(col, row); + double b = GetElement(row, col); + bool is_equiv = ((fabs(a - b) <= (atol + rtol * fabs(b)))); + if (!is_equiv) return false; + } + } + return true; +} diff --git a/src/DataSet_2D.h b/src/DataSet_2D.h index b86a34cb08..d162a97bf6 100644 --- a/src/DataSet_2D.h +++ b/src/DataSet_2D.h @@ -83,7 +83,8 @@ class DataSet_2D : public DataSet { } return OK; } - + /// \return True if matrix is symmetric + bool IsSymmetric() const; // ------------------------------------------- // TODO: Remove this. Only needed by DataSet_1D.h void Add(size_t,const void*) { } diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index 8aba0138ac..01d6b8e599 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -9,7 +9,10 @@ // Definition of Fortran subroutines called from this class extern "C" { // LAPACK + /// Compute the eigenvalues and (optionally) the left and/or right eigenvectors for a symmetric matrix void dspev_(char&, char&, int&, double*, double*, double*, int&, double*, int&); + /// Compute the eigenvalues and (optionally) the left and/or right eigenvectors for a general matrix + void dgeev_(char&, char&, int&, double*, int&, double*, double*, double*, int&, double*, int&, double*, int&, int&); // ARPACK void dsaupd_(int&, char&, int&, char*, int&, double&, double*, int&, double*, int&, int*, int*, double*, double*, diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 082d57cc5c..0342001035 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -234,6 +234,7 @@ DataIO_Xplor.o : DataIO_Xplor.cpp ArgList.h ArrayIterator.h AssociatedData.h Ato 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 AtomMask.h AtomType.h Box.h Cluster/Cframes.h Cluster/Cmatrix_NC.h CompactFrameArray.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_Coords.h DataSet_Coords_CRD.h DataSet_Coords_FRM.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_PairwiseCache.h DataSet_PairwiseCache_MEM.h DataSet_PairwiseCache_NC.h DataSet_Parameters.h DataSet_RemLog.h DataSet_StringVar.h DataSet_Tensor.h DataSet_Topology.h DataSet_Vector.h DataSet_Vector_Scalar.h DataSet_Zmatrix.h DataSet_double.h DataSet_float.h DataSet_integer.h DataSet_integer_disk.h DataSet_integer_mem.h DataSet_pH.h DataSet_string.h DataSet_unsignedInt.h Dimension.h FileIO.h FileName.h Frame.h Grid.h GridBin.h InputTrajCommon.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 Segment.h Spline.h StringRoutines.h SymbolExporting.h SymmetricTensor.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h TrajFrameIndex.h Trajin.h TypeNameHolder.h Unit.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_2D.o : DataSet_2D.cpp AssociatedData.h CpptrajFile.h DataSet.h DataSet_2D.h Dimension.h FileIO.h FileName.h MetaData.h Parallel.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_Coords.o : DataSet_Coords.cpp AssociatedData.h Atom.h AtomMask.h AtomType.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_Coords.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 ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Topology.h TypeNameHolder.h Unit.h Vec3.h DataSet_Coords_CRD.o : DataSet_Coords_CRD.cpp AssociatedData.h Atom.h AtomMask.h AtomType.h Box.h CompactFrameArray.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataSet.h DataSet_Coords.h DataSet_Coords_CRD.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 ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Topology.h TypeNameHolder.h Unit.h Vec3.h diff --git a/src/cpptrajfiles b/src/cpptrajfiles index 688fe361e5..c6e9723c61 100644 --- a/src/cpptrajfiles +++ b/src/cpptrajfiles @@ -205,6 +205,7 @@ COMMON_SOURCES= \ DataSet.cpp \ DataSetList.cpp \ DataSet_1D.cpp \ + DataSet_2D.cpp \ DataSet_3D.cpp \ DataSet_Coords.cpp \ DataSet_Coords_CRD.cpp \ From 30ee295631e2805e2e22a81069ffd77488c27cea Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 10 Apr 2024 14:50:40 -0400 Subject: [PATCH 089/200] Fix up depends in DataSet_Modes. Start adding general eigenvalue solve. --- src/DataSet_Modes.cpp | 28 +++++++++++++++++++++++++--- src/DataSet_Modes.h | 6 +++++- src/cpptrajdepend | 6 +++--- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index 01d6b8e599..b588de5682 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -1,9 +1,11 @@ -#include // sqrt #include "DataSet_Modes.h" -#include "CpptrajStdio.h" #include "ArgList.h" #include "Constants.h" // PI, TWOPI +#include "CpptrajStdio.h" +#include "DataSet_2D.h" +#include "DataSet_MatrixDbl.h" #include "Frame.h" +#include // sqrt #ifndef NO_MATHLIB // Definition of Fortran subroutines called from this class @@ -26,7 +28,7 @@ extern "C" { const char* DataSet_Modes::DeprecateFileMsg = "Modes should be read in prior to this command with 'readdata'\n"; -// CONSTRUCTOR +/** CONSTRUCTOR */ DataSet_Modes::DataSet_Modes() : // 0 dim indicates DataSet-specific write DataSet(MODES, GENERIC, TextFormat(TextFormat::DOUBLE, 10, 5), 0), @@ -142,6 +144,26 @@ int DataSet_Modes::AllocateModes(unsigned int n_eigenvalues, unsigned int evects return 0; } +/** Get all eigenvectors and eigenvalues from given matrix. They will be + * stored in descending order (largest eigenvalue first). + */ +int DataSet_Modes::CalcEigen(DataSet_2D const& mIn) { +# ifdef NO_MATHLIB + mprinterr("Error: Compiled without LAPACK/BLAS routines.\n"); + return 1; +# else + int n_to_calc = mIn.Ncols(); + + if (mIn.IsSymmetric()) { + return CalcEigen(mIn, n_to_calc); + } + + // If we are here, mIn is not symmetric. Need to solve general eigenvalue problem. + + return 0; +# endif /* NO_MATHLIB */ +} + /** Get n_to_calc eigenvectors and eigenvalues from given matrix. They will be * stored in descending order (largest eigenvalue first). */ diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index 46b5efd245..0a29a9c05d 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -1,6 +1,7 @@ #ifndef INC_DATASET_MODES_H #define INC_DATASET_MODES_H -#include "DataSet_MatrixDbl.h" +#include "DataSet.h" +class DataSet_2D; /// Hold eigenvalues/eigenvectors and optionally averaged coords. class DataSet_Modes : public DataSet { public: @@ -42,6 +43,9 @@ class DataSet_Modes : public DataSet { int SetModes(bool, int, int, const double*, const double*); /// Allocate memory for modes data int AllocateModes(unsigned int, unsigned int, unsigned int, unsigned int); + /// Calculate all eigenvalues/eigenvectors for given matrix + int CalcEigen(DataSet_2D const&); + /// Calculate specific # of eigenvalues/eigenvectors for given symmetric matrix int CalcEigen(DataSet_2D const&,int); void PrintModes(); int EigvalToFreq(double); diff --git a/src/cpptrajdepend b/src/cpptrajdepend index 0342001035..4d8ecd8e53 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -63,7 +63,7 @@ Action_Outtraj.o : Action_Outtraj.cpp Action.h ActionFrameCounter.h ActionState. Action_PairDist.o : Action_PairDist.cpp Action.h ActionState.h Action_PairDist.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_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Mesh.h Dimension.h DispatchObject.h DistRoutines.h FileIO.h FileName.h FileTypes.h Frame.h ImageOption.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OnlineVarT.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h Spline.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_Pairwise.o : Action_Pairwise.cpp Action.h ActionFrameCounter.h ActionState.h Action_Pairwise.h ArgList.h ArrayIterator.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_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h Dimension.h DispatchObject.h ExclusionArray.h FileIO.h FileName.h FileTypes.h Frame.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h OutputTrajCommon.h PDBfile.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h Action_Principal.o : Action_Principal.cpp Action.h ActionState.h Action_Principal.h ArgList.h ArrayIterator.h AssociatedData.h Atom.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_Mat3x3.h DataSet_Vector.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_Projection.o : Action_Projection.cpp Action.h ActionFrameCounter.h ActionState.h Action_Projection.h ArgList.h Array1D.h ArrayIterator.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_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Modes.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 Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +Action_Projection.o : Action_Projection.cpp Action.h ActionFrameCounter.h ActionState.h Action_Projection.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 DataSet_Modes.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 StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_Pucker.o : Action_Pucker.cpp Action.h ActionState.h Action_Pucker.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TorsionRoutines.h TypeNameHolder.h Unit.h Vec3.h Action_Radgyr.o : Action_Radgyr.cpp Action.h ActionState.h Action_Radgyr.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 ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Action_Radial.o : Action_Radial.cpp Action.h ActionState.h Action_Radial.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 Gpu.h ImageOption.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 cuda_kernels/kernel_rdf.cuh @@ -116,7 +116,7 @@ Analysis_Lifetime.o : Analysis_Lifetime.cpp ActionState.h Analysis.h AnalysisSta Analysis_LowestCurve.o : Analysis_LowestCurve.cpp ActionState.h Analysis.h AnalysisState.h Analysis_LowestCurve.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 HistBin.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 Analysis_Matrix.o : Analysis_Matrix.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Matrix.h ArgList.h ArrayIterator.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_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Modes.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h Analysis_MeltCurve.o : Analysis_MeltCurve.cpp ActionState.h Analysis.h AnalysisState.h Analysis_MeltCurve.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 -Analysis_Modes.o : Analysis_Modes.cpp ActionFrameCounter.h ActionState.h Analysis.h AnalysisState.h Analysis_Modes.h ArgList.h ArrayIterator.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_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Modes.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 OutputTrajCommon.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 TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h +Analysis_Modes.o : Analysis_Modes.cpp ActionFrameCounter.h ActionState.h Analysis.h AnalysisState.h Analysis_Modes.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 DataSet_Modes.h Dimension.h DispatchObject.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 Range.h ReferenceFrame.h ReplicaDimArray.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajectoryFile.h Trajout_Single.h TypeNameHolder.h Unit.h Vec3.h Analysis_MultiHist.o : Analysis_MultiHist.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Hist.h Analysis_KDE.h Analysis_MultiHist.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 HistBin.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 TrajectoryFile.h TypeNameHolder.h Unit.h Vec3.h Analysis_Multicurve.o : Analysis_Multicurve.cpp ActionState.h Analysis.h AnalysisState.h Analysis_CurveFit.h Analysis_Multicurve.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_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 Analysis_Overlap.o : Analysis_Overlap.cpp ActionState.h Analysis.h AnalysisState.h Analysis_Overlap.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_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 @@ -218,7 +218,7 @@ DataIO_CharmmRtfPrm.o : DataIO_CharmmRtfPrm.cpp ArgList.h AssociatedData.h Atom. DataIO_Cmatrix_Binary.o : DataIO_Cmatrix_Binary.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Cluster/Cframes.h Cluster/Cmatrix_Binary.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Cmatrix_Binary.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_PairwiseCache.h DataSet_PairwiseCache_MEM.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h DataIO_Cmatrix_NC.o : DataIO_Cmatrix_NC.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Cluster/Cframes.h Cluster/Cmatrix_NC.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Cmatrix_NC.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_PairwiseCache.h DataSet_PairwiseCache_MEM.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h DataIO_Cpout.o : DataIO_Cpout.cpp ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h Cph.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Cpout.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_PHREMD.h DataSet_PHREMD_Explicit.h DataSet_PHREMD_Implicit.h DataSet_pH.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h -DataIO_Evecs.o : DataIO_Evecs.cpp ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedFrame.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Evecs.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixDbl.h DataSet_Modes.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h +DataIO_Evecs.o : DataIO_Evecs.cpp ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedFrame.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Evecs.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_Modes.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h DataIO_Gnuplot.o : DataIO_Gnuplot.cpp ArgList.h Array1D.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h BufferedLine.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajStdio.h DataIO.h DataIO_Gnuplot.h DataSet.h DataSetList.h DataSet_1D.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h DataIO_Grace.o : DataIO_Grace.cpp ArgList.h AssociatedData.h Atom.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 Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h DataIO_Mdout.o : DataIO_Mdout.cpp ArgList.h AssociatedData.h Atom.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 Segment.h StringRoutines.h SymbolExporting.h TextFormat.h Timer.h Topology.h TypeNameHolder.h Unit.h Vec3.h From d981df100a847b434ad49ee702153ce462a2bf51 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Thu, 11 Apr 2024 06:48:12 -0400 Subject: [PATCH 090/200] Start thinking about how to implement the general eigenvalue calc --- src/Analysis_TICA.cpp | 11 +++++++++++ src/DataSet_Modes.cpp | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index c1a675caa4..3643b47b9c 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -459,10 +459,21 @@ const outfile5.WriteDataOut(); tmpArgs.SetAllUnmarked(); + DataSet_Modes Ct_Modes; + Ct_Modes.SetAvgCoords( meanX ); + // Want all eigenvectors if (Cxy.IsSymmetric()) { mprintf("\tCt is symmetric.\n"); + //if (Ct_Modes.CalcEigen( Ct_trans, Ct_trans.Ncols() )) { + // mprinterr("Error: Could not calculate eigenvectors and eigenvalues for Ct matrix.\n"); + // return 1; + //} } else { mprintf("\tCt is not symmetric.\n"); + //if (Ct_Modes.CalcEigen( Ct_trans )) { + // mprinterr("Error: Could not calculate eigenvectors and eigenvalues for Ct matrix (non-symmetric).\n"); + // return 1; + //} } return 0; diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index b588de5682..bfd637b226 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -159,8 +159,9 @@ int DataSet_Modes::CalcEigen(DataSet_2D const& mIn) { } // If we are here, mIn is not symmetric. Need to solve general eigenvalue problem. + mprinterr("Internal Error: DataSet_Modes::CalcEigen: Non-symmetric matrix calc not yet implemented.\n"); - return 0; + return 1; # endif /* NO_MATHLIB */ } From 30d4650b3eb4fec254f0db9d0ab1c1ed56d88747 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 12 Apr 2024 09:14:37 -0400 Subject: [PATCH 091/200] Try calculating eigenvals/eigenvecs of Ct trans --- src/Analysis_TICA.cpp | 38 ++++++++++++++++++++++++++++---------- src/DataSet_Modes.cpp | 43 +++++++++++++++++++++++++++++++++---------- src/DataSet_Modes.h | 2 +- 3 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 3643b47b9c..d6a8ec97a6 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -239,6 +239,22 @@ static void matT_times_mat_symmetric( DataSet_2D* out, } } +/// For debugging - print eigenvalues/eigenvectors to stdout +static void printEigen(DataSet_Modes const& C0_Modes, const char* desc) { + // DEBUG - print eigenvalues + std::vector tmpevals; + for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) + tmpevals.push_back( C0_Modes.Eigenvalue(ii) ); + printDarray(desc, tmpevals, "%16.8e"); + // DEBUG - print first 3 values of each eigenvector + for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { + const double* evec = C0_Modes.Eigenvector(ii); + for (int jj = 0; jj < 3; jj++) + mprintf("%12.8f", evec[jj]); + mprintf("\n"); + } +} + /** Calculate instantaneous covariance and lagged covariance arrays */ int Analysis_TICA::calculateCovariance_C0CT(DSarray const& sets) const @@ -396,7 +412,8 @@ const // TODO remove negative eigenvalues // DEBUG - print eigenvalues - Darray tmpevals; + printEigen( C0_Modes, "C0evals" ); +/* Darray tmpevals; for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) tmpevals.push_back( C0_Modes.Eigenvalue(ii) ); printDarray("C0evals", tmpevals, "%16.8e"); @@ -406,7 +423,7 @@ const for (int jj = 0; jj < 3; jj++) mprintf("%12.8f", evec[jj]); mprintf("\n"); - } + }*/ // Create matrix Ltrans, where rows are eigenvectors of C0 times eigenvalues of C0 DataSet_MatrixDbl matLtrans; @@ -464,17 +481,18 @@ const // Want all eigenvectors if (Cxy.IsSymmetric()) { mprintf("\tCt is symmetric.\n"); - //if (Ct_Modes.CalcEigen( Ct_trans, Ct_trans.Ncols() )) { - // mprinterr("Error: Could not calculate eigenvectors and eigenvalues for Ct matrix.\n"); - // return 1; - //} + if (Ct_Modes.CalcEigen( Ct_trans, Ct_trans.Ncols() )) { + mprinterr("Error: Could not calculate eigenvectors and eigenvalues for Ct matrix.\n"); + return 1; + } } else { mprintf("\tCt is not symmetric.\n"); - //if (Ct_Modes.CalcEigen( Ct_trans )) { - // mprinterr("Error: Could not calculate eigenvectors and eigenvalues for Ct matrix (non-symmetric).\n"); - // return 1; - //} + if (Ct_Modes.CalcEigen_General( Ct_trans )) { + mprinterr("Error: Could not calculate eigenvectors and eigenvalues for Ct matrix (non-symmetric).\n"); + return 1; + } } + printEigen( Ct_Modes, "Ctevals" ); return 0; } diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index bfd637b226..f258c637c4 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -144,10 +144,10 @@ int DataSet_Modes::AllocateModes(unsigned int n_eigenvalues, unsigned int evects return 0; } -/** Get all eigenvectors and eigenvalues from given matrix. They will be - * stored in descending order (largest eigenvalue first). +/** Get all eigenvectors and eigenvalues from given matrix. They + * will be stored in descending order (largest eigenvalue first). */ -int DataSet_Modes::CalcEigen(DataSet_2D const& mIn) { +int DataSet_Modes::CalcEigen_General(DataSet_2D const& mIn) { # ifdef NO_MATHLIB mprinterr("Error: Compiled without LAPACK/BLAS routines.\n"); return 1; @@ -165,8 +165,8 @@ int DataSet_Modes::CalcEigen(DataSet_2D const& mIn) { # endif /* NO_MATHLIB */ } -/** Get n_to_calc eigenvectors and eigenvalues from given matrix. They will be - * stored in descending order (largest eigenvalue first). +/** Get n_to_calc eigenvectors and eigenvalues from given symmetric matrix. + * They will be stored in descending order (largest eigenvalue first). */ int DataSet_Modes::CalcEigen(DataSet_2D const& mIn, int n_to_calc) { # ifdef NO_MATHLIB @@ -176,9 +176,33 @@ int DataSet_Modes::CalcEigen(DataSet_2D const& mIn, int n_to_calc) { bool eigenvaluesOnly = false; int info = 0; int ncols = (int)mIn.Ncols(); - if (mIn.MatrixKind() != DataSet_2D::HALF) { - mprinterr("Error: Eigenvector/value calc only for symmetric matrices.\n"); - return 1; + double* mat = 0; + // Create copy of matrix since call to dspev destroys it + if (mIn.MatrixKind() == DataSet_2D::HALF) { + mat = mIn.MatrixArray(); + } else { + // FULL or TRI matrix. Convert to HALF form. + // Check that Matrix is symmetric. + if (mIn.Nrows() != mIn.Ncols()) { + mprinterr("Error: # of rows in '%s' != # of columns; cannot calculate eigenvectors/values.\n", + mIn.legend()); + return 1; + } + if (!mIn.IsSymmetric()) { + mprintf("Warning: DataSet_Modes::CalcEigen(): Matrix '%s' does not appear to be symmetric.\n", + mIn.legend()); + // TODO report most dissimilar i,j pair? + } + //mprinterr("Error: Eigenvector/value calc only for symmetric matrices.\n"); + //return 1; + unsigned int matsize = mIn.Ncols() * (mIn.Ncols() + 1) / 2; + mat = new double[matsize]; + unsigned int idx = 0; + for (unsigned int row = 0; row < mIn.Nrows(); row++) { + for (unsigned int col = row; col < mIn.Ncols(); col++) { + mat[idx++] = mIn.GetElement(row, col); // row,col is lower, col,row is upper + } + } } // If number to calc is 0, assume we want eigenvalues only if (n_to_calc < 1) { @@ -224,8 +248,7 @@ int DataSet_Modes::CalcEigen(DataSet_2D const& mIn, int n_to_calc) { // Set up space to hold eigenvalues if (evalues_ != 0) delete[] evalues_; evalues_ = new double[ ncols ]; - // Create copy of matrix since call to dspev destroys it - double* mat = mIn.MatrixArray(); + // Lower triangle; not upper since fortran array layout is inverted w.r.t. C/C++ char uplo = 'L'; // Allocate temporary workspace diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index 0a29a9c05d..0a3274fb20 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -44,7 +44,7 @@ class DataSet_Modes : public DataSet { /// Allocate memory for modes data int AllocateModes(unsigned int, unsigned int, unsigned int, unsigned int); /// Calculate all eigenvalues/eigenvectors for given matrix - int CalcEigen(DataSet_2D const&); + int CalcEigen_General(DataSet_2D const&); /// Calculate specific # of eigenvalues/eigenvectors for given symmetric matrix int CalcEigen(DataSet_2D const&,int); void PrintModes(); From 6d5b221fd247e2a141b79276ec031c6f15a30e12 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 12 Apr 2024 10:44:04 -0400 Subject: [PATCH 092/200] More debug printing --- src/Analysis_TICA.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index d6a8ec97a6..5fbb73ac8a 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -255,6 +255,18 @@ static void printEigen(DataSet_Modes const& C0_Modes, const char* desc) { } } +/// For debugging - print eigenvalues to file +static void printEvals(DataSet_Modes const& modes, const char* fname) { + CpptrajFile outfile; + if (outfile.OpenWrite(fname)) { + mprinterr("Internal Error: printEvals: could not open file %s\n", fname); + return; + } + for (int ii = 0; ii < modes.Nmodes(); ii++) + outfile.Printf("%12.8f\n", modes.Eigenvalue(ii)); + outfile.CloseFile(); +} + /** Calculate instantaneous covariance and lagged covariance arrays */ int Analysis_TICA::calculateCovariance_C0CT(DSarray const& sets) const @@ -412,7 +424,8 @@ const // TODO remove negative eigenvalues // DEBUG - print eigenvalues - printEigen( C0_Modes, "C0evals" ); + //printEigen( C0_Modes, "C0evals" ); + printEvals(C0_Modes, "sm.dat"); /* Darray tmpevals; for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) tmpevals.push_back( C0_Modes.Eigenvalue(ii) ); @@ -427,6 +440,8 @@ const // Create matrix Ltrans, where rows are eigenvectors of C0 times eigenvalues of C0 DataSet_MatrixDbl matLtrans; + matLtrans.SetupFormat().SetFormatWidthPrecision(12,8); // DEBUG + matLtrans.SetupFormat().SetFormatType(TextFormat::DOUBLE); // DEBUG matLtrans.Allocate2D( C0_Modes.VectorSize(), C0_Modes.Nmodes() ); unsigned int idx = 0; for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { @@ -437,7 +452,7 @@ const } // DEBUG - write unnormalized matrix DataFile outfile3; - outfile3.SetupDatafile("matL.dat", tmpArgs, 0); + outfile3.SetupDatafile("matLtrans.dat", tmpArgs, 0); outfile3.AddDataSet( &matLtrans ); outfile3.WriteDataOut(); tmpArgs.SetAllUnmarked(); From a2f3ffb8e826dafb6f1e1951616ef31d5fe22f07 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 12 Apr 2024 11:31:13 -0400 Subject: [PATCH 093/200] Print eigenvectors to file function. Start filtering out bad eigenvalues --- src/Analysis_TICA.cpp | 49 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 5fbb73ac8a..31ab2cb4e8 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -7,6 +7,7 @@ #include "DataSet_MatrixDbl.h" // TODO remove? #include "DataSet_Modes.h" #include //sqrt +#include // std::max /** CONSTRUCTOR */ Analysis_TICA::Analysis_TICA() : @@ -267,6 +268,22 @@ static void printEvals(DataSet_Modes const& modes, const char* fname) { outfile.CloseFile(); } +/// For debugging - print eigenvectors to file +static void printEvecs(DataSet_Modes const& modes, const char* fname) { + CpptrajFile outfile; + if (outfile.OpenWrite(fname)) { + mprinterr("Internal Error: printEvals: could not open file %s\n", fname); + return; + } + for (int ii = 0; ii < modes.Nmodes(); ii++) { + const double* evec = modes.Eigenvector(ii); + for (int jj = 0; jj < modes.VectorSize(); jj++) + outfile.Printf("%12.8f", evec[jj]); + outfile.Printf("\n"); + } + outfile.CloseFile(); +} + /** Calculate instantaneous covariance and lagged covariance arrays */ int Analysis_TICA::calculateCovariance_C0CT(DSarray const& sets) const @@ -421,11 +438,39 @@ const mprinterr("Error: Could not calculate eigenvectors and eigenvales for C0 matrix.\n"); return 1; } - // TODO remove negative eigenvalues - + // Eigenvec/vals should come out of CalcEigen sorted from largest Eigenval to smallest. + // Determine cutoff; C0 is symmetric positive-definite so select + // cutoff so that negative eigenvalues vanish. + double min_eval = C0_Modes.Eigenvalue(C0_Modes.Nmodes()-1); +/* double min_eval = C0_Modes.Eigenvalue(0); + for (int ii = 1; ii < C0_Modes.Nmodes(); ii++) { + if (C0_Modes.EigenValue(ii) < min_eval) + min_eval = C0_Modes.Eigenvalue(ii); + }*/ + mprintf("Min C0 eigenvalue= %g\n", min_eval); + double epsilon = 1e-6; // FIXME TODO make user-definable + if (min_eval < 0) { + epsilon = std::max(epsilon, -min_eval + 1e-16); + } + // Get the absolute value of each eigenvector + Darray abs_c0_evals; + abs_c0_evals.reserve( C0_Modes.Nmodes() ); + for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) + abs_c0_evals.push_back( fabs( C0_Modes.Eigenvalue(ii) ) ); + // Find the index of the first abs(eigenvalue) smaller than epsilon + int idx_first_smaller = 0; + for (; idx_first_smaller < C0_Modes.Nmodes(); idx_first_smaller++) { + if ( abs_c0_evals[idx_first_smaller] < epsilon ) { + mprintf("%g < %g\n", abs_c0_evals[idx_first_smaller], epsilon ); + break; + } + } + mprintf("DEBUG: Index of eigenvalue smaller than %g %i\n", epsilon, idx_first_smaller); + // DEBUG - print eigenvalues //printEigen( C0_Modes, "C0evals" ); printEvals(C0_Modes, "sm.dat"); + printEvecs(C0_Modes, "Vm.dat"); /* Darray tmpevals; for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) tmpevals.push_back( C0_Modes.Eigenvalue(ii) ); From 7bafa7f724ea5ff48fd2adda5e3d8b6ce17ef0c8 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 12 Apr 2024 12:19:45 -0400 Subject: [PATCH 094/200] Filter out eigenvectors that are too small --- src/Analysis_TICA.cpp | 1 + src/DataSet_Modes.cpp | 27 +++++++++++++++++++++++++++ src/DataSet_Modes.h | 2 ++ 3 files changed, 30 insertions(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 31ab2cb4e8..d245372899 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -466,6 +466,7 @@ const } } mprintf("DEBUG: Index of eigenvalue smaller than %g %i\n", epsilon, idx_first_smaller); + C0_Modes.ResizeModes( idx_first_smaller ); // DEBUG - print eigenvalues //printEigen( C0_Modes, "C0evals" ); diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index f258c637c4..b74daeb79b 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -489,6 +489,33 @@ int DataSet_Modes::MassWtEigvect() { return 0; } +/** Resize so that only the first N modes are saved. */ +int DataSet_Modes::ResizeModes(int NtoSave) { + if (NtoSave < 1) { + mprinterr("Internal Error: DataSet_Modes::ResizeModes: # of modes to save < 1\n"); + return 1; + } + if (NtoSave >= nmodes_) { + mprintf("Warning: No need to resize modes %s; # to keep (%i) >= # modes (%i)\n", + legend(), NtoSave, nmodes_); + return 0; + } + // Resize values + double* newEvals = new double[ NtoSave ]; + std::copy( evalues_, evalues_ + NtoSave, newEvals ); + delete[] evalues_; + evalues_ = newEvals; + // Resize vectors + unsigned int newSize = NtoSave * vecsize_; + double* newEvecs = new double[ newSize ]; + std::copy( evectors_, evectors_ + newSize, newEvecs ); + delete[] evectors_; + evectors_ = newEvecs; + + nmodes_ = NtoSave; + return 0; +} + // DataSet_Modes::ReduceVectors() int DataSet_Modes::ReduceVectors() { if (evectors_ == 0) { diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index 0a3274fb20..c0334c6ad8 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -51,6 +51,8 @@ class DataSet_Modes : public DataSet { int EigvalToFreq(double); int MassWtEigvect(); int ReduceVectors(); + /// Resize so that only the first N modes are saved + int ResizeModes(int); int Thermo(CpptrajFile&, int, double, double) const; double Eigenvalue(int i) const { return evalues_[i]; } // IRED From 0e62c5df67ac387034506d650fbb25c400fb362c Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 12 Apr 2024 12:40:06 -0400 Subject: [PATCH 095/200] Enforce canonical eigenvector signs. --- src/Analysis_TICA.cpp | 22 ++++++++++++++++++++++ src/DataSet_Modes.cpp | 7 +++++++ src/DataSet_Modes.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index d245372899..f5ea24ef75 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -467,6 +467,28 @@ const } mprintf("DEBUG: Index of eigenvalue smaller than %g %i\n", epsilon, idx_first_smaller); C0_Modes.ResizeModes( idx_first_smaller ); + // Enforce canonical eigenvector signs + for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { + // Find the maximum absolute value of the eigenvector + double abs_maxval = 0; + int abs_maxidx = 0; + const double* evec = C0_Modes.Eigenvector(ii); + for (int jj = 0; jj < C0_Modes.VectorSize(); jj++) { + double dval = fabs( evec[jj] ); + if ( dval > abs_maxval ) { + abs_maxval = dval; + abs_maxidx = jj; + } + } + mprintf("argmax %i %i %g\n", ii, abs_maxidx, evec[abs_maxidx]); + double sign; + if ( evec[abs_maxidx] < 0 ) + sign = -1.0; + else + sign = 1.0; + // Multiply all elements of the eigenvector by the sign of the max abs element + C0_Modes.MultiplyEvecByFac( ii, sign ); + } // DEBUG - print eigenvalues //printEigen( C0_Modes, "C0evals" ); diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index b74daeb79b..b379601433 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -516,6 +516,13 @@ int DataSet_Modes::ResizeModes(int NtoSave) { return 0; } +/** Multiply all elements of specified eigenvector by a factor */ +void DataSet_Modes::MultiplyEvecByFac(int nvec, double fac) { + double* evec = evectors_ + (nvec * vecsize_); + for (int jj = 0; jj < vecsize_; jj++) + evec[jj] *= fac; +} + // DataSet_Modes::ReduceVectors() int DataSet_Modes::ReduceVectors() { if (evectors_ == 0) { diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index c0334c6ad8..0082fa3a81 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -47,6 +47,8 @@ class DataSet_Modes : public DataSet { int CalcEigen_General(DataSet_2D const&); /// Calculate specific # of eigenvalues/eigenvectors for given symmetric matrix int CalcEigen(DataSet_2D const&,int); + /// Multiply all elements of the specified eigenvector by given value + void MultiplyEvecByFac(int, double); void PrintModes(); int EigvalToFreq(double); int MassWtEigvect(); From 6dbfa8ec15016d2d479e57d49f1d86be7e608893 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 12 Apr 2024 16:09:25 -0400 Subject: [PATCH 096/200] Start sort by abs(eigenvalue) --- src/Analysis_TICA.cpp | 4 +++- src/DataSet_Modes.cpp | 18 +++++++++++++++++- src/DataSet_Modes.h | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index f5ea24ef75..7951a4b6f7 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -575,7 +575,9 @@ const return 1; } } - printEigen( Ct_Modes, "Ctevals" ); + //printEigen( Ct_Modes, "Ctevals" ); + printEvals(Ct_Modes, "ctvals.dat"); + printEvecs(Ct_Modes, "ctvecs.dat"); return 0; } diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index b379601433..88356b7262 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -5,7 +5,9 @@ #include "DataSet_2D.h" #include "DataSet_MatrixDbl.h" #include "Frame.h" -#include // sqrt +#include // sqrt, fabs +#include // std::pair +#include // std::sort #ifndef NO_MATHLIB // Definition of Fortran subroutines called from this class @@ -523,6 +525,20 @@ void DataSet_Modes::MultiplyEvecByFac(int nvec, double fac) { evec[jj] *= fac; } +/** Sort eigenvectors and eigenvalues in descending order of abs(eigenvalue) */ +void DataSet_Modes::SortByAbsEigenvalue() { + // Create eigenvalue/index pairs + typedef std::pair Epair; + typedef std::vector Earray; + + Earray Pairs; + for (int ii = 0; ii < nmodes_; ii++) + Pairs.push_back( Epair(fabs(evalues_[ii]), ii) ); + // Sort by abs(eigenvalue) + std::sort( Pairs.begin(), Pairs.end() ); + +} + // DataSet_Modes::ReduceVectors() int DataSet_Modes::ReduceVectors() { if (evectors_ == 0) { diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index 0082fa3a81..805072b203 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -49,6 +49,8 @@ class DataSet_Modes : public DataSet { int CalcEigen(DataSet_2D const&,int); /// Multiply all elements of the specified eigenvector by given value void MultiplyEvecByFac(int, double); + /// Descending sort by absolute value of eigenvalues + void SortByAbsEigenvalue(); void PrintModes(); int EigvalToFreq(double); int MassWtEigvect(); From ffb118a29af74c345832386578bcabd5e4ddef7f Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 12 Apr 2024 19:34:41 -0400 Subject: [PATCH 097/200] Sort by absolute value of eigenvectors --- src/Analysis_TICA.cpp | 2 ++ src/DataSet_Modes.cpp | 35 ++++++++++++++++++++++++++++++----- src/DataSet_Modes.h | 3 +++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 7951a4b6f7..19882bbd7e 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -575,6 +575,8 @@ const return 1; } } + // Sort by abs(eigenvalue) + Ct_Modes.SortByAbsEigenvalue(); //printEigen( Ct_Modes, "Ctevals" ); printEvals(Ct_Modes, "ctvals.dat"); printEvecs(Ct_Modes, "ctvecs.dat"); diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index 88356b7262..98472df39e 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -6,7 +6,6 @@ #include "DataSet_MatrixDbl.h" #include "Frame.h" #include // sqrt, fabs -#include // std::pair #include // std::sort #ifndef NO_MATHLIB @@ -525,18 +524,44 @@ void DataSet_Modes::MultiplyEvecByFac(int nvec, double fac) { evec[jj] *= fac; } +/// Class used to sort eigenvalue/index pairs +class DataSet_Modes::EvIdxPair { + public: + EvIdxPair(double e, int i) : eval_(e), idx_(i) {} + + bool operator<(EvIdxPair const& rhs) const { + return (eval_ > rhs.eval_); + } + double Eval() const { return eval_; } + int Idx() const { return idx_; } + private: + double eval_; + int idx_; +}; + /** Sort eigenvectors and eigenvalues in descending order of abs(eigenvalue) */ void DataSet_Modes::SortByAbsEigenvalue() { // Create eigenvalue/index pairs - typedef std::pair Epair; - typedef std::vector Earray; + typedef std::vector Earray; Earray Pairs; for (int ii = 0; ii < nmodes_; ii++) - Pairs.push_back( Epair(fabs(evalues_[ii]), ii) ); + Pairs.push_back( EvIdxPair(fabs(evalues_[ii]), ii) ); // Sort by abs(eigenvalue) std::sort( Pairs.begin(), Pairs.end() ); - + // Recreate the vectors array, sorted + double* newEvals = new double[ nmodes_ ]; + double* newEvecs = new double[ nmodes_ * vecsize_ ]; + for (Earray::const_iterator it = Pairs.begin(); it != Pairs.end(); ++it) { + newEvals[it - Pairs.begin()] = evalues_[it->Idx()]; + double* evecNew = newEvecs + ((it - Pairs.begin()) * vecsize_); + const double* evecOld = evectors_ + (it->Idx() * vecsize_); + std::copy( evecOld, evecOld + vecsize_, evecNew ); + } + delete[] evectors_; + delete[] evalues_; + evalues_ = newEvals; + evectors_ = newEvecs; } // DataSet_Modes::ReduceVectors() diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index 805072b203..02bd7a78c9 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -69,6 +69,9 @@ class DataSet_Modes : public DataSet { bool EvecsAreMassWtd() const { return evecsAreMassWtd_; } bool EvalsAreFreq() const { return evalsAreFreq_; } private: + /// Class used to sort eigenvalue/index pairs + class EvIdxPair; + int ReduceCovar(); int ReduceDistCovar(); From aa4359e1bc25f9c5c35803e51ed48728527176a4 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 12 Apr 2024 22:37:13 -0400 Subject: [PATCH 098/200] Put function tomodes --- src/Analysis_TICA.cpp | 5 +++-- src/DataSet_Modes.cpp | 27 +++++++++++++++++++++++++++ src/DataSet_Modes.h | 2 ++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 19882bbd7e..e186e0d940 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -468,7 +468,8 @@ const mprintf("DEBUG: Index of eigenvalue smaller than %g %i\n", epsilon, idx_first_smaller); C0_Modes.ResizeModes( idx_first_smaller ); // Enforce canonical eigenvector signs - for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { + C0_Modes.SetCanonicalEvecSigns(); +/* for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { // Find the maximum absolute value of the eigenvector double abs_maxval = 0; int abs_maxidx = 0; @@ -488,7 +489,7 @@ const sign = 1.0; // Multiply all elements of the eigenvector by the sign of the max abs element C0_Modes.MultiplyEvecByFac( ii, sign ); - } + }*/ // DEBUG - print eigenvalues //printEigen( C0_Modes, "C0evals" ); diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index 98472df39e..dbb59c85a6 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -564,6 +564,33 @@ void DataSet_Modes::SortByAbsEigenvalue() { evectors_ = newEvecs; } +/** Enforce canonical eigenvector signs by multiplying every element of each + * eigenvector by the sign of the element with the greatest absolute value. + */ +void DataSet_Modes::SetCanonicalEvecSigns() { + for (int ii = 0; ii < Nmodes(); ii++) { + // Find the maximum absolute value of the eigenvector + double abs_maxval = 0; + int abs_maxidx = 0; + const double* evec = Eigenvector(ii); + for (int jj = 0; jj < VectorSize(); jj++) { + double dval = fabs( evec[jj] ); + if ( dval > abs_maxval ) { + abs_maxval = dval; + abs_maxidx = jj; + } + } + mprintf("argmax %i %i %g\n", ii, abs_maxidx, evec[abs_maxidx]); + double sign; + if ( evec[abs_maxidx] < 0 ) + sign = -1.0; + else + sign = 1.0; + // Multiply all elements of the eigenvector by the sign of the max abs element + MultiplyEvecByFac( ii, sign ); + } +} + // DataSet_Modes::ReduceVectors() int DataSet_Modes::ReduceVectors() { if (evectors_ == 0) { diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index 02bd7a78c9..48ff2ca8e5 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -51,6 +51,8 @@ class DataSet_Modes : public DataSet { void MultiplyEvecByFac(int, double); /// Descending sort by absolute value of eigenvalues void SortByAbsEigenvalue(); + /// Enforce canonical signs for each eigenvector + void SetCanonicalEvecSigns(); void PrintModes(); int EigvalToFreq(double); int MassWtEigvect(); From c4e8a3d5483acab403f65743afcd2650b4a1dc11 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Sat, 13 Apr 2024 15:17:45 -0400 Subject: [PATCH 099/200] Add function to get transpose of incoming DataSet_2D --- src/Analysis_TICA.cpp | 15 +++++++++++++++ src/DataSet_2D.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index e186e0d940..424893a7ab 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -582,6 +582,21 @@ const printEvals(Ct_Modes, "ctvals.dat"); printEvecs(Ct_Modes, "ctvecs.dat"); + // The following is to test the math in the same exact order as L x Ct_Modes^T + DataSet_MatrixDbl matL; + ret = matL.TransposeOf( matLtrans ); + if (ret != DataSet_2D::OK) { + mprinterr("Error: Could not get transpose of L^T\n"); + if ( ret == DataSet_2D::ALLOC_ERR) mprinterr("Error: Allocation error.\n"); + return 1; + } + // DEBUG - write unnormalized matrix + DataFile outfile6; + outfile6.SetupDatafile("matL.dat", tmpArgs, 0); + outfile6.AddDataSet( &matL ); + outfile6.WriteDataOut(); + tmpArgs.SetAllUnmarked(); + return 0; } diff --git a/src/DataSet_2D.h b/src/DataSet_2D.h index d162a97bf6..f51216d399 100644 --- a/src/DataSet_2D.h +++ b/src/DataSet_2D.h @@ -83,6 +83,34 @@ class DataSet_2D : public DataSet { } return OK; } + /// Set this matrix with the result of M1^T + RetType TransposeOf(DataSet_2D const& M1) { + RetType ret = ERR; + MatrixKindType m1kind = M1.MatrixKind(); + if (m1kind == FULL) { + if (Allocate2D( M1.Nrows(), M1.Ncols() )) return ALLOC_ERR; + ret = OK; + for (unsigned int row = 0; row < M1.Nrows(); row++) { + for (unsigned int col = 0; col < M1.Ncols(); col++) + SetElement( row, col, M1.GetElement(col, row) ); + } + } else if (m1kind == HALF) { + if (AllocateHalf( M1.Ncols() )) return ALLOC_ERR; + ret = OK; + for (unsigned int row = 0; row < M1.Nrows(); row++) { + for (unsigned int col = row; col < M1.Ncols(); col++) + SetElement( row, col, M1.GetElement(col, row) ); + } + } else if (m1kind == TRI) { + if (AllocateTriangle( M1.Ncols() )) return ALLOC_ERR; + ret = OK; + for (unsigned int row = 0; row < M1.Nrows(); row++) { + for (unsigned int col = row + 1; col < M1.Ncols(); col++) + SetElement( row, col, M1.GetElement(col, row) ); + } + } + return ret; + } /// \return True if matrix is symmetric bool IsSymmetric() const; // ------------------------------------------- From 2d52fb33baae183a9c0d96ac146fe8233efc9ba1 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 15 Apr 2024 10:34:11 -0400 Subject: [PATCH 100/200] Calculate matR --- src/Analysis_TICA.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 424893a7ab..58fba2d82f 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -596,6 +596,39 @@ const outfile6.AddDataSet( &matL ); outfile6.WriteDataOut(); tmpArgs.SetAllUnmarked(); + // Put eigenvectors in columns + DataSet_MatrixDbl R_trans; + if (R_trans.Allocate2D( Ct_Modes.Nmodes(), Ct_Modes.VectorSize() )) { + mprinterr("Error: Could not allocate matrix for Ct eigenvectors.\n"); + return 1; + } + idx = 0; + for (unsigned int row = 0; row < R_trans.Nrows(); row++) { + for (unsigned int col = 0; col < R_trans.Ncols(); col++) { + const double* evec = Ct_Modes.Eigenvector(col); + R_trans[idx++] = evec[row]; + } + } + // DEBUG - write unnormalized matrix + R_trans.SetupFormat().SetFormatWidthPrecision(12,8); // DEBUG + R_trans.SetupFormat().SetFormatType(TextFormat::DOUBLE); // DEBUG + DataFile outfile7; + outfile7.SetupDatafile("R_trans.dat", tmpArgs, 0); + outfile7.AddDataSet( &R_trans ); + outfile7.WriteDataOut(); + tmpArgs.SetAllUnmarked(); + + // Calculate L * R^T + DataSet_MatrixDbl matR; + matR.Multiply( matL, R_trans ); + // DEBUG - write unnormalized matrix + matR.SetupFormat().SetFormatWidthPrecision(12,8); // DEBUG + matR.SetupFormat().SetFormatType(TextFormat::DOUBLE); // DEBUG + DataFile outfile8; + outfile8.SetupDatafile("matR.dat", tmpArgs, 0); + outfile8.AddDataSet( &matR ); + outfile8.WriteDataOut(); + tmpArgs.SetAllUnmarked(); return 0; } From 86daeb6161bfa64af9305e3aa43ebf0685f630d6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 15 Apr 2024 11:21:23 -0400 Subject: [PATCH 101/200] Change eigenvector signs of the matR matrix --- src/Analysis_TICA.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 58fba2d82f..20077a557b 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -621,6 +621,32 @@ const // Calculate L * R^T DataSet_MatrixDbl matR; matR.Multiply( matL, R_trans ); + + // Change eigenvector (in columns) signs + for (unsigned int col = 0; col < matR.Ncols(); col++) { + // Find the maximum absolute value of the eigenvector (in column) + double abs_maxval = 0; + unsigned int abs_maxidx = 0; + for (unsigned int row = 0; row < matR.Nrows(); row++) { + double dval = fabs( matR.GetElement( col, row ) ); + if (dval > abs_maxval) { + abs_maxval = dval; + abs_maxidx = row; + } + } + double elt = matR.GetElement(col, abs_maxidx); + mprintf("argmax %u %u %g\n", col, abs_maxidx, elt); + double sign; + if (elt < 0) + sign = -1.0; + else + sign = 1.0; + // Multiply all elements of eigenvector (in column) by sign of max abs element + for (unsigned int row = 0; row < matR.Nrows(); row++) { + double dval = matR.GetElement( col, row ) * sign; + matR.SetElement( col, row, dval ); + } + } // DEBUG - write unnormalized matrix matR.SetupFormat().SetFormatWidthPrecision(12,8); // DEBUG matR.SetupFormat().SetFormatType(TextFormat::DOUBLE); // DEBUG From b2bd607d1c9be3af12d7af77fec37179709654d6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 15 Apr 2024 11:23:47 -0400 Subject: [PATCH 102/200] Will likely just leave eigenvector sign function in the TICA analysis --- src/Analysis_TICA.cpp | 6 +++--- src/DataSet_Modes.cpp | 4 ++-- src/DataSet_Modes.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 20077a557b..c39e75edb4 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -468,8 +468,8 @@ const mprintf("DEBUG: Index of eigenvalue smaller than %g %i\n", epsilon, idx_first_smaller); C0_Modes.ResizeModes( idx_first_smaller ); // Enforce canonical eigenvector signs - C0_Modes.SetCanonicalEvecSigns(); -/* for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { + //C0_Modes.SetCanonicalEvecSigns(); + for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { // Find the maximum absolute value of the eigenvector double abs_maxval = 0; int abs_maxidx = 0; @@ -489,7 +489,7 @@ const sign = 1.0; // Multiply all elements of the eigenvector by the sign of the max abs element C0_Modes.MultiplyEvecByFac( ii, sign ); - }*/ + } // DEBUG - print eigenvalues //printEigen( C0_Modes, "C0evals" ); diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index dbb59c85a6..9e44eef021 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -567,7 +567,7 @@ void DataSet_Modes::SortByAbsEigenvalue() { /** Enforce canonical eigenvector signs by multiplying every element of each * eigenvector by the sign of the element with the greatest absolute value. */ -void DataSet_Modes::SetCanonicalEvecSigns() { +/*void DataSet_Modes::SetCanonicalEvecSigns() { for (int ii = 0; ii < Nmodes(); ii++) { // Find the maximum absolute value of the eigenvector double abs_maxval = 0; @@ -589,7 +589,7 @@ void DataSet_Modes::SetCanonicalEvecSigns() { // Multiply all elements of the eigenvector by the sign of the max abs element MultiplyEvecByFac( ii, sign ); } -} +}*/ // DataSet_Modes::ReduceVectors() int DataSet_Modes::ReduceVectors() { diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index 48ff2ca8e5..39f44a8ed0 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -52,7 +52,7 @@ class DataSet_Modes : public DataSet { /// Descending sort by absolute value of eigenvalues void SortByAbsEigenvalue(); /// Enforce canonical signs for each eigenvector - void SetCanonicalEvecSigns(); + //void SetCanonicalEvecSigns(); void PrintModes(); int EigvalToFreq(double); int MassWtEigvect(); From 8464a92320a463c5c2f52e136d01d0650e71b0a9 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 15 Apr 2024 11:27:57 -0400 Subject: [PATCH 103/200] Keep sign functionality in tica --- src/Analysis_TICA.cpp | 1 - src/DataSet_Modes.cpp | 27 --------------------------- src/DataSet_Modes.h | 2 -- 3 files changed, 30 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index c39e75edb4..8bba19be08 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -468,7 +468,6 @@ const mprintf("DEBUG: Index of eigenvalue smaller than %g %i\n", epsilon, idx_first_smaller); C0_Modes.ResizeModes( idx_first_smaller ); // Enforce canonical eigenvector signs - //C0_Modes.SetCanonicalEvecSigns(); for (int ii = 0; ii < C0_Modes.Nmodes(); ii++) { // Find the maximum absolute value of the eigenvector double abs_maxval = 0; diff --git a/src/DataSet_Modes.cpp b/src/DataSet_Modes.cpp index 9e44eef021..98472df39e 100644 --- a/src/DataSet_Modes.cpp +++ b/src/DataSet_Modes.cpp @@ -564,33 +564,6 @@ void DataSet_Modes::SortByAbsEigenvalue() { evectors_ = newEvecs; } -/** Enforce canonical eigenvector signs by multiplying every element of each - * eigenvector by the sign of the element with the greatest absolute value. - */ -/*void DataSet_Modes::SetCanonicalEvecSigns() { - for (int ii = 0; ii < Nmodes(); ii++) { - // Find the maximum absolute value of the eigenvector - double abs_maxval = 0; - int abs_maxidx = 0; - const double* evec = Eigenvector(ii); - for (int jj = 0; jj < VectorSize(); jj++) { - double dval = fabs( evec[jj] ); - if ( dval > abs_maxval ) { - abs_maxval = dval; - abs_maxidx = jj; - } - } - mprintf("argmax %i %i %g\n", ii, abs_maxidx, evec[abs_maxidx]); - double sign; - if ( evec[abs_maxidx] < 0 ) - sign = -1.0; - else - sign = 1.0; - // Multiply all elements of the eigenvector by the sign of the max abs element - MultiplyEvecByFac( ii, sign ); - } -}*/ - // DataSet_Modes::ReduceVectors() int DataSet_Modes::ReduceVectors() { if (evectors_ == 0) { diff --git a/src/DataSet_Modes.h b/src/DataSet_Modes.h index 39f44a8ed0..02bd7a78c9 100644 --- a/src/DataSet_Modes.h +++ b/src/DataSet_Modes.h @@ -51,8 +51,6 @@ class DataSet_Modes : public DataSet { void MultiplyEvecByFac(int, double); /// Descending sort by absolute value of eigenvalues void SortByAbsEigenvalue(); - /// Enforce canonical signs for each eigenvector - //void SetCanonicalEvecSigns(); void PrintModes(); int EigvalToFreq(double); int MassWtEigvect(); From 79ed4a078e069408d7e0f0c12aaa41c900903ea4 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 15 Apr 2024 11:36:52 -0400 Subject: [PATCH 104/200] Add note --- src/Analysis_TICA.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 8bba19be08..b53e542e8c 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -618,6 +618,7 @@ const tmpArgs.SetAllUnmarked(); // Calculate L * R^T + // TODO calculate R^T * L^T to get (LR)^T instead? DataSet_MatrixDbl matR; matR.Multiply( matL, R_trans ); From d3b2d86164e314f54ab29baaffc2e724b5e68fde Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 15 Apr 2024 11:41:06 -0400 Subject: [PATCH 105/200] Add Multiply_M1transpose --- src/Analysis_TICA.cpp | 1 + src/DataSet_2D.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index b53e542e8c..b278649090 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -430,6 +430,7 @@ const delete CenteredY[jdx]; } + // --------------------------------------------- // Get C0 eigenvectors/eigenvalues DataSet_Modes C0_Modes; C0_Modes.SetAvgCoords( meanX ); diff --git a/src/DataSet_2D.h b/src/DataSet_2D.h index f51216d399..3622d201a0 100644 --- a/src/DataSet_2D.h +++ b/src/DataSet_2D.h @@ -83,6 +83,23 @@ class DataSet_2D : public DataSet { } return OK; } + /// Set this matrix with the result of M1^T x M2 + RetType Multiply_M1transpose(DataSet_2D const& M1, DataSet_2D const& M2) { + if (M1.Nrows() != M2.Nrows()) return DIM_MISMATCH; + unsigned int len = M1.Nrows(); + if (Allocate2D( M2.Ncols(), M1.Ncols() )) return ALLOC_ERR; + unsigned int idx = 0; + for (unsigned int row = 0; row != Nrows(); row++) { + for (unsigned int col = 0; col != Ncols(); col++) { + double sum = 0; + for (unsigned int k = 0; k != len; k++) + sum += M1.GetElement(row, k) * M2.GetElement(col, k); + SetElement(idx++, sum); + } + } + return OK; + } + /// Set this matrix with the result of M1^T RetType TransposeOf(DataSet_2D const& M1) { RetType ret = ERR; From 1008e7acd32500275327d6d6d2ae94ab07d2666d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 15 Apr 2024 11:50:43 -0400 Subject: [PATCH 106/200] Use DataSet_double directly --- src/Analysis_TICA.cpp | 58 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index b278649090..7ce41e5b3b 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -164,14 +164,14 @@ static inline void calculate_sum(std::vector& sumX, } /// Subtract the set mean from every element of the set -static inline void subtract_mean(DataSet_1D* outPtr, +static inline void subtract_mean(DataSet_double& out, DataSet_1D const* in, unsigned int nelt_, double total_weight, double sumX, unsigned int startFrame, unsigned int endFrame) { - DataSet_double& out = static_cast( *outPtr ); +// DataSet_double& out = static_cast( *outPtr ); //out.clear(); out.Allocate(DataSet::SizeArray(1, endFrame - startFrame)); //out.reserve(endFrame - startFrame); @@ -184,21 +184,21 @@ static inline void subtract_mean(DataSet_1D* outPtr, /// Multiply transpose of matrix by matrix TODO since the resulting matrix is supposed to be symmetric we can speed this up static void matT_times_mat( DataSet_2D* out, - std::vector const& M1, - std::vector const& M2) + std::vector const& M1, + std::vector const& M2) { unsigned int Nrows = M1.size(); unsigned int Ncols = M2.size(); out->Allocate2D( Ncols, Nrows ); unsigned int idx = 0; for (unsigned int row = 0; row < Nrows; row++) { - DataSet_1D* seti = M1[row]; + DataSet_double const& seti = M1[row]; for (unsigned int col = 0; col < Ncols; col++) { - DataSet_1D* setj = M2[col]; + DataSet_double const& setj = M2[col]; // seti->Size() must equal setj->Size() double sum = 0; - for (unsigned int k = 0; k < seti->Size(); k++) { - sum += (seti->Dval(k) * setj->Dval(k)); + for (unsigned int k = 0; k < seti.Size(); k++) { + sum += (seti.Dval(k) * setj.Dval(k)); } out->SetElement(idx++, sum); //mprintf(" %12.4f", sum); @@ -209,8 +209,8 @@ static void matT_times_mat( DataSet_2D* out, /// For eaach matrix, Multiply transpose of matrix by matrix, then sum static void matT_times_mat_symmetric( DataSet_2D* out, - std::vector const& M1, - std::vector const& M2 ) + std::vector const& M1, + std::vector const& M2 ) { if (M1.size() != M2.size()) { mprinterr("Internal Error: matT_times_mat_symmetric: Different # of sets.\n"); @@ -221,17 +221,17 @@ static void matT_times_mat_symmetric( DataSet_2D* out, unsigned int Ncols = Nrows; unsigned int idx = 0; for (unsigned int row = 0; row < Nrows; row++) { - DataSet_1D* seti1 = M1[row]; - DataSet_1D* seti2 = M2[row]; + DataSet_double const& seti1 = M1[row]; + DataSet_double const& seti2 = M2[row]; for (unsigned int col = row; col < Ncols; col++) { - DataSet_1D* setj1 = M1[col]; - DataSet_1D* setj2 = M2[col]; + DataSet_double const& setj1 = M1[col]; + DataSet_double const& setj2 = M2[col]; double sum = 0; // ALL SETS MUST HAVE SAME SIZE - unsigned int nframes = seti1->Size(); + unsigned int nframes = seti1.Size(); for (unsigned int k = 0; k < nframes; k++) { - sum += (seti1->Dval(k) * setj1->Dval(k)); - sum += (seti2->Dval(k) * setj2->Dval(k)); + sum += (seti1.Dval(k) * setj1.Dval(k)); + sum += (seti2.Dval(k) * setj2.Dval(k)); } out->SetElement(idx++, sum); //mprintf(" %12.4f", sum); @@ -362,22 +362,22 @@ const printDarray("sx_raw_centered", sx_centered, "%16.8e"); printDarray("sy_raw_centered", sy_centered, "%16.8e"); - // Remove mean // FIXME do without new - typedef std::vector DDArray; + // Remove mean + typedef std::vector DDArray; DDArray CenteredX(sets.size()); DDArray CenteredY(sets.size()); - for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { - CenteredX[jdx] = (DataSet_1D*)new DataSet_double(); - CenteredY[jdx] = (DataSet_1D*)new DataSet_double(); - } + //for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { + // CenteredX[jdx] = (DataSet_1D*)new DataSet_double(); + // CenteredY[jdx] = (DataSet_1D*)new DataSet_double(); + //} Darray tmpx, tmpy; // DEBUG FIXME // Because symmetric, sy = sx //TODO use meanX set Darray const& sy = sx; for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { subtract_mean(CenteredX[jdx], sets[jdx], nelt_, total_weight, sx[jdx], 0, c0end); subtract_mean(CenteredY[jdx], sets[jdx], nelt_, total_weight, sy[jdx], ctstart, maxFrames); - tmpx.push_back( CenteredX[jdx]->Dval(0) ); // DEBUG - tmpy.push_back( CenteredY[jdx]->Dval(0) ); // DEBUG + tmpx.push_back( CenteredX[jdx].Dval(0) ); // DEBUG + tmpy.push_back( CenteredY[jdx].Dval(0) ); // DEBUG } printDarray("X0", tmpx, "%16.8e"); printDarray("Y0", tmpy, "%16.8e"); @@ -425,10 +425,10 @@ const tmpArgs.SetAllUnmarked(); // Free memory - for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { - delete CenteredX[jdx]; - delete CenteredY[jdx]; - } + //for (unsigned int jdx = 0; jdx != sets.size(); jdx++) { + // delete CenteredX[jdx]; + // delete CenteredY[jdx]; + //} // --------------------------------------------- // Get C0 eigenvectors/eigenvalues From 266057453ac2bc371522b88445c4357bbc3ef755 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 15 Apr 2024 12:08:13 -0400 Subject: [PATCH 107/200] Add note --- src/Analysis_TICA.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index 7ce41e5b3b..df18326555 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -382,6 +382,7 @@ const printDarray("X0", tmpx, "%16.8e"); printDarray("Y0", tmpy, "%16.8e"); + // --------------------------------------------- ArgList tmpArgs("square2d noheader"); // Calculate Cxxyy DataSet_MatrixDbl CXXYY;// = (DataSet_2D*)new DataSet_MatrixDbl(); From c19bace5185ea561de55a8b78559462ad9c52a9d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 15 Apr 2024 12:24:02 -0400 Subject: [PATCH 108/200] Add map options --- src/Analysis_TICA.cpp | 26 ++++++++++++++++++++++++-- src/Analysis_TICA.h | 23 +++++++++++++++-------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/Analysis_TICA.cpp b/src/Analysis_TICA.cpp index df18326555..bc4c115497 100644 --- a/src/Analysis_TICA.cpp +++ b/src/Analysis_TICA.cpp @@ -15,14 +15,17 @@ Analysis_TICA::Analysis_TICA() : lag_(0), useMass_(false), debugC0_(0), - debugCT_(0) + debugCT_(0), + evectorScale_(NO_SCALING) { SetHidden(true); } // Analysis_TICA::Help() void Analysis_TICA::Help() const { - mprintf("[crdset ] [lag