// 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; }
// 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_Jcoupling::Init() Action::RetType Action_Jcoupling::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { debug_ = debugIn; outfile_ = 0; // Get Keywords outputfile_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("outfile"), "J-coupling"); outfile_ = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs ); std::string karpluspath = actionArgs.GetStringKey("kfile"); setname_ = actionArgs.GetStringKey("name"); // Get Masks if (Mask1_.SetMaskString( actionArgs.GetMaskNext() )) return Action::ERR; // If no Karplus params specified check environment vars. if (karpluspath.empty()) { // Check if the KARPLUS env var is set. const char* env = getenv("KARPLUS"); if (env != 0) { mprintf("Info: Using parameter file defined by $KARPLUS environment variable.\n"); karpluspath.assign(env); } else { // If KARPLUS not set check for $AMBERHOME/dat/Karplus.txt env = getenv("AMBERHOME"); if (env == 0) { mprinterr("Error: Either AMBERHOME must be set or KARPLUS must point\n" "Error: to the file containing Karplus parameters.\n"); return Action::ERR; } mprintf("Info: Using parameter file in '$AMBERHOME/dat/'.\n"); karpluspath.assign(env); karpluspath += "/dat/Karplus.txt"; } } // Load Karplus parameters if (loadKarplus(karpluspath)) return Action::ERR; mprintf(" J-COUPLING: Searching for dihedrals in mask [%s].\n" "\tUsing Karplus parameters in \"%s\"\n" "\t%i parameters found for %zu residues.\n", Mask1_.MaskString(), karpluspath.c_str(), Nconstants_, KarplusConstants_.size()); if (outfile_ != 0) mprintf("\tDataSets will be written to %s\n", outfile_->DataFilename().full()); if (outputfile_ != 0) mprintf("\tWriting fixed-format output to %s\n",outputfile_->Filename().full()); mprintf("# Citations: Chou et al. JACS (2003) 125 p.8959-8966\n" "# Perez et al. JACS (2001) 123 p.7081-7093\n"); init.DSL().SetDataSetsPending(true); masterDSL_ = init.DslPtr(); return Action::OK; }
Action::RetType Action_MultiVector::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { debug_ = debugIn; // Get keywords outfile_ = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs); std::string resrange_arg = actionArgs.GetStringKey("resrange"); if (!resrange_arg.empty()) if (resRange_.SetRange( resrange_arg )) return Action::ERR; ired_ = actionArgs.hasKey("ired"); // Get atom names if (SetName(name1_, actionArgs.GetStringKey("name1"), "name1")) return Action::ERR; if (SetName(name2_, actionArgs.GetStringKey("name2"), "name2")) return Action::ERR; // Setup DataSet(s) name dsetname_ = actionArgs.GetStringNext(); mprintf(" MULTIVECTOR: Calculating"); if (ired_) mprintf(" IRED"); if (!resRange_.Empty()) mprintf(" vectors for residues in range %s\n", resRange_.RangeArg()); else mprintf(" vectors for all solute residues.\n"); mprintf("\tName1='%s' (origin) Name2='%s'\n", *name1_, *name2_); if (!dsetname_.empty()) mprintf("\tDataSet name: %s\n", dsetname_.c_str()); if (outfile_ != 0) mprintf("\tOutput to %s\n", outfile_->DataFilename().base()); init.DSL().SetDataSetsPending(true); masterDSL_ = init.DslPtr(); return Action::OK; }
/** Called once before traj processing. Set up reference info. */ Action::RetType Action_DistRmsd::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { // Check for keywords DataFile* outfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs ); // Reference keywords // TODO: Can these just be put in the InitRef call? bool first = actionArgs.hasKey("first"); ReferenceFrame REF = init.DSL().GetReferenceFrame( actionArgs ); std::string reftrajname = actionArgs.GetStringKey("reftraj"); Topology* RefParm = init.DSL().GetTopology( actionArgs ); // Get the RMS mask string for target std::string mask0 = actionArgs.GetMaskNext(); TgtMask_.SetMaskString(mask0); // Get the RMS mask string for reference std::string mask1 = actionArgs.GetMaskNext(); if (mask1.empty()) mask1 = mask0; // Initialize reference if (refHolder_.InitRef(false, first, false, false, reftrajname, REF, RefParm, mask1, actionArgs, "distrmsd")) return Action::ERR; // Set up the RMSD data set drmsd_ = init.DSL().AddSet(DataSet::DOUBLE, actionArgs.GetStringNext(),"DRMSD"); if (drmsd_==0) return Action::ERR; // Add dataset to data file list if (outfile != 0) outfile->AddDataSet( drmsd_ ); mprintf(" DISTRMSD: (%s), reference is %s\n",TgtMask_.MaskString(), refHolder_.RefModeString()); return Action::OK; }
// 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; }
// Action_Angle::init() Action::RetType Action_Angle::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { // Get keywords DataFile* outfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs ); useMass_ = actionArgs.hasKey("mass"); // Get Masks std::string mask1 = actionArgs.GetMaskNext(); std::string mask2 = actionArgs.GetMaskNext(); std::string mask3 = actionArgs.GetMaskNext(); if (mask1.empty() || mask2.empty() || mask3.empty()) { mprinterr("Error: angle: Requires 3 masks\n"); return Action::ERR; } Mask1_.SetMaskString(mask1); Mask2_.SetMaskString(mask2); Mask3_.SetMaskString(mask3); // Dataset to store angles ang_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(actionArgs.GetStringNext(),MetaData::M_ANGLE),"Ang"); if (ang_==0) return Action::ERR; // Add dataset to data file list if (outfile != 0) outfile->AddDataSet( ang_ ); mprintf(" ANGLE: [%s]-[%s]-[%s]\n",Mask1_.MaskString(), Mask2_.MaskString(), Mask3_.MaskString()); if (useMass_) mprintf("\tUsing center of mass of atoms in masks.\n"); return Action::OK; }
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; }
// 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; }
// Action_Energy::Init() Action::RetType Action_Energy::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { ENE_.SetDebug( debugIn ); // Get keywords DataFile* outfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs ); // Which terms will be calculated? Ecalcs_.clear(); if (actionArgs.hasKey("bond")) Ecalcs_.push_back(BND); if (actionArgs.hasKey("angle")) Ecalcs_.push_back(ANG); if (actionArgs.hasKey("dihedral")) Ecalcs_.push_back(DIH); if (actionArgs.hasKey("nb14")) Ecalcs_.push_back(N14); if (actionArgs.hasKey("nonbond")) Ecalcs_.push_back(NBD); // If nothing is selected, select all. if (Ecalcs_.empty()) { for (int c = 0; c <= (int)NBD; c++) Ecalcs_.push_back( (CalcType)c ); } // Get Masks Mask1_.SetMaskString( actionArgs.GetMaskNext() ); // DataSet std::string setname = actionArgs.GetStringNext(); if (setname.empty()) setname = init.DSL().GenerateDefaultName("ENE"); Energy_.clear(); Energy_.resize( (int)TOTAL + 1, 0 ); for (calc_it calc = Ecalcs_.begin(); calc != Ecalcs_.end(); ++calc) { switch (*calc) { case BND: if (AddSet(BOND, init.DSL(), outfile, setname)) return Action::ERR; break; case ANG: if (AddSet(ANGLE, init.DSL(), outfile, setname)) return Action::ERR; break; case DIH: if (AddSet(DIHEDRAL, init.DSL(), outfile, setname)) return Action::ERR; break; case N14: if (AddSet(V14, init.DSL(), outfile, setname)) return Action::ERR; if (AddSet(Q14, init.DSL(), outfile, setname)) return Action::ERR; break; case NBD: if (AddSet(VDW, init.DSL(), outfile, setname)) return Action::ERR; if (AddSet(ELEC, init.DSL(), outfile, setname)) return Action::ERR; break; } } // if (Ecalcs_.size() > 1) { if (AddSet(TOTAL, init.DSL(), outfile, setname)) return Action::ERR; // } mprintf(" ENERGY: Calculating energy for atoms in mask '%s'\n", Mask1_.MaskString()); mprintf("\tCalculating terms:"); for (calc_it calc = Ecalcs_.begin(); calc != Ecalcs_.end(); ++calc) mprintf(" %s", Cstring[*calc]); mprintf("\n"); return Action::OK; }
// Action_SymmetricRmsd::Init() Action::RetType Action_SymmetricRmsd::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { // Check for keywords bool fit = !actionArgs.hasKey("nofit"); bool useMass = actionArgs.hasKey("mass"); DataFile* outfile = init.DFL().AddDataFile(actionArgs.GetStringKey("out"), actionArgs); remap_ = actionArgs.hasKey("remap"); // Reference keywords bool previous = actionArgs.hasKey("previous"); bool first = actionArgs.hasKey("first"); ReferenceFrame REF = init.DSL().GetReferenceFrame( actionArgs ); std::string reftrajname = actionArgs.GetStringKey("reftraj"); Topology* RefParm = init.DSL().GetTopology( actionArgs ); // Get the RMS mask string for target std::string tMaskExpr = actionArgs.GetMaskNext(); if (tgtMask_.SetMaskString( tMaskExpr )) return Action::ERR; // Initialize Symmetric RMSD calc. if (SRMSD_.InitSymmRMSD( fit, useMass, debugIn )) return Action::ERR; // Initialize reference std::string rMaskExpr = actionArgs.GetMaskNext(); if (rMaskExpr.empty()) rMaskExpr = tMaskExpr; if (REF_.InitRef(previous, first, useMass, fit, reftrajname, REF, RefParm, rMaskExpr, actionArgs, "symmrmsd")) return Action::ERR; // Set up the RMSD data set. MetaData md(actionArgs.GetStringNext(), MetaData::M_RMS); rmsd_ = init.DSL().AddSet(DataSet::DOUBLE, md, "RMSD"); if (rmsd_==0) return Action::ERR; // Add dataset to data file list if (outfile != 0) outfile->AddDataSet( rmsd_ ); if (remap_ || SRMSD_.Fit()) action_return_ = Action::MODIFY_COORDS; else action_return_ = Action::OK; mprintf(" SYMMRMSD: (%s), reference is %s", tgtMask_.MaskString(), REF_.RefModeString()); if (!SRMSD_.Fit()) mprintf(", no fitting"); else mprintf(", with fitting"); if (SRMSD_.UseMass()) mprintf(", mass-weighted"); mprintf(".\n"); if (remap_) mprintf("\tAtoms will be re-mapped for symmetry.\n"); return Action::OK; }
// 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_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; }
// Action_Distance::Init() Action::RetType Action_Distance::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { AssociatedData_NOE noe; // Get Keywords image_.InitImaging( !(actionArgs.hasKey("noimage")) ); useMass_ = !(actionArgs.hasKey("geom")); DataFile* outfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs ); MetaData::scalarType stype = MetaData::UNDEFINED; std::string stypename = actionArgs.GetStringKey("type"); if ( stypename == "noe" ) { stype = MetaData::NOE; if (noe.NOE_Args( actionArgs )) return Action::ERR; } // Get Masks std::string mask1 = actionArgs.GetMaskNext(); std::string mask2 = actionArgs.GetMaskNext(); if (mask1.empty() || mask2.empty()) { mprinterr("Error: distance requires 2 masks\n"); return Action::ERR; } Mask1_.SetMaskString(mask1); Mask2_.SetMaskString(mask2); // Dataset to store distances TODO store masks in data set? dist_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(actionArgs.GetStringNext(), MetaData::M_DISTANCE, stype), "Dis"); if (dist_==0) return Action::ERR; if ( stype == MetaData::NOE ) { dist_->AssociateData( &noe ); dist_->SetLegend(Mask1_.MaskExpression() + " and " + Mask2_.MaskExpression()); } // Add dataset to data file if (outfile != 0) outfile->AddDataSet( dist_ ); mprintf(" DISTANCE: %s to %s",Mask1_.MaskString(), Mask2_.MaskString()); if (!image_.UseImage()) mprintf(", non-imaged"); if (useMass_) mprintf(", center of mass"); else mprintf(", geometric center"); mprintf(".\n"); return Action::OK; }
// Action_Principal::Init() Action::RetType Action_Principal::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { debug_ = debugIn; // Keywords std::string dsname = actionArgs.GetStringKey("name"); doRotation_ = actionArgs.hasKey("dorotation"); // CPPTRAJ always uses mass no matter what this keyword says. useMass_ = actionArgs.hasKey("mass"); std::string filename = actionArgs.GetStringKey("out"); if (!doRotation_ && filename.empty() && dsname.empty()) { mprinterr("Error: At least one of 'dorotation', 'out <filename>', or 'name <dsname>' must be specified.\n"); return Action::ERR; } // Masks mask_.SetMaskString( actionArgs.GetMaskNext() ); // Set up data if (!dsname.empty()) { vecData_ = (DataSet_Mat3x3*)init.DSL().AddSet(DataSet::MAT3X3, MetaData(dsname, "evec")); valData_ = (DataSet_Vector*)init.DSL().AddSet(DataSet::VECTOR, MetaData(dsname, "eval")); if (vecData_ == 0 || valData_ == 0) return Action::ERR; } mprintf(" PRINCIPAL:"); if (!filename.empty()) { outfile_ = init.DFL().AddCpptrajFile(filename, "Eigenvectors/Eigenvalues"); if (outfile_ == 0) return Action::ERR; mprintf(" output eigenvectors/eigenvalues to %s,", outfile_->Filename().full()); } if (doRotation_) mprintf(" with rotation by"); else mprintf(" without rotation by"); if (useMass_) mprintf(" center of mass"); else mprintf(" center of geometry"); mprintf(", atoms selected by [%s]\n", mask_.MaskString()); if (vecData_ != 0) mprintf("\tSaving eigenvectors to '%s' (in rows of 3x3 matrices).\n" "\tSaving eigenvalues to '%s'\n", vecData_->legend(), valData_->legend()); 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; }
// Action_Surf::Init() Action::RetType Action_Surf::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { // Get keywords DataFile* outfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs); // Get Masks Mask1_.SetMaskString( actionArgs.GetMaskNext() ); // Dataset to store surface area surf_ = init.DSL().AddSet(DataSet::DOUBLE, actionArgs.GetStringNext(), "SA"); if (surf_==0) return Action::ERR; // Add dataset to data file list if (outfile != 0) outfile->AddDataSet( surf_ ); mprintf(" SURF: Calculating surface area for atoms in mask [%s]\n",Mask1_.MaskString()); mprintf("#Citation: Weiser, J.; Shenkin, P. S.; Still, W. C.; \"Approximate atomic\n" "# surfaces from linear combinations of pairwise overlaps (LCPO).\"\n" "# J. Comp. Chem. (1999), V.20, pp.217-230.\n"); return Action::OK; }
// 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; }
// 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; }
// 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_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; }
// 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; }
// ----------------------------------------------------------------------------- // 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; }
// Action_LIE::init() Action::RetType Action_LIE::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { // Always use imaged distances InitImaging(true); double cut; // Get Keywords doelec_ = !(actionArgs.hasKey("noelec")); dovdw_ = !(actionArgs.hasKey("novdw")); DataFile* datafile = init.DFL().AddDataFile(actionArgs.GetStringKey("out"), actionArgs); dielc_ = actionArgs.getKeyDouble("diel", 1.0); cut = actionArgs.getKeyDouble("cutvdw", 12.0); cut2vdw_ = cut * cut; // store square of cut for computational efficiency cut = actionArgs.getKeyDouble("cutelec", 12.0); cut2elec_ = cut * cut; // store square of cut for computational efficiency onecut2_ = 1 / cut2elec_; bool has_mask2 = false; if (!doelec_ && !dovdw_) { mprinterr("Error: LIE: Cannot skip both ELEC and VDW calcs\n"); return Action::ERR; } // Get Masks Mask1_.SetMaskString( actionArgs.GetMaskNext() ); std::string refmask = actionArgs.GetMaskNext(); if (!refmask.empty()) { Mask2_.SetMaskString(refmask); has_mask2 = true; } else { Mask2_ = Mask1_; Mask2_.InvertMaskExpression(); } // Get data set name std::string ds_name = actionArgs.GetStringNext(); if (ds_name.empty()) ds_name = init.DSL().GenerateDefaultName("LIE"); // Datasets if (doelec_) { elec_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(ds_name, "EELEC")); if (elec_ == 0) return Action::ERR; if (datafile != 0) datafile->AddDataSet(elec_); } if (dovdw_) { vdw_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(ds_name, "EVDW")); if (vdw_ == 0) return Action::ERR; if (datafile != 0) datafile->AddDataSet(vdw_); } mprintf(" LIE: Ligand mask is %s. Surroundings are ", Mask1_.MaskString()); if (!has_mask2) mprintf("everything else. "); else mprintf("atoms in mask %s. ", Mask2_.MaskString()); mprintf("Cutoff is %.3lf Ang. ", cut); if (!doelec_) mprintf("Skipping Electrostatic Calc. "); if (!dovdw_) mprintf("Skipping VDW Calc. "); mprintf("\n"); return Action::OK; }
// Action_Diffusion::Init() Action::RetType Action_Diffusion::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { # ifdef MPI trajComm_ = init.TrajComm(); # endif debug_ = debugIn; image_.InitImaging( !(actionArgs.hasKey("noimage")) ); // Determine if this is old syntax or new. if (actionArgs.Nargs() > 2 && actionArgs.ArgIsMask(1) && validDouble(actionArgs[2])) { // Old syntax: <mask> <time per frame> [average] [<prefix>] printIndividual_ = !(actionArgs.hasKey("average")); calcDiffConst_ = false; mprintf("Warning: Deprecated syntax for 'diffusion'. Consider using new syntax:\n"); ShortHelp(); mask_.SetMaskString( actionArgs.GetMaskNext() ); time_ = actionArgs.getNextDouble(1.0); if (CheckTimeArg(time_)) return Action::ERR; std::string outputNameRoot = actionArgs.GetStringNext(); // Default filename: 'diffusion' if (outputNameRoot.empty()) outputNameRoot.assign("diffusion"); // Open output files ArgList oldArgs("prec 8.3 noheader"); DataFile::DataFormatType dft = DataFile::DATAFILE; outputx_ = init.DFL().AddDataFile(outputNameRoot+"_x.xmgr", dft, oldArgs); outputy_ = init.DFL().AddDataFile(outputNameRoot+"_y.xmgr", dft, oldArgs); outputz_ = init.DFL().AddDataFile(outputNameRoot+"_z.xmgr", dft, oldArgs); outputr_ = init.DFL().AddDataFile(outputNameRoot+"_r.xmgr", dft, oldArgs); outputa_ = init.DFL().AddDataFile(outputNameRoot+"_a.xmgr", dft, oldArgs); } else { // New syntax: [{separateout <suffix> | out <filename>}] [time <time per frame>] // [<mask>] [<set name>] [individual] [diffout <filename>] [nocalc] printIndividual_ = actionArgs.hasKey("individual"); calcDiffConst_ = !(actionArgs.hasKey("nocalc")); std::string suffix = actionArgs.GetStringKey("separateout"); std::string outname = actionArgs.GetStringKey("out"); if (!outname.empty() && !suffix.empty()) { mprinterr("Error: Specify either 'out' or 'separateout', not both.\n"); return Action::ERR; } diffout_ = init.DFL().AddDataFile(actionArgs.GetStringKey("diffout")); time_ = actionArgs.getKeyDouble("time", 1.0); if (CheckTimeArg(time_)) return Action::ERR; mask_.SetMaskString( actionArgs.GetMaskNext() ); // Open output files. if (!suffix.empty()) { FileName FName( suffix ); outputx_ = init.DFL().AddDataFile(FName.PrependFileName("x_"), actionArgs); outputy_ = init.DFL().AddDataFile(FName.PrependFileName("y_"), actionArgs); outputz_ = init.DFL().AddDataFile(FName.PrependFileName("z_"), actionArgs); outputr_ = init.DFL().AddDataFile(FName.PrependFileName("r_"), actionArgs); outputa_ = init.DFL().AddDataFile(FName.PrependFileName("a_"), actionArgs); if (diffout_ == 0 && calcDiffConst_) diffout_ = init.DFL().AddDataFile(FName.PrependFileName("diff_"), actionArgs); } else if (!outname.empty()) { outputr_ = init.DFL().AddDataFile( outname, actionArgs ); outputx_ = outputy_ = outputz_ = outputa_ = outputr_; } } if (diffout_ != 0) calcDiffConst_ = true; // Add DataSets dsname_ = actionArgs.GetStringNext(); if (dsname_.empty()) dsname_ = init.DSL().GenerateDefaultName("Diff"); avg_x_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(dsname_, "X")); avg_y_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(dsname_, "Y")); avg_z_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(dsname_, "Z")); avg_r_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(dsname_, "R")); avg_a_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(dsname_, "A")); if (avg_x_ == 0 || avg_y_ == 0 || avg_z_ == 0 || avg_r_ == 0 || avg_a_ == 0) return Action::ERR; if (outputr_ != 0) outputr_->AddDataSet( avg_r_ ); if (outputx_ != 0) outputx_->AddDataSet( avg_x_ ); if (outputy_ != 0) outputy_->AddDataSet( avg_y_ ); if (outputz_ != 0) outputz_->AddDataSet( avg_z_ ); if (outputa_ != 0) outputa_->AddDataSet( avg_a_ ); // Set X dim Xdim_ = Dimension(0.0, time_, "Time"); avg_x_->SetDim(Dimension::X, Xdim_); avg_y_->SetDim(Dimension::X, Xdim_); avg_z_->SetDim(Dimension::X, Xdim_); avg_r_->SetDim(Dimension::X, Xdim_); avg_a_->SetDim(Dimension::X, Xdim_); // Add DataSets for diffusion constant calc if (calcDiffConst_) { MetaData::tsType ts = MetaData::NOT_TS; diffConst_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(dsname_, "D", ts)); diffLabel_ = init.DSL().AddSet(DataSet::STRING, MetaData(dsname_, "Label", ts)); diffSlope_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(dsname_, "Slope", ts)); diffInter_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(dsname_, "Intercept", ts)); diffCorrl_ = init.DSL().AddSet(DataSet::DOUBLE, MetaData(dsname_, "Corr", ts)); if (diffConst_ == 0 || diffLabel_ == 0 || diffSlope_ == 0 || diffInter_ == 0 || diffCorrl_ == 0) return Action::ERR; # ifdef MPI // No sync needed since these are not time series diffConst_->SetNeedsSync( false ); diffLabel_->SetNeedsSync( false ); diffSlope_->SetNeedsSync( false ); diffInter_->SetNeedsSync( false ); diffCorrl_->SetNeedsSync( false ); # endif if (diffout_ != 0) { diffout_->AddDataSet( diffConst_ ); diffout_->AddDataSet( diffSlope_ ); diffout_->AddDataSet( diffInter_ ); diffout_->AddDataSet( diffCorrl_ ); diffout_->AddDataSet( diffLabel_ ); } Dimension Ddim( 1, 1, "Set" ); diffConst_->SetDim(Dimension::X, Ddim); diffLabel_->SetDim(Dimension::X, Ddim); diffSlope_->SetDim(Dimension::X, Ddim); diffInter_->SetDim(Dimension::X, Ddim); diffCorrl_->SetDim(Dimension::X, Ddim); } // Save master data set list, needed when printIndividual_ masterDSL_ = init.DslPtr(); mprintf(" DIFFUSION:\n"); mprintf("\tAtom Mask is [%s]\n", mask_.MaskString()); if (printIndividual_) mprintf("\tBoth average and individual diffusion will be calculated.\n"); else mprintf("\tOnly average diffusion will be calculated.\n"); mprintf("\tData set base name: %s\n", avg_x_->Meta().Name().c_str()); if (image_.UseImage()) mprintf("\tCorrections for imaging enabled.\n"); else mprintf("\tCorrections for imaging disabled.\n"); // If one file defined, assume all are. if (outputx_ != 0) { mprintf("\tOutput files:\n" "\t %s: (x) Mean square displacement(s) in the X direction (in Ang.^2).\n" "\t %s: (y) Mean square displacement(s) in the Y direction (in Ang.^2).\n" "\t %s: (z) Mean square displacement(s) in the Z direction (in Ang.^2).\n" "\t %s: (r) Overall mean square displacement(s) (in Ang.^2).\n" "\t %s: (a) Total distance travelled (in Ang.).\n", outputx_->DataFilename().full(), outputy_->DataFilename().full(), outputz_->DataFilename().full(), outputr_->DataFilename().full(), outputa_->DataFilename().full()); } mprintf("\tThe time between frames is %g ps.\n", time_); if (calcDiffConst_) { mprintf("\tCalculating diffusion constants by fitting slope to MSD vs time\n" "\t and multiplying by 10.0/2*N (where N is # of dimensions), units\n" "\t are 1x10^-5 cm^2/s.\n"); if (diffout_ != 0) mprintf("\tDiffusion constant output to '%s'\n", diffout_->DataFilename().full()); else mprintf("\tDiffusion constant output to STDOUT.\n"); } else mprintf("\tTo calculate diffusion constant from mean squared displacement plots,\n" "\t calculate the slope of MSD vs time and multiply by 10.0/2*N (where N\n" "\t is # of dimensions); this will give units of 1x10^-5 cm^2/s.\n"); return Action::OK; }
// Action_Vector::Init() Action::RetType Action_Vector::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { DataFile* df = 0; std::string filename = actionArgs.GetStringKey("out"); if (actionArgs.hasKey("trajout")) return DeprecatedErr( "trajout" ); if (actionArgs.hasKey("trajfmt")) return DeprecatedErr( "trajfmt" ); if (actionArgs.hasKey("parmout")) return DeprecatedErr( "parmout" ); ptrajoutput_ = actionArgs.hasKey("ptrajoutput"); if (ptrajoutput_) { if (filename.empty()) { mprinterr("Error: 'ptrajoutput' specified but no 'out <filename>' arg given.\n"); return Action::ERR; } outfile_ = init.DFL().AddCpptrajFile(filename, "Vector (PTRAJ)"); if (outfile_ == 0) return Action::ERR; } else df = init.DFL().AddDataFile( filename, actionArgs ); bool calc_magnitude = actionArgs.hasKey("magnitude"); if (calc_magnitude && ptrajoutput_) { mprinterr("Error: 'ptrajoutput' and 'magnitude' are incompatible.\n"); return Action::ERR; } needBoxInfo_ = false; // Deprecated: corrired, corr, ired if ( actionArgs.hasKey("principal") ) { mode_ = PRINCIPAL_X; if ( actionArgs.hasKey("x") ) mode_ = PRINCIPAL_X; if ( actionArgs.hasKey("y") ) mode_ = PRINCIPAL_Y; if ( actionArgs.hasKey("z") ) mode_ = PRINCIPAL_Z; } else if (actionArgs.hasKey("center")) mode_ = CENTER; else if (actionArgs.hasKey("dipole")) mode_ = DIPOLE; else if (actionArgs.hasKey("box")) mode_ = BOX; else if (actionArgs.hasKey("corrplane")) mode_ = CORRPLANE; else if (actionArgs.hasKey("corrired")) return WarnDeprecated(); else if (actionArgs.hasKey("corr")) return WarnDeprecated(); else if (actionArgs.hasKey("mask")) mode_ = MASK; else if (actionArgs.hasKey("ucellx")) mode_ = BOX_X; else if (actionArgs.hasKey("ucelly")) mode_ = BOX_Y; else if (actionArgs.hasKey("ucellz")) mode_ = BOX_Z; else if (actionArgs.hasKey("boxcenter")) mode_ = BOX_CTR; else if (actionArgs.hasKey("minimage")) mode_ = MINIMAGE; else mode_ = MASK; if (mode_ == BOX || mode_ == BOX_X || mode_ == BOX_Y || mode_ == BOX_Z || mode_ == BOX_CTR || mode_ == MINIMAGE) needBoxInfo_ = true; // Check if IRED vector bool isIred = actionArgs.hasKey("ired"); // Vector Mask if (mode_ != BOX && mode_ != BOX_X && mode_ != BOX_Y && mode_ != BOX_Z) mask_.SetMaskString( actionArgs.GetMaskNext() ); // Get second mask if necessary if (mode_ == MASK || mode_ == MINIMAGE) { std::string maskexpr = actionArgs.GetMaskNext(); if (maskexpr.empty()) { mprinterr("Error: Specified vector mode (%s) requires a second mask.\n", ModeString[ mode_ ]); return Action::ERR; } mask2_.SetMaskString( maskexpr ); } // Set up vector dataset and IRED status MetaData md(actionArgs.GetStringNext(), MetaData::M_VECTOR); if (isIred) md.SetScalarType( MetaData::IREDVEC ); Vec_ = (DataSet_Vector*)init.DSL().AddSet(DataSet::VECTOR, md, "Vec"); if (Vec_ == 0) return Action::ERR; // Add set to output file if not doing ptraj-compatible output if (!ptrajoutput_ && df != 0) df->AddDataSet( Vec_ ); // Set up magnitude data set. if (calc_magnitude) { Magnitude_ = init.DSL().AddSet(DataSet::FLOAT, MetaData(Vec_->Meta().Name(), "Mag")); if (Magnitude_ == 0) return Action::ERR; if (df != 0) df->AddDataSet( Magnitude_ ); } mprintf(" VECTOR: Type %s", ModeString[ mode_ ]); if (calc_magnitude) mprintf(" (with magnitude)"); if (isIred) mprintf(", IRED"); if (mask_.MaskStringSet()) mprintf(", mask [%s]", mask_.MaskString()); if (mask2_.MaskStringSet()) mprintf(", second mask [%s]", mask2_.MaskString()); if (!filename.empty()) { if (ptrajoutput_) mprintf(", ptraj-compatible output to"); else mprintf(", output to"); mprintf(" %s", filename.c_str()); } mprintf("\n"); return Action::OK; }
// Action_AtomMap::Init() Action::RetType Action_AtomMap::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { DataFile* rmsout = 0; int refatom,targetatom; debug_ = debugIn; RefMap_.SetDebug(debug_); TgtMap_.SetDebug(debug_); // Get Args CpptrajFile* outputfile = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("mapout"), "Atom Map"); maponly_ = actionArgs.hasKey("maponly"); rmsfit_ = actionArgs.hasKey("rmsfit"); if (rmsfit_) rmsout = init.DFL().AddDataFile( actionArgs.GetStringKey("rmsout"), actionArgs ); std::string targetName = actionArgs.GetStringNext(); std::string refName = actionArgs.GetStringNext(); if (targetName.empty()) { mprinterr("Error: No target specified.\n"); return Action::ERR; } if (refName.empty()) { mprinterr("Error: No reference specified.\n"); return Action::ERR; } // Get Reference RefFrame_ = (DataSet_Coords_REF*)init.DSL().FindSetOfType( refName, DataSet::REF_FRAME ); if (RefFrame_ == 0) { mprinterr("Error: Could not get reference frame %s\n",refName.c_str()); return Action::ERR; } // Get Target TgtFrame_ = (DataSet_Coords_REF*)init.DSL().FindSetOfType( targetName, DataSet::REF_FRAME ); if (TgtFrame_ == 0) { mprinterr("Error: Could not get target frame %s\n",targetName.c_str()); return Action::ERR; } mprintf(" ATOMMAP: Atoms in trajectories associated with parm %s will be\n", TgtFrame_->Top().c_str()); mprintf(" mapped according to parm %s.\n",RefFrame_->Top().c_str()); if (outputfile != 0) mprintf(" Map will be written to %s\n",outputfile->Filename().full()); if (maponly_) mprintf(" maponly: Map will only be written, not used in trajectory read.\n"); if (!maponly_ && rmsfit_) { mprintf(" rmsfit: Will rms fit mapped atoms in tgt to reference.\n"); if (rmsout != 0) { rmsdata_ = init.DSL().AddSet(DataSet::DOUBLE, actionArgs.GetStringNext(), "RMSD"); if (rmsdata_==0) return Action::ERR; rmsout->AddDataSet(rmsdata_); } } // For each map, set up (get element for each atom, initialize map mem), // determine what atoms are bonded to each other via simple distance // cutoffs, the give each atom an ID based on what atoms are bonded to // it, noting which IDs are unique for that map. if (RefMap_.Setup(RefFrame_->Top())!=0) return Action::ERR; //RefMap_.WriteMol2((char*)"RefMap.mol2\0"); // DEBUG RefMap_.DetermineAtomIDs(); if (TgtMap_.Setup(TgtFrame_->Top())!=0) return Action::ERR; //TgtMap_.WriteMol2((char*)"TgtMap.mol2\0"); // DEBUG TgtMap_.DetermineAtomIDs(); // Check if number of atoms in each map is equal if (RefMap_.Natom() != TgtMap_.Natom()) { mprintf("Warning: # atoms in reference (%i) not equal\n", RefMap_.Natom()); mprintf("Warning:\tto # atoms in target (%i).\n",TgtMap_.Natom()); } // Set up RMS frames to be able to hold max # of possible atoms rmsRefFrame_.SetupFrame(RefMap_.Natom()); rmsTgtFrame_.SetupFrame(RefMap_.Natom()); // Allocate memory for atom map // AMap_[reference]=target AMap_.resize( RefMap_.Natom(), -1); // Map unique atoms int numMappedAtoms = MapUniqueAtoms(RefMap_, TgtMap_); if (debug_>0) mprintf("* MapUniqueAtoms: %i atoms mapped.\n",numMappedAtoms); // If no unique atoms mapped system is highly symmetric and needs to be // iteratively mapped. Otherwise just map remaining atoms. if (numMappedAtoms==0) { if (MapWithNoUniqueAtoms(RefMap_,TgtMap_)) return Action::ERR; } else { if (MapAtoms(RefMap_,TgtMap_)) return Action::ERR; } // Print atom map and count # mapped atoms numMappedAtoms = 0; outputfile->Printf("%-6s %4s %6s %4s\n","#TgtAt","Tgt","RefAt","Ref"); for (refatom=0; refatom < RefMap_.Natom(); refatom++) { targetatom = AMap_[refatom]; if (targetatom < 0) outputfile->Printf("%6s %4s %6i %4s\n","---","---",refatom+1,RefMap_[refatom].c_str()); else outputfile->Printf("%6i %4s %6i %4s\n",targetatom+1,TgtMap_[targetatom].c_str(), refatom+1, RefMap_[refatom].c_str()); if (targetatom>=0) { //mprintf("* TargetAtom %6i(%4s) maps to RefAtom %6i(%4s)\n", // targetatom,TgtMap_.P->names[targetatom], // refatom,RefMap_.P->names[refatom]); ++numMappedAtoms; } //else { // mprintf("* Could not map any TargetAtom to RefAtom %6i(%4s)\n", // refatom,RefMap_.P->names[refatom]); //} } mprintf(" %i total atoms were mapped.\n",numMappedAtoms); if (maponly_) return Action::OK; // If rmsfit is specified, an rms fit of target to reference will be // performed using all atoms that were successfully mapped from // target to reference. if (rmsfit_) { // Set up a reference frame containing only mapped reference atoms rmsRefFrame_.StripUnmappedAtoms(RefFrame_->RefFrame(), AMap_); mprintf(" rmsfit: Will rms fit %i atoms from target to reference.\n",numMappedAtoms); return Action::OK; } // Check if not all atoms could be mapped if (numMappedAtoms != RefMap_.Natom()) { // If the number of mapped atoms is less than the number of reference // atoms but equal to the number of target atoms, can modify the reference // frame to only include mapped atoms if (numMappedAtoms<RefMap_.Natom() && numMappedAtoms==TgtMap_.Natom()) { // Create mask that includes only reference atoms that could be mapped AtomMask M1; for (refatom = 0; refatom < RefMap_.Natom(); refatom++) { if (AMap_[refatom] != -1) M1.AddAtom(refatom); } // Strip reference parm mprintf(" Modifying reference '%s' topology and frame to match mapped atoms.\n", RefFrame_->legend()); if (RefFrame_->StripRef( M1 )) return Action::ERR; // Since AMap[ ref ] = tgt but ref is now missing any stripped atoms, // the indices of AMap must be shifted to match int refIndex = 0; // The new index for (refatom = 0; refatom < RefMap_.Natom(); refatom++) { targetatom = AMap_[refatom]; if (targetatom<0) continue; else AMap_[refIndex++]=targetatom; } } else { mprintf("Warning: AtomMap: Not all atoms were mapped. Frames will not be modified.\n"); maponly_=true; } } if (!maponly_) { // Set up new Frame newFrame_ = new Frame(); newFrame_->SetupFrameM( TgtFrame_->Top().Atoms() ); // Set up new Parm newParm_ = TgtFrame_->Top().ModifyByMap(AMap_); } return Action::OK; }
// Action_DSSP::Init() Action::RetType Action_DSSP::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { debug_ = debugIn; Nframe_ = 0; // Get keywords outfile_ = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs ); std::string temp = actionArgs.GetStringKey("sumout"); if (temp.empty() && outfile_ != 0) temp = outfile_->DataFilename().Full() + ".sum"; dsspFile_ = init.DFL().AddDataFile( temp ); DataFile* totalout = init.DFL().AddDataFile( actionArgs.GetStringKey("totalout"), actionArgs ); assignout_ = init.DFL().AddCpptrajFile(actionArgs.GetStringKey("assignout"), "SS assignment"); printString_ = actionArgs.hasKey("ptrajformat"); temp = actionArgs.GetStringKey("namen"); if (!temp.empty()) BB_N_ = temp; temp = actionArgs.GetStringKey("nameh"); if (!temp.empty()) BB_H_ = temp; temp = actionArgs.GetStringKey("namec"); if (!temp.empty()) BB_C_ = temp; temp = actionArgs.GetStringKey("nameo"); if (!temp.empty()) BB_O_ = temp; temp = actionArgs.GetStringKey("nameca"); if (!temp.empty()) BB_CA_ = temp; // Get masks Mask_.SetMaskString( actionArgs.GetMaskNext() ); // Set up the DSSP data set dsetname_ = actionArgs.GetStringNext(); // Set default name if none specified if (dsetname_.empty()) dsetname_ = init.DSL().GenerateDefaultName("DSSP"); // Set up Z labels if (outfile_ != 0) outfile_->ProcessArgs("zlabels None,Para,Anti,3-10,Alpha,Pi,Turn,Bend"); // Create data sets for total fraction SS vs time. for (int i = 0; i < NSSTYPE; i++) { totalDS_[i] = init.DSL().AddSet(DataSet::FLOAT, MetaData(dsetname_, SSname[i])); if (totalDS_[i] == 0) { mprinterr("Error: Could not create DSSP total frac v time data set.\n"); return Action::ERR; } // For now dont add 'None' so colors match up. if (totalout != 0 && i > 0) totalout->AddDataSet( totalDS_[i] ); } mprintf( " SECSTRUCT: Calculating secondary structure using mask [%s]\n",Mask_.MaskString()); if (outfile_ != 0) mprintf("\tDumping results to %s\n", outfile_->DataFilename().full()); if (dsspFile_ != 0) mprintf("\tSum results to %s\n", dsspFile_->DataFilename().full()); if (printString_) { mprintf("\tSS data for each residue will be stored as a string.\n"); for (int i = 0; i < NSSTYPE; i++) mprintf("\t\t%s = %s\n", SSchar[i], SSname[i]); } else { mprintf("\tSS data for each residue will be stored as integers.\n"); for (int i = 0; i < NSSTYPE; i++) mprintf("\t\t%i = %s\n", i, SSname[i]); } if (assignout_ != 0) mprintf("\tOverall assigned SS will be written to %s\n", assignout_->Filename().full()); mprintf("\tBackbone Atom Names: N=[%s] H=[%s] C=[%s] O=[%s] CA=[%s]\n", *BB_N_, *BB_H_, *BB_C_, *BB_O_, *BB_CA_ ); mprintf("# Citation: Kabsch, W.; Sander, C.; \"Dictionary of Protein Secondary Structure:\n" "# Pattern Recognition of Hydrogen-Bonded and Geometrical Features.\"\n" "# Biopolymers (1983), V.22, pp.2577-2637.\n" ); init.DSL().SetDataSetsPending(true); Init_ = init; return Action::OK; }
// Action_Density::Init() Action::RetType Action_Density::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { # ifdef MPI trajComm_ = init.TrajComm(); # endif DataFile* outfile = init.DFL().AddDataFile(actionArgs.GetStringKey("out"), actionArgs); std::string dsname = actionArgs.GetStringKey("name"); if (actionArgs.hasKey("x") ) { axis_ = DX; area_coord_[0] = DY; area_coord_[1] = DZ; } else if (actionArgs.hasKey("y") ) { axis_ = DY; area_coord_[0] = DX; area_coord_[1] = DZ; } else if (actionArgs.hasKey("z") ) { axis_ = DZ; area_coord_[0] = DX; area_coord_[1] = DY; } property_ = NUMBER; if (actionArgs.hasKey("number") ) property_ = NUMBER; else if (actionArgs.hasKey("mass") ) property_ = MASS; else if (actionArgs.hasKey("charge") ) property_ = CHARGE; else if (actionArgs.hasKey("electron") ) property_ = ELECTRON; binType_ = CENTER; if (actionArgs.hasKey("bincenter")) binType_ = CENTER; else if (actionArgs.hasKey("binedge") ) binType_ = EDGE; delta_ = actionArgs.getKeyDouble("delta", 0.01); if (delta_ <= 0) { mprinterr("Error: Delta must be > 0.0\n"); return Action::ERR; } // for compatibility with ptraj, ignored because we rely on the atom code to // do the right thing, see Atom.{h,cpp} if (actionArgs.hasKey("efile")) mprintf("Warning: The 'efile' keyword is deprecated.\n"); // read the rest of the command line as a series of masks std::string maskstr; unsigned int idx = 1; while ( (maskstr = actionArgs.GetMaskNext() ) != emptystring) { masks_.push_back( AtomMask(maskstr) ); if (dsname.empty()) dsname = init.DSL().GenerateDefaultName("DENSITY"); MetaData MD(dsname, "avg", idx); MD.SetTimeSeries( MetaData::NOT_TS ); // Hold average density DataSet* ads = init.DSL().AddSet( DataSet::DOUBLE, MD ); if (ads == 0) return Action::ERR; ads->SetLegend( NoWhitespace(masks_.back().MaskExpression()) ); AvSets_.push_back( ads ); if (outfile != 0) outfile->AddDataSet( ads ); // Hold SD density MD.SetAspect("sd"); DataSet* sds = init.DSL().AddSet( DataSet::DOUBLE, MD ); if (sds == 0) return Action::ERR; sds->SetLegend( NoWhitespace("sd(" + masks_.back().MaskExpression() + ")") ); SdSets_.push_back( sds ); if (outfile != 0) outfile->AddDataSet( sds ); # ifdef MPI ads->SetNeedsSync( false ); // Populated in Print() sds->SetNeedsSync( false ); # endif idx++; } if (masks_.empty()) { // If no masks assume we want total system density. if (dsname.empty()) dsname = actionArgs.GetStringNext(); density_ = init.DSL().AddSet(DataSet::DOUBLE, dsname, "DENSITY"); if (density_ == 0) return Action::ERR; if (outfile != 0) outfile->AddDataSet( density_ ); image_.InitImaging( true ); // Hijack delta for storing sum of masses delta_ = 0.0; } else { // Density selected by mask(s) along an axis density_ = 0; histograms_.resize(masks_.size() ); } mprintf(" DENSITY:"); if (density_ == 0) { const char* binStr[] = {"center", "edge"}; mprintf(" Determining %s density for %zu masks.\n", PropertyStr_[property_], masks_.size()); mprintf("\troutine version: %s\n", ROUTINE_VERSION_STRING); mprintf("\tDelta is %f\n", delta_); mprintf("\tAxis is %s\n", AxisStr_[axis_]); mprintf("\tData set name is '%s'\n", dsname.c_str()); mprintf("\tData set aspect [avg] holds the mean, aspect [sd] holds standard deviation.\n"); mprintf("\tBin coordinates will be to bin %s.\n", binStr[binType_]); } else { mprintf(" No masks specified, calculating total system density in g/cm^3.\n"); mprintf("\tData set name is '%s'\n", density_->legend()); } if (outfile != 0) mprintf("\tOutput to '%s'\n", outfile->DataFilename().full()); return Action::OK; }