Skip to content

Commit c993443

Browse files
authored
Add vectormath average keyword (#1155)
* Add vectormath average * Add vectormath average test * Add vectormath average entry and dataset aspects for vectormath. * Remove extra unneeded variable that was causing problems generating the manual pdf * Update manual pdf * 6.29.19. Revision bump for vectormath average.
1 parent 7e4081a commit c993443

File tree

8 files changed

+120
-47
lines changed

8 files changed

+120
-47
lines changed

doc/CpptrajManual.pdf

-120 Bytes
Binary file not shown.

doc/DocumentChecksums.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
b37726e7a841f6fc695ecd7fb040ffbf CpptrajDevelopmentGuide.lyx
2-
8fe330adac3e61d024fceb51b814a8ba cpptraj.lyx
2+
5af47ac2cb73a9c7cd83fc82c1d2f421 cpptraj.lyx
33
5d9b5b5ed47a3ded57b6464df99b3585 CpptrajManual.lyx

doc/cpptraj.lyx

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
\origin unavailable
77
\textclass article
88
\begin_preamble
9-
% Added by lyx2lyx
10-
%% Variable width box for table cells
11-
\newenvironment{cellvarwidth}[1][t]
12-
{\begin{varwidth}[#1]{\linewidth}}
13-
{\@finalstrut\@arstrutbox\end{varwidth}}
14-
% Added by lyx2lyx
159
\usepackage{varwidth}
1610
\end_preamble
1711
\use_default_options true
@@ -20918,36 +20912,11 @@ Calculate the dihedral angle using four points.
2091820912
\begin_inset Text
2091920913

2092020914
\begin_layout Plain Layout
20921-
\begin_inset ERT
20922-
status collapsed
20923-
20924-
\begin_layout Plain Layout
20925-
20926-
20927-
\backslash
20928-
begin{cellvarwidth}
20929-
\end_layout
20930-
20931-
\end_inset
20932-
20933-
dihrms
20915+
dihrms,
2093420916
\end_layout
2093520917

2093620918
\begin_layout Plain Layout
2093720919
dihedralrms
20938-
\begin_inset ERT
20939-
status collapsed
20940-
20941-
\begin_layout Plain Layout
20942-
20943-
20944-
\backslash
20945-
end{cellvarwidth}
20946-
\end_layout
20947-
20948-
\end_inset
20949-
20950-
2095120920
\end_layout
2095220921

2095320922
\end_inset
@@ -55231,7 +55200,8 @@ vectormath vec1 <vecname1> vec2 <vecname2> [out <filename>] [norm] [name
5523155200
\end_layout
5523255201

5523355202
\begin_layout LyX-Code
55234-
[ dotproduct | dotangle | crossproduct | magnitude ]
55203+
[ dotproduct | dotangle | crossproduct | magnitude | average
55204+
]
5523555205
\begin_inset Separator latexpar
5523655206
\end_inset
5523755207

@@ -55271,6 +55241,24 @@ vec2
5527155241
Name of file to write output to.
5527255242
\end_layout
5527355243

55244+
\begin_layout Description
55245+
[norm] Normalize the vectors; this will affect any subsequent calculations
55246+
with the vectors.
55247+
This is turned on automatically if
55248+
\series bold
55249+
dotangle/magnitude
55250+
\series default
55251+
specified.
55252+
\end_layout
55253+
55254+
\begin_layout Description
55255+
[name
55256+
\begin_inset space ~
55257+
\end_inset
55258+
55259+
<setname>] Output data set name.
55260+
\end_layout
55261+
5527455262
\begin_layout Description
5527555263
[dotproduct] (Default) Calculate the dot-product of the two vectors.
5527655264
\end_layout
@@ -55297,13 +55285,59 @@ vec2
5529755285
\end_layout
5529855286

5529955287
\begin_layout Description
55300-
[norm] Normalize the vectors; this will affect any subsequent calculations
55301-
with the vectors.
55302-
This is turned on automatically if
55288+
[average] Calculate the average (over frames) of vectors selected by
5530355289
\series bold
55304-
dotangle/magnitude
55290+
vec1
5530555291
\series default
55306-
specified.
55292+
(no need to specify
55293+
\series bold
55294+
vec2
55295+
\series default
55296+
).
55297+
\end_layout
55298+
55299+
\begin_layout Standard
55300+
DataSets created:
55301+
\end_layout
55302+
55303+
\begin_layout Description
55304+
<setname>[Dot] (double) Vector dot product (
55305+
\series bold
55306+
dotproduct
55307+
\series default
55308+
only).
55309+
\end_layout
55310+
55311+
\begin_layout Description
55312+
<setname>[Angle] (double) Angle in degrees from vector dot product (
55313+
\series bold
55314+
dotangle
55315+
\series default
55316+
only).
55317+
\end_layout
55318+
55319+
\begin_layout Description
55320+
<setname>[Cross] (vector) Cross product (
55321+
\series bold
55322+
crossproduct
55323+
\series default
55324+
only).
55325+
\end_layout
55326+
55327+
\begin_layout Description
55328+
<setname>[Mag] (double) Magnitude (
55329+
\series bold
55330+
magnitude
55331+
\series default
55332+
only).
55333+
\end_layout
55334+
55335+
\begin_layout Description
55336+
<setname>[Avg] (vector) Average vector (
55337+
\series bold
55338+
average
55339+
\series default
55340+
only).
5530755341
\end_layout
5530855342

5530955343
\end_deeper

src/Analysis_VectorMath.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/// Strings corresponding to modes, used in output.
1010
const char* Analysis_VectorMath::ModeString[] = {
11-
"Dot product", "Angle from dot product", "Cross product", "Magnitude" };
11+
"Dot product", "Angle from dot product", "Cross product", "Magnitude", "Average" };
1212

1313
// CONSTRUCTOR
1414
Analysis_VectorMath::Analysis_VectorMath() :
@@ -18,12 +18,12 @@ Analysis_VectorMath::Analysis_VectorMath() :
1818

1919
void Analysis_VectorMath::Help() const {
2020
mprintf("\tvec1 <vecname1> vec2 <vecname2> [out <filename>] [norm] [name <setname>]\n"
21-
"\t[ dotproduct | dotangle | crossproduct | magnitude ]\n"
21+
"\t[ dotproduct | dotangle | crossproduct | magnitude | average ]\n"
2222
" Calculate dot product, angle from dot product (degrees), or cross product\n"
2323
" for specified vectors. Either vec1 or vec2 can be size 1, otherwise they\n"
24-
" must both be the same size. If 'magnitude' is specified, just calculate\n"
25-
" the magnitudes of the vectors selected by 'vec1' (no need to specify\n"
26-
" 'vec2').\n");
24+
" must both be the same size.\n"
25+
" If 'magnitude' or 'average' is specified, just calculate the magnitudes\n"
26+
" or averages of the vector selected by 'vec1' (no need to specify 'vec2').\n");
2727
}
2828

2929
// Analysis_VectorMath::Setup()
@@ -54,6 +54,11 @@ Analysis::RetType Analysis_VectorMath::Setup(ArgList& analyzeArgs, AnalysisSetup
5454
mprintf("Warning: 'norm' does not make sense with 'magnitude', ignoring.\n");
5555
norm_ = false;
5656
}
57+
} else if (analyzeArgs.hasKey("average")) {
58+
mode_ = AVERAGE;
59+
dtype = DataSet::VECTOR;
60+
dname = "Avg";
61+
requires_two_vecs = false;
5762
}
5863

5964
// Get Vectors
@@ -145,6 +150,26 @@ const
145150
return 0;
146151
}
147152

