void xReferenceFrame::createReferenceFrameTest() { ReferenceFrame rf1(ReferenceFrame::Unknown); ReferenceFrame rf2(ReferenceFrame::WGS84); ReferenceFrame rf3(ReferenceFrame::PZ90); ReferenceFrame rf4("Junk String That Will Never Match Up"); ReferenceFrame rf5("WGS84"); ReferenceFrame rf6("PZ90"); ReferenceFrame test; test = test.createReferenceFrame("PZ90"); //We want it to assert that test is the same as rf6 and rf3 CPPUNIT_ASSERT(test == rf3); CPPUNIT_ASSERT(test == rf6); CPPUNIT_ASSERT(test != rf1); //Made up string test = test.createReferenceFrame("ZP84"); CPPUNIT_ASSERT(test != rf1); CPPUNIT_ASSERT(test != rf2); CPPUNIT_ASSERT(test != rf3); CPPUNIT_ASSERT(test != rf4); CPPUNIT_ASSERT(test != rf5); CPPUNIT_ASSERT(test != rf6); //Make a new frame of type zp84 ReferenceFrame test1("ZP84"); CPPUNIT_ASSERT(test == test1); CPPUNIT_ASSERT(test1 != rf1); }
/*! Get the angular velocity of the body in the universal frame. */ Vector3d Body::getAngularVelocity(double tdb) const { const TimelinePhase* phase = timeline->findPhase(tdb); Vector3d v = phase->rotationModel()->angularVelocityAtTime(tdb); ReferenceFrame* bodyFrame = phase->bodyFrame(); v = bodyFrame->getOrientation(tdb).conjugate() * v; if (!bodyFrame->isInertial()) { v += bodyFrame->getAngularVelocity(tdb); } return v; }
/*! Get the velocity of the body in the universal frame. */ Vector3d Body::getVelocity(double tdb) const { const TimelinePhase* phase = timeline->findPhase(tdb); ReferenceFrame* orbitFrame = phase->orbitFrame(); Vector3d v = phase->orbit()->velocityAtTime(tdb); v = orbitFrame->getOrientation(tdb).conjugate() * v + orbitFrame->getCenter().getVelocity(tdb); if (!orbitFrame->isInertial()) { Vector3d r = Selection(const_cast<Body*>(this)).getPosition(tdb).offsetFromKm(orbitFrame->getCenter().getPosition(tdb)); v += orbitFrame->getAngularVelocity(tdb).cross(r); } return v; }
// 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; }
// 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; }
void RobotConfiguration::isReadyUpdate(){ _isReady = false; ReferenceFrame * baseReferenceFrame = frame(_baseReferenceFrameId); if (! baseReferenceFrame) return; // for each sensor, check if you can determine the transformation to the base link for (std::map<std::string, BaseSensor*>::iterator it = _sensorMap.begin(); it!=_sensorMap.end(); it++){ BaseSensor* s = it->second; if (! s) return; ReferenceFrame * f = s->frame(); if (! f) return; if (! f->canTransformTo(baseReferenceFrame)) return; } _isReady = true; }
// 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; }
void MultiFingersObjImpController::GetFKRefFrame(int ind, ReferenceFrame& refFrame) { if(ind < mFingerDescriptors.size()) { mSensorsGroup.ReadSensors(); Vector currJntPos = mSensorsGroup.GetJointAngles(); refFrame.Set(mRobot.GetReferenceFrame(mFingerDescriptors[ind].nEndID, mFingerDescriptors[ind].nStartID)); //printf("Calculate Foward Kinematics between link %d and %d\n", mFingerDescriptors[ind].nStartID, mFingerDescriptors[ind].nEndID); //refFrame.GetOrigin().Print(); //refFrame.GetOrient().Print(); } //printf("Getting FK ref frame done.\n"); return; }
// 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; }
/*! Get the position of the body in the universal coordinate system. * This method uses high-precision coordinates and is thus * slower relative to getAstrocentricPosition(), which works strictly * with standard double precision. For most purposes, * getAstrocentricPosition() should be used instead of the more * general getPosition(). */ UniversalCoord Body::getPosition(double tdb) const { Vector3d position = Vector3d::Zero(); const TimelinePhase* phase = timeline->findPhase(tdb); Vector3d p = phase->orbit()->positionAtTime(tdb); ReferenceFrame* frame = phase->orbitFrame(); while (frame->getCenter().getType() == Selection::Type_Body) { phase = frame->getCenter().body()->timeline->findPhase(tdb); position += frame->getOrientation(tdb).conjugate() * p; p = phase->orbit()->positionAtTime(tdb); frame = phase->orbitFrame(); } position += frame->getOrientation(tdb).conjugate() * p; if (frame->getCenter().star()) return frame->getCenter().star()->getPosition(tdb).offsetKm(position); else return frame->getCenter().getPosition(tdb).offsetKm(position); }
Action::RetType Action_Unwrap::Init(ArgList& actionArgs, TopologyList* PFL, FrameList* FL, DataSetList* DSL, DataFileList* DFL, int debugIn) { // Get reference ReferenceFrame REF = FL->GetFrameFromArgs( actionArgs ); if (REF.error()) return Action::ERR; if (!REF.empty()) { RefFrame_ = *(REF.Coord()); // Get reference parm for frame RefParm_ = REF.Parm(); } // Get mask string mask_.SetMaskString( actionArgs.GetMaskNext() ); mprintf(" UNWRAP: (%s), reference is ", mask_.MaskString()); if ( !REF.empty()) mprintf("%s", REF.FrameName().c_str()); else mprintf("first frame."); mprintf("\n"); return Action::OK; }
int SequenceAlign(CpptrajState& State, ArgList& argIn) { std::string blastfile = argIn.GetStringKey("blastfile"); if (blastfile.empty()) { mprinterr("Error: 'blastfile' must be specified.\n"); return 1; } ReferenceFrame qref = State.DSL()->GetReferenceFrame(argIn); if (qref.error() || qref.empty()) { mprinterr("Error: Must specify reference structure for query.\n"); return 1; } std::string outfilename = argIn.GetStringKey("out"); if (outfilename.empty()) { mprinterr("Error: Must specify output file.\n"); return 1; } TrajectoryFile::TrajFormatType fmt = TrajectoryFile::GetFormatFromArg(argIn); if (fmt != TrajectoryFile::PDBFILE && fmt != TrajectoryFile::MOL2FILE) fmt = TrajectoryFile::PDBFILE; // Default to PDB int smaskoffset = argIn.getKeyInt("smaskoffset", 0) + 1; int qmaskoffset = argIn.getKeyInt("qmaskoffset", 0) + 1; // Load blast file mprintf("\tReading BLAST alignment from '%s'\n", blastfile.c_str()); BufferedLine infile; if (infile.OpenFileRead( blastfile )) return 1; // Seek down to first Query line. const char* ptr = infile.Line(); bool atFirstQuery = false; while (ptr != 0) { if (*ptr == 'Q') { if ( strncmp(ptr, "Query", 5) == 0 ) { atFirstQuery = true; break; } } ptr = infile.Line(); } if (!atFirstQuery) { mprinterr("Error: 'Query' not found.\n"); return 1; } // Read alignment. Replacing query with subject. typedef std::vector<char> Carray; typedef std::vector<int> Iarray; Carray Query; // Query residues Carray Sbjct; // Sbjct residues Iarray Smap; // Smap[Sbjct index] = Query index while (ptr != 0) { const char* qline = ptr; // query line const char* aline = infile.Line(); // alignment line const char* sline = infile.Line(); // subject line if (aline == 0 || sline == 0) { mprinterr("Error: Missing alignment line or subject line after Query:\n"); mprinterr("Error: %s", qline); return 1; } for (int idx = 12; qline[idx] != ' '; idx++) { if (qline[idx] == '-') { // Sbjct does not have corresponding res in Query Smap.push_back(-1); Sbjct.push_back( sline[idx] ); } else if (sline[idx] == '-') { // Query does not have a corresponding res in Sbjct Query.push_back( qline[idx] ); } else { // Direct Query to Sbjct map Smap.push_back( Query.size() ); Sbjct.push_back( sline[idx] ); Query.push_back( qline[idx] ); } } // Scan to next Query ptr = infile.Line(); while (ptr != 0) { if (*ptr == 'Q') { if ( strncmp(ptr, "Query", 5) == 0 ) break; } ptr = infile.Line(); } } // DEBUG std::string SmaskExp, QmaskExp; if (State.Debug() > 0) mprintf(" Map of Sbjct to Query:\n"); for (int sres = 0; sres != (int)Sbjct.size(); sres++) { if (State.Debug() > 0) mprintf("%-i %3s %i", sres+smaskoffset, Residue::ConvertResName(Sbjct[sres]), Smap[sres]+qmaskoffset); const char* qres = ""; if (Smap[sres] != -1) { qres = Residue::ConvertResName(Query[Smap[sres]]); if (SmaskExp.empty()) SmaskExp.assign( integerToString(sres+smaskoffset) ); else SmaskExp.append( "," + integerToString(sres+smaskoffset) ); if (QmaskExp.empty()) QmaskExp.assign( integerToString(Smap[sres]+qmaskoffset) ); else QmaskExp.append( "," + integerToString(Smap[sres]+qmaskoffset) ); } if (State.Debug() > 0) mprintf(" %3s\n", qres); } mprintf("Smask: %s\n", SmaskExp.c_str()); mprintf("Qmask: %s\n", QmaskExp.c_str()); // Check that query residues match reference. for (unsigned int sres = 0; sres != Sbjct.size(); sres++) { int qres = Smap[sres]; if (qres != -1) { if (Query[qres] != qref.Parm().Res(qres).SingleCharName()) { mprintf("Warning: Potential residue mismatch: Query %s reference %s\n", Residue::ConvertResName(Query[qres]), qref.Parm().Res(qres).c_str()); } } } // Build subject using coordinate from reference. //AtomMask sMask; // Contain atoms that should be in sTop Topology sTop; Frame sFrame; Iarray placeHolder; // Atom indices of placeholder residues. for (unsigned int sres = 0; sres != Sbjct.size(); sres++) { int qres = Smap[sres]; NameType SresName( Residue::ConvertResName(Sbjct[sres]) ); if (qres != -1) { Residue const& QR = qref.Parm().Res(qres); Residue SR(SresName, sres+1, ' ', QR.ChainID()); if (Query[qres] == Sbjct[sres]) { // Exact match. All non-H atoms. for (int qat = QR.FirstAtom(); qat != QR.LastAtom(); qat++) { if (qref.Parm()[qat].Element() != Atom::HYDROGEN) sTop.AddTopAtom( qref.Parm()[qat], SR ); sFrame.AddXYZ( qref.Coord().XYZ(qat) ); //sMask.AddAtom(qat); } } else { // Partial match. Copy only backbone and CB. for (int qat = QR.FirstAtom(); qat != QR.LastAtom(); qat++) { if ( qref.Parm()[qat].Name().Match("N" ) || qref.Parm()[qat].Name().Match("CA") || qref.Parm()[qat].Name().Match("CB") || qref.Parm()[qat].Name().Match("C" ) || qref.Parm()[qat].Name().Match("O" ) ) { sTop.AddTopAtom( qref.Parm()[qat], SR ); sFrame.AddXYZ( qref.Coord().XYZ(qat) ); } } } } else { // Residue in query does not exist for subject. Just put placeholder CA for now. Vec3 Zero(0.0); placeHolder.push_back( sTop.Natom() ); sTop.AddTopAtom( Atom("CA", "C "), Residue(SresName, sres+1, ' ', ' ') ); sFrame.AddXYZ( Zero.Dptr() ); } } //sTop.PrintAtomInfo("*"); mprintf("\tPlaceholder residue indices:"); for (Iarray::const_iterator p = placeHolder.begin(); p != placeHolder.end(); ++p) mprintf(" %i", *p + 1); mprintf("\n"); // Try to give placeholders more reasonable coordinates. if (!placeHolder.empty()) { Iarray current_indices; unsigned int pidx = 0; while (pidx < placeHolder.size()) { if (current_indices.empty()) { current_indices.push_back( placeHolder[pidx++] ); // Search for the end of this segment for (; pidx != placeHolder.size(); pidx++) { if (placeHolder[pidx] - current_indices.back() > 1) break; current_indices.push_back( placeHolder[pidx] ); } // DEBUG mprintf("\tSegment:"); for (Iarray::const_iterator it = current_indices.begin(); it != current_indices.end(); ++it) mprintf(" %i", *it + 1); // Get coordinates of residues bordering segment. int prev_res = sTop[current_indices.front()].ResNum() - 1; int next_res = sTop[current_indices.back() ].ResNum() + 1; mprintf(" (prev_res=%i, next_res=%i)\n", prev_res+1, next_res+1); Vec3 prev_crd(sFrame.XYZ(current_indices.front() - 1)); Vec3 next_crd(sFrame.XYZ(current_indices.back() + 1)); prev_crd.Print("prev_crd"); next_crd.Print("next_crd"); Vec3 crd_step = (next_crd - prev_crd) / (double)(current_indices.size()+1); crd_step.Print("crd_step"); double* xyz = sFrame.xAddress() + (current_indices.front() * 3); for (unsigned int i = 0; i != current_indices.size(); i++, xyz += 3) { prev_crd += crd_step; xyz[0] = prev_crd[0]; xyz[1] = prev_crd[1]; xyz[2] = prev_crd[2]; } current_indices.clear(); } } } //Topology* sTop = qref.Parm().partialModifyStateByMask( sMask ); //if (sTop == 0) return 1; //Frame sFrame(qref.Coord(), sMask); // Write output traj Trajout_Single trajout; if (trajout.PrepareTrajWrite(outfilename, argIn, &sTop, CoordinateInfo(), 1, fmt)) return 1; if (trajout.WriteSingle(0, sFrame)) return 1; trajout.EndTraj(); return 0; }
/** Called once before traj processing. Set up reference info. */ Action::RetType Action_Rmsd::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { debug_ = debugIn; // Check for keywords fit_ = !actionArgs.hasKey("nofit"); if (fit_) rotate_ = !actionArgs.hasKey("norotate"); useMass_ = actionArgs.hasKey("mass"); DataFile* outfile = init.DFL().AddDataFile(actionArgs.GetStringKey("out"), actionArgs); bool saveMatrices = actionArgs.hasKey("savematrices"); // Reference keywords bool previous = actionArgs.hasKey("previous"); bool first = actionArgs.hasKey("first"); ReferenceFrame refFrm = init.DSL().GetReferenceFrame( actionArgs ); std::string reftrajname = actionArgs.GetStringKey("reftraj"); if (!reftrajname.empty()) RefParm_ = init.DSL().GetTopology( actionArgs ); // Per-res keywords perres_ = actionArgs.hasKey("perres"); if (perres_) { perresout_ = init.DFL().AddDataFile( actionArgs.GetStringKey("perresout") ); perresinvert_ = actionArgs.hasKey("perresinvert"); TgtRange_.SetRange( actionArgs.GetStringKey("range") ); RefRange_.SetRange( actionArgs.GetStringKey("refrange") ); perresmask_ = actionArgs.GetStringKey("perresmask"); if (perresmask_.empty()) perresmask_.assign(""); else { // If perresmask does not start with ampersand, insert one. if (perresmask_[0] != '&') perresmask_ = '&' + perresmask_; } perrescenter_ = actionArgs.hasKey("perrescenter"); perresavg_ = init.DFL().AddDataFile( actionArgs.GetStringKey("perresavg") ); } // Get the RMS mask string for target std::string tMaskExpr = actionArgs.GetMaskNext(); tgtMask_.SetMaskString(tMaskExpr); // Get the RMS mask string for reference std::string rMaskExpr = actionArgs.GetMaskNext(); if (rMaskExpr.empty()) rMaskExpr = tMaskExpr; // Initialize reference if (REF_.InitRef(previous, first, useMass_, fit_, reftrajname, refFrm, RefParm_, rMaskExpr, actionArgs, "rmsd")) return Action::ERR; // Set RefParm for perres if not empty if (perres_ && RefParm_ == 0 && !refFrm.empty()) RefParm_ = refFrm.ParmPtr(); // 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_ ); // Set up rotation matrix data set if specified if (saveMatrices) { md.SetAspect("RM"); if (!fit_) { mprinterr("Error: Must be fitting in order to save rotation matrices.\n"); return Action::ERR; } rmatrices_ = init.DSL().AddSet(DataSet::MAT3X3, md); if (rmatrices_ == 0) return Action::ERR; } mprintf(" RMSD: (%s), reference is %s", tgtMask_.MaskString(), REF_.RefModeString()); if (!fit_) mprintf(", no fitting"); else { mprintf(", with fitting"); if (!rotate_) mprintf(" (no rotation)"); } if (useMass_) mprintf(", mass-weighted"); mprintf(".\n"); if (rmatrices_ != 0) mprintf("\tRotation matrices will be saved to set '%s'\n", rmatrices_->legend()); // Per-residue RMSD info. if (perres_) { mprintf(" No-fit RMSD will also be calculated for "); if (TgtRange_.Empty()) mprintf("each solute residue"); else mprintf("residues %s",TgtRange_.RangeArg()); if (!RefRange_.Empty()) mprintf(" (reference residues %s)",RefRange_.RangeArg()); mprintf(" using mask [:X%s].\n",perresmask_.c_str()); if (perresout_ != 0) mprintf(" Per-residue output file is %s\n",perresout_->DataFilename().base()); if (perresavg_ != 0) mprintf(" Avg per-residue output file is %s\n",perresavg_->DataFilename().base()); if (perrescenter_) mprintf(" perrescenter: Each residue will be centered prior to RMS calc.\n"); if (perresinvert_) mprintf(" perresinvert: Frames will be written in rows instead of columns.\n"); } if (perres_) init.DSL().SetDataSetsPending(true); masterDSL_ = init.DslPtr(); return Action::OK; }
static bool CreateTimeline(Body* body, PlanetarySystem* system, Universe& universe, Hash* planetData, const string& path, Disposition disposition, BodyType bodyType) { FrameTree* parentFrameTree = NULL; Selection parentObject = GetParentObject(system); bool orbitsPlanet = false; if (parentObject.body()) { parentFrameTree = parentObject.body()->getOrCreateFrameTree(); orbitsPlanet = true; } else if (parentObject.star()) { SolarSystem* solarSystem = universe.getSolarSystem(parentObject.star()); if (solarSystem == NULL) solarSystem = universe.createSolarSystem(parentObject.star()); parentFrameTree = solarSystem->getFrameTree(); } else { // Bad orbit barycenter specified return false; } ReferenceFrame* defaultOrbitFrame = NULL; ReferenceFrame* defaultBodyFrame = NULL; if (bodyType == SurfaceObject) { defaultOrbitFrame = new BodyFixedFrame(parentObject, parentObject); defaultBodyFrame = CreateTopocentricFrame(parentObject, parentObject, Selection(body)); defaultOrbitFrame->addRef(); defaultBodyFrame->addRef(); } else { defaultOrbitFrame = parentFrameTree->getDefaultReferenceFrame(); defaultBodyFrame = parentFrameTree->getDefaultReferenceFrame(); } // If there's an explicit timeline definition, parse that. Otherwise, we'll do // things the old way. Value* value = planetData->getValue("Timeline"); if (value != NULL) { if (value->getType() != Value::ArrayType) { clog << "Error: Timeline must be an array\n"; return false; } Timeline* timeline = CreateTimelineFromArray(body, universe, value->getArray(), path, defaultOrbitFrame, defaultBodyFrame); if (timeline == NULL) { return false; } else { body->setTimeline(timeline); return true; } } // Information required for the object timeline. ReferenceFrame* orbitFrame = NULL; ReferenceFrame* bodyFrame = NULL; Orbit* orbit = NULL; RotationModel* rotationModel = NULL; double beginning = -numeric_limits<double>::infinity(); double ending = numeric_limits<double>::infinity(); // If any new timeline values are specified, we need to overrideOldTimeline will // be set to true. bool overrideOldTimeline = false; // The interaction of Modify with timelines is slightly complicated. If the timeline // is specified by putting the OrbitFrame, Orbit, BodyFrame, or RotationModel directly // in the object definition (i.e. not inside a Timeline structure), it will completely // replace the previous timeline if it contained more than one phase. Otherwise, the // properties of the single phase will be modified individually, for compatibility with // Celestia versions 1.5.0 and earlier. if (disposition == ModifyObject) { const Timeline* timeline = body->getTimeline(); if (timeline->phaseCount() == 1) { const TimelinePhase* phase = timeline->getPhase(0); orbitFrame = phase->orbitFrame(); bodyFrame = phase->bodyFrame(); orbit = phase->orbit(); rotationModel = phase->rotationModel(); beginning = phase->startTime(); ending = phase->endTime(); } } // Get the object's orbit reference frame. bool newOrbitFrame = false; Value* frameValue = planetData->getValue("OrbitFrame"); if (frameValue != NULL) { ReferenceFrame* frame = CreateReferenceFrame(universe, frameValue, parentObject, body); if (frame != NULL) { orbitFrame = frame; newOrbitFrame = true; overrideOldTimeline = true; } } // Get the object's body frame. bool newBodyFrame = false; Value* bodyFrameValue = planetData->getValue("BodyFrame"); if (bodyFrameValue != NULL) { ReferenceFrame* frame = CreateReferenceFrame(universe, bodyFrameValue, parentObject, body); if (frame != NULL) { bodyFrame = frame; newBodyFrame = true; overrideOldTimeline = true; } } // If no orbit or body frame was specified, use the default ones if (orbitFrame == NULL) orbitFrame = defaultOrbitFrame; if (bodyFrame == NULL) bodyFrame = defaultBodyFrame; // If the center of the is a star, orbital element units are // in AU; otherwise, use kilometers. if (orbitFrame->getCenter().star() != NULL) orbitsPlanet = false; else orbitsPlanet = true; Orbit* newOrbit = CreateOrbit(orbitFrame->getCenter(), planetData, path, !orbitsPlanet); if (newOrbit == NULL && orbit == NULL) { if (body->getTimeline() && disposition == ModifyObject) { // The object definition is modifying an existing object with a multiple phase // timeline, but no orbit definition was given. This can happen for completely // sensible reasons, such a Modify definition that just changes visual properties. // Or, the definition may try to change other timeline phase properties such as // the orbit frame, but without providing an orbit. In both cases, we'll just // leave the original timeline alone. return true; } else { clog << "No valid orbit specified for object '" << body->getName() << "'. Skipping.\n"; return false; } } // If a new orbit was given, override any old orbit if (newOrbit != NULL) { orbit = newOrbit; overrideOldTimeline = true; } // Get the rotation model for this body double syncRotationPeriod = orbit->getPeriod(); RotationModel* newRotationModel = CreateRotationModel(planetData, path, syncRotationPeriod); // If a new rotation model was given, override the old one if (newRotationModel != NULL) { rotationModel = newRotationModel; overrideOldTimeline = true; } // If there was no rotation model specified, nor a previous rotation model to // override, create the default one. if (rotationModel == NULL) { // If no rotation model is provided, use a default rotation model-- // a uniform rotation that's synchronous with the orbit (appropriate // for nearly all natural satellites in the solar system.) rotationModel = CreateDefaultRotationModel(syncRotationPeriod); } if (ParseDate(planetData, "Beginning", beginning)) overrideOldTimeline = true; if (ParseDate(planetData, "Ending", ending)) overrideOldTimeline = true; // Something went wrong if the disposition isn't modify and no timeline // is to be created. assert(disposition == ModifyObject || overrideOldTimeline); if (overrideOldTimeline) { if (beginning >= ending) { clog << "Beginning time must be before Ending time.\n"; return false; } // We finally have an orbit, rotation model, frames, and time range. Create // the object timeline. TimelinePhase* phase = TimelinePhase::CreateTimelinePhase(universe, body, beginning, ending, *orbitFrame, *orbit, *bodyFrame, *rotationModel); // We've already checked that beginning < ending; nothing else should go // wrong during the creation of a TimelinePhase. assert(phase != NULL); if (phase == NULL) { clog << "Internal error creating TimelinePhase.\n"; return false; } Timeline* timeline = new Timeline(); timeline->appendPhase(phase); body->setTimeline(timeline); // Check for circular references in frames; this can only be done once the timeline // has actually been set. // TIMELINE-TODO: This check is not comprehensive; it won't find recursion in // multiphase timelines. if (newOrbitFrame && isFrameCircular(*body->getOrbitFrame(0.0), ReferenceFrame::PositionFrame)) { clog << "Orbit frame for " << body->getName() << " is nested too deep (probably circular)\n"; return false; } if (newBodyFrame && isFrameCircular(*body->getBodyFrame(0.0), ReferenceFrame::OrientationFrame)) { clog << "Body frame for " << body->getName() << " is nested too deep (probably circular)\n"; return false; } } return true; }
TimelinePhase* CreateTimelinePhase(Body* body, Universe& universe, Hash* phaseData, const string& path, ReferenceFrame* defaultOrbitFrame, ReferenceFrame* defaultBodyFrame, bool isFirstPhase, bool isLastPhase, double previousPhaseEnd) { double beginning = previousPhaseEnd; double ending = numeric_limits<double>::infinity(); // Beginning is optional for the first phase of a timeline, and not // allowed for the other phases, where beginning is always the ending // of the previous phase. bool hasBeginning = ParseDate(phaseData, "Beginning", beginning); if (!isFirstPhase && hasBeginning) { clog << "Error: Beginning can only be specified for initial phase of timeline.\n"; return NULL; } // Ending is required for all phases except for the final one. bool hasEnding = ParseDate(phaseData, "Ending", ending); if (!isLastPhase && !hasEnding) { clog << "Error: Ending is required for all timeline phases other than the final one.\n"; return NULL; } // Get the orbit reference frame. ReferenceFrame* orbitFrame; Value* frameValue = phaseData->getValue("OrbitFrame"); if (frameValue != NULL) { orbitFrame = CreateReferenceFrame(universe, frameValue, defaultOrbitFrame->getCenter(), body); if (orbitFrame == NULL) { return NULL; } } else { // No orbit frame specified; use the default frame. orbitFrame = defaultOrbitFrame; } orbitFrame->addRef(); // Get the body reference frame ReferenceFrame* bodyFrame; Value* bodyFrameValue = phaseData->getValue("BodyFrame"); if (bodyFrameValue != NULL) { bodyFrame = CreateReferenceFrame(universe, bodyFrameValue, defaultBodyFrame->getCenter(), body); if (bodyFrame == NULL) { orbitFrame->release(); return NULL; } } else { // No body frame specified; use the default frame. bodyFrame = defaultBodyFrame; } bodyFrame->addRef(); // Use planet units (AU for semimajor axis) if the center of the orbit // reference frame is a star. bool usePlanetUnits = orbitFrame->getCenter().star() != NULL; // Get the orbit Orbit* orbit = CreateOrbit(orbitFrame->getCenter(), phaseData, path, usePlanetUnits); if (!orbit) { clog << "Error: missing orbit in timeline phase.\n"; bodyFrame->release(); orbitFrame->release(); return NULL; } // Get the rotation model // TIMELINE-TODO: default rotation model is UniformRotation with a period // equal to the orbital period. Should we do something else? RotationModel* rotationModel = CreateRotationModel(phaseData, path, orbit->getPeriod()); if (!rotationModel) { // TODO: Should distinguish between a missing rotation model (where it's // appropriate to use a default one) and a bad rotation model (where // we should report an error.) rotationModel = new ConstantOrientation(Quaterniond::Identity()); } TimelinePhase* phase = TimelinePhase::CreateTimelinePhase(universe, body, beginning, ending, *orbitFrame, *orbit, *bodyFrame, *rotationModel); // Frame ownership transfered to phase; release local references orbitFrame->release(); bodyFrame->release(); return phase; }
// 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; }
/** Called once before traj processing. Set up reference info. */ Action::RetType Action_Rmsd::Init(ArgList& actionArgs, TopologyList* PFL, FrameList* FL, DataSetList* DSL, DataFileList* DFL, int debugIn) { // Check for keywords GetRmsKeywords( actionArgs ); DataFile* outfile = DFL->AddDataFile(actionArgs.GetStringKey("out"), actionArgs); // Reference keywords bool previous = actionArgs.hasKey("previous"); bool first = actionArgs.hasKey("first"); ReferenceFrame REF = FL->GetFrameFromArgs( actionArgs ); std::string reftrajname = actionArgs.GetStringKey("reftraj"); RefParm_ = PFL->GetParm( actionArgs ); // Per-res keywords perres_ = actionArgs.hasKey("perres"); if (perres_) { perresout_ = DFL->AddDataFile( actionArgs.GetStringKey("perresout") ); perresinvert_ = actionArgs.hasKey("perresinvert"); ResRange_.SetRange( actionArgs.GetStringKey("range") ); RefRange_.SetRange( actionArgs.GetStringKey("refrange") ); perresmask_ = actionArgs.GetStringKey("perresmask"); if (perresmask_.empty()) perresmask_.assign(""); else { // If perresmask does not start with ampersand, insert one. if (perresmask_[0] != '&') perresmask_ = '&' + perresmask_; } perrescenter_ = actionArgs.hasKey("perrescenter"); perresavg_ = DFL->AddDataFile( actionArgs.GetStringKey("perresavg") ); } // Get the RMS mask string for target std::string mask1 = GetRmsMasks(actionArgs); // Initialize reference if (InitRef(previous, first, UseMass(), Fit(), reftrajname, REF, RefParm_, mask1, actionArgs, "rmsd")) return Action::ERR; // Set RefParm for perres if not empty if (perres_ && RefParm_ == 0 && !REF.empty()) RefParm_ = REF.Parm(); // Set up the RMSD data set. rmsd_ = DSL->AddSet(DataSet::DOUBLE, actionArgs.GetStringNext(),"RMSD"); if (rmsd_==0) return Action::ERR; rmsd_->SetScalar( DataSet::M_RMS ); // Add dataset to data file list if (outfile != 0) outfile->AddSet( rmsd_ ); mprintf(" RMSD: (%s), reference is %s",TgtMask().MaskString(), RefModeString()); PrintRmsStatus(); // Per-residue RMSD info. if (perres_) { mprintf(" No-fit RMSD will also be calculated for "); if (ResRange_.Empty()) mprintf("each solute residue"); else mprintf("residues %s",ResRange_.RangeArg()); if (!RefRange_.Empty()) mprintf(" (reference residues %s)",RefRange_.RangeArg()); mprintf(" using mask [:X%s].\n",perresmask_.c_str()); if (perresout_ != 0) mprintf(" Per-residue output file is %s\n",perresout_->DataFilename().base()); if (perresavg_ != 0) mprintf(" Avg per-residue output file is %s\n",perresavg_->DataFilename().base()); if (perrescenter_) mprintf(" perrescenter: Each residue will be centered prior to RMS calc.\n"); if (perresinvert_) mprintf(" perresinvert: Frames will be written in rows instead of columns.\n"); } masterDSL_ = DSL; return Action::OK; }
// ReferenceAction::InitRef() int ReferenceAction::InitRef(bool previousIn, bool firstIn, bool massIn, bool fitIn, std::string const& reftrajname, ReferenceFrame const& REF, Topology* RefParm, std::string const& refmaskIn, ArgList& actionArgs, const char* call) { refmode_ = UNKNOWN_REF; previous_ = previousIn; if (firstIn || previous_) refmode_ = FIRST; else { if (REF.error()) return 1; if (REF.empty()) { if (!reftrajname.empty()) { if (RefParm == 0) { mprinterr("Error: %s: No parm found for reftraj %s. Make sure parm has been loaded.\n", call, reftrajname.c_str()); return 1; } refmode_ = REFTRAJ; } else { // No reference keywords specified. Default to first. mprintf("Warning: %s: No reference structure given. Defaulting to first.\n",call); refmode_ = FIRST; } } else refmode_ = REFFRAME; } // Set the reference mask expression refMask_.SetMaskString(refmaskIn); // Initialize reference if not 'first' if (refmode_ != FIRST) { if ( !reftrajname.empty() ) { // Reference trajectory if (SetRefMask( *RefParm, call )!=0) return 1; // Attempt to open reference traj. if (refTraj_.SetupTrajRead( reftrajname, actionArgs, RefParm)) { mprinterr("Error: %s: Could not set up reftraj %s\n", call, reftrajname.c_str()); return 1; } refFrame_.SetupFrameV(RefParm->Atoms(), refTraj_.TrajCoordInfo()); if (refTraj_.BeginTraj()) { mprinterr("Error: %s: Could not open reftraj %s\n", call, reftrajname.c_str()); return 1; } } else { // Reference Frame if (SetRefMask( REF.Parm(), call ) != 0) return 1; SetRefStructure( REF.Coord(), fitIn, massIn ); } } // Set reference mode string if (previous_) modeString_ = "previous frame"; else if (refmode_ == FIRST) modeString_ = "first frame"; else if (refmode_==REFTRAJ) modeString_ = "trajectory " + refTraj_.Traj().Filename().Full(); else // REFFRAME modeString_ = "\"" + REF.RefName() + "\""; modeString_ += " (" + refMask_.MaskExpression() + ")"; return 0; }
// 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_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; }
static bool isFrameCircular(const ReferenceFrame& frame, ReferenceFrame::FrameType frameType) { return frame.nestingDepth(MaxFrameDepth, frameType) > MaxFrameDepth; }