File: Fragment.h

package info (click to toggle)
rdkit 202209.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 203,880 kB
  • sloc: cpp: 334,239; python: 80,247; ansic: 24,579; java: 7,667; sql: 2,123; yacc: 1,884; javascript: 1,358; lex: 1,260; makefile: 576; xml: 229; fortran: 183; cs: 181; sh: 101
file content (105 lines) | stat: -rw-r--r-- 3,547 bytes parent folder | download
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
//
//  Copyright (C) 2018-2021 Susan H. Leung 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 <RDGeneral/export.h>
#ifndef RD_FRAGMENT_REMOVER_H
#define RD_FRAGMENT_REMOVER_H

#include <Catalogs/Catalog.h>
#include <GraphMol/MolStandardize/FragmentCatalog/FragmentCatalogEntry.h>
#include <GraphMol/MolStandardize/FragmentCatalog/FragmentCatalogParams.h>
#include <GraphMol/MolStandardize/MolStandardize.h>

namespace RDKit {
class ROMol;

namespace MolStandardize {

RDKIT_MOLSTANDARDIZE_EXPORT extern const CleanupParameters
    defaultCleanupParameters;

typedef RDCatalog::HierarchCatalog<FragmentCatalogEntry, FragmentCatalogParams,
                                   int>
    FragmentCatalog;

class RDKIT_MOLSTANDARDIZE_EXPORT FragmentRemover {
 public:
  FragmentRemover();
  FragmentRemover(const std::string fragmentFile, bool leave_last,
                  bool skip_if_all_match = false);
  FragmentRemover(std::istream &fragmentStream, bool leave_last,
                  bool skip_if_all_match = false);
  FragmentRemover(const std::vector<std::pair<std::string, std::string>> &data,
                  bool leave_last, bool skip_if_all_match = false);
  ~FragmentRemover();

  //! making FragmentRemover objects non-copyable
  FragmentRemover(const FragmentRemover &other) = delete;
  FragmentRemover &operator=(FragmentRemover const &) = delete;

  ROMol *remove(const ROMol &mol);

 private:
  // Setting leave_last to True will ensure at least one fragment
  //  is left in the molecule, even if it is matched by a
  //  FragmentPattern
  bool LEAVE_LAST;
  // If set, this causes the original molecule to be returned
  // if every fragment in it matches the salt list
  bool SKIP_IF_ALL_MATCH;
  FragmentCatalog *d_fcat;

};  // class FragmentRemover

// caller owns the returned pointer
inline FragmentRemover *fragmentRemoverFromParams(
    const CleanupParameters &params, bool leave_last = true,
    bool skip_if_all_match = false) {
  if (params.fragmentData.empty()) {
    return new FragmentRemover(params.fragmentFile, leave_last,
                               skip_if_all_match);
  } else {
    return new FragmentRemover(params.fragmentData, leave_last,
                               skip_if_all_match);
  }
}

class RDKIT_MOLSTANDARDIZE_EXPORT LargestFragmentChooser {
 public:
  //  LargestFragmentChooser() {}
  LargestFragmentChooser(bool preferOrganic = false)
      : preferOrganic(preferOrganic) {}
  LargestFragmentChooser(const CleanupParameters &params)
      : preferOrganic(params.preferOrganic),
        useAtomCount(params.largestFragmentChooserUseAtomCount),
        countHeavyAtomsOnly(params.largestFragmentChooserCountHeavyAtomsOnly) {}
  LargestFragmentChooser(const LargestFragmentChooser &other);
  ~LargestFragmentChooser() = default;

  ROMol *choose(const ROMol &mol);
  struct Largest {
    Largest();
    Largest(std::string &smiles, boost::shared_ptr<ROMol> fragment,
            unsigned int &numatoms, double &weight, bool &organic);
    std::string Smiles;
    boost::shared_ptr<ROMol> Fragment;
    unsigned int NumAtoms{0};
    double Weight{0};
    bool Organic{false};
  };

 private:
  bool preferOrganic;
  bool useAtomCount{true};
  bool countHeavyAtomsOnly{false};
};  // class LargestFragmentChooser
}  // namespace MolStandardize
}  // namespace RDKit

#endif