Skip to content

Commit

Permalink
Add the 'time' action (#722)
Browse files Browse the repository at this point in the history
* DRR - Cpptraj: Initial incarnation of the time action.

* DRR - Cpptraj: Enable time command

* DRR - Cpptraj: Add basic time addition test

* DRR - Cpptraj: Clean up error message. Return MODIFY_TOPOLOGY even though we are not really modifying the topology so that if 'time' is used with 'crdaction' the warning about COORDS data sets not storing time values is printed.

* DRR - Cpptraj: Add time to trajectory test

* DRR - Cpptraj: Modify time info test

* DRR - Cpptraj: Change 'notime' to 'remove' - just makes more sense.

* DRR - Cpptraj: Add test for removing time info

* DRR - Cpptraj: Add test to makefile

* DRR - Cpptraj: Revision bump for adding 'time' action

* DRR - Cpptraj: Update manual.

* DRR - Cpptraj: Want TrajoutNum(), not incoming frameNum.

* DRR - Cpptraj: Test that writes netcdf in parallel requires parallel netcdf
  • Loading branch information
drroe committed May 20, 2019
1 parent d90e41f commit 16f56d6
Show file tree
Hide file tree
Showing 13 changed files with 620 additions and 5 deletions.
Binary file modified doc/CpptrajManual.pdf
Binary file not shown.
83 changes: 81 additions & 2 deletions doc/cpptraj.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -14508,7 +14508,7 @@ Mod
\begin_layout Standard
\align center
\begin_inset Tabular
<lyxtabular version="3" rows="84" columns="3">
<lyxtabular version="3" rows="85" columns="3">
<features islongtable="true" longtabularalignment="center">
<column alignment="center" valignment="top" width="1.3in">
<column alignment="center" valignment="top" width="4.5in">
Expand Down Expand Up @@ -16724,6 +16724,35 @@ Calculate system temperature using velocities of specified atoms.
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
time
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Add/remove/modify time information in frames.
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
X
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
trans, translate
\end_layout
Expand Down Expand Up @@ -31756,7 +31785,57 @@ Calculate temperature in frame based on velocity information.
\series default
is specified just use frame temperature (read in from e.g.
REMD trajectory).

\end_layout

\begin_layout Subsection
time
\end_layout

\begin_layout LyX-Code
time {time0 <initial time> dt <step> [update] | remove}
\end_layout

\begin_deeper
\begin_layout Description
time0
\begin_inset space ~
\end_inset

<initial
\begin_inset space ~
\end_inset

time> Time of the first frame (ps).
\end_layout

\begin_layout Description
dt
\begin_inset space ~
\end_inset

<step> Time step between frames (ps).
\end_layout

\begin_layout Description
[update] If specified, modify any existing time info.
\end_layout

\begin_layout Description
remove Remove any time info from frame.
\end_layout

\end_deeper
\begin_layout Standard
Either add time information to frames, modify existing time information
in frames, or remove existing time information from frames.
Note that currently COORDS data sets do not store time information, so
using this command with the
\series bold
\emph on
crdaction
\series default
\emph default
command will have no effect.
\end_layout

\begin_layout Subsection
Expand Down
98 changes: 98 additions & 0 deletions src/Action_Time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "Action_Time.h"
#include "CpptrajStdio.h"

/// CONSTRUCTOR
Action_Time::Action_Time() :
time0_(0.0),
dt_(0.001),
mode_(ADD)
{}

// Action_Time::Help()
void Action_Time::Help() const {
mprintf("\t{time0 <initial time> dt <step> [update] | remove}\n"
" Add, modify, or remove time information from each frame.\n"
" time0 <initial time> : Time of the first frame (ps).\n"
" dt <step> : Time step between frames (ps).\n"
" update : If specified, modify any existing time info.\n"
" remove : Remove any time info from frame.\n");
}

// Action_Time::Init()
Action::RetType Action_Time::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
/// Make sure that something has been specified.
if (actionArgs.hasKey("remove"))
mode_ = REMOVE;
else {
if (!actionArgs.Contains("time0") &&
!actionArgs.Contains("dt"))
{
mprinterr("Error: Must specify either 'time0', 'dt', or both if 'remove' not specified.\n");
return Action::ERR;
}
time0_ = actionArgs.getKeyDouble("time0", 0.0);
dt_ = actionArgs.getKeyDouble("dt", 0.001);
if (actionArgs.hasKey("update"))
mode_ = MODIFY;
else
mode_ = ADD;
}

mprintf(" TIME:");
if (mode_ == REMOVE)
mprintf(" Removing all time information from frames.\n");
else {
if (mode_ == MODIFY)
mprintf(" Updating time information in frames.\n");
else
mprintf(" Adding/overwriting time information in frames.\n");
mprintf("\tInitial time = %g ps\n", time0_);
mprintf("\tTime step = %g ps\n", dt_);
}
return Action::OK;
}

