Exemple #1
0
Action::RetType Action_Channel::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  // Keywords.
  DataFile* outfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  dxyz_[0] = actionArgs.getKeyDouble("dx", 0.35);
  dxyz_[1] = actionArgs.getKeyDouble("dy", dxyz_[0]);
  dxyz_[2] = actionArgs.getKeyDouble("dz", dxyz_[1]);
  // solute mask
  std::string sMask = actionArgs.GetMaskNext();
  if (sMask.empty()) {
    mprinterr("Error: No solute mask specified.\n");
    return Action::ERR;
  }
  soluteMask_.SetMaskString( sMask );
  // solvent mask
  sMask = actionArgs.GetMaskNext();
  if (sMask.empty())
    sMask.assign(":WAT@O");
  solventMask_.SetMaskString( sMask );

  // Grid Data Set
  grid_ = init.DSL().AddSet(DataSet::GRID_FLT, actionArgs.GetStringNext(), "Channel");
  if (grid_ == 0) return Action::ERR;
  if (outfile != 0) outfile->AddDataSet( grid_ );

  mprintf("Warning: *** THIS ACTION IS EXPERIMENTAL AND NOT FULLY IMPLEMENTED. ***\n");
  mprintf("    CHANNEL: Solute mask [%s], solvent mask [%s]\n",
          soluteMask_.MaskString(), solventMask_.MaskString());
  mprintf("\tSpacing: XYZ={ %g %g %g }\n", dxyz_[0], dxyz_[1], dxyz_[2]);
  return Action::OK;
}
Exemple #2
0
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;
}
// Action_FilterByData::Init()
Action::RetType Action_FilterByData::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  maxmin_ = init.DSL().AddSet( DataSet::INTEGER, actionArgs.GetStringKey("name"), "Filter" );
  if (maxmin_ == 0) return Action::ERR;
  DataFile* maxminfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  if (maxminfile != 0)
    maxminfile->AddDataSet( maxmin_ );
  // Get min and max args.
  while (actionArgs.Contains("min"))
    Min_.push_back( actionArgs.getKeyDouble("min", 0.0) );
  while (actionArgs.Contains("max"))
    Max_.push_back( actionArgs.getKeyDouble("max", 0.0) );
  if (Min_.empty()) {
    mprinterr("Error: At least one 'min' arg must be specified.\n");
    return Action::ERR;
  }
  if (Max_.empty()) {
    mprinterr("Error: At least one 'max' arg must be specified.\n");
    return Action::ERR;
  }
  if (Min_.size() != Max_.size()) {
    mprinterr("Error: # of 'min' args (%zu) != # of 'max' args (%zu)\n",
              Min_.size(), Max_.size());
    return Action::ERR;
  }
  // Get DataSets from remaining arguments
  Dsets_.AddSetsFromArgs( actionArgs.RemainingArgs(), init.DSL() );

  if (Dsets_.empty()) {
    mprinterr("Error: No data sets specified.\n");
    return Action::ERR;
  }

  if ( Dsets_.size() < Min_.size() ) {
    mprinterr("Error: More 'min'/'max' args (%zu) than data sets (%zu).\n",
              Min_.size(), Dsets_.size());
    return Action::ERR;
  }
  if ( Dsets_.size() > Min_.size() ) {
    unsigned int Nremaining = Dsets_.size() - Min_.size();
    double useMin = Min_.back();
    double useMax = Max_.back();
    mprintf("Warning: More data sets than 'min'/'max' args.\n"
            "Warning:  Using min=%f and max=%f for last %zu data sets.\n",
            useMin, useMax, Nremaining);
    for (unsigned int ds = 0; ds < Nremaining; ++ds) {
      Min_.push_back( useMin );
      Max_.push_back( useMax );
    }
  }

  mprintf("    FILTER: Filtering out frames using %zu data sets.\n", Dsets_.size());
  for (unsigned int ds = 0; ds < Dsets_.size(); ds++)
    mprintf("\t%.4f < '%s' < %.4f\n", Min_[ds], Dsets_[ds]->legend(), Max_[ds]);
  if (maxminfile != 0)
    mprintf("\tFilter frame info will be written to %s\n", maxminfile->DataFilename().full());

  return Action::OK;
}
Exemple #4
0
// Action_Grid::Init()
Action::RetType Action_Grid::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  debug_ = debugIn;
  nframes_ = 0;
  // Get output filename
  std::string filename = actionArgs.GetStringKey("out");
  // Get grid options
  grid_ = GridInit( "GRID", actionArgs, init.DSL() );
  if (grid_ == 0) return Action::ERR;
# ifdef MPI
  if (ParallelGridInit(init.TrajComm(), grid_)) return Action::ERR;
# endif
  // Get extra options
  max_ = actionArgs.getKeyDouble("max", 0.80);
  madura_ = actionArgs.getKeyDouble("madura", 0);
  smooth_ = actionArgs.getKeyDouble("smoothdensity", 0);
  invert_ = actionArgs.hasKey("invert");
  pdbfile_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("pdb"),"Grid PDB",DataFileList::PDB,true);
  density_ = actionArgs.getKeyDouble("density",0.033456);
  if (actionArgs.hasKey("normframe")) normalize_ = TO_FRAME;
  else if (actionArgs.hasKey("normdensity")) normalize_ = TO_DENSITY;
  else normalize_ = NONE;
  if (normalize_ != NONE && (smooth_ > 0.0 || madura_ > 0.0)) {
    mprinterr("Error: Normalize options are not compatible with smoothdensity/madura options.\n");
    init.DSL().RemoveSet( grid_ );
    return Action::ERR;
  }
  // Get mask
  std::string maskexpr = actionArgs.GetMaskNext();
  if (maskexpr.empty()) {
    mprinterr("Error: GRID: No mask specified.\n");
    init.DSL().RemoveSet( grid_ );
    return Action::ERR;
  }
  mask_.SetMaskString(maskexpr);

  // Setup output file
  // For backwards compat., if no 'out' assume next string is filename
  if (filename.empty() && actionArgs.Nargs() > 1 && !actionArgs.Marked(1))
    filename = actionArgs.GetStringNext();
  DataFile* outfile = init.DFL().AddDataFile(filename, actionArgs);
  if (outfile != 0) outfile->AddDataSet((DataSet*)grid_);

  // Info
  mprintf("    GRID:\n");
  GridInfo( *grid_ );
  if (outfile != 0) mprintf("\tGrid will be printed to file %s\n", outfile->DataFilename().full());
  mprintf("\tGrid data set: '%s'\n", grid_->legend());
  mprintf("\tMask expression: [%s]\n",mask_.MaskString());
  if (pdbfile_ != 0)
      mprintf("\tPseudo-PDB will be printed to %s\n", pdbfile_->Filename().full());
  if (normalize_ == TO_FRAME)
    mprintf("\tGrid will be normalized by number of frames.\n");
  else if (normalize_ == TO_DENSITY)
    mprintf("\tGrid will be normalized to a density of %g molecules/Ang^3.\n", density_);
  // TODO: print extra options

  return Action::OK;
}
// Traj_AmberRestartNC::processWriteArgs()
int Traj_AmberRestartNC::processWriteArgs(ArgList& argIn) {
  // For write, assume we want velocities unless specified
  SetVelocity(!argIn.hasKey("novelocity"));
  SetTemperature(argIn.hasKey("remdtraj"));
  time0_ = argIn.getKeyDouble("time0", 1.0);
  dt_ = argIn.getKeyDouble("dt",1.0);
  return 0;
}
// Analysis_Wavelet::Setup
Analysis::RetType Analysis_Wavelet::Setup(ArgList& analyzeArgs, DataSetList* datasetlist,
        TopologyList* PFLin, DataFileList* DFLin, int debugIn)
{
    // Attempt to get COORDS DataSet from DataSetList. If none specified the
    // default COORDS set will be used.
    std::string setname = analyzeArgs.GetStringKey("crdset");
    coords_ = (DataSet_Coords*)datasetlist->FindCoordsSet( setname );
    if (coords_ == 0) {
        mprinterr("Error: Could not locate COORDS set corresponding to %s\n", setname.c_str());
        return Analysis::ERR;
    }
    // Get keywords
    DataFile* outfile = DFLin->AddDataFile( analyzeArgs.GetStringKey("out"), analyzeArgs );
    setname = analyzeArgs.GetStringKey("name");
    // TODO: Check defaults
    nb_ = analyzeArgs.getKeyInt("nb", 0); // FIXME: Should be more descriptive? nscale?
    if (nb_ < 1) {
        mprinterr("Error: Scaling number must be > 0\n");
        return Analysis::ERR;
    }
    S0_ = analyzeArgs.getKeyDouble("s0", 0.2);
    ds_ = analyzeArgs.getKeyDouble("ds", 1.0/3.0);
    correction_ = analyzeArgs.getKeyDouble("correction", 1.01);
    chival_ = analyzeArgs.getKeyDouble("chival", 0.2231);
    // Wavelet type: default to Morlet
    std::string wavelet_name = analyzeArgs.GetStringKey("type");
    if (wavelet_name.empty())
        wavelet_type_ = W_MORLET;
    else {
        wavelet_type_ = W_NONE;
        for (int itoken = 0; itoken != (int)W_NONE; itoken++)
            if (wavelet_name.compare(Tokens_[itoken].key_) == 0) {
                wavelet_type_ = (WaveletType)itoken;
                break;
            }
        if (wavelet_type_ == W_NONE) {
            mprinterr("Error: Unrecognized wavelet type: %s\n", wavelet_name.c_str());
            return Analysis::ERR;
        }
    }
    // Atom mask
    mask_.SetMaskString( analyzeArgs.GetMaskNext() );
    // Set up output data set
    output_ = datasetlist->AddSet( DataSet::MATRIX_FLT, setname, "WAVELET" );
    if (output_ == 0) return Analysis::ERR;
    if (outfile != 0) outfile->AddDataSet( output_ );

    mprintf("    WAVELET: Using COORDS set '%s', wavelet type %s\n",
            coords_->legend(), Tokens_[wavelet_type_].description_);
    mprintf("\tCalculating for atoms in mask '%s'\n", mask_.MaskString());
    mprintf("\tScaling wavelet %i times starting from %g with delta of %g\n",
            nb_, S0_, ds_);
    mprintf("\tCorrection: %g\n", correction_);
    mprintf("\tChiVal:     %g\n", chival_);
    if (outfile != 0) mprintf("\tOutput to '%s'\n", outfile->DataFilename().full());

    return Analysis::OK;
}
// Traj_AmberRestart::processWriteArgs()
int Traj_AmberRestart::processWriteArgs(ArgList& argIn) {
  // For write, assume we want velocities unless specified
  outputVel_ = !argIn.hasKey("novelocity");
  outputTime_ = !argIn.hasKey("notime");
  outputTemp_ = argIn.hasKey("remdtraj");
  time0_ = argIn.getKeyDouble("time0", -1.0);
  dt_ = argIn.getKeyDouble("dt",1.0);
  singleWrite_ = argIn.hasKey("single");
  return 0;
}
Exemple #8
0
// DataIO::ProcessCommonArgs()
int DataIO::ProcessCommonArgs(ArgList &argIn) {
  if (argIn.hasKey("noxcol")) hasXcolumn_ = false;
  if (argIn.hasKey("noemptyframes")) printEmptyFrames_ = false;
  std::string label = argIn.GetStringKey("xlabel");
  if (!label.empty()) x_label_ = label;
  xmin_ = argIn.getKeyDouble("xmin",xmin_);
  xstep_ = argIn.getKeyDouble("xstep",xstep_);
  if (argIn.Contains("time")) {
    xstep_ = argIn.getKeyDouble("time",xstep_);
    xmin_ = 0.0;
    xoffset_ = 1.0;
  }
  return 0;
}  
Exemple #9
0
// DataIO_Std::processWriteArgs()
int DataIO_Std::processWriteArgs(ArgList &argIn) {
  if (!isInverted_ && argIn.hasKey("invert"))
    isInverted_ = true;
  std::string grouparg = argIn.GetStringKey("groupby");
  if (!grouparg.empty()) {
    if (group_ != BY_NAME && grouparg == "name")
      group_ = BY_NAME;
    else if (group_ != BY_ASPECT && grouparg == "aspect")
      group_ = BY_ASPECT;
    else if (group_ != BY_IDX && grouparg == "idx")
      group_ = BY_IDX;
    else if (group_ != BY_ENS && grouparg == "ens")
      group_ = BY_ENS;
    else if (group_ != BY_DIM && grouparg == "dim")
      group_ = BY_DIM;
    else {
      mprintf("Warning: Unrecognized arg for 'groupby' (%s), ignoring.\n", grouparg.c_str());
    }
  }
  if (hasXcolumn_ && argIn.hasKey("noxcol"))
    hasXcolumn_ = false;
  if (writeHeader_ && argIn.hasKey("noheader"))
    writeHeader_ = false;
  if (!square2d_ && argIn.hasKey("square2d"))
    square2d_ = true;
  else if (square2d_ && argIn.hasKey("nosquare2d"))
    square2d_ = false;
  if (!sparse_ && argIn.hasKey("sparse"))
    sparse_ = true;
  else if (sparse_ && argIn.hasKey("nosparse"))
    sparse_ = false;
  if (sparse_)
    cut_ = argIn.getKeyDouble("cut", cut_);
  return 0;
}
Action::RetType Action_Rotate::Init(ArgList& actionArgs, TopologyList* PFL, FrameList* FL,
                          DataSetList* DSL, DataFileList* DFL, int debugIn)
{
  double xrot = actionArgs.getKeyDouble("x",0.0);
  double yrot = actionArgs.getKeyDouble("y",0.0);
  double zrot = actionArgs.getKeyDouble("z",0.0);
  mask_.SetMaskString( actionArgs.GetMaskNext() );

  // Calc rotation matrix
  RotMatrix_.CalcRotationMatrix( xrot * DEGRAD, yrot * DEGRAD, zrot * DEGRAD );

  mprintf("    ROTATE: Rotating atoms in mask %s\n", mask_.MaskString());
  mprintf("\t%f degrees around X, %f degrees around Y, %f degrees around Z\n",
          xrot, yrot, zrot);
  return Action::OK;
};
Exemple #11
0
// Action_Outtraj::Init()
Action::RetType Action_Outtraj::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  // Set up output traj
  outtraj_.SetDebug(debugIn);
  std::string trajfilename = actionArgs.GetStringNext();
  if (trajfilename.empty()) {
    mprinterr("Error: No filename given.\nError: Usage: ");
    Help();
    return Action::ERR;
  }
  associatedParm_ = init.DSL().GetTopology(actionArgs);
  if (associatedParm_ == 0) {
    mprinterr("Error: Could not get associated topology for %s\n",trajfilename.c_str());
    return Action::ERR;
  }
  // If maxmin, get the name of the dataset as well as the max and min values.
  double lastmin = 0.0;
  double lastmax = 0.0;
  while ( actionArgs.Contains("maxmin") ) {
    std::string datasetName = actionArgs.GetStringKey("maxmin");
    if (!datasetName.empty()) {
      DataSet* dset = init.DSL().GetDataSet(datasetName);
      if (dset==0) {
        mprintf("Error: maxmin: Could not get dataset %s\n",datasetName.c_str());
        return Action::ERR;
      } else {
        // Currently only allow int, float, or double datasets
        if (dset->Type() != DataSet::INTEGER &&
            dset->Type() != DataSet::FLOAT &&
            dset->Type() != DataSet::DOUBLE) 
        {
          mprinterr("Error: maxmin: Only int, float, or double dataset (%s) supported.\n",
                  datasetName.c_str());
          return Action::ERR;
        }
        Dsets_.push_back( (DataSet_1D*)dset );
        Max_.push_back( actionArgs.getKeyDouble("max",lastmax) );
        Min_.push_back( actionArgs.getKeyDouble("min",lastmin) );
        lastmax = Max_.back();
        lastmin = Min_.back();
      }
    } else {
      mprinterr("Error: maxmin Usage: maxmin <setname> max <max> min <min>\n");
      return Action::ERR;
    }
  }
  // Initialize output trajectory with remaining arguments
  if ( outtraj_.InitEnsembleTrajWrite(trajfilename, actionArgs.RemainingArgs(), 
                                      TrajectoryFile::UNKNOWN_TRAJ, init.DSL().EnsembleNum()) ) 
    return Action::ERR;
  isSetup_ = false;

  mprintf("    OUTTRAJ: Writing frames associated with topology '%s'\n", associatedParm_->c_str());
  for (unsigned int ds = 0; ds < Dsets_.size(); ++ds)
    mprintf("\tmaxmin: Printing trajectory frames based on %g <= %s <= %g\n",
            Min_[ds], Dsets_[ds]->legend(), Max_[ds]);

  return Action::OK;
} 
// Action_VelocityAutoCorr::Init()
Action::RetType Action_VelocityAutoCorr::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  if (actionArgs.hasKey("usevelocity")) {
    mprinterr("Error: The 'usevelocity' keyword is deprecated. Velocity information\n"
              "Error:   is now used by default if present. To force cpptraj to use\n"
              "Error:   coordinates to estimate velocities (not recommended) use the\n"
              "Error:   'usecoords' keyword.\n");
    return Action::ERR;
  }
  useVelInfo_ = !actionArgs.hasKey("usecoords");
  if (mask_.SetMaskString( actionArgs.GetMaskNext() )) return Action::ERR;
  DataFile* outfile =  init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  diffout_ = init.DFL().AddCpptrajFile( actionArgs.GetStringKey("diffout"),
                                        "VAC diffusion constants", DataFileList::TEXT, true );
  maxLag_ = actionArgs.getKeyInt("maxlag", -1);
  tstep_ = actionArgs.getKeyDouble("tstep", 1.0);
  useFFT_ = !actionArgs.hasKey("direct");
  normalize_ = actionArgs.hasKey("norm");
  // Set up output data set
  VAC_ = init.DSL().AddSet(DataSet::DOUBLE, actionArgs.GetStringNext(), "VAC");
  if (VAC_ == 0) return Action::ERR;
  // TODO: This should just be a scalar
  diffConst_ = init.DSL().AddSet(DataSet::DOUBLE,
                                 MetaData(VAC_->Meta().Name(), "D", MetaData::NOT_TS));
  if (diffConst_ == 0) return Action::ERR;
  if (outfile != 0) outfile->AddDataSet( VAC_ );
