void fingerprint2::getFragments(vector<int> levels, vector<int> curfrag, int level, OBAtom* patom, OBBond* pbond) { //Recursive routine to analyse schemical structure and populate fragset and ringset //Hydrogens,charges(except dative bonds), spinMultiplicity ignored const int Max_Fragment_Size = 7; int bo=0; if(pbond) { bo = pbond->IsAromatic() ? 5 : pbond->GetBO(); // OBAtom* pprevat = pbond->GetNbrAtom(patom); // if(patom->GetFormalCharge() && (patom->GetFormalCharge() == -pprevat->GetFormalCharge())) // ++bo; //coordinate (dative) bond eg C[N+]([O-])=O is seen as CN(=O)=O } curfrag.push_back(bo); curfrag.push_back(patom->GetAtomicNum()); levels[patom->GetIdx()-1] = level; vector<OBEdgeBase*>::iterator itr; OBBond *pnewbond; // PrintFpt(curfrag,(int)patom); for (pnewbond = patom->BeginBond(itr);pnewbond;pnewbond = patom->NextBond(itr)) { if(pnewbond==pbond) continue; //don't retrace steps OBAtom* pnxtat = pnewbond->GetNbrAtom(patom); if(pnxtat->GetAtomicNum() == OBElements::Hydrogen) continue; int atlevel = levels[pnxtat->GetIdx()-1]; if(atlevel) //ring { if(atlevel==1) { //If complete ring (last bond is back to starting atom) add bond at front //and save in ringset curfrag[0] = pnewbond->IsAromatic() ? 5 : pnewbond->GetBO(); ringset.insert(curfrag); curfrag[0] = 0; } } else //no ring { if(level<Max_Fragment_Size) { // TRACE("level=%d size=%d %p frag[0]=%p\n",level, curfrag.size(),&curfrag, &(curfrag[0])); //Do the next atom; levels, curfrag are passed by value and hence copied getFragments(levels, curfrag, level+1, pnxtat, pnewbond); } } } //do not save C,N,O single atom fragments if(curfrag[0]==0 && (level>1 || patom->GetAtomicNum()>8 || patom->GetAtomicNum()<6)) { fragset.insert(curfrag); //curfrag ignored if an identical fragment already present // PrintFpt(curfrag,level); } }
bool WriteAlchemy(ostream &ofs,OBMol &mol) { unsigned int i; char buffer[BUFF_SIZE]; char bond_string[10]; snprintf(buffer, BUFF_SIZE, "%5d ATOMS, %5d BONDS, 0 CHARGES", mol.NumAtoms(), mol.NumBonds()); ofs << buffer << endl; ttab.SetFromType("INT"); ttab.SetToType("ALC"); OBAtom *atom; string str,str1; for(i = 1;i <= mol.NumAtoms(); i++) { atom = mol.GetAtom(i); str = atom->GetType(); ttab.Translate(str1,str); snprintf(buffer, BUFF_SIZE, "%5d %-6s%8.4f %8.4f %8.4f 0.0000", i, (char*)str1.c_str(), atom->GetX(), atom->GetY(), atom->GetZ()); ofs << buffer << endl; } OBBond *bond; vector<OBEdgeBase*>::iterator j; for (bond = mol.BeginBond(j);bond;bond = mol.NextBond(j)) { switch(bond->GetBO()) { case 1 : strcpy(bond_string,"SINGLE"); break; case 2 : strcpy(bond_string,"DOUBLE"); break; case 3 : strcpy(bond_string,"TRIPLE"); break; case 5 : strcpy(bond_string,"AROMATIC"); break; default : strcpy(bond_string,"SINGLE"); } snprintf(buffer, BUFF_SIZE, "%5d %4d %4d %s", bond->GetIdx()+1, bond->GetBeginAtomIdx(), bond->GetEndAtomIdx(), bond_string); ofs << buffer << endl; } return(true); }
bool WriteHIN(ostream &ofs,OBMol &mol) { unsigned int i, file_num = 1; string str,str1; char buffer[BUFF_SIZE]; OBAtom *atom; OBBond *bond; vector<OBEdgeBase*>::iterator j; char bond_char; ofs << "mol " << file_num << " " << mol.GetTitle() << endl;; for(i = 1;i <= mol.NumAtoms(); i++) { atom = mol.GetAtom(i); sprintf(buffer,"atom %d - %-3s ** - %8.5f %8.5f %8.5f %8.5f %d ", i, etab.GetSymbol(atom->GetAtomicNum()), atom->GetPartialCharge(), atom->GetX(), atom->GetY(), atom->GetZ(), atom->GetValence()); ofs << buffer; for (bond = atom->BeginBond(j); bond; bond = atom->NextBond(j)) { switch(bond->GetBO()) { case 1 : bond_char = 's'; break; case 2 : bond_char = 'd'; break; case 3 : bond_char = 't'; break; case 5 : bond_char = 'a'; break; default: bond_char = 's'; break; } sprintf(buffer,"%d %c ", (bond->GetNbrAtom(atom))->GetIdx(), bond_char); ofs << buffer; } ofs << endl; } ofs << "endmol " << file_num << endl; return(true); }
bool MOL2Format::WriteMolecule(OBBase* pOb, OBConversion* pConv) { OBMol* pmol = dynamic_cast<OBMol*>(pOb); if(pmol==NULL) return false; //Define some references so we can use the old parameter names ostream &ofs = *pConv->GetOutStream(); OBMol &mol = *pmol; bool ligandsOnly = pConv->IsOption("l", OBConversion::OUTOPTIONS)!=NULL; //The old code follows.... string str,str1; char buffer[BUFF_SIZE],label[BUFF_SIZE]; char rnum[BUFF_SIZE],rlabel[BUFF_SIZE]; ofs << "@<TRIPOS>MOLECULE" << endl; str = mol.GetTitle(); if (str.empty()) ofs << "*****" << endl; else ofs << str << endl; snprintf(buffer, BUFF_SIZE," %d %d 0 0 0", mol.NumAtoms(),mol.NumBonds()); ofs << buffer << endl; ofs << "SMALL" << endl; OBPairData *dp = (OBPairData*)mol.GetData("PartialCharges"); if (dp != NULL) { // Tripos spec says: // NO_CHARGES, DEL_RE, GASTEIGER, GAST_HUCK, HUCKEL, PULLMAN, // GAUSS80_CHARGES, AMPAC_CHARGES, MULLIKEN_CHARGES, DICT_ CHARGES, // MMFF94_CHARGES, USER_CHARGES if (dp->GetValue() == "Mulliken") ofs << "MULLIKEN_CHARGES" << endl; else // should pick from the Tripos types ofs << "GASTEIGER" << endl; } else { // No idea what these charges are... all our code sets "PartialCharges" ofs << "GASTEIGER" << endl; } ofs << "Energy = " << mol.GetEnergy() << endl; if (mol.HasData(OBGenericDataType::CommentData)) { OBCommentData *cd = (OBCommentData*)mol.GetData(OBGenericDataType::CommentData); ofs << cd->GetData(); } ofs << endl; ofs << "@<TRIPOS>ATOM" << endl; OBAtom *atom; OBResidue *res; vector<OBAtom*>::iterator i; vector<int> labelcount; labelcount.resize( etab.GetNumberOfElements() ); ttab.SetFromType("INT"); ttab.SetToType("SYB"); for (atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i)) { // // Use sequentially numbered atom names if no residues // snprintf(label,BUFF_SIZE, "%s%d", etab.GetSymbol(atom->GetAtomicNum()), ++labelcount[atom->GetAtomicNum()]); strcpy(rlabel,"<1>"); strcpy(rnum,"1"); str = atom->GetType(); ttab.Translate(str1,str); // // Use original atom names if there are residues // if (!ligandsOnly && (res = atom->GetResidue()) ) { // use original atom names defined by residue snprintf(label,BUFF_SIZE,"%s",(char*)res->GetAtomID(atom).c_str()); // make sure that residue name includes its number snprintf(rlabel,BUFF_SIZE,"%s%d",res->GetName().c_str(), res->GetNum()); snprintf(rnum,BUFF_SIZE,"%d",res->GetNum()); } snprintf(buffer,BUFF_SIZE,"%7d%1s%-6s%12.4f%10.4f%10.4f%1s%-5s%4s%1s %-8s%10.4f", atom->GetIdx(),"",label, atom->GetX(),atom->GetY(),atom->GetZ(), "",str1.c_str(), rnum,"",rlabel, atom->GetPartialCharge()); ofs << buffer << endl; } ofs << "@<TRIPOS>BOND" << endl; OBBond *bond; vector<OBBond*>::iterator j; OBSmartsPattern pat; string s1, s2; for (bond = mol.BeginBond(j);bond;bond = mol.NextBond(j)) { s1 = bond->GetBeginAtom()->GetType(); s2 = bond->GetEndAtom()->GetType(); if (bond->IsAromatic() || s1 == "O.co2" || s2 == "O.co2") strcpy(label,"ar"); else if (bond->IsAmide()) strcpy(label,"am"); else snprintf(label,BUFF_SIZE,"%d",bond->GetBO()); snprintf(buffer, BUFF_SIZE,"%6d%6d%6d%3s%2s", bond->GetIdx()+1,bond->GetBeginAtomIdx(),bond->GetEndAtomIdx(), "",label); ofs << buffer << endl; } // NO trailing blank line (PR#1868929). // ofs << endl; return(true); }
bool MacroModFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv) { OBMol* pmol = pOb->CastAndClear<OBMol>(); if(pmol==NULL) return false; //Define some references so we can use the old parameter names istream &ifs = *pConv->GetInStream(); OBMol &mol = *pmol; const char* defaultTitle = pConv->GetTitle(); // Get Title char buffer[BUFF_SIZE]; int natoms; vector<vector<pair<int,int> > > connections; if (ifs.getline(buffer,BUFF_SIZE)) { vector<string> vs; tokenize(vs,buffer," \n"); if ( !vs.empty() && vs.size() > 0) sscanf(buffer,"%i%*s",&natoms); if (natoms == 0) return false; if ( !vs.empty() && vs.size() > 1) mol.SetTitle(vs[1]); else { string s = defaultTitle; mol.SetTitle(defaultTitle); } } else return(false); mol.BeginModify(); mol.ReserveAtoms(natoms); connections.resize(natoms+1); /***********************************************************************/ // Get Type Bonds, BondOrder, X, Y, Z double x,y,z; vector3 v; char temp_type[10]; int i,j; double charge; OBAtom atom; ttab.SetFromType("MMD"); for (i = 1; i <= natoms; i++) { if (!ifs.getline(buffer,BUFF_SIZE)) break; int end[6], order[6]; sscanf(buffer,"%9s%d%d%d%d%d%d%d%d%d%d%d%d%lf%lf%lf", temp_type,&end[0],&order[0],&end[1],&order[1],&end[2],&order[2], &end[3], &order[3], &end[4], &order[4], &end[5], &order[5], &x, &y, &z); pair<int,int> tmp; for ( j = 0 ; j <=5 ; j++ ) { if ( end[j] > 0 && end[j] > i) { tmp.first = end[j]; tmp.second = order[j]; connections[i].push_back(tmp); } } v.SetX(x); v.SetY(y); v.SetZ(z); atom.SetVector(v); string str = temp_type,str1; ttab.SetToType("ATN"); ttab.Translate(str1,str); atom.SetAtomicNum(atoi(str1.c_str())); ttab.SetToType("INT"); ttab.Translate(str1,str); atom.SetType(str1); // stuff for optional fields buffer[109]='\0'; sscanf(&buffer[101],"%lf", &charge); atom.SetPartialCharge(charge); mol.AddAtom(atom); } for (i = 1; i <= natoms; i++) for (j = 0; j < (signed)connections[i].size(); j++) mol.AddBond(i, connections[i][j].first, connections[i][j].second); mol.EndModify(); OBBond *bond; vector<OBBond*>::iterator bi; for (bond = mol.BeginBond(bi);bond;bond = mol.NextBond(bi)) if (bond->GetBO() == 5 && !bond->IsInRing()) bond->SetBO(1); if ( natoms != (signed)mol.NumAtoms() ) return(false); // clean out remaining blank lines while(ifs.peek() != EOF && ifs.good() && (ifs.peek() == '\n' || ifs.peek() == '\r')) ifs.getline(buffer,BUFF_SIZE); return(true); }
bool OBResidueData::AssignBonds(OBMol &mol,OBBitVec &bv) { if (!_init) Init(); OBAtom *a1,*a2; OBResidue *r1,*r2; vector<OBAtom*>::iterator i,j; vector3 v; int bo; string skipres = ""; // Residue Number to skip string rname = ""; //assign residue bonds for (a1 = mol.BeginAtom(i);a1;a1 = mol.NextAtom(i)) { r1 = a1->GetResidue(); if (r1 == NULL) // atoms may not have residues continue; if (skipres.length() && r1->GetNumString() == skipres) continue; if (r1->GetName() != rname) { skipres = SetResName(r1->GetName()) ? "" : r1->GetNumString(); rname = r1->GetName(); } //assign bonds for each atom for (j=i,a2 = mol.NextAtom(j);a2;a2 = mol.NextAtom(j)) { r2 = a2->GetResidue(); if (r2 == NULL) // atoms may not have residues continue; if (r1->GetNumString() != r2->GetNumString()) break; if (r1->GetName() != r2->GetName()) break; if (r1->GetChain() != r2->GetChain()) break; // Fixes PR#2889763 - Fabian if ((bo = LookupBO(r1->GetAtomID(a1),r2->GetAtomID(a2)))) { // Suggested by Liu Zhiguo 2007-08-13 // for predefined residues, don't perceive connection // by distance // v = a1->GetVector() - a2->GetVector(); // if (v.length_2() < 3.5) //check by distance mol.AddBond(a1->GetIdx(),a2->GetIdx(),bo); } } } int hyb; string type; //types and hybridization rname = ""; // name of current residue skipres = ""; // don't skip any residues right now for (a1 = mol.BeginAtom(i);a1;a1 = mol.NextAtom(i)) { if (a1->GetAtomicNum() == OBElements::Oxygen && !a1->GetValence()) { a1->SetType("O3"); continue; } if (a1->GetAtomicNum() == OBElements::Hydrogen) { a1->SetType("H"); continue; } //***valence rule for O- if (a1->GetAtomicNum() == OBElements::Oxygen && a1->GetValence() == 1) { OBBond *bond; bond = (OBBond*)*(a1->BeginBonds()); if (bond->GetBO() == 2) { a1->SetType("O2"); a1->SetHyb(2); } else if (bond->GetBO() == 1) { // Leave the protonation/deprotonation to phmodel.txt a1->SetType("O3"); a1->SetHyb(3); // PR#3203039 -- Fix from Magnus Lundborg // a1->SetFormalCharge(0); } continue; } r1 = a1->GetResidue(); if (r1 == NULL) continue; // atoms may not have residues if (skipres.length() && r1->GetNumString() == skipres) continue; if (r1->GetName() != rname) { // if SetResName fails, skip this residue skipres = SetResName(r1->GetName()) ? "" : r1->GetNumString(); rname = r1->GetName(); } if (LookupType(r1->GetAtomID(a1),type,hyb)) { a1->SetType(type); a1->SetHyb(hyb); } else // try to figure it out by bond order ??? {} } return(true); }
bool ChemDrawXMLFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv) { static const xmlChar C_MOLECULE[] = "fragment"; static const xmlChar C_CDXML[] = "CDXML"; static const xmlChar C_BONDLENGTH[] = "BondLength"; static const xmlChar C_PAGE[] = "page"; static const xmlChar C_ATOM[] = "n"; static const xmlChar C_BOND[] = "b"; static const xmlChar C_ID[] = "id"; static const xmlChar C_CHARGE[] = "Charge"; static const xmlChar C_COORDS[] = "p"; static const xmlChar C_ELEMENT[] = "Element"; static const xmlChar C_ORDER[] = "Order"; static const xmlChar C_BEGIN[] = "B"; static const xmlChar C_END[] = "E"; static const xmlChar C_DISPLAY[] = "Display"; _pxmlConv = XMLConversion::GetDerived(pConv,false); if(!_pxmlConv) return false; OBMol* pmol = dynamic_cast<OBMol*>(pOb); if(pmol==NULL) return false; OBMol &mol = *pmol; OBBond *pbond; vector<OBBond*>::iterator j; if(_pxmlConv->GetOutputIndex() == 1) { xmlTextWriterStartDocument(writer(), NULL, NULL, NULL); xmlTextWriterWriteDTD(writer(), BAD_CAST "CDXML", NULL, BAD_CAST "http://www.camsoft.com/xml/cdxml.dtd", NULL); xmlTextWriterStartElement(writer(), C_CDXML); xmlTextWriterWriteFormatAttribute(writer(), C_BONDLENGTH , "30"); xmlTextWriterStartElement(writer(), C_PAGE); // put everything on one page // now guess the average bond size for the first molecule and scale to 30. _scale = 0.; if (mol.NumBonds()) { for (pbond = mol.BeginBond(j); pbond; pbond = mol.NextBond(j)) _scale += pbond->GetLength(); _scale /= mol.NumBonds(); } else _scale = 1.; // FIXME: what happens if the molecule has no bond? _scale = 30. / _scale; _offset = 0; } xmlTextWriterStartElement(writer(), C_MOLECULE); OBAtom *patom; vector<OBAtom*>::iterator i; int n; for (patom = mol.BeginAtom(i); patom; patom = mol.NextAtom(i)) { xmlTextWriterStartElement(writer(), C_ATOM); xmlTextWriterWriteFormatAttribute(writer(), C_ID , "%d", patom->GetIdx() + _offset); xmlTextWriterWriteFormatAttribute(writer(), C_COORDS , "%f %f", patom->GetX() * _scale, patom->GetY() * _scale); n = patom->GetAtomicNum(); if (n != 6) { xmlTextWriterWriteFormatAttribute(writer(), C_ELEMENT , "%d", n); } n = patom->GetFormalCharge(); if (n != 0) { xmlTextWriterWriteFormatAttribute(writer(), C_CHARGE , "%d", n); } xmlTextWriterEndElement(writer()); } for (pbond = mol.BeginBond(j); pbond; pbond = mol.NextBond(j)) { xmlTextWriterStartElement(writer(), C_BOND); patom = pbond->GetBeginAtom(); xmlTextWriterWriteFormatAttribute(writer(), C_BEGIN , "%d", patom->GetIdx() + _offset); patom = pbond->GetEndAtom(); xmlTextWriterWriteFormatAttribute(writer(), C_END , "%d", patom->GetIdx() + _offset); n = pbond->GetBO(); if (n != 1) { xmlTextWriterWriteFormatAttribute(writer(), C_ORDER , "%d", n); } if (pbond->IsHash()) xmlTextWriterWriteFormatAttribute(writer(), C_DISPLAY , "WedgeBegin"); else if (pbond->IsWedge()) xmlTextWriterWriteFormatAttribute(writer(), C_DISPLAY , "WedgedHashEnd"); xmlTextWriterEndElement(writer()); } _offset += mol.NumAtoms (); xmlTextWriterEndElement(writer());//molecule //TODO: Writing property block if(_pxmlConv->IsLast()) { xmlTextWriterEndDocument(writer()); // page xmlTextWriterEndDocument(writer()); //document OutputToStream(); } return true; }
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; }
bool HINFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv) { OBMol* pmol = dynamic_cast<OBMol*>(pOb); if(pmol==NULL) return false; //Define some references so we can use the old parameter names ostream &ofs = *pConv->GetOutStream(); OBMol &mol = *pmol; unsigned int i, file_num = 1; string str,str1; char buffer[BUFF_SIZE]; OBAtom *atom; OBBond *bond; vector<OBBond*>::iterator j; char bond_char; // make sure to escape titles in double quotes // PR#1501694 ofs << "mol " << file_num << " \"" << mol.GetTitle() << "\"\n"; for(i = 1;i <= mol.NumAtoms(); i++) { atom = mol.GetAtom(i); snprintf(buffer, BUFF_SIZE, "atom %d - %-3s ** - %8.5f %8.5f %8.5f %8.5f %d ", i, etab.GetSymbol(atom->GetAtomicNum()), atom->GetPartialCharge(), atom->GetX(), atom->GetY(), atom->GetZ(), atom->GetValence()); ofs << buffer; for (bond = atom->BeginBond(j); bond; bond = atom->NextBond(j)) { switch(bond->GetBO()) { case 1 : bond_char = 's'; break; case 2 : bond_char = 'd'; break; case 3 : bond_char = 't'; break; case 5 : bond_char = 'a'; break; default: bond_char = 's'; break; } if (bond->IsAromatic()) bond_char = 'a'; snprintf(buffer,BUFF_SIZE, "%d %c ", (bond->GetNbrAtom(atom))->GetIdx(), bond_char); ofs << buffer; } ofs << endl; } ofs << "endmol " << file_num << endl; return(true); }
bool AlchemyFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv) { OBMol* pmol = dynamic_cast<OBMol*>(pOb); if(pmol==NULL) return false; //Define some references so we can use the old parameter names ostream &ofs = *pConv->GetOutStream(); OBMol &mol = *pmol; unsigned int i; char buffer[BUFF_SIZE]; char bond_string[10]; snprintf(buffer, BUFF_SIZE, "%5d ATOMS, %5d BONDS, 0 CHARGES", mol.NumAtoms(), mol.NumBonds()); ofs << buffer << endl; OBAtom *atom; string str,str1; for(i = 1;i <= mol.NumAtoms(); i++) { atom = mol.GetAtom(i); str = atom->GetType(); ttab.SetFromType("INT"); ttab.SetToType("ALC"); ttab.Translate(str1,str); snprintf(buffer, BUFF_SIZE, "%5d %-6s%8.4f %8.4f %8.4f 0.0000", i, (char*)str1.c_str(), atom->GetX(), atom->GetY(), atom->GetZ()); ofs << buffer << endl; } OBBond *bond; vector<OBBond*>::iterator j; for (bond = mol.BeginBond(j);bond;bond = mol.NextBond(j)) { switch(bond->GetBO()) { case 1 : strcpy(bond_string,"SINGLE"); break; case 2 : strcpy(bond_string,"DOUBLE"); break; case 3 : strcpy(bond_string,"TRIPLE"); break; case 5 : strcpy(bond_string,"AROMATIC"); break; default : strcpy(bond_string,"SINGLE"); } snprintf(buffer, BUFF_SIZE, "%5d %4d %4d %s", bond->GetIdx()+1, bond->GetBeginAtomIdx(), bond->GetEndAtomIdx(), bond_string); ofs << buffer << endl; } return(true); }