static void drawSelInterAtomLine(MolAtomPtr pAtom1, MolAtomPtr pAtom2, DisplayContext *pdl) { if (pAtom1.isnull() || pAtom2.isnull()) return; pdl->vertex(pAtom1->getPos()); pdl->vertex(pAtom2->getPos()); }
bool MolSurfBuilder::init(MolCoordPtr pmol) { AtomIterator aiter(pmol); int i, natoms=0; // count atom number for (aiter.first(); aiter.hasMore(); aiter.next()) { MolAtomPtr pAtom = aiter.get(); MB_ASSERT(!pAtom.isnull()); ++natoms; } // copy to the m_data m_data.resize(natoms); m_tree.alloc(natoms); for (i=0,aiter.first(); aiter.hasMore()&&i<natoms; aiter.next(),++i) { MolAtomPtr pAtom = aiter.get(); m_data[i].pos = pAtom->getPos(); m_data[i].rad = 1.5; m_data[i].aid = pAtom->getID(); m_tree.setAt(i, m_data[i].pos, i); } // build BSP tree m_tree.build(); m_rmax = 1.5; m_rprobe = 1.2; return true; }
void SimpleRenderer::drawAtom(MolAtomPtr pAtom, DisplayContext *pdl) { pdl->color(ColSchmHolder::getColor(pAtom)); const Vector4D pos = pAtom->getPos(); const double rad = 0.25; pdl->drawAster(pos, rad); ++m_nAtomDrawn; }
void BallStickRenderer::rendAtom(DisplayContext *pdl, MolAtomPtr pAtom, bool) { if (m_sphr>0.0) { pdl->color(ColSchmHolder::getColor(pAtom)); pdl->sphere(m_sphr, pAtom->getPos()); } checkRing(pAtom->getID()); }
void SelectionRenderer::rendAtom(DisplayContext *pdl, MolAtomPtr pAtom, bool fbonded) { if (m_nMode==0) { if (!fbonded) drawSelAtom(pAtom, pdl); } else { pdl->vertex(pAtom->getPos()); //Vector4D pos = pAtom->getPos(); //pdl->drawPixels(pos, m_boximg, *(m_color.get())); } }
void BallStickRenderer::drawInterAtomLine(MolAtomPtr pAtom1, MolAtomPtr pAtom2, DisplayContext *pdl) { if (pAtom1.isnull() || pAtom2.isnull()) return; const Vector4D pos1 = pAtom1->getPos(); const Vector4D pos2 = pAtom2->getPos(); ColorPtr pcol1 = ColSchmHolder::getColor(pAtom1); ColorPtr pcol2 = ColSchmHolder::getColor(pAtom2); if ( pcol1->equals(*pcol2.get()) ) { pdl->color(pcol1); pdl->cylinder(m_bondw, pos1, pos2); } else { const Vector4D mpos = (pos1 + pos2).divide(2.0); pdl->color(pcol1); pdl->cylinder(m_bondw, pos1, mpos); pdl->color(pcol2); pdl->cylinder(m_bondw, pos2, mpos); } }
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; }
void SimpleRenderer::drawInterAtomLine(MolAtomPtr pAtom1, MolAtomPtr pAtom2, MolBond *pMB, DisplayContext *pdl) { if (pAtom1.isnull() || pAtom2.isnull()) return; const Vector4D pos1 = pAtom1->getPos(); const Vector4D pos2 = pAtom2->getPos(); ColorPtr pcol1 = ColSchmHolder::getColor(pAtom1); ColorPtr pcol2 = ColSchmHolder::getColor(pAtom2); int nBondType = pMB->getType(); if (m_bValBond && (nBondType==MolBond::DOUBLE || nBondType==MolBond::TRIPLE)) { MolCoordPtr pMol = getClientMol(); Vector4D dvd = pMB->getDblBondDir(pMol); if (nBondType==MolBond::DOUBLE) { // double bond if ( pcol1->equals(*pcol2.get()) ) { pdl->color(pcol1); pdl->vertex(pos1 + dvd.scale(m_dCvScl1)); pdl->vertex(pos2 + dvd.scale(m_dCvScl1)); pdl->vertex(pos1 + dvd.scale(m_dCvScl2)); pdl->vertex(pos2 + dvd.scale(m_dCvScl2)); } else { const Vector4D minpos = (pos1 + pos2).divide(2.0); pdl->color(pcol1); pdl->vertex(pos1 + dvd.scale(m_dCvScl1)); pdl->vertex(minpos + dvd.scale(m_dCvScl1)); pdl->vertex(pos1 + dvd.scale(m_dCvScl2)); pdl->vertex(minpos + dvd.scale(m_dCvScl2)); pdl->color(pcol2); pdl->vertex(pos2 + dvd.scale(m_dCvScl1)); pdl->vertex(minpos + dvd.scale(m_dCvScl1)); pdl->vertex(pos2 + dvd.scale(m_dCvScl2)); pdl->vertex(minpos + dvd.scale(m_dCvScl2)); } } else { // triple bond if ( pcol1->equals(*pcol2.get()) ) { pdl->color(pcol1); pdl->vertex(pos1); pdl->vertex(pos2); pdl->vertex(pos1 + dvd.scale(m_dCvScl1)); pdl->vertex(pos2 + dvd.scale(m_dCvScl1)); pdl->vertex(pos1 + dvd.scale(-m_dCvScl1)); pdl->vertex(pos2 + dvd.scale(-m_dCvScl1)); } else { const Vector4D minpos = (pos1 + pos2).divide(2.0); pdl->color(pcol1); pdl->vertex(pos1); pdl->vertex(minpos); pdl->vertex(pos1 + dvd.scale(m_dCvScl1)); pdl->vertex(minpos + dvd.scale(m_dCvScl1)); pdl->vertex(pos1 + dvd.scale(-m_dCvScl1)); pdl->vertex(minpos + dvd.scale(-m_dCvScl1)); pdl->color(pcol2); pdl->vertex(pos2); pdl->vertex(minpos); pdl->vertex(pos2 + dvd.scale(m_dCvScl1)); pdl->vertex(minpos + dvd.scale(m_dCvScl1)); pdl->vertex(pos2 + dvd.scale(-m_dCvScl1)); pdl->vertex(minpos + dvd.scale(-m_dCvScl1)); } } ++m_nBondDrawn; return; } if ( pcol1->equals(*pcol2.get()) ) { pdl->color(pcol1); pdl->vertex(pos1); pdl->vertex(pos2); } else { const Vector4D minpos = (pos1 + pos2).divide(2.0); pdl->color(pcol1); pdl->vertex(pos1); pdl->vertex(minpos); pdl->color(pcol2); pdl->vertex(pos2); pdl->vertex(minpos); } ++m_nBondDrawn; return; }
void BallStickRenderer::drawRingImpl(const std::list<int> atoms, DisplayContext *pdl) { MolCoordPtr pMol = getClientMol(); double len; int i, nsize = atoms.size(); Vector4D *pvecs = MB_NEW Vector4D[nsize]; Vector4D cen; std::list<int>::const_iterator iter = atoms.begin(); std::list<int>::const_iterator eiter = atoms.end(); MolAtomPtr pPivAtom, pAtom; for (i=0; iter!=eiter; ++iter, i++) { MolAtomPtr pAtom = pMol->getAtom(*iter); if (pAtom.isnull()) return; MolResiduePtr pres = pAtom->getParentResidue(); MolChainPtr pch = pAtom->getParentChain(); MB_DPRINTLN("RING %s %s", pres->toString().c_str(), pAtom->getName().c_str()); pvecs[i] = pAtom->getPos(); cen += pvecs[i]; if (pPivAtom.isnull() && pAtom->getElement()==ElemSym::C) pPivAtom = pAtom; } if (pPivAtom.isnull()) pPivAtom = pAtom; // no carbon atom --> last atom becomes pivot cen = cen.divide(nsize); // calculate the normal vector Vector4D norm; for (i=0; i<nsize; i++) { int ni = (i+1)%nsize; Vector4D v1 = pvecs[ni] - pvecs[i]; Vector4D v2 = cen - pvecs[i]; Vector4D ntmp; ntmp = v1.cross(v2); len = ntmp.length(); if (len<=F_EPS8) { LOG_DPRINTLN("BallStick> *****"); return; } //ntmp.scale(1.0/len); ntmp = ntmp.divide(len); norm += ntmp; } len = norm.length(); norm = norm.divide(len); Vector4D dv = norm.scale(m_tickness); ColorPtr col = evalMolColor(m_ringcol, ColSchmHolder::getColor(pPivAtom)); /* ColorPtr col = m_ringcol; // check molcol reference gfx::MolColorRef *pMolCol = dynamic_cast<gfx::MolColorRef *>(col.get()); if (pMolCol!=NULL) { // molcol ref case --> resolve the pivot's color col = ColSchmHolder::getColor(pPivAtom); } */ pdl->setPolygonMode(gfx::DisplayContext::POLY_FILL_NOEGLN); pdl->startTriangleFan(); pdl->normal(norm); pdl->color(col); pdl->vertex(cen+dv); for (i=0; i<=nsize; i++) { pdl->vertex(pvecs[i%nsize]+dv); } pdl->end(); pdl->startTriangleFan(); pdl->normal(-norm); pdl->color(col); pdl->vertex(cen-dv); for (i=nsize; i>=0; i--) { pdl->vertex(pvecs[i%nsize]-dv); } pdl->end(); pdl->setPolygonMode(gfx::DisplayContext::POLY_FILL); delete [] pvecs; }
void MolSurfObj::createSESFromMol(MolCoordPtr pMol, SelectionPtr pSel, double density, double probe_r) { AtomIterator aiter(pMol, pSel); int i, natoms=0; // count atom number for (aiter.first(); aiter.hasMore(); aiter.next()) { MolAtomPtr pAtom = aiter.get(); if (!chkAltConf(pAtom)) continue; MB_ASSERT(!pAtom.isnull()); ++natoms; } std::vector< BALL::TSphere3<double> > spheres(natoms); TopparManager *pTM = TopparManager::getInstance(); const double vdw_default = 2.0; // copy to the m_data Vector4D pos; for (i=0,aiter.first(); aiter.hasMore()&&i<natoms; aiter.next()) { MolAtomPtr pAtom = aiter.get(); if (!chkAltConf(pAtom)) continue; pos = pAtom->getPos(); double vdw = pTM->getVdwRadius(pAtom, false); if (vdw<0) vdw = vdw_default; spheres.at(i) = BALL::TSphere3<double>(BALL::TVector3<double>(pos.x(), pos.y(), pos.z()), vdw); ++i; } double diff = probe_r < 1.5 ? 0.01 : -0.01; bool ok = false; double rad = probe_r; BALL::ReducedSurface *pRS = NULL; BALL::SolventExcludedSurface *pSES = NULL; for (int i=0; !ok && i<10; ++i) { pRS = new BALL::ReducedSurface(spheres, rad); pRS->compute(); pSES = new BALL::SolventExcludedSurface(pRS); pSES->compute(); if (pSES->check()) break; // failed --> retry with different probe radius delete pRS; pRS = NULL; delete pSES; pSES = NULL; rad += diff; LOG_DPRINTLN("MolSurfBuilder> SES check failed --> retry (%d) with different probe r=%f", i, rad); } if (pSES==NULL) { //std::cout << "ses check failed" << std::endl; LOG_DPRINTLN("MolSurfBuilder> SES generation failed."); MB_THROW(qlib::RuntimeException, "MolSurfBuilder> SES generation failed."); return; } MB_ASSERT(pSES!=NULL&&pRS!=NULL); BALL::TriangulatedSES surface(pSES, density); surface.compute(); int nverts = surface.getNumberOfPoints(); int nfaces = surface.getNumberOfTriangles(); setVertSize(nverts); setFaceSize(nfaces); { BALL::TriangulatedSES::ConstPointIterator iter = surface.beginPoint(); BALL::TriangulatedSES::ConstPointIterator eiter = surface.endPoint(); int i = 0; for (;iter != eiter; ++iter) { BALL::TrianglePoint& tri_point = **iter; Vector4D n(tri_point.normal_.x,tri_point.normal_.y,tri_point.normal_.z); Vector4D v(tri_point.point_.x,tri_point.point_.y,tri_point.point_.z); setVertex(i, v, n); tri_point.setIndex(i); i++; } } { BALL::TriangulatedSES::ConstTriangleIterator iter = surface.beginTriangle(); BALL::TriangulatedSES::ConstTriangleIterator eiter = surface.endTriangle(); int i=0; for (; iter!=eiter; ++iter, ++i) { //std::cout << (**iter) << std::endl; int v1 = (*iter)->getVertex(0)->getIndex(); int v2 = (*iter)->getVertex(1)->getIndex(); int v3 = (*iter)->getVertex(2)->getIndex(); //printf("%6d %6d %6d\n", v1, v2, v3); setFace(i, v1, v2, v3); } } delete pSES; delete pRS; }
static void drawSelAtom(MolAtomPtr pAtom, DisplayContext *pdl) { pdl->drawAster(pAtom->getPos(), 0.25); }