alidenewade commited on
Commit
3b2df55
Β·
verified Β·
1 Parent(s): 1dbaef1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -206,10 +206,10 @@ def calculate_molecular_properties(smiles_list: list):
206
 
207
  def assess_drug_likeness(df: pd.DataFrame):
208
  """
209
- Assesses drug-likeness based on Lipinski's Rule of Five.
210
  """
211
  if df.empty:
212
- return pd.DataFrame(), "Cannot assess drug-likeness: No properties data."
213
  df_copy = df.copy()
214
  df_copy['MW_OK'] = df_copy['MW'] <= 500
215
  df_copy['LogP_OK'] = df_copy['LogP'] <= 5
@@ -218,15 +218,15 @@ def assess_drug_likeness(df: pd.DataFrame):
218
  df_copy['Lipinski_Violations'] = (~df_copy[['MW_OK', 'LogP_OK', 'HBD_OK', 'HBA_OK']]).sum(axis=1)
219
  # Fixed: Use proper colored emojis instead of boolean values
220
  df_copy['Drug_Like'] = df_copy['Lipinski_Violations'].apply(lambda x: 'βœ… Yes' if x <= 1 else '❌ No')
221
- log = "βœ… Assessed drug-likeness using Lipinski's Rule of Five.\n"
222
- return df_copy, log
223
 
224
  def plot_properties_dashboard(df: pd.DataFrame):
225
  """
226
- Creates a 2x2 dashboard of molecular property visualizations.
227
  """
228
  if df.empty:
229
- return None, "Cannot plot: No analysis data."
230
 
231
  plt.style.use('dark_background')
232
  fig, axes = plt.subplots(2, 2, figsize=(12, 10))
@@ -237,15 +237,17 @@ def plot_properties_dashboard(df: pd.DataFrame):
237
  for ax in ax_row:
238
  ax.set_facecolor('none')
239
 
240
- axes[0,0].scatter(df['MW'], df['LogP'], c=df['Drug_Like'].map({True: 'green', False: 'red'}), s=80, alpha=0.7)
 
241
  axes[0,0].set_title('Molecular Weight vs LogP')
242
- axes[0,0].set_xlabel('Molecular Weight (Da)')
243
- axes[0,0].set_ylabel('LogP')
244
- axes[0,0].axvline(500, color='r', linestyle='--', alpha=0.6, label='MW < 500')
245
- axes[0,0].axhline(5, color='r', linestyle='--', alpha=0.6, label='LogP < 5')
246
  axes[0,0].legend()
247
 
248
- axes[0,1].scatter(df['HBD'], df['HBA'], c=df['Drug_Like'].map({True: 'green', False: 'red'}), s=80, alpha=0.7)
 
249
  axes[0,1].set_title('Hydrogen Bonding Properties')
250
  axes[0,1].set_xlabel('Hydrogen Bond Donors')
251
  axes[0,1].set_ylabel('Hydrogen Bond Acceptors')
@@ -253,20 +255,22 @@ def plot_properties_dashboard(df: pd.DataFrame):
253
  axes[0,1].axhline(10, color='r', linestyle='--', alpha=0.6, label='HBA < 10')
254
  axes[0,1].legend()
255
 
256
- axes[1,0].scatter(df['TPSA'], df['RotBonds'], c=df['Drug_Like'].map({True: 'green', False: 'red'}), s=80, alpha=0.7)
257
- axes[1,0].set_title('TPSA vs Flexibility')
258
- axes[1,0].set_xlabel('Topological Polar Surface Area (Γ…Β²)')
259
- axes[1,0].set_ylabel('Rotatable Bonds')
 
260
 
261
  drug_like_counts = df['Drug_Like'].value_counts()
262
- labels = ['Drug-like' if i else 'Non-drug-like' for i in drug_like_counts.index]
263
- colors = ['green' if i else 'red' for i in drug_like_counts.index]
 
264
  axes[1,1].pie(drug_like_counts.values, labels=labels, colors=colors, autopct='%1.1f%%', startangle=90)
265
  axes[1,1].set_title('Drug-likeness Distribution')
266
 
267
  plt.tight_layout(rect=[0, 0, 1, 0.96])
268
  return fig, "βœ… Generated properties dashboard."
269
-
270
  # ===== Phase 2 Functions =====
271
  def get_phase2_molecules():
272
  return {
 
206
 
207
  def assess_drug_likeness(df: pd.DataFrame):
208
  """
209
+ Assesses drug-likeness based on Lipinski's Rule of Five.
210
  """
211
  if df.empty:
212
+ return pd.DataFrame(), "Cannot assess drug-likeness: No properties data." [cite: 26]
213
  df_copy = df.copy()
214
  df_copy['MW_OK'] = df_copy['MW'] <= 500
215
  df_copy['LogP_OK'] = df_copy['LogP'] <= 5
 
218
  df_copy['Lipinski_Violations'] = (~df_copy[['MW_OK', 'LogP_OK', 'HBD_OK', 'HBA_OK']]).sum(axis=1)
219
  # Fixed: Use proper colored emojis instead of boolean values
220
  df_copy['Drug_Like'] = df_copy['Lipinski_Violations'].apply(lambda x: 'βœ… Yes' if x <= 1 else '❌ No')
221
+ log = "βœ… Assessed drug-likeness using Lipinski's Rule of Five.\n" [cite: 27]
222
+ return df_copy, log [cite: 27]
223
 
224
  def plot_properties_dashboard(df: pd.DataFrame):
225
  """
226
+ Creates a 2x2 dashboard of molecular property visualizations.
227
  """
228
  if df.empty:
229
+ return None, "Cannot plot: No analysis data." [cite: 28]
230
 
231
  plt.style.use('dark_background')
232
  fig, axes = plt.subplots(2, 2, figsize=(12, 10))
 
237
  for ax in ax_row:
238
  ax.set_facecolor('none')
239
 
240
+ # FIXED: Correctly map string values to colors
241
+ axes[0,0].scatter(df['MW'], df['LogP'], c=df['Drug_Like'].map({'βœ… Yes': 'green', '❌ No': 'red'}), s=80, alpha=0.7)
242
  axes[0,0].set_title('Molecular Weight vs LogP')
243
+ axes[0,0].set_xlabel('Molecular Weight (Da)') [cite: 29]
244
+ axes[0,0].set_ylabel('LogP') [cite: 29]
245
+ axes[0,0].axvline(500, color='r', linestyle='--', alpha=0.6, label='MW < 500') [cite: 29]
246
+ axes[0,0].axhline(5, color='r', linestyle='--', alpha=0.6, label='LogP < 5') [cite: 29]
247
  axes[0,0].legend()
248
 
249
+ # FIXED: Correctly map string values to colors
250
+ axes[0,1].scatter(df['HBD'], df['HBA'], c=df['Drug_Like'].map({'βœ… Yes': 'green', '❌ No': 'red'}), s=80, alpha=0.7)
251
  axes[0,1].set_title('Hydrogen Bonding Properties')
252
  axes[0,1].set_xlabel('Hydrogen Bond Donors')
253
  axes[0,1].set_ylabel('Hydrogen Bond Acceptors')
 
255
  axes[0,1].axhline(10, color='r', linestyle='--', alpha=0.6, label='HBA < 10')
256
  axes[0,1].legend()
257
 
258
+ # FIXED: Correctly map string values to colors
259
+ axes[1,0].scatter(df['TPSA'], df['RotBonds'], c=df['Drug_Like'].map({'βœ… Yes': 'green', '❌ No': 'red'}), s=80, alpha=0.7)
260
+ axes[1,0].set_title('TPSA vs Flexibility') [cite: 30]
261
+ axes[1,0].set_xlabel('Topological Polar Surface Area (Γ…Β²)') [cite: 30]
262
+ axes[1,0].set_ylabel('Rotatable Bonds') [cite: 30]
263
 
264
  drug_like_counts = df['Drug_Like'].value_counts()
265
+ # FIXED: Correctly map string values to labels and colors
266
+ labels = drug_like_counts.index
267
+ colors = ['green' if i == 'βœ… Yes' else 'red' for i in drug_like_counts.index]
268
  axes[1,1].pie(drug_like_counts.values, labels=labels, colors=colors, autopct='%1.1f%%', startangle=90)
269
  axes[1,1].set_title('Drug-likeness Distribution')
270
 
271
  plt.tight_layout(rect=[0, 0, 1, 0.96])
272
  return fig, "βœ… Generated properties dashboard."
273
+
274
  # ===== Phase 2 Functions =====
275
  def get_phase2_molecules():
276
  return {