double WeightWrapper::getWeight(const Residue & r, Residue::ResidueType res_type) const { if (weight_mode_ == WeightWrapper::MONO) return r.getMonoWeight(res_type); else return r.getAverageWeight(res_type); }
Residue* PeptideBuilder::createResidue_(const String& type, const int id) { Residue* res = new Residue(type, String(id)); PDBAtom* nitrogen = new PDBAtom(PTE[Element::N], "N"); PDBAtom* carbona = new PDBAtom(PTE[Element::C], "CA"); PDBAtom* carbon = new PDBAtom(PTE[Element::C], "C"); // put CA into the starting position carbona->setPosition(Vector3( 0.00, 0.00, 0.0)); // insert N and C nitrogen->setPosition(Vector3(-1 * BOND_LENGTH_N_CA, 0.00, 0.00)); carbon->setPosition (Vector3(BOND_LENGTH_C_CA * (cos(Constants::PI * 71./180.)), 0.00, BOND_LENGTH_C_CA * (sin(Constants::PI * 71. / 180.)))); // insert atomes into residue/chain/protein res->insert(*nitrogen); res->insert(*carbona); res->insert(*carbon); // flag as an amino acid res->setProperty(Residue::PROPERTY__AMINO_ACID); // create the bonds nitrogen->createBond(*carbona)->setOrder(Bond::ORDER__SINGLE); carbona->createBond(*carbon)->setOrder(Bond::ORDER__SINGLE); return res; }
Hierarchy get_previous_residue(Residue rd) { // only handle simple case so far Hierarchy p = rd.get_parent(); Chain c = p.get_as_chain(); Hierarchy r = get_residue(c, rd.get_index() - 1); return r; }
Residue CG6p::to_cg(const Residue &r) const { auto foo = [this](const Residue &res, auto && names) { Residue r; r.m_cg = m_cg; r.name = res.name; for (auto &&name : names) { auto it = std::find_if(res.begin(), res.end(), [&name](auto &&atom) { return atom.name == name; }); std::ostringstream stream; stream << "jian::CG6p::to_cg error! Atom '" << name << "' not found"; if (it == res.end()) throw stream.str(); r.push_back(*it); } return r; }; const CompleteResidue &complete = CompleteResidue::instance(); if (is_cg(r)) { return r; } else { if (complete.lack_atoms(r)) { Residue res = r; complete(res); return foo(res, m_basic_atoms); } else { return foo(r, m_basic_atoms); } } }
void PeptideBuilder::setOmega_(Residue& resold, Residue& resnew, const Angle& omega) { PDBAtom* pcarbon = getAtomByName_(resold, "C"); PDBAtom* pnitrogen_n = getAtomByName_(resnew, "N"); Vector3 C_NN_axis =(pnitrogen_n->getPosition() - pcarbon->getPosition()).normalize(); // At this point, omega has been fixed to 180 degrees Matrix4x4 mat; mat.setRotation(Angle(omega-Angle(Constants::PI)), C_NN_axis); TransformationProcessor omegatrans(mat); // translate to 0|0|0 (needed for the rotation) Vector3 toOrigin = pnitrogen_n->getPosition(); TranslationProcessor translation; translation.setTranslation(((float)(-1.))*toOrigin); resnew.apply(translation); // rotate resnew.apply(omegatrans); // translate back to the correct position translation.setTranslation(toOrigin); resnew.apply(translation); return; }
const Residue* ResidueDB::getModifiedResidue(const Residue* residue, const String& modification) { OPENMS_PRECONDITION(!modification.empty(), "Modification cannot be empty") // search if the mod already exists String res_name = residue->getName(); if (residue_names_.find(res_name) == residue_names_.end()) { throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, String("Residue with name " + res_name + " was not registered in residue DB, register first!").c_str()); } // terminal mods. don't apply to residue (side chain), so don't consider them: const ResidueModification& mod = ModificationsDB::getInstance()->getModification(modification, residue->getOneLetterCode(), ResidueModification::ANYWHERE); String id = mod.getId(); if (id.empty()) id = mod.getFullId(); if (residue_mod_names_.has(res_name) && residue_mod_names_[res_name].has(id)) { return residue_mod_names_[res_name][id]; } Residue* res = new Residue(*residue_names_[res_name]); res->setModification_(mod); //res->setLossFormulas(vector<EmpiricalFormula>()); //res->setLossNames(vector<String>()); // now register this modified residue addResidue_(res); return res; }
Residue make_residue(const string &name, const Mat &coords) { Residue residue; residue.name = name; for (int i = 0; i < coords.rows(); i++) { residue.push_back(Atom(_atom_names[name][i], coords(i, 0), coords(i, 1), coords(i, 2))); } return residue; }
Hierarchy get_next_residue(Residue rd) { // only handle simple case so far Hierarchy p = rd.get_parent(); /*if (!p.get_as_chain()) { IMP_NOT_IMPLEMENTED("get_next_residue() only handles the simple case" << " so far. Complain about it."); }*/ IMP_USAGE_CHECK(Chain::get_is_setup(p), "Parent of residue must be a chain. It is not."); Hierarchy r = get_residue(Chain(p), rd.get_index() + 1); return r; }
void LSQFitDialog::ListTarget() { if (m_target) { Residue *res = m_target->residuesBegin(); QListWidget *list = targetListWidget; list->clear(); while (res != NULL) { list->addItem(resid(res).c_str()); res = res->next(); } } }
void getchain(unsigned short chain_id, Residue *reslist, Residue* &nter, Residue* &cter) { nter = cter = NULL; Residue *res = reslist; while ((res != NULL) && res->chain_id() != chain_id) { res = res->next(); } nter = res; while ((res != NULL) && res->chain_id() == chain_id) { cter = res; res = res->next(); } }
AtomPointerVector PDBTopology::getBackboneAtoms(Residue &_res){ AtomPointerVector results; map<string,bool>::iterator it; for (it = backboneAtoms.begin();it != backboneAtoms.end();it++){ if (it->second && _res.atomExists(it->first)){ results.push_back(&_res.getAtom(it->first)); } else { if (it->second){ MSLOUT.stream() << " getBackboneAtoms(Residue) , residue "<<_res.toString()<<" does not have backbone atom '"<<it->second<<"'"<<endl; } } } return results; }
void XMLArchive::WriteField(const Residue &res) { /* write a RESIDUE field */ tags.push_back("Residue"); calc_indent(); char secstr = res.secstr(); // this fixes a wierd bug - if these happen to be 0 - disaster! if (!isalpha(secstr)) { secstr = 'U'; } if (!isalpha(res.name1())) { secstr = 'X'; } f = format("%s<Residue name=\"%s\" type=\"%s\" chain=\"%d\" secstr=\"%c\" confomer=\"%d\" flags=\"%d\" linkage_type=\"%d\" name1=\"%c\" seqpos=\"%d\" >\n", indent, res.name().c_str(), res.type().c_str(), (int)res.chain_id(), secstr, (int)res.confomer(), (int)res.flags(), (int)res.linkage_type(), res.name1(), res.seqpos()); Write(f); inTag++; for (int i = 0; i < res.atomCount(); i++) { WriteField(res.atom(i)); } EndTag(); }
bool LSQFitDialog::MatchOK(MATCH *m) { Residue *res = m->target; int n = 0; while ((res != NULL) && n < m->length) { if (!atom_from_name(m->atomtype.c_str(), *res)) { break; } n++; res = res->next(); } if (n < m->length) { m->length = n; } if (m->length <= 0) { return false; } res = m->source; n = 0; while ((res != NULL) && n < m->length) { if (!atom_from_name(m->atomtype.c_str(), *res)) { break; } n++; res = res->next(); } if (n < m->length) { m->length = n; } if (m->length <= 0) { return false; } return true; }
void read(Residue &res) { char c; read(res.name, res.num, res.m_cg); while (true) { read(c); if (c == 'r') { return; } else if (c == 'A') { res.push_back(Atom{}); read(res.back()); } else { throw "This is not a standard '.jn' file! Illegal " + c; } } }
Atom get_atom(Residue rd, AtomType at) { Hierarchy mhd(rd.get_particle()); for (unsigned int i=0; i< mhd.get_number_of_children(); ++i) { Atom a(mhd.get_child(i)); if (a.get_atom_type() == at) return a; } IMP_LOG(VERBOSE, "Atom not found " << at << std::endl); return Atom(); }
void PeptideBuilder::peptide_(Residue& resold, Residue& resnew) { PDBAtom* poxygen = new PDBAtom(PTE[Element::O], "O"); // dynamic_cast<PDBAtom*>(resold->getAtom("C")); ????? PDBAtom* pcarbon = getAtomByName_(resold, "C"); PDBAtom* pcarbona = getAtomByName_(resold, "CA"); PDBAtom* pnitrogen_n = getAtomByName_(resnew, "N"); Vector3 CA_C_axis =(pcarbon->getPosition() - pcarbona->getPosition()).normalize(); Vector3 C_NN_axis =(pnitrogen_n->getPosition() - pcarbon->getPosition()).normalize(); Matrix4x4 mat; mat.setRotation(Angle(Constants::PI), CA_C_axis); Vector3 newpos = mat * C_NN_axis; // newpos = mat * newpos; newpos = newpos.normalize() * BOND_LENGTH_C_O + pcarbon->getPosition(); //newpos= pcarbon->getPosition(); poxygen->setPosition(newpos); //set C-O-bond (pcarbon->createBond(*poxygen))->setOrder(Bond::ORDER__DOUBLE); resold.insert(*poxygen); //----------set hydrogen. We can't do this for proline, // since in this case, this hydrogen doesn't exist if (!is_proline_) { PDBAtom* phydrogen = new PDBAtom(PTE[Element::H], "H"); pcarbon = getAtomByName_(resold, "C"); pnitrogen_n = getAtomByName_(resnew, "N"); poxygen = getAtomByName_(resold, "O"); newpos = (pcarbon->getPosition() - poxygen->getPosition()).normalize(); newpos = newpos * BOND_LENGTH_N_H + pnitrogen_n->getPosition(); phydrogen->setPosition(newpos); phydrogen->createBond(*pnitrogen_n)->setOrder(Bond::ORDER__SINGLE);; resnew.insert(*phydrogen); } return; }
Residue * Molecule::addResidue(unsigned long id) { Q_D(Molecule); Residue *residue = new Residue(this); if (id >= d->residues.size()) d->residues.resize(id+1,0); d->residues[id] = residue; d->residueList.push_back(residue); residue->setId(id); residue->setIndex(d->residueList.size()-1); // now that the id is correct, emit the signal connect(residue, SIGNAL(updated()), this, SLOT(updatePrimitive())); emit primitiveAdded(residue); return(residue); }
void LSQFitDialog::on_targetListWidget_currentTextChanged(const QString &str) { if (m_target == NULL || str.size()==0) { targetres = NULL; targetTextCtrl->setText(""); return; } std::string resstr = str.toStdString(); Residue *res = m_target->residuesBegin(); while (res != NULL) { if (resid(res) == resstr) { targetres = res; } res = res->next(); } targetTextCtrl->setText(resstr.c_str()); }
void RibbonEngine::updateChains(PainterDevice *pd) { if (!isEnabled()) return; m_chains.clear(); QList<Primitive *> list; list = primitives().subList(Primitive::ResidueType); unsigned int currentChain = 0; QVector<Vector3d> pts; // Get a list of residues for the molecule const Molecule *molecule = pd->molecule(); foreach(Primitive *p, list) { Residue *r = static_cast<Residue *>(p); if(r->name() =="HOH") { continue; } if(r->chainNumber() != currentChain) { // this residue is on a new chain if(pts.size() > 0) m_chains.push_back(pts); currentChain = r->chainNumber(); pts.clear(); } foreach (unsigned long atom, r->atoms()) { // should be CA QString atomId = r->atomId(atom); atomId = atomId.trimmed(); if (atomId == "CA") { pts.push_back(*molecule->atomById(atom)->pos()); } else if (atomId == "N" && m_useNitrogens == 2) { pts.push_back(*molecule->atomById(atom)->pos()); } } // end atoms in residue } // end primitive list (i.e., all residues)
void _MatchItemImp::paintSeq(QPainter * p, int width) { const int w = g_textWidth; const int ww = width; // Root::Math::max( width, ( d_match.d_fits.size() + 1 ) * w ); const int h = height(); int x = 0; p->fillRect( 0, 0, ww, h , Qt::lightGray ); if( d_match.d_start->getPred() && d_match.d_lJoker != -1.0 ) { int dy = h * d_match.d_lJoker; p->fillRect( x, h - dy, w, dy , Qt::green ); d_match.d_start->getPred()->formatLabel( s_buf, sizeof(s_buf) ); p->setPen( Qt::black ); p->drawText( x, 0, w, h, Qt::AlignCenter, s_buf ); if( d_match.d_start->getPred()->getSystem() != 0 ) p->fillRect( x, 0, 3, 3, Qt::black ); } p->setPen( Qt::white ); p->drawLine( x + w - 1, 0, x + w - 1, h - 1 ); x += w; Residue* resi = d_match.d_start; for( int i = 0; i < d_match.d_fits.size(); i++ ) { assert( resi ); int dy = h * d_match.d_fits[ i ]; p->fillRect( x, h - dy, w, dy , Qt::green ); resi->formatLabel( s_buf, sizeof(s_buf) ); p->setPen( Qt::black ); p->drawText( x, 0, w, h, Qt::AlignCenter, s_buf ); if( resi->getSystem() != 0 ) p->fillRect( x, 0, 3, 3, Qt::black ); p->setPen( Qt::white ); p->drawLine( x + w - 1, 0, x + w - 1, h - 1 ); x += w; resi = resi->getSucc(); } if( resi && d_match.d_rJoker != -1.0 ) { int dy = h * d_match.d_rJoker; p->fillRect( x, h - dy, w, dy , Qt::green ); resi->formatLabel( s_buf, sizeof(s_buf) ); p->setPen( Qt::black ); p->drawText( x, 0, w, h, Qt::AlignCenter, s_buf ); if( resi->getSystem() ) p->fillRect( x, 0, 3, 3, Qt::black ); p->setPen( Qt::white ); p->drawLine( x + w - 1, 0, x + w - 1, h - 1 ); } p->setPen( Qt::white ); p->drawLine( 0, h - 1, ww - 1, h - 1 ); }
double Action_Spam::Calculate_Energy(Frame *frameIn, Residue const& res) { // The first atom of the solvent residue we want the energy from double result = 0; /* Now loop through all atoms in the residue and loop through the pairlist to * get the energies */ for (int i = res.FirstAtom(); i < res.LastAtom(); i++) { Vec3 atm1 = Vec3(frameIn->XYZ(i)); for (int j = 0; j < CurrentParm_.Natom(); j++) { if (j >= res.FirstAtom() && j < res.LastAtom()) continue; Vec3 atm2 = Vec3(frameIn->XYZ(j)); double dist2; // Get imaged distance Matrix_3x3 ucell, recip; switch( ImageType() ) { case NONORTHO: frameIn->BoxCrd().ToRecip(ucell, recip); dist2 = DIST2_ImageNonOrtho(atm1, atm2, ucell, recip); break; case ORTHO: dist2 = DIST2_ImageOrtho(atm1, atm2, frameIn->BoxCrd()); break; default: dist2 = DIST2_NoImage(atm1, atm2); } if (dist2 < cut2_) { double qiqj = atom_charge_[i] * atom_charge_[j]; NonbondType const& LJ = CurrentParm_.GetLJparam(i, j); double r2 = 1 / dist2; double r6 = r2 * r2 * r2; // Shifted electrostatics: qiqj/r * (1-r/rcut)^2 + VDW double shift = (1 - dist2 * onecut2_); result += qiqj / sqrt(dist2) * shift * shift + LJ.A() * r6 * r6 - LJ.B() * r6; } } } return result; }
void LSQFitDialog::ListSource() { if (m_source) { Residue *res = m_source->residuesBegin(); QListWidget *list = sourceListWidget; QComboBox *chains = chainsChoice; list->clear(); chains->clear(); int chainid = -9921; while (res != NULL) { if (res->chain_id() != chainid) { chainid = res->chain_id(); char cid = (char) chainid; chains->addItem(QString(cid)); } list->addItem(resid(res).c_str()); res = res->next(); } } }
Processor::Result ResidueChecker::operator () (Residue& residue) { String res_name; if ((residue.getChain() != 0) && (residue.getChain()->getName() != BALL_CHAIN_DEFAULT_NAME)) { res_name = residue.getChain()->getName() + ":"; } res_name += residue.getName() + ":" + residue.getID(); // Check charges. status_ &= checkCharge(residue, res_name); // Check atom positions. status_ &= checkAtomPositions(residue, res_name); // if a fragment data base is defined, check for completeness // of the residue if (fragment_db_ != 0) { const Residue* reference = dynamic_cast<const Residue*>(fragment_db_->getReferenceFragment(residue)); if (reference == 0) { if (isEnabled(UNKNOWN_RESIDUES)) { Log.warn() << "ResidueChecker: didn't find a reference fragment for " << res_name << endl; status_ = false; // If selection is enabled, mark the whol residue if (selection_) { residue.select(); } } } else { status_ &= checkCompleteness(residue, *reference, res_name); status_ &= checkTemplate(residue, *reference, res_name); } } return Processor::CONTINUE; }
ExitCodes main_(int, const char**) { vector<ProteinIdentification> prot_ids; vector<PeptideIdentification> pep_ids; ProteinHit temp_protein_hit; //------------------------------------------------------------- // parsing parameters //------------------------------------------------------------- String inputfile_id = getStringOption_("id"); String inputfile_feature = getStringOption_("feature"); String inputfile_consensus = getStringOption_("consensus"); String inputfile_raw = getStringOption_("in"); String outputfile_name = getStringOption_("out"); //~ bool Ms1(getFlag_("MS1")); //~ bool Ms2(getFlag_("MS2")); bool remove_duplicate_features(getFlag_("remove_duplicate_features")); //------------------------------------------------------------- // fetch vocabularies //------------------------------------------------------------ ControlledVocabulary cv; cv.loadFromOBO("PSI-MS", File::find("/CV/psi-ms.obo")); cv.loadFromOBO("QC", File::find("/CV/qc-cv.obo")); QcMLFile qcmlfile; //------------------------------------------------------------- // MS aqiusition //------------------------------------------------------------ String base_name = QFileInfo(QString::fromStdString(inputfile_raw)).baseName(); cout << "Reading mzML file..." << endl; MzMLFile mz_data_file; MSExperiment<Peak1D> exp; MzMLFile().load(inputfile_raw, exp); //---prep input exp.sortSpectra(); UInt min_mz = std::numeric_limits<UInt>::max(); UInt max_mz = 0; std::map<Size, UInt> mslevelcounts; qcmlfile.registerRun(base_name,base_name); //TODO use UIDs //---base MS aquisition qp String msaq_ref = base_name + "_msaq"; QcMLFile::QualityParameter qp; qp.id = msaq_ref; ///< Identifier qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000004"; try { //~ const ControlledVocabulary::CVTerm& test = cv.getTermByName("MS aquisition result details"); //~ cout << test.name << test.id << endl; const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); //~ const ControlledVocabulary::CVTerm& term = cv.getTerm("0000004"); qp.name = term.name; ///< Name } catch (...) { qp.name = "mzML file"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); //---file origin qp qp = QcMLFile::QualityParameter(); qp.name = "mzML file"; ///< Name qp.id = base_name + "_run_name"; ///< Identifier qp.cvRef = "MS"; ///< cv reference qp.cvAcc = "MS:1000577"; qp.value = base_name; qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.name = "instrument model"; ///< Name qp.id = base_name + "_instrument_name"; ///< Identifier qp.cvRef = "MS"; ///< cv reference qp.cvAcc = "MS:1000031"; qp.value = exp.getInstrument().getName(); qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.name = "completion time"; ///< Name qp.id = base_name + "_date"; ///< Identifier qp.cvRef = "MS"; ///< cv reference qp.cvAcc = "MS:1000747"; qp.value = exp.getDateTime().getDate(); qcmlfile.addRunQualityParameter(base_name, qp); //---precursors at QcMLFile::Attachment at; at.cvRef = "QC"; ///< cv reference at.cvAcc = "QC:0000044"; at.qualityRef = msaq_ref; at.id = base_name + "_precursors"; ///< Identifier try { const ControlledVocabulary::CVTerm& term = cv.getTerm(at.cvAcc); at.name = term.name; ///< Name } catch (...) { at.name = "precursors"; ///< Name } at.colTypes.push_back("MS:1000894_[sec]"); //RT at.colTypes.push_back("MS:1000040"); //MZ for (Size i = 0; i < exp.size(); ++i) { mslevelcounts[exp[i].getMSLevel()]++; if (exp[i].getMSLevel() == 2) { if (exp[i].getPrecursors().front().getMZ() < min_mz) { min_mz = exp[i].getPrecursors().front().getMZ(); } if (exp[i].getPrecursors().front().getMZ() > max_mz) { max_mz = exp[i].getPrecursors().front().getMZ(); } std::vector<String> row; row.push_back(exp[i].getRT()); row.push_back(exp[i].getPrecursors().front().getMZ()); at.tableRows.push_back(row); } } qcmlfile.addRunAttachment(base_name, at); //---aquisition results qp qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000006"; ///< cv accession for "aquisition results" qp.id = base_name + "_ms1aquisition"; ///< Identifier qp.value = String(mslevelcounts[1]); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "number of ms1 spectra"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000007"; ///< cv accession for "aquisition results" qp.id = base_name + "_ms2aquisition"; ///< Identifier qp.value = String(mslevelcounts[2]); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "number of ms2 spectra"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000008"; ///< cv accession for "aquisition results" qp.id = base_name + "_Chromaquisition"; ///< Identifier qp.value = String(exp.getChromatograms().size()); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "number of chromatograms"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); at = QcMLFile::Attachment(); at.cvRef = "QC"; ///< cv reference at.cvAcc = "QC:0000009"; at.qualityRef = msaq_ref; at.id = base_name + "_mzrange"; ///< Identifier try { const ControlledVocabulary::CVTerm& term = cv.getTerm(at.cvAcc); at.name = term.name; ///< Name } catch (...) { at.name = "MS MZ aquisition ranges"; ///< Name } at.colTypes.push_back("QC:0000010"); //MZ at.colTypes.push_back("QC:0000011"); //MZ std::vector<String> rowmz; rowmz.push_back(String(min_mz)); rowmz.push_back(String(max_mz)); at.tableRows.push_back(rowmz); qcmlfile.addRunAttachment(base_name, at); at = QcMLFile::Attachment(); at.cvRef = "QC"; ///< cv reference at.cvAcc = "QC:0000012"; at.qualityRef = msaq_ref; at.id = base_name + "_rtrange"; ///< Identifier try { const ControlledVocabulary::CVTerm& term = cv.getTerm(at.cvAcc); at.name = term.name; ///< Name } catch (...) { at.name = "MS RT aquisition ranges"; ///< Name } at.colTypes.push_back("QC:0000013"); //MZ at.colTypes.push_back("QC:0000014"); //MZ std::vector<String> rowrt; rowrt.push_back(String(exp.begin()->getRT())); rowrt.push_back(String(exp.getSpectra().back().getRT())); at.tableRows.push_back(rowrt); qcmlfile.addRunAttachment(base_name, at); //---ion current stability ( & tic ) qp at = QcMLFile::Attachment(); at.cvRef = "QC"; ///< cv reference at.cvAcc = "QC:0000022"; at.qualityRef = msaq_ref; at.id = base_name + "_tics"; ///< Identifier try { const ControlledVocabulary::CVTerm& term = cv.getTerm(at.cvAcc); at.name = term.name; ///< Name } catch (...) { at.name = "MS TICs"; ///< Name } at.colTypes.push_back("MS:1000894_[sec]"); at.colTypes.push_back("MS:1000285"); UInt max = 0; Size below_10k = 0; for (Size i = 0; i < exp.size(); ++i) { if (exp[i].getMSLevel() == 1) { UInt sum = 0; for (Size j = 0; j < exp[i].size(); ++j) { sum += exp[i][j].getIntensity(); } if (sum > max) { max = sum; } if (sum < 10000) { ++below_10k; } std::vector<String> row; row.push_back(exp[i].getRT()); row.push_back(sum); at.tableRows.push_back(row); } } qcmlfile.addRunAttachment(base_name, at); qp = QcMLFile::QualityParameter(); qp.id = base_name + "_ticslump"; ///< Identifier qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000023"; qp.value = String((100 / exp.size()) * below_10k); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "percentage of tic slumps"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); //------------------------------------------------------------- // MS id //------------------------------------------------------------ if (inputfile_id != "") { IdXMLFile().load(inputfile_id, prot_ids, pep_ids); cerr << "idXML read ended. Found " << pep_ids.size() << " peptide identifications." << endl; ProteinIdentification::SearchParameters params = prot_ids[0].getSearchParameters(); vector<String> var_mods = params.variable_modifications; //~ boost::regex re("(?<=[KR])(?=[^P])"); String msid_ref = base_name + "_msid"; QcMLFile::QualityParameter qp; qp.id = msid_ref; ///< Identifier qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000025"; try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "MS identification result details"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); at = QcMLFile::Attachment(); at.cvRef = "QC"; ///< cv reference at.cvAcc = "QC:0000026"; at.qualityRef = msid_ref; at.id = base_name + "_idsetting"; ///< Identifier try { const ControlledVocabulary::CVTerm& term = cv.getTerm(at.cvAcc); at.name = term.name; ///< Name } catch (...) { at.name = "MS id settings"; ///< Name } at.colTypes.push_back("MS:1001013"); //MS:1001013 db name MS:1001016 version MS:1001020 taxonomy at.colTypes.push_back("MS:1001016"); at.colTypes.push_back("MS:1001020"); std::vector<String> row; row.push_back(String(prot_ids.front().getSearchParameters().db)); row.push_back(String(prot_ids.front().getSearchParameters().db_version)); row.push_back(String(prot_ids.front().getSearchParameters().taxonomy)); at.tableRows.push_back(row); qcmlfile.addRunAttachment(base_name, at); UInt spectrum_count = 0; Size peptide_hit_count = 0; UInt runs_count = 0; Size protein_hit_count = 0; set<String> peptides; set<String> proteins; Size missedcleavages = 0; for (Size i = 0; i < pep_ids.size(); ++i) { if (!pep_ids[i].empty()) { ++spectrum_count; peptide_hit_count += pep_ids[i].getHits().size(); const vector<PeptideHit>& temp_hits = pep_ids[i].getHits(); for (Size j = 0; j < temp_hits.size(); ++j) { peptides.insert(temp_hits[j].getSequence().toString()); } } } for (set<String>::iterator it = peptides.begin(); it != peptides.end(); ++it) { for (String::const_iterator st = it->begin(); st != it->end() - 1; ++st) { if (*st == 'K' || *st == 'R') { ++missedcleavages; } } } for (Size i = 0; i < prot_ids.size(); ++i) { ++runs_count; protein_hit_count += prot_ids[i].getHits().size(); const vector<ProteinHit>& temp_hits = prot_ids[i].getHits(); for (Size j = 0; j < temp_hits.size(); ++j) { proteins.insert(temp_hits[j].getAccession()); } } qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000037"; ///< cv accession qp.id = base_name + "_misscleave"; ///< Identifier qp.value = missedcleavages; try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "total number of missed cleavages"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000032"; ///< cv accession qp.id = base_name + "_totprot"; ///< Identifier qp.value = protein_hit_count; try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "total number of identified proteins"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000033"; ///< cv accession qp.id = base_name + "_totuniqprot"; ///< Identifier qp.value = String(proteins.size()); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "total number of uniquely identified proteins"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000029"; ///< cv accession qp.id = base_name + "_psms"; ///< Identifier qp.value = String(spectrum_count); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "total number of PSM"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000030"; ///< cv accession qp.id = base_name + "_totpeps"; ///< Identifier qp.value = String(peptide_hit_count); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "total number of identified peptides"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000031"; ///< cv accession qp.id = base_name + "_totuniqpeps"; ///< Identifier qp.value = String(peptides.size()); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "total number of uniquely identified peptides"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); at = QcMLFile::Attachment(); at.cvRef = "QC"; ///< cv reference at.cvAcc = "QC:0000038"; at.qualityRef = msid_ref; at.id = base_name + "_massacc"; ///< Identifier try { const ControlledVocabulary::CVTerm& term = cv.getTerm(at.cvAcc); at.name = term.name; ///< Name } catch (...) { at.name = "delta ppm tables"; } //~ delta ppm QC:0000039 RT MZ uniqueness ProteinID MS:1000885 target/decoy Score PeptideSequence MS:1000889 Annots string Similarity Charge UO:0000219 TheoreticalWeight UO:0000221 Oxidation_(M) at.colTypes.push_back("RT"); at.colTypes.push_back("MZ"); at.colTypes.push_back("Score"); at.colTypes.push_back("PeptideSequence"); at.colTypes.push_back("Charge"); at.colTypes.push_back("TheoreticalWeight"); at.colTypes.push_back("delta_ppm"); for (UInt w = 0; w < var_mods.size(); ++w) { at.colTypes.push_back(String(var_mods[w]).substitute(' ', '_')); } std::vector<double> deltas; //~ prot_ids[0].getSearchParameters(); for (vector<PeptideIdentification>::iterator it = pep_ids.begin(); it != pep_ids.end(); ++it) { if (it->getHits().size() > 0) { std::vector<String> row; row.push_back(it->getRT()); row.push_back(it->getMZ()); PeptideHit tmp = it->getHits().front(); //TODO depends on score & sort vector<UInt> pep_mods; for (UInt w = 0; w < var_mods.size(); ++w) { pep_mods.push_back(0); } for (AASequence::ConstIterator z = tmp.getSequence().begin(); z != tmp.getSequence().end(); ++z) { Residue res = *z; String temp; if (res.getModification().size() > 0 && res.getModification() != "Carbamidomethyl") { temp = res.getModification() + " (" + res.getOneLetterCode() + ")"; //cout<<res.getModification()<<endl; for (UInt w = 0; w < var_mods.size(); ++w) { if (temp == var_mods[w]) { //cout<<temp; pep_mods[w] += 1; } } } } row.push_back(tmp.getScore()); row.push_back(tmp.getSequence().toString().removeWhitespaces()); row.push_back(tmp.getCharge()); row.push_back(String((tmp.getSequence().getMonoWeight() + tmp.getCharge() * Constants::PROTON_MASS_U) / tmp.getCharge())); double dppm = /* std::abs */ (getMassDifference(((tmp.getSequence().getMonoWeight() + tmp.getCharge() * Constants::PROTON_MASS_U) / tmp.getCharge()), it->getMZ(), true)); row.push_back(String(dppm)); deltas.push_back(dppm); for (UInt w = 0; w < var_mods.size(); ++w) { row.push_back(pep_mods[w]); } at.tableRows.push_back(row); } } qcmlfile.addRunAttachment(base_name, at); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000040"; ///< cv accession qp.id = base_name + "_mean_delta"; ///< Identifier qp.value = String(OpenMS::Math::mean(deltas.begin(), deltas.end())); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "mean delta ppm"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000041"; ///< cv accession qp.id = base_name + "_median_delta"; ///< Identifier qp.value = String(OpenMS::Math::median(deltas.begin(), deltas.end(), false)); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "median delta ppm"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000035"; ///< cv accession qp.id = base_name + "_ratio_id"; ///< Identifier qp.value = String(double(pep_ids.size()) / double(mslevelcounts[2])); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "id ratio"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); } //------------------------------------------------------------- // MS quantitation //------------------------------------------------------------ FeatureMap map; String msqu_ref = base_name + "_msqu"; if (inputfile_feature != "") { FeatureXMLFile f; f.load(inputfile_feature, map); cout << "Read featureXML file..." << endl; //~ UInt fiter = 0; map.sortByRT(); map.updateRanges(); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000045"; ///< cv accession qp.id = msqu_ref; ///< Identifier try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "MS quantification result details"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); qp = QcMLFile::QualityParameter(); qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:0000046"; ///< cv accession qp.id = base_name + "_feature_count"; ///< Identifier qp.value = String(map.size()); try { const ControlledVocabulary::CVTerm& term = cv.getTerm(qp.cvAcc); qp.name = term.name; ///< Name } catch (...) { qp.name = "number of features"; ///< Name } qcmlfile.addRunQualityParameter(base_name, qp); } if (inputfile_feature != "" && !remove_duplicate_features) { QcMLFile::Attachment at; at = QcMLFile::Attachment(); at.cvRef = "QC"; ///< cv reference at.cvAcc = "QC:0000047"; at.qualityRef = msqu_ref; at.id = base_name + "_features"; ///< Identifier try { const ControlledVocabulary::CVTerm& term = cv.getTerm(at.cvAcc); at.name = term.name; ///< Name } catch (...) { at.name = "features"; ///< Name } at.colTypes.push_back("MZ"); at.colTypes.push_back("RT"); at.colTypes.push_back("Intensity"); at.colTypes.push_back("Charge"); at.colTypes.push_back("Quality"); at.colTypes.push_back("FWHM"); at.colTypes.push_back("IDs"); UInt fiter = 0; map.sortByRT(); //ofstream out(outputfile_name.c_str()); while (fiter < map.size()) { std::vector<String> row; row.push_back(map[fiter].getMZ()); row.push_back(map[fiter].getRT()); row.push_back(map[fiter].getIntensity()); row.push_back(map[fiter].getCharge()); row.push_back(map[fiter].getOverallQuality()); row.push_back(map[fiter].getWidth()); row.push_back(map[fiter].getPeptideIdentifications().size()); fiter++; at.tableRows.push_back(row); } qcmlfile.addRunAttachment(base_name, at); } else if (inputfile_feature != "" && remove_duplicate_features) { QcMLFile::Attachment at; at = QcMLFile::Attachment(); at.cvRef = "QC"; ///< cv reference at.cvAcc = "QC:0000047"; at.qualityRef = msqu_ref; at.id = base_name + "_features"; ///< Identifier try { const ControlledVocabulary::CVTerm& term = cv.getTerm(at.cvAcc); at.name = term.name; ///< Name } catch (...) { at.name = "features"; ///< Name } at.colTypes.push_back("MZ"); at.colTypes.push_back("RT"); at.colTypes.push_back("Intensity"); at.colTypes.push_back("Charge"); FeatureMap map, map_out; FeatureXMLFile f; f.load(inputfile_feature, map); UInt fiter = 0; map.sortByRT(); while (fiter < map.size()) { FeatureMap map_tmp; for (UInt k = fiter; k <= map.size(); ++k) { if (abs(map[fiter].getRT() - map[k].getRT()) < 0.1) { //~ cout << fiter << endl; map_tmp.push_back(map[k]); } else { fiter = k; break; } } map_tmp.sortByMZ(); UInt retif = 1; map_out.push_back(map_tmp[0]); while (retif < map_tmp.size()) { if (abs(map_tmp[retif].getMZ() - map_tmp[retif - 1].getMZ()) > 0.01) { cout << "equal RT, but mass different" << endl; map_out.push_back(map_tmp[retif]); } retif++; } } qcmlfile.addRunAttachment(base_name, at); } if (inputfile_consensus != "") { cout << "Reading consensusXML file..." << endl; ConsensusXMLFile f; ConsensusMap map; f.load(inputfile_consensus, map); //~ String CONSENSUS_NAME = "_consensus.tsv"; //~ String combined_out = outputfile_name + CONSENSUS_NAME; //~ ofstream out(combined_out.c_str()); at = QcMLFile::Attachment(); qp.name = "consensuspoints"; ///< Name //~ qp.id = base_name + "_consensuses"; ///< Identifier qp.cvRef = "QC"; ///< cv reference qp.cvAcc = "QC:xxxxxxxx"; ///< cv accession "featuremapper results" at.colTypes.push_back("Native_spectrum_ID"); at.colTypes.push_back("DECON_RT_(sec)"); at.colTypes.push_back("DECON_MZ_(Th)"); at.colTypes.push_back("DECON_Intensity"); at.colTypes.push_back("Feature_RT_(sec)"); at.colTypes.push_back("Feature_MZ_(Th)"); at.colTypes.push_back("Feature_Intensity"); at.colTypes.push_back("Feature_Charge"); for (ConsensusMap::const_iterator cmit = map.begin(); cmit != map.end(); ++cmit) { const ConsensusFeature& CF = *cmit; for (ConsensusFeature::const_iterator cfit = CF.begin(); cfit != CF.end(); ++cfit) { std::vector<String> row; FeatureHandle FH = *cfit; row.push_back(CF.getMetaValue("spectrum_native_id")); row.push_back(CF.getRT()); row.push_back(CF.getMZ()); row.push_back(CF.getIntensity()); row.push_back(FH.getRT()); row.push_back(FH.getMZ()); row.push_back(FH.getCharge()); at.tableRows.push_back(row); } } qcmlfile.addRunAttachment(base_name, at); } //------------------------------------------------------------- // finalize //------------------------------------------------------------ qcmlfile.store(outputfile_name); return EXECUTION_OK; }
void write_pdb(const ParticlesTemp& ps, TextOutput out) { IMP_FUNCTION_LOG; int last_index = 0; bool use_input_index = true; for (unsigned int i = 0; i < ps.size(); ++i) { if (Atom(ps[i]).get_input_index() != last_index + 1) { use_input_index = false; break; } else { ++last_index; } } for (unsigned int i = 0; i < ps.size(); ++i) { if (Atom::get_is_setup(ps[i])) { Atom ad(ps[i]); Residue rd = get_residue(ad); // really dumb and slow, fix later char chain; Chain c = get_chain(rd); if (c) { chain = c.get_id()[0]; } else { chain = ' '; } int inum = i+1; if (i>=99999) inum=99999; out.get_stream() << get_pdb_string( core::XYZ(ps[i]).get_coordinates(), use_input_index ? ad.get_input_index() : static_cast<int>(inum), ad.get_atom_type(), rd.get_residue_type(), chain, rd.get_index(), rd.get_insertion_code(), ad.get_occupancy(), ad.get_temperature_factor(), ad.get_element()); if (!out) { IMP_THROW("Error writing to file in write_pdb", IOException); } } else if (Residue::get_is_setup(ps[i])) { // if C-alpha residue is available Residue rd = IMP::atom::Residue(ps[i]); // comment 1 by SJ - TODO: How to retrieve the correct chain information without an hierarchy? char chain; Chain c = get_chain(rd); if (c) { chain = c.get_id()[0]; } else { chain = ' '; } // comment 2 by SJ - TODO: The C-alpha residues are not sorted yet. We need to sort the residues similarly to what PMI does. out.get_stream() << get_pdb_string( core::XYZ(ps[i]).get_coordinates(), static_cast<int>(i + 1), IMP::atom::AT_CA, rd.get_residue_type(), chain, rd.get_index(), ' ', 1.0, IMP::core::XYZR(ps[i]).get_radius()); } else { // if a coarse-grained BEAD is available Ints resindexes = IMP::atom::Fragment(ps[i]).get_residue_indexes(); int resindex = (int)resindexes.front() + (int)(resindexes.size()/2); // comment 1 by SJ - TODO: How to retrieve the correct chain information without an hierarchy? char chain = ' '; // comment 3 by SJ - TODO: The BEADs are not sorted yet. We need to sort the residues similarly to what PMI does. // comment 4 by SJ - TODO: currently IMP does not allow "BEA" as a residue name, while PMI allows it. Thus "UNK" was used instead. out.get_stream() << get_pdb_string( core::XYZ(ps[i]).get_coordinates(), static_cast<int>(i + 1), IMP::atom::AT_CA, IMP::atom::UNK, chain, (int)resindex, ' ', 1.0, IMP::core::XYZR(ps[i]).get_radius()); } } }
// Organizes the the data by chains void PDB::populateChains(bool center) { // Flag to hold the current chain id char chainID = '-'; // Index for the chain int chainIndex = -1; vector<char>chainIDs; // Go through each atom for(unsigned int i = 0; i < atoms.size(); i++) { if(atoms[i].chainID != chainID ) { chainID = atoms[i].chainID; chainIndex = distance(chainIDs.begin(),find(chainIDs.begin(),chainIDs.end(),chainID)); if( chainIndex == chainIDs.size() ) { chainIDs.push_back(chainID); chains.resize(chainIndex+1); chains[chainIndex].id = chainID; } } // Separate the atoms into amino acids AminoAcid aa; unsigned int residue_number = atoms[i].resSeq; char iCode = atoms[i].iCode; vector<char> altloc_ids; while(residue_number == atoms[i].resSeq && atoms[i].chainID == chainID && atoms[i].iCode == iCode ) { // Determine how many alternate locations there are if(atoms[i].altLoc != ' ') { vector<char>::iterator found = find(altloc_ids.begin(), altloc_ids.end(), atoms[i].altLoc); if(found == altloc_ids.end()) { altloc_ids.push_back(atoms[i].altLoc); } } aa.atom.push_back(&atoms[i]); i++; if( i == atoms.size() ) { break; } } i--; aa.determineAltLoc(altloc_ids); aa.residue = atoms[i].residueName; vector<string>::iterator found1 = find(residue1->begin(), residue1->end(), aa.residue); vector<string>::iterator found2 = find(residue2->begin(), residue2->end(), aa.residue); if( found1 != residue1->end() || found2 != residue2->end()) { aa.calculateCenter(center); } else { aa.skip = true; } // This is a little hack to skip over residue locations that have // insertion codes. Mainly because this adds more complexity than // we need. if( aa.atom[0]->iCode != ' ' ) { aa.skip = true; } // Store the reference of the atom in the corresponding chain info chains[chainIndex].addAminoAcid(aa); } //reset the flags chainID = '-'; chainIndex = -1; // Go through each hetatm if( ligandsToFind ) { for(int i = 0; i < hetatms.size(); i++) { // Check if this is a new chain if(hetatms[i].chainID != chainID ) { chainID = hetatms[i].chainID; chainIndex = distance(chainIDs.begin(),find(chainIDs.begin(),chainIDs.end(),chainID)); if( chainIndex == chainIDs.size() ) { chainIDs.push_back(chainID); chains.resize(chainIndex+1); chains[chainIndex].id = chainID; } } // Separate the hetatms into Residues Residue r; unsigned int residue_number = hetatms[i].resSeq; while(residue_number == hetatms[i].resSeq && hetatms[i].chainID == chainID) { r.atom.push_back(&hetatms[i]); i++; if( i == hetatms.size() ) { break; } } i--; r.residue = hetatms[i].residueName; vector<string>::iterator found1 = find(ligandsToFind->begin(), ligandsToFind->end(), r.residue); if(found1 != ligandsToFind->end()) { r.calculateCenter(center); } // Store the reference of the hetatm in the corresponding chain info chains[chainIndex].addHetatm(r); } } }
using std::ofstream; using std::ios; SecondaryStructure* s1; CHECK(SecondaryStructure() throw()) s1 = new SecondaryStructure; TEST_NOT_EQUAL(s1, 0) RESULT CHECK(~SecondaryStructure() throw()) delete s1; RESULT CHECK(SecondaryStructure(const SecondaryStructure& secondary_structure, bool deep = true) throw()) Residue r1; SecondaryStructure s1("s1"), s2; s1.append(r1); s2 = SecondaryStructure(s1); TEST_EQUAL(s2.getName(), "s1") TEST_EQUAL(s2.countResidues(), 1) RESULT CHECK(SecondaryStructure(const String& name) throw()) SecondaryStructure s1("s1"); TEST_EQUAL(s1.getName(), "s1") SecondaryStructure s2(""); TEST_EQUAL(s2.getName(), "") RESULT CHECK(void clear() throw())
void PDBLoopParser::parse_single_pdb_file(string pdb_filename) { // Open the file stream ifstream ifs; ifs.open(pdb_filename.c_str()); string line; // Since some of the PDB files may have multiple Structures inside (i.e. // two HUs) seperated by a TER line, need to return multiple Structures Structure *s = new Structure(pdb_filename); Chain *c = new Chain(); Residue *r = new Residue(); Atom *a = new Atom(); // Save the previous Residue and Chain PDB IDs to compare and decide whether // or not a new one needs to be made. int r_id_prev = 0; string c_id_prev = ""; bool make_new = false; string atom("ATOM"); string ter("TER"); while( getline(ifs, line) ) { if (line.empty()) continue; if (make_new) { s = new Structure(pdb_filename); make_new = false; } if (line.compare(0, atom.length(), atom) == 0) { // Information in PDB files follow strict column sizes. This may // not be very robust, but works fine with my PDB files. //int a_id = atoi(line.substr(6,5).c_str()); string a_name = line.substr(13,3); string r_name = boost::trim_copy(line.substr(17,3)); string c_id = line.substr(21,1); int r_id = atoi(line.substr(23,3).c_str()); double x = atof(line.substr(31,7).c_str()); double y = atof(line.substr(38,7).c_str()); double z = atof(line.substr(46,7).c_str()); // If an Entity has a different ID than the one before, if (c_id_prev.compare(c_id) != 0) { c = new Chain(c_id); // Create a new chain with new ID s->add_child(c); // Attach to parent Entity c_id_prev = c_id; // Keep track of new ID } if (r_id_prev != r_id) { r = new Residue(r_name, r_id); c->add_child(r); r_id_prev = r_id; } // Every line should contain a new atom, then attach it to a residue a = new Atom(a_name, x, y, z); r->add_child(a); } /* If a TER comes in the file, denoting multiple structures in the PDB, add the previously parsed structure to the vector which will be loaded into the loop, then start a new structure. If the TER is before the EOF, an empty Structure will be created TODO: Ensure that the empty structure does not get committed to DB */ else if (line.compare(0, ter.length(), ter) == 0) { if (DEBUG) { cout << "Pushing back " << *s << endl; } m_loop.add_child(s); make_new = true; } } // If no TER at the EOF, add the structure if ( (s->get_child_vector().size() != 0) && !make_new ) { if (DEBUG) {cout << "Pushing back " << *s << endl;} m_loop.add_child(s); } }
void PeptideCapProcessor::optimizeCapPosition(Chain& chain, bool start) { Vector3 translation; Atom* axis = NULL; Residue* cap = NULL; std::vector<Atom*> a; std::vector<Atom*> b; Size nr = chain.countResidues(); // cap at the beginning of a peptide if (start) { // put ACE-C to the center for (AtomIterator it = chain.getResidue(1)->beginAtom(); +it; ++it) { if (it->getName() == "N") { translation = it->getPosition(); } b.push_back(&*it); } cap = chain.getResidue(0); for (AtomIterator it = cap->beginAtom(); +it; ++it) { a.push_back(&*it); if (it->getName() == "C") { axis = &*it; } } } //cap at the end of a peptide else { for (AtomIterator it = chain.getResidue(nr-2)->beginAtom(); +it; ++it) { if (it->getName() == "C") { translation = it->getPosition(); } b.push_back(&*it); } cap = chain.getResidue(nr-1); for (AtomIterator it = cap->beginAtom(); +it; ++it) { a.push_back(&*it); if (it->getName() == "N") { axis = &*it; } } } //translate the anchor to origin TranslationProcessor tlp; tlp.setTranslation(translation*-1.0); chain.apply(tlp); //try all torsions float largest_distance = 0.0; float tmp_distance = 0.0; float torsion = 0.0; float step = 2.0; TransformationProcessor tfp; Matrix4x4 m; m.setRotation( Angle(step, false), axis->getPosition()); tfp.setTransformation(m); for (Position r = step; r <= 360; r+=step) { cap->apply(tfp); tmp_distance = computeDistance(a,b); if (largest_distance < tmp_distance) { largest_distance = tmp_distance; torsion = r; } } //apply best rotation angle m.setRotation( Angle(torsion, false), axis->getPosition()); tfp.setTransformation(m); cap->apply(tfp); //now translate the protein back tlp.setTranslation(translation); chain.apply(tlp); }
Residue ResidueSubstitutionTable::replaceResidue(Residue &_res) { // If this residue isn't in our list of residues to be replaced, // just return it! if( !isResidueInSubstitutionTable(_res) ) return _res; // Clone the current residue, and find the replacement info. Residue newRes; ReplacementInfo ri = find( _res.getResidueName() )->second; string newName = ri.first; AtomHash ah = ri.second; // Loop over all of the atoms in the residue. for(int i=0; i < _res.size(); ++i ){ Atom &currAtom = _res.getAtom(i); string currAtomName = currAtom.getName(); // If the current atom is in the list of atoms we should keep, // add it. if( ah.find(currAtomName) != ah.end() ) newRes.addAtom( currAtom ); } // Set the new name of the residue. newRes.setResidueNumber( _res.getResidueNumber() ); newRes.setResidueIcode( _res.getResidueIcode() ); newRes.setChainId( _res.getChainId() ); newRes.setResidueName( newName ); return newRes; }