Nanny7 commited on
Commit
a0082eb
·
1 Parent(s): d2f237b

Improve plotly visualization sizing and rendering with CDN and proper styling

Browse files
Files changed (2) hide show
  1. app.py +19 -7
  2. force_rebuild.txt +1 -1
app.py CHANGED
@@ -292,21 +292,33 @@ def smiles_to_molecular_orbitals(smiles_input: str, name_input: str) -> str:
292
 
293
  fig.update_layout(
294
  title=f'{label} Orbital',
 
 
295
  scene=dict(
296
- xaxis_title='X',
297
- yaxis_title='Y',
298
- zaxis_title='Z'
299
- )
 
 
300
  )
301
 
302
- # Generate HTML
303
  import plotly.io as pio
304
- html_sections.append(f"<h3>{label}</h3>" + pio.to_html(fig, full_html=False))
 
 
 
 
 
 
305
 
306
  if not html_sections:
307
  return "<p>Could not prepare HOMO/LUMO visualizations.</p>"
308
 
309
- return "".join(html_sections)
 
 
310
  except Exception as exc: # pragma: no cover - runtime heavy
311
  return f"<p>Unable to compute molecular orbitals: {exc}</p>"
312
  finally:
 
292
 
293
  fig.update_layout(
294
  title=f'{label} Orbital',
295
+ width=800,
296
+ height=600,
297
  scene=dict(
298
+ xaxis_title='X (Å)',
299
+ yaxis_title='Y (Å)',
300
+ zaxis_title='Z (Å)',
301
+ aspectmode='data'
302
+ ),
303
+ margin=dict(l=0, r=0, t=40, b=0)
304
  )
305
 
306
+ # Generate HTML with config
307
  import plotly.io as pio
308
+ config = {
309
+ 'displayModeBar': True,
310
+ 'displaylogo': False,
311
+ 'modeBarButtonsToRemove': ['toImage']
312
+ }
313
+ plot_html = pio.to_html(fig, full_html=False, include_plotlyjs='cdn', config=config)
314
+ html_sections.append(f"<div style='margin: 20px 0;'><h3>{label}</h3>{plot_html}</div>")
315
 
316
  if not html_sections:
317
  return "<p>Could not prepare HOMO/LUMO visualizations.</p>"
318
 
319
+ # Wrap in a container div with proper styling
320
+ result_html = "<div style='width: 100%; max-width: 1200px;'>" + "".join(html_sections) + "</div>"
321
+ return result_html
322
  except Exception as exc: # pragma: no cover - runtime heavy
323
  return f"<p>Unable to compute molecular orbitals: {exc}</p>"
324
  finally:
force_rebuild.txt CHANGED
@@ -1,2 +1,2 @@
1
  # Force rebuild
2
- 2025-11-08 v7
 
1
  # Force rebuild
2
+ 2025-11-08 v8