andreamena commited on
Commit
42a3ea6
·
verified ·
1 Parent(s): 93a84e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -19
app.py CHANGED
@@ -95,21 +95,36 @@ def batch_predict(file_obj):
95
  def generate_and_screen(num_to_gen):
96
  candidates = []
97
  for _ in range(num_to_gen):
98
- # ... (keep your generation and prediction code the same) ...
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
  if mol:
101
- # 1. Check Benchmarks
102
- # Pass Yield Strength Target (>0.075 GPa) [cite: 236]
 
 
 
 
 
 
103
  pass_strength = strength > 0.075
104
- # Pass SA Score Target (<5.0) [cite: 224]
105
  pass_sa = sa_val < 5.0
106
- # Pass Degradability Target (>0.303) [cite: 231, 236]
107
  pass_deg = deg_val > 0.303
108
 
109
- # 2. Calculate Number of Passes
110
  num_passes = sum([pass_strength, pass_sa, pass_deg])
111
 
112
- # 3. Assign 3-Category Classification
113
  if num_passes == 3:
114
  status = "Excellent"
115
  elif num_passes == 2:
@@ -170,26 +185,23 @@ with gr.Blocks(title="PolymerDesignAI") as demo:
170
  with gr.Tab("Autonomous Design"):
171
  gr.Markdown("### Stage C & D: Integrated Generation + Screening")
172
 
173
- gr.Markdown("""
174
- **Goal:** Discover novel polymers that balance High Strength, Ease of Synthesis, and Environmental Impact.
175
-
176
- ---
177
 
178
  ### 📊 Classification Logic
179
- Candidates are filtered based on the triple-objective criteria outlined in the **RLPolyG** paper
180
-
181
  | Category | Criteria |
182
  | :--- | :--- |
183
- | **✅ Excellent** | **Passes ALL 3 benchmarks**: High Strength, Easy to Make, and Eco-Friendly. |
184
- | **⚠️ Review** | **Passes 2 benchmarks**: Fails exactly one criteria. Requires expert adjustment. |
185
- | **❌ Bad** | **Passes 1 or 0 benchmarks**: Fails two or more criteria. High risk of failure. |
186
 
187
  ---
188
 
189
  ### 🧪 Targets & Benchmarks
190
- * **Strength Target**: $\sigma_y > 0.075$ GPa (High performance)
191
- * **SA Score Target**: $< 5.0$ (Synthetically accessible)
192
- * **Degradability Target**: $> 0.303$ (Non-persistent in environment)
193
 
194
  **Degradability Interpretation:**
195
  * **Undegradable**: $\leq 0.303$
 
95
  def generate_and_screen(num_to_gen):
96
  candidates = []
97
  for _ in range(num_to_gen):
98
+ # 1. Generation
99
+ input_seq = torch.tensor([[char_to_int['<SOS>']]])
100
+ h, generated = None, ""
101
+ for _ in range(100):
102
+ output, h = gen_model(input_seq, h)
103
+ probs = F.softmax(output[0, -1], dim=0)
104
+ idx = torch.multinomial(probs, 1).item()
105
+ char = int_to_char[idx]
106
+ if char == '<EOS>': break
107
+ generated += char
108
+ input_seq = torch.tensor([[idx]])
109
+
110
+ # --- FIX: Create the 'mol' object here before checking 'if mol:' ---
111
+ mol = Chem.MolFromSmiles(generated.replace('*', 'C'))
112
 
113
  if mol:
114
+ feats = get_expanded_features(generated)
115
+ strength_log = judge.predict(feats.reshape(1, -1))
116
+ strength = np.expm1(strength_log)[0]
117
+
118
+ sa_val = sascorer.calculateScore(mol) if sascorer else 5.0
119
+ deg_val = degradability_model.predict(feats.reshape(1, -1))[0] if degradability_model else 0.5
120
+
121
+ # Check Benchmarks
122
  pass_strength = strength > 0.075
 
123
  pass_sa = sa_val < 5.0
 
124
  pass_deg = deg_val > 0.303
125
 
 
126
  num_passes = sum([pass_strength, pass_sa, pass_deg])
127
 
 
128
  if num_passes == 3:
129
  status = "Excellent"
130
  elif num_passes == 2:
 
185
  with gr.Tab("Autonomous Design"):
186
  gr.Markdown("### Stage C & D: Integrated Generation + Screening")
187
 
188
+ # Adding 'r' before the triple quotes fixes the LaTeX display issues
189
+ gr.Markdown(r"""
190
+ **Goal:** Discover novel polymers that balance High Strength, Ease of Synthesis, and Environmental Impact.
 
191
 
192
  ### 📊 Classification Logic
 
 
193
  | Category | Criteria |
194
  | :--- | :--- |
195
+ | **✅ Excellent** | **Passes ALL 3 benchmarks**: High Strength, Easy to Make, and Eco-Friendly. |
196
+ | **⚠️ Review** | **Passes 2 benchmarks**: Fails exactly one criteria. |
197
+ | **❌ Bad** | **Passes 1 or 0 benchmarks**: Fails two or more criteria. |
198
 
199
  ---
200
 
201
  ### 🧪 Targets & Benchmarks
202
+ * **Strength Target**: $\sigma_y > 0.075$ GPa
203
+ * **SA Score Target**: $< 5.0$
204
+ * **Degradability Target**: $> 0.303$
205
 
206
  **Degradability Interpretation:**
207
  * **Undegradable**: $\leq 0.303$