Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the 'keep' action. Opposite of 'strip'; can also be used to only keep bridging waters from 'hbond' #957

Merged
merged 30 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8a62984
Start adding Keep action
drroe Mar 14, 2022
f3698fd
Start parsing bridge ID set
drroe Mar 14, 2022
90eb5bc
Start testing keep
drroe Mar 14, 2022
ae4c5ef
Add modified topology and frame
drroe Mar 14, 2022
aa25bea
Start modifying top and frame
drroe Mar 14, 2022
54548f1
Add topwriter
drroe Mar 15, 2022
dcb540e
Indices in bridge res ID data start from 1
drroe Mar 15, 2022
25275d7
Start keep tests
drroe Mar 15, 2022
2846384
Add test for bridge with keepmask
drroe Mar 15, 2022
3db8ee6
Allow keepmask to work on its own
drroe Mar 15, 2022
9580243
Make nobox option a part of ActionTopWriter
drroe Mar 15, 2022
c13f2ec
Add basic test for keep, use strip test save
drroe Mar 15, 2022
9652d59
Add nobox to other ActionTopWriter actions
drroe Mar 15, 2022
e43ca3c
Add residue status array. Check that bridging residue specified by data
drroe Mar 16, 2022
742d9ef
Start adding bridgeresonly; allow fine tuning of what atoms to keep when
drroe Mar 16, 2022
8d37be7
Ensure that only the requested number of bridges are retained (fewer or
drroe Mar 16, 2022
83cbcc2
Add test keeping only 1 bridging water
drroe Mar 16, 2022
7f39ca3
Actually set the status
drroe Mar 16, 2022
520eb98
Add keep two bridging waters at specified residues test
drroe Mar 16, 2022
64c0445
Reorganize vars to keep everything set in Init in one place
drroe Mar 16, 2022
8667edb
Fix up help
drroe Mar 16, 2022
05b498b
Test reading in hb bridge data
drroe Mar 16, 2022
52207ee
Add 'keep' entry. Fix actions table to indicate when actions modify
drroe Mar 16, 2022
205aa12
Hide some debug info. Improve warnings
drroe Mar 16, 2022
e4e8bf3
Add nobridgewarn option
drroe Mar 16, 2022
c861aae
Add nobridgewarn to manual
drroe Mar 16, 2022
c30ab9e
Enable keep test and protect in parallel. Add warning when run in
drroe Mar 16, 2022
b48ef6d
6.4.3. Revision bump for addition of keep action.
drroe Mar 16, 2022
75f1373
Merge branch 'master' into hbond.bridge.closest
drroe Mar 16, 2022
b37c7c3
Add code docs
drroe Mar 16, 2022
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
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