Hydrogen Bond Donors (HBD) Distribution Dashboard

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

# 1. HBD (Hydrogen Bond Donors) data
bin_centers = [0, 1, 2, 3, 4, 5, 6, 7, 8]
frequencies = [21.73, 27.33, 23.85, 11.47, 8.07, 2.88, 2.24, 0.76, 1.68]

# 2. Gaussian Fit Parameters
amplitude = 26.66
mean = 1.041
sd = 1.747

# Generate smooth X data for the curve
x_smooth = np.linspace(-2, 9, 300)

# Calculate Y using the Gaussian equation
y_smooth = amplitude * np.exp(-0.5 * ((x_smooth - mean) / sd)**2)

# 3. Define colors (HBD traffic light - Lipinski <= 5)
colors = []
for x in bin_centers:
    # Optimal Range: 0 to 3 (The vast majority)
    if 0 <= x <= 3:
        colors.append('green')
    # Caution Range: 4 to 5 (Lipinski Limit)
    elif 4 <= x <= 5:
        colors.append('gold')
    # Risk Rank: > 5 (Violation)
    else:
        colors.append('firebrick')

# 4. Create the chart
plt.figure(figsize=(7, 6))

# A. Draw Bars
plt.bar(bin_centers, frequencies, width=0.8, color=colors, edgecolor='black', alpha=0.7, label='Data Frequency')

# B. Draw Trend Line
plt.plot(x_smooth, y_smooth, color='darkorange', linewidth=2, label='Gaussian Fit')

# 5. Tags and Titles
plt.xlabel('Hydrogen Bond Donors (HBD)', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('HBD Distribution', fontsize=14)

# Adjust X axis
plt.xticks(bin_centers) 
plt.xlim(-0.5, 8.5)

# 6. Custom Legend
legend_elements = [
    Line2D([0], [0], color='darkorange', lw=2, label=f'Fit (Mean={mean}, SD={sd})'),
    Patch(facecolor='green', edgecolor='black', alpha=0.7, label='Excellent Permeability (0 - 3)'),
    Patch(facecolor='gold', edgecolor='black', alpha=0.7, label='Lipinski Limit (4 - 5)'),
    Patch(facecolor='firebrick', edgecolor='black', alpha=0.7, label='Poor Permeability (> 5)')
]

plt.legend(handles=legend_elements, loc='upper right')
plt.grid(axis='y', linestyle='--', alpha=0.5)
plt.tight_layout()

plt.show()