The “ground truth” for the workspace configuration is maintained in the cryoSPARC instance’s database, and should be copied automatically and frequently to a file workspaces.json
inside the project directory. If workspaces.json
is absent or outdated, the project’s import to another cryoSPARC instance will be faulty or will fail altogether.
We are currently working to make the creation and update of the workspaces.json
file more reliable.
Until the update is released, and only if problems with the automatic creation or update of workspaces.json
are encountered, one may force creation/update of workspaces.json
for that project using this script written by a member of our team:
import json
import os
import sys
import time
from bson import json_util
from cryosparc_compute import client
from pymongo import MongoClient
def export_workspaces(project_uid):
tic = time.time()
host = os.getenv('CRYOSPARC_MASTER_HOSTNAME')
command_port = int(os.getenv('CRYOSPARC_BASE_PORT')) + 2
db_port = int(os.getenv('CRYOSPARC_BASE_PORT')) + 1
cli = client.CommandClient(host, command_port)
mongo_url = f"mongodb://{host}:{db_port}"
db = MongoClient(mongo_url)['meteor']
project_dir = cli.get_project_dir_abs(project_uid)
all_workspaces = list(db.workspaces.find(
{'project_uid': project_uid, 'deleted': False}, {'_id': 0}))
print(f"Exporting {len(all_workspaces)} workspace(s) in {project_uid}...")
for workspace in all_workspaces:
if workspace['workspace_type'] == 'live':
if workspace['status'] in ['paused', 'completed']:
workspace['rtp_workers'] = {}
workspace['rtp_childs'] = []
export_workspace_path = "workspaces.json"
abs_export_workspace_path = os.path.join(
project_dir, export_workspace_path)
with open(abs_export_workspace_path, 'w') as openfile:
json.dump(all_workspaces, openfile, indent=4,
default=json_util.default)
print(f"Done exporting workspaces in {time.time()-tic:.3f}s")
if __name__ == '__main__':
assert len(sys.argv) > 1, "Must provide a project_uid to export."
export_workspaces(sys.argv[1])
This script should be saved to a file export_workspaces.py
. If there are problems with the creation/update of hypothetical project P1
, one can then force the update of workspaces.json
with this command:
cryosparcm call python export_workspaces.py P1
I recommend that this command be executed by the Linux user who runs the cryoSPARC instance as I otherwise foresee various file ownership/permissions problems.