void DrawPolar(QPainter *p,pigalePaint *paint) {TopologicalGraph G(paint->GCP); Prop<Tpoint> Vcoord(G.Set(tvertex()),PROP_DRAW_COORD); Prop<Tpoint> Epoint1(G.Set(tedge()),PROP_DRAW_POINT_1); Prop<Tpoint> Epoint2(G.Set(tedge()),PROP_DRAW_POINT_2); Prop<Tpoint> Epoint11(G.Set(tedge()),PROP_DRAW_POINT_3); Prop<Tpoint> Epoint12(G.Set(tedge()),PROP_DRAW_POINT_4); Prop<Tpoint> Epoint21(G.Set(tedge()),PROP_DRAW_POINT_5); Prop<Tpoint> Epoint22(G.Set(tedge()),PROP_DRAW_POINT_6); Prop<double> Erho (G.Set(tedge()),PROP_DRAW_DBLE_1); Prop<double> Etheta1(G.Set(tedge()),PROP_DRAW_DBLE_2); Prop<double> Etheta2(G.Set(tedge()),PROP_DRAW_DBLE_3); Prop1<double> nw(G.Set(),PROP_DRAW_DBLE_1); Prop<short> vcolor(G.Set(tvertex()),PROP_COLOR); int m = G.ne(); int ox,oy,nx,ny,theta,dt; QPen pn = p->pen();pn.setWidth(1); for (tedge ee=1; ee<=m; ee++) {if (Erho[ee]==-1) {paint->DrawSeg(p,Epoint1[ee],Epoint2[ee],Red); continue; } if (Epoint11[ee]!=Tpoint(-1,-1)) {paint->DrawSeg(p,Epoint1[ee],Epoint11[ee],Blue); paint->DrawSeg(p,Epoint11[ee],Epoint12[ee],Blue); } else if (Epoint12[ee]!=Tpoint(-1,-1)) paint->DrawSeg(p,Epoint1[ee],Epoint12[ee],Blue); if (Epoint21[ee]!=Tpoint(-1,-1)) {paint->DrawSeg(p,Epoint2[ee],Epoint21[ee],Blue); paint->DrawSeg(p,Epoint21[ee],Epoint22[ee],Blue); } else if (Epoint22[ee]!=Tpoint(-1,-1)) paint->DrawSeg(p,Epoint2[ee],Epoint22[ee],Blue); pn.setColor(color[Blue]);pn.setWidth(2);p->setPen(pn); ox = paint->to_x(-Erho[ee]); oy = paint->to_y(Erho[ee]); nx = (int)(2*Erho[ee]*paint->xscale + .5); ny = (int)(2*Erho[ee]*paint->yscale + .5); theta = (int)(Etheta1[ee]*16*180/PI+.5); dt = (int)((Etheta2[ee] - Etheta1[ee])*16*180/PI+.5); p->drawArc(ox,oy,nx,ny,theta,dt); } // Draw the vertices double dx = .001; for(tvertex v = 1;v <= G.nv();v++) {double x = Vcoord[v].x()-dx*.5; double y = Vcoord[v].y()-dx*.5; Tpoint pt(x,y); paint->DrawText(p,pt, v,vcolor[v],1); } }
void DrawPolyline(QPainter *p,pigalePaint *paint) {GeometricGraph G(paint->GCP); Prop<Tpoint> Vcoord(G.Set(tvertex()),PROP_DRAW_POINT_1); Prop<Tpoint> Epoint1(G.Set(tedge()),PROP_DRAW_POINT_1); Prop<Tpoint> Epoint2(G.Set(tedge()),PROP_DRAW_POINT_2); Prop<Tpoint> Ebend(G.Set(tedge()),PROP_DRAW_POINT_3); Prop<short> ecolor(G.Set(tedge()),PROP_COLOR); Prop<short> vcolor(G.Set(tvertex()),PROP_COLOR); QPen pn = p->pen();pn.setWidth(2); for (tedge ee=1; ee<= G.ne(); ee++) {if (Ebend[ee] != Tpoint(-1, -1)) {paint->DrawSeg(p, Epoint1[ee], Ebend[ee],ecolor[ee]); paint->DrawSeg(p, Ebend[ee], Epoint2[ee],ecolor[ee]); } else paint->DrawSeg(p, Epoint1[ee], Epoint2[ee] , ecolor[ee]); } // Draw the vertices p->setFont(QFont("sans",Min((int)(.45 * Min(paint->xscale,paint->yscale) + .5),13))); for(tvertex v = 1;v <= G.nv();v++) paint->DrawText(p,Vcoord[v],v,vcolor[v],1); }
// Action_Watershell::DoAction() Action::RetType Action_Watershell::DoAction(int frameNum, ActionFrame& frm) { int nlower = 0; int nupper = 0; # ifdef CUDA // Copy solvent atom coords to array unsigned int idx = 0; // Index into V_atom_coords_ for (AtomMask::const_iterator atm = solventMask_.begin(); atm != solventMask_.end(); ++atm, idx += 3) { const double* xyz = frm.Frm().XYZ( *atm ); V_atom_coords_[idx ] = xyz[0]; V_atom_coords_[idx+1] = xyz[1]; V_atom_coords_[idx+2] = xyz[2]; } Matrix_3x3 ucell, recip; if (image_.ImageType() == NONORTHO) frm.Frm().BoxCrd().ToRecip(ucell, recip); // Copy solute atom coords to array idx = 0; for (AtomMask::const_iterator atm = soluteMask_.begin(); atm != soluteMask_.end(); ++atm, idx += 3) { const double* XYZ = frm.Frm().XYZ( *atm ); soluteCoords_[idx ] = XYZ[0]; soluteCoords_[idx+1] = XYZ[1]; soluteCoords_[idx+2] = XYZ[2]; } Action_Closest_NoCenter( &V_atom_coords_[0], &V_distances_[0], &soluteCoords_[0], 9999999999999.0, NsolventMolecules_, NAtoms_, soluteMask_.Nselected(), image_.ImageType(), frm.Frm().BoxCrd().boxPtr(), ucell.Dptr(), recip.Dptr() ); // V_distances_ now has the closest distance of each solvent molecule to // solute. Determine shell status of each. for (Darray::const_iterator dist2 = V_distances_.begin(); dist2 != V_distances_.end(); ++dist2) if (*dist2 < upperCutoff_) { ++nupper; // Less than lower, 1st shell if (*dist2 < lowerCutoff_) ++nlower; } # else // --------------------------------------------------------------------------- int NV = solventMask_.Nselected(); int Vidx; # ifdef _OPENMP int mythread; # endif int* status = 0; if (image_.ImageType() == NONORTHO) { // ----- NON-ORTHORHOMBIC IMAGING ------------ Matrix_3x3 ucell, recip; frm.Frm().BoxCrd().ToRecip(ucell, recip); // Wrap all solute atoms back into primary cell, save coords. Image::WrapToCell0( soluteCoords_, frm.Frm(), soluteMask_, ucell, recip ); // Calculate every imaged distance of all solvent atoms to solute # ifdef _OPENMP # pragma omp parallel private(Vidx, mythread, status) { mythread = omp_get_thread_num(); status = &(shellStatus_thread_[mythread][0]); # pragma omp for # else status = &shellStatus_[0]; # endif for (Vidx = 0; Vidx < NV; Vidx++) { int Vat = solventMask_[Vidx]; int currentRes = (*CurrentParm_)[ Vat ].ResNum(); // Convert to frac coords Vec3 vFrac = recip * Vec3( frm.Frm().XYZ( Vat ) ); // Wrap to primary unit cell vFrac[0] = vFrac[0] - floor(vFrac[0]); vFrac[1] = vFrac[1] - floor(vFrac[1]); vFrac[2] = vFrac[2] - floor(vFrac[2]); // Loop over all images of this solvent atom for (int ix = -1; ix != 2; ix++) for (int iy = -1; iy != 2; iy++) for (int iz = -1; iz != 2; iz++) { // Convert image back to Cartesian Vec3 vCart = ucell.TransposeMult( vFrac + Vec3(ix, iy, iz) ); // Loop over all solute atoms for (unsigned int idx = 0; idx < soluteCoords_.size(); idx += 3) { if (status[currentRes] < 2) { // Residue is not yet marked as 1st shell, calc distance double x = vCart[0] - soluteCoords_[idx ]; double y = vCart[1] - soluteCoords_[idx+1]; double z = vCart[2] - soluteCoords_[idx+2]; double dist2 = x*x + y*y + z*z; // Less than upper, 2nd shell if (dist2 < upperCutoff_) { status[currentRes] = 1; // Less than lower, 1st shell if (dist2 < lowerCutoff_) status[currentRes] = 2; } } else { // Residue already in first shell. No need for more distance calcs ix = iy = iz = 1; break; } } // END loop over solute atoms } // END loop over images (Z) } // END loop over solvent atoms # ifdef _OPENMP } // END pragma omp parallel # endif } else { // ----- ORTHORHOMBIC/NO IMAGING ------------- // Store selected solute coordinates. int idx = 0; for (AtomMask::const_iterator atm = soluteMask_.begin(); atm != soluteMask_.end(); ++atm, idx += 3) { const double* XYZ = frm.Frm().XYZ( *atm ); soluteCoords_[idx ] = XYZ[0]; soluteCoords_[idx+1] = XYZ[1]; soluteCoords_[idx+2] = XYZ[2]; } // Calculate distance of all solvent atoms to solute # ifdef _OPENMP # pragma omp parallel private(Vidx, mythread, status) { mythread = omp_get_thread_num(); status = &(shellStatus_thread_[mythread][0]); # pragma omp for # else status = &shellStatus_[0]; # endif for (Vidx = 0; Vidx < NV; Vidx++) { int Vat = solventMask_[Vidx]; int currentRes = (*CurrentParm_)[ Vat ].ResNum(); Vec3 Vcoord( frm.Frm().XYZ( Vat ) ); // Loop over all solute atoms for (unsigned int idx = 0; idx < soluteCoords_.size(); idx += 3) { if (status[currentRes] < 2) { // Residue is not yet marked as 1st shell, calc distance Vec3 Ucoord( soluteCoords_[idx], soluteCoords_[idx+1], soluteCoords_[idx+2] ); double dist2; if (image_.ImageType() == ORTHO) dist2 = DIST2_ImageOrtho( Vcoord, Ucoord, frm.Frm().BoxCrd() ); else dist2 = DIST2_NoImage( Vcoord, Ucoord ); // Less than upper, 2nd shell if (dist2 < upperCutoff_) { status[currentRes] = 1; // Less than lower, 1st shell if (dist2 < lowerCutoff_) status[currentRes] = 2; } } else { // Residue already in first shell. No need for more distance calcs. break; } } // END loop over solute atoms } // END loop over solvent atoms # ifdef _OPENMP } // END pragma omp parallel # endif } # ifdef _OPENMP // Combine results from each thread. for (unsigned int res = 0; res < shellStatus_thread_[0].size(); res++) { int shell = 0; for (unsigned int thread = 0; thread < shellStatus_thread_.size(); thread++) { shell = std::max( shellStatus_thread_[thread][res], shell ); // Dont break here so we can reset counts. Could also do with a fill shellStatus_thread_[thread][res] = 0; } if (shell > 0) { ++nupper; if (shell > 1) ++nlower; } } # else // Now each residue is marked 0 (no shell), 1 (second shell), 2 (first shell) for (Iarray::iterator shell = shellStatus_.begin(); shell != shellStatus_.end(); ++shell) { if ( *shell > 0 ) { ++nupper; if ( *shell > 1 ) ++nlower; } // Reset for next pass *shell = 0; } # endif # endif /* CUDA */ lower_->Add(frameNum, &nlower); upper_->Add(frameNum, &nupper); return Action::OK; }
int EmbedPolyline(TopologicalGraph &G) {if(G.nv() < 3 || G.ne() < 2)return -1; int OldNumEdge = G.ne(); PSet1 propSave(G.Set()); G.MakeConnected(); if(!G.FindPlanarMap() ) {Tprintf("Not Planar Graph"); for(tedge e = G.ne(); e > OldNumEdge; e--) G.DeleteEdge(e); return -1; } tbrin FirstBrin = 1; bool MaxPlanar = (G.ne() != 3 * G.nv() - 6) ? false : true; int len; if(!FirstBrin && !MaxPlanar) G.LongestFace(FirstBrin,len); else if(FirstBrin == 0) {FirstBrin = G.extbrin();FirstBrin = -G.acir[FirstBrin];} if(!MaxPlanar && G.ZigZagTriangulate())return -2; svector<short> ecolor(1, G.ne()); SchnyderDecomp(G,FirstBrin,ecolor); GeometricGraph G0(G); //Compute trees tedge ee; Prop<Tpoint> Ebend(G.Set(tedge()),PROP_DRAW_POINT_3); svector<tbrin> FatherB(1,G.nv(),(tbrin)0); FatherB.SetName("FatherB"); svector<tbrin> FatherG(1,G.nv(),(tbrin)0); FatherG.SetName("FatherG"); svector<tbrin> FatherR(1,G.nv(),(tbrin)0); FatherR.SetName("FatherR"); svector<int> x(1,G.nv(),0), y(1,G.nv(),0); x.clear(); y.clear(); compute_parents(G0, Blue, -FirstBrin, FatherB, ecolor); compute_parents(G0, Red, FirstBrin, FatherR, ecolor); compute_parents(G0, Green, -G0.acir[FirstBrin], FatherG, ecolor); // Compute the number of leaves of each tree int nb_leavesB, nb_leavesR, nb_leavesG; nb_leavesB = nb_leaves(G0, Blue, -FirstBrin, ecolor); nb_leavesR = nb_leaves(G0, Red, FirstBrin, ecolor); nb_leavesG = nb_leaves(G0, Green, -G0.acir[FirstBrin], ecolor); // Compute the coordinates using the tree with the minimum number of leaves ForAllEdges(ee, G) Ebend[ee] = Tpoint(-1,-1); if (nb_leavesB <= nb_leavesR && nb_leavesB <= nb_leavesG) compute_coords(G0,Red,Blue,-FirstBrin,FatherB,FatherR,FatherG,ecolor,x,y,Ebend); else if (nb_leavesR <= nb_leavesG) compute_coords(G0,Green,Red,G0.acir[FirstBrin],FatherR,FatherG,FatherB,ecolor,x,y,Ebend); else compute_coords(G0,Blue,Green,G0.acir[-G0.acir[FirstBrin]],FatherG,FatherB,FatherR,ecolor,x,y,Ebend); // computes extremities of vertices Prop<Tpoint> Epoint1(G.Set(tedge()),PROP_DRAW_POINT_1); Prop<Tpoint> Epoint2(G.Set(tedge()),PROP_DRAW_POINT_2); Prop<Tpoint> Vcoord(G.Set(tvertex()),PROP_DRAW_POINT_1); G.Set() = propSave; Prop1<Tpoint> pmin(G.Set(),PROP_POINT_MIN); Prop1<Tpoint> pmax(G.Set(),PROP_POINT_MAX); tvertex vv; pmin() = Tpoint(0,0); pmax() = Tpoint(0,0); ForAllVertices(vv, G0) {Vcoord[vv] = Tpoint(x[vv], y[vv]); if (Vcoord[vv].x() > pmax().x()) pmax().x() = Vcoord[vv].x(); if (Vcoord[vv].y() > pmax().y()) pmax().y() = Vcoord[vv].y(); }