*/
class IndexFileWriterModule : public AnalysisDataModuleSerial
{
- public:
- IndexFileWriterModule();
- ~IndexFileWriterModule() override;
-
- //! Sets the file name to write the index file to.
- void setFileName(const std::string &fnm);
- /*! \brief
- * Adds information about a group to be printed.
- *
- * Must be called for each group present in the input data.
- */
- void addGroup(const std::string &name, bool bDynamic);
-
- int flags() const override;
-
- void dataStarted(AbstractAnalysisData *data) override;
- void frameStarted(const AnalysisDataFrameHeader &header) override;
- void pointsAdded(const AnalysisDataPointSetRef &points) override;
- void frameFinished(const AnalysisDataFrameHeader &header) override;
- void dataFinished() override;
-
- private:
- void closeFile();
-
- struct GroupInfo
- {
- GroupInfo(const std::string &name, bool bDynamic)
- : name(name), bDynamic(bDynamic)
- { }
-
- std::string name;
- bool bDynamic;
- };
-
- std::string fnm_;
- std::vector<GroupInfo> groups_;
- FILE *fp_;
- int currentGroup_;
- int currentSize_;
- bool bAnyWritten_;
+public:
+ IndexFileWriterModule();
+ ~IndexFileWriterModule() override;
+
+ //! Sets the file name to write the index file to.
+ void setFileName(const std::string& fnm);
+ /*! \brief
+ * Adds information about a group to be printed.
+ *
+ * Must be called for each group present in the input data.
+ */
+ void addGroup(const std::string& name, bool bDynamic);
+
+ int flags() const override;
+
+ void dataStarted(AbstractAnalysisData* data) override;
+ void frameStarted(const AnalysisDataFrameHeader& header) override;
+ void pointsAdded(const AnalysisDataPointSetRef& points) override;
+ void frameFinished(const AnalysisDataFrameHeader& header) override;
+ void dataFinished() override;
+
+private:
+ void closeFile();
+
+ struct GroupInfo
+ {
+ GroupInfo(const std::string& name, bool bDynamic) : name(name), bDynamic(bDynamic) {}
+
+ std::string name;
+ bool bDynamic;
+ };
+
+ std::string fnm_;
+ std::vector<GroupInfo> groups_;
+ FILE* fp_;
+ int currentGroup_;
+ int currentSize_;
+ bool bAnyWritten_;
};
/********************************************************************
* IndexFileWriterModule
*/
-IndexFileWriterModule::IndexFileWriterModule()
- : fp_(nullptr), currentGroup_(-1), currentSize_(0), bAnyWritten_(false)
+IndexFileWriterModule::IndexFileWriterModule() :
+ fp_(nullptr),
+ currentGroup_(-1),
+ currentSize_(0),
+ bAnyWritten_(false)
{
}
}
-void IndexFileWriterModule::setFileName(const std::string &fnm)
+void IndexFileWriterModule::setFileName(const std::string& fnm)
{
fnm_ = fnm;
}
-void IndexFileWriterModule::addGroup(const std::string &name, bool bDynamic)
+void IndexFileWriterModule::addGroup(const std::string& name, bool bDynamic)
{
std::string newName(name);
std::replace(newName.begin(), newName.end(), ' ', '_');
}
-void IndexFileWriterModule::dataStarted(AbstractAnalysisData * /*data*/)
+void IndexFileWriterModule::dataStarted(AbstractAnalysisData* /*data*/)
{
if (!fnm_.empty())
{
}
-void IndexFileWriterModule::frameStarted(const AnalysisDataFrameHeader & /*header*/)
+void IndexFileWriterModule::frameStarted(const AnalysisDataFrameHeader& /*header*/)
{
bAnyWritten_ = false;
currentGroup_ = -1;
}
-void
-IndexFileWriterModule::pointsAdded(const AnalysisDataPointSetRef &points)
+void IndexFileWriterModule::pointsAdded(const AnalysisDataPointSetRef& points)
{
if (fp_ == nullptr)
{
if (points.firstColumn() == 0)
{
++currentGroup_;
- GMX_RELEASE_ASSERT(currentGroup_ < ssize(groups_),
- "Too few groups initialized");
+ GMX_RELEASE_ASSERT(currentGroup_ < ssize(groups_), "Too few groups initialized");
if (bFirstFrame || groups_[currentGroup_].bDynamic)
{
if (!bFirstFrame || currentGroup_ > 0)
}
-void IndexFileWriterModule::frameFinished(const AnalysisDataFrameHeader & /*header*/)
-{
-}
+void IndexFileWriterModule::frameFinished(const AnalysisDataFrameHeader& /*header*/) {}
void IndexFileWriterModule::dataFinished()
PdbAtomsSelection_Selected
};
//! String values corresponding to ResidueNumbering.
-const char *const cResNumberEnum[] = { "number", "index" };
+const char* const cResNumberEnum[] = { "number", "index" };
//! String values corresponding to PdbAtomsSelection.
-const char *const cPDBAtomsEnum[] = { "all", "maxsel", "selected" };
+const char* const cPDBAtomsEnum[] = { "all", "maxsel", "selected" };
class Select : public TrajectoryAnalysisModule
{
- public:
- Select();
-
- void initOptions(IOptionsContainer *options,
- TrajectoryAnalysisSettings *settings) override;
- void optionsFinished(TrajectoryAnalysisSettings *settings) override;
- void initAnalysis(const TrajectoryAnalysisSettings &settings,
- const TopologyInformation &top) override;
-
- void analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
- TrajectoryAnalysisModuleData *pdata) override;
-
- void finishAnalysis(int nframes) override;
- void writeOutput() override;
-
- private:
- SelectionList sel_;
-
- std::string fnSize_;
- std::string fnFrac_;
- std::string fnIndex_;
- std::string fnNdx_;
- std::string fnMask_;
- std::string fnOccupancy_;
- std::string fnPDB_;
- std::string fnLifetime_;
- bool bTotNorm_;
- bool bFracNorm_;
- bool bResInd_;
- bool bCumulativeLifetimes_;
- ResidueNumbering resNumberType_;
- PdbAtomsSelection pdbAtoms_;
-
- //! The input topology.
- const TopologyInformation *top_;
- std::vector<int> totsize_;
- AnalysisData sdata_;
- AnalysisData cdata_;
- AnalysisData idata_;
- AnalysisData mdata_;
- AnalysisDataAverageModulePointer occupancyModule_;
- AnalysisDataLifetimeModulePointer lifetimeModule_;
+public:
+ Select();
+
+ void initOptions(IOptionsContainer* options, TrajectoryAnalysisSettings* settings) override;
+ void optionsFinished(TrajectoryAnalysisSettings* settings) override;
+ void initAnalysis(const TrajectoryAnalysisSettings& settings, const TopologyInformation& top) override;
+
+ void analyzeFrame(int frnr, const t_trxframe& fr, t_pbc* pbc, TrajectoryAnalysisModuleData* pdata) override;
+
+ void finishAnalysis(int nframes) override;
+ void writeOutput() override;
+
+private:
+ SelectionList sel_;
+
+ std::string fnSize_;
+ std::string fnFrac_;
+ std::string fnIndex_;
+ std::string fnNdx_;
+ std::string fnMask_;
+ std::string fnOccupancy_;
+ std::string fnPDB_;
+ std::string fnLifetime_;
+ bool bTotNorm_;
+ bool bFracNorm_;
+ bool bResInd_;
+ bool bCumulativeLifetimes_;
+ ResidueNumbering resNumberType_;
+ PdbAtomsSelection pdbAtoms_;
+
+ //! The input topology.
+ const TopologyInformation* top_;
+ std::vector<int> totsize_;
+ AnalysisData sdata_;
+ AnalysisData cdata_;
+ AnalysisData idata_;
+ AnalysisData mdata_;
+ AnalysisDataAverageModulePointer occupancyModule_;
+ AnalysisDataLifetimeModulePointer lifetimeModule_;
};
-Select::Select()
- : bTotNorm_(false), bFracNorm_(false), bResInd_(false),
- bCumulativeLifetimes_(true), resNumberType_(ResidueNumbering_ByNumber),
- pdbAtoms_(PdbAtomsSelection_All), top_(nullptr),
- occupancyModule_(new AnalysisDataAverageModule()),
- lifetimeModule_(new AnalysisDataLifetimeModule())
+Select::Select() :
+ bTotNorm_(false),
+ bFracNorm_(false),
+ bResInd_(false),
+ bCumulativeLifetimes_(true),
+ resNumberType_(ResidueNumbering_ByNumber),
+ pdbAtoms_(PdbAtomsSelection_All),
+ top_(nullptr),
+ occupancyModule_(new AnalysisDataAverageModule()),
+ lifetimeModule_(new AnalysisDataLifetimeModule())
{
mdata_.addModule(occupancyModule_);
mdata_.addModule(lifetimeModule_);
}
-void
-Select::initOptions(IOptionsContainer *options, TrajectoryAnalysisSettings *settings)
+void Select::initOptions(IOptionsContainer* options, TrajectoryAnalysisSettings* settings)
{
- static const char *const desc[] = {
+ static const char* const desc[] = {
"[THISMODULE] writes out basic data about dynamic selections.",
"It can be used for some simple analyses, or the output can",
"be combined with output from other programs and/or external",
settings->setHelpText(desc);
- options->addOption(FileNameOption("os").filetype(eftPlot).outputFile()
- .store(&fnSize_).defaultBasename("size")
- .description("Number of positions in each selection"));
- options->addOption(FileNameOption("oc").filetype(eftPlot).outputFile()
- .store(&fnFrac_).defaultBasename("cfrac")
- .description("Covered fraction for each selection"));
- options->addOption(FileNameOption("oi").filetype(eftGenericData).outputFile()
- .store(&fnIndex_).defaultBasename("index")
- .description("Indices selected by each selection"));
- options->addOption(FileNameOption("on").filetype(eftIndex).outputFile()
- .store(&fnNdx_).defaultBasename("index")
- .description("Index file from the selection"));
- options->addOption(FileNameOption("om").filetype(eftPlot).outputFile()
- .store(&fnMask_).defaultBasename("mask")
- .description("Mask for selected positions"));
- options->addOption(FileNameOption("of").filetype(eftPlot).outputFile()
- .store(&fnOccupancy_).defaultBasename("occupancy")
- .description("Occupied fraction for selected positions"));
- options->addOption(FileNameOption("ofpdb").filetype(eftPDB).outputFile()
- .store(&fnPDB_).defaultBasename("occupancy")
- .description("PDB file with occupied fraction for selected positions"));
- options->addOption(FileNameOption("olt").filetype(eftPlot).outputFile()
- .store(&fnLifetime_).defaultBasename("lifetime")
- .description("Lifetime histogram"));
-
- options->addOption(SelectionOption("select").storeVector(&sel_)
- .required().multiValue()
- .description("Selections to analyze"));
-
- options->addOption(BooleanOption("norm").store(&bTotNorm_)
- .description("Normalize by total number of positions with -os"));
- options->addOption(BooleanOption("cfnorm").store(&bFracNorm_)
- .description("Normalize by covered fraction with -os"));
- options->addOption(EnumOption<ResidueNumbering>("resnr").store(&resNumberType_)
- .enumValue(cResNumberEnum)
- .description("Residue number output type with -oi and -on"));
- options->addOption(EnumOption<PdbAtomsSelection>("pdbatoms").store(&pdbAtoms_)
- .enumValue(cPDBAtomsEnum)
- .description("Atoms to write with -ofpdb"));
- options->addOption(BooleanOption("cumlt").store(&bCumulativeLifetimes_)
- .description("Cumulate subintervals of longer intervals in -olt"));
+ options->addOption(FileNameOption("os")
+ .filetype(eftPlot)
+ .outputFile()
+ .store(&fnSize_)
+ .defaultBasename("size")
+ .description("Number of positions in each selection"));
+ options->addOption(FileNameOption("oc")
+ .filetype(eftPlot)
+ .outputFile()
+ .store(&fnFrac_)
+ .defaultBasename("cfrac")
+ .description("Covered fraction for each selection"));
+ options->addOption(FileNameOption("oi")
+ .filetype(eftGenericData)
+ .outputFile()
+ .store(&fnIndex_)
+ .defaultBasename("index")
+ .description("Indices selected by each selection"));
+ options->addOption(FileNameOption("on")
+ .filetype(eftIndex)
+ .outputFile()
+ .store(&fnNdx_)
+ .defaultBasename("index")
+ .description("Index file from the selection"));
+ options->addOption(FileNameOption("om")
+ .filetype(eftPlot)
+ .outputFile()
+ .store(&fnMask_)
+ .defaultBasename("mask")
+ .description("Mask for selected positions"));
+ options->addOption(FileNameOption("of")
+ .filetype(eftPlot)
+ .outputFile()
+ .store(&fnOccupancy_)
+ .defaultBasename("occupancy")
+ .description("Occupied fraction for selected positions"));
+ options->addOption(
+ FileNameOption("ofpdb")
+ .filetype(eftPDB)
+ .outputFile()
+ .store(&fnPDB_)
+ .defaultBasename("occupancy")
+ .description("PDB file with occupied fraction for selected positions"));
+ options->addOption(FileNameOption("olt")
+ .filetype(eftPlot)
+ .outputFile()
+ .store(&fnLifetime_)
+ .defaultBasename("lifetime")
+ .description("Lifetime histogram"));
+
+ options->addOption(SelectionOption("select").storeVector(&sel_).required().multiValue().description(
+ "Selections to analyze"));
+
+ options->addOption(
+ BooleanOption("norm").store(&bTotNorm_).description("Normalize by total number of positions with -os"));
+ options->addOption(
+ BooleanOption("cfnorm").store(&bFracNorm_).description("Normalize by covered fraction with -os"));
+ options->addOption(EnumOption<ResidueNumbering>("resnr")
+ .store(&resNumberType_)
+ .enumValue(cResNumberEnum)
+ .description("Residue number output type with -oi and -on"));
+ options->addOption(EnumOption<PdbAtomsSelection>("pdbatoms")
+ .store(&pdbAtoms_)
+ .enumValue(cPDBAtomsEnum)
+ .description("Atoms to write with -ofpdb"));
+ options->addOption(BooleanOption("cumlt")
+ .store(&bCumulativeLifetimes_)
+ .description("Cumulate subintervals of longer intervals in -olt"));
}
-void
-Select::optionsFinished(TrajectoryAnalysisSettings *settings)
+void Select::optionsFinished(TrajectoryAnalysisSettings* settings)
{
if (!fnPDB_.empty())
{
}
}
-void
-Select::initAnalysis(const TrajectoryAnalysisSettings &settings,
- const TopologyInformation &top)
+void Select::initAnalysis(const TrajectoryAnalysisSettings& settings, const TopologyInformation& top)
{
bResInd_ = (resNumberType_ == ResidueNumbering_ByIndex);
}
if (!fnSize_.empty())
{
- AnalysisDataPlotModulePointer plot(
- new AnalysisDataPlotModule(settings.plotSettings()));
+ AnalysisDataPlotModulePointer plot(new AnalysisDataPlotModule(settings.plotSettings()));
plot->setFileName(fnSize_);
plot->setTitle("Selection size");
plot->setXAxisIsTime();
cdata_.setColumnCount(0, sel_.size());
if (!fnFrac_.empty())
{
- AnalysisDataPlotModulePointer plot(
- new AnalysisDataPlotModule(settings.plotSettings()));
+ AnalysisDataPlotModulePointer plot(new AnalysisDataPlotModule(settings.plotSettings()));
plot->setFileName(fnFrac_);
plot->setTitle("Covered fraction");
plot->setXAxisIsTime();
// TODO: For large systems, a float may not have enough precision
if (!fnIndex_.empty())
{
- AnalysisDataPlotModulePointer plot(
- new AnalysisDataPlotModule(settings.plotSettings()));
+ AnalysisDataPlotModulePointer plot(new AnalysisDataPlotModule(settings.plotSettings()));
plot->setFileName(fnIndex_);
plot->setPlainOutput(true);
plot->setYFormat(4, 0);
lifetimeModule_->setCumulative(bCumulativeLifetimes_);
if (!fnMask_.empty())
{
- AnalysisDataPlotModulePointer plot(
- new AnalysisDataPlotModule(settings.plotSettings()));
+ AnalysisDataPlotModulePointer plot(new AnalysisDataPlotModule(settings.plotSettings()));
plot->setFileName(fnMask_);
plot->setTitle("Selection mask");
plot->setXAxisIsTime();
}
if (!fnOccupancy_.empty())
{
- AnalysisDataPlotModulePointer plot(
- new AnalysisDataPlotModule(settings.plotSettings()));
+ AnalysisDataPlotModulePointer plot(new AnalysisDataPlotModule(settings.plotSettings()));
plot->setFileName(fnOccupancy_);
plot->setTitle("Fraction of time selection matches");
plot->setXLabel("Selected position");
}
if (!fnLifetime_.empty())
{
- AnalysisDataPlotModulePointer plot(
- new AnalysisDataPlotModule(settings.plotSettings()));
+ AnalysisDataPlotModulePointer plot(new AnalysisDataPlotModule(settings.plotSettings()));
plot->setFileName(fnLifetime_);
plot->setTitle("Lifetime histogram");
plot->setXAxisIsTime();
}
-void
-Select::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc * /* pbc */,
- TrajectoryAnalysisModuleData *pdata)
+void Select::analyzeFrame(int frnr, const t_trxframe& fr, t_pbc* /* pbc */, TrajectoryAnalysisModuleData* pdata)
{
AnalysisDataHandle sdh = pdata->dataHandle(sdata_);
AnalysisDataHandle cdh = pdata->dataHandle(cdata_);
AnalysisDataHandle idh = pdata->dataHandle(idata_);
AnalysisDataHandle mdh = pdata->dataHandle(mdata_);
- const SelectionList &sel = pdata->parallelSelections(sel_);
+ const SelectionList& sel = pdata->parallelSelections(sel_);
sdh.startFrame(frnr, fr.time);
for (size_t g = 0; g < sel.size(); ++g)
idh.finishPointSet();
for (int i = 0; i < sel[g].posCount(); ++i)
{
- const SelectionPosition &p = sel[g].position(i);
+ const SelectionPosition& p = sel[g].position(i);
if (sel[g].type() == INDEX_RES && !bResInd_)
{
idh.setPoint(1, top_->atoms()->resinfo[p.mappedId()].nr);
}
-void
-Select::finishAnalysis(int /*nframes*/)
-{
-}
+void Select::finishAnalysis(int /*nframes*/) {}
-void
-Select::writeOutput()
+void Select::writeOutput()
{
if (!fnPDB_.empty())
{
{
for (int i = 0; i < sel_[g].posCount(); ++i)
{
- ArrayRef<const int> atomIndices
- = sel_[g].position(i).atomIndices();
+ ArrayRef<const int> atomIndices = sel_[g].position(i).atomIndices();
ArrayRef<const int>::const_iterator ai;
for (ai = atomIndices.begin(); ai != atomIndices.end(); ++ai)
{
{
case PdbAtomsSelection_All:
{
- t_trxstatus *status = open_trx(fnPDB_.c_str(), "w");
+ t_trxstatus* status = open_trx(fnPDB_.c_str(), "w");
write_trxframe(status, &fr, nullptr);
close_trx(status);
break;
ArrayRef<const int> atomIndices = sel_[g].atomIndices();
atomIndicesSet.insert(atomIndices.begin(), atomIndices.end());
}
- std::vector<int> allAtomIndices(atomIndicesSet.begin(),
- atomIndicesSet.end());
- t_trxstatus *status = open_trx(fnPDB_.c_str(), "w");
- write_trxframe_indexed(status, &fr, allAtomIndices.size(),
- allAtomIndices.data(), nullptr);
+ std::vector<int> allAtomIndices(atomIndicesSet.begin(), atomIndicesSet.end());
+ t_trxstatus* status = open_trx(fnPDB_.c_str(), "w");
+ write_trxframe_indexed(status, &fr, allAtomIndices.size(), allAtomIndices.data(), nullptr);
close_trx(status);
break;
}
indices.push_back(i);
}
}
- t_trxstatus *status = open_trx(fnPDB_.c_str(), "w");
+ t_trxstatus* status = open_trx(fnPDB_.c_str(), "w");
write_trxframe_indexed(status, &fr, indices.size(), indices.data(), nullptr);
close_trx(status);
break;
}
}
-} // namespace
+} // namespace
const char SelectInfo::name[] = "select";
-const char SelectInfo::shortDescription[] =
- "Print general information about selections";
+const char SelectInfo::shortDescription[] = "Print general information about selections";
TrajectoryAnalysisModulePointer SelectInfo::create()
{