Ejemplo n.º 1
0
/* * Open the netcdf file, read all dimension and variable IDs, close.
  * Return the number of frames in the file. 
  */
int Traj_AmberNetcdf::setupTrajin(std::string const& fname, Topology* trajParm)
{
  filename_.SetFileNameWithExpansion( fname );
  if (openTrajin()) return TRAJIN_ERR;

  // Sanity check - Make sure this is a Netcdf trajectory
  if ( GetNetcdfConventions() != NC_AMBERTRAJ ) {
    mprinterr("Error: Netcdf file %s conventions do not include \"AMBER\"\n",filename_.base());
    return TRAJIN_ERR;
  }
  // Get global attributes
  std::string attrText = GetAttrText("ConventionVersion");
  if ( attrText != "1.0") 
    mprintf("Warning: Netcdf file %s has ConventionVersion that is not 1.0 (%s)\n",
            filename_.base(), attrText.c_str());
  // Get title
  SetTitle( GetAttrText("title") );
  // Get Frame info
  if ( SetupFrame()!=0 ) return TRAJIN_ERR;
  // Setup Coordinates/Velocities
  if ( SetupCoordsVelo()!=0 ) return TRAJIN_ERR;
  SetVelocity( HasVelocities() );
  // Check that specified number of atoms matches expected number.
  if (Ncatom() != trajParm->Natom()) {
    mprinterr("Error: Number of atoms in NetCDF file %s (%i) does not\n",
              filename_.base(),Ncatom());
    mprinterr("       match number in associated parmtop (%i)!\n",trajParm->Natom());
    return TRAJIN_ERR;
  }
  // Setup Time
  if ( SetupTime()!=0 ) return TRAJIN_ERR;
  // Box info
  double boxcrd[6];
  if (SetupBox(boxcrd, NC_AMBERTRAJ) == 1) // 1 indicates an error
    return TRAJIN_ERR;
  SetBox( boxcrd );
  // Replica Temperatures - Allowed to fail silently
  if (SetupTemperature() == 0)
    SetTemperature( true );
  // Replica Dimensions
  if ( SetupMultiD() == -1 ) return TRAJIN_ERR;
  // NOTE: TO BE ADDED
  // labelDID;
  //int cell_spatialDID, cell_angularDID;
  //int spatialVID, cell_spatialVID, cell_angularVID;
  // Amber Netcdf coords are float. Allocate a float array for converting
  // float to/from double.
  if (Coord_ != 0) delete[] Coord_;
  Coord_ = new float[ Ncatom3() ];
  if (Veloc_ != 0) delete[] Veloc_;
  if (velocityVID_ != -1) 
    Veloc_ = new float[ Ncatom3() ];
  else
    Veloc_ = 0;
  if (debug_>1) NetcdfDebug();
  closeTraj();
  // NetCDF files are always seekable
  SetSeekable( true );
  return Ncframe();
}
Ejemplo n.º 2
0
/* * Open the netcdf file, read all dimension and variable IDs, close.
  * Return the number of frames in the file. 
  */
int Traj_AmberNetcdf::setupTrajin(FileName const& fname, Topology* trajParm)
{
  filename_ = fname;
  if (openTrajin()) return TRAJIN_ERR;
  readAccess_ = true;
  // Sanity check - Make sure this is a Netcdf trajectory
  if ( GetNetcdfConventions() != NC_AMBERTRAJ ) {
    mprinterr("Error: Netcdf file %s conventions do not include \"AMBER\"\n",filename_.base());
    return TRAJIN_ERR;
  }
  // Get global attributes
  std::string attrText = GetAttrText("ConventionVersion");
  if ( attrText != "1.0") 
    mprintf("Warning: Netcdf file %s has ConventionVersion that is not 1.0 (%s)\n",
            filename_.base(), attrText.c_str());
  // Get title
  SetTitle( GetAttrText("title") );
  // Get Frame info
  if ( SetupFrameDim()!=0 ) return TRAJIN_ERR;
  if ( Ncframe() < 1 ) {
    mprinterr("Error: Netcdf file is empty.\n");
    return TRAJIN_ERR;
  }
  // Setup Coordinates/Velocities
  if ( SetupCoordsVelo( useVelAsCoords_ )!=0 ) return TRAJIN_ERR;
  // Check that specified number of atoms matches expected number.
  if (Ncatom() != trajParm->Natom()) {
    mprinterr("Error: Number of atoms in NetCDF file %s (%i) does not\n"
              "Error:   match number in associated parmtop (%i)!\n", 
              filename_.base(), Ncatom(), trajParm->Natom());
    return TRAJIN_ERR;
  }
  // Setup Time - FIXME: Allowed to fail silently
  SetupTime();
  // Box info
  double boxcrd[6];
  if (SetupBox(boxcrd, NC_AMBERTRAJ) == 1) // 1 indicates an error
    return TRAJIN_ERR;
  // Replica Temperatures - FIXME: Allowed to fail silently
  SetupTemperature();
  // Replica Dimensions
  ReplicaDimArray remdDim;
  if ( SetupMultiD(remdDim) == -1 ) return TRAJIN_ERR;
  // Set traj info: FIXME - no forces yet
  SetCoordInfo( CoordinateInfo(remdDim, Box(boxcrd), HasVelocities(),
                               HasTemperatures(), HasTimes(), false) ); 
  // NOTE: TO BE ADDED
  // labelDID;
  //int cell_spatialDID, cell_angularDID;
  //int spatialVID, cell_spatialVID, cell_angularVID;
  // Amber Netcdf coords are float. Allocate a float array for converting
  // float to/from double.
  if (Coord_ != 0) delete[] Coord_;
  Coord_ = new float[ Ncatom3() ];
  if (debug_>1) NetcdfDebug();
  closeTraj();
  return Ncframe();
}
Ejemplo n.º 3
0
/** Prepare trajectory for reading. Determine number of frames. */
int Traj_GmxTrX::setupTrajin(FileName const& fname, Topology* trajParm)
{
    int nframes = 0;
    if (file_.SetupRead( fname, debug_ )) return TRAJIN_ERR;
    // Open and read in header
    if ( file_.OpenFile() ) return TRAJIN_ERR;
    ReadTrxHeader();
    if (debug_ > 0) GmxInfo(); // DEBUG
    // Warn if # atoms in parm does not match
    if (trajParm->Natom() != natoms_) {
        mprinterr("Error: # atoms in TRX file (%i) does not match # atoms in parm %s (%i)\n",
                  natoms_, trajParm->c_str(), trajParm->Natom());
        return TRAJIN_ERR;
    }
    // If float precision, create temp array. Temp array not needed for double reads.
    if (precision_ == sizeof(float)) {
        if (farray_ != 0) delete[] farray_;
        farray_ = new float[ natom3_ ];
    }
    // Attempt to determine # of frames in traj
    headerBytes_ = (size_t)file_.Tell();
    frameSize_ = headerBytes_ + (size_t)box_size_ + (size_t)vir_size_ + (size_t)pres_size_ +
                 (size_t)x_size_   + (size_t)v_size_ +   (size_t)f_size_;
    //(size_t)ir_size_ + (size_t)e_size_ + (size_t)top_size_ +
    //(size_t)sym_size_;
    size_t file_size = (size_t)file_.UncompressedSize();
    if (file_size > 0) {
        nframes = (int)(file_size / frameSize_);
        if ( (file_size % frameSize_) != 0 ) {
            mprintf("Warning: %s: Number of frames in TRX file could not be accurately determined.\n"
                    "Warning:   Will attempt to read %i frames.\n", file_.Filename().base(), nframes);
        }
    } else {
        mprintf("Warning: Uncompressed size could not be determined. This is normal for\n");
        mprintf("Warning: bzip2 files. Cannot check # of frames. Frames will be read until EOF.\n");
        nframes = TRAJIN_UNK;
    }
    // Load box info so that it can be checked.
    double box[6];
    box[0]=0.0;
    box[1]=0.0;
    box[2]=0.0;
    box[3]=0.0;
    box[4]=0.0;
    box[5]=0.0;
    if ( box_size_ > 0 ) {
        if ( ReadBox( box ) ) return TRAJIN_ERR;
    }
    // Set traj info - No time or temperature
    SetCoordInfo( CoordinateInfo(Box(box), (v_size_ > 0), false, false) );
    closeTraj();
    return nframes;
}
Ejemplo n.º 4
0
/** Set up netcdf restart file for reading, get all variable and dimension IDs. 
  * Also check number of atoms against associated parmtop.
  */
int Traj_AmberRestartNC::setupTrajin(std::string const& fname, Topology* trajParm)
{
  filename_.SetFileNameWithExpansion( fname );
  if (openTrajin()) return TRAJIN_ERR;
  // Sanity check - Make sure this is a Netcdf restart
  if ( GetNetcdfConventions() != NC_AMBERRESTART ) {
    mprinterr("Error: Netcdf restart file %s conventions do not include \"AMBERRESTART\"\n",
              filename_.base());
    return TRAJIN_ERR;
  }
  // Get global attributes
  std::string attrText = GetAttrText("ConventionVersion");
  if (attrText!="1.0")
    mprintf("Warning: Netcdf restart file %s has ConventionVersion that is not 1.0 (%s)\n",
            filename_.base(), attrText.c_str());
  // Get title
  SetTitle( GetAttrText("title") );
  // Setup Coordinates/Velocities
  if ( SetupCoordsVelo()!=0 ) return TRAJIN_ERR;
  SetVelocity( HasVelocities() );
  // Check that specified number of atoms matches expected number.
  if (Ncatom() != trajParm->Natom()) {
    mprinterr("Error: Number of atoms in NetCDF restart file %s (%i) does not\n",
              filename_.base(), Ncatom());
    mprinterr("       match number in associated parmtop (%i)!\n",trajParm->Natom());
    return TRAJIN_ERR;
  }
  // Setup Time
  if ( SetupTime()!=0 ) return TRAJIN_ERR;
  // Box info
  double boxcrd[6];
  if (SetupBox(boxcrd, NC_AMBERRESTART) == 1) // 1 indicates an error
    return TRAJIN_ERR;
  SetBox( boxcrd );
  // Replica Temperatures - allowed to fail silently 
  if (SetupTemperature() == 0)
    SetTemperature( true );
  if ( SetupMultiD() == -1 ) return TRAJIN_ERR;
  // NOTE: TO BE ADDED
  // labelDID;
  //int cell_spatialDID, cell_angularDID;
  //int spatialVID, cell_spatialVID, cell_angularVID;
  closeTraj();
  // Only 1 frame for NC restarts
  return 1;
}
Ejemplo n.º 5
0
void Traj_GmxTrX::parallelCloseTraj() {
    closeTraj();
}
Ejemplo n.º 6
0
// Traj_AmberRestartNC::writeFrame() 
int Traj_AmberRestartNC::writeFrame(int set, double *X, double *V,double *box, double T) {
  // Set up file for this set
  bool V_present = (HasV() && V != 0);
  std::string fname;
  // Create filename for this set
  // If just writing 1 frame dont modify output filename
  if (singleWrite_)
    fname = filename_.Full();
  else
    fname = NumberFilename(filename_.Full(), set+1);
  if ( NC_create( fname.c_str(), NC_AMBERRESTART, Ncatom(), V_present,
                  HasBox(), HasT(), (time0_ >= 0), Title() ) )
    return 1;
  // write coords
  start_[0] = 0;
  start_[1] = 0;
  count_[0] = Ncatom(); 
  count_[1] = 3;
  if (checkNCerr(nc_put_vara_double(ncid_,coordVID_,start_,count_,X)) ) {
    mprinterr("Error: Netcdf restart Writing coordinates %i\n",set);
    return 1;
  }
  // write velocity
  if (V_present) {
    mprintf("DEBUG: Writing V, VID=%i\n",velocityVID_);
    if (checkNCerr(nc_put_vara_double(ncid_,velocityVID_,start_,count_,V)) ) {
      mprinterr("Error: Netcdf restart writing velocity %i\n",set);
      return 1;
    }
  }
  // write box
  if (cellLengthVID_ != -1) {
    count_[0] = 3;
    count_[1] = 0;
    if (checkNCerr(nc_put_vara_double(ncid_,cellLengthVID_,start_,count_,box)) ) {
      mprinterr("Error: Writing cell lengths.\n");
      return 1;
    }
    if (checkNCerr(nc_put_vara_double(ncid_,cellAngleVID_,start_,count_, box+3)) ) {
      mprinterr("Error: Writing cell angles.\n");
      return 1;
    }
  }
  // write time
  if (timeVID_ != -1) {
    restartTime_ = (time0_ + (double)set) * dt_;
    if (checkNCerr(nc_put_var_double(ncid_,timeVID_,&restartTime_)) ) {
      mprinterr("Error: Writing restart time.\n");
      return 1;
    }
  }
  // write temperature
  if (TempVID_ != -1) {
    if (checkNCerr(nc_put_var_double(ncid_,TempVID_,&T)) ) {
      mprinterr("Error: Writing restart temperature.\n"); 
      return 1;
    }
  }
  //nc_sync(ncid_); // Necessary? File about to close anyway... 
  // Close file for this set
  closeTraj();
  return 0;
}  
Ejemplo n.º 7
0
void Traj_AmberCoord::parallelCloseTraj() { closeTraj(); }