/// Convert aid to (persistent) string representation LString MolCoord::toStrAID(int atomid) const { MolAtomPtr pAtom = getAtom(atomid); if (pAtom.isnull()) return LString(); LString value = LString::format("%s.%s.%s", pAtom->getChainName().c_str(), pAtom->getResIndex().toString().c_str(), pAtom->getName().c_str()); char conf_id = pAtom->getConfID(); if (conf_id) value += ":" + LString(conf_id); return value; }
bool MolCoord::removeAtom(int atomid) { MolAtomPtr pAtom = getAtom(atomid); if (pAtom.isnull() || pAtom->getParentUID()!=getUID()) return false; m_atomPool.remove(atomid); // invalidate ID pAtom->setID(-1); const LString &aname = pAtom->getName(); char cConfID = pAtom->getConfID(); ResidIndex nresid = pAtom->getResIndex(); const LString &cname = pAtom->getChainName(); MolChainPtr pCh = getChain(cname); if (pCh.isnull()) return false; MolResiduePtr pRes = getResidue(cname, nresid); if (pRes.isnull()) return false; // remove atom if (!pRes->removeAtom(aname, cConfID)) return false; if (pRes->getAtomSize()>0) return true; // purge the empty residue if (!pCh->removeResidue(nresid)) return false; // delete pRes; if (pCh->getSize()>0) return true; // purge the empty chain if (!removeChain(cname)) return false; // delete pCh; return true; }
void MolArrayMap::setup(MolCoordPtr pRefMol) { m_data.erase(m_data.begin(), m_data.end()); int i = 0; AtomIterator iter(pRefMol); for (iter.first(); iter.hasMore(); iter.next(), ++i) { MolAtomPtr pa = iter.get(); MolArrayMapElem a; a.chain = pa->getChainName().c_str(); a.resid = pa->getResIndex().toInt(); a.atom = pa->getName().c_str(); a.pA = pa; m_data.insert(data_t::value_type(a, -1)); //MB_DPRINTLN("fitref %s %d %s", a.chain.c_str(), a.resid, a.atom.c_str()); } setupIndex(); }
int MolCoord::appendAtom(MolAtomPtr pAtom) { pAtom->setParentUID(getUID()); const LString &cname = pAtom->getChainName(); const LString &rname = pAtom->getResName(); const LString &aname = pAtom->getName(); ResidIndex nresid = pAtom->getResIndex(); if (cname.length()<=0 || aname.length()<=0) { LString msg = LString::format("MolCoord> ERROR: appending atom with invalid properties" " (c:'%s' rn:'%s' ri:'%s' an:'%s')", cname.c_str(), rname.c_str(), nresid.toString().c_str(), aname.c_str()); MB_DPRINTLN(msg); MB_THROW(qlib::IllegalArgumentException, msg); return -1; } MolChainPtr pCh = getChain(cname); if (pCh.isnull()) { pCh = MolChainPtr(MB_NEW MolChain()); pCh->setParentUID(getUID()); pCh->setName(cname); appendChain(pCh); } MolResiduePtr pRes = pCh->getResidue(nresid); if (pRes.isnull()) { pRes = MolResiduePtr(MB_NEW MolResidue()); pRes->setParentUID(getUID()); pRes->setIndex(nresid); pRes->setName(rname); // pRes->setChainName(cname); pCh->appendResidue(pRes); } else { const LString &pre_rname = pRes->getName(); if (!pre_rname.equals(rname)) { MB_DPRINTLN("MolCoord> ERROR: appending an atom (%s %s%s %s) with inconsistent residue (%s)", cname.c_str(), rname.c_str(), nresid.toString().c_str(), aname.c_str(), pre_rname.c_str()); // TO DO: throw exception (???) // This is often the case, so is not an exception. // return -1; } } // // Append to the atompool --> assign the atom ID // int atomid = m_atomPool.put(pAtom); if (atomid<0) { // This isn't fail in normal situation. MB_THROW(qlib::RuntimeException, "append to the atompool failed"); return -1; } pAtom->setID(atomid); // MolResidue::appendAtom() must be called after setID(), // because MolResidue makes map from name to AID, which requires "AID". if (!pRes->appendAtom(pAtom)) { // This is often the case with malformed PDB files, so is not an exception. MB_DPRINTLN("MolCoord> ERROR: appending duplicated atom (%s %s%s %s)", cname.c_str(), rname.c_str(), nresid.toString().c_str(), aname.c_str()); // Remove the mis-appended atom from the pool. m_atomPool.remove(atomid); return -1; } // Update the cached xform matrix if required pAtom->resetXformMatrix(); if (!getXformMatrix().isIdent()) pAtom->setXformMatrix(getXformMatrix()); return atomid; }