# ifdef MPI
  trajComm_ = init.TrajComm(); 
  if (trajComm_.Size() > 1 && !useVelInfo_)
    mprintf("\nWarning: When calculating velocities between consecutive frames,\n"
            "\nWarning:   'velocityautocorr' in parallel will not work correctly if\n"
            "\nWarning:   coordinates have been modified by previous actions (e.g. 'rms').\n\n");
  diffConst_->SetNeedsSync( false );
# endif
  mprintf("    VELOCITYAUTOCORR:\n"
          "\tCalculate velocity auto-correlation function for atoms in mask '%s'\n",
          mask_.MaskString());
  if (useVelInfo_)
    mprintf("\tUsing velocity information present in frames.\n");
  else
    mprintf("\tCalculating velocities between consecutive frames from coordinates.\n");
  if (outfile != 0)
    mprintf("\tOutput velocity autocorrelation function '%s' to '%s'\n", VAC_->legend(), 
            outfile->DataFilename().full());
  mprintf("\tWriting diffusion constants to '%s'\n", diffout_->Filename().full());
  if (maxLag_ < 1)
    mprintf("\tMaximum lag will be half total # of frames");
  else
    mprintf("\tMaximum lag is %i frames", maxLag_);
  mprintf(", time step between frames is %f ps\n", tstep_);
  if (useFFT_)
    mprintf("\tUsing FFT to calculate autocorrelation function.\n");
  else
    mprintf("\tUsing direct method to calculate autocorrelation function.\n");
  if (normalize_)
    mprintf("\tNormalizing autocorrelation function to 1.0\n");
  return Action::OK;
}
// Action_CheckStructure::Init()
Action::RetType Action_CheckStructure::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  // Get Keywords
  std::string around = actionArgs.GetStringKey("around");
  SeparateInit( !(actionArgs.hasKey("noimage")), actionArgs.GetMaskNext(),
                around, actionArgs.GetStringKey("reportfile"),
                actionArgs.getKeyDouble("cut",0.8),
                actionArgs.getKeyDouble("offset",1.15),
                actionArgs.hasKey("silent"), init.DFL() );
  // DoAction-only keywords.
  bondcheck_ = !actionArgs.hasKey("nobondcheck");
  skipBadFrames_ = actionArgs.hasKey("skipbadframes");

  mprintf("    CHECKSTRUCTURE: Checking atoms in mask '%s'",Mask1_.MaskString());
  if (Mask2_.MaskStringSet())
    mprintf(" around mask '%s'", Mask2_.MaskString());
  if (!image_.UseImage())
    mprintf(", imaging off");
  if (outfile_ != 0)
    mprintf(", output to %s", outfile_->Filename().full());
  mprintf(".\n");
  if (!bondcheck_) {
    mprintf("\tChecking inter-atomic distances only.\n");
    mprintf("\tWarnings will be printed for non-bond distances < %.2f Ang.\n", sqrt(nonbondcut2_));
  } else {
    mprintf("\tChecking inter-atomic and bond distances.\n");
    mprintf("\tWarnings will be printed for bond lengths > eq + %.2f Ang\n",
            bondoffset_);
    mprintf("\tand non-bond distances < %.2f Ang.\n", sqrt(nonbondcut2_));
  }
  if (skipBadFrames_)
    mprintf("\tFrames with problems will be skipped.\n");
  if (silent_)
    mprintf("\tWarning messages will be suppressed.\n");
# ifdef _OPENMP
# pragma omp parallel
  {
#   pragma omp master
    {
    mprintf("\tParallelizing calculation with %i threads.\n", omp_get_num_threads());
    }
  }
# endif
  return Action::OK;
}
Exemple #14
0
int Cluster_DPeaks::SetupCluster(ArgList& analyzeArgs) {
  epsilon_ = analyzeArgs.getKeyDouble("epsilon", -1.0);
  if (epsilon_ <= 0.0) {
    mprinterr("Error: DPeaks requires epsilon to be set and > 0.0\n"
              "Error: Use 'epsilon <e>'\n");
    return 1;
  }
  densityCut_ = analyzeArgs.getKeyDouble("densitycut", -1.0);
  distanceCut_ = analyzeArgs.getKeyDouble("distancecut", -1.0);
  calc_noise_ = analyzeArgs.hasKey("noise");
  dvdfile_ = analyzeArgs.GetStringKey("dvdfile");
  rafile_ = analyzeArgs.GetStringKey("runavg");
  radelta_ = analyzeArgs.GetStringKey("deltafile");
  avg_factor_ = analyzeArgs.getKeyInt("avgfactor", -1);
  if (avg_factor_ != -1 && avg_factor_ < 1) {
    mprinterr("Error: avgfactor must be >= 1.\n");
    return 1;
  }
  useGaussianKernel_ = analyzeArgs.hasKey("gauss");
  // Determine how peaks will be chosen. Default is not to choose peaks,
  // just print out density versus distance for manual choice.
  choosePoints_ = PLOT_ONLY;
  std::string choose_keyword = analyzeArgs.GetStringKey("choosepoints");
  if (!choose_keyword.empty()) {
    if      (choose_keyword == "manual") choosePoints_ = MANUAL;
    else if (choose_keyword == "auto"  ) choosePoints_ = AUTOMATIC;
    else {
      mprinterr("Error: Unrecognized choosepoints keyword: %s\n", choose_keyword.c_str());
      return 1;
    }
  }
  if (choosePoints_ == PLOT_ONLY && dvdfile_.empty())
    dvdfile_.assign("DensityVsDistance.dat");
  else if ( choosePoints_ == MANUAL &&
            (distanceCut_ < 0.0 || densityCut_ < 0.0) )
  {
    mprinterr("Error: For choosepoints manual must specify distancecut and densitycut.\n");
    return 1;
  }
  return 0;
}
Exemple #15
0
int AssociatedData_NOE::NOE_Args(ArgList& argIn) {
  l_bound_ = argIn.getKeyDouble("bound", 0.0);
  u_bound_ = argIn.getKeyDouble("bound", 0.0);
  rexp_ = argIn.getKeyDouble("rexp", -1.0);
  if (argIn.hasKey("noe_weak")) {
    l_bound_ = 3.5;
    u_bound_ = 5.0;
  } else if (argIn.hasKey("noe_medium")) {
    l_bound_ = 2.9;
    u_bound_ = 3.5;
  } else if (argIn.hasKey("noe_strong")) {
    l_bound_ = 1.8;
    u_bound_ = 2.9;
  }
  if (u_bound_ <= l_bound_) {
    mprinterr("Error: noe lower bound (%g) must be less than upper bound (%g).\n",
              l_bound_, u_bound_);
    return 1;
  }
  return 0;
}
Exemple #16
0
/** Expect lowest replica file name to be passed in. 'remdtraj' should have
  * already been parsed out of input arguments.
  */
