本文整理汇总了C++中OBAtom::GetImplicitHCount方法的典型用法代码示例。如果您正苦于以下问题:C++ OBAtom::GetImplicitHCount方法的具体用法?C++ OBAtom::GetImplicitHCount怎么用?C++ OBAtom::GetImplicitHCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBAtom
的用法示例。
在下文中一共展示了OBAtom::GetImplicitHCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Apply
bool OBChemTsfm::Apply(OBMol &mol)
{
if (!_bgn.Match(mol))
return(false);
mol.BeginModify();
vector<vector<int> > mlist = _bgn.GetUMapList();
obErrorLog.ThrowError(__FUNCTION__,
"Ran OpenBabel::OBChemTransform", obAuditMsg);
if (!_vchrg.empty()) //modify charges
{
vector<vector<int> >::iterator i;
vector<pair<int,int> >::iterator j;
for (i = mlist.begin();i != mlist.end();++i)
for (j = _vchrg.begin();j != _vchrg.end();++j)
if (j->first < (signed)i->size()) { //goof proofing
OBAtom *atom = mol.GetAtom((*i)[j->first]);
int old_charge = atom->GetFormalCharge();
atom->SetFormalCharge(j->second);
int new_hcount = atom->GetImplicitHCount() + (j->second - old_charge);
if (new_hcount < 0)
new_hcount = 0;
atom->SetImplicitHCount(new_hcount);
}
}
if (!_vbond.empty()) //modify bond orders
{
OBBond *bond;
vector<vector<int> >::iterator i;
vector<pair<pair<int,int>,int> >::iterator j;
for (i = mlist.begin();i != mlist.end();++i)
for (j = _vbond.begin();j != _vbond.end();++j)
{
bond = mol.GetBond((*i)[j->first.first],(*i)[j->first.second]);
if (!bond)
{
obErrorLog.ThrowError(__FUNCTION__, "unable to find bond", obDebug);
continue;
}
unsigned int old_bond_order = bond->GetBondOrder();
bond->SetBondOrder(j->second);
for (int k = 0; k < 2; ++k) {
OBAtom* atom = k == 0 ? bond->GetBeginAtom() : bond->GetEndAtom();
int new_hcount = atom->GetImplicitHCount() - (j->second - old_bond_order);
if (new_hcount < 0)
new_hcount = 0;
atom->SetImplicitHCount(new_hcount);
}
}
}
if (!_vadel.empty() || !_vele.empty()) //delete atoms and change elements
{
vector<int>::iterator j;
vector<vector<int> >::iterator i;
if (!_vele.empty())
{
vector<pair<int,int> >::iterator k;
for (i = mlist.begin();i != mlist.end();++i)
for (k = _vele.begin();k != _vele.end();++k)
mol.GetAtom((*i)[k->first])->SetAtomicNum(k->second);
}
//make sure same atom isn't deleted twice
vector<bool> vda;
vector<OBAtom*> vdel;
vda.resize(mol.NumAtoms()+1,false);
for (i = mlist.begin();i != mlist.end();++i)
for (j = _vadel.begin();j != _vadel.end();++j)
if (!vda[(*i)[*j]])
{
vda[(*i)[*j]] = true;
vdel.push_back(mol.GetAtom((*i)[*j]));
}
vector<OBAtom*>::iterator k;
for (k = vdel.begin();k != vdel.end();++k)
mol.DeleteAtom((OBAtom*)*k);
}
mol.EndModify();
return(true);
}