Exec::RetType Exec_CrdAction::DoCrdAction(CpptrajState& State, ArgList& actionargs, DataSet_Coords* CRD, Action* act, TrajFrameCounter const& frameCount) const { Timer total_time; total_time.Start(); # ifdef MPI ActionInit state(State.DSL(), State.DFL(), trajComm_); # else ActionInit state(State.DSL(), State.DFL()); # endif if ( act->Init( actionargs, state, State.Debug() ) != Action::OK ) return CpptrajState::ERR; actionargs.CheckForMoreArgs(); // Set up frame and parm for COORDS. ActionSetup originalSetup( CRD->TopPtr(), CRD->CoordsInfo(), CRD->Size() ); Frame originalFrame = CRD->AllocateFrame(); ActionFrame frm( &originalFrame, 0 ); // Set up for this topology Action::RetType setup_ret = act->Setup( originalSetup ); if ( setup_ret == Action::ERR || setup_ret == Action::SKIP ) return CpptrajState::ERR; // Loop over all frames in COORDS. ProgressBar progress( frameCount.TotalReadFrames() ); int set = 0; for (int frame = frameCount.Start(); frame < frameCount.Stop(); frame += frameCount.Offset(), ++set) { progress.Update( set ); CRD->GetFrame( frame, originalFrame ); frm.SetTrajoutNum( set ); Action::RetType ret = act->DoAction( set, frm ); if (ret == Action::ERR) { mprinterr("Error: crdaction: Frame %i, set %i\n", frame + 1, set + 1); break; } // Check if frame was modified. If so, update COORDS. if ( ret == Action::MODIFY_COORDS ) CRD->SetCRD( frame, frm.Frm() ); } # ifdef MPI act->SyncAction(); # endif // Check if parm was modified. If so, update COORDS. if ( setup_ret == Action::MODIFY_TOPOLOGY ) { mprintf("Info: crdaction: Parm for %s was modified by action %s\n", CRD->legend(), actionargs.Command()); CRD->CoordsSetup( originalSetup.Top(), originalSetup.CoordInfo() ); } act->Print(); State.MasterDataFileWrite(); total_time.Stop(); mprintf("TIME: Total action execution time: %.4f seconds.\n", total_time.Total()); return CpptrajState::OK; }
/** Add specified analysis to the analysis list with given args and * DataSetList. */ int AnalysisList::AddAnalysis(DispatchObject::DispatchAllocatorType Alloc, ArgList& argIn, DataSetList* DSLin, DataFileList* DFLin) { Analysis* ana = (Analysis*)Alloc(); // Attempt to set up analysis if (ana->Setup( argIn, DSLin, DFLin, debug_) != Analysis::OK) { mprinterr("Error: Could not setup analysis [%s]\n", argIn.Command()); delete ana; return 1; } analysisList_.push_back( ana ); analysisCmd_.push_back( argIn.ArgLine() ); analysisStatus_.push_back( SETUP ); if (argIn.CheckForMoreArgs()) return 1; return 0; }
/** Add specified analysis to the analysis list with given args and * DataSetList. */ int AnalysisList::AddAnalysis(Analysis* anaIn, ArgList& argIn, AnalysisSetup& setup) { if (anaIn == 0) { mprinterr("Internal Error: AddAnalysis() called with null Analysis.\n"); return 1; } AnaHolder ana; ana.ptr_ = anaIn; ana.args_ = argIn; // Attempt to set up analysis if (ana.ptr_->Setup( argIn, setup, debug_) != Analysis::OK) { mprinterr("Error: Could not setup analysis [%s]\n", argIn.Command()); delete ana.ptr_; return 1; } ana.status_ = SETUP; analysisList_.push_back( ana ); if (argIn.CheckForMoreArgs()) return 1; return 0; }
// ActionList::AddAction() int ActionList::AddAction(DispatchObject::DispatchAllocatorType Alloc, ArgList& argIn, TopologyList* PFL, DataSetList* DSL, DataFileList* DFL) { int err = 0; if (actionsAreSilent_) SetWorldSilent( true ); Action* act = (Action*)Alloc(); // Attempt to initialize action if ( act->Init( argIn, PFL, DSL, DFL, debug_ ) != Action::OK ) { mprinterr("Error: Could not initialize action [%s]\n", argIn.Command()); delete act; err = 1; } else { actionlist_.push_back( act ); actioncmd_.push_back( argIn.ArgLine() ); actionAlloc_.push_back( Alloc ); actionstatus_.push_back( INIT ); if (argIn.CheckForMoreArgs()) err = 1; } if (actionsAreSilent_) SetWorldSilent( false ); return err; }
/** Process command relating to data files. */ int DataFileList::ProcessDataFileArgs(ArgList& dataArg) { // Next string is DataFile name that command will be passed to. std::string df_cmd = dataArg.GetStringNext(); if (df_cmd.empty()) { mprintf("Warning: datafile: No filename given.\n"); return 0; } // Check for deprecated commands if (df_cmd == "create" || df_cmd == "precision") mprintf("Warning: 'datafile %s' is deprecated; use %s instead.\n", df_cmd.c_str(), df_cmd.c_str()); //mprintf(" [%s]\n",(*dataArg).ArgLine()); DataFile* df = GetDataFile( df_cmd.c_str() ); if (df == 0) { mprinterr("Error: datafile: File %s not found.\n", df_cmd.c_str()); return 1; } // Process command int err = df->ProcessArgs( dataArg ); if (err != 0 || dataArg.CheckForMoreArgs()) return 1; return 0; }
Exec::RetType Exec_CrdAction::DoCrdAction(CpptrajState& State, ArgList& actionargs, DataSet_Coords* CRD, Action* act, TrajFrameCounter const& frameCount) const { Timer total_time; total_time.Start(); # ifdef MPI ActionInit state(State.DSL(), State.DFL(), trajComm_); # else ActionInit state(State.DSL(), State.DFL()); # endif if ( act->Init( actionargs, state, State.Debug() ) != Action::OK ) return CpptrajState::ERR; actionargs.CheckForMoreArgs(); // Set up frame and parm for COORDS. ActionSetup originalSetup( CRD->TopPtr(), CRD->CoordsInfo(), CRD->Size() ); Frame originalFrame = CRD->AllocateFrame(); // Set up for this topology Action::RetType setup_ret = act->Setup( originalSetup ); if ( setup_ret == Action::ERR || setup_ret == Action::SKIP ) return CpptrajState::ERR; // If the topology was modified, we will need a new COORDS set. DataSet_Coords* crdOut = 0; if ( setup_ret == Action::MODIFY_TOPOLOGY ) { // This will not work for a TRJ set. switch ( CRD->Type() ) { case DataSet::TRAJ : mprinterr("Error: Cannot modify TRAJ data sets.\n"); break; case DataSet::COORDS : crdOut = (DataSet_Coords*)new DataSet_Coords_CRD(); break; case DataSet::REF_FRAME : crdOut = (DataSet_Coords*)new DataSet_Coords_REF(); break; default: crdOut = 0; // SANITY } if (crdOut == 0) return CpptrajState::ERR; mprintf("Info: crdaction: COORDS set '%s' will be modified by action '%s'\n", CRD->legend(), actionargs.Command()); if (frameCount.TotalReadFrames() != (int)CRD->Size()) mprintf("Info: crdaction: Previous size= %zu, new size is %i\n", CRD->Size(), frameCount.TotalReadFrames()); // Set up set, copy original metadata crdOut->SetMeta( CRD->Meta() ); if (crdOut->CoordsSetup( originalSetup.Top(), originalSetup.CoordInfo() )) return CpptrajState::ERR; DataSet::SizeArray mfArray(1, frameCount.TotalReadFrames()); if (crdOut->Allocate( mfArray )) return CpptrajState::ERR; } // Loop over all frames in COORDS. ProgressBar* progress = 0; if (State.ShowProgress()) progress = new ProgressBar( frameCount.TotalReadFrames() ); int set = 0; for (int frame = frameCount.Start(); frame < frameCount.Stop(); frame += frameCount.Offset(), ++set) { // Since Frame can be modified by actions, save original and use currentFrame ActionFrame frm( &originalFrame, set ); if (progress != 0) progress->Update( set ); CRD->GetFrame( frame, originalFrame ); Action::RetType ret = act->DoAction( set, frm ); if (ret == Action::ERR) { mprinterr("Error: crdaction: Frame %i, set %i\n", frame + 1, set + 1); break; } // Check if frame was modified. If so, update COORDS. if ( ret == Action::MODIFY_COORDS ) { if (crdOut != 0) crdOut->AddFrame( frm.Frm() ); else CRD->SetCRD( frame, frm.Frm() ); } } if (progress != 0) delete progress; # ifdef MPI act->SyncAction(); # endif // If topology was modified, replace old set with new. if ( setup_ret == Action::MODIFY_TOPOLOGY ) { mprintf("Info: crdaction: Topology for '%s' was modified by action '%s'\n", CRD->legend(), actionargs.Command()); State.DSL().RemoveSet( CRD ); State.DSL().AddSet( crdOut ); } act->Print(); State.MasterDataFileWrite(); total_time.Stop(); mprintf("TIME: Total action execution time: %.4f seconds.\n", total_time.Total()); return CpptrajState::OK; }