Xmipp  v3.23.11-Nereus
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cif::compound_factory_impl Class Reference
Inheritance diagram for cif::compound_factory_impl:
Inheritance graph
[legend]
Collaboration diagram for cif::compound_factory_impl:
Collaboration graph
[legend]

Public Member Functions

 compound_factory_impl (std::shared_ptr< compound_factory_impl > next)
 
 compound_factory_impl (const fs::path &file, std::shared_ptr< compound_factory_impl > next)
 
virtual ~compound_factory_impl ()
 
compound * get (std::string id)
 
std::shared_ptr< compound_factory_implnext () const
 
bool is_known_peptide (const std::string &resName)
 
bool is_known_base (const std::string &resName)
 

Protected Member Functions

virtual compound * create (const std::string &id)
 

Protected Attributes

std::shared_timed_mutex mMutex
 
std::vector< compound * > m_compounds
 
std::set< std::string > m_known_peptides
 
std::set< std::string > m_known_bases
 
std::set< std::string > m_missing
 
std::shared_ptr< compound_factory_implm_next
 

Detailed Description

Definition at line 290 of file compound.cpp.

Constructor & Destructor Documentation

◆ compound_factory_impl() [1/2]

cif::compound_factory_impl::compound_factory_impl ( std::shared_ptr< compound_factory_impl next)

Definition at line 378 of file compound.cpp.

379  : m_next(next)
380 {
381  for (const auto &[key, value] : compound_factory::kAAMap)
382  m_known_peptides.insert(key);
383 
384  for (const auto &[key, value] : compound_factory::kBaseMap)
385  m_known_bases.insert(key);
386 }
std::set< std::string > m_known_peptides
Definition: compound.cpp:370
std::set< std::string > m_known_bases
Definition: compound.cpp:371
std::shared_ptr< compound_factory_impl > m_next
Definition: compound.cpp:373
std::shared_ptr< compound_factory_impl > next() const
Definition: compound.cpp:343

◆ compound_factory_impl() [2/2]

cif::compound_factory_impl::compound_factory_impl ( const fs::path &  file,
std::shared_ptr< compound_factory_impl next 
)

Definition at line 388 of file compound.cpp.

389  : m_next(next)
390 {
391  cif::file cifFile(file);
392 
393  if (cifFile.contains("comp_list")) // So this is a CCP4 restraints file, special handling
394  {
395  auto &compList = cifFile["comp_list"];
396  auto &chemComp = compList["chem_comp"];
397 
398  for (const auto &[id, name, group] : chemComp.rows<std::string, std::string, std::string>("id", "name", "group"))
399  {
400  std::string type;
401 
402  // known groups are (counted from ccp4 monomer dictionary)
403 
404  // D-pyranose
405  // DNA
406  // L-PEPTIDE LINKING
407  // L-SACCHARIDE
408  // L-peptide
409  // L-pyranose
410  // M-peptide
411  // NON-POLYMER
412  // P-peptide
413  // RNA
414  // furanose
415  // non-polymer
416  // non_polymer
417  // peptide
418  // pyranose
419  // saccharide
420 
421  if (cif::iequals(id, "gly"))
422  type = "peptide linking";
423  else if (cif::iequals(group, "l-peptide") or cif::iequals(group, "L-peptide linking") or cif::iequals(group, "peptide") or cif::iequals(group, "p-peptide"))
424  type = "L-peptide linking";
425  else if (cif::iequals(group, "DNA"))
426  type = "DNA linking";
427  else if (cif::iequals(group, "RNA"))
428  type = "RNA linking";
429  else
430  type = "non-polymer";
431 
432  auto &db = cifFile["comp_" + id];
433 
434  m_compounds.push_back(new compound(db, id, name, type, group));
435  }
436  }
437  else
438  {
439  // A CCD components file, validate it first
440  try
441  {
442  cifFile.load_dictionary("mmcif_pdbx.dic");
443 
444  if (not cifFile.is_valid())
445  {
446  std::cerr << "The components file " << file << " is not valid" << std::endl;
447  if (cif::VERBOSE < 1)
448  std::cerr << "(use --verbose to see why)" << std::endl;
449  }
450  }
451  catch (const std::exception &e)
452  {
453  std::cerr << "When trying to load the components file " << file << " there was an exception:" << std::endl
454  << e.what() << std::endl;
455  }
456 
457  for (auto &db : cifFile)
458  m_compounds.push_back(new compound(db));
459  }
460 }
std::vector< compound * > m_compounds
Definition: compound.cpp:369
bool iequals(std::string_view a, std::string_view b)
Definition: text.cpp:59
if(fabs(c[*nmax+ *nmax *c_dim1])==0.e0)
viol type
int VERBOSE
Definition: utilities.cpp:58
std::shared_ptr< compound_factory_impl > m_next
Definition: compound.cpp:373
std::shared_ptr< compound_factory_impl > next() const
Definition: compound.cpp:343

