File: Metal.cpp

package info (click to toggle)
rdkit 202503.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 578; xml: 229; fortran: 183; sh: 105
file content (134 lines) | stat: -rw-r--r-- 5,348 bytes parent folder | download | duplicates (3)
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
//
//  Copyright (C) 2018 Susan H. Leung
//
//   @@ 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 <RDBoost/Wrap.h>

#include <GraphMol/RDKitBase.h>
#include <GraphMol/SmilesParse/SmartsWrite.h>
#include <GraphMol/MolStandardize/Metal.h>

namespace python = boost::python;

namespace {

class MetalDisconnectorWrap {
 public:
  MetalDisconnectorWrap(python::object options = python::object()) {
    if (options.is_none()) {
      md_.reset(new RDKit::MolStandardize::MetalDisconnector());
    } else {
      RDKit::MolStandardize::MetalDisconnectorOptions md_opts;
      md_opts.splitGrignards =
          python::extract<bool>(options.attr("splitGrignards"));
      md_opts.splitAromaticC =
          python::extract<bool>(options.attr("splitAromaticC"));
      md_opts.adjustCharges =
          python::extract<bool>(options.attr("adjustCharges"));
      md_opts.removeHapticDummies =
          python::extract<bool>(options.attr("removeHapticDummies"));
      md_.reset(new RDKit::MolStandardize::MetalDisconnector(md_opts));
    }
  }

  RDKit::ROMol *getMetalNof() { return md_->getMetalNof(); }
  RDKit::ROMol *getMetalNon() { return md_->getMetalNon(); }
  void setMetalNof(const RDKit::ROMol &mol) { md_->setMetalNof(mol); }
  void setMetalNon(const RDKit::ROMol &mol) { md_->setMetalNon(mol); }

  RDKit::ROMol *disconnect(const RDKit::ROMol &mol) {
    return md_->disconnect(mol);
  }
  void disconnectInPlace(RDKit::ROMol &mol) {
    return md_->disconnectInPlace(static_cast<RDKit::RWMol &>(mol));
  }

 private:
  std::unique_ptr<RDKit::MolStandardize::MetalDisconnector> md_;
};

std::string getMetalNofHelper(MetalDisconnectorWrap &self) {
  return RDKit::MolToSmarts(*(self.getMetalNof()));
}

std::string getMetalNonHelper(MetalDisconnectorWrap &self) {
  return RDKit::MolToSmarts(*(self.getMetalNon()));
}

void setMetalNonHelper(MetalDisconnectorWrap &self, const RDKit::ROMol &mol) {
  self.setMetalNon(mol);
}

void setMetalNofHelper(MetalDisconnectorWrap &self, const RDKit::ROMol &mol) {
  self.setMetalNof(mol);
}
}  // namespace

struct metal_wrapper {
  static void wrap() {
    python::scope().attr("__doc__") =
        "Module containing functions for molecular standardization";

    std::string docString = "Metal Disconnector Options";
    python::class_<RDKit::MolStandardize::MetalDisconnectorOptions>(
        "MetalDisconnectorOptions", docString.c_str(),
        python::init<>(python::args("self")))
        .def_readwrite(
            "splitGrignards",
            &RDKit::MolStandardize::MetalDisconnectorOptions::splitGrignards,
            "Whether to split Grignard-type complexes. Default false.")
        .def_readwrite(
            "splitAromaticC",
            &RDKit::MolStandardize::MetalDisconnectorOptions::splitAromaticC,
            "Whether to split metal-aromatic C bonds.  Default false.")
        .def_readwrite(
            "adjustCharges",
            &RDKit::MolStandardize::MetalDisconnectorOptions::adjustCharges,
            "Whether to adjust charges on ligand atoms.  Default true.")
        .def_readwrite("removeHapticDummies",
                       &RDKit::MolStandardize::MetalDisconnectorOptions::
                           removeHapticDummies,
                       "Whether to remove the dummy atoms representing haptic"
                       " bonds.  Such dummies are bonded to the metal with a"
                       " bond that has the MolFileBondEndPts prop set."
                       "  Default false.");

    docString =
        "a class to disconnect metals that are defined as covalently bonded to"
        " non-metals";
    python::class_<MetalDisconnectorWrap, boost::noncopyable>(
        "MetalDisconnector", docString.c_str(),
        python::init<python::optional<python::object>>(
            (python::arg("self"), python::arg("options") = python::object())))
        .add_property("MetalNof", &getMetalNofHelper,
                      "SMARTS defining the metals to disconnect if attached to "
                      "Nitrogen, Oxygen or Fluorine")
        .add_property(
            "MetalNon", &getMetalNonHelper,
            "SMARTS defining the metals to disconnect other inorganic elements")
        .def(
            "SetMetalNon", &setMetalNonHelper,
            (python::arg("self"), python::arg("mol")),
            "Set the query molecule defining the metals to disconnect from other"
            " inorganic elements.")
        .def(
            "SetMetalNof", &setMetalNofHelper,
            (python::arg("self"), python::arg("mol")),
            "Set the query molecule defining the metals to disconnect if attached"
            " to Nitrogen, Oxygen or Fluorine.")
        .def("Disconnect", &MetalDisconnectorWrap::disconnect,
             (python::arg("self"), python::arg("mol")),
             "performs the disconnection",
             python::return_value_policy<python::manage_new_object>())
        .def("DisconnectInPlace", &MetalDisconnectorWrap::disconnectInPlace,
             (python::arg("self"), python::arg("mol")),
             "performs the disconnection, modifies the input molecule");
  }
};

void wrap_metal() { metal_wrapper::wrap(); }