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
|
//
// 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 "MolStandardize.h"
#include "Metal.h"
#include "Normalize.h"
#include "Tautomer.h"
#include "Fragment.h"
#include <GraphMol/RDKitBase.h>
#include <iostream>
#include <GraphMol/ROMol.h>
#include <GraphMol/MolOps.h>
#include <GraphMol/MolStandardize/TransformCatalog/TransformCatalogParams.h>
#include "Charge.h"
#include <GraphMol/SmilesParse/SmilesWrite.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
using namespace std;
namespace RDKit {
namespace MolStandardize {
const CleanupParameters defaultCleanupParameters;
RWMol *cleanup(const RWMol &mol, const CleanupParameters ¶ms) {
RWMol m(mol);
MolOps::sanitizeMol(m);
MolOps::removeHs(m);
MolStandardize::MetalDisconnector md;
md.disconnect(m);
RWMOL_SPTR normalized(MolStandardize::normalize(&m, params));
RWMol *reionized = MolStandardize::reionize(normalized.get(), params);
MolOps::assignStereochemistry(*reionized);
return reionized;
}
void tautomerParent(RWMol &mol, const CleanupParameters ¶ms) {
RDUNUSED_PARAM(mol);
RDUNUSED_PARAM(params);
UNDER_CONSTRUCTION("Not yet implmented");
}
// Return the fragment parent of a given molecule.
// The fragment parent is the largest organic covalent unit in the molecule.
//
RWMol *fragmentParent(const RWMol &mol, const CleanupParameters ¶ms,
bool skip_standardize) {
const RWMol *cleaned = nullptr;
if (!skip_standardize) {
cleaned = cleanup(mol, params);
} else {
cleaned = &mol;
}
LargestFragmentChooser lfragchooser(params.preferOrganic);
ROMol nm(*cleaned);
ROMOL_SPTR lfrag(lfragchooser.choose(nm));
delete cleaned;
return new RWMol(*lfrag);
}
void stereoParent(RWMol &mol, const CleanupParameters ¶ms) {
RDUNUSED_PARAM(mol);
RDUNUSED_PARAM(params);
UNDER_CONSTRUCTION("Not yet implmented");
}
void isotopeParent(RWMol &mol, const CleanupParameters ¶ms) {
RDUNUSED_PARAM(mol);
RDUNUSED_PARAM(params);
UNDER_CONSTRUCTION("Not yet implmented");
}
RWMol *chargeParent(const RWMol &mol, const CleanupParameters ¶ms,
bool skip_standardize) {
// Return the charge parent of a given molecule.
// The charge parent is the uncharged version of the fragment parent.
RWMol *m = nullptr;
if (!skip_standardize) {
m = cleanup(mol, params);
}
RWMOL_SPTR fragparent(fragmentParent(*m, params, true));
// if fragment...
ROMol nm(*fragparent);
Uncharger uncharger;
ROMOL_SPTR uncharged(uncharger.uncharge(nm));
RWMol *omol = cleanup(static_cast<RWMol>(*uncharged), params);
return omol;
}
void superParent(RWMol &mol, const CleanupParameters ¶ms) {
RDUNUSED_PARAM(mol);
RDUNUSED_PARAM(params);
UNDER_CONSTRUCTION("Not yet implmented");
}
RWMol *normalize(const RWMol *mol, const CleanupParameters ¶ms) {
Normalizer normalizer(params.normalizations, params.maxRestarts);
ROMol m(*mol);
ROMol *normalized = normalizer.normalize(m);
return static_cast<RWMol *>(normalized);
}
RWMol *reionize(const RWMol *mol, const CleanupParameters ¶ms) {
RDUNUSED_PARAM(params);
Reionizer reionizer;
ROMol m(*mol);
ROMol *reionized = reionizer.reionize(m);
return static_cast<RWMol *>(reionized);
}
std::string standardizeSmiles(const std::string &smiles) {
RWMOL_SPTR mol(SmilesToMol(smiles, 0, false));
if (!mol) {
std::string message =
"SMILES Parse Error: syntax error for input: " + smiles;
throw ValueErrorException(message);
}
CleanupParameters params;
RWMOL_SPTR cleaned(cleanup(*mol, params));
return MolToSmiles(*cleaned);
}
std::vector<std::string> enumerateTautomerSmiles(
const std::string &smiles, const CleanupParameters ¶ms) {
std::shared_ptr<RWMol> mol(SmilesToMol(smiles, 0, false));
cleanup(*mol, params);
MolOps::sanitizeMol(*mol);
auto *tautparams = new TautomerCatalogParams(params.tautomerTransforms);
// unsigned int ntautomers = tautparams->getNumTautomers();
TautomerCatalog tautcat(tautparams);
TautomerEnumerator te;
std::vector<ROMOL_SPTR> res =
te.enumerate(static_cast<ROMol>(*mol), &tautcat);
std::vector<std::string> tsmiles;
for (const auto &r : res) {
tsmiles.push_back(MolToSmiles(*r));
}
return tsmiles;
}
} // end of namespace MolStandardize
} // end of namespace RDKit
|