本文整理汇总了C++中CpptrajState类的典型用法代码示例。如果您正苦于以下问题:C++ CpptrajState类的具体用法?C++ CpptrajState怎么用?C++ CpptrajState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CpptrajState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mprinterr
Exec::RetType Exec_Precision::Execute(CpptrajState& State, ArgList& argIn) {
// Next string is DataSet(s)/DataFile that command pertains to.
std::string name1 = argIn.GetStringNext();
if (name1.empty()) {
mprinterr("Error: No filename/setname given.\n");
return CpptrajState::ERR;
}
// This will break if dataset name starts with a digit...
int width = argIn.getNextInteger(12);
if (width < 1) {
mprintf("Error: Cannot set width < 1 (%i).\n", width);
return CpptrajState::ERR;
}
int precision = argIn.getNextInteger(4);
if (precision < 0) precision = 0;
DataFile* df = State.DFL().GetDataFile(name1);
if (df != 0) {
mprintf("\tSetting precision for all sets in %s to %i.%i\n", df->DataFilename().base(),
width, precision);
df->SetDataFilePrecision(width, precision);
} else {
State.DSL().SetPrecisionOfDataSets( name1, width, precision );
}
return CpptrajState::OK;
}
示例2: mprinterr
// Exec_DataSetCmd::Make2D()
Exec::RetType Exec_DataSetCmd::Make2D(CpptrajState& State, ArgList& argIn) {
std::string name = argIn.GetStringKey("name");
int ncols = argIn.getKeyInt("ncols", 0);
int nrows = argIn.getKeyInt("nrows", 0);
if (ncols <= 0 || nrows <= 0) {
mprinterr("Error: Must specify both ncols and nrows\n");
return CpptrajState::ERR;
}
DataSet* ds1 = State.DSL().GetDataSet( argIn.GetStringNext() );
if (ds1 == 0) return CpptrajState::ERR;
if (ds1->Ndim() != 1) {
mprinterr("Error: make2d only works for 1D data sets.\n");
return CpptrajState::ERR;
}
if (nrows * ncols != (int)ds1->Size()) {
mprinterr("Error: Size of '%s' (%zu) != nrows X ncols.\n", ds1->legend(), ds1->Size());
return CpptrajState::ERR;
}
if (name.empty())
name = State.DSL().GenerateDefaultName("make2d");
MetaData md(name, MetaData::M_MATRIX);
DataSet* ds3 = State.DSL().AddSet( DataSet::MATRIX_DBL, md );
if (ds3 == 0) return CpptrajState::ERR;
mprintf("\tConverting values from 1D set '%s' to 2D matrix '%s' with %i cols, %i rows.\n",
ds1->legend(), ds3->legend(), ncols, nrows);
DataSet_1D const& data = static_cast<DataSet_1D const&>( *ds1 );
DataSet_MatrixDbl& matrix = static_cast<DataSet_MatrixDbl&>( *ds3 );
if (matrix.Allocate2D( ncols, nrows )) return CpptrajState::ERR;
for (unsigned int idx = 0; idx != data.Size(); idx++)
matrix.AddElement( data.Dval(idx) );
return CpptrajState::OK;
}
示例3: mprinterr
// Exec_CrdAction::ProcessArgs()
Exec::RetType Exec_CrdAction::ProcessArgs(CpptrajState& State, ArgList& argIn) {
std::string setname = argIn.GetStringNext();
if (setname.empty()) {
mprinterr("Error: %s: Specify COORDS dataset name.\n", argIn.Command());
return CpptrajState::ERR;
}
DataSet_Coords* CRD = (DataSet_Coords*)State.DSL().FindCoordsSet( setname );
if (CRD == 0) {
mprinterr("Error: %s: No COORDS set with name %s found.\n", argIn.Command(), setname.c_str());
return CpptrajState::ERR;
}
mprintf("\tUsing set '%s'\n", CRD->legend());
// Start, stop, offset
TrajFrameCounter frameCount;
ArgList crdarg( argIn.GetStringKey("crdframes"), "," );
if (frameCount.CheckFrameArgs( CRD->Size(), crdarg )) return CpptrajState::ERR;
frameCount.PrintInfoLine(CRD->legend());
ArgList actionargs = argIn.RemainingArgs();
actionargs.MarkArg(0);
Cmd const& cmd = Command::SearchTokenType( DispatchObject::ACTION, actionargs.Command() );
if ( cmd.Empty() ) return CpptrajState::ERR;
Action* act = (Action*)cmd.Alloc();
if (act == 0) return CpptrajState::ERR;
CpptrajState::RetType err = DoCrdAction(State, actionargs, CRD, act, frameCount);
delete act;
return err;
}
示例4: if
// Exec_DataSetCmd::ChangeOutputFormat()
Exec::RetType Exec_DataSetCmd::ChangeOutputFormat(CpptrajState const& State, ArgList& argIn)
{
TextFormat::FmtType fmt;
if (argIn.hasKey("double"))
fmt = TextFormat::DOUBLE;
else if (argIn.hasKey("scientific"))
fmt = TextFormat::SCIENTIFIC;
else if (argIn.hasKey("general"))
fmt = TextFormat::GDOUBLE;
else {
mprinterr("Error: Expected either 'double', 'scientific', or 'general'\n");
return CpptrajState::ERR;
}
// Loop over all DataSet arguments
std::string ds_arg = argIn.GetStringNext();
while (!ds_arg.empty()) {
DataSetList dsl = State.DSL().GetMultipleSets( ds_arg );
for (DataSetList::const_iterator ds = dsl.begin(); ds != dsl.end(); ++ds)
if ((*ds)->SetupFormat().SetFormatType(fmt))
mprintf("\tSet '%s' output format changed to '%s'\n",
(*ds)->legend(), TextFormat::typeDescription(fmt));
ds_arg = argIn.GetStringNext();
}
return CpptrajState::OK;
}
示例5: mprintf
Exec::RetType Exec_ParmBox::Execute(CpptrajState& State, ArgList& argIn) {
Box pbox;
bool nobox = false;
if ( argIn.hasKey("nobox") )
nobox = true;
else {
pbox.SetX( argIn.getKeyDouble("x",0) );
pbox.SetY( argIn.getKeyDouble("y",0) );
pbox.SetZ( argIn.getKeyDouble("z",0) );
pbox.SetAlpha( argIn.getKeyDouble("alpha",0) );
pbox.SetBeta( argIn.getKeyDouble("beta",0) );
pbox.SetGamma( argIn.getKeyDouble("gamma",0) );
}
Topology* parm = State.DSL().GetTopByIndex( argIn );
if (parm == 0) return CpptrajState::ERR;
if (nobox)
mprintf("\tRemoving box information from parm %i:%s\n", parm->Pindex(), parm->c_str());
else
// Fill in missing parm box information from specified parm
pbox.SetMissingInfo( parm->ParmBox() );
if (argIn.hasKey("truncoct")) pbox.SetTruncOct();
parm->SetParmBox( pbox );
parm->ParmBox().PrintInfo();
return CpptrajState::OK;
}
示例6: mprinterr
Exec::RetType Exec_ParmStrip::Execute(CpptrajState& State, ArgList& argIn) {
Topology* parm = State.DSL().GetTopByIndex( argIn );
if (parm == 0) return CpptrajState::ERR;
// Check if this topology has already been used to set up an input
// trajectory, as this will break the traj read.
bool topology_in_use = false;
const char* fname = 0;
for (TrajinList::trajin_it tIn = State.InputTrajList().trajin_begin();
tIn != State.InputTrajList().trajin_end(); ++tIn)
if ( (*tIn)->Traj().Parm() == parm ) {
topology_in_use = true;
fname = (*tIn)->Traj().Filename().full();
break;
}
if (!topology_in_use) {
for (TrajinList::ensemble_it eIn = State.InputTrajList().ensemble_begin();
eIn != State.InputTrajList().ensemble_end(); ++eIn)
if ( (*eIn)->Traj().Parm() == parm ) {
topology_in_use = true;
fname = (*eIn)->Traj().Filename().full();
break;
}
}
if (topology_in_use) {
mprinterr("Error: Topology '%s' has already been used to set up trajectory '%s'.\n"
"Error: To strip this topology use the 'strip' action.\n",
parm->c_str(), fname);
return CpptrajState::ERR;
}
AtomMask tempMask( argIn.GetMaskNext() );
// Since want to keep atoms outside mask, invert selection
tempMask.InvertMaskExpression();
if (parm->SetupIntegerMask( tempMask )) return CpptrajState::ERR;
mprintf("\tStripping atoms in mask [%s] (%i) from %s\n",tempMask.MaskString(),
parm->Natom() - tempMask.Nselected(), parm->c_str());
Topology* tempParm = parm->modifyStateByMask(tempMask);
if (tempParm==0) {
mprinterr("Error: %s: Could not strip parm.\n", argIn.Command());
return CpptrajState::ERR;
} else {
// Replace parm with stripped version
*parm = *tempParm;
parm->Brief("Stripped parm:");
delete tempParm;
}
return CpptrajState::OK;
}
示例7: while
// Exec_SortEnsembleData::Execute()
Exec::RetType Exec_SortEnsembleData::Execute(CpptrajState& State, ArgList& argIn)
{
debug_ = State.Debug();
DataSetList setsToSort;
std::string dsarg = argIn.GetStringNext();
while (!dsarg.empty()) {
setsToSort += State.DSL().GetMultipleSets( dsarg );
dsarg = argIn.GetStringNext();
}
int err = 0;
# ifdef MPI
// For now, require ensemble mode in parallel.
if (!Parallel::EnsembleIsSetup()) {
rprinterr("Error: Data set ensemble sort requires ensemble mode in parallel.\n");
return CpptrajState::ERR;
}
// Only TrajComm masters have complete data.
if (Parallel::TrajComm().Master()) {
comm_ = Parallel::MasterComm();
# endif
DataSetList OutputSets;
err = SortData( setsToSort, OutputSets );
if (err == 0) {
// Remove unsorted sets.
for (DataSetList::const_iterator ds = setsToSort.begin(); ds != setsToSort.end(); ++ds)
State.DSL().RemoveSet( *ds );
// Add sorted sets.
for (DataSetList::const_iterator ds = OutputSets.begin(); ds != OutputSets.end(); ++ds)
State.DSL().AddSet( *ds );
// Since sorted sets have been transferred to master DSL, OutputSets now
// just has copies.
OutputSets.SetHasCopies( true );
mprintf("\tSorted sets:\n");
OutputSets.List();
}
# ifdef MPI
}
if (Parallel::World().CheckError( err ))
# else
if (err != 0)
# endif
return CpptrajState::ERR;
return CpptrajState::OK;
}
示例8: state
Exec::RetType Exec_DataFilter::Execute(CpptrajState& State, ArgList& argIn) {
Action_FilterByData filterAction;
ActionInit state(State.DSL(), State.DFL());
if (filterAction.Init(argIn, state, State.Debug()) != Action::OK)
return CpptrajState::ERR;
size_t nframes = filterAction.DetermineFrames();
if (nframes < 1) {
mprinterr("Error: No data to filter. All sets must contain some data.\n");
return CpptrajState::ERR;
}
ProgressBar progress( nframes );
ActionFrame frm;
for (size_t frame = 0; frame != nframes; frame++) {
progress.Update( frame );
filterAction.DoAction(frame, frm); // Filter does not need frame.
}
// Trigger master datafile write just in case
State.MasterDataFileWrite();
return CpptrajState::OK;
}
示例9: mprinterr
Exec::RetType Exec_ReadData::Execute(CpptrajState& State, ArgList& argIn) {
DataFile dataIn;
dataIn.SetDebug( State.DFL().Debug() );
std::string filenameIn = argIn.GetStringNext();
File::NameArray fnames = File::ExpandToFilenames( filenameIn );
if (fnames.empty()) {
mprinterr("Error: '%s' matches no files.\n", filenameIn.c_str());
return CpptrajState::ERR;
}
int err = 0;
int idx = -1;
bool useIndex = argIn.hasKey("separate");
for (File::NameArray::const_iterator fn = fnames.begin(); fn != fnames.end(); ++fn) {
if (useIndex) idx++;
if (dataIn.ReadDataIn( *fn, argIn, State.DSL(), idx, fnames.size() )!=0) {
mprinterr("Error: Could not read data file '%s'.\n", fn->full());
err++;
}
}
if (err > 0) return CpptrajState::ERR;
return CpptrajState::OK;
}
示例10: mprintf
// Exec_DataSetCmd::Concatenate()
Exec::RetType Exec_DataSetCmd::Concatenate(CpptrajState& State, ArgList& argIn) {
std::string name = argIn.GetStringKey("name");
bool use_offset = !argIn.hasKey("nooffset");
DataSet* ds3 = State.DSL().AddSet( DataSet::XYMESH, name, "CAT" );
if (ds3 == 0) return CpptrajState::ERR;
DataSet_1D& out = static_cast<DataSet_1D&>( *ds3 );
mprintf("\tConcatenating sets into '%s'\n", out.legend());
if (use_offset)
mprintf("\tX values will be offset.\n");
else
mprintf("\tX values will not be offset.\n");
std::string dsarg = argIn.GetStringNext();
double offset = 0.0;
while (!dsarg.empty()) {
DataSetList dsl = State.DSL().GetMultipleSets( dsarg );
double XY[2];
for (DataSetList::const_iterator ds = dsl.begin(); ds != dsl.end(); ++ds)
{
if ( (*ds)->Group() != DataSet::SCALAR_1D )
{
mprintf("Warning: '%s': Concatenation only supported for 1D scalar data sets.\n",
(*ds)->legend());
} else {
DataSet_1D const& set = static_cast<DataSet_1D const&>( *(*ds) );
mprintf("\t\t'%s'\n", set.legend());
for (size_t i = 0; i != set.Size(); i++) {
XY[0] = set.Xcrd( i ) + offset;
XY[1] = set.Dval( i );
out.Add( i, XY ); // NOTE: value of i does not matter for mesh
}
if (use_offset) offset = XY[0];
}
}
dsarg = argIn.GetStringNext();
}
return CpptrajState::OK;
}
示例11: mprinterr
Exec::RetType Exec_ParmSolvent::Execute(CpptrajState& State, ArgList& argIn) {
std::string maskexpr;
if (!argIn.hasKey("none")) {
maskexpr = argIn.GetMaskNext();
if ( maskexpr.empty() ) {
mprinterr("Error: solvent: No mask specified.\n");
return CpptrajState::ERR;
}
}
// Get parm index
Topology* parm = State.DSL().GetTopByIndex( argIn );
if (parm == 0) return CpptrajState::ERR;
parm->SetSolvent( maskexpr );
return CpptrajState::OK;
}
示例12: state
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;
}
示例13: Execute
// Exec_DataSetCmd::Execute()
Exec::RetType Exec_DataSetCmd::Execute(CpptrajState& State, ArgList& argIn) {
RetType err = CpptrajState::OK;
if (argIn.Contains("legend")) { // Set legend for one data set
std::string legend = argIn.GetStringKey("legend");
DataSet* ds = State.DSL().GetDataSet( argIn.GetStringNext() );
if (ds == 0) return CpptrajState::ERR;
mprintf("\tChanging legend '%s' to '%s'\n", ds->legend(), legend.c_str());
ds->SetLegend( legend );
// ---------------------------------------------
} else if (argIn.hasKey("outformat")) { // Change double precision set output format
err = ChangeOutputFormat(State, argIn);
// ---------------------------------------------
} else if (argIn.hasKey("remove")) { // Remove data sets by various criteria
err = Remove(State, argIn);
// ---------------------------------------------
} else if (argIn.hasKey("makexy")) { // Combine values from two sets into 1
err = MakeXY(State, argIn);
// ---------------------------------------------
} else if (argIn.hasKey("make2d")) { // Create 2D matrix from 1D set
err = Make2D(State, argIn);
// ---------------------------------------------
} else if (argIn.hasKey("vectorcoord")) { // Extract vector X/Y/Z coord as new set
err = VectorCoord(State, argIn);
// ---------------------------------------------
} else if (argIn.hasKey("filter")) { // Filter points in data set to make new data set
err = Filter(State, argIn);
// ---------------------------------------------
} else if (argIn.hasKey("cat")) { // Concatenate two or more data sets
err = Concatenate(State, argIn);
// ---------------------------------------------
} else if (argIn.hasKey("droppoints")) { // Drop points from set
err = ModifyPoints(State, argIn, true);
// ---------------------------------------------
} else if (argIn.hasKey("keeppoints")) { // Keep points in set
err = ModifyPoints(State, argIn, false);
// ---------------------------------------------
} else if (argIn.hasKey("dim")) { // Modify dimension of set(s)
err = ChangeDim(State, argIn);
// ---------------------------------------------
} else if (argIn.hasKey("invert")) { // Invert set(s) X/Y, create new sets
err = InvertSets(State, argIn);
// ---------------------------------------------
} else { // Default: change mode/type for one or more sets.
err = ChangeModeType(State, argIn);
}
return err;
}
示例14: mprinterr
// Exec_Analyze::Execute()
Exec::RetType Exec_Analyze::Execute(CpptrajState& State, ArgList& argIn) {
// Remove 'analyze'
ArgList arg = argIn;
arg.RemoveFirstArg();
if (arg.empty()) {
mprinterr("Error: No analysis command specified.\n");
return CpptrajState::ERR;
}
mprintf("Warning: The 'analyze' prefix is no longer necessary and may be soon deprecated.\n");
if (arg.CommandIs("matrix"))
mprintf("Warning: NOTE: 'analyze matrix' is now 'diagmatrix'.\n");
else
mprintf("Warning: To add an analysis command the the queue, only the command name needs\n"
"Warning: to be specified, e.g. '%s <args>'.\n", arg.Command());
Cmd const& cmd = Command::SearchTokenType(DispatchObject::ANALYSIS, arg.Command());
if (cmd.Empty()) {
mprinterr("Error: Analysis command '%s' not found.\n", arg.Command());
return CpptrajState::ERR;
}
return State.AddToAnalysisQueue( (Analysis*)cmd.Alloc(), arg );
}
示例15: mprinterr
Exec::RetType Exec_LoadTraj::Execute(CpptrajState& State, ArgList& argIn) {
// Get Keywords
std::string setname = argIn.GetStringKey("name");
if (setname.empty()) {
mprinterr("Error: Must provide data set name ('name <setname>')\n");
return CpptrajState::ERR;
}
DataSet_Coords_TRJ* trj = (DataSet_Coords_TRJ*)
State.DSL().FindSetOfType(setname, DataSet::TRAJ);
if (trj == 0)
trj = (DataSet_Coords_TRJ*)
State.DSL().AddSet(DataSet::TRAJ, setname, "__DTRJ__");
if (trj == 0) {
mprinterr("Error: Could not set up TRAJ data set.\n");
return CpptrajState::ERR;
}
std::string trajname = argIn.GetStringNext();
if (trajname.empty()) {
// Add all existing input trajectories
if (State.InputTrajList().empty()) {
mprinterr("Error: No input trajectories loaded.\n");
return CpptrajState::ERR;
}
if (State.InputTrajList().Mode() != TrajinList::NORMAL) {
mprinterr("Error: Cannot convert ensemble input trajectories to data.\n");
return CpptrajState::ERR;
}
mprintf("\tSaving currently loaded input trajectories as data set with name '%s'\n",
setname.c_str());
for (TrajinList::trajin_it Trajin = State.InputTrajList().trajin_begin();
Trajin != State.InputTrajList().trajin_end(); ++Trajin)
if (trj->AddInputTraj( *Trajin )) return CpptrajState::ERR;
// TODO: Clear input trajectories from trajinList?
} else {
// Add the named trajectory
if (trj->AddSingleTrajin( trajname, argIn, State.DSL().GetTopology(argIn) ))
return CpptrajState::ERR;
}
return CpptrajState::OK;
}