I have found an alchemy file which OpenBabel v2.1.1 cannot open, because the file contains comments and whitespace which OpenBabel does not accept.
The file is the alchemy example on the Chemical MIME Home page.
I have altered alchemyformat.cpp to be more flexible, and thus successfully open this file. I have submitted the alchemy file to the test repository ( ID 1820997 ).
I will attempt to submit my bug-fix for this bug next.
In case I am unsuccessfull, here is the code which contains my changes, from alchemyformat.cpp line 76 on:
int i;
int natoms = 0, nbonds = 0;
char buffer[BUFF_SIZE];
ifs.getline(buffer,BUFF_SIZE);
sscanf(buffer," %d %*s %d", &natoms, &nbonds);
if (!natoms)
{
ifs.getline(buffer,BUFF_SIZE);
sscanf(buffer," %d %*s %d", &natoms, &nbonds);
if (!natoms)
{
return(false);
}
}
mol.ReserveAtoms(natoms);
mol.BeginModify();
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() < 5)
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%99s",&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);
}
Logged In: YES
user_id=1900870
Originator: YES
Modified formats/alchemyformat.cpp and svn Committed revision 2081 which I believe fixes this item.