import matplotlib.pyplot as plt
import matplotlib.patches as patches
import os
# Dictionary with continuous parameters for the Absorption profile
# Includes adjusted bounds to render proportional segments correctly
absorption_data = {
"logS": {"bounds": [-8, -6, -4, 0.5, 1, 3], "colors": ["#C14E4E", "#FFDF33", "#63C28D", "#FFDF33", "#C14E4E"]},
"logP": {"bounds": [-5, 0, 1, 3, 5, 10], "colors": ["#C14E4E", "#FFDF33", "#63C28D", "#FFDF33", "#C14E4E"]},
"pKa": {"bounds": [-5, 0, 3, 8, 11, 16], "colors": ["#C14E4E", "#FFDF33", "#63C28D", "#FFDF33", "#C14E4E"]},
# New manually added pKa rules
"Acidic_pKa": {"bounds": [-5, 0, 3, 9, 12, 16], "colors": ["#C14E4E", "#FFDF33", "#63C28D", "#FFDF33", "#C14E4E"]},
"Basic_pKa": {"bounds": [-5, 0, 3, 9, 11, 16], "colors": ["#C14E4E", "#FFDF33", "#63C28D", "#FFDF33", "#C14E4E"]},
# Caco-2 permeability models (Papp value and Probability model)
"Caco_2_Papp": {"bounds": [-10, -6, -5.15, 0], "colors": ["#C14E4E", "#FFDF33", "#63C28D"]},
"Caco_2_Prob": {"bounds": [0, 0.3, 0.7, 1.0], "colors": ["#C14E4E", "#FFDF33", "#63C28D"]},
# Intestinal absorption and cell models
"HIA": {"bounds": [0, 0.3, 0.7, 1.0], "colors": ["#C14E4E", "#FFDF33", "#63C28D"]},
"MDCK": {"bounds": [0, 0.4, 0.6, 1.0], "colors": ["#C14E4E", "#FFDF33", "#63C28D"]},
# Bioavailability parameters
"F50": {"bounds": [0, 0.3, 0.5, 1.0], "colors": ["#C14E4E", "#FFDF33", "#63C28D"]},
"F30": {"bounds": [0, 0.3, 0.5, 1.0], "colors": ["#C14E4E", "#FFDF33", "#63C28D"]},
"F20": {"bounds": [0, 0.3, 0.5, 1.0], "colors": ["#C14E4E", "#FFDF33", "#63C28D"]},
}
def create_absorption_bars():
"""
Generates and saves the proportional bar charts for the Absorption parameters.
"""
# Dimensions requested: 8 cm x 2 cm (converted to inches for matplotlib)
fig_width = 8 / 2.54
fig_height = 1.3 / 2.54
# Create a new directory specific for Figure 2 (Absorption)
output_dir = "ADMET_Absorption_Bars"
os.makedirs(output_dir, exist_ok=True)
# Background color matching the established paper style
bg_color = '#FFFFFF'
for param, info in absorption_data.items():
bounds = info["bounds"]
colors = info["colors"]
# Use numerical limits as labels
labels = [str(b) for b in bounds]
# Initialize figure
fig, ax = plt.subplots(figsize=(fig_width, fig_height))
fig.patch.set_facecolor(bg_color)
ax.set_facecolor(bg_color)
min_val = bounds[0]
max_val = bounds[-1]
# Draw each colored segment proportionally based on value distance
for i in range(len(colors)):
start = bounds[i]
width = bounds[i+1] - bounds[i]
rect = patches.Rectangle(
(start, 0), width, 1,
facecolor=colors[i], edgecolor='none'
)
ax.add_patch(rect)
# Axes scaling
ax.set_xlim(min_val, max_val)
ax.set_ylim(0, 1)
# X-axis setup (ticks and labels)
ax.set_xticks(bounds)
ax.set_xticklabels(labels, rotation=45, ha='right', rotation_mode='anchor', fontsize=9)
# Hide top, left and right spines (borders)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
# Offset the bottom spine slightly downwards so it does not overlap the bar
ax.spines['bottom'].set_position(('outward', 5))
ax.spines['bottom'].set_linewidth(1)
# Tick styling
ax.tick_params(axis='x', direction='out', length=4, width=1, colors='black')
# Completely hide the Y axis
ax.get_yaxis().set_visible(False)
# Parameter label below the X-axis
# Format the title slightly to make it look nicer (e.g., F50 -> F50 (%))
display_param = param.replace("_", " ")
if param in ["F50", "F30", "F20"]:
display_param += " (%)"
ax.set_xlabel(display_param, fontsize=11, labelpad=5, weight='bold')
# Adjust layout manually to prevent UserWarning about margins
plt.subplots_adjust(bottom=0.45)
# Save the figure
filename = os.path.join(output_dir, f"{param}_bar.png")
plt.savefig(filename, dpi=300, bbox_inches='tight', facecolor=fig.get_facecolor())
plt.close()
if __name__ == "__main__":
print("Starting generation of Absorption profile bars...")
create_absorption_bars()
print("Process completed successfully! Check the 'ADMET_Absorption_Bars' folder.")