本文整理汇总了C++中OBMol::Has3D方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::Has3D方法的具体用法?C++ OBMol::Has3D怎么用?C++ OBMol::Has3D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBMol
的用法示例。
在下文中一共展示了OBMol::Has3D方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tmpStr
extern "C" int
ob_3D (char *molfile)
{
OBMol mol;
OBConversion conv;
string tmpStr (molfile);
istringstream molstream (tmpStr);
int threed = 0;
conv.SetInAndOutFormats ("MDL", "MDL");
conv.Read (&mol, &molstream);
if (mol.Has3D ())
threed++;
return (threed);
}
示例2: readSmiString
bool OBReader::readSmiString(QString smiString)
{
using namespace OpenBabel;
OBConversion conv;
if (!conv.SetInFormat("smi"))
{
qDebug() << "Error in conv.SetInFormat().";
return false;
}
OBMol obMol;
if (!conv.ReadString(&obMol, smiString.toStdString()))
{
qDebug() << "Error occured while reading the smi string.";
return false;
}
if (!obMol.Has3D())
{
if (!buildGeometry(&obMol))
{
qDebug() << "Error in buildGeometry()";
return false;
}
}
if (!toMolecule(&obMol))
{
qDebug() << "Could not convert OBMol to Molecule.";
return false;
}
return true;
}
示例3: readFile
bool OBReader::readFile(QString fileName)
{
using namespace OpenBabel;
OBConversion conv;
OBFormat *format = conv.FormatFromExt(fileName.toStdString());
if (!format || !conv.SetInFormat(format))
{
qDebug() << "Unsupported File Format.";
return false;
}
std::ifstream ifs;
ifs.open(fileName.toStdString());
if (!ifs)
{
qDebug() << "Could not open the file.";
return false;
}
OBMol obMol;
if (!conv.Read(&obMol, &ifs))
{
qDebug() << "Error occured while reading the file.";
return false;
}
if (!obMol.Has3D())
{
static bool showMsgBox = true;
if (showMsgBox)
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("OBReader"));
msgBox.setText(tr("No 3D coordinate values present in this file."));
msgBox.setInformativeText(tr("OBReader will generate the rough molecular geometry."));
msgBox.setCheckBox(new QCheckBox(tr("Don’t show this message again.")));
msgBox.setIcon(QMessageBox::Information);
msgBox.exec();
showMsgBox = !msgBox.checkBox()->isChecked();
}
if (!buildGeometry(&obMol))
{
qDebug() << "Error in buildGeometry()";
return false;
}
}
if (!toMolecule(&obMol))
{
qDebug() << "Could not convert OBMol to Molecule.";
return false;
}
return true;
}
示例4: main
int main(int argc,char *argv[])
{
// turn off slow sync with C-style output (we don't use it anyway).
std::ios::sync_with_stdio(false);
OBConversion conv;
OBFormat *inFormat, *canFormat;
OBMol mol;
ifstream ifs;
vector<OBMol> fragments;
unsigned int fragmentCount = 0; // track how many in library -- give a running count
map<string, int> index; // index of cansmi
string currentCAN;
unsigned int size;
OBAtom *atom;
OBBond *bond;
bool nonRingAtoms, nonRingBonds;
char buffer[BUFF_SIZE];
canFormat = conv.FindFormat("can");
conv.SetOutFormat(canFormat);
if (argc < 2)
{
cout << "Usage: obfragment <file>" << endl;
return(-1);
}
for (int i = 1; i < argc; i++) {
cerr << " Reading file " << argv[i] << endl;
inFormat = conv.FormatFromExt(argv[i]);
if(inFormat==NULL || !conv.SetInFormat(inFormat))
{
cerr << " Cannot read file format for " << argv[i] << endl;
continue; // try next file
}
ifs.open(argv[i]);
if (!ifs)
{
cerr << "Cannot read input file: " << argv[i] << endl;
continue;
}
while(ifs.peek() != EOF && ifs.good())
{
conv.Read(&mol, &ifs);
if (!mol.Has3D()) continue; // invalid coordinates!
mol.DeleteHydrogens(); // remove these before we do anything else
do {
nonRingAtoms = false;
size = mol.NumAtoms();
for (unsigned int i = 1; i <= size; ++i)
{
atom = mol.GetAtom(i);
if (!atom->IsInRing()) {
mol.DeleteAtom(atom);
nonRingAtoms = true;
break; // don't know how many atoms there are
}
// Previously, we changed atoms to carbon here.
// Now we perform this alchemy in terms of string-rewriting
// once the canonical SMILES is generated
}
} while (nonRingAtoms);
if (mol.NumAtoms() < 3)
continue;
if (mol.NumBonds() == 0)
continue;
do {
nonRingBonds = false;
size = mol.NumBonds();
for (unsigned int i = 0; i < size; ++i)
{
bond = mol.GetBond(i);
if (!bond->IsInRing()) {
mol.DeleteBond(bond);
nonRingBonds = true;
break; // don't know how many bonds there are
}
}
} while (nonRingBonds);
fragments = mol.Separate();
for (unsigned int i = 0; i < fragments.size(); ++i)
{
if (fragments[i].NumAtoms() < 3) // too small to care
continue;
currentCAN = conv.WriteString(&fragments[i], true);
currentCAN = RewriteSMILES(currentCAN); // change elements to "a/A" for compression
if (index.find(currentCAN) != index.end()) { // already got this
index[currentCAN] += 1; // add to the count for bookkeeping
//.........这里部分代码省略.........
示例5: CalcSignedVolume
//! Calculate the signed volume for an atom. If the atom has a valence of 3
//! the coordinates of an attached hydrogen are calculated
//! Puts attached Hydrogen last at the moment, like mol V3000 format.
//! If ReZero=false (the default is true) always make pseudo z coords and leave them in mol
double CalcSignedVolume(OBMol &mol,OBAtom *atm, bool ReZeroZ)
{
vector3 tmp_crd;
vector<unsigned int> nbr_atms;
vector<vector3> nbr_crds;
bool use_central_atom = false,is2D=false;
// double hbrad = etab.CorrectedBondRad(1,0);
if (!ReZeroZ || !mol.Has3D()) //give pseudo Z coords if mol is 2D
{
vector3 v,vz(0.0,0.0,1.0);
is2D = true;
OBAtom *nbr;
OBBond *bond;
vector<OBBond*>::iterator i;
for (bond = atm->BeginBond(i);bond;bond = atm->NextBond(i))
{
nbr = bond->GetEndAtom();
if (nbr != atm)
{
v = nbr->GetVector();
if (bond->IsWedge())
v += vz;
else
if (bond->IsHash())
v -= vz;
nbr->SetVector(v);
}
else
{
nbr = bond->GetBeginAtom();
v = nbr->GetVector();
if (bond->IsWedge())
v -= vz;
else
if (bond->IsHash())
v += vz;
nbr->SetVector(v);
}
}
}
if (atm->GetHvyValence() < 3)
{
stringstream errorMsg;
errorMsg << "Cannot calculate a signed volume for an atom with a heavy atom valence of " << atm->GetHvyValence() << endl;
obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obInfo);
return(0.0);
}
// Create a vector with the coordinates of the neighbor atoms
// Also make a vector with Atom IDs
OBAtom *nbr;
vector<OBBond*>::iterator bint;
for (nbr = atm->BeginNbrAtom(bint);nbr;nbr = atm->NextNbrAtom(bint))
{
nbr_atms.push_back(nbr->GetIdx());
}
// sort the neighbor atoms to insure a consistent ordering
sort(nbr_atms.begin(),nbr_atms.end());
for (unsigned int i = 0; i < nbr_atms.size(); ++i)
{
OBAtom *tmp_atm = mol.GetAtom(nbr_atms[i]);
nbr_crds.push_back(tmp_atm->GetVector());
}
/*
// If we have three heavy atoms we need to calculate the position of the fourth
if (atm->GetHvyValence() == 3)
{
double bondlen = hbrad+etab.CorrectedBondRad(atm->GetAtomicNum(),atm->GetHyb());
atm->GetNewBondVector(tmp_crd,bondlen);
nbr_crds.push_back(tmp_crd);
}
*/
for(unsigned int j=0;j < nbr_crds.size();++j) // Checks for a neighbour having 0 co-ords (added hydrogen etc)
{
// are the coordinates zero to 6 or more significant figures
if (nbr_crds[j].IsApprox(VZero, 1.0e-6) && use_central_atom==false)
use_central_atom=true;
else if (nbr_crds[j].IsApprox(VZero, 1.0e-6))
{
obErrorLog.ThrowError(__FUNCTION__, "More than 2 neighbours have 0 co-ords when attempting 3D chiral calculation", obInfo);
}
}
// If we have three heavy atoms we can use the chiral center atom itself for the fourth
// will always give same sign (for tetrahedron), magnitude will be smaller.
if(nbr_atms.size()==3 || use_central_atom==true)
{
nbr_crds.push_back(atm->GetVector());
nbr_atms.push_back(mol.NumAtoms()+1); // meed to add largest number on end to work
}
OBChiralData* cd=(OBChiralData*)atm->GetData(OBGenericDataType::ChiralData); //Set the output atom4refs to the ones used
if(cd==NULL)
//.........这里部分代码省略.........