int Trajin_Multi::SetupTrajRead(FileName const& tnameIn, ArgList& argIn, Topology *tparmIn)
{
    // Set file name and topology pointer.
    if (SetTraj().SetNameAndParm(tnameIn, tparmIn)) return 1;
    REMDtraj_.ClearIOarray();
    // Check for deprecated args
    if (argIn.hasKey("remdout")) {
        mprinterr("%s", TrajIOarray::DEPRECATED_remdout);
        return 1;
    }
    // Process REMD-specific arguments
    if (argIn.Contains("remdtrajidx")) {
        // Looking for specific indices
        ArgList indicesArg(argIn.GetStringKey("remdtrajidx"), ",");
        if (indicesArg.empty()) {
            mprinterr("Error: remdtrajidx expects comma-separated list of target indices in each\n"
                      "Error: dimension, '<dim1 idx>,<dim2 idx>,...,<dimN idx>'. Indices start\n"
                      "Error: from 1.\n");
            return 1;
        }
        for (ArgList::const_iterator arg = indicesArg.begin(); // TODO: validInteger?
                arg != indicesArg.end(); ++arg)
            remdtrajidx_.push_back( convertToInteger( *arg ) );
        targetType_ = ReplicaInfo::INDICES;
    } else if (argIn.Contains("remdtrajtemp")) {
        // Looking for target temperature
        remdtrajtemp_ = argIn.getKeyDouble("remdtrajtemp",0.0);
        targetType_ = ReplicaInfo::TEMP;
    }
    // Set up replica file names.
    if (REMDtraj_.SetupReplicaFilenames( tnameIn, argIn )) return 1;

    // Set up TrajectoryIO classes for all file names.
    if (REMDtraj_.SetupIOarray(argIn, SetTraj().Counter(), cInfo_, Traj().Parm())) return 1;

    // Check that replica dimension valid for desired indices.
    if (targetType_ == ReplicaInfo::INDICES &&
            cInfo_.ReplicaDimensions().Ndims() != (int)remdtrajidx_.size())
    {
        mprinterr("Error: Replica # of dim (%i) not equal to target # dim (%zu)\n",
                  cInfo_.ReplicaDimensions().Ndims(), remdtrajidx_.size());
        return 1;
    }

    // If target type is temperature make sure there is temperature info.
    if (targetType_ == ReplicaInfo::TEMP && !cInfo_.HasTemp()) {
        mprinterr("Error: Some or all replicas are missing temperature info.\n");
        return 1;
    }

    return 0;
}
// Action_RandomizeIons::Init()
Action::RetType Action_RandomizeIons::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  debug_ = debugIn;
  // Get first mask
  std::string ionmask = actionArgs.GetMaskNext();
  if (ionmask.empty()) {
    mprinterr("Error: randomizeions: No mask for ions specified.\n");
    return Action::ERR;
  }
  ions_.SetMaskString( ionmask );

  // Get Keywords
  image_.InitImaging( !actionArgs.hasKey("noimage") );
  int seed = actionArgs.getKeyInt("seed", -1);
  overlap_ = actionArgs.getKeyDouble("overlap", 3.5);
  min_ = actionArgs.getKeyDouble("by", 3.5);
  // Pre-square overlap and min
  overlap_ *= overlap_;
  min_ *= min_;
  // If no around mask specified, leave blank
  std::string aroundmask = actionArgs.GetStringKey("around");
  if (!aroundmask.empty())
    around_.SetMaskString( aroundmask );
  
  // INFO
  mprintf("    RANDOMIZEIONS: Swapping postions of ions in mask '%s' with solvent.\n",
          ions_.MaskString());
  mprintf("\tNo ion can get closer than %.2f angstroms to another ion.\n", sqrt( overlap_ ));
  if (around_.MaskStringSet())
    mprintf("\tNo ion can get closer than %.2f angstroms to atoms in mask '%s'\n",
            sqrt( min_ ), around_.MaskString());
  if (!image_.UseImage())
    mprintf("\tImaging of the coordinates will not be performed.\n");
  if (seed > 0)
    mprintf("\tRandom number generator seed is %i\n", seed);
  RN_.rn_set( seed );

  return Action::OK;
}
Exemple #18
0
// ParmFile::ReadTopology()
int ParmFile::ReadTopology(Topology& Top, FileName const& fnameIn, 
                           ArgList const& argListIn, int debugIn) 
{
  if (fnameIn.empty()) {
    mprinterr("Error: No input topology name given.\n");
    return 1;
  }
  if (!File::Exists( fnameIn )) {
    mprinterr("Error: Topology '%s' does not exist.\n", fnameIn.full());
    return 1;
  }
  parmName_ = fnameIn;
  ArgList argIn = argListIn;
  ParmFormatType pfType;
  ParmIO* parmio = 0;
  Top.SetDebug( debugIn );
  // Only force bond search when 'bondsearch' is specified.
  bool bondsearch = false;
  if (argIn.Contains("bondsearch")) {
    Top.SetOffset( argIn.getKeyDouble("bondsearch", -1.0) );
    bondsearch = true;
  }
  // 'as' keyword specifies a format
  std::string as_arg = argIn.GetStringKey("as");
  if (!as_arg.empty()) {
    pfType = (ParmFormatType)FileTypes::GetFormatFromString( PF_KeyArray, as_arg, UNKNOWN_PARM );
    if (pfType == UNKNOWN_PARM) {
      mprinterr("Error: Topology format '%s' not recognized.\n", as_arg.c_str());
      return 1;
    }
    parmio = (ParmIO*)FileTypes::AllocIO( PF_AllocArray, pfType, false );
  } else
    parmio = DetectFormat( parmName_, pfType );
  if (parmio == 0) {
    mprinterr("Error: Could not determine format of topology '%s'\n", parmName_.full());
    return 1;
  }
  mprintf("\tReading '%s' as %s\n", parmName_.full(),
          FileTypes::FormatDescription(PF_AllocArray, pfType) );
  parmio->SetDebug( debugIn );
  if (parmio->processReadArgs(argIn)) return 1;
  int err = parmio->ReadParm( parmName_.Full(), Top);
  // Perform setup common to all parm files.
  if (err == 0) 
    err = Top.CommonSetup(bondsearch || parmio->NeedsBondSearch());
  else
    mprinterr("Error reading topology file '%s'\n", parmName_.full());
  delete parmio;
  if (err > 0) return 1;
  return 0;
}
// Action_AtomicCorr::Init()
Action::RetType Action_AtomicCorr::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  debug_ = debugIn;
  outfile_ = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  cut_ = actionArgs.getKeyDouble("cut", 0.0);
  if (cut_ < 0.0 || cut_ > 1.0) {
    mprinterr("Error: cut value must be between 0 and 1.\n");
    return Action::ERR;
  }
  min_ = actionArgs.getKeyInt("min",0);
  if (actionArgs.hasKey("byatom"))
    acorr_mode_ = ATOM;
  else if (actionArgs.hasKey("byres"))
    acorr_mode_ = RES;
  mask_.SetMaskString( actionArgs.GetMaskNext() );
  
  // Set up DataSet
  dset_ = init.DSL().AddSet( DataSet::MATRIX_FLT, actionArgs.GetStringNext(), "ACorr" );
  if (dset_ == 0) {
    mprinterr("Error: Could not allocate output data set.\n");
    return Action::ERR;
  }
  // Add DataSet to output file
  if (outfile_ != 0) outfile_->AddDataSet( dset_ );

  mprintf("    ATOMICCORR: Correlation of %s motions will be calculated for\n",
          ModeString[acorr_mode_]);
  mprintf("\tatoms in mask [%s]", mask_.MaskString());
  if (outfile_ != 0) mprintf(", output to file %s", outfile_->DataFilename().full());
  mprintf("\n\tData saved in set '%s'\n", dset_->legend());
  if (cut_ != 0)
    mprintf("\tOnly correlations greater than %.2f or less than -%.2f will be printed.\n",
            cut_,cut_);
  if (min_!=0)
    mprintf("\tOnly correlations for %ss > %i apart will be calculated.\n",
            ModeString[acorr_mode_],min_);
# ifdef MPI
  trajComm_ = init.TrajComm();
  if (trajComm_.Size() > 1)
    mprintf("\nWarning: 'atomiccorr' in parallel will not work correctly if coordinates have\n"
              "Warning:   been modified by previous actions (e.g. 'rms').\n\n");
  // Since matrix calc only happens in Print(), no sync needed.
  dset_->SetNeedsSync( false );
# endif
  return Action::OK;
}
// Action_VelocityAutoCorr::Init()
Action::RetType Action_VelocityAutoCorr::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  useVelInfo_ = actionArgs.hasKey("usevelocity");
  mask_.SetMaskString( actionArgs.GetMaskNext() );
  DataFile* outfile =  init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  maxLag_ = actionArgs.getKeyInt("maxlag", -1);
  tstep_ = actionArgs.getKeyDouble("tstep", 1.0);
  useFFT_ = !actionArgs.hasKey("direct");
  normalize_ = actionArgs.hasKey("norm");
  // Set up output data set
  VAC_ = init.DSL().AddSet(DataSet::DOUBLE, actionArgs.GetStringNext(), "VAC");
  if (VAC_ == 0) return Action::ERR;
  if (outfile != 0) outfile->AddDataSet( VAC_ );
# ifdef MPI
  trajComm_ = init.TrajComm(); 
  if (trajComm_.Size() > 1 && !useVelInfo_)
    mprintf("\nWarning: When calculating velocities between consecutive frames,\n"
            "\nWarning:   'velocityautocorr' in parallel will not work correctly if\n"
            "\nWarning:   coordinates have been modified by previous actions (e.g. 'rms').\n\n");
# endif
  mprintf("    VELOCITYAUTOCORR:\n"
          "\tCalculate velocity auto-correlation function for atoms in mask '%s'\n",
          mask_.MaskString());
  if (useVelInfo_)
    mprintf("\tUsing velocity information present in frames.\n");
  else
    mprintf("\tCalculating velocities between consecutive frames.\n");
  if (outfile != 0)
    mprintf("\tOutput data set '%s' to '%s'\n", VAC_->legend(), 
            outfile->DataFilename().full());
  if (maxLag_ < 1)
    mprintf("\tMaximum lag will be half total # of frames");
  else
    mprintf("\tMaximum lag is %i frames", maxLag_);
  mprintf(", time step is %f ps\n", tstep_);
  if (useFFT_)
    mprintf("\tUsing FFT to calculate autocorrelation function.\n");
  else
    mprintf("\tUsing direct method to calculate autocorrelation function.\n");
  if (normalize_)
    mprintf("\tNormalizing autocorrelation function to 1.0\n");
  return Action::OK;
}
// Action_GridFreeEnergy::init()
Action::RetType Action_GridFreeEnergy::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  // Get output filename
  DataFile* outfile = init.DFL().AddDataFile(actionArgs.GetStringNext(), actionArgs);
  if (outfile == 0) {
    mprinterr("Error: GridFreeEnergy: no output filename specified.\n");
    return Action::ERR;
  }
  // Get grid options (<nx> <dx> <ny> <dy> <nz> <dz> [box|origin] [negative])
  grid_ = GridInit( "GridFreeEnergy", actionArgs, init.DSL() );
  if (grid_ == 0) return Action::ERR;
# ifdef MPI
  if (ParallelGridInit(init.TrajComm(), grid_)) return Action::ERR;
# endif
  //grid_.PrintXplor( filename_, "", "REMARKS Change in Free energy from bulk solvent with bin normalisation of " + integerToString(currentLargestVoxelOccupancyCount) );

  // Get mask
  std::string maskexpr = actionArgs.GetMaskNext();
  if (maskexpr.empty()) {
    mprinterr("Error: GridFreeEnergy: No mask specified.\n");
    init.DSL().RemoveSet( grid_ );
    return Action::ERR;
  }
  mask_.SetMaskString(maskexpr);

  // Get extra args
  tempInKevin_ = actionArgs.getKeyDouble("temp", 293.0);
  outfile->AddDataSet( grid_ );

  // Info
  mprintf("Warning: DNAIONTRACKER is experimental code!\n");
  mprintf("    GridFreeEnergy\n");
  GridInfo( *grid_ );
  mprintf("\tGrid will be printed to file %s\n",outfile->DataFilename().full());
  mprintf("\tMask expression: [%s]\n",mask_.MaskString());
  mprintf("\tTemp is : %f K\n",tempInKevin_);

  // Allocate grid
  //if (GridAllocate()) return 1;

  return Action::OK;
}
Exemple #22
0
// Analysis_FFT::Setup()
Analysis::RetType Analysis_FFT::Setup(ArgList& analyzeArgs, DataSetList* datasetlist, DataFileList* DFLin, int debugIn)
{
  std::string setname = analyzeArgs.GetStringKey("name");
  DataFile* outfile = DFLin->AddDataFile(analyzeArgs.GetStringKey("out"), analyzeArgs);
  dt_ = analyzeArgs.getKeyDouble("dt",1.0);
  // Select datasets from remaining args
  if (input_dsets_.AddSetsFromArgs( analyzeArgs.RemainingArgs(), *datasetlist )) {
    mprinterr("Error: Could not add data sets.\n");
    return Analysis::ERR;
  }
  if (input_dsets_.empty()) {
    mprinterr("Error: No input data sets.\n");
    return Analysis::ERR;
  }
  // If setname is empty generate a default name
  if (setname.empty())
    setname = datasetlist->GenerateDefaultName( "FFT" );
  // Setup output datasets.
  int idx = 0;
  if ( input_dsets_.size() == 1 )
    idx = -1; // Only one input set, no need to refer to it by index
  for ( Array1D::const_iterator DS = input_dsets_.begin(); 
                                DS != input_dsets_.end(); ++DS) 
  {
    DataSet* dsout = datasetlist->AddSet( DataSet::DOUBLE, MetaData(setname, idx++) );
    if (dsout==0) return Analysis::ERR;
    dsout->SetLegend( (*DS)->Meta().Legend() );
    output_dsets_.push_back( (DataSet_1D*)dsout );
    if (outfile != 0) outfile->AddDataSet( dsout );
  }

  mprintf("    FFT: Calculating FFT for %u data sets.\n", input_dsets_.size());
  mprintf("\tTime step: %f\n", dt_);
  if ( !setname.empty() )
    mprintf("\tSet name: %s\n", setname.c_str() );
  if ( outfile != 0 )
    mprintf("\tOutfile name: %s\n", outfile->DataFilename().base());

  return Analysis::OK;
}
Exemple #23
0
// Action_AtomicCorr::Init()
Action::RetType Action_AtomicCorr::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  debug_ = debugIn;
  outfile_ = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  cut_ = actionArgs.getKeyDouble("cut", 0.0);
  if (cut_ < 0.0 || cut_ > 1.0) {
    mprinterr("Error: cut value must be between 0 and 1.\n");
    return Action::ERR;
  }
  min_ = actionArgs.getKeyInt("min",0);
  if (actionArgs.hasKey("byatom"))
    acorr_mode_ = ATOM;
  else if (actionArgs.hasKey("byres"))
    acorr_mode_ = RES;
  mask_.SetMaskString( actionArgs.GetMaskNext() );
  
  // Set up DataSet
  dset_ = init.DSL().AddSet( DataSet::MATRIX_FLT, actionArgs.GetStringNext(), "ACorr" );
  if (dset_ == 0) {
    mprinterr("Error: Could not allocate output data set.\n");
    return Action::ERR;
  }
  // Add DataSet to output file
  if (outfile_ != 0) outfile_->AddDataSet( dset_ );

  mprintf("    ATOMICCORR: Correlation of %s motions will be calculated for\n",
          ModeString[acorr_mode_]);
  mprintf("\tatoms in mask [%s]", mask_.MaskString());
  if (outfile_ != 0) mprintf(", output to file %s", outfile_->DataFilename().full());
  mprintf("\n\tData saved in set '%s'\n", dset_->legend());
  if (cut_ != 0)
    mprintf("\tOnly correlations greater than %.2f or less than -%.2f will be printed.\n",
            cut_,cut_);
  if (min_!=0)
    mprintf("\tOnly correlations for %ss > %i apart will be calculated.\n",
            ModeString[acorr_mode_],min_);

  return Action::OK;
}
Exemple #24
0
int Cluster_DBSCAN::SetupCluster(ArgList& analyzeArgs) {
  kdist_.SetRange(analyzeArgs.GetStringKey("kdist"));
  if (kdist_.Empty()) {
    minPoints_ = analyzeArgs.getKeyInt("minpoints", -1);
    if (minPoints_ < 1) {
      mprinterr("Error: DBSCAN requires minimum # of points to be set and >= 1\n"
                "Error: Use 'minpoints <N>'\n");
      return 1;
    }
    epsilon_ = analyzeArgs.getKeyDouble("epsilon", -1.0);
    if (epsilon_ <= 0.0) {
      mprinterr("Error: DBSCAN requires epsilon to be set and > 0.0\n"
                "Error: Use 'epsilon <e>'\n");
      return 1;
    }
    sieveToCentroid_ = !analyzeArgs.hasKey("sievetoframe");
  } else {
    k_prefix_ = analyzeArgs.GetStringKey("kfile");
    if (!k_prefix_.empty() && k_prefix_.at(k_prefix_.size()-1) != '/')
      k_prefix_ += '/';
  }
  return 0;
}
Exemple #25
0
/** Set up histogram with specified data sets. */
Analysis::RetType Analysis_Hist::Setup(ArgList& analyzeArgs, AnalysisSetup& setup, int debugIn)
{
  debug_ = debugIn;
  // Keywords
  std::string histname = analyzeArgs.GetStringKey("name");
  outfilename_ = analyzeArgs.GetStringKey("out");
  if (outfilename_.empty()) {
    mprinterr("Error: Hist: No output filename specified.\n");
    return Analysis::ERR;
  }
  traj3dName_ = analyzeArgs.GetStringKey("traj3d");
  traj3dFmt_ = TrajectoryFile::WriteFormatFromString( analyzeArgs.GetStringKey("trajfmt"),
                                                      TrajectoryFile::AMBERTRAJ );
  parmoutName_ = analyzeArgs.GetStringKey("parmout");
  // Create a DataFile here so any DataFile arguments can be processed. If it
  // turns out later that native output is needed the DataFile will be removed.
  outfile_ = setup.DFL().AddDataFile(outfilename_, analyzeArgs);
  if (outfile_==0) return Analysis::ERR;
  Temp_ = analyzeArgs.getKeyDouble("free",-1.0);
  if (Temp_!=-1.0) 
    calcFreeE_ = true;
  else
    calcFreeE_ = false;
  gnuplot_ = analyzeArgs.hasKey("gnu");
  if (analyzeArgs.hasKey("norm"))
    normalize_ = NORM_SUM;
  else if (analyzeArgs.hasKey("normint"))
    normalize_ = NORM_INT;
  else
    normalize_ = NO_NORM;
  circular_ = analyzeArgs.hasKey("circular");
  nativeOut_ = analyzeArgs.hasKey("nativeout");
  if ( analyzeArgs.Contains("min") ) {
    default_min_ = analyzeArgs.getKeyDouble("min", 0.0);
    minArgSet_ = true;
  }
  if ( analyzeArgs.Contains("max") ) {
    default_max_ = analyzeArgs.getKeyDouble("max", 0.0);
    maxArgSet_ = true;
  }
  default_step_ = analyzeArgs.getKeyDouble("step", 0.0) ;
  default_bins_ = analyzeArgs.getKeyInt("bins", -1);
  calcAMD_ = false;
  std::string amdname = analyzeArgs.GetStringKey("amd");
  if (!amdname.empty()) {
    DataSet* ds = setup.DSL().GetDataSet( amdname );
    if (ds == 0) {
      mprinterr("Error: AMD data set %s not found.\n", amdname.c_str());
      return Analysis::ERR;
    }
    if (ds->Ndim() != 1) {
      mprinterr("Error: AMD data set must be 1D.\n");
      return Analysis::ERR;
    }
    amddata_ = (DataSet_1D*)ds;
    calcAMD_ = true;
  }

  // Treat all remaining arguments as dataset names. Do not set up dimensions
  // yet since the data sets may not be fully populated.
  ArgList dsetNames = analyzeArgs.RemainingArgs();
  for ( ArgList::const_iterator setname = dsetNames.begin(); 
                                setname != dsetNames.end(); ++setname)
  { 
    if (CheckDimension( *setname, setup.DSL() )) return Analysis::ERR;
  }
  // histdata contains the DataSets to be histogrammed
  if (histdata_.empty()) {
    mprinterr("Error: Hist: No datasets specified.\n");
    return Analysis::ERR;
  }
  // Total # of dimensions for the histogram is the number of sets to be binned.
  N_dimensions_ = histdata_.size();
  if (!nativeOut_) {
    switch ( N_dimensions_ ) {
      case 1: hist_ = setup.DSL().AddSet( DataSet::DOUBLE,     histname, "Hist"); break;
      case 2: hist_ = setup.DSL().AddSet( DataSet::MATRIX_DBL, histname, "Hist"); break;
      // TODO: GRID_DBL
      case 3: hist_ = setup.DSL().AddSet( DataSet::GRID_FLT,   histname, "Hist"); break;
      default: // FIXME: GET N DIMENSION CASE!
        mprintf("Warning: Histogram dimension > 3. DataSet/DataFile output not supported.\n");
        nativeOut_ = true;
    }
  }
  // traj3d only supported with 3D histograms
  if (!traj3dName_.empty() && N_dimensions_ != 3) {
    mprintf("Warning: 'traj3d' only supported with 3D histograms.\n");
    traj3dName_.clear();
    parmoutName_.clear();
  }
  if (!nativeOut_) {
    // DataFile output. Add DataSet to DataFile.
    if (hist_ == 0) {
      mprinterr("Error: Could not set up histogram data set.\n");
      return Analysis::ERR;
    }
    outfile_->AddDataSet( hist_ );
  } else {
    // Native output. Remove DataFile from DataFileList
    outfile_ = setup.DFL().RemoveDataFile( outfile_ );
    native_ = setup.DFL().AddCpptrajFile( outfilename_, "Histogram output" );
    if (native_ == 0) return Analysis::ERR; 
  }

  mprintf("\tHist: %s: Set up for %zu dimensions using the following datasets:\n", 
          outfilename_.c_str(), N_dimensions_);
  mprintf("\t[ ");
  for (std::vector<DataSet_1D*>::iterator ds=histdata_.begin(); ds!=histdata_.end(); ++ds)
    mprintf("%s ",(*ds)->legend());
  mprintf("]\n");
  if (calcAMD_)
    mprintf("\tPopulating bins using AMD boost from data set %s\n", 
            amddata_->legend());
  if (calcFreeE_)
    mprintf("\tFree energy in kcal/mol will be calculated from bin populations at %f K.\n",Temp_);
  if (nativeOut_)
    mprintf("\tUsing internal routine for output. Data will not be stored on the data set list.\n");
  //if (circular_ || gnuplot_) {
  //  mprintf("\tWarning: gnuplot and/or circular specified; advanced grace/gnuplot\n");
  //  mprintf("\t         formatting disabled.\n");*/
    if (circular_)
      mprintf("\tcircular: Output coordinates will be wrapped.\n");
    if (gnuplot_ && outfile_ == 0)
      mprintf("\tgnuplot: Output will be in gnuplot-readable format.\n");
  //}
  if (normalize_ == NORM_SUM)
    mprintf("\tnorm: Sum over bins will be normalized to 1.0.\n");
  else if (normalize_ == NORM_INT)
    mprintf("\tnormint: Integral over bins will be normalized to 1.0.\n");
  if (!traj3dName_.empty()) {
    mprintf("\tPseudo-trajectory will be written to '%s' with format %s\n",
            traj3dName_.c_str(), TrajectoryFile::FormatString(traj3dFmt_));
    if (!parmoutName_.empty())
      mprintf("\tCorresponding pseudo-topology will be written to '%s'\n",
              parmoutName_.c_str());
  }

  return Analysis::OK;
}
Exemple #26
0
// Action_Radial::Init()
Action::RetType Action_Radial::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  debug_ = debugIn;
  // Get Keywords
  image_.InitImaging( !(actionArgs.hasKey("noimage")) );
  std::string outfilename = actionArgs.GetStringKey("out");
  // Default particle density (mols/Ang^3) for water based on 1.0 g/mL
  density_ = actionArgs.getKeyDouble("density",0.033456);
  if (actionArgs.hasKey("center1"))
    rmode_ = CENTER1;
  else if (actionArgs.hasKey("center2"))
    rmode_ = CENTER2;
  else if (actionArgs.hasKey("nointramol"))
    rmode_ = NO_INTRAMOL;
  else
    rmode_ = NORMAL;
  useVolume_ = actionArgs.hasKey("volume");
  DataFile* intrdfFile = init.DFL().AddDataFile(actionArgs.GetStringKey("intrdf"));
  DataFile* rawrdfFile = init.DFL().AddDataFile(actionArgs.GetStringKey("rawrdf"));
  spacing_ = actionArgs.getNextDouble(-1.0);
  if (spacing_ < 0) {
    mprinterr("Error: Radial: No spacing argument or arg < 0.\n");
    Help();
    return Action::ERR;
  }
  double maximum = actionArgs.getNextDouble(-1.0);
  if (maximum < 0) {
    mprinterr("Error: Radial: No maximum argument or arg < 0.\n");
    Help();
    return Action::ERR;
  }
  // Store max^2, distances^2 greater than max^2 do not need to be
  // binned and therefore do not need a sqrt calc.
  maximum2_ = maximum * maximum;

  // Get First Mask
  std::string mask1 = actionArgs.GetMaskNext();
  if (mask1.empty()) {
    mprinterr("Error: Radial: No mask given.\n");
    return Action::ERR;
  }
  Mask1_.SetMaskString(mask1);

  // Check for second mask - if none specified use first mask
  std::string mask2 = actionArgs.GetMaskNext();
  if (!mask2.empty()) 
    Mask2_.SetMaskString(mask2);
  else
    Mask2_.SetMaskString(mask1);
  // If filename not yet specified check for backwards compat.
  if (outfilename.empty() && actionArgs.Nargs() > 1 && !actionArgs.Marked(1))
    outfilename = actionArgs.GetStringNext();

  // Set up output dataset. 
  Dset_ = init.DSL().AddSet( DataSet::DOUBLE, actionArgs.GetStringNext(), "g(r)");
  if (Dset_ == 0) return RDF_ERR("Could not allocate RDF data set.");
  DataFile* outfile = init.DFL().AddDataFile(outfilename, actionArgs);
  if (outfile != 0) outfile->AddDataSet( Dset_ );
  // Make default precision a little higher than normal
  Dset_->SetupFormat().SetFormatWidthPrecision(12,6);
  // Set DataSet legend from mask strings.
  Dset_->SetLegend(Mask1_.MaskExpression() + " => " + Mask2_.MaskExpression());
  // TODO: Set Yaxis label in DataFile
  // Calculate number of bins
  one_over_spacing_ = 1 / spacing_;
  double temp_numbins = maximum * one_over_spacing_;
  temp_numbins = ceil(temp_numbins);
  numBins_ = (int) temp_numbins;
  // Setup output datafile. Align on bin centers instead of left.
  // TODO: Use Rdim for binning?
  Dimension Rdim( spacing_ / 2.0, spacing_, "Distance (Ang)" ); 
  Dset_->SetDim(Dimension::X, Rdim);
  // Set up output for integral of mask2 if specified.
  if (intrdfFile != 0) {
    intrdf_ = init.DSL().AddSet( DataSet::DOUBLE, MetaData(Dset_->Meta().Name(), "int" ));
    if (intrdf_ == 0) return RDF_ERR("Could not allocate RDF integral data set.");
    intrdf_->SetupFormat().SetFormatWidthPrecision(12,6);
    intrdf_->SetLegend("Int[" + Mask2_.MaskExpression() + "]");
    intrdf_->SetDim(Dimension::X, Rdim);
    intrdfFile->AddDataSet( intrdf_ );
  } else
    intrdf_ = 0;
  // Set up output for raw rdf
  if (rawrdfFile != 0) {
    rawrdf_ = init.DSL().AddSet( DataSet::DOUBLE, MetaData(Dset_->Meta().Name(), "raw" ));
    if (rawrdf_ == 0) return RDF_ERR("Could not allocate raw RDF data set.");
    rawrdf_->SetupFormat().SetFormatWidthPrecision(12,6);
    rawrdf_->SetLegend("Raw[" + Dset_->Meta().Legend() + "]");
    rawrdf_->SetDim(Dimension::X, Rdim);
    rawrdfFile->AddDataSet( rawrdf_ );
  } else
    rawrdf_ = 0;

  // Set up histogram
  RDF_ = new int[ numBins_ ];
  std::fill(RDF_, RDF_ + numBins_, 0);
# ifdef _OPENMP
  // Since RDF is shared by all threads and we cant guarantee that a given
  // bin in RDF wont be accessed at the same time by the same thread,
  // each thread needs its own bin space.
#pragma omp parallel
{
  if (omp_get_thread_num()==0)
    numthreads_ = omp_get_num_threads();
}
  rdf_thread_ = new int*[ numthreads_ ];
  for (int i=0; i < numthreads_; i++) {
    rdf_thread_[i] = new int[ numBins_ ];
    std::fill(rdf_thread_[i], rdf_thread_[i] + numBins_, 0);
  }
# endif
  
  mprintf("    RADIAL: Calculating RDF for atoms in mask [%s]",Mask1_.MaskString());
  if (!mask2.empty()) 
    mprintf(" to atoms in mask [%s]",Mask2_.MaskString());
  mprintf("\n");
  if (outfile != 0)
    mprintf("            Output to %s.\n", outfile->DataFilename().full());
  if (intrdf_ != 0)
    mprintf("            Integral of mask2 atoms will be output to %s\n",
            intrdfFile->DataFilename().full());
  if (rawrdf_ != 0)
    mprintf("            Raw RDF bin values will be output to %s\n",
            rawrdfFile->DataFilename().full());
  if (rmode_==CENTER1)
    mprintf("            Using center of atoms in mask1.\n");
  else if (rmode_==CENTER2)
    mprintf("            Using center of atoms in mask2.\n");
  mprintf("            Histogram max %f, spacing %f, bins %i.\n",maximum,
          spacing_,numBins_);
  if (useVolume_)
    mprintf("            Normalizing based on cell volume.\n");
  else
    mprintf("            Normalizing using particle density of %f molecules/Ang^3.\n",density_);
  if (!image_.UseImage()) 
    mprintf("            Imaging disabled.\n");
  if (numthreads_ > 1)
    mprintf("            Parallelizing RDF calculation with %i threads.\n",numthreads_);

  return Action::OK;
}
Exemple #27
0
// Action_Contacts::Init()
Action::RetType Action_Contacts::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{

  byResidue_ = actionArgs.hasKey("byresidue");
  double dist = actionArgs.getKeyDouble("distance", 7.0);
  dt_ = actionArgs.getKeyDouble("time", 1.0);
  // Square the cutoff
  distance_ = dist * dist;
  first_ = actionArgs.hasKey("first");
  // Get reference
  ReferenceFrame REF = init.DSL().GetReferenceFrame( actionArgs );
  if (REF.error()) return Action::ERR;
  std::string outfilename = actionArgs.GetStringKey("out"); 
  outfile_ = init.DFL().AddCpptrajFile(outfilename, "Contacts", DataFileList::TEXT, true);
  if (outfile_ == 0) return Action::ERR;
  if (byResidue_) {
    if (outfilename.empty()) {
      mprinterr("Error: Contacts 'byresidue' requires output filename.\n");
      return Action::ERR;
    }
    outfile2_ = init.DFL().AddCpptrajFile(outfilename + ".native", "Contacts by residue");
    if (outfile2_ == 0) return Action::ERR;
  }

  // Get Mask
  std::string mask0 = actionArgs.GetMaskNext();
  if (mask0.empty() && byResidue_)
    Mask_.SetMaskString("@CA");
  else
    Mask_.SetMaskString( mask0 );
  
  // Initialize reference. If no reference mask is given mask0 will be used.
  // First arg 'nofit' set to true, no fitting with contacts. Allows last arg
  // 'RefTrans' to be null.
  //if (RefInit(true, false, Mask_.MaskString(), actionArgs, FL, PFL, 0)!=0)
  //  return 1;
  if (!first_ && REF.empty()) {
    mprintf("\tNo reference structure specified. Defaulting to first.\n");
    first_ = true;
  }

  if (!first_) {
    // TODO: Convert FrameList to return frame reference?
    // Set up atom mask for reference frame
    if (REF.Parm().SetupIntegerMask(Mask_, REF.Coord())) return Action::ERR;
    // Set up reference contacts 
    SetupContacts(REF.Coord(), REF.Parm());
  }

  // Output file header - only if not byresidue
  if (!byResidue_) {
    outfile_->Printf("#time\tContacts\tnative Contacts ");
    if (!first_)
      outfile_->Printf("(number of natives: %zu)", nativecontacts_.size());
    outfile_->Printf("\n");
  }

  mprintf("    CONTACTS: [%s] Calculating current contacts and comparing results to",
          Mask_.MaskString());
  if (first_)
    mprintf(" first frame.\n");
  else
    mprintf(" reference structure.\n");
  mprintf("\tDistance cutoff is %g angstroms.\n", dist);
  mprintf("\tWriting results to %s\n", outfile_->Filename().full());
  if (byResidue_)
    mprintf("\tResults are output on a per-residue basis to %s.\n", outfile2_->Filename().full());

  return Action::OK;
}
Action::RetType Action_DNAionTracker::Init(ArgList& actionArgs, TopologyList* PFL, DataSetList* DSL, DataFileList* DFL, int debugIn)
{
  // Get keywords
  DataFile* outfile = DFL->AddDataFile(actionArgs.GetStringKey("out"), actionArgs);
  poffset_ = actionArgs.getKeyDouble("poffset", 5.0);
  InitImaging( !actionArgs.hasKey("noimage") );
  if (actionArgs.hasKey("shortest"))
    bintype_ = SHORTEST;
  else if (actionArgs.hasKey("counttopcone"))
    bintype_ = TOPCONE;
  else if (actionArgs.hasKey("countbottomcone"))
    bintype_ = BOTTOMCONE;
  else if (actionArgs.hasKey("count"))
    bintype_ = COUNT;

  // Get masks - 4 must be specified
  std::string m1 = actionArgs.GetMaskNext();
  std::string m2 = actionArgs.GetMaskNext();
  std::string m3 = actionArgs.GetMaskNext();
  std::string m4 = actionArgs.GetMaskNext();
  if (m1.empty() || m2.empty() || m3.empty() || m4.empty()) {
    mprinterr("Error: dnaiontracker requires 4 masks.\n");
    return Action::ERR;
  }
  p1_.SetMaskString(m1);
  p2_.SetMaskString(m2);
  base_.SetMaskString(m3);
  ions_.SetMaskString(m4);

  // Add dataset to dataset list (and datafile list if filename specified)
  distance_ = DSL->AddSet(DataSet::DOUBLE, MetaData(actionArgs.GetStringNext(),
                                                    MetaData::M_DISTANCE), "DNAion");
  if (distance_==0) return Action::ERR;
  if (outfile != 0)
    outfile->AddDataSet( distance_ );

  // INFO
  mprintf("    DNAIONTRACKER: Data representing the ");
  switch (bintype_) {
    case COUNT : 
      mprintf("count within the cone will be\n"); break;
    case SHORTEST: 
      mprintf("shortest distance to a phosphate or base centroid will be\n"); break;
    case TOPCONE: 
      mprintf("count in the top half of the cone (and sort-of bound) will be\n"); break;
    case BOTTOMCONE: 
      mprintf("count in the bottom half of the cone will be\n"); break;
  }
  mprintf("      saved to array named %s\n", distance_->legend());
  mprintf("      Perpendicular offset for cone is %5.2f angstroms\n", poffset_);
  if (!UseImage())
    mprintf("      Imaging has been disabled\n");
  mprintf("\tPhosphate1 Mask [%s]\n", p1_.MaskString());
  mprintf("\tPhosphate2 Mask [%s]\n", p2_.MaskString());
  mprintf("\tBase Mask       [%s]\n", base_.MaskString());
  mprintf("\tIons Mask       [%s]\n", ions_.MaskString());
  if (outfile != 0)
    mprintf("\tData will be printed to a file named %s\n", outfile->DataFilename().full());

  return Action::OK;
}
Exemple #29
0
Analysis::RetType Analysis_Spline::Setup(ArgList& analyzeArgs, DataSetList* datasetlist, DataFileList* DFLin, int debugIn)
{
  std::string setname = analyzeArgs.GetStringKey("name");
  outfile_ = DFLin->AddDataFile(analyzeArgs.GetStringKey("out"), analyzeArgs);
  meshsize_ = analyzeArgs.getKeyInt("meshsize", 0);
  meshfactor_ = -1.0;
  if (meshsize_ < 3) {
    meshfactor_ = analyzeArgs.getKeyDouble("meshfactor", -1.0);
    if (meshfactor_ < Constants::SMALL) {
      mprinterr("Error: Either meshsize must be specified and > 2, or meshfactor must be\n"
                "Error:   specified and > 0.0\n");
      return Analysis::ERR;
    }
  }
  if (analyzeArgs.Contains("meshmin")) {
    meshmin_ = analyzeArgs.getKeyDouble("meshmin", 0.0);
    useDefaultMin_ = true;
  } else
    useDefaultMin_ = false;
  if (analyzeArgs.Contains("meshmax")) {
    meshmax_ = analyzeArgs.getKeyDouble("meshmax", -1.0);
    useDefaultMax_ = true;
  } else
    useDefaultMax_ = false;
  if (useDefaultMin_ && useDefaultMax_ && meshmax_ < meshmin_) {
    mprinterr("Error: meshmax must be > meshmin\n");
    return Analysis::ERR;
  }
  // Select datasets from remaining args
  if (input_dsets_.AddSetsFromArgs( analyzeArgs.RemainingArgs(), *datasetlist )) {
    mprinterr("Error: Could not add data sets.\n");
    return Analysis::ERR;
  }
  if (input_dsets_.empty()) {
    mprinterr("Error: No input data sets.\n");
    return Analysis::ERR;
  }

  // Set up output datasets
  Dimension Xdim( meshmin_, (meshmax_ - meshmin_) / (double)meshsize_ );
  for (Array1D::const_iterator dsIn = input_dsets_.begin();
                               dsIn != input_dsets_.end(); ++dsIn)
  {
    DataSet* ds = datasetlist->AddSet(DataSet::XYMESH, setname, "Spline");
    if (ds == 0) return Analysis::ERR;
    ds->SetLegend( "Spline(" + (*dsIn)->Meta().Legend() + ")" );
    // TODO: Set individually based on input_dsets_
    ds->SetDim(Dimension::X, Xdim);
    if (outfile_ != 0) outfile_->AddDataSet( ds );
    output_dsets_.push_back( (DataSet_Mesh*)ds );
  }

  mprintf("    SPLINE: Applying cubic splining to %u data sets\n", input_dsets_.size());
  if (meshfactor_ < 0)
    mprintf("\tMesh size= %i\n", meshsize_);
  else
    mprintf("\tMesh size will be input set size multiplied by %f\n", meshfactor_);
  if (useDefaultMin_)
    mprintf("\tMesh min= %f,", meshmin_);
  else
    mprintf("\tMesh min will be input set min,");
  if (useDefaultMax_)
    mprintf(" Mesh max= %f\n", meshmax_);
  else
    mprintf(" Mesh max will be input set max.\n");
  if (outfile_ != 0) {
    if (!setname.empty())
      mprintf("\tOutput set name: %s\n", setname.c_str());
    mprintf("\tOutfile name: %s\n", outfile_->DataFilename().base());
  }
  //for (Array1D::const_iterator set = input_dsets_.begin(); set != input_dsets_.end(); ++set)
  //  mprintf("\t%s\n", (*set)->legend());
  return Analysis::OK;
}
Exemple #30
0
// -----------------------------------------------------------------------------
// Action_NMRrst::Init()
Action::RetType Action_NMRrst::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
# ifdef MPI
  if (init.TrajComm().Size() > 1) {
    mprinterr("Error: 'nmrrst' action does not work with > 1 thread (%i threads currently).\n",
              init.TrajComm().Size());
    return Action::ERR;
  }
