Acidic pKa Distribution Dashboard

DrugBank database
MolPort database
Python script number 15 to build the frequency distribution graph of the Acidic_pKa parameter on DrugBank molecules.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Patch
from matplotlib.lines import Line2D

# 1. Bin Centers and % Frequency Data
bin_centers = [-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
frequencies = [0.0424, 0.0, 0.0849, 0.3397, 1.7834, 5.4777, 11.2102, 14.2251, 
               13.7580, 13.0786, 13.4183, 14.2675, 7.3461, 3.6943, 0.6369, 
               0.2123, 0.2972, 0.1274]

# 2. Gaussian Fit Parameters
amplitude = 15.56
mean = 6.736
sd = 2.658

# 3. Navigability Zones Classification (Colors)
# - Green (Optimal): 3 to 9 (Weak/moderate acids, good ionization balance)
# - Gold (Caution): 0-2 and 10-12 (Very strong or very weak acids)
# - Firebrick (Risk): < 0 and > 12 (Extremes complicating absorption/solubility)
colors = []
for b in bin_centers:
    if 3 <= b <= 9:
        colors.append('green')
    elif 0 <= b <= 2 or 10 <= b <= 12:
        colors.append('gold')
    else:
        colors.append('firebrick')

# 4. Create Figure
plt.figure(figsize=(7, 6))
plt.bar(bin_centers, frequencies, width=0.8, color=colors, edgecolor='black', alpha=0.7)

# 5. Generate Gaussian Curve
x_fit = np.linspace(min(bin_centers) - 1, max(bin_centers) + 1, 200)
# Formula: Amplitude * exp(-0.5 * ((x - Mean)/SD)^2)
y_fit = amplitude * np.exp(-0.5 * ((x_fit - mean) / sd) ** 2)
plt.plot(x_fit, y_fit, color='darkorange', lw=2.5)

# 6. Labels and Titles
plt.xlabel('Acidic pKa', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('Acidic pKa Distribution', fontsize=14)

# 7. Axes adjustments
plt.xticks(np.arange(-2, 16, 1))
plt.xlim(-2.5, 15.5)
plt.ylim(0, 18)

# 8.Custom Legend
legend_elements = [
    Line2D([0], [0], color='darkorange', lw=2.5, label=f'Fit (Mean={mean}, SD={sd})'),
    Patch(facecolor='green', edgecolor='black', alpha=0.7, label='Optimal (pKa 3 - 9)'),
    Patch(facecolor='gold', edgecolor='black', alpha=0.7, label='Caution (pKa 0-2, 10-12)'),
    Patch(facecolor='firebrick', edgecolor='black', alpha=0.7, label='Risk / Extremes (< 0, > 12)')
]

plt.legend(handles=legend_elements, loc='upper right')

# 9. Final Styling
plt.grid(axis='y', linestyle=':', alpha=0.7, zorder=0)
plt.tight_layout()

# Show plot
plt.show()