153+
/** Calculate the average vector. */
154+
int Analysis_VectorMath::Average(DataSet* Dout, DataSet_Vector const& V1)
155+
const
156+
{
157+
DataSet_Vector& Out = static_cast<DataSet_Vector&>( *Dout );
158+
Vec3 VXYZ(0.0, 0.0, 0.0);
159+
for (unsigned int idx = 0; idx < V1.Size(); idx++)
160+
VXYZ += V1[idx];
161+
VXYZ /= (double)V1.Size();
162+
if (V1.HasOrigins()) {
163+
Vec3 OXYZ(0.0, 0.0, 0.0);
164+
for (unsigned int idx = 0; idx < V1.Size(); idx++)
165+
OXYZ += V1.OXYZ(idx);
166+
OXYZ /= (double)V1.Size();
167+
Out.AddVxyzo( VXYZ, OXYZ );
168+
} else
169+
Out.AddVxyz( VXYZ );
170+
return 0;
171+
}
172+
148173
// Analysis_VectorMath::DotProduct()
149174
int Analysis_VectorMath::DotProduct(DataSet* Dout, DataSet_Vector& V1, DataSet_Vector& V2,
150175
unsigned int vmax, unsigned int v1inc, unsigned int v2inc)
@@ -235,6 +260,8 @@ Analysis::RetType Analysis_VectorMath::Analyze() {
235260
int err = 1;
236261
if (mode_ == MAGNITUDE)
237262
err = Magnitude( DataOut_[ii], *(vinfo1_[ii]) );
263+
else if (mode_ == AVERAGE)
264+
err = Average( DataOut_[ii], *(vinfo1_[ii]) );
238265
if (err != 0) {
239266
mprinterr("Error: A problem occurred when performing vector math for set '%s'\n",
240267
vinfo1_[ii]->legend());

src/Analysis_VectorMath.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ class Analysis_VectorMath : public Analysis {
1111
Analysis::RetType Setup(ArgList&, AnalysisSetup&, int);
1212
Analysis::RetType Analyze();
1313
private:
14-
enum ModeType { DOTPRODUCT = 0, DOTANGLE, CROSSPRODUCT, MAGNITUDE };
14+
enum ModeType { DOTPRODUCT = 0, DOTANGLE, CROSSPRODUCT, MAGNITUDE, AVERAGE };
1515
static const char* ModeString[];
1616

1717
int Magnitude(DataSet*, DataSet_Vector const&) const;
18+
int Average(DataSet*, DataSet_Vector const&) const;
1819
int DotProduct(DataSet*, DataSet_Vector&, DataSet_Vector&,
1920
unsigned int, unsigned int, unsigned int) const;
2021
int CrossProduct(DataSet*, DataSet_Vector&, DataSet_Vector&,

src/Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Whenever a number that precedes <revision> is incremented, all subsequent
1313
* numbers should be reset to 0.
1414
*/
15-
#define CPPTRAJ_INTERNAL_VERSION "V6.29.18"
15+
#define CPPTRAJ_INTERNAL_VERSION "V6.29.19"
1616
/// PYTRAJ relies on this
1717
#define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION
1818
#endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Frame V12avg
2+
1 13.1965 -12.6155 3.4216 6.7847 0.1828 -13.8070

test/Test_VectorMath/RunTest.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
. ../MasterTest.sh
44

5-
CleanFiles vectors.dat dotproduct.dat corr.in v1init_dot_v1.dat Magnitude.dat
5+
CleanFiles vectors.dat dotproduct.dat corr.in v1init_dot_v1.dat Magnitude.dat \
6+
Average.dat
67

78
INPUT="corr.in"
89
TOP=../tz2.parm7
@@ -37,5 +38,13 @@ EOF
3738
RunCpptraj "$UNITNAME"
3839
DoTest Magnitude.dat.save Magnitude.dat
3940

41+
UNITNAME='Vector average tests'
42+
cat > corr.in <<EOF
43+
readdata ../Test_Vector/vtest.dat.12.save as dat vector magnitude name V12
44+
runanalysis vectormath vec1 V12 average out Average.dat name V12avg
45+
EOF
46+
RunCpptraj "$UNITNAME"
47+
DoTest Average.dat.save Average.dat
48+
4049
EndTest
4150
exit 0

0 commit comments

Comments
 (0)