Ejemplo n.º 1
0
// Action_Average::init()
Action::RetType Action_Average::Init(ArgList& actionArgs, TopologyList* PFL, FrameList* FL,
                          DataSetList* DSL, DataFileList* DFL, int debugIn)
{
  debug_ = debugIn;
  // Get Keywords
  avgfilename_ = actionArgs.GetStringNext();
  if (avgfilename_.empty()) {
    mprinterr("Error: average: No filename given.\n");
    return Action::ERR;
  }
  // Get start/stop/offset args
  if (InitFrameCounter(actionArgs)) return Action::ERR;

  // Get Masks
  Mask1_.SetMaskString( actionArgs.GetMaskNext() );

  // Save all remaining arguments for setting up the trajectory at the end.
  trajArgs_ = actionArgs.RemainingArgs();

  mprintf("    AVERAGE: Averaging over coordinates in mask [%s]\n",Mask1_.MaskString());
  FrameCounterInfo();
  mprintf("\tWriting averaged coords to [%s]\n",avgfilename_.c_str());

  Nframes_ = 0;

  return Action::OK;
}
Ejemplo n.º 2
0
// Action_AtomicFluct::Init()
Action::RetType Action_AtomicFluct::Init(ArgList& actionArgs, TopologyList* PFL, DataSetList* DSL, DataFileList* DFL, int debugIn)
{
    // Get frame # keywords
    if (InitFrameCounter(actionArgs)) return Action::ERR;
    // Get other keywords
    bfactor_ = actionArgs.hasKey("bfactor");
    calc_adp_ = actionArgs.hasKey("calcadp");
    adpoutfile_ = DFL->AddCpptrajFile(actionArgs.GetStringKey("adpout"), "PDB w/ADP",
                                      DataFileList::PDB);;
    if (adpoutfile_!=0) calc_adp_ = true; // adpout implies calcadp
    if (calc_adp_ && !bfactor_) bfactor_ = true;
    DataFile* outfile = DFL->AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
    if (actionArgs.hasKey("byres"))
        outtype_ = BYRES;
    else if (actionArgs.hasKey("bymask"))
        outtype_ = BYMASK;
    else if (actionArgs.hasKey("byatom") || actionArgs.hasKey("byatm"))
        outtype_ = BYATOM;
    // Get Mask
    Mask_.SetMaskString( actionArgs.GetMaskNext()  );
    // Get DataSet name
    std::string setname = actionArgs.GetStringNext();
    // Add output dataset
    MetaData md( setname );
    md.SetTimeSeries( MetaData::NOT_TS );
    if (bfactor_)
        md.SetLegend("B-factors");
    else
        md.SetLegend("AtomicFlx");
    dataout_ = DSL->AddSet( DataSet::XYMESH, md, "Fluct" );
    if (dataout_ == 0) {
        mprinterr("Error: AtomicFluct: Could not allocate dataset for output.\n");
        return Action::ERR;
    }
    if (outfile != 0)
        outfile->AddDataSet( dataout_ );

    mprintf("    ATOMICFLUCT: calculating");
    if (bfactor_)
        mprintf(" B factors");
    else
        mprintf(" atomic positional fluctuations");
    if (outfile != 0)
        mprintf(", output to file %s", outfile->DataFilename().full());
    mprintf("\n                 Atom mask: [%s]\n",Mask_.MaskString());
    FrameCounterInfo();
    if (calc_adp_) {
        mprintf("\tCalculating anisotropic displacement parameters.\n");
        if (adpoutfile_!=0) mprintf("\tWriting PDB with ADP to '%s'\n", adpoutfile_->Filename().full());
    }
    if (!setname.empty())
        mprintf("\tData will be saved to set named %s\n", setname.c_str());

    return Action::OK;
}
Ejemplo n.º 3
0
// Action_Matrix::Init()
Action::RetType Action_Matrix::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
# ifdef MPI
  trajComm_ = init.TrajComm();
# endif
  debug_ = debugIn;
  // Get Keywords
  std::string outfilename = actionArgs.GetStringKey("out");
  // Get start/stop/offset
  if (InitFrameCounter(actionArgs)) return Action::ERR;
  // Determine matrix type
  MetaData::scalarType mtype = MetaData::DIST;
  if (actionArgs.hasKey("distcovar"))
    mtype = MetaData::DISTCOVAR;
  else if (actionArgs.hasKey("mwcovar"))
    mtype = MetaData::MWCOVAR;
  else if (actionArgs.hasKey("dist"))
    mtype = MetaData::DIST;
  else if (actionArgs.hasKey("covar"))
    mtype = MetaData::COVAR;
  else if (actionArgs.hasKey("correl"))
    mtype = MetaData::CORREL;
  else if (actionArgs.hasKey("idea"))
    mtype = MetaData::IDEA;
  else if (actionArgs.hasKey("ired"))
    mtype = MetaData::IREDMAT;
  else if (actionArgs.hasKey("dihcovar"))
    mtype = MetaData::DIHCOVAR;
  // Output type
  if (actionArgs.hasKey("byres"))
    outtype_ = BYRESIDUE;
  else if (actionArgs.hasKey("bymask"))
    outtype_ = BYMASK;
  else if (actionArgs.hasKey("byatom"))
    outtype_ = BYATOM;
  else
    outtype_ = BYATOM;
  // Check if output type is valid for matrix type
  if ( outtype_ != BYATOM && (mtype == MetaData::COVAR || 
                              mtype == MetaData::MWCOVAR || 
                              mtype == MetaData::IREDMAT ) )
  {
    mprinterr("Error: matrix: for COVAR, MWCOVAR, or IRED matrix only byatom output possible\n");
    return Action::ERR;
  }
  // Get matrix name
  std::string name = actionArgs.GetStringKey("name");
  // UseMass
  useMass_ = actionArgs.hasKey("mass");
  // NOTE: Determine matrix kind here so subsequent Actions/Analyses know about it.
  DataSet_2D::MatrixKindType mkind = DataSet_2D::HALF;
  if (mtype == MetaData::IREDMAT) { // IRED matrix
    // Setup IRED vectors and determine Legendre order
    order_ = actionArgs.getKeyInt("order",1);
    if (order_ <= 0) {
      mprinterr("Error: matrix: order parameter <= 0, ignoring command\n");
      return Action::ERR;
    }
    for ( DataSetList::const_iterator DS = init.DSL().begin(); DS != init.DSL().end(); ++DS) {
      if ( (*DS)->Type() == DataSet::VECTOR && (*DS)->Meta().ScalarType() == MetaData::IREDVEC )
        IredVectors_.push_back( (DataSet_Vector*)*DS );
    }
    if (IredVectors_.empty()) {
      mprinterr("Error: matrix: no vectors defined for IRED\n");
      return Action::ERR;
    }
  } else if (mtype == MetaData::DIHCOVAR) { // Dihedral Covariance
    // Get data set mask for dihedral covariance
    DihedralSets_.clear();
    DihedralSets_.AddTorsionSets( init.DSL().GetMultipleSets( actionArgs.GetStringKey("dihedrals") ) );
    if ( DihedralSets_.empty() ) {
      mprinterr("Error: No valid data sets found.\n");
      return Action::ERR;
    }
  } else {
    // Get masks if not IRED/DIHCOVAR
    mask1_.SetMaskString( actionArgs.GetMaskNext() );
    std::string maskexpr = actionArgs.GetMaskNext();
    if (!maskexpr.empty()) useMask2_ = true;
    if ( useMask2_ && (mtype == MetaData::IDEA || mtype == MetaData::DISTCOVAR) )
    {
      mprinterr("Error: Mask 2 [%s] specified but not used for %s matrix\n",
                maskexpr.c_str(), MetaData::TypeString(mtype));
      useMask2_ = false;
      return Action::ERR;
    }
    if (useMask2_) {
      mask2_.SetMaskString( maskexpr );
      mkind = DataSet_2D::FULL;
    }
  }

  // Create matrix BYATOM DataSet
  Mat_ = (DataSet_MatrixDbl*)init.DSL().AddSet(DataSet::MATRIX_DBL,
                                         MetaData(name, MetaData::M_MATRIX, mtype), "Mat");
  if (Mat_ == 0) return Action::ERR;
  // NOTE: Type/Kind is set here so subsequent analyses/actions know about it.
  Mat_->SetMatrixKind( mkind );
  // Set default precision for backwards compat.
  Mat_->SetupFormat().SetFormatWidthPrecision(6, 3);
  Mat_->ModifyDim(Dimension::X).SetLabel("Atom");
  // Determine what will be output.
  matByRes_ = 0;
  outfile_ = 0;
  byMaskOut_ = 0;
  if (outtype_ == BYMASK) {
    // BYMASK output - no final data set, just write to file/STDOUT.
    byMaskOut_ = init.DFL().AddCpptrajFile(outfilename, "Matrix by mask",
                                     DataFileList::TEXT, true);
    if (byMaskOut_ == 0) return Action::ERR;
  } else {
    // BYATOM or BYRESIDUE output. Set up DataFile. 
    if (outtype_ == BYRESIDUE) {
      MetaData md(Mat_->Meta().Name(), "ByRes");
      md.SetScalarMode(MetaData::M_MATRIX);
      matByRes_ = (DataSet_MatrixDbl*)init.DSL().AddSet(DataSet::MATRIX_DBL, md);
      if (matByRes_ == 0) return Action::ERR;
      matByRes_->SetupFormat().SetFormatWidthPrecision(6, 3);
      matByRes_->ModifyDim(Dimension::X).SetLabel("Res");
#     ifdef MPI
      // Since by-residue matrix allocated in Print(), no sync needed.
      matByRes_->SetNeedsSync( false );
#     endif
    } 
    outfile_ = init.DFL().AddDataFile(outfilename, actionArgs);
    if (outfile_ != 0) {
      if (outtype_ == BYATOM)
        outfile_->AddDataSet( Mat_ );
      else
        outfile_->AddDataSet( matByRes_ );
    }
  }

  mprintf("    MATRIX: Calculating %s matrix, output is", Mat_->Meta().TypeString());
  switch (outtype_) {
    case BYATOM:    mprintf(" by atom.\n"); break;
    case BYRESIDUE: mprintf(" averaged by residue.\n"); break;
    case BYMASK:    mprintf(" averaged by mask.\n"); break;
  }
  if (outtype_ != BYATOM) {
    if (useMass_)
      mprintf("\tAverages will be mass-weighted.\n");
    else
      mprintf("\tAverages will not be mass-weighted.\n");
  }
  if (mtype == MetaData::IREDMAT)
    mprintf("\t%u IRED vecs, Order of Legendre polynomials: %i\n",
            IredVectors_.size(), order_);
  else if (mtype == MetaData::DIHCOVAR)
    mprintf("\t%u data sets.\n", DihedralSets_.size());
  if (outfile_ != 0)
    mprintf("\tPrinting to file %s\n", outfile_->DataFilename().full());
  if (byMaskOut_ != 0)
    mprintf("\tAveraged by mask output to %s\n", byMaskOut_->Filename().full());
  mprintf("\tMatrix data set is '%s'\n", Mat_->legend());
  if (matByRes_ != 0)
    mprintf("\tAveraged by residue matrix data set is '%s'\n", matByRes_->legend());
  FrameCounterInfo();
  if (mtype != MetaData::IREDMAT && mtype != MetaData::DIHCOVAR) {
    mprintf("\tMask1 is '%s'\n",mask1_.MaskString());
    if (useMask2_)
      mprintf("\tMask2 is '%s'\n",mask2_.MaskString());
  }
#ifdef NEW_MATRIX_PARA
  mprintf("DEBUG: NEW COVARIANCE MATRIX PARALLELIZATION SCHEME IN USE.\n");
#endif
  return Action::OK;
}