Created
October 24, 2023 18:47
-
-
Save yuxuanzhuang/15a571338625b43c83a86683642de6ad 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": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# !pip install MDAnalysis\n", | |
"# !pip install MDAnalysisTests" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "5ce6d2ca-5f5f-4234-baee-5a4703e334e8", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import bpy\n", | |
"import numpy as np\n", | |
"import MolecularNodes as mn\n", | |
"import MDAnalysis as mda\n", | |
"\n", | |
"# !pip install MDAnalysisTests\n", | |
"from MDAnalysis.tests.datafiles import PSF, DCD\n", | |
"from MDAnalysis.analysis import distances" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "404a2610-f445-4efe-a173-12d2e004c234", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"bpy.context.scene.render.engine = 'CYCLES'\n", | |
"bpy.context.scene.cycles.device = \"GPU\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"u = mda.Universe(PSF, DCD)\n", | |
"\n", | |
"custom_selections = {'name_ca': 'name CA',\n", | |
" }" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# use log 6 for frame_mapping\n", | |
"frame_mapping = np.logspace(0, np.log(len(u.trajectory)) / np.log(100), 150, base=100, dtype=int) - 1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import matplotlib.pyplot as plt\n", | |
"plt.plot(frame_mapping, 'o')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "33f569b5", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"mda_session = mn.mda.MDAnalysisSession()\n", | |
"mda_session.show(u,\n", | |
" selection='protein',\n", | |
" name='protein',\n", | |
" custom_selections=custom_selections,\n", | |
" frame_mapping=frame_mapping,\n", | |
" subframe=3\n", | |
" )" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "51496469-d7d7-4072-908f-63bee7f3a264", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# add transformation\n", | |
"from MDAnalysis.transformations import PositionAverager\n", | |
"\n", | |
"transformation = PositionAverager(3, check_reset=True)\n", | |
"u.trajectory.add_transformations(transformation)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "0d3fe7ef-acf9-428a-bad4-df111afffc7b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"file_path = \"/Users/ugmhackathon/blender_and_mda.blend\"\n", | |
"\n", | |
"bpy.ops.wm.save_as_mainfile(filepath=file_path)\n", | |
"\n", | |
"# the .blend file can be opened by\n", | |
"# file_path = \"blender_and_mda.blend\"\n", | |
"# bpy.ops.wm.open_mainfile(filepath=file_path)\n", | |
"# mda_session = bpy.context.scene.mda_session" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "aa099c48", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# the .blend file can be opened by\n", | |
"import bpy\n", | |
"file_path = \"/Users/ugmhackathon/blender_and_mda.blend\"\n", | |
"bpy.ops.wm.open_mainfile(filepath=file_path)\n", | |
"mda_session = bpy.context.scene.mda_session" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "blender_3.6.2", | |
"language": "python", | |
"name": "blender_3.6.2" | |
}, | |
"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.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment