Example #1
0
// Action_Esander::Init()
Action::RetType Action_Esander::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
# ifdef MPI
  trajComm_ = init.TrajComm();
# endif
  SANDER_.SetDebug( debugIn );
  Init_ = init;
  // Get keywords
  outfile_ = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  save_forces_ = actionArgs.hasKey("saveforces");
  ReferenceFrame REF = init.DSL().GetReferenceFrame( actionArgs );
  if (REF.error()) return Action::ERR;
  if (!REF.empty()) {
    refFrame_ = REF.Coord();
    currentParm_ = REF.ParmPtr();
  }
  if (SANDER_.SetInput( actionArgs )) return Action::ERR;
  // DataSet name and array
  setname_ = actionArgs.GetStringNext();
  if (setname_.empty())
    setname_ = init.DSL().GenerateDefaultName("ENE");
  Esets_.clear();
  Esets_.resize( (int)Energy_Sander::N_ENERGYTYPES, 0 );

  mprintf("    ESANDER: Calculating energy using Sander.\n");
  mprintf("\tTemporary topology file name is '%s'\n", SANDER_.TopFilename().full());
  if (save_forces_) mprintf("\tSaving force information to frame.\n");
  mprintf("\tReference for initialization");
  if (!REF.empty())
    mprintf(" is '%s'\n", REF.refName());
  else
    mprintf(" will be first frame.\n");
  return Action::OK;
}
Example #2
0
// Action_Center::Init()
Action::RetType Action_Center::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  // Get keywords
  useMass_ = actionArgs.hasKey("mass");
  ReferenceFrame refFrm = init.DSL().GetReferenceFrame( actionArgs );
  if (refFrm.error()) return Action::ERR;
  // Determine center mode.
  if (!refFrm.empty())
    centerMode_ = REF;
  else if (actionArgs.hasKey("origin"))
    centerMode_ = ORIGIN;
  else if (actionArgs.hasKey("point")) {
    centerMode_ = POINT;
    refCenter_[0] = actionArgs.getNextDouble(0.0);
    refCenter_[1] = actionArgs.getNextDouble(0.0);
    refCenter_[2] = actionArgs.getNextDouble(0.0);
  } else
    centerMode_ = BOXCTR;

  // Get Masks
  Mask_.SetMaskString( actionArgs.GetMaskNext() );
  // Get reference mask if reference specified.
  AtomMask refMask;
  if (centerMode_ == REF) {
    std::string rMaskExpr = actionArgs.GetMaskNext();
    if (rMaskExpr.empty())
      rMaskExpr = Mask_.MaskExpression();
    refMask.SetMaskString( rMaskExpr );
    if (refFrm.Parm().SetupIntegerMask( refMask, refFrm.Coord() ))
      return Action::ERR;
    // Get center of mask in reference
    if (useMass_)
      refCenter_ = refFrm.Coord().VCenterOfMass( refMask );
    else
      refCenter_ = refFrm.Coord().VGeometricCenter( refMask );
  }

  mprintf("    CENTER: Centering coordinates using");
  if (useMass_)
    mprintf(" center of mass");
  else
    mprintf(" geometric center");
  mprintf(" of atoms in mask (%s) to\n", Mask_.MaskString());
  switch (centerMode_) {
    case ORIGIN: mprintf("\tcoordinate origin.\n"); break;
    case BOXCTR: mprintf("\tbox center.\n"); break;
    case REF:
      mprintf("\tcenter of mask (%s) in reference '%s'.\n", refMask.MaskString(),
              refFrm.refName());
      break;
    case POINT:  mprintf("\tpoint (%g, %g, %g).\n",
                         refCenter_[0], refCenter_[1], refCenter_[2]);
      break;
  }
  return Action::OK;
}
Example #3
0
// Action_Unwrap::Init()
Action::RetType Action_Unwrap::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  // Get Keywords
  center_ = actionArgs.hasKey("center");
  if (actionArgs.hasKey("bymol"))
    imageMode_ = Image::BYMOL;
  else if (actionArgs.hasKey("byres"))
    imageMode_ = Image::BYRES;
  else if (actionArgs.hasKey("byatom")) {
    imageMode_ = Image::BYATOM;
    // Unwrapping to center by atom makes no sense
    if (center_) center_ = false;
  } else
    imageMode_ = Image::BYATOM;
  // Get reference
  ReferenceFrame REF = init.DSL().GetReferenceFrame( actionArgs );
  if (REF.error()) return Action::ERR;
  if (!REF.empty()) {
    RefFrame_ = REF.Coord();
    // Get reference parm for frame
    RefParm_ = REF.ParmPtr();
  }

  // Get mask string
  maskExpression_ = actionArgs.GetMaskNext();

  mprintf("    UNWRAP: By %s", Image::ModeString(imageMode_));
  if (!maskExpression_.empty())
    mprintf(" using mask '%s'", maskExpression_.c_str());
  else
    mprintf(" using all atoms");
  if (imageMode_ != Image::BYATOM) {
    if (center_)
      mprintf(" based on center of mass.");
    else
      mprintf(" based on first atom position.");
  }
  mprintf("\n");
  if ( !REF.empty())
    mprintf("\tReference is %s", REF.refName());
  else
    mprintf("\tReference is first frame.");
  mprintf("\n");

  return Action::OK;
}
Example #4
0
// Action_Center::Init()
Action::RetType Action_Center::Init(ArgList& actionArgs, TopologyList* PFL, DataSetList* DSL, DataFileList* DFL, int debugIn)
{
  // Get keywords
  if (actionArgs.hasKey("origin"))
    centerMode_ = ORIGIN;
  else
    centerMode_ = BOXCTR;
  useMass_ = actionArgs.hasKey("mass");
  ReferenceFrame refFrm = DSL->GetReferenceFrame( actionArgs );
  if (refFrm.error()) return Action::ERR;

  // Get Masks
  Mask_.SetMaskString( actionArgs.GetMaskNext() );
  // Get reference mask if reference specified.
  AtomMask refMask;
  if (!refFrm.empty()) {
    std::string rMaskExpr = actionArgs.GetMaskNext();
    if (rMaskExpr.empty())
      rMaskExpr = Mask_.MaskExpression();
    refMask.SetMaskString( rMaskExpr );
    if (refFrm.Parm().SetupIntegerMask( refMask, refFrm.Coord() ))
      return Action::ERR;
    // Get center of mask in reference
    if (useMass_)
      refCenter_ = refFrm.Coord().VCenterOfMass( refMask );
    else
      refCenter_ = refFrm.Coord().VGeometricCenter( refMask );
    centerMode_ = POINT; 
  }

  mprintf("    CENTER: Centering coordinates using");
  if (useMass_)
    mprintf(" center of mass");
  else
    mprintf(" geometric center");
  mprintf(" of atoms in mask (%s) to\n", Mask_.MaskString());
  if (centerMode_ == POINT)
    mprintf("\tcenter of mask (%s) in reference '%s'.\n", refMask.MaskString(),
            refFrm.refName());
  else if (centerMode_ == ORIGIN)
    mprintf("\tcoordinate origin.\n");
  else
    mprintf("\tbox center.\n");

  return Action::OK;
}
// Action_NativeContacts::Init()
Action::RetType Action_NativeContacts::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
# ifdef MPI
  trajComm_ = init.TrajComm();
# endif
  masterDSL_ = init.DslPtr();
  debug_ = debugIn;
  // Get Keywords
  image_.InitImaging( !(actionArgs.hasKey("noimage")) );
  double dist = actionArgs.getKeyDouble("distance", 7.0);
  byResidue_ = actionArgs.hasKey("byresidue");
  resoffset_ = actionArgs.getKeyInt("resoffset", 0) + 1;
  if (resoffset_ < 1) {
    mprinterr("Error: Residue offset must be >= 0\n");
    return Action::ERR;
  }
  includeSolvent_ = actionArgs.hasKey("includesolvent");
  series_ = actionArgs.hasKey("series");
  saveNonNative_ = actionArgs.hasKey("savenonnative");
  if (actionArgs.hasKey("skipnative"))
    determineNativeContacts_ = false;
  if (!determineNativeContacts_ && !saveNonNative_) {
    mprintf("Warning: 'skipnative' specified; implies 'savenonnative'.\n");
    saveNonNative_ = true;
  }
# ifdef MPI
  if (saveNonNative_) {
    mprinterr("Error: Saving non-native contact data not yet supported for MPI\n");
    return Action::ERR;
  }
# endif
  distance_ = dist * dist; // Square the cutoff
  first_ = actionArgs.hasKey("first");
  DataFile* outfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  Rseries_ = NO_RESSERIES;
  if (series_) {
    seriesout_ = init.DFL().AddDataFile(actionArgs.GetStringKey("seriesout"), actionArgs);
    init.DSL().SetDataSetsPending( true );
    if (saveNonNative_)
      seriesNNout_ = init.DFL().AddDataFile(actionArgs.GetStringKey("seriesnnout"), actionArgs);
    std::string rs_arg = actionArgs.GetStringKey("resseries");
    if (!rs_arg.empty()) {
      if (rs_arg == "present")
        Rseries_ = RES_PRESENT;
      else if (rs_arg == "sum")
        Rseries_ = RES_SUM;
      else {
        mprinterr("Error: '%s' is not a valid 'resseries' keyword.\n", rs_arg.c_str());
        return Action::ERR;
      }
      seriesRout_ = init.DFL().AddDataFile(actionArgs.GetStringKey("resseriesout"), actionArgs);
    }
  } else {
    if (KeywordError(actionArgs,"seriesout")) return Action::ERR;
    if (KeywordError(actionArgs,"seriesnnout")) return Action::ERR;
    if (KeywordError(actionArgs,"resseries")) return Action::ERR;
    if (KeywordError(actionArgs,"resseriesout")) return Action::ERR;
  }
  cfile_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("writecontacts"), "Native Contacts",
                               DataFileList::TEXT, true);
  pfile_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("contactpdb"), "Contact PDB",
                               DataFileList::PDB);
  if (saveNonNative_)
    nfile_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("nncontactpdb"),
                                       "Non-native Contact PDB", DataFileList::PDB);
  rfile_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("resout"), "Contact Res Pairs",
                               DataFileList::TEXT, true);
  if (cfile_ == 0 || rfile_ == 0) return Action::ERR;
  pdbcut_ = (float)actionArgs.getKeyDouble("pdbcut", -1.0);
  usepdbcut_ = (pdbcut_ > -1.0);
  // Get reference for native contacts. Do this even if we wont be
  // determining native contacts in order to set up contact lists.
  ReferenceFrame REF = init.DSL().GetReferenceFrame( actionArgs );
  if (!first_) {
    if (REF.error()) return Action::ERR;
    if (REF.empty()) {
      mprintf("Warning: No reference structure specified. Defaulting to first.\n");
      first_ = true;
    }
  } else {
    if (!REF.empty()) {
      mprinterr("Error: Must only specify 'first' or a reference structure, not both.\n");
      return Action::ERR;
    }
  }
  
  // Create data sets
  std::string name = actionArgs.GetStringKey("name");
  if (name.empty())
    name = init.DSL().GenerateDefaultName("Contacts");
  numnative_ = init.DSL().AddSet(DataSet::INTEGER, MetaData(name, "native"));
  nonnative_ = init.DSL().AddSet(DataSet::INTEGER, MetaData(name, "nonnative"));
  if (outfile != 0) {
    outfile->AddDataSet(numnative_);
    outfile->AddDataSet(nonnative_);
  }
  if (numnative_ == 0 || nonnative_ == 0) return Action::ERR;
  if (actionArgs.hasKey("mindist")) {
    mindist_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(name, "mindist"));
    if (mindist_ == 0) return Action::ERR;
    if (outfile != 0) outfile->AddDataSet(mindist_);
  }
  if (actionArgs.hasKey("maxdist")) {
    maxdist_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(name, "maxdist"));
    if (maxdist_ == 0) return Action::ERR;
    if (outfile != 0) outfile->AddDataSet(maxdist_);
  }
  DataFile *natmapfile = 0, *nonmapfile = 0;
  if (actionArgs.hasKey("map")) {
    nativeMap_ = (DataSet_MatrixDbl*)init.DSL().AddSet(DataSet::MATRIX_DBL, MetaData(name, "nativemap"));
    if (nativeMap_ == 0) return Action::ERR;
    nonnatMap_ = (DataSet_MatrixDbl*)init.DSL().AddSet(DataSet::MATRIX_DBL, MetaData(name, "nonnatmap"));
    if (nonnatMap_ == 0) return Action::ERR;
    FileName mapFilename;
    mapFilename.SetFileName( actionArgs.GetStringKey("mapout") );
    if (!mapFilename.empty()) {
      natmapfile = init.DFL().AddDataFile(mapFilename.PrependFileName("native."));
      if (natmapfile != 0) natmapfile->AddDataSet(nativeMap_);
      nonmapfile = init.DFL().AddDataFile(mapFilename.PrependFileName("nonnative."));
      if (nonmapfile != 0) nonmapfile->AddDataSet(nonnatMap_);
    }
  }
  // Get Masks
  if (Mask1_.SetMaskString( actionArgs.GetMaskNext() )) return Action::ERR;
  std::string mask2 = actionArgs.GetMaskNext();
  if (!mask2.empty()) {
    if (Mask2_.SetMaskString( mask2 )) return Action::ERR;
  }
  mprintf("    NATIVECONTACTS: Mask1='%s'", Mask1_.MaskString());
  if (Mask2_.MaskStringSet())
    mprintf(" Mask2='%s'", Mask2_.MaskString());
  if (determineNativeContacts_) {
    mprintf(", native contacts set up based on");
    if (first_)
      mprintf(" first frame.\n");
    else
      mprintf("'%s'.\n", REF.refName());
  } else {
    mprintf(", skipping native contacts set up.\n");
  }
  if (byResidue_) {
    mprintf("\tContacts will be ignored for residues spaced < %i apart.\n", resoffset_);
    if (nativeMap_ != 0)
      mprintf("\tMap will be printed by residue.\n");
  }
  if (saveNonNative_)
    mprintf("\tSaving non-native contacts as well (may use a lot of memory).\n");
  mprintf("\tDistance cutoff is %g Angstroms,", sqrt(distance_));
  if (!image_.UseImage())
    mprintf(" imaging is off.\n");
  else
    mprintf(" imaging is on.\n");
  if (includeSolvent_)
    mprintf("\tMask selection will including solvent.\n");
  else
    mprintf("\tMask selection will not include solvent.\n");
  mprintf("\tData set name: %s\n", name.c_str());
  if (maxdist_ != 0)
    mprintf("\tSaving maximum observed distances in set '%s'\n", maxdist_->legend());
  if (mindist_ != 0)
    mprintf("\tSaving minimum observed distances in set '%s'\n", mindist_->legend());
  if (outfile != 0)
    mprintf("\tOutput to '%s'\n", outfile->DataFilename().full());
  mprintf("\tContact stats will be written to '%s'\n", cfile_->Filename().full());
  mprintf("\tContact res pairs will be written to '%s'\n", rfile_->Filename().full());
  if (pfile_ != 0) {
    mprintf("\tContact PDB will be written to '%s'\n", pfile_->Filename().full());
    if (usepdbcut_) mprintf("\tOnly atoms with values > %g will be written to PDB.\n", pdbcut_);
  }
  if (nfile_ != 0) {
    mprintf("\tNon-native contact PDB will be written to '%s'\n", nfile_->Filename().full());
    if (usepdbcut_) mprintf("\tOnly atoms with values > %g will be written to PDB.\n", pdbcut_);
  }
  if (nativeMap_ != 0) {
    mprintf("\tNative contacts map will be saved as set '%s'\n"
            "\tNon-native contacts map will be saved as set '%s'\n",
            nativeMap_->legend(), nonnatMap_->legend());
    if (natmapfile!=0) mprintf("\tNative map output to '%s'\n",natmapfile->DataFilename().full());
    if (nonmapfile!=0) mprintf("\tNative map output to '%s'\n",nonmapfile->DataFilename().full());
  }
  if (series_) {
    mprintf("\tSaving native contact time series %s[NC].\n", name.c_str());
    if (seriesout_ != 0) mprintf("\tWriting native contact time series to %s\n",
                                 seriesout_->DataFilename().full());
    if (saveNonNative_) {
      mprintf("\tSaving non-native contact time series %s[NN]\n", name.c_str());
      if (seriesNNout_ != 0) mprintf("\tWriting non-native contact time series to %s\n",
                                     seriesNNout_->DataFilename().full());
    }
    if (Rseries_ != NO_RESSERIES) {
      if (Rseries_ == RES_PRESENT)
        mprintf("\tResidue contact time series will reflect presence of individual contacts.\n");
      else if (Rseries_ == RES_SUM)
        mprintf("\tResidue contact time series will reflect sum of individual contacts.\n");
      if (seriesRout_ != 0) mprintf("\tWriting residue contact time series to %s\n",
                                    seriesRout_->DataFilename().full());
    }
  }
  // Set up reference if necessary.
  if (!first_) {
    // Set up imaging info for ref parm
    image_.SetupImaging( REF.CoordsInfo().TrajBox().Type() );
    if (image_.ImageType() == NONORTHO)
      REF.Coord().BoxCrd().ToRecip(ucell_, recip_);
    if (DetermineNativeContacts( REF.Parm(), REF.Coord() )) return Action::ERR;
  }
  return Action::OK;
}
Example #6
0
// Action_Pairwise::Init()
Action::RetType Action_Pairwise::Init(ArgList& actionArgs, ActionInit& init, int debugIn)
{
  // Get Keywords
  DataFile* dataout = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs );
  DataFile* vmapout = init.DFL().AddDataFile( actionArgs.GetStringKey("vmapout"), actionArgs );
  DataFile* emapout = init.DFL().AddDataFile( actionArgs.GetStringKey("emapout"), actionArgs );
  avgout_ = actionArgs.GetStringKey("avgout");
  std::string eout = actionArgs.GetStringKey("eout");
  cut_eelec_ = fabs(actionArgs.getKeyDouble("cuteelec",1.0));
  cut_evdw_ = fabs(actionArgs.getKeyDouble("cutevdw",1.0));
  mol2Prefix_ = actionArgs.GetStringKey("cutout");
  std::string pdbout = actionArgs.GetStringKey("pdbout");
  ReferenceFrame REF = init.DSL().GetReferenceFrame( actionArgs );
  
  // Get Masks
  Mask0_.SetMaskString( actionArgs.GetMaskNext() );
  std::string refmask = actionArgs.GetMaskNext();
  if (!refmask.empty())
    RefMask_.SetMaskString(refmask);
  else
    RefMask_.SetMaskString( Mask0_.MaskString() );

  // Datasets
  std::string ds_name = actionArgs.GetStringNext();
  if (ds_name.empty())
    ds_name = init.DSL().GenerateDefaultName("PW");
  ds_vdw_  = init.DSL().AddSet(DataSet::DOUBLE, MetaData(ds_name, "EVDW"));
  ds_elec_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(ds_name, "EELEC"));
  if (ds_vdw_ == 0 || ds_elec_ == 0) return Action::ERR;
  // Add DataSets to data file list
  if (dataout != 0) {
    dataout->AddDataSet(ds_vdw_);
    dataout->AddDataSet(ds_elec_);
  }
  vdwMat_ = (DataSet_MatrixDbl*)init.DSL().AddSet(DataSet::MATRIX_DBL, MetaData(ds_name, "VMAP"));
  eleMat_ = (DataSet_MatrixDbl*)init.DSL().AddSet(DataSet::MATRIX_DBL, MetaData(ds_name, "EMAP"));
  if (vdwMat_ == 0 || eleMat_ == 0) return Action::ERR;
  if (vmapout != 0) vmapout->AddDataSet(vdwMat_);
  if (emapout != 0) emapout->AddDataSet(eleMat_);

  // Get reference structure
  if (REF.error()) return Action::ERR;
  if (!REF.empty()) { 
    // Set up reference mask
    if ( REF.Parm().SetupIntegerMask(RefMask_) ) return Action::ERR;
    if (RefMask_.None()) {
      mprinterr("Error: No atoms selected in reference mask.\n");
      return Action::ERR;
    }
    // Set up nonbonded params for reference
    if ( (N_ref_interactions_=SetupNonbondParm( RefMask_, REF.Parm() )) == -1 ) 
      return Action::ERR;
    // Calculate energy for reference
    nb_calcType_ = SET_REF;
    NonbondEnergy(REF.Coord(), REF.Parm(), RefMask_);
    nb_calcType_ = COMPARE_REF;
  }

  // Output for individual atom energy | dEnergy
  if (!eout.empty()) {
    Eout_ = init.DFL().AddCpptrajFile(eout, "Atom Energies");
    if (Eout_ == 0) {
      mprinterr("Error: Could not set up file %s for eout.\n",eout.c_str());
      return Action::ERR;
    }
  }

  // Set up output pdb
  if (!pdbout.empty()) {
    if (PdbOut_.OpenWrite( pdbout )) return Action::ERR;
  }

  // Action Info
  mprintf("    PAIRWISE: Atoms in mask [%s].\n",Mask0_.MaskString());
  if (!eout.empty())
    mprintf("\tEnergy info for each atom will be written to %s\n",eout.c_str());
  if (nb_calcType_ == COMPARE_REF) { 
    mprintf("\tReference %s, mask [%s]\n", REF.refName(), RefMask_.MaskString());
    mprintf("\tReference energy (kcal/mol): EVDW= %12.5e  EELEC= %12.5e\n", ELJ_, Eelec_);
    mprintf("\tSize of reference energy array is %zu elements (%s)\n",
            ref_nonbondEnergy_.size(),
            ByteString(ref_nonbondEnergy_.size() * 2 * sizeof(double), BYTE_DECIMAL).c_str());
  }
  mprintf("\tEelec absolute cutoff (kcal/mol): %.4f\n", cut_eelec_);
  mprintf("\tEvdw absolute cutoff (kcal/mol) : %.4f\n", cut_evdw_);
  if (!mol2Prefix_.empty())
    mprintf("\tAtoms satisfying cutoff will be printed to %s.e<type>.mol2\n",
            mol2Prefix_.c_str());
  if (PdbOut_.IsOpen())
    mprintf("\tPDB with evdw/eelec in occ/b-fac columns will be written to %s\n",
            PdbOut_.Filename().full());
  
  return Action::OK;
}