File: minilib.h

package info (click to toggle)
rdkit 202503.6-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 222,024 kB
  • sloc: cpp: 411,111; python: 78,482; ansic: 26,181; java: 8,285; javascript: 4,404; sql: 2,393; yacc: 1,626; lex: 1,267; cs: 1,090; makefile: 580; xml: 229; fortran: 183; sh: 121
file content (412 lines) | stat: -rw-r--r-- 15,864 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
//
//
//  Copyright (C) 2019-2021 Greg Landrum and other RDKit contributors
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#include <string>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/SubstructLibrary/SubstructLibrary.h>
#include <GraphMol/ChemReactions/Reaction.h>
#include <GraphMol/ChemReactions/ReactionParser.h>

#ifdef RDK_BUILD_MINIMAL_LIB_MMPA
#include <GraphMol/MMPA/MMPA.h>
#endif
#ifdef RDK_BUILD_MINIMAL_LIB_RGROUPDECOMP
#include <GraphMol/RGroupDecomposition/RGroupDecomp.h>
#endif

class JSMolList;

class JSMolBase {
 public:
  JSMolBase(const JSMolBase &) = delete;
  JSMolBase &operator=(const JSMolBase &) = delete;
  virtual ~JSMolBase(){};
  virtual const RDKit::RWMol &get() const = 0;
  virtual RDKit::RWMol &get() = 0;
  virtual void reset(RDKit::RWMol *other) = 0;
  std::string get_smiles() const;
  std::string get_smiles(const std::string &details) const;
  std::string get_cxsmiles() const;
  std::string get_cxsmiles(const std::string &details) const;
  std::string get_smarts() const;
  std::string get_smarts(const std::string &details) const;
  std::string get_cxsmarts() const;
  std::string get_cxsmarts(const std::string &details) const;
  std::string get_molblock(const std::string &details) const;
  std::string get_molblock() const { return get_molblock("{}"); }
  std::string get_v3Kmolblock(const std::string &details) const;
  std::string get_v3Kmolblock() const { return get_v3Kmolblock("{}"); }
  std::string get_pickle(const std::string &details) const;
  std::string get_pickle() const { return get_pickle(""); };
#ifdef RDK_BUILD_INCHI_SUPPORT
  std::string get_inchi(const std::string &options) const;
  std::string get_inchi() const { return get_inchi(""); }
#endif
  std::string get_json() const;
  std::string get_svg(int width, int height) const;
  std::string get_svg() const {
    return get_svg(d_defaultWidth, d_defaultHeight);
  }
  std::string get_svg_with_highlights(const std::string &details) const;
  std::string get_substruct_match(const JSMolBase &q) const;
  std::string get_substruct_matches(const JSMolBase &q) const;
  std::string get_descriptors() const;
  std::string get_morgan_fp(const std::string &details) const;
  std::string get_morgan_fp() const { return get_morgan_fp("{}"); }
  std::string get_morgan_fp_as_binary_text(const std::string &details) const;
  std::string get_morgan_fp_as_binary_text() const {
    return get_morgan_fp_as_binary_text("{}");
  }
  std::string get_pattern_fp(const std::string &details) const;
  std::string get_pattern_fp() const { return get_pattern_fp("{}"); }
  std::string get_pattern_fp_as_binary_text(const std::string &details) const;
  std::string get_pattern_fp_as_binary_text() const {
    return get_pattern_fp_as_binary_text("{}");
  }
  std::string get_topological_torsion_fp(const std::string &details) const;
  std::string get_topological_torsion_fp() const {
    return get_topological_torsion_fp("{}");
  };
  std::string get_topological_torsion_fp_as_binary_text(
      const std::string &details) const;
  std::string get_topological_torsion_fp_as_binary_text() const {
    return get_topological_torsion_fp_as_binary_text("{}");
  }
  std::string get_rdkit_fp(const std::string &details) const;
  std::string get_rdkit_fp() const { return get_rdkit_fp("{}"); }
  std::string get_rdkit_fp_as_binary_text(const std::string &details) const;
  std::string get_rdkit_fp_as_binary_text() const {
    return get_rdkit_fp_as_binary_text("{}");
  }
  std::string get_atom_pair_fp(const std::string &details) const;
  std::string get_atom_pair_fp() const { return get_atom_pair_fp("{}"); }
  std::string get_atom_pair_fp_as_binary_text(const std::string &details) const;
  std::string get_atom_pair_fp_as_binary_text() const {
    return get_atom_pair_fp_as_binary_text("{}");
  }
  std::string get_maccs_fp() const;
  std::string get_maccs_fp_as_binary_text() const;
#ifdef RDK_BUILD_AVALON_SUPPORT
  std::string get_avalon_fp(const std::string &details) const;
  std::string get_avalon_fp() const { return get_avalon_fp("{}"); }
  std::string get_avalon_fp_as_binary_text(const std::string &details) const;
  std::string get_avalon_fp_as_binary_text() const {
    return get_avalon_fp_as_binary_text("{}");
  }
#endif
  std::string condense_abbreviations(double maxCoverage, bool useLinkers);
  std::string condense_abbreviations() {
    return condense_abbreviations(0.4, false);
  }
  std::string condense_abbreviations_from_defs(const std::string &definitions,
                                               double maxCoverage,
                                               bool areLinkers);
  std::string generate_aligned_coords(const JSMolBase &templateMol,
                                      const std::string &details);
  std::string generate_aligned_coords(const JSMolBase &templateMol) {
    return generate_aligned_coords(templateMol, "{}");
  }
  [[deprecated(
      "please check the get_mol/get_qmol return value for non-nullness "
      "instead")]] bool
  is_valid() const;
  int has_coords() const;
  const RDGeom::POINT3D_VECT &get_coords() const;

