Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -298,6 +298,25 @@ def main():
|
|
| 298 |
help="Choose to upload your own files or use example data"
|
| 299 |
)
|
| 300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
uploaded_files = []
|
| 302 |
|
| 303 |
if data_source == "Upload Files":
|
|
@@ -429,6 +448,21 @@ def main():
|
|
| 429 |
if 'selections' not in st.session_state:
|
| 430 |
st.session_state['selections'] = {}
|
| 431 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
# Auto-initialize selections for all structures (exclude first and last residue)
|
| 433 |
if 'auto_initialized' not in st.session_state:
|
| 434 |
for struct in structure_data:
|
|
|
|
| 298 |
help="Choose to upload your own files or use example data"
|
| 299 |
)
|
| 300 |
|
| 301 |
+
# Clear session state when data source changes
|
| 302 |
+
if 'previous_data_source' not in st.session_state:
|
| 303 |
+
st.session_state['previous_data_source'] = data_source
|
| 304 |
+
|
| 305 |
+
if st.session_state['previous_data_source'] != data_source:
|
| 306 |
+
# Data source changed - clear all structure-related session state
|
| 307 |
+
if 'selections' in st.session_state:
|
| 308 |
+
del st.session_state['selections']
|
| 309 |
+
if 'auto_initialized' in st.session_state:
|
| 310 |
+
del st.session_state['auto_initialized']
|
| 311 |
+
if 'results' in st.session_state:
|
| 312 |
+
del st.session_state['results']
|
| 313 |
+
if 'structure_data' in st.session_state:
|
| 314 |
+
del st.session_state['structure_data']
|
| 315 |
+
if 'reference_name' in st.session_state:
|
| 316 |
+
del st.session_state['reference_name']
|
| 317 |
+
st.session_state['previous_data_source'] = data_source
|
| 318 |
+
st.sidebar.info("🔄 Switched data source - session cleared")
|
| 319 |
+
|
| 320 |
uploaded_files = []
|
| 321 |
|
| 322 |
if data_source == "Upload Files":
|
|
|
|
| 448 |
if 'selections' not in st.session_state:
|
| 449 |
st.session_state['selections'] = {}
|
| 450 |
|
| 451 |
+
# Track current file names to detect if files changed
|
| 452 |
+
current_file_names = set([s['name'] for s in structure_data])
|
| 453 |
+
if 'current_files' not in st.session_state:
|
| 454 |
+
st.session_state['current_files'] = current_file_names
|
| 455 |
+
|
| 456 |
+
# If file set changed, reset auto-initialization
|
| 457 |
+
if st.session_state['current_files'] != current_file_names:
|
| 458 |
+
st.session_state['current_files'] = current_file_names
|
| 459 |
+
if 'auto_initialized' in st.session_state:
|
| 460 |
+
del st.session_state['auto_initialized']
|
| 461 |
+
# Clear old selections that don't match current files
|
| 462 |
+
old_selections = set(st.session_state['selections'].keys())
|
| 463 |
+
for old_name in old_selections - current_file_names:
|
| 464 |
+
del st.session_state['selections'][old_name]
|
| 465 |
+
|
| 466 |
# Auto-initialize selections for all structures (exclude first and last residue)
|
| 467 |
if 'auto_initialized' not in st.session_state:
|
| 468 |
for struct in structure_data:
|