kabudadada commited on
Commit
23f0e72
·
1 Parent(s): 05544d4

feat(esm mcp): save predictions to /data/predictions with fallback

Browse files
esm/mcp_output/mcp_plugin/mcp_service.py CHANGED
@@ -150,8 +150,20 @@ def predict_structure(sequence: str):
150
  pdb_io = io.StringIO(response.text)
151
  structure = parser.get_structure("esmfold_prediction", pdb_io)
152
 
153
- predictions_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "predictions")
154
- os.makedirs(predictions_dir, exist_ok=True)
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
157
  pdb_filename = f"prediction_{timestamp}.pdb"
 
150
  pdb_io = io.StringIO(response.text)
151
  structure = parser.get_structure("esmfold_prediction", pdb_io)
152
 
153
+ # Prefer persistent storage in Space (e.g., /data), fallback to local package dir
154
+ default_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "predictions")
155
+ preferred_dir = "/data/predictions"
156
+ predictions_dir = preferred_dir
157
+ try:
158
+ os.makedirs(predictions_dir, exist_ok=True)
159
+ # Test write permission with a temp touch
160
+ _probe_path = os.path.join(predictions_dir, ".write_probe")
161
+ with open(_probe_path, "w") as _probe:
162
+ _probe.write("ok")
163
+ os.remove(_probe_path)
164
+ except Exception:
165
+ predictions_dir = default_dir
166
+ os.makedirs(predictions_dir, exist_ok=True)
167
 
168
  timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
169
  pdb_filename = f"prediction_{timestamp}.pdb"