  std::string get_stereo_tags();
  std::string get_aromatic_form() const;
  void convert_to_aromatic_form();
  std::string get_kekule_form() const;
  void convert_to_kekule_form();
  bool set_new_coords(bool useCoordGen);
  bool set_new_coords() { return set_new_coords(false); }
  std::string get_new_coords(bool useCoordGen) const;
  std::string get_new_coords() const { return get_new_coords(false); }
  bool has_prop(const std::string &key) const;
  std::vector<std::string> get_prop_list(bool includePrivate,
                                         bool includeComputed) const;
  std::vector<std::string> get_prop_list(bool includePrivate) const {
    return get_prop_list(includePrivate, true);
  }
  std::vector<std::string> get_prop_list() const {
    return get_prop_list(true, true);
  }
  bool set_prop(const std::string &key, const std::string &val, bool computed);
  bool set_prop(const std::string &key, const std::string &val) {
    return set_prop(key, val, false);
  }
  std::string get_prop(const std::string &key) const;
  bool clear_prop(const std::string &key);
  std::string remove_hs(const std::string &details_json) const;
  std::string remove_hs() const { return remove_hs(""); }
  bool remove_hs_in_place(const std::string &details_json);
  bool remove_hs_in_place() { return remove_hs_in_place(""); }
  std::string add_hs() const;
  bool add_hs_in_place();
  double normalize_depiction(int canonicalize, double scaleFactor);
  double normalize_depiction(int canonicalize) {
    return normalize_depiction(canonicalize, -1.);
  }
  double normalize_depiction() { return normalize_depiction(1, -1.); }
  void straighten_depiction(bool minimizeRotation);
  void straighten_depiction() { straighten_depiction(false); }
  std::pair<JSMolList *, std::string> get_frags(
      const std::string &details_json) const;
  std::pair<JSMolList *, std::string> get_frags() const {
    return get_frags("{}");
  }
  unsigned int get_num_atoms(bool heavyOnly) const;
  unsigned int get_num_atoms() const { return get_num_atoms(false); };
  unsigned int get_num_bonds() const;
  std::string add_to_png_blob(const std::string &pngString,
                              const std::string &details) const;
  std::string combine_with(const JSMolBase &other, const std::string &details);
  std::string combine_with(const JSMolBase &other) {
    return combine_with(other, "{}");
  }
#ifdef RDK_BUILD_MINIMAL_LIB_MMPA
  std::pair<JSMolList *, JSMolList *> get_mmpa_frags(
      unsigned int minCuts, unsigned int maxCuts,
      unsigned int maxCutBonds) const;
#endif

  static constexpr int d_defaultWidth = 250;
  static constexpr int d_defaultHeight = 200;

 protected:
  JSMolBase() = default;
};

class JSMol : public JSMolBase {
 public:
  JSMol() : d_mol(new RDKit::RWMol()) {}
  JSMol(RDKit::RWMol *mol) : d_mol(mol) { checkNotNull(); }
  JSMol(const JSMol &other) { d_mol.reset(new RDKit::RWMol(other.get())); }
  JSMol &operator=(const JSMol &other) {
    d_mol.reset(new RDKit::RWMol(other.get()));
    return *this;
  }
  const RDKit::RWMol &get() const {
    checkNotNull();
    return *d_mol.get();
  }
  RDKit::RWMol &get() {
    checkNotNull();
    return *d_mol.get();
  }
  void reset(RDKit::RWMol *other) {
    PRECONDITION(other, "other cannot be null");
    d_mol.reset(other);
  }

