mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
Cleanup/get atoms and bonds (#9243)
This commit is contained in:
17
External/FreeSASA/RDFreeSASA.cpp
vendored
17
External/FreeSASA/RDFreeSASA.cpp
vendored
@@ -89,8 +89,7 @@ bool classifyAtoms(ROMol &mol, std::vector<double> &radii,
|
||||
}
|
||||
|
||||
bool success = true;
|
||||
for (ROMol::AtomIterator at = mol.beginAtoms(); at != mol.endAtoms(); ++at) {
|
||||
Atom *atom = *at;
|
||||
for (const auto atom : mol.atoms()) {
|
||||
freesasa_atom_class cls = FREESASA_ATOM_UNKNOWN;
|
||||
std::string classification = "Unclassified";
|
||||
double radius = 0.0;
|
||||
@@ -168,9 +167,9 @@ double internalCalcSASA(const ROMol &mol, const std::vector<double> &radii,
|
||||
double sasa = res->total;
|
||||
mol.setProp(common_properties::Molecule::SASA, sasa);
|
||||
size_t i = 0;
|
||||
for (ROMol::ConstAtomIterator at = mol.beginAtoms(); at != mol.endAtoms();
|
||||
++at, ++i) {
|
||||
(*at)->setProp(common_properties::Atom::SASA, res->sasa[i]);
|
||||
for (const auto atom : mol.atoms()) {
|
||||
atom->setProp(common_properties::Atom::SASA, res->sasa[i]);
|
||||
++i;
|
||||
}
|
||||
|
||||
freesasa_result_free(res);
|
||||
@@ -184,10 +183,10 @@ double calcSASA(const RDKit::ROMol &mol, const std::vector<double> &radii,
|
||||
double result = internalCalcSASA(mol, radii, confIdx, opts);
|
||||
if (query) {
|
||||
result = 0.0f;
|
||||
for (ROMol::ConstQueryAtomIterator at = mol.beginQueryAtoms(query);
|
||||
at != mol.endQueryAtoms(); ++at) {
|
||||
const Atom *atom = *at;
|
||||
result += atom->getProp<double>("SASA");
|
||||
for (const auto atom : mol.atoms()) {
|
||||
if (query->Match(atom)) {
|
||||
result += atom->getProp<double>("SASA");
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
85
External/INCHI-API/inchi.cpp
vendored
85
External/INCHI-API/inchi.cpp
vendored
@@ -1149,97 +1149,96 @@ bool _Valence3ClCleanUp1(RWMol &mol, Atom *atom) {
|
||||
}
|
||||
|
||||
void cleanUp(RWMol &mol) {
|
||||
ROMol::AtomIterator ai;
|
||||
bool aromHolder;
|
||||
for (ai = mol.beginAtoms(); ai != mol.endAtoms(); ++ai) {
|
||||
switch ((*ai)->getAtomicNum()) {
|
||||
for (const auto atom : mol.atoms()) {
|
||||
switch (atom->getAtomicNum()) {
|
||||
case 7:
|
||||
if ((*ai)->calcExplicitValence(false) == 4) {
|
||||
if (_Valence4NCleanUp1(mol, *ai)) {
|
||||
if (atom->calcExplicitValence(false) == 4) {
|
||||
if (_Valence4NCleanUp1(mol, atom)) {
|
||||
continue;
|
||||
}
|
||||
if ((*ai)->getFormalCharge() == -1) {
|
||||
if (_Valence4NCleanUp2(mol, *ai)) {
|
||||
if (atom->getFormalCharge() == -1) {
|
||||
if (_Valence4NCleanUp2(mol, atom)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*ai)->getFormalCharge()) {
|
||||
if (atom->getFormalCharge()) {
|
||||
continue;
|
||||
}
|
||||
aromHolder = (*ai)->getIsAromatic();
|
||||
(*ai)->setIsAromatic(0);
|
||||
aromHolder = atom->getIsAromatic();
|
||||
atom->setIsAromatic(0);
|
||||
|
||||
if ((*ai)->calcExplicitValence(false) == 5) {
|
||||
if (atom->calcExplicitValence(false) == 5) {
|
||||
// rings CN1=CCN=CC=1, CN1=NCOCC=1, [N]=C1N=CN=N1, [N]=C1C=CN=N1
|
||||
(_Valence5NCleanUp6(mol, *ai)) || (_Valence5NCleanUp7(mol, *ai)) ||
|
||||
(_Valence5NCleanUp8(mol, *ai)) ||
|
||||
(_Valence5NCleanUp9(mol, *ai)) ||
|
||||
(_Valence5NCleanUpA(mol, *ai)) ||
|
||||
(_Valence5NCleanUp6(mol, atom)) || (_Valence5NCleanUp7(mol, atom)) ||
|
||||
(_Valence5NCleanUp8(mol, atom)) ||
|
||||
(_Valence5NCleanUp9(mol, atom)) ||
|
||||
(_Valence5NCleanUpA(mol, atom)) ||
|
||||
// try search for valence-5 N connected to a N+
|
||||
(_Valence5NCleanUp1(mol, *ai)) ||
|
||||
(_Valence5NCleanUp1(mol, atom)) ||
|
||||
// connected to N- through a tiple then single bond
|
||||
(_Valence5NCleanUp2(mol, *ai)) ||
|
||||
(_Valence5NCleanUp2(mol, atom)) ||
|
||||
// directly to a N
|
||||
(_Valence5NCleanUp3(mol, *ai)) ||
|
||||
(_Valence5NCleanUp3(mol, atom)) ||
|
||||
// to two Si- via double bonds
|
||||
(_Valence5NCleanUp4(mol, *ai)) ||
|
||||
(_Valence5NCleanUp4(mol, atom)) ||
|
||||
// alternating bonds to O
|
||||
(_Valence5NCleanUp5(mol, *ai, 8)) ||
|
||||
(_Valence5NCleanUp5(mol, atom, 8)) ||
|
||||
// alternating bonds to S
|
||||
(_Valence5NCleanUp5(mol, *ai, 16)) ||
|
||||
(_Valence5NCleanUp5(mol, atom, 16)) ||
|
||||
// alternating bonds to S
|
||||
(_Valence5NCleanUp5(mol, *ai, 9)) ||
|
||||
(_Valence5NCleanUp5(mol, atom, 9)) ||
|
||||
// alternating bonds to S
|
||||
(_Valence5NCleanUp5(mol, *ai, 17)) ||
|
||||
(_Valence5NCleanUp5(mol, atom, 17)) ||
|
||||
// last resort
|
||||
(_Valence5NCleanUpB(mol, *ai));
|
||||
(_Valence5NCleanUpB(mol, atom));
|
||||
}
|
||||
if (aromHolder) {
|
||||
(*ai)->setIsAromatic(1);
|
||||
atom->setIsAromatic(1);
|
||||
}
|
||||
break;
|
||||
case 17:
|
||||
if ((*ai)->calcExplicitValence(false) == 8 &&
|
||||
_Valence8ClCleanUp1(mol, *ai)) {
|
||||
if (atom->calcExplicitValence(false) == 8 &&
|
||||
_Valence8ClCleanUp1(mol, atom)) {
|
||||
continue;
|
||||
}
|
||||
if ((*ai)->calcExplicitValence(false) == 5 &&
|
||||
_Valence5ClCleanUp1(mol, *ai)) {
|
||||
if (atom->calcExplicitValence(false) == 5 &&
|
||||
_Valence5ClCleanUp1(mol, atom)) {
|
||||
continue;
|
||||
}
|
||||
if ((*ai)->calcExplicitValence(false) == 3 &&
|
||||
_Valence3ClCleanUp1(mol, *ai)) {
|
||||
if (atom->calcExplicitValence(false) == 3 &&
|
||||
_Valence3ClCleanUp1(mol, atom)) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
if ((*ai)->calcExplicitValence(false) == 7) {
|
||||
if (_Valence7SCleanUp1(mol, *ai)) {
|
||||
if (atom->calcExplicitValence(false) == 7) {
|
||||
if (_Valence7SCleanUp1(mol, atom)) {
|
||||
continue;
|
||||
}
|
||||
if (_Valence7SCleanUp2(mol, *ai)) {
|
||||
if (_Valence7SCleanUp2(mol, atom)) {
|
||||
continue;
|
||||
}
|
||||
if (_Valence7SCleanUp3(mol, *ai)) {
|
||||
if (_Valence7SCleanUp3(mol, atom)) {
|
||||
continue;
|
||||
}
|
||||
_Valence8SCleanUp1(mol, *ai);
|
||||
} else if ((*ai)->calcExplicitValence(false) == 8) {
|
||||
_Valence8SCleanUp1(mol, *ai);
|
||||
_Valence8SCleanUp1(mol, atom);
|
||||
} else if (atom->calcExplicitValence(false) == 8) {
|
||||
_Valence8SCleanUp1(mol, atom);
|
||||
}
|
||||
break;
|
||||
case 35:
|
||||
if ((*ai)->calcExplicitValence(false) == 3 &&
|
||||
(*ai)->getFormalCharge() == 0) {
|
||||
if (atom->calcExplicitValence(false) == 3 &&
|
||||
atom->getFormalCharge() == 0) {
|
||||
// connected to Se. Example: PubChem 10787526
|
||||
if ((*ai)->getDegree() == 1) {
|
||||
if (atom->getDegree() == 1) {
|
||||
RWMol::ADJ_ITER nid, end;
|
||||
boost::tie(nid, end) = mol.getAtomNeighbors(*ai);
|
||||
boost::tie(nid, end) = mol.getAtomNeighbors(atom);
|
||||
if (mol.getAtomWithIdx(*nid)->getAtomicNum() == 34) {
|
||||
mol.getBondBetweenAtoms((*ai)->getIdx(), *nid)
|
||||
mol.getBondBetweenAtoms(atom->getIdx(), *nid)
|
||||
->setBondType(Bond::SINGLE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user