本文整理汇总了C++中OBMol::ReserveAtoms方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::ReserveAtoms方法的具体用法?C++ OBMol::ReserveAtoms怎么用?C++ OBMol::ReserveAtoms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBMol
的用法示例。
在下文中一共展示了OBMol::ReserveAtoms方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadFeat
bool ReadFeat(istream &ifs,OBMol &mol, const char *title)
{
char buffer[BUFF_SIZE];
int i,natoms;
ifs.getline(buffer,BUFF_SIZE);
sscanf(buffer,"%d",&natoms);
mol.ReserveAtoms(natoms);
mol.BeginModify();
if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
mol.SetTitle(buffer);
double x,y,z;
char type[20];
OBAtom *atom;
for (i = 0; i < natoms;i++)
{
if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
sscanf(buffer,"%s %lf %lf %lf",
type,
&x,
&y,
&z);
CleanAtomType(type);
atom = mol.NewAtom();
atom->SetVector(x,y,z);
atom->SetAtomicNum(etab.GetAtomicNum(type));
}
mol.EndModify();
return(true);
}
示例2: ReadAlchemy
bool ReadAlchemy(istream &ifs,OBMol &mol, const char *title)
{
int i;
int natoms,nbonds;
char buffer[BUFF_SIZE];
ifs.getline(buffer,BUFF_SIZE);
sscanf(buffer,"%d %*s %d", &natoms, &nbonds);
if (!natoms) return(false);
mol.ReserveAtoms(natoms);
ttab.SetFromType("ALC");
string str;
double x,y,z;
OBAtom *atom;
vector<string> vs;
for (i = 1; i <= natoms; i ++)
{
if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
tokenize(vs,buffer);
if (vs.size() != 6) return(false);
atom = mol.NewAtom();
x = atof((char*)vs[2].c_str());
y = atof((char*)vs[3].c_str());
z = atof((char*)vs[4].c_str());
atom->SetVector(x,y,z); //set coordinates
//set atomic number
ttab.SetToType("ATN"); ttab.Translate(str,vs[1]);
atom->SetAtomicNum(atoi(str.c_str()));
//set type
ttab.SetToType("INT"); ttab.Translate(str,vs[1]);
atom->SetType(str);
}
char bobuf[100];
string bostr;
int bgn,end,order;
for (i = 0; i < nbonds; i++)
{
if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
sscanf(buffer,"%*d%d%d%s",&bgn,&end,bobuf);
bostr = bobuf; order = 1;
if (bostr == "DOUBLE") order = 2;
else if (bostr == "TRIPLE") order = 3;
else if (bostr == "AROMATIC") order = 5;
mol.AddBond(bgn,end,order);
}
mol.SetTitle(title);
return(true);
}
示例3: ReadXYZ
bool ReadXYZ(istream &ifs,OBMol &mol,const char *title)
{
char buffer[BUFF_SIZE];
// Read the first line, which should contain the number of atoms in
// the molecule.
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 first line, file error." << endl;
return(false);
}
unsigned int natoms; // [ejk] assumed natoms could not be -ve
if (sscanf(buffer,"%d", &natoms) == 0) {
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
//.........这里部分代码省略.........
示例4: 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);
}