/** Process a mask from the command line. */ int Cpptraj::ProcessMask( Sarray const& topFiles, Sarray const& refFiles, std::string const& maskexpr, bool verbose, bool residue ) const { SetWorldSilent(true); if (topFiles.empty()) { mprinterr("Error: No topology file specified.\n"); return 1; } ParmFile pfile; Topology parm; if (pfile.ReadTopology(parm, topFiles[0], State_.Debug())) return 1; if (!refFiles.empty()) { DataSet_Coords_REF refCoords; if (refCoords.LoadRefFromFile( refFiles[0], parm, State_.Debug())) return 1; parm.SetDistMaskRef( refCoords.RefFrame() ); } if (!verbose) { AtomMask tempMask( maskexpr ); if (parm.SetupIntegerMask( tempMask )) return 1; loudPrintf("Selected="); if (residue) { int res = -1; for (AtomMask::const_iterator atom = tempMask.begin(); atom != tempMask.end(); ++atom) { if (parm[*atom].ResNum() > res) { loudPrintf(" %i", parm[*atom].ResNum()+1); res = parm[*atom].ResNum(); } } } else for (AtomMask::const_iterator atom = tempMask.begin(); atom != tempMask.end(); ++atom) loudPrintf(" %i", *atom + 1); loudPrintf("\n"); } else { if (residue) parm.PrintResidueInfo( maskexpr ); else parm.PrintAtomInfo( maskexpr ); } return 0; }
// Action_MakeStructure::Init() Action::RetType Action_MakeStructure::Init(ArgList& actionArgs, TopologyList* PFL, DataSetList* DSL, DataFileList* DFL, int debugIn) { debug_ = debugIn; secstruct_.clear(); // Get all arguments std::string ss_expr = actionArgs.GetStringNext(); while ( !ss_expr.empty() ) { ArgList ss_arg(ss_expr, ":"); if (ss_arg.Nargs() < 2) { mprinterr("Error: Malformed SS arg.\n"); Help(); return Action::ERR; } // Type is 1st arg, range is 2nd arg. SecStructHolder ss_holder(ss_arg[1], FindSStype(ss_arg[0])); if (ss_arg.Nargs() == 2) { // Find SS type: <ss type>:<range> if (ss_holder.sstype_idx == SS_EMPTY) { mprinterr("Error: SS type %s not found.\n", ss_arg[0].c_str()); return Action::ERR; } ss_holder.dihSearch_.SearchFor(MetaData::PHI); ss_holder.dihSearch_.SearchFor(MetaData::PSI); secstruct_.push_back( ss_holder ); } else if (ss_arg[0] == "ref") { // Use dihedrals from reference structure if (ss_arg.Nargs() < 3) { mprinterr("Error: Invalid 'ref' arg. Requires 'ref:<range>:<refname>[:<ref range>]'\n"); return Action::ERR; } ss_arg.MarkArg(0); ss_arg.MarkArg(1); // Sanity check: Currently only unique args of this type are allowed if (ss_holder.sstype_idx != SS_EMPTY) { mprinterr("Error: Ref backbone types must be unique [%s]\n", ss_arg[0].c_str()); return Action::ERR; } // Use backbone phi/psi from reference structure ss_holder.dihSearch_.SearchFor(MetaData::PHI); ss_holder.dihSearch_.SearchFor(MetaData::PSI); // Get reference structure DataSet_Coords_REF* REF = (DataSet_Coords_REF*) DSL->FindSetOfType(ss_arg.GetStringNext(), DataSet::REF_FRAME); // ss_arg[2] if (REF == 0) { mprinterr("Error: Could not get reference structure [%s]\n", ss_arg[2].c_str()); return Action::ERR; } // Get reference residue range, or use resRange Range refRange(ss_arg.GetStringNext(), -1); // ss_arg[3] if (!refRange.Empty()) { if (ss_holder.resRange.Size() != refRange.Size()) { mprinterr("Error: Reference range [%s] must match residue range [%s]\n", refRange.RangeArg(), ss_holder.resRange.RangeArg()); return Action::ERR; } } else refRange = ss_holder.resRange; // Look for phi/psi only in reference DihedralSearch refSearch; refSearch.SearchFor(MetaData::PHI); refSearch.SearchFor(MetaData::PSI); if (refSearch.FindDihedrals( REF->Top(), refRange )) return Action::ERR; // For each found dihedral, set theta for (DihedralSearch::mask_it dih = refSearch.begin(); dih != refSearch.end(); ++dih) { double torsion = Torsion( REF->RefFrame().XYZ(dih->A0()), REF->RefFrame().XYZ(dih->A1()), REF->RefFrame().XYZ(dih->A2()), REF->RefFrame().XYZ(dih->A3()) ); ss_holder.thetas_.push_back( (float)torsion ); } secstruct_.push_back( ss_holder ); } else if (ss_arg.Nargs() == 4 && isalpha(ss_arg[2][0])) { // Single dihedral type: <name>:<range>:<dih type>:<angle> DihedralSearch::DihedralType dtype = DihedralSearch::GetType(ss_arg[2]); if (ss_holder.sstype_idx == SS_EMPTY) { // Type not yet defined. Create new type. if (dtype == MetaData::UNDEFINED) { mprinterr("Error: Dihedral type %s not found.\n", ss_arg[2].c_str()); return Action::ERR; } if (!validDouble(ss_arg[3])) { mprinterr("Error: 4th arg (angle) is not a valid number.\n"); return Action::ERR; } SS.push_back( SS_TYPE(convertToDouble(ss_arg[3]), 0.0, 0.0, 0.0, 2, ss_arg[0]) ); ss_holder.sstype_idx = (int)(SS.size() - 1); } ss_holder.dihSearch_.SearchFor( dtype ); secstruct_.push_back( ss_holder ); } else if (ss_arg.Nargs() == 7 || ss_arg.Nargs() == 8) { // Single custom dihedral type: <name>:<range>:<at0>:<at1>:<at2>:<at3>:<angle>[:<offset>] if (ss_holder.sstype_idx == SS_EMPTY) { // Type not yet defined. Create new type. if (!validDouble(ss_arg[6])) { mprinterr("Error: 7th arg (angle) is not a valid number.\n"); return Action::ERR; } SS.push_back( SS_TYPE(convertToDouble(ss_arg[6]), 0.0, 0.0, 0.0, 2, ss_arg[0]) ); ss_holder.sstype_idx = (int)(SS.size() - 1); } int offset = 0; if (ss_arg.Nargs() == 8) { if (!validInteger(ss_arg[7])) { mprinterr("Error: 8th arg (offset) is not a valid number.\n"); return Action::ERR; } offset = convertToInteger(ss_arg[7]); } ss_holder.dihSearch_.SearchForNewType(offset,ss_arg[2],ss_arg[3],ss_arg[4],ss_arg[5], ss_arg[0]); secstruct_.push_back( ss_holder ); } else if (ss_arg.Nargs() == 4 || ss_arg.Nargs() == 6) { // Custom SS/turn type: <name>:<range>:<phi1>:<psi1>[:<phi2>:<psi2>] if (ss_holder.sstype_idx == SS_EMPTY) { // Type not yet defined. Create new type. if (!validDouble(ss_arg[2]) || !validDouble(ss_arg[3])) { mprinterr("Error: 3rd or 4th arg (phi1/psi1) is not a valid number.\n"); return Action::ERR; } double phi1 = convertToDouble(ss_arg[2]); double psi1 = convertToDouble(ss_arg[3]); int isTurn = 0; double phi2 = 0.0; double psi2 = 0.0; if (ss_arg.Nargs() == 6) { isTurn = 1; if (!validDouble(ss_arg[4]) || !validDouble(ss_arg[5])) { mprinterr("Error: 5th or 6th arg (phi2/psi2) is not a valid number.\n"); return Action::ERR; } phi2 = convertToDouble(ss_arg[4]); psi2 = convertToDouble(ss_arg[5]); } SS.push_back(SS_TYPE(phi1, psi1, phi2, psi2, isTurn, ss_arg[0] )); ss_holder.sstype_idx = (int)(SS.size() - 1); } ss_holder.dihSearch_.SearchFor(MetaData::PHI); ss_holder.dihSearch_.SearchFor(MetaData::PSI); secstruct_.push_back( ss_holder ); } else { mprinterr("Error: SS arg type [%s] not recognized.\n", ss_arg[0].c_str()); return Action::ERR; } ss_expr = actionArgs.GetStringNext(); } // End loop over args if (secstruct_.empty()) { mprinterr("Error: No SS types defined.\n"); return Action::ERR; } mprintf(" MAKESTRUCTURE:\n"); for (std::vector<SecStructHolder>::iterator ss = secstruct_.begin(); ss != secstruct_.end(); ++ss) { if (ss->sstype_idx != SS_EMPTY) { const SS_TYPE& myType = SS[ss->sstype_idx]; switch ( myType.isTurn ) { case 0: mprintf("\tSS type %s will be applied to residue(s) %s\n", myType.type_arg.c_str(), ss->resRange.RangeArg()); break; case 1: mprintf("\tTurn type %s will be applied to residue(s) %s\n", myType.type_arg.c_str(), ss->resRange.RangeArg()); break; case 2: mprintf("\tDihedral value of %.2f will be applied to %s dihedrals in residue(s) %s\n", myType.phi, myType.type_arg.c_str(), ss->resRange.RangeArg()); } } else mprintf("\tBackbone angles from reference will be applied to residue(s) %s\n", ss->resRange.RangeArg()); } return Action::OK; }