◆ ~compound_factory_impl()

virtual cif::compound_factory_impl::~compound_factory_impl ( )
inlinevirtual

Definition at line 297 of file compound.cpp.

298  {
299  for (auto c : m_compounds)
300  delete c;
301  }
doublereal * c
std::vector< compound * > m_compounds
Definition: compound.cpp:369

Member Function Documentation

◆ create()

virtual compound* cif::compound_factory_impl::create ( const std::string &  id)
inlineprotectedvirtual

Reimplemented in cif::CCP4_compound_factory_impl, and cif::CCD_compound_factory_impl.

Definition at line 361 of file compound.cpp.

362  {
363  // For the base class we assume every compound is preloaded
364  return nullptr;
365  }

◆ get()

compound* cif::compound_factory_impl::get ( std::string  id)
inline

Definition at line 303 of file compound.cpp.

304  {
305  cif::to_upper(id);
306 
307  std::shared_lock lock(mMutex);
308 
309  compound *result = nullptr;
310 
311  // walk the list, see if any of us has the compound already
312  for (auto impl = shared_from_this(); impl; impl = impl->m_next)
313  {
314  for (auto cmp : impl->m_compounds)
315  {
316  if (cmp->id() == id)
317  {
318  result = cmp;
319  break;
320  }
321  }
322 
323  if (result)
324  break;
325  }
326 
327  if (result == nullptr and m_missing.count(id) == 0)
328  {
329  for (auto impl = shared_from_this(); impl; impl = impl->m_next)
330  {
331  result = impl->create(id);
332  if (result != nullptr)
333  break;
334  }
335 
336  if (result == nullptr)
337  m_missing.insert(id);
338  }
339 
340  return result;
341  }
void to_upper(std::string &s)
Definition: text.cpp:128
std::set< std::string > m_missing
Definition: compound.cpp:372
std::shared_timed_mutex mMutex
Definition: compound.cpp:367

◆ is_known_base()

bool cif::compound_factory_impl::is_known_base ( const std::string &  resName)
inline

Definition at line 354 of file compound.cpp.

355  {
356  return m_known_bases.count(resName) or
357  (m_next and m_next->is_known_base(resName));
358  }
std::set< std::string > m_known_bases
Definition: compound.cpp:371
std::shared_ptr< compound_factory_impl > m_next
Definition: compound.cpp:373

◆ is_known_peptide()

bool cif::compound_factory_impl::is_known_peptide ( const std::string &  resName)
inline

Definition at line 348 of file compound.cpp.

349  {
350  return m_known_peptides.count(resName) or
351  (m_next and m_next->is_known_peptide(resName));
352  }
std::set< std::string > m_known_peptides
Definition: compound.cpp:370
std::shared_ptr< compound_factory_impl > m_next
Definition: compound.cpp:373

◆ next()

std::shared_ptr<compound_factory_impl> cif::compound_factory_impl::next ( ) const
inline

Definition at line 343 of file compound.cpp.

344  {
345  return m_next;
346  }
std::shared_ptr< compound_factory_impl > m_next
Definition: compound.cpp:373

Member Data Documentation

◆ m_compounds

std::vector<compound *> cif::compound_factory_impl::m_compounds
protected

Definition at line 369 of file compound.cpp.

◆ m_known_bases

std::set<std::string> cif::compound_factory_impl::m_known_bases
protected

Definition at line 371 of file compound.cpp.

◆ m_known_peptides

std::set<std::string> cif::compound_factory_impl::m_known_peptides
protected

Definition at line 370 of file compound.cpp.

◆ m_missing

std::set<std::string> cif::compound_factory_impl::m_missing
protected

Definition at line 372 of file compound.cpp.

◆ m_next

std::shared_ptr<compound_factory_impl> cif::compound_factory_impl::m_next
protected

Definition at line 373 of file compound.cpp.

◆ mMutex

std::shared_timed_mutex cif::compound_factory_impl::mMutex
protected

Definition at line 367 of file compound.cpp.


The documentation for this class was generated from the following file: