Last active
March 15, 2024 19:13
-
-
Save matteoferla/94eb8e4f8441ddfb458bfc45722469b8 to your computer and use it in GitHub Desktop.
A small function to fix the pH protonation/deprotonation of RDKit Chem objects —fixes the charge of simple, i.e. biological cases. So amino acid is fine, but complex artificial drug won't be.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rdkit import mol | |
def set_to_neutral_pH(mol: Chem): | |
""" | |
Not great, but does the job. | |
* Protonates amines, but not aromatic bound amines. | |
* Deprotonates carboxylic acid, phosphoric acid and sulfuric acid, without ruining esters. | |
""" | |
protons_added = 0 | |
protons_removed = 0 | |
for indices in mol.GetSubstructMatches(Chem.MolFromSmarts('[N;D1]')): | |
atom = mol.GetAtomWithIdx(indices[0]) | |
if atom.GetNeighbors()[0].GetIsAromatic(): | |
continue # aniline | |
atom.SetFormalCharge(1) | |
protons_added += 1 | |
for indices in mol.GetSubstructMatches(Chem.MolFromSmarts('C(=O)[O;D1]')): | |
atom = mol.GetAtomWithIdx(indices[2]) | |
# benzoic acid pKa is low. | |
atom.SetFormalCharge(-1) | |
protons_removed += 1 | |
for indices in mol.GetSubstructMatches(Chem.MolFromSmarts('P(=O)[Oh1]')): | |
atom = mol.GetAtomWithIdx(indices[2]) | |
# benzoic acid pKa is low. | |
atom.SetFormalCharge(-1) | |
protons_removed += 1 | |
for indices in mol.GetSubstructMatches(Chem.MolFromSmarts('S(=O)(=O)[Oh1]')): | |
atom = mol.GetAtomWithIdx(indices[3]) | |
# benzoic acid pKa is low. | |
atom.SetFormalCharge(-1) | |
protons_removed += 1 | |
return (protons_added, protons_removed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment