import matplotlib.pyplot as plt
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
import numpy as np
# 1. HBA (Hydrogen Bond Acceptors) data
bin_centers = list(range(0, 17))
frequencies = [
4.583, 5.808, 14.737, 15.448, 15.251, 10.865, 11.023, 5.531, 5.334, 3.003,
2.094, 1.343, 1.896, 0.711, 0.988, 0.672, 0.711
]
# 2. Gaussian Fit Parameters
amplitude = 15.01
mean = 3.751
sd = 2.594
# Generate smooth X data for the curve
x_smooth = np.linspace(-1, 17, 300)
# Calculate Y using the Gaussian equation
y_smooth = amplitude * np.exp(-0.5 * ((x_smooth - mean) / sd)**2)
# 3. Define colors (HBA Traffic Light - Lipinski Rule)
colors = []
for x in bin_centers:
# Optimal Range: 1 to 10 (Lipinski meets <= 10)
if 1 <= x <= 10:
colors.append('green')
# Caution Range: 0 (Very Nonpolar) or 11-12 (Upper Limit)
elif (x == 0) or (11 <= x <= 12):
colors.append('gold')
# Risk Range: > 12 (Clear 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 Acceptors (HBA)', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('HBA Distribution', fontsize=14)
# Adjust X axis
plt.xticks(bin_centers)
plt.xlim(-1, 17)
# 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='Lipinski Compliant (1 - 10)'),
Patch(facecolor='gold', edgecolor='black', alpha=0.7, label='Caution (0, 11-12)'),
Patch(facecolor='firebrick', edgecolor='black', alpha=0.7, label='Violation / High Polarity (> 12)')
]
plt.legend(handles=legend_elements, loc='upper right')
plt.grid(axis='y', linestyle='--', alpha=0.5)
plt.tight_layout()
plt.show()