本文整理汇总了C++中OBBond::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ OBBond::GetLength方法的具体用法?C++ OBBond::GetLength怎么用?C++ OBBond::GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBBond
的用法示例。
在下文中一共展示了OBBond::GetLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteMolecule
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())
{
//.........这里部分代码省略.........
示例2: DrawMolecule
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);
//.........这里部分代码省略.........