Commit 8539e050 by Maarten L. Hekkelman

add code to load default components.cif file

parent 3b2c5731
...@@ -161,6 +161,7 @@ class CompoundFactory ...@@ -161,6 +161,7 @@ class CompoundFactory
static CompoundFactory &instance(); static CompoundFactory &instance();
static void clear(); static void clear();
void setDefaultDictionary(const std::string &inDictFile);
void pushDictionary(const std::string &inDictFile); void pushDictionary(const std::string &inDictFile);
void popDictionary(); void popDictionary();
......
...@@ -433,6 +433,12 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string &file, CompoundFactor ...@@ -433,6 +433,12 @@ CompoundFactoryImpl::CompoundFactoryImpl(const std::string &file, CompoundFactor
class CCDCompoundFactoryImpl : public CompoundFactoryImpl class CCDCompoundFactoryImpl : public CompoundFactoryImpl
{ {
public: public:
CCDCompoundFactoryImpl(CompoundFactoryImpl *next, const fs::path& file)
: CompoundFactoryImpl(next)
, mCompoundsFile(file)
{
}
CCDCompoundFactoryImpl(CompoundFactoryImpl *next) CCDCompoundFactoryImpl(CompoundFactoryImpl *next)
: CompoundFactoryImpl(next) : CompoundFactoryImpl(next)
{ {
...@@ -441,15 +447,23 @@ class CCDCompoundFactoryImpl : public CompoundFactoryImpl ...@@ -441,15 +447,23 @@ class CCDCompoundFactoryImpl : public CompoundFactoryImpl
Compound *create(const std::string &id) override; Compound *create(const std::string &id) override;
cif::DatablockIndex mIndex; cif::DatablockIndex mIndex;
fs::path mCompoundsFile;
}; };
Compound *CCDCompoundFactoryImpl::create(const std::string &id) Compound *CCDCompoundFactoryImpl::create(const std::string &id)
{ {
Compound *result = nullptr; Compound *result = nullptr;
auto ccd = cif::loadResource("components.cif"); std::unique_ptr<std::istream> ccd;
if (not ccd)
throw std::runtime_error("Could not locate the CCD components.cif file, please make sure the software is installed properly and/or use the update-dictionary-script to fetch the data."); if (mCompoundsFile.empty())
{
ccd = cif::loadResource("components.cif");
if (not ccd)
throw std::runtime_error("Could not locate the CCD components.cif file, please make sure the software is installed properly and/or use the update-dictionary-script to fetch the data.");
}
else
ccd.reset(new std::ifstream(mCompoundsFile));
cif::File file; cif::File file;
...@@ -469,7 +483,14 @@ Compound *CCDCompoundFactoryImpl::create(const std::string &id) ...@@ -469,7 +483,14 @@ Compound *CCDCompoundFactoryImpl::create(const std::string &id)
std::cout << " done" << std::endl; std::cout << " done" << std::endl;
// reload the resource, perhaps this should be improved... // reload the resource, perhaps this should be improved...
ccd = cif::loadResource("components.cif"); if (mCompoundsFile.empty())
{
ccd = cif::loadResource("components.cif");
if (not ccd)
throw std::runtime_error("Could not locate the CCD components.cif file, please make sure the software is installed properly and/or use the update-dictionary-script to fetch the data.");
}
else
ccd.reset(new std::ifstream(mCompoundsFile));
} }
if (cif::VERBOSE > 1) if (cif::VERBOSE > 1)
...@@ -663,6 +684,22 @@ void CompoundFactory::clear() ...@@ -663,6 +684,22 @@ void CompoundFactory::clear()
} }
} }
void CompoundFactory::setDefaultDictionary(const std::string &inDictFile)
{
if (not fs::exists(inDictFile))
throw std::runtime_error("file not found: " + inDictFile);
try
{
mImpl = new CCDCompoundFactoryImpl(mImpl, inDictFile);
}
catch (const std::exception &ex)
{
std::cerr << "Error loading dictionary " << inDictFile << std::endl;
throw;
}
}
void CompoundFactory::pushDictionary(const std::string &inDictFile) void CompoundFactory::pushDictionary(const std::string &inDictFile)
{ {
if (not fs::exists(inDictFile)) if (not fs::exists(inDictFile))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment