本文整理汇总了C++中OBMol::SetTitle方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::SetTitle方法的具体用法?C++ OBMol::SetTitle怎么用?C++ OBMol::SetTitle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBMol
的用法示例。
在下文中一共展示了OBMol::SetTitle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ReadMolecule
bool GenBankFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = pOb->CastAndClear<OBMol>();
if (pmol == 0)
return false;
std::istream * in = pConv->GetInStream();
pmol->BeginModify();
std::string line;
SequenceType sequence_type = UnknownSequence;
getline( * in, line);
while (!in->eof())
{ // We have a new line in 'line'
if (!line.compare(0, 6, "LOCUS", 6) || !line.compare(0, 2, "ID ", 2))
{
if (sequence_type == GenBankFormat::UnknownSequence)
{ // attempt to determine the sequence type
if (line.find("RNA") != std::string::npos)
sequence_type = GenBankFormat::RNASequence;
else if (line.find("DNA") != std::string::npos)
sequence_type = GenBankFormat::DNASequence;
}
}
else if (!line.compare(0, 6, "DEFINITION", 6) || !line.compare(0, 2, "DE ", 2))
{
if (sequence_type == GenBankFormat::UnknownSequence)
{ // attempt to determine the sequence type
if (line.find("RNA") != std::string::npos)
sequence_type = GenBankFormat::RNASequence;
else if (line.find("DNA") != std::string::npos)
sequence_type = GenBankFormat::DNASequence;
else if (line.find("gene") != std::string::npos)
sequence_type = GenBankFormat::DNASequence;
}
if (pmol->GetTitle()[0] == 0)
{
std::string::size_type fc = line.find(' ');
while (fc != std::string::npos && strchr(" \t\n\r", line[fc]))
++ fc;
if (fc != std::string::npos)
pmol->SetTitle( & (line.c_str()[fc]) );
}
}
else if (!line.compare(0, 6, "ORIGIN", 6) || !line.compare(0, 2, "SQ ", 2))
break;
getline( * in, line);
}
if (sequence_type == GenBankFormat::UnknownSequence)
sequence_type = GenBankFormat::DNASequence;
bool rv = ReadFASTASequence(pmol, sequence_type, in,
!pConv->IsOption("b",OBConversion::INOPTIONS), !pConv->IsOption("s",OBConversion::INOPTIONS));
pmol->EndModify();
return rv;
}
示例3: 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);
}
示例4: 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;
}
示例5: 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);
}
示例6: ReadHIN
bool ReadHIN(istream &ifs,OBMol &mol, const char *title)
{
// Right now only read in the first molecule
int i;
int max, bo;
char buffer[BUFF_SIZE];
string str,str1;
double x,y,z;
OBAtom *atom;
vector<string> vs;
ifs.getline(buffer, BUFF_SIZE);
while (strstr(buffer,"mol") == NULL)
ifs.getline(buffer, BUFF_SIZE);
ifs.getline(buffer, BUFF_SIZE);
mol.BeginModify();
while (strstr(buffer,"endmol") == NULL)
{
tokenize(vs,buffer); // Don't really know how long it'll be
if (vs.size() < 11) break;
atom = mol.NewAtom();
atom->SetAtomicNum(etab.GetAtomicNum(vs[3].c_str()));
x = atof((char*)vs[7].c_str());
y = atof((char*)vs[8].c_str());
z = atof((char*)vs[9].c_str());
atom->SetVector(x,y,z);
max = 11 + 2 * atoi((char *)vs[10].c_str());
for (i = 11; i < max; i+=2)
{
switch(((char*)vs[i+1].c_str())[0]) // First char in next token
{
case 's': bo = 1; break;
case 'd': bo = 2; break;
case 't': bo = 3; break;
case 'a': bo = 5; break;
default : bo = 1; break;
}
mol.AddBond(mol.NumAtoms(), atoi((char *)vs[i].c_str()), bo);
}
ifs.getline(buffer, BUFF_SIZE);
}
mol.EndModify();
mol.SetTitle(title);
return(true);
}
示例7: main
int main(int argc, char **argv)
{
// Define location of file formats for testing
#ifdef FORMATDIR
char env[BUFF_SIZE];
snprintf(env, BUFF_SIZE, "BABEL_LIBDIR=%s", FORMATDIR);
putenv(env);
#endif
std::ifstream ifs(GetFilename("canonstable.can").c_str());
OB_REQUIRE( ifs );
OBMol mol;
OBConversion conv;
conv.SetInFormat("smi");
conv.SetOutFormat("can");
std::string line;
while (std::getline(ifs, line)) {
OB_REQUIRE( conv.ReadString(&mol, line.c_str()) );
std::vector<OBAtom*> atoms;
FOR_ATOMS_OF_MOL(atom, mol)
atoms.push_back(&*atom);
for (int i = 0; i < 5; ++i) {
// shuffle the atoms
std::random_shuffle(atoms.begin(), atoms.end());
mol.RenumberAtoms(atoms);
// get can smiles
mol.SetTitle("");
std::string cansmi = conv.WriteString(&mol, true);
// comapare with ref
if (cansmi != line) {
cout << "ref = " << line << endl;
cout << "can = " << cansmi << endl;
OB_ASSERT( cansmi == line );
}
}
}
return 0;
}
示例8: ReadMolecule
bool TitleFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
// Reads titles separated by spaces, tabs or newlines,
// If option -at set titles can contain spaces.
OBMol* pmol = pOb->CastAndClear<OBMol>();
string title;
istream& ifs = *pConv->GetInStream();
if(pConv->IsOption("t",OBConversion::INOPTIONS))
{
while( ifs && (ifs.peek()!='\t') && (ifs.peek()!='\n') && (ifs.peek()!=EOF))
title += ifs.get();
ifs.get(); //delimiter
}
else
ifs >> title;
pmol->SetTitle(Trim(title));
return true;
}
示例9: ReadMolecule
bool ThermoFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = pOb->CastAndClear<OBMol>();
if(!pmol)
return false;
bool stopOnEnd = pConv->IsOption("e",OBConversion::INOPTIONS)!=NULL;
pmol->SetDimension(0);
OBNasaThermoData* pND = new OBNasaThermoData; //to store rate constant data
pND->SetOrigin(fileformatInput);
pmol->SetData(pND);
istream &ifs = *pConv->GetInStream();
double DefaultMidT = 1500;
char ln[BUFF_SIZE];
unsigned int i;
//find line with 1 in col 80
do
{
if(!ifs.getline(ln,BUFF_SIZE) || stopOnEnd && !strncasecmp(ln,"END",3))
return false;
}while(ln[79]!='1');
char phase, nam[25], dum[7], elname[3];
elname[2]=0;
int elnum;
double Coeff[14];
sscanf(ln,"%18s%6s",nam,dum);
pmol->SetTitle(nam);
char* p=ln+24;
if(ln[80]=='&')
{
//Reaction Design extension
p+=20;
string line;
if(!getline(ifs,line))return false;
vector<string> toks;
tokenize(toks,line," \t\n\r");
for(i=0;i<toks.size();i+=2)
{
OBAtom atom;
atom.SetAtomicNum(etab.GetAtomicNum(toks[i].c_str()));
elnum = atoi(toks[i+1].c_str());
atom.ForceNoH();
for(;elnum>0;--elnum)
pmol->AddAtom(atom);
}
}
else
{
for(i=0;i<4;i++,p+=5)
{
char snum[4]={0,0,0,0};//Was problem with F 10 0 reading as ten
sscanf(p,"%c%c%c%c%c",elname,elname+1,snum,snum+1,snum+2);
elnum=atoi(snum);
if(elname[0]!=' ' && elname[0]!='0')
{
if(elname[1]==' ')
elname[1]=0;
OBAtom atom;
atom.SetAtomicNum(etab.GetAtomicNum(elname));
atom.ForceNoH();
for(;elnum>0;--elnum)
pmol->AddAtom(atom);
}
}
}
double LoT, HiT, MidT=0;
/* int nc = */sscanf(p,"%c%10lf%10lf10%lf",&phase, &LoT, &HiT, &MidT);
pND->SetPhase(phase);
pND->SetLoT(LoT);
pND->SetHiT(HiT);
if(MidT>HiT || MidT<LoT)
MidT=DefaultMidT;
pND->SetMidT(MidT);
if (!ifs.getline(ln, BUFF_SIZE)) return false;
p=ln;
for(i=0;i<5;i++,p+=15)
sscanf(p,"%15lf",&Coeff[i]);
if (!ifs.getline(ln, BUFF_SIZE)) return false;
p=ln;
for(i=5;i<10;i++,p+=15)
sscanf(p,"%15lf",&Coeff[i]);
if (!ifs.getline(ln, BUFF_SIZE)) return false;
p=ln;
for(i=10;i<14;i++,p+=15)
sscanf(p,"%15lf",&Coeff[i]);
for(i=0;i<14;++i)
pND->SetCoeff(i, Coeff[i]);
pmol->AssignSpinMultiplicity();
return true;
}
示例10: MakeCombinedMolecule
/*! Makes a new OBMol on the heap by combining two molecules according to the rule below.
If both have OBGenericData of the same type, or OBPairData with the
same attribute, the version from pFirst is used.
Returns a pointer to a new OBMol which will need deleting by the calling program
(probably by being sent to an output format).
If the molecules cannot be regarded as being the same structure a NULL
pointer is returned and an error message logged.
pFirst and pSecond and the objects they point to are not changed. (const
modifiers difficult because class OBMol not designed appropriately)
Combining molecules: rules for each of the three parts
Title:
Use the title of pFirst unless it has none, when use that of pSecond.
Warning if neither molecule has a title.
Structure
- a structure with atoms replaces one with no atoms
- a structure with bonds replaces one with no bonds,
provided the formula is the same, else an error.
- structures with atoms and bonds are compared by InChI; error if not the same.
- a structure with 3D coordinates replaces one with 2D coordinates
- a structure with 2D coordinates replace one with 0D coordinates
OBGenericData
OBPairData
*/
OBMol* OBMoleculeFormat::MakeCombinedMolecule(OBMol* pFirst, OBMol* pSecond)
{
//Decide on which OBMol provides the new title
string title("No title");
if(*pFirst->GetTitle()!=0)
title = pFirst->GetTitle();
else
{
if(*pSecond->GetTitle()!=0)
title = pSecond->GetTitle();
else
obErrorLog.ThrowError(__FUNCTION__,"Combined molecule has no title", obWarning);
}
//Decide on which OBMol provides the new structure
bool swap=false;
if(pFirst->NumAtoms()==0 && pSecond->NumAtoms()!=0)
swap=true;
else if(pSecond->NumAtoms()!=0)
{
if(pFirst->GetSpacedFormula()!=pSecond->GetSpacedFormula())
{
obErrorLog.ThrowError(__FUNCTION__,
"Molecules with name = " + title + " have different formula",obError);
return NULL;
}
else
{
if(pSecond->NumBonds()!=0 && pFirst->NumBonds()==0)
swap=true;
else
{
//Compare by inchi; error if different NOT YET IMPLEMENTED
//Use the one with the higher dimension
if(pSecond->GetDimension() > pFirst->GetDimension())
swap=true;
}
}
}
OBMol* pNewMol = new OBMol;
pNewMol->SetTitle(title);
OBMol* pMain = swap ? pSecond : pFirst;
OBMol* pOther = swap ? pFirst : pSecond;
*pNewMol = *pMain; //Now copies all data
//Copy some OBGenericData from the OBMol which did not provide the structure
vector<OBGenericData*>::iterator igd;
for(igd=pOther->BeginData();igd!=pOther->EndData();++igd)
{
//copy only if not already data of the same type from molecule already copied to pNewMol
unsigned datatype = (*igd)->GetDataType();
OBGenericData* pData = pNewMol->GetData(datatype);
if(datatype==OBGenericDataType::PairData)
{
if(pData->GetAttribute() == (*igd)->GetAttribute())
continue;
}
else if(pNewMol->GetData(datatype)!=NULL)
continue;
OBGenericData* pCopiedData = (*igd)->Clone(pNewMol);
pNewMol->SetData(pCopiedData);
}
return pNewMol;
}
示例11: ReadMolecule
//------------------------------------------------------------------------------
bool OBOpenDXCubeFormat::ReadMolecule( OBBase* pOb, OBConversion* pConv )
{
OBMol* pmol = pOb->CastAndClear<OBMol>();
if(pmol == 0)
return false;
istream& ifs = *pConv->GetInStream();
const char* title = pConv->GetTitle();
char buffer[BUFF_SIZE];
stringstream errorMsg;
if (!ifs)
return false; // We are attempting to read past the end of the file
pmol->SetTitle(title);
while (ifs.good() && ifs.getline(buffer,BUFF_SIZE)) {
if (buffer[0] == '#')
continue; // comment line
if (EQn(buffer, "object", 6))
break;
}
if (!ifs)
return false; // ran out of lines
vector<string> vs;
tokenize(vs, buffer);
// Number of grid points (voxels)
vector<int> voxels(3);
if (!EQn(buffer, "object", 6) || vs.size() != 8)
return false;
else {
voxels[0] = atoi(vs[5].c_str());
voxels[1] = atoi(vs[6].c_str());
voxels[2] = atoi(vs[7].c_str());
}
double x, y, z;
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "origin", 6))
return false;
else {
tokenize(vs, buffer);
if (vs.size() != 4)
return false;
x = atof(vs[1].c_str());
y = atof(vs[2].c_str());
z = atof(vs[3].c_str());
}
vector3 origin(x, y, z);
// now three lines with the x, y, and z axes
vector<vector3> axes;
for (unsigned int i = 0; i < 3; ++i) {
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "delta", 5))
return false;
else {
tokenize(vs, buffer);
if (vs.size() != 4)
return false;
x = atof(vs[1].c_str());
y = atof(vs[2].c_str());
z = atof(vs[3].c_str());
axes.push_back(vector3(x, y, z));
}
}
// Two remaining header lines before the data:
/*
object 2 class gridconnections counts nx ny nz
object 3 class array type double rank 0 times n data follows
*/
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6))
return false;
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6))
return false;
pmol->BeginModify();
pmol->SetDimension(3);
OBGridData *gd = new OBGridData;
gd->SetAttribute("OpenDX");
// get all values as one vector<double>
char *endptr;
vector<double> values;
int n = voxels[0]*voxels[1]*voxels[2];
int line = 0;
values.reserve(n);
while (ifs.getline(buffer, BUFF_SIZE))
{
++line;
if (EQn(buffer, "attribute", 9))
break; // we're finished with reading data -- although we should probably have a voxel check in here too
tokenize(vs, buffer);
if (vs.size() == 0)
//.........这里部分代码省略.........
示例12: ReadMolecule
bool RXNFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = pOb->CastAndClear<OBMol>();
if (pmol == NULL)
return false;
OBFormat* pMolFormat = pConv->FindFormat("MOL");
if (pMolFormat==NULL)
return false;
istream &ifs = *pConv->GetInStream();
string ln;
// When MDLFormat reads the last product it may also read and discard
// the line with $RXN for the next reaction. But it then sets $RXNread option.
if(pConv->IsOption("$RXNread"))
pConv->RemoveOption("$RXNread", OBConversion::OUTOPTIONS);
else
{
if (!getline(ifs,ln))
return(false);
if(Trim(ln).find("$RXN")!=0)
return false; //Has to start with $RXN
}
if (!getline(ifs,ln))
return false; //reaction title
pmol->SetTitle(Trim(ln));
if (!getline(ifs,ln))
return false; //creator
if (!getline(ifs, ln))
return false; //comment
// Originally the comment was added to the reaction via:
// pmol->SetComment(Trim(ln));
if (!getline(ifs, ln))
return false; // num reactants, products, and optionally agents
unsigned int nReactants = 0, nProducts = 0, nAgents = 0;
bool ok = ParseComponent(ln.c_str() + 0, &nReactants);
if (!ok)
return false;
ok = ParseComponent(ln.c_str() + 3, &nProducts);
if (!ok)
return false;
if (ln[6] != '\0') { // optional agents
ok = ParseComponent(ln.c_str() + 6, &nAgents);
if (!ok)
return false;
}
if(nReactants + nProducts + nAgents)
{
//Read the first $MOL. The others are read at the end of the previous MOL
if(!getline(ifs, ln))
return false;
if(Trim(ln).find("$MOL")==string::npos)
return false;
}
OBReactionFacade rxnfacade(pmol);
// Note: If we supported it, we could read each of the rxn components directly
// into the returned OBMol instead of having to do a copy. Unfortunately,
// this isn't possible at the moment (MOL format will need some work first).
// Here is some example code to do it:
//
//unsigned int old_numatoms = 0;
//unsigned int compid = 1;
//for (int i = 0; i<nReactants; i++)
//{
// //Read a MOL file using the same OBConversion object but with a different format
// if (!pMolFormat->ReadMolecule(pmol, pConv))
// obErrorLog.ThrowError(__FUNCTION__, "Failed to read a reactant", obWarning);
// unsigned int numatoms = pmol->NumAtoms();
// for (unsigned int idx = old_numatoms + 1; idx <= numatoms; ++idx) {
// OBAtom* atom = pmol->GetAtom(idx);
// rxnfacade.SetRole(atom, REACTANT);
// rxnfacade.SetComponentId(atom, compid);
// }
// old_numatoms = numatoms;
// compid++;
//}
const char* type[3] = {"a reactant", "a product", "an agent"};
OBReactionRole role;
unsigned int num_components;
for(unsigned int N=0; N<3; N++) {
switch(N) {
case 0:
role = REACTANT;
num_components = nReactants;
break;
case 1:
role = PRODUCT;
num_components = nProducts;
break;
case 2:
role = AGENT;
num_components = nAgents;
break;
//.........这里部分代码省略.........
示例13: 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);
}
示例14: 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
//.........这里部分代码省略.........
示例15: 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);
}