本文整理汇总了C++中OBMol::PerceiveBondOrders方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::PerceiveBondOrders方法的具体用法?C++ OBMol::PerceiveBondOrders怎么用?C++ OBMol::PerceiveBondOrders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBMol
的用法示例。
在下文中一共展示了OBMol::PerceiveBondOrders方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadMolecule
//------------------------------------------------------------------------------
bool OBMoldenFormat::ReadMolecule( OBBase* pOb, OBConversion* pConv )
{
OBMol* pmol = dynamic_cast< OBMol* >(pOb);
if( pmol == 0 ) return false;
istream& ifs = *pConv->GetInStream();
pmol->BeginModify();
pmol->SetDimension( 3 );
string lineBuffer;
getline( ifs, lineBuffer );
while( ifs && lineBuffer.find( "[Atoms]" ) == string::npos
&& lineBuffer.find( "[ATOMS]" ) == string::npos )
{
getline( ifs, lineBuffer );
}
if( !ifs ) return false;
//[Atoms] AU OR Angs
double factor = 1.; // Angstrom
if( lineBuffer.find( "AU" ) != string::npos ) factor = 0.529177249; // Bohr
while( ifs )
{
getline( ifs, lineBuffer );
if( lineBuffer.size() == 0 ) continue;
if( lineBuffer.find( '[' ) != string::npos ) break;
istringstream is( lineBuffer );
string atomName;
int atomId;
int atomicNumber;
double x, y, z;
is >> atomName >> atomId >> atomicNumber >> x >> y >> z;
OBAtom* atom = pmol->NewAtom();
if( !atom ) break;
atom->SetAtomicNum( atomicNumber );
atom->SetVector( x * factor, y * factor, z * factor );
}
if( !pConv->IsOption( "b", OBConversion::INOPTIONS ) ) pmol->ConnectTheDots();
if (!pConv->IsOption( "s", OBConversion::INOPTIONS )
&& !pConv->IsOption( "b", OBConversion::INOPTIONS ) )
{
pmol->PerceiveBondOrders();
}
pmol->EndModify();
return true;
}
示例2: ReadPQS_geom
int ReadPQS_geom(istream &ifs, OBMol &mol, const char *title,
int input_style, double bohr_to_angstrom)
{
int atom_count=0;
double x, y, z;
char buffer[BUFF_SIZE];
string str;
OBAtom *atom;
vector<string> vs;
mol.Clear();
mol.BeginModify();
while (ifs.getline(buffer,BUFF_SIZE) && !card_found(buffer))
{
if (buffer[0]!='$')
{
tokenize(vs, buffer);
if (vs.size() < 1) return false; // timvdm 18/06/2008
atom=mol.NewAtom();
str=vs[0];
if (input_style==0)
{
if (vs.size() < 4) return false; // timvdm 18/06/2008
atom->SetAtomicNum(OBElements::GetAtomicNum(str.c_str()));
x=atof((char*) vs[1].c_str())*bohr_to_angstrom;
y=atof((char*) vs[2].c_str())*bohr_to_angstrom;
z=atof((char*) vs[3].c_str())*bohr_to_angstrom;
}
else
{
if (vs.size() < 5) return false; // timvdm 18/06/2008
str.replace (0,2,"");
atom->SetAtomicNum(OBElements::GetAtomicNum(str.c_str()));
x=atof((char*) vs[2].c_str())*bohr_to_angstrom;
y=atof((char*) vs[3].c_str())*bohr_to_angstrom;
z=atof((char*) vs[4].c_str())*bohr_to_angstrom;
}
atom->SetVector(x, y, z);
atom_count++;
}
}
mol.ConnectTheDots();
mol.PerceiveBondOrders();
mol.EndModify();
mol.SetTitle(title);
return atom_count;
}
示例3: ReadBiosymCAR
bool ReadBiosymCAR(istream &ifs,OBMol &mol, const char *title)
{
char buffer[BUFF_SIZE];
string str;
double x,y,z;
OBAtom *atom;
vector<string> vs;
mol.BeginModify();
while (ifs.getline(buffer,BUFF_SIZE))
{
if(strstr(buffer,"PBC") != NULL)
{
if(strstr(buffer,"ON") != NULL)
{
ifs.getline(buffer,BUFF_SIZE);
ifs.getline(buffer,BUFF_SIZE);
ifs.getline(buffer,BUFF_SIZE);
}
else
{
ifs.getline(buffer,BUFF_SIZE);
ifs.getline(buffer,BUFF_SIZE);
}
break;
}
}
while (ifs.getline(buffer,BUFF_SIZE))
{
if(strstr(buffer,"end") != NULL)
break;
atom = mol.NewAtom();
tokenize(vs,buffer);
atom->SetAtomicNum(etab.GetAtomicNum(vs[7].c_str()));
x = atof((char*)vs[1].c_str());
y = atof((char*)vs[2].c_str());
z = atof((char*)vs[3].c_str());
atom->SetVector(x,y,z);
}
mol.EndModify();
mol.ConnectTheDots();
mol.PerceiveBondOrders();
mol.SetTitle(title);
return(true);
}
示例4: ReadMolecule
bool ACRFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = pOb->CastAndClear<OBMol>();
if(pmol==NULL)
return false;
istream& ifs = *pConv->GetInStream();
pmol->BeginModify();
/** Parse the input stream and use the OpenBabel API to populate the OBMol **/
int id;
char buf[BUFF_SIZE];
int atoms, bonds, tmp;
float scale, dtmp;
bool atom_input = false, bond_input = false;
string type;
//int from, to;
double X,Y,Z;
vector<string> vs;
// read in one at a time
/* WARNING: Atom id starts from zero in Carine; not so in openbabel.
* Solution: increment atom id's */
while (true) {
ifs.getline(buf, BUFF_SIZE);
if (ifs.eof()) {
break;
}
if (sscanf(buf, "General Scale=%f\n", &dtmp)) {
scale = dtmp;
continue;
} else if (sscanf(buf, "Number of Atoms in Crystal=%d\n", &tmp)) {
atoms = tmp;
atom_input = true;
// read table column names
ifs.getline(buf, BUFF_SIZE);
continue;
} else if (sscanf(buf, "Number of Links in Crystal=%d\n", &tmp)) {
atom_input = false;
bond_input = true;
bonds = tmp;
// read table column names
ifs.getline(buf, BUFF_SIZE);
continue;
} else if ( '#' == buf[0] || '\r' == buf[0] || '\n' == buf[0] ) {
// between sections, in both windows and unix.
continue;
}
tokenize(vs, buf, " \t\r\n");
if (atom_input) {
if (vs.size() < 9) return false; // timvdm 18/06/2008
id = atoi((char*)vs[0].c_str()) + 1; // see warning above
type = vs[1];
X = atof((char*)vs[6].c_str())/scale;
Y = atof((char*)vs[7].c_str())/scale;
Z = atof((char*)vs[8].c_str())/scale;
OBAtom* a = pmol->NewAtom();
if (*(type.c_str()) != '*')
a->SetAtomicNum(etab.GetAtomicNum(type.c_str()));
a->SetVector(X,Y,Z);
} else if (bond_input) {
if (vs.size() < 2) return false; // timvdm 18/06/2008
// add to pmol
if (!pmol->AddBond(atoi((char*)vs[0].c_str()) + 1, atoi((char*)vs[1].c_str()) + 1,
1 /* bond order not specified in Carine, use PerceiveBondOrder later */))
{
obErrorLog.ThrowError(__FUNCTION__, "addition of bond between " + vs[0] + " and " + vs[1] + " failed", obError);
return false;
}
}
}
/* got sanity? */
if ( pmol->NumBonds() != bonds ) {
// then we read a different number of bonds than those promised.
obErrorLog.ThrowError(__FUNCTION__, "Number of bonds read does not match the number promised", obError);
return false;
} else if ( pmol->NumAtoms() != atoms ) {
obErrorLog.ThrowError(__FUNCTION__, "Number of atoms read does not match the number promised", obError);
return false;
}
pmol->PerceiveBondOrders();
pmol->EndModify();
return true;
}
示例5: ReadViewMol
bool ReadViewMol(istream &ifs,OBMol &mol,const char *title)
{
char buffer[BUFF_SIZE];
OBAtom *atom;
double x,y,z, border;
double factor = 1.0;
int bgn, end, order;
vector<string> vs;
bool foundTitle = false;
bool foundBonds = false;
mol.BeginModify();
while (ifs.getline(buffer,BUFF_SIZE))
{
if (strstr(buffer,"$title") != NULL)
{
if (!ifs.getline(buffer,BUFF_SIZE)) return (false);
mol.SetTitle(buffer);
foundTitle = true;
}
else if (strstr(buffer,"$coord") != NULL)
{
tokenize(vs,buffer);
if (vs.size() == 2)
factor = atof((char*)vs[1].c_str()); // conversion to angstrom
while (ifs.getline(buffer,BUFF_SIZE))
{
if (buffer[0] == '$') break;
tokenize(vs,buffer);
if (vs.size() != 4) return(false);
atom = mol.NewAtom();
x = atof((char*)vs[0].c_str()) * factor;
y = atof((char*)vs[1].c_str()) * factor;
z = atof((char*)vs[2].c_str()) * factor;
atom->SetVector(x,y,z); //set coordinates
atom->SetAtomicNum(etab.GetAtomicNum(vs[3].c_str()));
}
}
else if (strstr(buffer,"$bonds") != NULL)
{
foundBonds = true;
while (ifs.getline(buffer,BUFF_SIZE))
{
if (buffer[0] == '$') break;
sscanf(buffer,"%d %d %lf",&bgn,&end, &border);
if (border > 1.0)
order = int(border);
else
order = 1;
mol.AddBond(bgn+1,end+1,order);
}
}
else if (strstr(buffer,"$end") != NULL)
break;
} // while
mol.EndModify();
if (!foundTitle)
mol.SetTitle(title);
if (!foundBonds)
{
mol.ConnectTheDots();
mol.PerceiveBondOrders();
}
return(true);
}
示例6: ReadXYZ
//.........这里部分代码省略.........
cerr << "WARNING: Problems reading an XYZ file, method 'bool ReadXYZ(istream &,OBMol &,const char *)'" << endl
<< " Problems reading the first line. The first line must contain the number of atoms." << endl
<< " OpenBabel found the line '" << buffer << "'" << endl
<< " which could not be interpreted as a number." << endl;
return(false);
}
if (!natoms) {
cerr << "WARNING: Problems reading an XYZ file, method 'bool ReadXYZ(istream &,OBMol &,const char *)'" << endl
<< " Problems reading the first line. The first line must contain the number of atoms." << endl
<< " OpenBabel found the number '0' which obviously does not work." << endl;
return(false);
}
mol.ReserveAtoms(natoms);
// The next line contains a title string for the molecule. Use this
// as the title for the molecule if the line is not
// empty. Otherwise, use the title given by the calling function.
if (!ifs.getline(buffer,BUFF_SIZE)) {
cerr << "WARNING: Problems reading an XYZ file, method 'bool ReadXYZ(istream &,OBMol &,const char *)'" << endl
<< " Could not read the second line, file error." << endl;
return(false);
}
if (strlen(buffer) == 0)
mol.SetTitle(buffer);
else
mol.SetTitle(title);
// The next lines contain four items each, separated by white
// spaces: the atom type, and the coordinates of the atom
vector<string> vs;
for (unsigned int i = 1; i <= natoms; i ++) {
if (!ifs.getline(buffer,BUFF_SIZE)) {
cerr << "WARNING: Problems reading an XYZ file, method 'bool ReadXYZ(istream &,OBMol &,const char *)'" << endl
<< " Could not read line #" << i+2 << ", file error." << endl
<< " According to line one, there should be " << natoms << " atoms, and therefore " << natoms+2 << " lines in the file" << endl;
return(false);
}
tokenize(vs,buffer);
if (vs.size() != 4) {
cerr << "WARNING: Problems reading an XYZ file, method 'bool ReadXYZ(istream &,OBMol &,const char *)'" << endl
<< " Could not read line #" << i+2 << "." << endl
<< " OpenBabel found the line '" << buffer << "'" << endl
<< " According to the specifications, this line should contain exactly 4 entries, separated by white space." << endl
<< " However, OpenBabel found " << vs.size() << " items." << endl;
return(false);
}
// Atom Type: get the atomic number from the element table, using
// the first entry in the currently read line. If the entry makes
// sense, set the atomic number and leave the atomic type open
// (the type is then later faulted in when atom->GetType() is
// called). If the entry does not make sense to use, set the atom
// type manually, assuming that the author of the xyz-file had
// something "special" in mind.
OBAtom *atom = mol.NewAtom();
int atomicNum = etab.GetAtomicNum(vs[0].c_str());
atom->SetAtomicNum(etab.GetAtomicNum(vs[0].c_str())); //set atomic number, or '0' if the atom type is not recognized
if (atomicNum == 0)
atom->SetType(vs[0]);
// Read the atom coordinates
char *endptr;
double x = strtod((char*)vs[1].c_str(),&endptr);
if (endptr == (char*)vs[1].c_str()) {
cerr << "WARNING: Problems reading an XYZ file, method 'bool ReadXYZ(istream &,OBMol &,const char *)'" << endl
<< " Could not read line #" << i+2 << "." << endl
<< " OpenBabel found the line '" << buffer << "'" << endl
<< " According to the specifications, this line should contain exactly 4 entries, separated by white space." << endl
<< " Item #0: Atom Type, Items #1-#3 cartesian coordinates in Angstrom." << endl
<< " OpenBabel could not interpret item #1 as a number." << endl;
return(false);
}
double y = strtod((char*)vs[2].c_str(),&endptr);
if (endptr == (char*)vs[2].c_str()) {
cerr << "WARNING: Problems reading an XYZ file, method 'bool ReadXYZ(istream &,OBMol &,const char *)'" << endl
<< " Could not read line #" << i+2 << "." << endl
<< " OpenBabel found the line '" << buffer << "'" << endl
<< " According to the specifications, this line should contain exactly 4 entries, separated by white space." << endl
<< " Item #0: Atom Type, Items #1-#3 cartesian coordinates in Angstrom." << endl
<< " OpenBabel could not interpret item #2 as a number." << endl;
return(false);
}
double z = strtod((char*)vs[3].c_str(),&endptr);
if (endptr == (char*)vs[3].c_str()) {
cerr << "WARNING: Problems reading an XYZ file, method 'bool ReadXYZ(istream &,OBMol &,const char *)'" << endl
<< " Could not read line #" << i+2 << "." << endl
<< " OpenBabel found the line '" << buffer << "'" << endl
<< " According to the specifications, this line should contain exactly 4 entries, separated by white space." << endl
<< " Item #0: Atom Type, Items #1-#3 cartesian coordinates in Angstrom." << endl
<< " OpenBabel could not interpret item #3 as a number." << endl;
return(false);
}
atom->SetVector(x,y,z); //set coordinates
}
mol.ConnectTheDots();
mol.PerceiveBondOrders();
return(true);
}
示例7: tokenize
bool CHEM3D1Format::ReadChem3d(istream &ifs,OBMol &mol,bool mmads,const char *type_key)
{
char buffer[BUFF_SIZE];
int natoms,i;
char tmp[16],tmp1[16];
char atomic_type[16];
double exponent = 0.0;
double divisor = 1.0;
double Alpha,Beta,Gamma,A,B,C;
bool has_fractional = false, has_divisor = false;
matrix3x3 m;
vector<string> vs;
ifs.getline(buffer,BUFF_SIZE);
tokenize(vs,buffer);
if (mmads)
{
if (vs.empty())
return(false);
natoms = atoi((char*)vs[0].c_str());
if (vs.size() == 2)
mol.SetTitle(vs[1]);
}
else
{
switch(vs.size())
{
case 7 :
sscanf(buffer,"%d%lf%lf%lf%lf%lf%lf",
&natoms,&Alpha,&Beta,&Gamma,&A,&B,&C);
m.FillOrth(Alpha,Beta,Gamma,A,B,C);
has_fractional = true;
break;
case 8 :
sscanf(buffer,"%d%lf%lf%lf%lf%lf%lf%lf",
&natoms,&Alpha,&Beta,&Gamma,&A,&B,&C,&exponent);
m.FillOrth(Alpha,Beta,Gamma,A,B,C);
has_fractional = true;
has_divisor = true;
break;
default :
sscanf(buffer,"%d",&natoms);
break;
}
}
if (!natoms)
return(false);
divisor = pow(10.0,exponent);
mol.ReserveAtoms(natoms);
ttab.SetToType("INT");
ttab.SetFromType(type_key);
OBAtom *atom;
double x,y,z;
vector3 v;
unsigned int k;
for (i = 1; i <= natoms; i++)
{
ifs.getline(buffer,BUFF_SIZE);
sscanf(buffer,"%15s%*d%lf%lf%lf%15s",
atomic_type,
&x,
&y,
&z,
tmp);
v.Set(x,y,z);
if (has_fractional)
v *= m;
if (has_divisor)
v/= divisor;
tokenize(vs,buffer);
if (vs.empty())
return(false);
atom = mol.NewAtom();
ttab.Translate(tmp1,tmp);
atom->SetType(tmp1);
atom->SetVector(v);
atom->SetAtomicNum(etab.GetAtomicNum(atomic_type));
for (k = 6;k < vs.size(); k++)
mol.AddBond(atom->GetIdx(),atoi((char*)vs[k].c_str()),1);
}
// clean out remaining blank lines
while(ifs.peek() != EOF && ifs.good() &&
(ifs.peek() == '\n' || ifs.peek() == '\r'))
ifs.getline(buffer,BUFF_SIZE);
mol.PerceiveBondOrders();
return(true);
}