 private:
  void checkNotNull() const { CHECK_INVARIANT(d_mol, "d_mol cannot be null"); }
  std::unique_ptr<RDKit::RWMol> d_mol;
};

class JSMolShared : public JSMolBase {
 public:
  JSMolShared() = delete;
  JSMolShared(const RDKit::ROMOL_SPTR &mol) : d_mol(mol) { checkNotNull(); }
  JSMolShared(const JSMolShared &other) { d_mol = other.d_mol; }
  JSMolShared &operator=(const JSMolShared &other) {
    d_mol = other.d_mol;
    return *this;
  }
  const RDKit::RWMol &get() const {
    checkNotNull();
    return static_cast<RDKit::RWMol &>(*d_mol.get());
  }
  RDKit::RWMol &get() {
    checkNotNull();
    return static_cast<RDKit::RWMol &>(*d_mol.get());
  }
  const RDKit::ROMOL_SPTR &get_sptr() const { return d_mol; }
  RDKit::ROMOL_SPTR &get_sptr() { return d_mol; }
  void reset(RDKit::RWMol *other) {
    PRECONDITION(other, "other cannot be null");
    d_mol.reset(other);
  }
  void reset_sptr(const RDKit::ROMOL_SPTR &other) {
    PRECONDITION(other, "other cannot be null");
    d_mol = other;
  }

 private:
  void checkNotNull() const { CHECK_INVARIANT(d_mol, "d_mol cannot be null"); }
  RDKit::ROMOL_SPTR d_mol;
};

class JSMolList {
 public:
  JSMolList(const std::vector<RDKit::ROMOL_SPTR> &mols)
      : d_mols(mols), d_idx(0){};
  JSMolList() : d_idx(0){};
  JSMolBase *next();
  size_t append(const JSMolBase &mol);
  size_t insert(size_t idx, const JSMolBase &mol);
  JSMolBase *at(size_t idx) const;
  JSMolBase *pop(size_t idx);
  void reset() { d_idx = 0; }
  bool at_end() const { return d_idx == d_mols.size(); }
  size_t size() const { return d_mols.size(); }
  const std::vector<RDKit::ROMOL_SPTR> &mols() const { return d_mols; }

 private:
  std::vector<RDKit::ROMOL_SPTR> d_mols;
  size_t d_idx;
};

namespace RDKit {
namespace MinimalLib {
class LogHandle;
}
}  // namespace RDKit

class JSLog {
 public:
  JSLog(RDKit::MinimalLib::LogHandle *logHandle);
  ~JSLog();
  std::string get_buffer() const;
  void clear_buffer() const;

 private:
  RDKit::MinimalLib::LogHandle *d_logHandle;
};

#ifdef RDK_BUILD_MINIMAL_LIB_RXN
class JSReaction {
 public:
  JSReaction() : d_rxn(new RDKit::ChemicalReaction()) {}
  JSReaction(RDKit::ChemicalReaction *rxn) : d_rxn(rxn) { assert(d_rxn); }
  [[deprecated(
      "please check the get_rxn return value for non-nullness "
      "instead")]] bool
  is_valid() const;

  std::vector<JSMolList *> run_reactants(const JSMolList &reactants,
                                         unsigned int maxProducts) const;
  static constexpr int maxProducts = 1000;
  std::string get_svg(int width, int height) const;
  std::string get_svg() const {
    return get_svg(d_defaultWidth, d_defaultHeight);
  }
  std::string get_svg_with_highlights(const std::string &details) const;

  std::unique_ptr<RDKit::ChemicalReaction> d_rxn;
  static constexpr int d_defaultWidth = 800;
  static constexpr int d_defaultHeight = 200;
};
#endif

#ifdef RDK_BUILD_MINIMAL_LIB_SUBSTRUCTLIBRARY
class JSSubstructLibrary {
 public:
  JSSubstructLibrary(unsigned int num_bits);
  JSSubstructLibrary() : JSSubstructLibrary(d_defaultNumBits) {}
  int add_mol(const JSMolBase &m);
  int add_smiles(const std::string &smi);
  int add_trusted_smiles(const std::string &smi);
  int add_trusted_smiles_and_pattern_fp(const std::string &smi,
                                        const std::string &patternFp);
  std::string get_trusted_smiles(unsigned int i) const;
  std::string get_pattern_fp(unsigned int i) const;
  JSMolBase *get_mol(unsigned int i);
  std::string get_matches(const JSMolBase &q, bool useChirality, int numThreads,
                          int maxResults) const;
  std::string get_matches(const JSMolBase &q, int maxResults) const {
    return get_matches(q, d_defaultUseChirality, d_defaultNumThreads,
                       maxResults);
  }
  std::string get_matches(const JSMolBase &q) const {
    return get_matches(q, d_defaultUseChirality, d_defaultNumThreads,
                       d_defaultMaxResults);
  }
  unsigned int count_matches(const JSMolBase &q, bool useChirality,
                             int numThreads) const;
  unsigned int count_matches(const JSMolBase &q, bool useChirality) const {
    return count_matches(q, useChirality, d_defaultNumThreads);
  }
  unsigned int count_matches(const JSMolBase &q) const {
    return count_matches(q, d_defaultUseChirality, d_defaultNumThreads);
  }
  unsigned int size() const { return d_sslib->size(); }

  std::unique_ptr<RDKit::SubstructLibrary> d_sslib;
  RDKit::CachedTrustedSmilesMolHolder *d_molHolder;
  RDKit::PatternHolder *d_fpHolder;
  unsigned int d_num_bits;
  static constexpr unsigned int d_defaultNumBits = 2048;
  static constexpr bool d_defaultUseChirality = true;
  static constexpr int d_defaultNumThreads = -1;
  static constexpr int d_defaultMaxResults = 1000;

 private:
  inline int add_mol_helper(const RDKit::ROMol &mol);
};
#endif

#ifdef RDK_BUILD_INCHI_SUPPORT
std::string get_inchikey_for_inchi(const std::string &input);
#endif
JSMolBase *get_mol(const std::string &input, const std::string &details_json);
JSMolBase *get_mol_from_pickle(const std::string &pkl);
JSMolBase *get_mol_copy(const JSMolBase &other);
JSMolBase *get_qmol(const std::string &input);
#ifdef RDK_BUILD_MINIMAL_LIB_RXN
JSReaction *get_rxn(const std::string &input, const std::string &details_json);
#endif
std::string version();
void prefer_coordgen(bool prefer);
bool use_legacy_stereo_perception(bool value);
bool allow_non_tetrahedral_chirality(bool value);
bool enable_logging(const std::string &logName);
bool disable_logging(const std::string &logName);
JSLog *set_log_tee(const std::string &log_name);
JSLog *set_log_capture(const std::string &log_name);
JSMolBase *get_mol_from_png_blob(const std::string &pngString,
                                 const std::string &details);
JSMolList *get_mols_from_png_blob(const std::string &pngString,
                                  const std::string &details);
#ifdef RDK_BUILD_MINIMAL_LIB_MCS
std::string get_mcs_as_json(const JSMolList &mols,
                            const std::string &details_json);
std::string get_mcs_as_smarts(const JSMolList &mols,
                              const std::string &details_json);
JSMolBase *get_mcs_as_mol(const JSMolList &mols,
                          const std::string &details_json);
#endif

#ifdef RDK_BUILD_MINIMAL_LIB_RGROUPDECOMP
class JSRGroupDecomposition {
 public:
  JSRGroupDecomposition(const JSMolBase &core, const std::string &details_json);
  JSRGroupDecomposition(const JSMolBase &core)
      : JSRGroupDecomposition(core, ""){};
  JSRGroupDecomposition(const JSMolList &cores,
                        const std::string &details_json);
  JSRGroupDecomposition(const JSMolList &cores)
      : JSRGroupDecomposition(cores, ""){};
  int add(const JSMolBase &mol);
  bool process();
  std::map<std::string, std::unique_ptr<JSMolList>> getRGroupsAsColumns() const;
  std::vector<std::map<std::string, std::unique_ptr<JSMolBase>>>
  getRGroupsAsRows() const;

 private:
  std::unique_ptr<RDKit::RGroupDecomposition> d_decomp;
  std::vector<unsigned int> d_unmatched;
};
#endif

#ifdef RDK_BUILD_MINIMAL_LIB_MOLZIP
JSMolBase *molzip(const JSMolBase &a, const JSMolBase &b,
                  const std::string &details_json);
#endif