-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
13 changed files
with
620 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.