RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Templates.h
Go to the documentation of this file.
1//
2// Copyright (C) 2023 Schrödinger, LLC
3//
4// @@ All Rights Reserved @@
5// This file is part of the RDKit.
6// The contents are covered by the terms of the BSD license
7// which is included in the file license.txt, found at the root
8// of the RDKit source tree.
9//
10
11#include <GraphMol/ROMol.h>
13#include <GraphMol/MolOps.h>
14
15#include "TemplateSmiles.h"
16
17#include <fstream>
18#include <unordered_map>
19
20namespace RDDepict {
21class RDKIT_DEPICTOR_EXPORT CoordinateTemplates {
22 public:
23 //! returns a reference to the singleton CoordinateTemplates
24 /*
25 \return a reference to the singleton CoordinateTemplates
26
27 <b>Notes:</b>
28 - if the singleton CoordinateTemplates has already been instantiated
29 the singleton will be returned, otherwise the singleton will
30 be constructed.
31
32 */
33 static CoordinateTemplates &getRingSystemTemplates() {
34 static CoordinateTemplates template_mols;
35 return template_mols;
36 }
37
38 bool hasTemplateOfSize(unsigned int atomCount) {
39 if (m_templates.find(atomCount) != m_templates.end()) {
40 return true;
41 }
42 return false;
43 }
44
45 const std::vector<std::shared_ptr<RDKit::ROMol>> &getMatchingTemplates(
46 unsigned int atomCount) {
47 return m_templates[atomCount];
48 }
49
50 void setRingSystemTemplates(const std::string &templatePath);
51 void addRingSystemTemplates(const std::string &templatePath);
52
53 //! check if a template is considered valid
54 /*
55 \param template mol
56 \param smiles for logging
57 \return whether the template is valid
58
59 <b>A template is considered valid if it:</b>
60 - has 2D coordinates
61 - is a ring system (spiro'd ring systems are OK)
62 - consists of only 1 fragment
63
64 */
65 static void assertValidTemplate(RDKit::ROMol &mol, const std::string &smiles);
66
68 clearTemplates();
69 // load default templates into m_templates map by atom count
70 for (const auto &smiles : TEMPLATE_SMILES) {
71 std::shared_ptr<RDKit::ROMol> mol(RDKit::SmilesToMol(smiles));
72 m_templates[mol->getNumAtoms()].push_back(mol);
73 }
74 }
75
76 private:
77 CoordinateTemplates() { loadDefaultTemplates(); }
78 CoordinateTemplates(const CoordinateTemplates &) = delete;
79 CoordinateTemplates &operator=(const CoordinateTemplates &) = delete;
80
81 void clearTemplates() {
82 for (auto &[atom_cout, romols] : m_templates) {
83 romols.clear();
84 }
85 m_templates.clear();
86 }
87
88 ~CoordinateTemplates() { clearTemplates(); }
89
90 void loadTemplatesFromPath(
91 const std::string &templatePath,
92 std::unordered_map<
93 unsigned int, std::vector<std::shared_ptr<RDKit::ROMol>>> &templates);
94
95 std::unordered_map<unsigned int, std::vector<std::shared_ptr<RDKit::ROMol>>>
96 m_templates;
97};
98} // namespace RDDepict
Defines the primary molecule class ROMol as well as associated typedefs.
const std::vector< std::string > TEMPLATE_SMILES
const std::vector< std::shared_ptr< RDKit::ROMol > > & getMatchingTemplates(unsigned int atomCount)
Definition Templates.h:45
bool hasTemplateOfSize(unsigned int atomCount)
Definition Templates.h:38
void addRingSystemTemplates(const std::string &templatePath)
static void assertValidTemplate(RDKit::ROMol &mol, const std::string &smiles)
check if a template is considered valid
void setRingSystemTemplates(const std::string &templatePath)
static CoordinateTemplates & getRingSystemTemplates()
returns a reference to the singleton CoordinateTemplates
Definition Templates.h:33
#define RDKIT_DEPICTOR_EXPORT
Definition export.h:97
RDKit::RWMol * SmilesToMol(const std::string &smi, const SmilesParserParams &ps)