int Schuffenhauer::CalculateDelta(OpenBabel::OBMol& mol) { OpenBabel::OBMol m(mol); std::vector<OpenBabel::OBRing*> rings(m.GetSSSR()); int nr(rings.size()); // Count fusion bonds std::set<OpenBabel::OBBond*> fusionBonds; OpenBabel::OBBond* bond; std::vector<OpenBabel::OBBond*>::iterator bvi; for (bond = m.BeginBond(bvi); bond; bond = m.NextBond(bvi)) { for (unsigned int i(0); i < rings.size(); ++i) { for (unsigned int j(i); j < rings.size(); ++j) { if (i != j) { if (rings[i]->IsMember(bond) && rings[j]->IsMember(bond)) { fusionBonds.insert(bond); } } } } } int nrrb(fusionBonds.size()); return (nrrb - (nr - 1)); }
/// Returns the smallest ring the bond is a member of or \c 0 if the /// bond is not in a ring. Ring* Bond::smallestRing() const { Ring *smallest = 0; foreach(Ring *ring, rings()){ if(!smallest || ring->size() < smallest->size()){ smallest = ring; } } return smallest; }
int Cylinder::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 6) qt_static_metacall(this, _c, _id, _a); _id -= 6; } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { if (_id < 6) *reinterpret_cast<int*>(_a[0]) = -1; _id -= 6; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< float*>(_v) = radius(); break; case 1: *reinterpret_cast< int*>(_v) = rings(); break; case 2: *reinterpret_cast< int*>(_v) = slices(); break; } _id -= 3; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setRadius(*reinterpret_cast< float*>(_v)); break; case 1: setRings(*reinterpret_cast< int*>(_v)); break; case 2: setSlices(*reinterpret_cast< int*>(_v)); break; } _id -= 3; } else if (_c == QMetaObject::ResetProperty) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 3; } else if (_c == QMetaObject::RegisterPropertyMetaType) { if (_id < 3) *reinterpret_cast<int*>(_a[0]) = -1; _id -= 3; } #endif // QT_NO_PROPERTIES return _id; }
int main() { const int ring_size = 300; // Ring diameter const int ring_line_width = ring_size / 8; const Point ring_origin { ring_size / 2 + 50, ring_size / 2 + 50 }; Simple_window win { Point{ 100,100 }, ring_size * 3 + ring_size , ring_size * 2 + ring_size, "Olympic rings" }; vector<Graph_lib::Color> ring_colors { Color::cyan, Color::black, Color::red, Color::yellow, Color::green }; vector<Graph_lib::Circle*> rings(5); for (int i = 0; i < 5; ++i) { int offset_y = ring_origin.y + (i / 3) * ring_size / 2; int offset_x = (i / 3) * ring_size / 2; if (i < 3) rings[i] = new Graph_lib::Circle{ Point{ring_origin.x + offset_x + (ring_size + ring_line_width)*i, offset_y }, ring_size / 2 }; else rings[i] = new Graph_lib::Circle{ Point{ring_origin.x + offset_x + (ring_size + ring_line_width)*(i-3), offset_y }, ring_size / 2 }; rings[i]->set_color(ring_colors[i]); rings[i]->set_style(Line_style{Line_style::solid, ring_line_width}); win.attach(*rings[i]); } win.wait_for_button(); }
int main(int argc, char* argv[]) { rings(); band(); printf("nihao!\n"); int a = 1; int b; b=-a-5; printf("%d\n", b); /* 输出转义符, 结果还是会自动换行 */ putchar('\n'); /* char bb; scanf("%c", &bb); printf("%c\\n", bb); */ /* 使用不可打印字符时,需要用转义字符标识 */ printf("note:\n a s\ti\b\bk\rp\n"); /* 输入ascii 部分码表 */ for (int i=0; i<26; i++) { printf("%c: %d ", 'A'+i, 'A'+i); if (i%7 == 6) printf("\n"); } printf("\n"); return 0; }
//-------------------------------------------------- void f0r_set_param_value(f0r_instance_t instance, f0r_param_t param, int param_index) { tp_inst_t* inst = (tp_inst_t*)instance; f0r_param_double* p = (f0r_param_double*) param; int chg,tmpi; float tmpf; chg=0; switch (param_index) { case 0: //type tmpf=*((double*)p); if (tmpf>=1.0) tmpi=(int)tmpf; else tmpi = map_value_forward(tmpf, 0.0, 9.9999); if ((tmpi<0)||(tmpi>9.0)) break; if (inst->type != tmpi) chg=1; inst->type = tmpi; break; case 1: //channel tmpf=*((double*)p); if (tmpf>=1.0) tmpi=(int)tmpf; else tmpi = map_value_forward(tmpf, 0.0, 7.9999); if ((tmpi<0)||(tmpi>7.0)) break; if (inst->chan != tmpi) chg=1; inst->chan = tmpi; case 2: //amplitude tmpf = map_value_forward(*((double*)p), 0.0, 1.0); if (inst->amp != tmpf) chg=1; inst->amp = tmpf; break; case 3: //linear period sweep tmpi = map_value_forward(*((double*)p), 0.0, 1.0); if (inst->linp != tmpi) chg=1; inst->linp = tmpi; break; case 4: //frequency 1 tmpf = map_value_forward(*((double*)p), 0.0, 1.0); if (inst->f1 != tmpf) chg=1; inst->f1 = tmpf; break; case 5: //frequency 2 tmpf = map_value_forward(*((double*)p), 0.0, 1.0); if (inst->f2 != tmpf) chg=1; inst->f2 = tmpf; break; case 6: //aspect type tmpf=*((double*)p); if (tmpf>=1.0) tmpi=(int)tmpf; else tmpi = map_value_forward(tmpf, 0.0, 6.9999); if ((tmpi<0)||(tmpi>6.0)) break; if (inst->aspt != tmpi) chg=1; inst->aspt = tmpi; switch (inst->aspt) //pixel aspect ratio { case 0: inst->par=1.000; break; //square pixels case 1: inst->par=1.067; break; //PAL DV case 2: inst->par=1.455; break; //PAL wide case 3: inst->par=0.889; break; //NTSC DV case 4: inst->par=1.212; break; //NTSC wide case 5: inst->par=1.333; break; //HDV case 6: inst->par=inst->mpar; break; //manual } break; case 7: //manual aspect tmpf = map_value_forward_log(*((double*)p), 0.5, 2.0); if (inst->mpar != tmpf) chg=1; inst->mpar = tmpf; if (inst->aspt==6) inst->par=inst->mpar; break; } if (chg==0) return; switch (inst->type) { case 0: //hor freq ver sweep sweep_v(inst->sl, inst->w, inst->h, 0, inst->amp, inst->linp, inst->par, 0.05, 0.7); break; case 1: //hor freq hor sweep sweep_h(inst->sl, inst->w, inst->h, 0, inst->amp, inst->linp, inst->par, 0.05, 0.7); break; case 2: //ver freq ver sweep sweep_v(inst->sl, inst->w, inst->h, 1, inst->amp, inst->linp, inst->par, 0.05, 0.7); //ver f ver sw break; case 3: //ver freq hor sweep sweep_h(inst->sl, inst->w, inst->h, 1, inst->amp, inst->linp, inst->par, 0.05, 0.7); break; case 4: // "Siemens star" radials(inst->sl, inst->w, inst->h, inst->amp, inst->par, 60.0); break; case 5: //rings outwards rings(inst->sl, inst->w, inst->h, inst->amp, inst->par, inst->linp, 0.05, 0.7); break; case 6: //rings inwards rings(inst->sl, inst->w, inst->h, inst->amp, inst->par, inst->linp, 0.7, 0.05); break; case 7: //uniform 2D spatial frequency diags(inst->sl, inst->w, inst->h, inst->amp, inst->par, inst->f1, inst->f2); break; case 8: // "Nyquist blocks" nblocks(inst->sl, inst->w, inst->h, inst->amp); break; case 9: //square bars at integer Nyquist fractions sqbars(inst->sl, inst->w, inst->h, inst->amp); break; default: break; } }
// --- Ring Perception ----------------------------------------------------- // /// Returns the ring at \p index for the bond. Ring* Bond::ring(size_t index) const { return rings().advance_begin(index).front(); }
bool OBDepict::DrawMolecule(OBMol *mol) { if (!d->painter) return false; d->mol = mol; double width=0.0, height=0.0; OBAtom *atom; OBBondIterator j; OBAtomIterator i; if(mol->NumAtoms()>0) { // scale bond lengths double bondLengthSum = 0.0; for (OBBond *bond = mol->BeginBond(j); bond; bond = mol->NextBond(j)) bondLengthSum += bond->GetLength(); const double averageBondLength = bondLengthSum / mol->NumBonds(); const double f = mol->NumBonds() ? d->bondLength / averageBondLength : 1.0; for (atom = mol->BeginAtom(i); atom; atom = mol->NextAtom(i)) atom->SetVector(atom->GetX() * f, atom->GetY() * f, 0.0); // find min/max values double min_x, max_x; double min_y, max_y; atom = mol->BeginAtom(i); min_x = max_x = atom->GetX(); min_y = max_y = atom->GetY(); for (atom = mol->NextAtom(i); atom; atom = mol->NextAtom(i)) { min_x = std::min(min_x, atom->GetX()); max_x = std::max(max_x, atom->GetX()); min_y = std::min(min_y, atom->GetY()); max_y = std::max(max_y, atom->GetY()); } const double margin = 40.0; // translate all atoms so the bottom-left atom is at margin,margin for (atom = mol->BeginAtom(i); atom; atom = mol->NextAtom(i)) atom->SetVector(atom->GetX() - min_x + margin, atom->GetY() - min_y + margin, 0.0); width = max_x - min_x + 2*margin; height = max_y - min_y + 2*margin; //d->painter->SetPenWidth(d->penWidth); //d->painter->SetPenColor(d->pen)); //d->painter->SetFillColor(OBColor("black")); } d->painter->NewCanvas(width, height); // draw bonds if(d->options & genWedgeHash) d->SetWedgeAndHash(mol); for (OBBond *bond = mol->BeginBond(j); bond; bond = mol->NextBond(j)) { OBAtom *begin = bond->GetBeginAtom(); OBAtom *end = bond->GetEndAtom(); if((d->options & internalColor) && bond->HasData("color")) d->painter->SetPenColor(OBColor(bond->GetData("color")->GetValue())); else d->painter->SetPenColor(d->bondColor); if (bond->IsWedge()) { d->DrawWedge(begin, end); } else if (bond->IsHash()) { d->DrawHash(begin, end); } else if (!bond->IsInRing()) { d->DrawSimpleBond(begin, end, bond->GetBO()); } } // draw ring bonds std::vector<OBRing*> rings(mol->GetSSSR()); OBBitVec drawnBonds; for (std::vector<OBRing*>::iterator k = rings.begin(); k != rings.end(); ++k) { OBRing *ring = *k; std::vector<int> indexes = ring->_path; vector3 center(VZero); for (std::vector<int>::iterator l = indexes.begin(); l != indexes.end(); ++l) { center += mol->GetAtom(*l)->GetVector(); } center /= indexes.size(); for (unsigned int l = 0; l < indexes.size(); ++l) { OBAtom *begin = mol->GetAtom(indexes[l]); OBAtom *end; if (l+1 < indexes.size()) end = mol->GetAtom(indexes[l+1]); else end = mol->GetAtom(indexes[0]); OBBond *ringBond = mol->GetBond(begin, end); if (drawnBonds.BitIsSet(ringBond->GetId())) continue; if((d->options & internalColor) && ringBond->HasData("color")) d->painter->SetPenColor(OBColor(ringBond->GetData("color")->GetValue())); else d->painter->SetPenColor(d->bondColor); d->DrawRingBond(begin, end, center, ringBond->GetBO()); drawnBonds.SetBitOn(ringBond->GetId()); } } // draw atom labels for (atom = mol->BeginAtom(i); atom; atom = mol->NextAtom(i)) { double x = atom->GetX(); double y = atom->GetY(); int alignment = GetLabelAlignment(atom); bool rightAligned = false; switch (alignment) { case TopRight: case CenterRight: case BottomRight: rightAligned = true; default: break; } if((d->options & internalColor) && atom->HasData("color")) d->painter->SetPenColor(OBColor(atom->GetData("color")->GetValue())); else if(d->options & bwAtoms) d->painter->SetPenColor(d->bondColor); else d->painter->SetPenColor(OBColor(etab.GetRGB(atom->GetAtomicNum()))); //charge and radical int charge = atom->GetFormalCharge(); int spin = atom->GetSpinMultiplicity(); if(charge || spin) { OBFontMetrics metrics = d->painter->GetFontMetrics("N"); double yoffset = d->HasLabel(atom) ? 0.4 * metrics.height : 0.0; switch (GetLabelAlignment(atom)) { case TopCenter: case TopRight: case TopLeft: case CenterLeft: case CenterRight: yoffset = - 1.2 * metrics.height; } stringstream ss; if(charge) { if(abs(charge)!=1) ss << abs(charge); ss << (charge>0 ? "+" : "-") ; } if(spin) { ss << (spin==2 ? "." : ".."); yoffset += 0.5 * metrics.height; } if(spin || charge<0) d->painter->SetFontSize(2 * metrics.fontSize); d->painter->DrawText(x-0.4*metrics.width, y-yoffset, ss.str()); d->painter->SetFontSize(metrics.fontSize);//restore } if (atom->IsCarbon()) { if(!(d->options & drawAllC)) { if (atom->GetValence() > 1) continue; if ((atom->GetValence() == 1) && !(d->options & drawTermC))//!d->drawTerminalC) continue; } } stringstream ss; AliasData* ad = NULL; if(d->aliasMode && atom->HasData(AliasDataType)) ad = static_cast<AliasData*>(atom->GetData(AliasDataType)); //For unexpanded aliases use appropriate form of alias instead of element symbol, Hs, etc if(ad && !ad->IsExpanded()) { ss <<ad->GetAlias(rightAligned); OBColor aliasColor = !ad->GetColor().empty() ? ad->GetColor() : d->bondColor; d->painter->SetPenColor(aliasColor); } else { const char* atomSymbol; if(atom->IsHydrogen() && atom->GetIsotope()>1) atomSymbol = atom->GetIsotope()==2 ? "D" : "T"; else atomSymbol = etab.GetSymbol(atom->GetAtomicNum()); unsigned int hCount = atom->ImplicitHydrogenCount(); // rightAligned: // false CH3 // true H3C if (hCount && rightAligned) ss << "H"; if ((hCount > 1) && rightAligned) ss << hCount; ss << atomSymbol; if (hCount && !rightAligned) ss << "H"; if ((hCount > 1) && !rightAligned) ss << hCount; } d->DrawAtomLabel(ss.str(), alignment, vector3(x, y, 0.0)); } return true; }
/// Returns the number of rings the bond is a member of. int Bond::ringCount() const { return rings().size(); }