make iostreams optional

This commit is contained in:
Greg Landrum
2019-05-08 17:33:17 +02:00
parent 89f769cd88
commit 17828cc2c9
8 changed files with 131 additions and 117 deletions

View File

@@ -54,6 +54,7 @@ option(RDK_BUILD_MOLINTERCHANGE_SUPPORT "build in support for CommonChem molecul
option(RDK_BUILD_YAEHMOP_SUPPORT "build support for the YAeHMOP wrapper" OFF)
option(RDK_INSTALL_DEV_COMPONENT "install libraries and headers" ON)
option(RDK_USE_BOOST_REGEX "use boost::regex instead of std::regex (needed for systems with g++-4.8)" OFF)
option(RDK_USE_BOOST_IOSTREAMS "use boost::iostreams" ON)
if(NOT MSVC)
if(RDK_OPTIMIZE_NATIVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mpopcnt")

View File

@@ -2,6 +2,7 @@
remove_definitions(-DRDKIT_GRAPHMOL_BUILD)
add_definitions(-DRDKIT_FILEPARSERS_BUILD)
if(RDK_USE_BOOST_IOSTREAMS)
if(WIN32)
find_package(Boost 1.56.0 COMPONENTS system iostreams REQUIRED)
find_package(Boost 1.56.0 COMPONENTS zlib)
@@ -16,6 +17,7 @@ else()
add_definitions("-DBOOST_IOSTREAMS_DYN_LINK")
endif()
endif()
endif(RDK_USE_BOOST_IOSTREAMS)
if(RDK_BUILD_COORDGEN_SUPPORT)
include_directories(${maeparser_INCLUDE_DIRS})

View File

@@ -129,7 +129,7 @@ int testMolSup() {
}
TEST_ASSERT(ok);
}
#endif // RDK_BUILD_COORDGEN_SUPPORT
#endif // RDK_BUILD_COORDGEN_SUPPORT
return 1;
}
@@ -319,10 +319,11 @@ void testSmilesSupFromText() {
// this was a delightful boundary condition:
BOOST_LOG(rdErrorLog)
<< "------------------------------------------------------" << std::endl;
text = "CC\n"
"CCC\n"
"CCOC\n"
"CCCCOC";
text =
"CC\n"
"CCC\n"
"CCOC\n"
"CCCCOC";
{
nSup2.setData(text, " ", 0, -1, false, true);
// BOOST_LOG(rdErrorLog) << "SIZE: " << nSup2.length() << std::endl;
@@ -395,11 +396,12 @@ void testSmilesSupFromText() {
}
// --------------
// basics:
text = "Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-3 CCC 9.0\n"
"mol-4 CCCC 16.0\n";
text =
"Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-3 CCC 9.0\n"
"mol-4 CCCC 16.0\n";
#if 1
nSup2.setData(text, " ", 1, 0, true, true);
mol = nSup2[3];
@@ -412,10 +414,11 @@ void testSmilesSupFromText() {
delete mol;
// ensure that we can call setData a second time:
text = "Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-3 CCC 9.0\n";
text =
"Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-3 CCC 9.0\n";
nSup2.setData(text, " ", 1, 0, true, true);
CHECK_INVARIANT(nSup2.length() == 3, "");
mol = nSup2[2];
@@ -426,11 +429,12 @@ void testSmilesSupFromText() {
delete mol;
// now test for failure handling:
text = "Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-3 fail 9.0\n"
"mol-4 CCCC 16.0\n";
text =
"Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-3 fail 9.0\n"
"mol-4 CCCC 16.0\n";
nSup2.setData(text, " ", 1, 0, true, true);
mol = nSup2[3];
// BOOST_LOG(rdErrorLog) << "SIZE: " << nSup2.length() << std::endl;
@@ -448,10 +452,11 @@ void testSmilesSupFromText() {
#endif
// issue 114, no \n at EOF:
text = "Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-4 CCCC 16.0\n";
text =
"Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-4 CCCC 16.0\n";
nSup2.setData(text, " ", 1, 0, true, true);
// BOOST_LOG(rdErrorLog) << "SIZE: " << nSup2.length() << std::endl;
TEST_ASSERT(nSup2.length() == 3);
@@ -464,10 +469,11 @@ void testSmilesSupFromText() {
TEST_ASSERT(nSup2.atEnd());
delete mol;
text = "Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-4 CCCC 16.0";
text =
"Id SMILES Column_2\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-4 CCCC 16.0";
nSup2.setData(text, " ", 1, 0, true, true);
// BOOST_LOG(rdErrorLog) << "SIZE: " << nSup2.length() << std::endl;
TEST_ASSERT(nSup2.length() == 3);
@@ -488,9 +494,10 @@ void testSmilesSupFromText() {
}
TEST_ASSERT(failed);
text = "mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-4 CCCC 16.0";
text =
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-4 CCCC 16.0";
nSup2.setData(text, " ", 1, 0, false, true);
// BOOST_LOG(rdErrorLog) << "SIZE: " << nSup2.length() << std::endl;
TEST_ASSERT(nSup2.length() == 3);
@@ -502,9 +509,10 @@ void testSmilesSupFromText() {
TEST_ASSERT(mname == "16.0");
delete mol;
text = "C\n"
"CC\n"
"CCCC";
text =
"C\n"
"CC\n"
"CCCC";
nSup2.setData(text, " ", 0, -1, false, true);
// BOOST_LOG(rdErrorLog) << "SIZE: " << nSup2.length() << std::endl;
TEST_ASSERT(nSup2.length() == 3);
@@ -516,10 +524,11 @@ void testSmilesSupFromText() {
// this was a delightful boundary condition:
BOOST_LOG(rdErrorLog)
<< "------------------------------------------------------" << std::endl;
text = "CC\n"
"CCC\n"
"CCOC\n"
"CCCCOC";
text =
"CC\n"
"CCC\n"
"CCOC\n"
"CCCCOC";
nSup2.setData(text, " ", 0, -1, false, true);
// BOOST_LOG(rdErrorLog) << "SIZE: " << nSup2.length() << std::endl;
mol = nSup2.next();
@@ -541,10 +550,11 @@ void testSmilesSupFromText() {
BOOST_LOG(rdErrorLog)
<< "------------------------------------------------------" << std::endl;
// this was a delightful boundary condition:
text = "CC\n"
"CCC\n"
"CCOC\n"
"CCCCOC";
text =
"CC\n"
"CCC\n"
"CCOC\n"
"CCCCOC";
nSup2.setData(text, " ", 0, -1, false, true);
// BOOST_LOG(rdErrorLog) << "SIZE: " << nSup2.length() << std::endl;
failed = false;
@@ -571,12 +581,13 @@ void testSmilesSupFromText() {
TEST_ASSERT(nDone == nSup2.length());
// ensure that we can call setData a second time:
text = "Id SMILES Column_2\n"
"# comment, ignore\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-3 CCC 9.0\n"
"mol-4 CCCC 16.0\n";
text =
"Id SMILES Column_2\n"
"# comment, ignore\n"
"mol-1 C 1.0\n"
"mol-2 CC 4.0\n"
"mol-3 CCC 9.0\n"
"mol-4 CCCC 16.0\n";
nSup2.setData(text, " ", 1, 0, true, true);
mol = nSup2[2];
mol->getProp(common_properties::_Name, mname);
@@ -593,12 +604,13 @@ void testSmilesSupFromText() {
delete mol;
// this was a delightful boundary condition:
text = "CC\n"
"CCC\n"
"CCOC\n"
"CCCCOC\n"
"\n"
"\n";
text =
"CC\n"
"CCC\n"
"CCOC\n"
"CCCCOC\n"
"\n"
"\n";
nSup2.setData(text, " ", 0, -1, false, true);
TEST_ASSERT(nSup2.length() == 4);
nSup2.reset();
@@ -837,9 +849,10 @@ void testSuppliersEmptyFile() {
void testCisTrans() {
std::string text;
text = "mol-1 ClC(C)=C(Br)C\n"
"mol-2 C1=COC=CC1C(Cl)=C(Br)C\n"
"mol-3 C1=COC=CC1\\C(Cl)=C(Br)\\C";
text =
"mol-1 ClC(C)=C(Br)C\n"
"mol-2 C1=COC=CC1C(Cl)=C(Br)C\n"
"mol-3 C1=COC=CC1\\C(Cl)=C(Br)\\C";
SmilesMolSupplier smiSup;
smiSup.setData(text, " ", 1, 0, false, true);
@@ -1076,18 +1089,19 @@ int testTDTSupplier3() {
TDTMolSupplier suppl;
data = "$SMI<Cc1nnc(N)nc1C>\n"
"CAS<17584-12-2>\n"
"|\n"
"$SMI<Cc1n[nH]c(=O)nc1N>\n"
"CAS<~>\n"
"|\n"
"$SMI<Cc1n[nH]c(=O)[nH]c1=O>\n"
"CAS<932-53-6>\n"
"|\n"
"$SMI<Cc1nnc(NN)nc1O>\n"
"CAS<~>\n"
"|\n";
data =
"$SMI<Cc1nnc(N)nc1C>\n"
"CAS<17584-12-2>\n"
"|\n"
"$SMI<Cc1n[nH]c(=O)nc1N>\n"
"CAS<~>\n"
"|\n"
"$SMI<Cc1n[nH]c(=O)[nH]c1=O>\n"
"CAS<932-53-6>\n"
"|\n"
"$SMI<Cc1nnc(NN)nc1O>\n"
"CAS<~>\n"
"|\n";
suppl.setData(data, "CAS");
i = 0;
@@ -1268,8 +1282,7 @@ void testSDSupplierFromTextStrLax1() {
while (!reader.atEnd()) {
ROMol *mol = reader.next();
TEST_ASSERT(mol->hasProp(common_properties::_Name));
if (i == 0)
TEST_ASSERT(!mol->hasProp("ID"));
if (i == 0) TEST_ASSERT(!mol->hasProp("ID"));
TEST_ASSERT(!mol->hasProp("ANOTHER_PROPERTY"));
i++;
delete mol;
@@ -1358,10 +1371,11 @@ void testSDSupplierFromTextStrLax2() {
mol->getProp("ID", s);
TEST_ASSERT(s == "Lig1");
mol->getProp("ANOTHER_PROPERTY", s);
TEST_ASSERT(s == "No blank line before dollars\n"
"$$$$\n"
"Structure1\n"
"csChFnd70/05230312262D");
TEST_ASSERT(s ==
"No blank line before dollars\n"
"$$$$\n"
"Structure1\n"
"csChFnd70/05230312262D");
i++;
delete mol;
}
@@ -1403,8 +1417,7 @@ void testSDSupplierStrLax1() {
while (!reader.atEnd()) {
ROMol *mol = reader.next();
TEST_ASSERT(mol->hasProp(common_properties::_Name));
if (i == 0)
TEST_ASSERT(!mol->hasProp("ID"));
if (i == 0) TEST_ASSERT(!mol->hasProp("ID"));
TEST_ASSERT(!mol->hasProp("ANOTHER_PROPERTY"));
i++;
delete mol;
@@ -1446,10 +1459,11 @@ void testSDSupplierStrLax2() {
mol->getProp("ID", s);
TEST_ASSERT(s == "Lig1");
mol->getProp("ANOTHER_PROPERTY", s);
TEST_ASSERT(s == "No blank line before dollars\n"
"$$$$\n"
"Structure1\n"
"csChFnd70/05230312262D");
TEST_ASSERT(s ==
"No blank line before dollars\n"
"$$$$\n"
"Structure1\n"
"csChFnd70/05230312262D");
i++;
delete mol;
}
@@ -1569,8 +1583,7 @@ void testIssue381() {
count = 0;
while (!sdsup->atEnd()) {
nmol = sdsup->next();
if (nmol)
delete nmol;
if (nmol) delete nmol;
count++;
}
TEST_ASSERT(sdsup->atEnd());
@@ -1592,12 +1605,10 @@ void testSetStreamIndices() {
std::streampos pos = 0;
std::string line;
while (notEof) {
if (addIndex)
pos = ifs.tellg();
if (addIndex) pos = ifs.tellg();
notEof = (std::getline(ifs, line) ? true : false);
if (notEof) {
if (addIndex)
indices.push_back(pos);
if (addIndex) indices.push_back(pos);
addIndex = (line.substr(0, 4) == "$$$$");
}
}
@@ -1615,8 +1626,7 @@ void testSetStreamIndices() {
count = 0;
while (!sdsup->atEnd()) {
nmol = sdsup->next();
if (nmol)
delete nmol;
if (nmol) delete nmol;
count++;
}
TEST_ASSERT(sdsup->atEnd());
@@ -2074,7 +2084,7 @@ int testForwardSDSupplier() {
}
TEST_ASSERT(i == 16);
}
#ifdef RDK_USE_BOOST_IOSTREAMS
// make sure the boost::iostreams are working
{
io::filtering_istream strm;
@@ -2084,10 +2094,8 @@ int testForwardSDSupplier() {
while (!strm.eof()) {
std::string line;
std::getline(strm, line);
if (!strm.eof())
++i;
if (i > 1000)
break;
if (!strm.eof()) ++i;
if (i > 1000) break;
}
TEST_ASSERT(i == 998);
}
@@ -2097,10 +2105,8 @@ int testForwardSDSupplier() {
while (!strm.eof()) {
std::string line;
std::getline(strm, line);
if (!strm.eof())
++i;
if (i > 1000)
break;
if (!strm.eof()) ++i;
if (i > 1000) break;
}
TEST_ASSERT(i == 997);
}
@@ -2121,6 +2127,7 @@ int testForwardSDSupplier() {
}
TEST_ASSERT(i == 16);
}
#endif
#ifdef RDK_BUILD_COORDGEN_SUPPORT
// Now test that Maestro parsing of gz files works
@@ -2136,10 +2143,8 @@ int testForwardSDSupplier() {
while (!strm.eof()) {
std::string line;
std::getline(strm, line);
if (!strm.eof())
++i;
if (i > 1700)
break;
if (!strm.eof()) ++i;
if (i > 1700) break;
}
TEST_ASSERT(i == 1663);
}
@@ -2150,10 +2155,8 @@ int testForwardSDSupplier() {
while (!strm.eof()) {
std::string line;
std::getline(strm, line);
if (!strm.eof())
++i;
if (i > 1700)
break;
if (!strm.eof()) ++i;
if (i > 1700) break;
}
TEST_ASSERT(i == 1663);
}
@@ -2172,8 +2175,7 @@ int testForwardSDSupplier() {
}
TEST_ASSERT(i == 16);
}
#endif // RDK_BUILD_COORDGEN_SUPPORT
#endif // RDK_BUILD_COORDGEN_SUPPORT
return 1;
}
@@ -2329,7 +2331,7 @@ void testGitHub2285() {
std::vector<std::string> smiles;
{
SDMolSupplier sdsup(fname);
while(!sdsup.atEnd()) {
while (!sdsup.atEnd()) {
ROMol *nmol = sdsup.next();
TEST_ASSERT(nmol);
smiles.push_back(MolToSmiles(*nmol));
@@ -2339,7 +2341,7 @@ void testGitHub2285() {
{
SDMolSupplier sdsup(fname, true, false);
int i = 0;
while(!sdsup.atEnd()) {
while (!sdsup.atEnd()) {
ROMol *nmol = sdsup.next();
TEST_ASSERT(nmol);
ROMol *m = MolOps::removeHs(*nmol);
@@ -2347,7 +2349,7 @@ void testGitHub2285() {
delete nmol;
delete m;
}
TEST_ASSERT(i>0);
TEST_ASSERT(i > 0);
}
}

View File

@@ -37,7 +37,7 @@ foreach(swigRDKitLib ${swigRDKitLibList})
endforeach()
set(swigRDKitLibs "${swigRDKitLibs}${Boost_SERIALIZATION_LIBRARY};")
if(RDK_USE_BOOST_IOSTREAMS)
if(WIN32)
find_package(Boost 1.56.0 COMPONENTS system iostreams REQUIRED)
set(swigRDKitLibs "${swigRDKitLibs}${Boost_IOSTREAMS_LIBRARY};${Boost_SYSTEM_LIBRARY};")
@@ -50,6 +50,7 @@ else()
find_package(Boost 1.56.0 COMPONENTS system iostreams REQUIRED)
set(swigRDKitLibs "${swigRDKitLibs}${Boost_IOSTREAMS_LIBRARY};${Boost_SYSTEM_LIBRARY};")
endif()
endif(RDK_USE_BOOST_IOSTREAMS)

View File

@@ -10,6 +10,7 @@
// RDKit configuration options
#cmakedefine RDK_USE_BOOST_SERIALIZATION
#cmakedefine RDK_USE_BOOST_IOSTREAMS
#cmakedefine RDK_OPTIMIZE_NATIVE
#ifdef RDK_OPTIMIZE_NATIVE

View File

@@ -1,3 +1,5 @@
if(RDK_USE_BOOST_IOSTREAMS)
find_package(Boost 1.56.0 COMPONENTS system iostreams REQUIRED)
set (link_iostreams ${Boost_LIBRARIES})
if (NOT Boost_USE_STATIC_LIBS)
@@ -12,6 +14,7 @@ if (WIN32)
endif()
add_definitions(-DRDKIT_RDSTREAMS_BUILD)
endif(RDK_USE_BOOST_IOSTREAMS)
rdkit_library(RDStreams streams.cpp
LINK_LIBRARIES ${Boost_LIBRARIES} ${link_iostreams} ${zlib_lib}
DEST RDStreams)

View File

@@ -1,11 +1,12 @@
#include "streams.h"
#ifdef RDK_USE_BOOST_IOSTREAMS
namespace RDKit
{
gzstream::gzstream(const std::string &fname) :
boost::iostreams::filtering_istream(),
is(fname.c_str(), std::ios_base::binary) {
namespace RDKit {
gzstream::gzstream(const std::string &fname)
: boost::iostreams::filtering_istream(),
is(fname.c_str(), std::ios_base::binary) {
push(boost::iostreams::gzip_decompressor());
push(is);
}
}
} // namespace RDKit
#endif

View File

@@ -1,5 +1,7 @@
//
#include <RDGeneral/export.h>
#ifdef RDK_USE_BOOST_IOSTREAMS
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
@@ -14,3 +16,4 @@ class RDKIT_RDSTREAMS_EXPORT gzstream
gzstream(const std::string &fname);
};
} // namespace RDKit
#endif