Commit bbe71af9 by Maarten L. Hekkelman

Accept invalid CCD component files, for now

parent 49912d01
...@@ -857,6 +857,7 @@ bool category::is_valid() const ...@@ -857,6 +857,7 @@ bool category::is_valid() const
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
result = false;
m_validator->report_error("Error validating " + m_columns[cix].m_name + ": " + e.what(), false); m_validator->report_error("Error validating " + m_columns[cix].m_name + ": " + e.what(), false);
continue; continue;
} }
......
/*- /*-
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
* *
* Copyright (c) 2020-2022 NKI/AVL, Netherlands Cancer Institute * Copyright (c) 2020-2022 NKI/AVL, Netherlands Cancer Institute
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this * 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer * list of conditions and the following disclaimer
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
...@@ -215,7 +215,8 @@ compound_atom compound::get_atom_by_atom_id(const std::string &atom_id) const ...@@ -215,7 +215,8 @@ compound_atom compound::get_atom_by_atom_id(const std::string &atom_id) const
bool compound::atoms_bonded(const std::string &atomId_1, const std::string &atomId_2) const bool compound::atoms_bonded(const std::string &atomId_1, const std::string &atomId_2) const
{ {
auto i = find_if(m_bonds.begin(), m_bonds.end(), auto i = find_if(m_bonds.begin(), m_bonds.end(),
[&](const compound_bond &b) { [&](const compound_bond &b)
{
return (b.atom_id[0] == atomId_1 and b.atom_id[1] == atomId_2) or (b.atom_id[0] == atomId_2 and b.atom_id[1] == atomId_1); return (b.atom_id[0] == atomId_1 and b.atom_id[1] == atomId_2) or (b.atom_id[0] == atomId_2 and b.atom_id[1] == atomId_1);
}); });
...@@ -226,39 +227,41 @@ bool compound::atoms_bonded(const std::string &atomId_1, const std::string &atom ...@@ -226,39 +227,41 @@ bool compound::atoms_bonded(const std::string &atomId_1, const std::string &atom
// known amino acids and bases // known amino acids and bases
const std::map<std::string, char> compound_factory::kAAMap{ const std::map<std::string, char> compound_factory::kAAMap{
{"ALA", 'A'}, { "ALA", 'A' },
{"ARG", 'R'}, { "ARG", 'R' },
{"ASN", 'N'}, { "ASN", 'N' },
{"ASP", 'D'}, { "ASP", 'D' },
{"CYS", 'C'}, { "CYS", 'C' },
{"GLN", 'Q'}, { "GLN", 'Q' },
{"GLU", 'E'}, { "GLU", 'E' },
{"GLY", 'G'}, { "GLY", 'G' },
{"HIS", 'H'}, { "HIS", 'H' },
{"ILE", 'I'}, { "ILE", 'I' },
{"LEU", 'L'}, { "LEU", 'L' },
{"LYS", 'K'}, { "LYS", 'K' },
{"MET", 'M'}, { "MET", 'M' },
{"PHE", 'F'}, { "PHE", 'F' },
{"PRO", 'P'}, { "PRO", 'P' },
{"SER", 'S'}, { "SER", 'S' },
{"THR", 'T'}, { "THR", 'T' },
{"TRP", 'W'}, { "TRP", 'W' },
{"TYR", 'Y'}, { "TYR", 'Y' },
{"VAL", 'V'}, { "VAL", 'V' },
{"GLX", 'Z'}, { "GLX", 'Z' },
{"ASX", 'B'}}; { "ASX", 'B' }
};
const std::map<std::string, char> compound_factory::kBaseMap{ const std::map<std::string, char> compound_factory::kBaseMap{
{"A", 'A'}, { "A", 'A' },
{"C", 'C'}, { "C", 'C' },
{"G", 'G'}, { "G", 'G' },
{"T", 'T'}, { "T", 'T' },
{"U", 'U'}, { "U", 'U' },
{"DA", 'A'}, { "DA", 'A' },
{"DC", 'C'}, { "DC", 'C' },
{"DG", 'G'}, { "DG", 'G' },
{"DT", 'T'}}; { "DT", 'T' }
};
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// a factory class to generate compounds // a factory class to generate compounds
...@@ -272,7 +275,7 @@ class compound_factory_impl : public std::enable_shared_from_this<compound_facto ...@@ -272,7 +275,7 @@ class compound_factory_impl : public std::enable_shared_from_this<compound_facto
virtual ~compound_factory_impl() virtual ~compound_factory_impl()
{ {
for (auto c: m_compounds) for (auto c : m_compounds)
delete c; delete c;
} }
...@@ -324,17 +327,16 @@ class compound_factory_impl : public std::enable_shared_from_this<compound_facto ...@@ -324,17 +327,16 @@ class compound_factory_impl : public std::enable_shared_from_this<compound_facto
bool is_known_peptide(const std::string &resName) bool is_known_peptide(const std::string &resName)
{ {
return m_known_peptides.count(resName) or return m_known_peptides.count(resName) or
(m_next and m_next->is_known_peptide(resName)); (m_next and m_next->is_known_peptide(resName));
} }
bool is_known_base(const std::string &resName) bool is_known_base(const std::string &resName)
{ {
return m_known_bases.count(resName) or return m_known_bases.count(resName) or
(m_next and m_next->is_known_base(resName)); (m_next and m_next->is_known_base(resName));
} }
protected: protected:
virtual compound *create(const std::string &id) virtual compound *create(const std::string &id)
{ {
// For the base class we assume every compound is preloaded // For the base class we assume every compound is preloaded
...@@ -414,10 +416,18 @@ compound_factory_impl::compound_factory_impl(const fs::path &file, std::shared_p ...@@ -414,10 +416,18 @@ compound_factory_impl::compound_factory_impl(const fs::path &file, std::shared_p
else else
{ {
// A CCD components file, validate it first // A CCD components file, validate it first
cifFile.load_dictionary("mmcif_pdbx.dic"); try
{
cifFile.load_dictionary("mmcif_pdbx.dic");
if (not cifFile.is_valid()) if (not cifFile.is_valid())
throw std::runtime_error("Invalid compound file"); std::cerr << "The components file " << file << " is not valid" << std::endl;
}
catch (const std::exception &e)
{
std::cerr << "When trying to load the components file " << file << " there was an exception:" << std::endl
<< e.what() << std::endl;
}
for (auto &db : cifFile) for (auto &db : cifFile)
m_compounds.push_back(new compound(db)); m_compounds.push_back(new compound(db));
...@@ -430,7 +440,7 @@ compound_factory_impl::compound_factory_impl(const fs::path &file, std::shared_p ...@@ -430,7 +440,7 @@ compound_factory_impl::compound_factory_impl(const fs::path &file, std::shared_p
class CCD_compound_factory_impl : public compound_factory_impl class CCD_compound_factory_impl : public compound_factory_impl
{ {
public: public:
CCD_compound_factory_impl(std::shared_ptr<compound_factory_impl> next, const fs::path& file) CCD_compound_factory_impl(std::shared_ptr<compound_factory_impl> next, const fs::path &file)
: compound_factory_impl(next) : compound_factory_impl(next)
, mCompoundsFile(file) , mCompoundsFile(file)
{ {
...@@ -647,7 +657,6 @@ compound_factory::compound_factory() ...@@ -647,7 +657,6 @@ compound_factory::compound_factory()
m_impl.reset(new CCP4_compound_factory_impl(clibd_mon)); m_impl.reset(new CCP4_compound_factory_impl(clibd_mon));
else if (cif::VERBOSE > 0) else if (cif::VERBOSE > 0)
std::cerr << "CCP4 monomers library not found, CLIBD_MON is not defined" << std::endl; std::cerr << "CCP4 monomers library not found, CLIBD_MON is not defined" << std::endl;
} }
compound_factory::~compound_factory() compound_factory::~compound_factory()
...@@ -729,4 +738,4 @@ bool compound_factory::is_known_base(const std::string &resName) const ...@@ -729,4 +738,4 @@ bool compound_factory::is_known_base(const std::string &resName) const
return m_impl ? m_impl->is_known_base(resName) : kBaseMap.count(resName) > 0; return m_impl ? m_impl->is_known_base(resName) : kBaseMap.count(resName) > 0;
} }
} // namespace pdbx } // namespace cif
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