Exemplo n.º 1
0
int SelCommand::isSelectedResid(MolResiduePtr pRes)
{
  if (m_pSelRoot==NULL)
    return true;

  MolCoordPtr pmol = pRes->getParent();
  if (pmol.isnull()) {
    LOG_DPRINTLN("isSelectedResid: parent mol is NULL!!");
    return SEL_NONE;
  }

  MolResidue::AtomCursor iter = pRes->atomBegin();
  int nsel=0, natoms=0;

  // m_pCurClient = pRes->getParent();

  for ( ; iter!=pRes->atomEnd(); iter++) {
    MolAtomPtr pAtom = pmol->getAtom(iter->second);
    if (m_pSelRoot->isSelected(pAtom))
      nsel++;
    natoms++;
  }
  
  // m_pCurClient = NULL;

  if (nsel==natoms)
    return SEL_ALL;
  else if (nsel==0)
    return SEL_NONE;
  else
    return SEL_PART;
}
Exemplo n.º 2
0
// write PDB file to stream
bool PDBFileWriter::write(qlib::OutStream &outs)
{
  m_pMol = getTarget<MolCoord>();

  if (m_pMol==NULL) {
    LOG_DPRINTLN("PDBWriter> MolCoord is not attached !!");
    return false;
  }

  // check extension record handlers
  PDBFileReader::HndlrTab &htab = PDBFileReader::m_htab;
  bool bUseHndlr = htab.size()>0;

  MolCoord *pMol = m_pMol;
  qlib::PrintStream prs(outs);

  //
  //  write header
  //
  //LString sbuf = pqsys->getVersion();
  //prs.formatln("REMARK   PDB File Generated by CueMol (ver %s)", sbuf.c_str());
  prs.formatln("REMARK   PDB File Generated by CueMol2");

  //
  //  write SSBOND record
  //
  writeSSBonds(prs);

  //
  //  write LINK record
  //
  writeLinks(prs);

  writeSecstr(prs);

  //
  //  write extension records (CRYST1)
  //
  if (bUseHndlr) {
    LString sbuf;
    PDBFileReader::HndlrTab::const_iterator iter = htab.begin();
    for (; iter!=htab.end(); ++iter) {
      PDBFileReader::RecordHandler *ph = iter->second;
      if (ph!=NULL && ph->write(sbuf, pMol)) {
        prs.println(sbuf);
      }
    }
  }
  
  //
  //  write body (ATOM/ANISOU records)
  //

  int nserial = 1;

  // Sort chain names by ASCII order
  // take care of '_' (empty) chain
  std::list<LString> chnames;
  {
    MolCoord::ChainIter iter = pMol->begin();
    bool bHasEmptyChain = false;
    for (; iter!=pMol->end(); ++iter) {
      MolChainPtr pChn = iter->second;
      LString chnam = (pChn->getName().c_str()); 
      if (chnam.equals("_")) {
        bHasEmptyChain = true;
        continue;
      }
      chnames.push_back(chnam);
    }
    chnames.sort();
    if (bHasEmptyChain)
      chnames.push_back("_");
  }
  
  std::list<LString>::const_iterator cniter = chnames.begin();
  for (; cniter!=chnames.end(); ++cniter) {
    LString chnam = *cniter;
    MolChainPtr pChn = pMol->getChain(chnam);

    // format chain name
    char cch = convChainName(chnam);

    LString resnam;
    MolChain::ResidCursor2 riter = pChn->begin2();
    // int nlastres = 0;
    for (; riter!=pChn->end2(); ++riter) {
      //MolResiduePtr pRes = *riter;
      MolResiduePtr pRes = riter->second;
      if (pRes.isnull()) continue;
      ResidIndex rindex = pRes->getIndex();
      resnam = pRes->getName();
      
      // format residue name
      // resnam = resnam.toUpperCase();
      resnam = resnam.substr(0,3);

      // sort atom by AID
      std::list<int> atmlist;
      {
        MolResidue::AtomCursor aiter = pRes->atomBegin();
        for (; aiter!=pRes->atomEnd(); ++aiter) {
          atmlist.push_back(aiter->second);
        }
        atmlist.sort();
      }

      std::list<int>::const_iterator iter = atmlist.begin();
      for (; iter!=atmlist.end(); ++iter) {
        int aid = *iter;
        MolAtomPtr pAtm = pMol->getAtom(aid);
        if (pAtm.isnull())
          continue;

        if (!m_pSel.isnull()) {
          if (!m_pSel->isSelected(pAtm))
            continue; // skip nonselected atom
        }

        writeAtomLine(nserial, rindex, resnam,
                      cch, pAtm, prs);
        nserial++;
      }
      // nlastres = rindex.first;
    }

    // print TER record
    /*prs.formatln("TER   "
                 "%5d"
                 "      "
                 "%3s "
                 "%1s"
                 "%4d"
                 "                                                      ",
                 nserial, resnam.c_str(), chnam.c_str(), nlastres);*/
    prs.println("TER");
    nserial ++;
  }  

  //prs.println("END                                                                             ");
  prs.println("END");
  return true;
}