diff --git a/modules/io/src/mol/sdf_reader.cc b/modules/io/src/mol/sdf_reader.cc index 381f5cbe9df655054d1710dbaf69839bab57ce75..660a9dcb5be68494a7d5944ced083d857f945f8c 100644 --- a/modules/io/src/mol/sdf_reader.cc +++ b/modules/io/src/mol/sdf_reader.cc @@ -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; } diff --git a/modules/io/tests/test_io_sdf.cc b/modules/io/tests/test_io_sdf.cc index df84041b0f47b79b8b19cdf865b1543f05666ce0..68009e9c990d1cf11962eaffdcaea489934d7a7e 100644 --- a/modules/io/tests/test_io_sdf.cc +++ b/modules/io/tests/test_io_sdf.cc @@ -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(); diff --git a/modules/io/tests/testfiles/sdf/1atg_C_ACT.sdf.gz b/modules/io/tests/testfiles/sdf/1atg_C_ACT.sdf.gz new file mode 100644 index 0000000000000000000000000000000000000000..436ae0021cac71c13e18238d165b9ebde27cb208 Binary files /dev/null and b/modules/io/tests/testfiles/sdf/1atg_C_ACT.sdf.gz differ