|
17 | 17 | BondType,
|
18 | 18 | GetSymmSSSR,
|
19 | 19 | RemoveHs,
|
| 20 | + Descriptors, |
20 | 21 | MurckoDecompose,
|
| 22 | + MolStandardize, |
21 | 23 | CHI_UNSPECIFIED,
|
22 | 24 | SANITIZE_ALL,
|
23 | 25 | SANITIZE_CLEANUP,
|
@@ -459,19 +461,73 @@ def keep_largest_fragment(mol):
|
459 | 461 | return max(frags, key=lambda x: x.GetNumAtoms())
|
460 | 462 |
|
461 | 463 |
|
462 |
| -def discharge_and_deradicalize(mol): |
463 |
| - """Discharge and remove radicals (brute force). |
| 464 | +def convert_radicals_to_hydrogen(mol): |
| 465 | + """Converts radical electrons in a molecule into bonds to hydrogens. |
464 | 466 |
|
465 |
| - This operation is performed in-place. |
| 467 | + Parameters |
| 468 | + ---------- |
| 469 | + mol : rdkit.Chem.rdchem.Mol |
| 470 | +
|
| 471 | + Returns |
| 472 | + ------- |
| 473 | + mol : rdkit.Chem.rdchem.Mol |
| 474 | + New molecule with radical electrons converted into |
| 475 | + bonds to hydrogens. |
| 476 | +
|
| 477 | + """ |
| 478 | + m = Mol(mol) |
| 479 | + if Descriptors.NumRadicalElectrons(m) == 0: |
| 480 | + return m |
| 481 | + else: |
| 482 | + for atom in m.GetAtoms(): |
| 483 | + nradicals = atom.GetNumRadicalElectrons() |
| 484 | + if nr > 0: |
| 485 | + atom.SetNumRadicalElectrons(0) |
| 486 | + atom.SetNumExplicitHs(nradicals) |
| 487 | + return m |
| 488 | + |
| 489 | + |
| 490 | +@suppress_rdlogger() |
| 491 | +def discharge_molecule(mol): |
| 492 | + """Discharge molecules using the RDKit Uncharger class. |
| 493 | +
|
| 494 | + Uncharges molecules by adding and/or removing hydrogens. |
| 495 | + For zwitterions, hydrogens are moved to eliminate charges where possible. |
| 496 | + In cases where there is a positive charge that is not neutralizable, |
| 497 | + an attempt is made to also preserve the corresponding negative charge. |
466 | 498 |
|
467 | 499 | Parameters
|
468 | 500 | ----------
|
469 | 501 | mol : rdkit.Chem.rdchem.Mol
|
470 | 502 |
|
| 503 | + Returns |
| 504 | + ------- |
| 505 | + mol : rdkit.Chem.rdchem.Mol |
| 506 | + New molecule with charges eliminated where possible. |
| 507 | +
|
471 | 508 | """
|
472 |
| - for atom in mol.GetAtoms(): |
473 |
| - atom.SetFormalCharge(0) |
474 |
| - atom.SetNumRadicalElectrons(0) |
| 509 | + uncharger = MolStandardize.charge.Uncharger() |
| 510 | + out = uncharger.uncharge(mol) |
| 511 | + return out |
| 512 | + |
| 513 | + |
| 514 | +def discharge_and_deradicalize(mol): |
| 515 | + """Discharge and remove radicals. |
| 516 | +
|
| 517 | + Parameters |
| 518 | + ---------- |
| 519 | + mol : rdkit.Chem.rdchem.Mol |
| 520 | +
|
| 521 | + Returns |
| 522 | + ------- |
| 523 | + mol : rdkit.Chem.rdchem.Mol |
| 524 | + New molecule with charges eliminated where possible |
| 525 | + and radicals removed. |
| 526 | +
|
| 527 | + """ |
| 528 | + out = convert_radicals_to_hydrogen(mol) |
| 529 | + out = discharge_molecule(out) |
| 530 | + return out |
475 | 531 |
|
476 | 532 |
|
477 | 533 | def remove_exocyclic_attachments(mol):
|
|
0 commit comments