Created
October 10, 2023 22:52
-
-
Save PlethoraChutney/2090ed915af1693fefb20ea6a684d262 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from cryosparc.tools import CryoSPARC\n", | |
"import json\n", | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"with open('/u/rposert/instance-info.json', 'r') as f:\n", | |
" instance_info = json.load(f)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Connection succeeded to CryoSPARC command_core at http://localhost:40002\n", | |
"Connection succeeded to CryoSPARC command_vis at http://localhost:40003\n", | |
"Connection succeeded to CryoSPARC command_rtp at http://localhost:40005\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"cs = CryoSPARC(**instance_info)\n", | |
"cs.test_connection()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"sym_exp_project_number = 'P294'\n", | |
"sym_exp_job_number = 'J31'\n", | |
"sym_exp_workspace_number = 'W2'\n", | |
"project = cs.find_project(sym_exp_project_number)\n", | |
"sym_exp = project.find_job(sym_exp_job_number)\n", | |
"expanded_particles = sym_exp.load_output('particles')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Only check 100 rows for speed. No symmetry group has >500 related positions\n", | |
"particles_df = pd.DataFrame(expanded_particles.take(range(500)).rows())\n", | |
"num_rotations = max(particles_df['sym_expand/idx'])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"This dataset was expanded using D7 symmetry, so has 14 symmetry-related particle rotations. The greatest index should be 13." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"13\n" | |
] | |
} | |
], | |
"source": [ | |
"print(num_rotations)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Now for each index, we create an external job with only that symmetry-related rotation." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for symmetry_index in range(num_rotations + 1):\n", | |
" sym_subset = expanded_particles.query({\n", | |
" 'sym_expand/idx': symmetry_index\n", | |
" })\n", | |
" \n", | |
" cs.save_external_result(\n", | |
" sym_exp_project_number,\n", | |
" sym_exp_workspace_number,\n", | |
" sym_subset,\n", | |
" type = 'particle',\n", | |
" slots = ['blob'],\n", | |
" passthrough = (sym_exp_job_number, 'particles'),\n", | |
" title = f\"Symmetry Index {symmetry_index}\"\n", | |
" )" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "cryosparc-tools", | |
"language": "python", | |
"name": "cryosparc-tools" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.10.13" | |
}, | |
"orig_nbformat": 4 | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment