
Hi Artie, One thing you could do to upgrade your current workflow is use the --system-site-packages flag when you create your virtual environment, which would give your new virtual environment access to the packages in ChimeraX. Alternatively, if you’re willing you could beta test the ChimeraX library release on PyPi. You can find it at https://pypi.org/project/ChimeraX/ The version is the release version shifted over 1 space. (1.71 —> 0.1.71) to indicate that it is a separate, alpha release. It incorporates the ChimeraX 1.71 codebase with all tools and GUI functionality removed. We would love for you to give it a try and give us feedback on its usefulness, ergonomics, and whether there is anything you need that is improperly dependent on GUI code and so gives a traceback when you try to import it. — Zach
On May 1, 2024, at 17:38, Artie Kushner via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Hi, I apologize sincerely since I imagine this comes up often on the mailing list.
I'm basically wondering if it's possible to import just the `core` functionality from a chimerax installation into a custom python environment and bypass the GUI and the binary completely. Example: I don't think it matters whether it's linux, mac, or source build, but let's say i installed a clean chimerax via my package manager (`yay i chimerax`). It's at `/opt/chimerax` and looks like this:
(venv) ᢹ ritual.rtviii[ /opt/chimerax ] ls -la total 24 drwxr-xr-x 6 root root 4096 May 1 16:08 . drwxr-xr-x 10 root root 4096 May 1 16:58 .. drwxr-xr-x 4 root root 4096 May 1 16:51 bin drwxr-xr-x 8 root root 4096 May 1 16:51 include drwxr-xr-x 4 root root 4096 May 1 16:51 lib drwxr-xr-x 6 root root 4096 May 1 16:51 share
If I launch `chimerax` at the command line, i get a functional GUI etc. It works. I create a fresh custom `virtualenv` with the same python that this chimerax ships:
virtualenv --python='/opt/chimerax/bin/python3.11' venv
Then i do something ugly in the name of science: i symlink the chimerax folder from the installation into my virtualenv:
ln -s /opt/chimerax/lib/python3.11/site-packages/chimerax /home/rtviii/dev/try_chimerax/venv/lib/python3.11/site-packages/chimerax i also tried: for P in $(ls /opt/chimerax/lib/python3.11/site-packages/); do ln -s /opt/chimerax/lib/python3.11/site-packages/$P /home/rtviii/dev/try_chimerax/venv/lib/python3.11/site-packages/$P; done
This enables me to import chimerax modules into my python code that uses this virtualenv: ```/home/rtviii/dev/try_chimerax/test.py from chimerax.core.commands import run from chimerax.core.session import Session import chimerax.mmcif.mmcif as mmcif
s = Session("Hi") print(s) run(s,"open 1ubq.cif") ``` However, this is where i'm struggling a little to use any actual functionality (especially interested in cutting, merging structures and operations treating density maps and mmcif structures) because the Session wouldn't initialize well:
``` <chimerax.core.session.Session object at 0x70472673b5d0> NOTE: Traceback (most recent call last): File "/home/rtviii/dev/try_chimerax/test.py", line 9, in <module> run(s,"open 1ubq.cif") File "/home/rtviii/dev/try_chimerax/venv/lib/python3.11/site- packages/chimerax/core/commands/run.py", line 49, in run results = command.run(text, log=log, return_json=return_json) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/rtviii/dev/try_chimerax/venv/lib/python3.11/site-packages/chimerax/core/commands/cli.py", line 2849, in run _compute_available_commands(session) File "/home/rtviii/dev/try_chimerax/venv/lib/python3.11/site-packages/chimerax/core/commands/cli.py", line 2431, in _compute_available_commands ts.register_available_commands(session.logger) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute'register_available_commands' BUG: AttributeError: 'NoneType' object has no attribute'register_available_commands' File "/home/rtviii/dev/try_chimerax/venv/lib/python3.11/site- packages/chimerax/core/commands/cli.py", line 2431, in _compute_available_commands ts.register_available_commands(session.logger) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _See log for complete Python traceback._ ```
I had some success with a similar approach in PyMol in this regard, but can't quite get this to work in ChimeraX. I really appreciate any advice for achieving this scripting decoupling from GUI/binary if that's possible at all:
- either how to "pull in" ChimeraX library code properly (i realize mine is an ugly hack) - how to use library code otherwise - how to bypass the dependence of a lot of commands on the Session object or how to initialize it outside of the gui properly: an example of how to use selections to open a local density map and perform a smoothing, for example.
Kindest regards and huge thanks for the monumental application.
Artem, UBC Vancouver _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/