Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified doc/CpptrajManual.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion doc/DocumentChecksums.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
b37726e7a841f6fc695ecd7fb040ffbf CpptrajDevelopmentGuide.lyx
8fe330adac3e61d024fceb51b814a8ba cpptraj.lyx
5af47ac2cb73a9c7cd83fc82c1d2f421 cpptraj.lyx
5d9b5b5ed47a3ded57b6464df99b3585 CpptrajManual.lyx
110 changes: 72 additions & 38 deletions doc/cpptraj.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -55231,7 +55200,8 @@ vectormath vec1 <vecname1> vec2 <vecname2> [out <filename>] [norm] [name
\end_layout

\begin_layout LyX-Code
[ dotproduct | dotangle | crossproduct | magnitude ]
[ dotproduct | dotangle | crossproduct | magnitude | average
]
\begin_inset Separator latexpar
\end_inset

Expand Down Expand Up @@ -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

<setname>] Output data set name.
\end_layout

\begin_layout Description
[dotproduct] (Default) Calculate the dot-product of the two vectors.
\end_layout
Expand All @@ -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
<setname>[Dot] (double) Vector dot product (
\series bold
dotproduct
\series default
only).
\end_layout

\begin_layout Description
<setname>[Angle] (double) Angle in degrees from vector dot product (
\series bold
dotangle
\series default
only).
\end_layout

\begin_layout Description
<setname>[Cross] (vector) Cross product (
\series bold
crossproduct
\series default
only).
\end_layout

\begin_layout Description
<setname>[Mag] (double) Magnitude (
\series bold
magnitude
\series default
only).
\end_layout

\begin_layout Description
<setname>[Avg] (vector) Average vector (
\series bold
average
\series default
only).
\end_layout

\end_deeper
Expand Down
37 changes: 32 additions & 5 deletions src/Analysis_VectorMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() :
Expand All @@ -18,12 +18,12 @@ Analysis_VectorMath::Analysis_VectorMath() :

void Analysis_VectorMath::Help() const {
mprintf("\tvec1 <vecname1> vec2 <vecname2> [out <filename>] [norm] [name <setname>]\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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<DataSet_Vector&>( *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)
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion src/Analysis_VectorMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -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&,
Expand Down
2 changes: 1 addition & 1 deletion src/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Whenever a number that precedes <revision> 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
2 changes: 2 additions & 0 deletions test/Test_VectorMath/Average.dat.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Frame V12avg
1 13.1965 -12.6155 3.4216 6.7847 0.1828 -13.8070
11 changes: 10 additions & 1 deletion test/Test_VectorMath/RunTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,5 +38,13 @@ EOF
RunCpptraj "$UNITNAME"
DoTest Magnitude.dat.save Magnitude.dat

UNITNAME='Vector average tests'
cat > corr.in <<EOF
readdata ../Test_Vector/vtest.dat.12.save as dat vector magnitude name V12
runanalysis vectormath vec1 V12 average out Average.dat name V12avg
EOF
RunCpptraj "$UNITNAME"
DoTest Average.dat.save Average.dat

EndTest
exit 0