コード例 #1
0
ファイル: TrajinList.cpp プロジェクト: SAMAN-64/cpptraj
int TrajinList::AddTrajin(std::string const& fname, Topology* topIn, ArgList const& argIn)
{
  if (topIn == 0) {
    mprinterr("Error: No topology for input trajectory '%s'\n", fname.c_str());
    return 1;
  }
  // CRDIDXARG
  finalCrdIndicesArg_.clear();
  ArgList trajin_args = argIn;
  bool isRemdtraj = trajin_args.hasKey("remdtraj");
  int err = 0;
  File::NameArray fnames = File::ExpandToFilenames( fname );
  if (fnames.empty()) return 1;
  Trajin* traj = 0;
  for (File::NameArray::const_iterator fn = fnames.begin(); fn != fnames.end(); ++fn) {
    ArgList args = trajin_args;
    if (isRemdtraj)
      traj = new Trajin_Multi();
    else
      traj = new Trajin_Single();
    if (traj == 0) {
      mprinterr("Error: Memory allocation for input trajectory failed.\n");
      return 1;
    }
    traj->SetDebug(debug_);
    if ( traj->SetupTrajRead(*fn, args, topIn) ) {
      mprinterr("Error: Could not set up input trajectory '%s'.\n", fn->full());
      delete traj;
      err++;
      continue;
    }
    // Add to trajin list and update # of frames.
    trajin_.push_back( traj );
    UpdateMaxFrames( traj->Traj() );
  }
  if (err > 0) return 1;
  // FIXME: For backwards compat. overwrite Topology box info with traj box info.
  topIn->SetBoxFromTraj( trajin_.back()->TrajCoordInfo().TrajBox() );
  return 0;
}
コード例 #2
0
ファイル: Exec_ReadData.cpp プロジェクト: Amber-MD/cpptraj
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;
}
コード例 #3
0
ファイル: TrajinList.cpp プロジェクト: SAMAN-64/cpptraj
// TrajinList::AddEnsembleIn()
int TrajinList::AddEnsembleIn(std::string const& fname, Topology* topIn, ArgList const& argIn)
{
  if (topIn == 0) {
    mprinterr("Error: No topology for input ensemble '%s'\n", fname.c_str());
    return 1;
  }
  int err = 0;
  File::NameArray fnames = File::ExpandToFilenames( fname );
  if (fnames.empty()) return 1;
  TrajectoryFile::TrajFormatType trajinFmt;
  TrajectoryIO* tio = 0;
  for (File::NameArray::const_iterator fn = fnames.begin(); fn != fnames.end(); ++fn) {
    ArgList args = argIn;
    // Determine whether this file is multiple file or single file ensemble.
    tio = TrajectoryFile::DetectFormat( *fn, trajinFmt );
    if (tio == 0) {
      mprinterr("Error: Could not determine trajectory %s format\n", fn->full());
      err++;
      continue;
    }
    EnsembleIn* ensemble = 0;
#   ifdef ENABLE_SINGLE_ENSEMBLE
    if (tio->CanProcessEnsemble())
      ensemble = new EnsembleIn_Single();
    else
#   endif
      ensemble = new EnsembleIn_Multi();
    if (ensemble == 0) {
      mprinterr("Error: Memory allocation for input ensemble failed.\n");
      delete tio;
      return 1;
    }
    ensemble->SetDebug( debug_ );
    // CRDIDXARG: Append coordinate indices arg if there is one
    args.AddArg( finalCrdIndicesArg_ );
    if ( ensemble->SetupEnsembleRead(*fn, args, topIn) ) {
      mprinterr("Error: Could not set up input ensemble '%s'.\n", fname.c_str());
      delete ensemble;
      delete tio;
      err++;
      continue;
    }
    // Currently all input ensembles must be same size.
    if (ensembleSize_ == -1)
      ensembleSize_ = ensemble->EnsembleCoordInfo().EnsembleSize();
    else if (ensembleSize_ != ensemble->EnsembleCoordInfo().EnsembleSize()) {
      mprinterr("Error: Ensemble size (%i) does not match first ensemble size (%i).\n",
                ensemble->EnsembleCoordInfo().EnsembleSize(), ensembleSize_);
      return 1;
    }
    // CRDIDXARG: If trajectory is REMD ensemble and sorting by CRDIDX, need to
    //            save final CRDIDX for next ensemble command.
    // TODO: This is very clunky - remlog dataset should contain all exchanges
    //       so trajin doesnt have to worry about it.
#   ifdef ENABLE_SINGLE_ENSEMBLE
    if ( !tio->CanProcessEnsemble() ) {
#   endif
      EnsembleIn_Multi const& mTraj = static_cast<EnsembleIn_Multi const&>( *ensemble );
      if ( mTraj.TargetMode() == ReplicaInfo::CRDIDX ) {
        finalCrdIndicesArg_ = mTraj.FinalCrdIndices();
        if (finalCrdIndicesArg_.empty()) {
          mprinterr("Error: Could not obtain final remlog indices.\n");
          delete ensemble;
          delete tio;
          err++;
          continue;
        }
        //mprintf("DEBUG: Final crd indices arg: %s\n", finalCrdIndicesArg_.c_str());
      }
#   ifdef ENABLE_SINGLE_ENSEMBLE
    } else
      mprintf("Warning: Single ensemble cannot process crdidx.\n");
#   endif
    // Add to ensemble list and update # of frames.
    ensemble_.push_back( ensemble );
    UpdateMaxFrames( ensemble->Traj() );
    delete tio;
  }
  if (err > 0) return 1;
  // FIXME: For backwards compat. overwrite Topology box info with traj box info.
  topIn->SetBoxFromTraj( ensemble_.back()->EnsembleCoordInfo().TrajBox() );
  return 0;
}
コード例 #4
0
ファイル: TrajIOarray.cpp プロジェクト: SAMAN-64/cpptraj
/** Loop over all filenames in replica_filenames, set up TrajectoryIO. */
int TrajIOarray::SetupIOarray(ArgList& argIn, TrajFrameCounter& counter,
                              CoordinateInfo& cInfo, Topology* trajParm)
{
  // Sanity check
  if (!IOarray_.empty()) {
    mprinterr("Internal Error: SetupIOarray() has been called twice.\n");
    return 1;
  }
  // Save arguments that have not been processed so they can be passed
  // to each replica in turn. Only the lowest replica will use argIn.
  ArgList argCopy( argIn );
  bool lowestRep = true;
  int rep0Frames = TrajectoryIO::TRAJIN_UNK;  // Total frames in replica 0
  int totalFrames = TrajectoryIO::TRAJIN_UNK; // Total # frames to be read from ensemble
  TrajectoryFile::TrajFormatType lastRepFmt = TrajectoryFile::UNKNOWN_TRAJ;
  // Right now enforce that all replicas have the same metadata as lowest
  // replica, e.g. if replica 0 has temperature, replica 1 does too etc.
  for (File::NameArray::const_iterator repfile = replica_filenames_.begin();
                                       repfile != replica_filenames_.end(); ++repfile)
  {
    // Detect format
    TrajectoryFile::TrajFormatType repformat = TrajectoryFile::UNKNOWN_TRAJ;
    TrajectoryIO* replica0 = TrajectoryFile::DetectFormat( *repfile, repformat );
    if ( replica0 == 0 ) {
      mprinterr("Error: Could not set up replica file %s\n", repfile->full());
      return 1;
    }
    if (repformat != lastRepFmt)
      mprintf("\tReading '%s' as %s\n", repfile->full(), TrajectoryFile::FormatString(repformat));
    lastRepFmt = repformat;
    replica0->SetDebug( debug_ );
    // Pushing replica0 here allows the destructor to handle it on errors
    IOarray_.push_back( replica0 );
    // Process format-specific read args. Do not exit on error in case
    // replicas have different formats supporting different args.
    if (lowestRep) {
      replica0->processReadArgs( argIn );
    } else {
      ArgList argtmp( argCopy );
      replica0->processReadArgs( argtmp );
    }
    // Set up replica for reading and get the number of frames.
    int nframes = replica0->setupTrajin( *repfile, trajParm );
    if (nframes == TrajectoryIO::TRAJIN_ERR) {
      mprinterr("Error: Could not set up %s for reading.\n", repfile->full());
      return 1;
    }
    // TODO: Do not allow unknown number of frames?
    if (lowestRep) {
      cInfo = replica0->CoordInfo();
      rep0Frames = nframes;
      totalFrames = nframes;
      if (cInfo.ReplicaDimensions().Ndims() > 0) {
        mprintf("\tReplica dimensions:\n");
        for (int rd = 0; rd < cInfo.ReplicaDimensions().Ndims(); rd++)
          mprintf("\t\t%i: %s\n", rd+1, cInfo.ReplicaDimensions().Description(rd));
      }
    } else {
      // Check total frames in this replica against lowest rep.
      if (nframes != rep0Frames)
        mprintf("Warning: Replica %s frames (%i) does not match # frames in first replica (%i).\n",
                repfile->base(), nframes, rep0Frames);
      //if (repframes < 0) {
      //  mprinterr("Error: RemdTraj: Unknown # of frames in replica.\n");
      //  return 1;
      //}
      if (nframes < totalFrames) {
        totalFrames = nframes; 
        mprintf("Warning: Setting total # of frames to read from replica ensemble to %i\n",
                totalFrames);
      }
      // Check box info against lowest rep.
      if ( replica0->CoordInfo().HasBox() != cInfo.HasBox() ) {
        mprinterr("Error: Replica %s box info does not match first replica.\n",
                  repfile->full());
        return 1;
      }
      // TODO: Check specific box type
      // Check velocity info against lowest rep.
      if ( replica0->CoordInfo().HasVel() != cInfo.HasVel() ) {
        mprinterr("Error: Replica %s velocity info does not match first replica.\n",
                  repfile->full());
        return 1;
      }
      // Check # dimensions and types against lowest rep
      if ( replica0->CoordInfo().ReplicaDimensions() != cInfo.ReplicaDimensions() ) {
        mprinterr("Error: Replica %s dimension info does not match first replica.\n",
                  repfile->full());
        ReplicaDimArray const& thisRepDims = replica0->CoordInfo().ReplicaDimensions();
        for (int rd = 0; rd < thisRepDims.Ndims(); rd++)
          mprinterr("\t\t%i: %s\n", rd+1, thisRepDims.Description(rd)); 
        return 1;
      }
      // If temperature/time info does not match set to false.
      if (cInfo.HasTemp() != replica0->CoordInfo().HasTemp())
        cInfo.SetTemperature( false );
      if (cInfo.HasTime() != replica0->CoordInfo().HasTime())
        cInfo.SetTime( false );
    }
    lowestRep = false;
  }
  // Check how many frames will actually be read
  if (counter.CheckFrameArgs( totalFrames, argIn )) return 1;
  // Check for errors.
  if (IOarray_.empty()) {
    mprinterr("Error: No replica trajectories set up.\n");
    return 1;
  }
  if (IOarray_.size() != replica_filenames_.size()) { // SANITY CHECK
    mprinterr("Error: Not all replica files were set up.\n");
    return 1;
  }
  // Update ensemble size
  cInfo.SetEnsembleSize( (int)IOarray_.size() );
  if (debug_ > 0)
    cInfo.PrintCoordInfo( replica_filenames_[0].full(), trajParm->c_str() );

  return 0;
}