alidenewade commited on
Commit
f1e0ac0
·
verified ·
1 Parent(s): f437662

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -343,13 +343,24 @@ def visualize_molecule_2d_3d(smiles: str, name: str):
343
  svg_2d = svg_2d.replace('stroke:rgb(0,0,0)', 'stroke:rgb(255,255,255)')
344
  svg_2d = svg_2d.replace('fill:rgb(0,0,0)', 'fill:rgb(255,255,255)')
345
 
346
- # Fix text/font colors for atom labels
347
  svg_2d = svg_2d.replace('<text', '<text fill="white"')
348
  svg_2d = svg_2d.replace('fill="white" fill="white"', 'fill="white"') # Remove duplicates
349
  svg_2d = svg_2d.replace('color="black"', 'color="white"')
350
  svg_2d = svg_2d.replace('color:#000000', 'color:#FFFFFF')
351
  svg_2d = svg_2d.replace('color:#000', 'color:#FFF')
352
 
 
 
 
 
 
 
 
 
 
 
 
353
  # Embed the SVG within a div with a dark background for consistency
354
  svg_2d = f'<div style="background-color: #1C1C1C; padding: 10px; border-radius: 5px;">{svg_2d}</div>'
355
 
 
343
  svg_2d = svg_2d.replace('stroke:rgb(0,0,0)', 'stroke:rgb(255,255,255)')
344
  svg_2d = svg_2d.replace('fill:rgb(0,0,0)', 'fill:rgb(255,255,255)')
345
 
346
+ # Fix text/font colors for atom labels and stereochemistry labels
347
  svg_2d = svg_2d.replace('<text', '<text fill="white"')
348
  svg_2d = svg_2d.replace('fill="white" fill="white"', 'fill="white"') # Remove duplicates
349
  svg_2d = svg_2d.replace('color="black"', 'color="white"')
350
  svg_2d = svg_2d.replace('color:#000000', 'color:#FFFFFF')
351
  svg_2d = svg_2d.replace('color:#000', 'color:#FFF')
352
 
353
+ # Additional fixes for stereochemistry labels (R) and (S) that might be rendered differently
354
+ # These labels are often in separate text elements
355
+ import re
356
+ # Find all text elements and ensure they have white fill
357
+ svg_2d = re.sub(r'<text([^>]*?)(?:fill="[^"]*")?([^>]*?)>', r'<text\1 fill="white"\2>', svg_2d)
358
+ # Fix any remaining black text in style attributes
359
+ svg_2d = re.sub(r'style="([^"]*?)fill:\s*black([^"]*?)"', r'style="\1fill:white\2"', svg_2d)
360
+ svg_2d = re.sub(r'style="([^"]*?)fill:\s*#000000([^"]*?)"', r'style="\1fill:#FFFFFF\2"', svg_2d)
361
+ svg_2d = re.sub(r'style="([^"]*?)fill:\s*#000([^"]*?)"', r'style="\1fill:#FFF\2"', svg_2d)
362
+ svg_2d = re.sub(r'style="([^"]*?)fill:\s*rgb\(0,0,0\)([^"]*?)"', r'style="\1fill:rgb(255,255,255)\2"', svg_2d)
363
+
364
  # Embed the SVG within a div with a dark background for consistency
365
  svg_2d = f'<div style="background-color: #1C1C1C; padding: 10px; border-radius: 5px;">{svg_2d}</div>'
366