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 <iostream>
18#include <fstream>
19#include <unordered_map>
20
21namespace RDDepict {
23 public:
24 //! returns a reference to the singleton CoordinateTemplates
25 /*
26 \return a reference to the singleton CoordinateTemplates
27
28 <b>Notes:</b>
29 - if the singleton CoordinateTemplates has already been instantiated
30 the singleton will be returned, otherwise the singleton will
31 be constructed.
32
33 */
35 static CoordinateTemplates template_mols;
36 return template_mols;
37 }
38
39 bool hasTemplateOfSize(unsigned int atomCount) {
40 if (m_templates.find(atomCount) != m_templates.end()) {
41 return true;
42 }
43 return false;
44 }
45
46 const std::vector<std::shared_ptr<RDKit::ROMol>> &getMatchingTemplates(
47 unsigned int atomCount) {
48 return m_templates[atomCount];
49 }
50
51 void setRingSystemTemplates(const std::string &templatePath);
52 void addRingSystemTemplates(const std::string &templatePath);
53
54 //! check if a template is considered valid
55 /*
56 \param template mol
57 \param smiles for logging
58 \return whether the template is valid
59
60 <b>A template is considered valid if it:</b>
61 - has 2D coordinates
62 - is a ring system (spiro'd ring systems are OK)
63 - consists of only 1 fragment
64
65 */
66 static void assertValidTemplate(RDKit::ROMol &mol, const std::string &smiles);
67
69 clearTemplates();
70 // load default templates into m_templates map by atom count
71 for (const auto &smiles : TEMPLATE_SMILES) {
72 std::shared_ptr<RDKit::ROMol> mol(RDKit::SmilesToMol(smiles));
73 m_templates[mol->getNumAtoms()].push_back(mol);
74 }
75 }
76
77 private:
78 CoordinateTemplates() { loadDefaultTemplates(); }
79 CoordinateTemplates(const CoordinateTemplates &) = delete;
80 CoordinateTemplates &operator=(const CoordinateTemplates &) = delete;
81
82 void clearTemplates() {
83 for (auto &[atom_cout, romols] : m_templates) {
84 romols.clear();
85 }
86 m_templates.clear();
87 }
88
89 ~CoordinateTemplates() { clearTemplates(); }
90
91 void loadTemplatesFromPath(
92 const std::string &templatePath,
93 std::unordered_map<
94 unsigned int, std::vector<std::shared_ptr<RDKit::ROMol>>> &templates);
95
96 std::unordered_map<unsigned int, std::vector<std::shared_ptr<RDKit::ROMol>>>
97 m_templates;
98};
99} // 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:46
bool hasTemplateOfSize(unsigned int atomCount)
Definition Templates.h:39
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:34
#define RDKIT_DEPICTOR_EXPORT
Definition export.h:89
RDKit::RWMol * SmilesToMol(const std::string &smi, const SmilesParserParams &ps)