import matplotlib.pyplot as plt
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
import numpy as np
# 1. QED data
bin_centers = [0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95]
frequencies = [1.05, 1.74, 1.62, 2.87, 2.79, 3.56, 5.02, 7.16, 6.88, 7.04, 6.59, 7.81, 6.96, 7.56, 8.29, 7.44, 7.36, 5.70, 2.39, 0.16]
# 2. Gaussian Fit Parameters (Your data)
amplitude = 8.128
mean = 0.5674
sd = 0.2662
# Generate smooth X data for the curve
x_smooth = np.linspace(-0.1, 1.1, 300)
# Calculate Y using the Gaussian equation
y_smooth = amplitude * np.exp(-0.5 * ((x_smooth - mean) / sd)**2)
# 3. Define colors (QED Traffic Light)
colors = []
for x in bin_centers:
# Optimal Range (High Drug-likeness)
if x >= 0.6:
colors.append('green')
# Mid Range (Acceptable)
elif 0.35 <= x < 0.6:
colors.append('gold')
# Low Range (Complex/Difficult)
else:
colors.append('firebrick')
# 4. Create the chart
plt.figure(figsize=(7, 6))
# A. Draw Bars
plt.bar(bin_centers, frequencies, width=0.04, color=colors, edgecolor='black', alpha=0.7, label='Data Frequency')
# B. Draw Trend Line
plt.plot(x_smooth, y_smooth, color='darkorange', linewidth=2.5, label='Gaussian Fit')
# 5. Tags and Titles
plt.xlabel('QED (Quantitative Estimate of Drug-likeness)', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('QED Distribution', fontsize=14)
plt.xticks(np.arange(0, 1.05, 0.05), rotation=45, fontsize=9) # Eje X detallado
plt.xlim(-0.05, 1.05) # Limitar la vista al rango 0-1
# 6. 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='High Drug-likeness (≥ 0.6)'),
Patch(facecolor='gold', edgecolor='black', alpha=0.7, label='Intermediate (0.35 - 0.6)'),
Patch(facecolor='firebrick', edgecolor='black', alpha=0.7, label='Low Drug-likeness (< 0.35)')
]
plt.legend(handles=legend_elements, loc='upper left')
plt.grid(axis='y', linestyle='--', alpha=0.5)
plt.tight_layout()
plt.show()