Skip to content

Commit

Permalink
Add the 'keep' action. Opposite of 'strip'; can also be used to only …
Browse files Browse the repository at this point in the history
…keep bridging waters from 'hbond' (#957)

* Start adding Keep action

* Start parsing bridge ID set

* Start testing keep

* Add modified topology and frame

* Start modifying top and frame

* Add topwriter

* Indices in bridge res ID data start from 1

* Start keep tests

* Add test for bridge with keepmask

* Allow keepmask to work on its own

* Make nobox option a part of ActionTopWriter

* Add basic test for keep, use strip test save

* Add nobox to other ActionTopWriter actions

* Add residue status array. Check that bridging residue specified by data
set was also specified as a bridge residue for command.

* Start adding bridgeresonly; allow fine tuning of what atoms to keep when
keeping bridging waters

* Ensure that only the requested number of bridges are retained (fewer or
more will invalidate the topology)

* Add test keeping only 1 bridging water

* Actually set the status

* Add keep two bridging waters at specified residues test

* Reorganize vars to keep everything set in Init in one place

* Fix up help

* Test reading in hb bridge data

* Add 'keep' entry. Fix actions table to indicate when actions modify
state (like strip).

* Hide some debug info. Improve warnings

* Add nobridgewarn option

* Add nobridgewarn to manual

* Enable keep test and protect in parallel. Add warning when run in
parallel with bridgedata

* 6.4.3. Revision bump for addition of keep action.

* Add code docs
  • Loading branch information
drroe authored Mar 16, 2022
1 parent 1222245 commit ebce523
Show file tree
Hide file tree
Showing 23 changed files with 1,747 additions and 40 deletions.
336 changes: 324 additions & 12 deletions doc/cpptraj.lyx

Large diffs are not rendered by default.

51 changes: 44 additions & 7 deletions src/ActionTopWriter.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
#include "ActionTopWriter.h"
#include "ActionState.h"
#include "ArgList.h"
#include "CoordinateInfo.h"
#include "CpptrajStdio.h"
#include "Topology.h"
#include "ParmFile.h"

static const char* keywords_ = "\t[outprefix <prefix>] [parmout <filename>]\n"
"\t[parmopts <comma-separated-list>]\n";
static const char* options_ =
" outprefix <prefix> : Write modified topology to <prefix>.<originalname>\n"
" parmout <filename> : Write modified topology to <filename>\n"
" parmopts <list> : Options for writing topology file\n";
const char* ActionTopWriter::keywords_ =
"\t[outprefix <prefix>] [nobox] [parmout <filename>]\n"
"\t[parmopts <comma-separated-list>]\n";
const char* ActionTopWriter::options_ =
" outprefix <prefix> : Write modified topology to <prefix>.<originalname>\n"
" nobox : If specified, remove box information from topology\n"
" parmout <filename> : Write modified topology to <filename>\n"
" parmopts <list> : Options for writing topology file\n";

const char* ActionTopWriter::Keywords() { return keywords_; }
const char* ActionTopWriter::Options() { return options_; }

/** CONSTRUCTOR */
ActionTopWriter::ActionTopWriter() :
debug_(0)
debug_(0),
removeBoxInfo_(false),
newCinfo_(0)
{}

/** DESTRUCTOR */
ActionTopWriter::~ActionTopWriter() {
if (newCinfo_ != 0) delete newCinfo_;
}

/** Parse arguments. */
int ActionTopWriter::InitTopWriter(ArgList& argIn, const char* typeStrIn, int debugIn) {
debug_ = debugIn;
removeBoxInfo_ = argIn.hasKey("nobox");
prefix_ = argIn.GetStringKey("outprefix");
parmoutName_ = argIn.GetStringKey("parmout");
parmOpts_ = argIn.GetStringKey("parmopts");
Expand All @@ -35,6 +47,8 @@ int ActionTopWriter::InitTopWriter(ArgList& argIn, const char* typeStrIn, int de

/** Print arguments to stdout. */
void ActionTopWriter::PrintOptions() const {
if (removeBoxInfo_)
mprintf("\tAny existing box information will be removed.\n");
if (!prefix_.empty())
mprintf("\tWriting '%s' topology file with prefix '%s'\n", typeStr_.c_str(), prefix_.c_str());
if (!parmoutName_.empty())
Expand Down Expand Up @@ -72,3 +86,26 @@ int ActionTopWriter::WriteTops(Topology const& topIn) const {
}
return err;
}

/** Modify given ActionSetup. */
int ActionTopWriter::ModifyActionState(ActionSetup& setup, Topology* topIn)
{
// Remove box information if asked
if (removeBoxInfo_) {
topIn->SetParmBox( Box() );
newCinfo_ = new CoordinateInfo( setup.CoordInfo() );
newCinfo_->SetBox( Box() );
setup.SetCoordInfo( newCinfo_ );
}
return 0;
}

/** Modify given Topology only. */
int ActionTopWriter::ModifyTop(Topology* topIn)
{
// Remove box information if asked
if (removeBoxInfo_) {
topIn->SetParmBox( Box() );
}
return 0;
}
12 changes: 12 additions & 0 deletions src/ActionTopWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#define INC_ACTIONTOPWRITER_H
#include <string>
// Forward declares
class ActionSetup;
class ArgList;
class CoordinateInfo;
class Topology;
/// Class to hold common functionality for actions that will write modified topologies.
class ActionTopWriter {
public:
ActionTopWriter();
~ActionTopWriter();

static const char* Keywords();
static const char* Options();
Expand All @@ -18,11 +21,20 @@ class ActionTopWriter {
void PrintOptions() const;
/// Write the Topology to file(s)
int WriteTops(Topology const&) const;
/// Remove box information from Topology/CoordinateInfo
int ModifyActionState(ActionSetup&, Topology*);
/// Remove box information from Topology
int ModifyTop(Topology*);
private:
std::string prefix_; ///< Prefix for writing topology as <prefix>.<originalname>
std::string parmoutName_; ///< Output topology file name
std::string parmOpts_; ///< Topology file write args
std::string typeStr_; ///< Label for kind of topology being written.
int debug_; ///< Debug level to pass to Topology file writer.
bool removeBoxInfo_; ///< If true, remove box information from Topology/CoordinateInfo
CoordinateInfo* newCinfo_; ///< Hold any modified CoordinateInfo

static const char* keywords_;
static const char* options_;
};
#endif
3 changes: 3 additions & 0 deletions src/Action_Closest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ Action::RetType Action_Closest::Setup(ActionSetup& setup) {
return Action::ERR;
}
setup.SetTopology( newParm_ );
// Remove box information if asked
if (topWriter_.ModifyActionState(setup, newParm_))
return Action::ERR;
newParm_->Brief("Closest topology:");
// Allocate space for new frame
newFrame_.SetupFrameV( setup.Top().Atoms(), setup.CoordInfo() );
Expand Down
5 changes: 4 additions & 1 deletion src/Action_FixAtomOrder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ Action::RetType Action_FixAtomOrder::Setup(ActionSetup& setup) {
mprinterr("Error: Could not create re-ordered topology.\n");
return Action::ERR;
}
newParm_->Brief("Re-ordered parm:");
setup.SetTopology( newParm_ );
// Remove box information if asked
if (topWriter_.ModifyActionState(setup, newParm_))
return Action::ERR;
newParm_->Brief("Re-ordered parm:");
// Allocate space for new frame
newFrame_.SetupFrameV( setup.Top().Atoms(), setup.CoordInfo() );

Expand Down
Loading

0 comments on commit ebce523

Please sign in to comment.