本文整理汇总了C++中OBAtom::SetFormalCharge方法的典型用法代码示例。如果您正苦于以下问题:C++ OBAtom::SetFormalCharge方法的具体用法?C++ OBAtom::SetFormalCharge怎么用?C++ OBAtom::SetFormalCharge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBAtom
的用法示例。
在下文中一共展示了OBAtom::SetFormalCharge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tmpStr
extern "C" char *
ob_strip_salts (char *smiles, int neutralize_residue)
{
OBAtom atom;
OBMol mol, largestFragment;
OBConversion conv;
string tmpStr (smiles);
string outstring;
istringstream molstream1 (tmpStr);
ostringstream molstream2;
vector<OBMol> fragments;
vector <OBMol>::const_iterator i;
char *tmpMolfile;
int max = 0;
conv.SetInAndOutFormats ("SMI", "SMI");
conv.Read (&mol, &molstream1);
fragments = mol.Separate();
for( i = fragments.begin(); i != fragments.end(); i++ ) {
if (i->NumAtoms() > max) {
max=i->NumAtoms();
largestFragment = *i;
}
}
if(neutralize_residue != 0) {
largestFragment.ConvertDativeBonds();
FOR_ATOMS_OF_MOL(atom, largestFragment) {
atom->SetFormalCharge(0);
}
示例2: DeleteExpandedAtoms
void AliasData::DeleteExpandedAtoms(OBMol& mol)
{
//The atom that carries the AliasData object remains as an Xx atom with no charge;
//the others are deleted. All the attached hydrogens are also deleted.
for(unsigned i=0;i<_expandedatoms.size();++i)
{
OBAtom* at = mol.GetAtomById(_expandedatoms[i]);
if(!at)
continue;
mol.DeleteHydrogens(at);
if(at->HasData(AliasDataType))
{
at->SetAtomicNum(0);
at->SetFormalCharge(0);
at->SetSpinMultiplicity(0);
}
else
mol.DeleteAtom(at);
}
_expandedatoms.clear();
}
示例3: 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);
}
示例4: parseAtomRecord
//.........这里部分代码省略.........
resname == "GPG" || resname == "NAD" || resname == "NAL" ||
resname == "NDP" || resname == "ABA") {
if (type.size() > 1)
type = type.substr(0,1);
//type.erase(1,type.size()-1);
} else // other residues
if (isdigit(type[0])){
type = type.substr(1,1);
}
else
if (type.size() > 1 && isdigit(type[1]))
type = type.substr(0,1);
else
if (type.size() > 1 && isalpha(type[1])) {
if (type[0] == 'O' && type[1] == 'H')
type = type.substr(0,1); // no "Oh" element (e.g. 1MBN)
else if(isupper(type[1])) {
type[1] = tolower(type[1]);
}
}
}
} // HETATM records
} // no element column to use
OBAtom atom;
/* X, Y, Z */
string xstr = sbuf.substr(24,8);
string ystr = sbuf.substr(32,8);
string zstr = sbuf.substr(40,8);
vector3 v(atof(xstr.c_str()),atof(ystr.c_str()),atof(zstr.c_str()));
atom.SetVector(v);
atom.ForceImplH();
// useful for debugging unknown atom types (e.g., PR#1577238)
// cout << mol.NumAtoms() + 1 << " : '" << element << "'" << " " << etab.GetAtomicNum(element.c_str()) << endl;
if (elementFound)
atom.SetAtomicNum(etab.GetAtomicNum(element.c_str()));
else // use our old-style guess from athe atom type
atom.SetAtomicNum(etab.GetAtomicNum(type.c_str()));
if ( (! scharge.empty()) && " " != scharge )
{
if ( isdigit(scharge[0]) && ('+' == scharge[1] || '-' == scharge[1]) )
{
const char reorderCharge[3] = { scharge[1], scharge[0], '\0' };
const int charge = atoi(reorderCharge);
atom.SetFormalCharge(charge);
}
else
{
stringstream errorMsg;
errorMsg << "WARNING: Problems reading a PDB file\n"
<< " Problems reading a HETATM or ATOM record.\n"
<< " According to the PDB specification,\n"
<< " columns 79-80 should contain charge of the atom\n"
<< " but OpenBabel found '" << scharge << "' (atom " << mol.NumAtoms()+1 << ").";
obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obWarning);
}
}
else {
atom.SetFormalCharge(0);
}
/* residue sequence number */
string resnum = sbuf.substr(16,4);
OBResidue *res = (mol.NumResidues() > 0) ? mol.GetResidue(mol.NumResidues()-1) : NULL;
if (res == NULL
|| res->GetName() != resname
|| res->GetNumString() != resnum
|| res->GetChain() != chain)
{
vector<OBResidue*>::iterator ri;
for (res = mol.BeginResidue(ri) ; res ; res = mol.NextResidue(ri))
if (res->GetName() == resname
&& res->GetNumString() == resnum
&& static_cast<int>(res->GetChain()) == chain)
break;
if (res == NULL) {
res = mol.NewResidue();
res->SetChain(chain);
res->SetName(resname);
res->SetNum(resnum);
}
}
if (!mol.AddAtom(atom))
return(false);
else {
OBAtom *atom = mol.GetAtom(mol.NumAtoms());
res->AddAtom(atom);
res->SetSerialNum(atom, atoi(serno.c_str()));
res->SetAtomID(atom, sbuf.substr(6,4));
res->SetHetAtom(atom, hetatm);
return(true);
}
} // end reading atom records
示例5: DoElement
bool ChemDrawXMLFormat::DoElement(const string& name)
{
string buf;
if(name=="fragment")
{
//This is the start of the molecule we are extracting and it will
//be put into the OBMol* _pmol declared in the parent class.
//initialise everything
_tempAtom.Clear();
atoms.clear();
_pmol->SetDimension(2);
_pmol->BeginModify();
buf = _pxmlConv->GetAttribute("id");
if (buf.length())
{
_pmol->SetTitle(buf);
}
}
else if(name=="n")
{
EnsureEndElement();
buf = _pxmlConv->GetAttribute("Type");
if (buf.length())
{
if (buf != "Unspecified" && buf != "Element")
{
cerr << "CDXML Format: Node type \"" << buf <<
"\" is not currently supported." << endl;
return false; // FIXME: use as many types as possible
}
}
_tempAtom.SetAtomicNum(6); // default is carbon
buf = _pxmlConv->GetAttribute("id");
if (buf.length())
_tempAtom.SetIdx(atoi(buf.c_str()));
buf = _pxmlConv->GetAttribute("Element");
if (buf.length())
_tempAtom.SetAtomicNum(atoi(buf.c_str()));
buf = _pxmlConv->GetAttribute("p"); // coords
if (buf.length())
{
double x = 0., y = 0.;
sscanf(buf.c_str(), "%lf %lf", &x, &y);
_tempAtom.SetVector(x, y, 0.);
}
buf = _pxmlConv->GetAttribute("Charge");
if (buf.length())
_tempAtom.SetFormalCharge(atoi(buf.c_str()));
}
else if(name=="b")
{
EnsureEndElement();
bool invert_ends = false;
Begin = End = Flag = 0;
buf = _pxmlConv->GetAttribute("Order");
if (buf.length())
Order = atoi(buf.c_str());
else
Order = 1; //default value
buf = _pxmlConv->GetAttribute("Display");
if (buf.length())
{
if (buf == "WedgeEnd")
{
invert_ends = true;
Flag = OB_HASH_BOND;
}
else if (buf == "WedgeBegin")
{
Flag = OB_HASH_BOND;
}
else if (buf == "Hash" ||buf == "WedgedHashBegin")
{
Flag = OB_WEDGE_BOND;
}
else if (buf == "WedgedHashEnd")
{
invert_ends = true;
Flag = OB_WEDGE_BOND;
}
}
buf = _pxmlConv->GetAttribute("B");
if (buf.length())
{
if (invert_ends)
End = atoms[atoi(buf.c_str())];
else
Begin = atoms[atoi(buf.c_str())];
}
buf = _pxmlConv->GetAttribute("E");
if (buf.length())
{
if (invert_ends)
Begin = atoms[atoi(buf.c_str())];
else
End = atoms[atoi(buf.c_str())];
}
//.........这里部分代码省略.........