diff --git a/doc/CpptrajManual.pdf b/doc/CpptrajManual.pdf index 9b8d909fb6..f10dd3fac5 100644 Binary files a/doc/CpptrajManual.pdf and b/doc/CpptrajManual.pdf differ diff --git a/doc/DocumentChecksums.txt b/doc/DocumentChecksums.txt index 6566b16707..5d21a6dc7e 100644 --- a/doc/DocumentChecksums.txt +++ b/doc/DocumentChecksums.txt @@ -1,3 +1,3 @@ b37726e7a841f6fc695ecd7fb040ffbf CpptrajDevelopmentGuide.lyx -8fe330adac3e61d024fceb51b814a8ba cpptraj.lyx +5af47ac2cb73a9c7cd83fc82c1d2f421 cpptraj.lyx 5d9b5b5ed47a3ded57b6464df99b3585 CpptrajManual.lyx diff --git a/doc/cpptraj.lyx b/doc/cpptraj.lyx index e99268f12a..d1a7927b82 100644 --- a/doc/cpptraj.lyx +++ b/doc/cpptraj.lyx @@ -6,12 +6,6 @@ \origin unavailable \textclass article \begin_preamble -% Added by lyx2lyx -%% Variable width box for table cells -\newenvironment{cellvarwidth}[1][t] - {\begin{varwidth}[#1]{\linewidth}} - {\@finalstrut\@arstrutbox\end{varwidth}} -% Added by lyx2lyx \usepackage{varwidth} \end_preamble \use_default_options true @@ -20918,36 +20912,11 @@ Calculate the dihedral angle using four points. \begin_inset Text \begin_layout Plain Layout -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - - -\backslash -begin{cellvarwidth} -\end_layout - -\end_inset - -dihrms +dihrms, \end_layout \begin_layout Plain Layout dihedralrms -\begin_inset ERT -status collapsed - -\begin_layout Plain Layout - - -\backslash -end{cellvarwidth} -\end_layout - -\end_inset - - \end_layout \end_inset @@ -55231,7 +55200,8 @@ vectormath vec1 vec2 [out ] [norm] [name \end_layout \begin_layout LyX-Code - [ dotproduct | dotangle | crossproduct | magnitude ] + [ dotproduct | dotangle | crossproduct | magnitude | average + ] \begin_inset Separator latexpar \end_inset @@ -55271,6 +55241,24 @@ vec2 Name of file to write output to. \end_layout +\begin_layout Description +[norm] Normalize the vectors; this will affect any subsequent calculations + with the vectors. + This is turned on automatically if +\series bold +dotangle/magnitude +\series default + specified. +\end_layout + +\begin_layout Description +[name +\begin_inset space ~ +\end_inset + +] Output data set name. +\end_layout + \begin_layout Description [dotproduct] (Default) Calculate the dot-product of the two vectors. \end_layout @@ -55297,13 +55285,59 @@ vec2 \end_layout \begin_layout Description -[norm] Normalize the vectors; this will affect any subsequent calculations - with the vectors. - This is turned on automatically if +[average] Calculate the average (over frames) of vectors selected by \series bold -dotangle/magnitude +vec1 \series default - specified. + (no need to specify +\series bold +vec2 +\series default +). +\end_layout + +\begin_layout Standard +DataSets created: +\end_layout + +\begin_layout Description +[Dot] (double) Vector dot product ( +\series bold +dotproduct +\series default + only). +\end_layout + +\begin_layout Description +[Angle] (double) Angle in degrees from vector dot product ( +\series bold +dotangle +\series default + only). +\end_layout + +\begin_layout Description +[Cross] (vector) Cross product ( +\series bold +crossproduct +\series default + only). +\end_layout + +\begin_layout Description +[Mag] (double) Magnitude ( +\series bold +magnitude +\series default + only). +\end_layout + +\begin_layout Description +[Avg] (vector) Average vector ( +\series bold +average +\series default + only). \end_layout \end_deeper diff --git a/src/Analysis_VectorMath.cpp b/src/Analysis_VectorMath.cpp index 041b937234..f0bd3ae70a 100644 --- a/src/Analysis_VectorMath.cpp +++ b/src/Analysis_VectorMath.cpp @@ -8,7 +8,7 @@ /// Strings corresponding to modes, used in output. const char* Analysis_VectorMath::ModeString[] = { - "Dot product", "Angle from dot product", "Cross product", "Magnitude" }; + "Dot product", "Angle from dot product", "Cross product", "Magnitude", "Average" }; // CONSTRUCTOR Analysis_VectorMath::Analysis_VectorMath() : @@ -18,12 +18,12 @@ Analysis_VectorMath::Analysis_VectorMath() : void Analysis_VectorMath::Help() const { mprintf("\tvec1 vec2 [out ] [norm] [name ]\n" - "\t[ dotproduct | dotangle | crossproduct | magnitude ]\n" + "\t[ dotproduct | dotangle | crossproduct | magnitude | average ]\n" " Calculate dot product, angle from dot product (degrees), or cross product\n" " for specified vectors. Either vec1 or vec2 can be size 1, otherwise they\n" - " must both be the same size. If 'magnitude' is specified, just calculate\n" - " the magnitudes of the vectors selected by 'vec1' (no need to specify\n" - " 'vec2').\n"); + " must both be the same size.\n" + " If 'magnitude' or 'average' is specified, just calculate the magnitudes\n" + " or averages of the vector selected by 'vec1' (no need to specify 'vec2').\n"); } // Analysis_VectorMath::Setup() @@ -54,6 +54,11 @@ Analysis::RetType Analysis_VectorMath::Setup(ArgList& analyzeArgs, AnalysisSetup mprintf("Warning: 'norm' does not make sense with 'magnitude', ignoring.\n"); norm_ = false; } + } else if (analyzeArgs.hasKey("average")) { + mode_ = AVERAGE; + dtype = DataSet::VECTOR; + dname = "Avg"; + requires_two_vecs = false; } // Get Vectors @@ -145,6 +150,26 @@ const return 0; } +/** Calculate the average vector. */ +int Analysis_VectorMath::Average(DataSet* Dout, DataSet_Vector const& V1) +const +{ + DataSet_Vector& Out = static_cast( *Dout ); + Vec3 VXYZ(0.0, 0.0, 0.0); + for (unsigned int idx = 0; idx < V1.Size(); idx++) + VXYZ += V1[idx]; + VXYZ /= (double)V1.Size(); + if (V1.HasOrigins()) { + Vec3 OXYZ(0.0, 0.0, 0.0); + for (unsigned int idx = 0; idx < V1.Size(); idx++) + OXYZ += V1.OXYZ(idx); + OXYZ /= (double)V1.Size(); + Out.AddVxyzo( VXYZ, OXYZ ); + } else + Out.AddVxyz( VXYZ ); + return 0; +} + // Analysis_VectorMath::DotProduct() int Analysis_VectorMath::DotProduct(DataSet* Dout, DataSet_Vector& V1, DataSet_Vector& V2, unsigned int vmax, unsigned int v1inc, unsigned int v2inc) @@ -235,6 +260,8 @@ Analysis::RetType Analysis_VectorMath::Analyze() { int err = 1; if (mode_ == MAGNITUDE) err = Magnitude( DataOut_[ii], *(vinfo1_[ii]) ); + else if (mode_ == AVERAGE) + err = Average( DataOut_[ii], *(vinfo1_[ii]) ); if (err != 0) { mprinterr("Error: A problem occurred when performing vector math for set '%s'\n", vinfo1_[ii]->legend()); diff --git a/src/Analysis_VectorMath.h b/src/Analysis_VectorMath.h index 2db995b74b..0fa3eee64e 100644 --- a/src/Analysis_VectorMath.h +++ b/src/Analysis_VectorMath.h @@ -11,10 +11,11 @@ class Analysis_VectorMath : public Analysis { Analysis::RetType Setup(ArgList&, AnalysisSetup&, int); Analysis::RetType Analyze(); private: - enum ModeType { DOTPRODUCT = 0, DOTANGLE, CROSSPRODUCT, MAGNITUDE }; + enum ModeType { DOTPRODUCT = 0, DOTANGLE, CROSSPRODUCT, MAGNITUDE, AVERAGE }; static const char* ModeString[]; int Magnitude(DataSet*, DataSet_Vector const&) const; + int Average(DataSet*, DataSet_Vector const&) const; int DotProduct(DataSet*, DataSet_Vector&, DataSet_Vector&, unsigned int, unsigned int, unsigned int) const; int CrossProduct(DataSet*, DataSet_Vector&, DataSet_Vector&, diff --git a/src/Version.h b/src/Version.h index 320c354fb6..02534d7d05 100644 --- a/src/Version.h +++ b/src/Version.h @@ -12,7 +12,7 @@ * Whenever a number that precedes is incremented, all subsequent * numbers should be reset to 0. */ -#define CPPTRAJ_INTERNAL_VERSION "V6.29.18" +#define CPPTRAJ_INTERNAL_VERSION "V6.29.19" /// PYTRAJ relies on this #define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION #endif diff --git a/test/Test_VectorMath/Average.dat.save b/test/Test_VectorMath/Average.dat.save new file mode 100644 index 0000000000..70ea14bbfc --- /dev/null +++ b/test/Test_VectorMath/Average.dat.save @@ -0,0 +1,2 @@ +#Frame V12avg + 1 13.1965 -12.6155 3.4216 6.7847 0.1828 -13.8070 diff --git a/test/Test_VectorMath/RunTest.sh b/test/Test_VectorMath/RunTest.sh index 0b538247ae..2eb39ac9d9 100755 --- a/test/Test_VectorMath/RunTest.sh +++ b/test/Test_VectorMath/RunTest.sh @@ -2,7 +2,8 @@ . ../MasterTest.sh -CleanFiles vectors.dat dotproduct.dat corr.in v1init_dot_v1.dat Magnitude.dat +CleanFiles vectors.dat dotproduct.dat corr.in v1init_dot_v1.dat Magnitude.dat \ + Average.dat INPUT="corr.in" TOP=../tz2.parm7 @@ -37,5 +38,13 @@ EOF RunCpptraj "$UNITNAME" DoTest Magnitude.dat.save Magnitude.dat +UNITNAME='Vector average tests' +cat > corr.in <