void TrajectoryAnalysisRunnerCommon::Impl::initTopology(bool required) { // Return immediately if the topology has already been loaded. if (topInfo_.hasTopology()) { return; } if (required && topfile_.empty()) { GMX_THROW(InconsistentInputError("No topology provided, but one is required for analysis")); } // Load the topology if requested. if (!topfile_.empty()) { snew(topInfo_.top_, 1); topInfo_.bTop_ = read_tps_conf(topfile_.c_str(), topInfo_.top_, &topInfo_.ePBC_, &topInfo_.xtop_, NULL, topInfo_.boxtop_, TRUE); if (hasTrajectory() && !settings_.hasFlag(TrajectoryAnalysisSettings::efUseTopX)) { sfree(topInfo_.xtop_); topInfo_.xtop_ = NULL; } } }
void TrajectoryAnalysisRunnerCommon::initTopology(SelectionCollection *selections) { // Return immediately if the topology has already been loaded. if (impl_->topInfo_.hasTopology()) { return; } const TrajectoryAnalysisSettings &settings = impl_->settings_; const bool bRequireTop = settings.hasFlag(TrajectoryAnalysisSettings::efRequireTop) || selections->requiresTopology(); if (bRequireTop && impl_->topfile_.empty()) { GMX_THROW(InconsistentInputError("No topology provided, but one is required for analysis")); } // Load the topology if requested. if (!impl_->topfile_.empty()) { char title[STRLEN]; snew(impl_->topInfo_.top_, 1); impl_->topInfo_.bTop_ = read_tps_conf(impl_->topfile_.c_str(), title, impl_->topInfo_.top_, &impl_->topInfo_.ePBC_, &impl_->topInfo_.xtop_, NULL, impl_->topInfo_.boxtop_, TRUE); if (hasTrajectory() && !settings.hasFlag(TrajectoryAnalysisSettings::efUseTopX)) { sfree(impl_->topInfo_.xtop_); impl_->topInfo_.xtop_ = NULL; } } // Read the first frame if we don't know the maximum number of atoms // otherwise. int natoms = -1; if (!impl_->topInfo_.hasTopology()) { initFirstFrame(); natoms = impl_->fr->natoms; } selections->setTopology(impl_->topInfo_.topology(), natoms); /* if (impl_->bSelDump) { gmx_ana_poscalc_coll_print_tree(stderr, impl_->pcc); fprintf(stderr, "\n"); } */ }
bool TrajectoryAnalysisRunnerCommon::readNextFrame() { bool bContinue = false; if (hasTrajectory()) { bContinue = read_next_frame(impl_->oenv_, impl_->status_, impl_->fr); } if (!bContinue) { impl_->finishTrajectory(); } return bContinue; }
void TrajectoryAnalysisRunnerCommon::initFirstFrame() { // Return if we have already initialized the trajectory. if (impl_->fr) { return; } time_unit_t time_unit = static_cast<time_unit_t>(impl_->settings_.timeUnit() + 1); output_env_init(&impl_->oenv_, 0, NULL, time_unit, FALSE, exvgNONE, 0, 0); int frflags = impl_->settings_.frflags(); frflags |= TRX_NEED_X; snew(impl_->fr, 1); const TopologyInformation &top = impl_->topInfo_; if (hasTrajectory()) { if (!read_first_frame(impl_->oenv_, &impl_->status_, impl_->trjfile_.c_str(), impl_->fr, frflags)) { GMX_THROW(FileIOError("Could not read coordinates from trajectory")); } impl_->bTrajOpen_ = true; if (top.hasTopology() && impl_->fr->natoms > top.topology()->atoms.nr) { GMX_THROW(InconsistentInputError(formatString( "Trajectory (%d atoms) does not match topology (%d atoms)", impl_->fr->natoms, top.topology()->atoms.nr))); } // Check index groups if they have been initialized based on the topology. /* if (top) { for (int i = 0; i < impl_->sel->nr(); ++i) { gmx_ana_index_check(impl_->sel->sel(i)->indexGroup(), impl_->fr->natoms); } } */ } else { // Prepare a frame from topology information. // TODO: Initialize more of the fields. if (frflags & (TRX_NEED_V)) { GMX_THROW(NotImplementedError("Velocity reading from a topology not implemented")); } if (frflags & (TRX_NEED_F)) { GMX_THROW(InvalidInputError("Forces cannot be read from a topology")); } impl_->fr->flags = frflags; impl_->fr->natoms = top.topology()->atoms.nr; impl_->fr->bX = TRUE; snew(impl_->fr->x, impl_->fr->natoms); memcpy(impl_->fr->x, top.xtop_, sizeof(*impl_->fr->x) * impl_->fr->natoms); impl_->fr->bBox = TRUE; copy_mat(const_cast<rvec *>(top.boxtop_), impl_->fr->box); } set_trxframe_ePBC(impl_->fr, top.ePBC()); if (top.hasTopology() && impl_->settings_.hasRmPBC()) { impl_->gpbc_ = gmx_rmpbc_init(&top.topology()->idef, top.ePBC(), impl_->fr->natoms, impl_->fr->box); } }
void TrajectoryAnalysisRunnerCommon::Impl::initFirstFrame() { // Return if we have already initialized the trajectory. if (fr != NULL) { return; } time_unit_t time_unit = static_cast<time_unit_t>(settings_.timeUnit() + 1); output_env_init(&oenv_, getProgramContext(), time_unit, FALSE, exvgNONE, 0); int frflags = settings_.frflags(); frflags |= TRX_NEED_X; snew(fr, 1); if (hasTrajectory()) { if (!read_first_frame(oenv_, &status_, trjfile_.c_str(), fr, frflags)) { GMX_THROW(FileIOError("Could not read coordinates from trajectory")); } bTrajOpen_ = true; if (topInfo_.hasTopology()) { const int topologyAtomCount = topInfo_.topology()->atoms.nr; if (fr->natoms > topologyAtomCount) { const std::string message = formatString("Trajectory (%d atoms) does not match topology (%d atoms)", fr->natoms, topologyAtomCount); GMX_THROW(InconsistentInputError(message)); } } } else { // Prepare a frame from topology information. // TODO: Initialize more of the fields. if (frflags & (TRX_NEED_V)) { GMX_THROW(NotImplementedError("Velocity reading from a topology not implemented")); } if (frflags & (TRX_NEED_F)) { GMX_THROW(InvalidInputError("Forces cannot be read from a topology")); } fr->natoms = topInfo_.topology()->atoms.nr; fr->bX = TRUE; snew(fr->x, fr->natoms); memcpy(fr->x, topInfo_.xtop_, sizeof(*fr->x) * fr->natoms); fr->bBox = TRUE; copy_mat(topInfo_.boxtop_, fr->box); } set_trxframe_ePBC(fr, topInfo_.ePBC()); if (topInfo_.hasTopology() && settings_.hasRmPBC()) { gpbc_ = gmx_rmpbc_init(&topInfo_.topology()->idef, topInfo_.ePBC(), fr->natoms); } }