Skip to content
Snippets Groups Projects
Unverified Commit 1645c2c9 authored by Xavier Robin's avatar Xavier Robin
Browse files

fix: allow short count lines

The RCSB ModelServer SDF files contain counts line with only 33
characters. Although invalid, they can be read by RDKit (which only
requires 6 characters). This commit emmulates the behavior of RDKit.
parent d2160122
No related branches found
No related tags found
No related merge requests found
......@@ -182,12 +182,22 @@ void SDFReader::ParseHeader(const String& line, int line_num,
break;
case 4: // counts line
{
if (line.length() < 39) {
String msg="Bad counts line %d: Not correct number of characters on "
"the line: %i (should be at least 39)";
String version_str;
if (line.length() < 6) {
String msg="Bad counts line %d: too short (%i characters, "
"should be at least 6 or 39)";
throw IOException(str(format(msg) % line_num % line.length()));
}
String version_str=line.substr(34, 5);
else if (line.length() < 39) {
String msg="Bad counts line %d: too short (%i characters, "
"should be at least 39). "
"Proceeding assuming V2000 format.";
LOG_WARNING(str(format(msg) % line_num % line.length()));
version_str="V2000";
}
else {
version_str=line.substr(34, 5);
}
if (version_str == "V2000" || version_str == "V3000") {
version_=version_str;
}
......
......@@ -252,5 +252,17 @@ BOOST_AUTO_TEST_CASE(empty_dataheader_error_sdf)
BOOST_CHECK_THROW(sdfh.Import(eh,"testfiles/sdf/empty_dataheader.sdf"), IOException);
}
BOOST_AUTO_TEST_CASE(rcsb_modelserver_sdf)
{
// Check that we can read invalid SDF files from the RCSB model server.
// These files have too short
mol::EntityHandle eh=mol::CreateEntity();
EntityIOSDFHandler sdfh;
sdfh.Import(eh,"testfiles/sdf/1atg_C_ACT.sdf.gz");
// check success
BOOST_CHECK_EQUAL(eh.GetChainCount(), 1);
}
BOOST_AUTO_TEST_SUITE_END();
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment