void TubeRenderer::beginRend(DisplayContext *pdl) { if (!m_pts->isValid()) m_pts->setupSectionTable(); super_t::beginRend(pdl); if (m_nPuttyMode==TBR_PUTTY_OFF) { return; } // calc max bfac/occ in the putty mode SelectionPtr pSel; MolCoordPtr pMol = getClientMol(); //MolRenderer *pMolRend = dynamic_cast<MolRenderer *>(pRend); //if (pMolRend!=NULL && m_nAuto==BFA_REND) pSel = getSelection(); double dmin = 1.0e100, dmax = -1.0e100, val, dsum = 0.0; int nadd=0; ResidIterator iter(pMol, pSel); for (iter.first(); iter.hasMore(); iter.next()) { MolResiduePtr pRes = iter.get(); MolAtomPtr pAtom = getPivotAtom(pRes); if (pAtom.isnull()) continue; if (m_nPuttyMode==TBR_PUTTY_OCC) val = pAtom->getOcc(); else val = pAtom->getBfac(); dsum += val; dmin = qlib::min(dmin, val); dmax = qlib::max(dmax, val); ++nadd; } m_dParHi = dmax; m_dParLo = dmin; m_dParAver = dsum/double(nadd); MB_DPRINTLN("Tube> init high=%f, low=%f, aver=%f OK.", dmax, dmin, m_dParAver); }
bool BfacColoring::init(MolCoordPtr pMol, Renderer *pRend) { if (m_nMode!=BFC_CENTER && !isAutoMode()) return true; m_parAutoLo = m_parAutoHi = 0.0; // MolCoordPtr pMol(pRend->getClientObj(), qlib::no_throw_tag()); if (pMol.isnull()) { return false; } if (m_nMode==BFC_CENTER) { m_vCenter = pMol->getCenterPos(false); if (!isAutoMode()) return true; } SelectionPtr pSel; MolRenderer *pMolRend = dynamic_cast<MolRenderer *>(pRend); if (pMolRend!=NULL && m_nAuto==BFA_REND) pSel = pMolRend->getSelection(); { double dmin = 1.0e100, dmax = -1.0e100, val; AtomIterator iter(pMol, pSel); for (iter.first(); iter.hasMore(); iter.next()) { MolAtomPtr pAtom = iter.get(); if (m_nMode==BFC_OCC) val = pAtom->getOcc(); else if (m_nMode==BFC_CENTER) val = (pAtom->getPos()-m_vCenter).length(); else val = pAtom->getBfac(); dmin = qlib::min(dmin, val); dmax = qlib::max(dmax, val); } MB_DPRINTLN("BfaxColoring> init high=%f, low=%f, OK.", dmax, dmin); m_parAutoHi = dmax; m_parAutoLo = dmin; } return true; }
bool BfacColoring::getAtomColor(MolAtomPtr pAtom, gfx::ColorPtr &col) { double par; if (m_nMode==BFC_OCC) par = pAtom->getOcc(); else if (m_nMode==BFC_CENTER) par = (pAtom->getPos()-m_vCenter).length(); else par = pAtom->getBfac(); col = m_colLow; double parLo = m_parLow; double parHi = m_parHigh; if (isAutoMode()) { parLo = m_parAutoLo; parHi = m_parAutoHi; } if (par<parLo) col = m_colLow; else if (par>parHi) col = m_colHigh; else { double ratio; if (qlib::isNear4(parHi, parLo)) ratio = 1.0; else ratio = (par-parLo)/(parHi-parLo); col = ColorPtr(MB_NEW gfx::GradientColor(m_colHigh, m_colLow, ratio)); } return true; }
bool PDBFileWriter::writeAtomLine(int nserial, const ResidIndex &rindex, const char *resnam, char chainch, MolAtomPtr pa, qlib::PrintStream &prs) { int resind = rindex.first; char inscode = rindex.second; LString atomnam = pa->getName().c_str(); // atomnam = atomnam.toUpperCase(); // conv ILE's CD name // (CD is converted to CD1 in PDBFileReader, so this should not occur) if (LChar::equals(resnam, "ILE") && atomnam.equals("CD")) atomnam = "CD1"; #ifdef QTL_CONV // conv nucl's prime to aster atomnam.replace('\'', '*'); // convert THY's C5A to C5M if (LChar::equals(resnam, "THY") && atomnam.equals("C5A")) { atomnam = "C5M"; } // conv nucl name if (LChar::equals(resnam, "ADE")) { resnam = " A"; } else if (LChar::equals(resnam, "THY")) { resnam = " T"; } else if (LChar::equals(resnam, "GUA")) { resnam = " G"; } else if (LChar::equals(resnam, "CYT")) { resnam = " C"; } else if (LChar::equals(resnam, "URI")) { resnam = " U"; } #endif LString shead; shead = LString::format("%5d ", nserial); // format atom name shead += formatAtomName(pa); shead += LString::format("%3s " "%c" "%4d" "%c", resnam, chainch, resind, (inscode=='\0') ? ' ' : inscode); ////////// // output to the stream prs.print("ATOM "); prs.print(shead); // Get atom position before applying xformMat, if xformMat is set Vector4D pos = pa->getRawPos(); prs.formatln(" " "%8.3f" "%8.3f" "%8.3f" "%6.2f" "%6.2f" " " " ", pos.x(), pos.y(), pos.z(), pa->getOcc(), pa->getBfac()); if (pa->hasAnIsoU()) { prs.print("ANISOU"); prs.print(shead); int u11 = int(pa->getU(0,0) * 1.0e4); int u22 = int(pa->getU(1,1) * 1.0e4); int u33 = int(pa->getU(2,2) * 1.0e4); int u12 = int(pa->getU(0,1) * 1.0e4); int u13 = int(pa->getU(0,2) * 1.0e4); int u23 = int(pa->getU(1,2) * 1.0e4); prs.formatln(" " " %6d" " %6d" " %6d" " %6d" " %6d" " %6d" " ", u11, u22, u33, u12, u13, u23); } return true; }