# endif
  debug_ = debugIn;
  // Get Keywords
  Image_.InitImaging( !(actionArgs.hasKey("noimage")) );
  useMass_ = !(actionArgs.hasKey("geom"));
  findNOEs_ = actionArgs.hasKey("findnoes");
  findOutput_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("findout"), "Found NOEs",
                                    DataFileList::TEXT, true);
  specOutput_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("specout"), "Specified NOEs",
                                    DataFileList::TEXT, true);
  if (findOutput_ == 0 || specOutput_ == 0) return Action::ERR;
  resOffset_ = actionArgs.getKeyInt("resoffset", 0);
  DataFile* outfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  max_cut_ = actionArgs.getKeyDouble("cut", 6.0);
  strong_cut_ = actionArgs.getKeyDouble("strongcut", 2.9);
  medium_cut_ = actionArgs.getKeyDouble("mediumcut", 3.5);
  weak_cut_ = actionArgs.getKeyDouble("weakcut", 5.0);
  series_ = actionArgs.hasKey("series");
  std::string rstfilename = actionArgs.GetStringKey("file");
  viewrst_ = actionArgs.GetStringKey("viewrst");
  setname_ = actionArgs.GetStringKey("name");
  if (setname_.empty())
    setname_ = init.DSL().GenerateDefaultName("NMR");
  nframes_ = 0;

  // Atom Mask
  Mask_.SetMaskString( actionArgs.GetMaskNext() );

  // Pairs specified on command line.
  std::string pair1 = actionArgs.GetStringKey("pair");
  while (!pair1.empty()) {
    std::string pair2 = actionArgs.GetStringNext();
    if (pair2.empty()) {
      mprinterr("Error: Only one mask specified for pair (%s)\n", pair1.c_str());
      return Action::ERR;
    }
    Pairs_.push_back( MaskPairType(AtomMask(pair1), AtomMask(pair2)) );
    pair1 = actionArgs.GetStringKey("pair");
  }

  // Check that something will be done
  if (!findNOEs_ && rstfilename.empty() && Pairs_.empty()) {
    mprinterr("Error: Must specify restraint file, 'pair', and/or 'findnoes'.\n");
    return Action::ERR;
  }

  // Read in NMR restraints.
  if (!rstfilename.empty()) {
    if (ReadNmrRestraints( rstfilename )) return Action::ERR;
  }

  // Set up distances.
  int num_noe = 1;
  for (noeDataArray::iterator noe = NOEs_.begin(); noe != NOEs_.end(); ++noe, ++num_noe) {
    // Translate any ambiguous atom names
    TranslateAmbiguous( noe->aName1_ ); 
    TranslateAmbiguous( noe->aName2_ );
    // Create mask expressions from resnum/atom name
    noe->dMask1_.SetMaskString( MaskExpression( noe->resNum1_, noe->aName1_ ) ); 
    noe->dMask2_.SetMaskString( MaskExpression( noe->resNum2_, noe->aName2_ ) ); 
    // Dataset to store distances
    AssociatedData_NOE noeData(noe->bound_, noe->boundh_, noe->rexp_);
    MetaData md(setname_, "NOE", num_noe);
    md.SetLegend( noe->dMask1_.MaskExpression() + " and " + noe->dMask2_.MaskExpression());
    md.SetScalarMode( MetaData::M_DISTANCE );
    md.SetScalarType( MetaData::NOE );
    noe->dist_ = init.DSL().AddSet(DataSet::DOUBLE, md);
    if (noe->dist_==0) return Action::ERR;
    noe->dist_->AssociateData( &noeData );
    // Add dataset to data file
    if (outfile != 0) outfile->AddDataSet( noe->dist_ );
  }

  masterDSL_ = init.DslPtr();
 
  mprintf("Warning: *** THIS ACTION IS EXPERIMENTAL. ***\n");
  mprintf("    NMRRST: %zu NOEs from NMR restraint file.\n", NOEs_.size());
  mprintf("\tShifting residue numbers in restraint file by %i\n", resOffset_);
  // DEBUG - print NOEs
  for (noeDataArray::const_iterator noe = NOEs_.begin(); noe != NOEs_.end(); ++noe)
    mprintf("\t'%s'  %f < %f < %f\n", noe->dist_->legend(),
            noe->bound_, noe->rexp_, noe->boundh_);
  if (findNOEs_) {
    mprintf("\tSearching for potential NOEs. Max cutoff is %g Ang.\n", max_cut_);
    mprintf("\tNOE distance criteria (Ang.): S= %g, M= %g, W= %g\n",
            strong_cut_, medium_cut_, weak_cut_);
    if (series_)
      mprintf("\tDistance data for NOEs less than cutoff will be saved as '%s[foundNOE]'.\n",
              setname_.c_str());
    mprintf("\tFound NOEs will be written to '%s'\n", findOutput_->Filename().full());
  }
  if (!Pairs_.empty()) {
    mprintf("\tSpecified NOE pairs:\n");
    for (MaskPairArray::const_iterator mp = Pairs_.begin(); mp != Pairs_.end(); ++mp)
      mprintf("\t\t[%s] to [%s]\n", mp->first.MaskString(), mp->second.MaskString());
    mprintf("\tSpecified NOE data will be written to '%s'\n", specOutput_->Filename().full());
  }
  if (!Image_.UseImage()) 
    mprintf("\tNon-imaged");
  else
    mprintf("\tImaged");
  if (useMass_) 
    mprintf(", center of mass.\n");
  else
    mprintf(", geometric center.\n");
  if (!viewrst_.empty())
    mprintf("\tTopologies corresponding to found NOEs will be written to '%s'\n", viewrst_.c_str());

  return Action::OK;
}