// Action_Time::Setup()
Action::RetType Action_Time::Setup(ActionSetup& setup)
{
cInfo_ = setup.CoordInfo();
if (!cInfo_.HasTime()) {
if (mode_ == MODIFY)
mprintf("Warning: 'update' specified but no time info in frame. Adding time info.\n");
else if (mode_ == REMOVE) {
mprintf("Warning: 'remove' specified but no time info in frame. Skipping.\n");
return Action::SKIP;
} else if (mode_ == ADD)
mprintf("\tAdding time information to frames.\n");
} else {
if (mode_ == MODIFY)
mprintf("\tUpdating time information in frames.\n");
else if (mode_ == REMOVE)
mprintf("\tRemoving time information in frames.\n");
else if (mode_ == ADD)
mprintf("\tOverwriting time information in frames.\n");
}
if (mode_ == REMOVE)
cInfo_.SetTime( false );
else
cInfo_.SetTime( true );
setup.SetCoordInfo( &cInfo_ );
return Action::MODIFY_TOPOLOGY;
}

// Action_Time::DoAction()
Action::RetType Action_Time::DoAction(int frameNum, ActionFrame& frm)
{
double currTime = 0.0;
double newTime = 0.0;
switch (mode_) {
case REMOVE : frm.ModifyFrm().SetTime( currTime ); break;
case MODIFY : currTime = frm.Frm().Time();
case ADD :
newTime = currTime + time0_ + ((double)frm.TrajoutNum() * dt_);
frm.ModifyFrm().SetTime( newTime );
break;
}
return Action::MODIFY_COORDS;
}
22 changes: 22 additions & 0 deletions src/Action_Time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef INC_ACTION_TIME_H
#define INC_ACTION_TIME_H
#include "Action.h"
/// Add/remove/modify time information in frame.
class Action_Time : public Action {
public:
Action_Time();
DispatchObject* Alloc() const { return (DispatchObject*)new Action_Time(); }
void Help() const;
private:
Action::RetType Init(ArgList&, ActionInit&, int);
Action::RetType Setup(ActionSetup&);
Action::RetType DoAction(int, ActionFrame&);
void Print() {}

double time0_; ///< Initial time
double dt_; ///< Time step.
enum ModeType { ADD = 0, MODIFY, REMOVE };
ModeType mode_; ///< Modification mode.
CoordinateInfo cInfo_; ///< The modified CoordinateInfo
};
#endif
2 changes: 2 additions & 0 deletions src/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
#include "Action_LipidOrder.h"
#include "Action_InfraredSpectrum.h"
#include "Action_XtalSymm.h"
#include "Action_Time.h"
// ----- ANALYSIS --------------------------------------------------------------
#include "Analysis_Hist.h"
#include "Analysis_Corr.h"
Expand Down Expand Up @@ -348,6 +349,7 @@ void Command::Init() {
Command::AddCmd( new Action_Surf(), Cmd::ACT, 1, "surf" );
Command::AddCmd( new Action_SymmetricRmsd(), Cmd::ACT, 1, "symmrmsd" );
Command::AddCmd( new Action_Temperature(), Cmd::ACT, 1, "temperature" );
Command::AddCmd( new Action_Time(), Cmd::ACT, 1, "time" );
Command::AddCmd( new Action_Translate(), Cmd::ACT, 2, "trans", "translate" );
Command::AddCmd( new Action_Unstrip(), Cmd::ACT, 1, "unstrip" );
Command::AddCmd( new Action_Unwrap(), Cmd::ACT, 1, "unwrap" );
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 "V4.14.2"
#define CPPTRAJ_INTERNAL_VERSION "V4.14.3"
/// PYTRAJ relies on this
#define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION
#endif
Loading

0 comments on commit 16f56d6

Please sign in to comment.