insilichem / pychimera

Use UCSF Chimera Python API in a standard interpreter
http://pychimera.readthedocs.io
GNU Lesser General Public License v3.0
57 stars 10 forks source link

python 3.6 support feature request #10

Closed bionicles closed 6 years ago

bionicles commented 6 years ago

Hi,

Cool repo! It would be wonderful to be able to use this also with python 3!

Thanks for the contributions,

Bion @ Bit Pharma

jaimergp commented 6 years ago

I wish! Unfortunately, that is virtually impossible.

UCSF Chimera codebase is entirely Python 2.7. Providing Python 3k support would involve migrating that first, which is a huge task even with automated tools like six and 2to3.

UCSF ChimeraX (the successor) is Python 3 though. I don't know they are handling library reuse in that version, but I'd say that at least it will be easier. Who knows, maybe PyChimeraX is something we need? Anyway, ChimeraX is still a young project and cannot compete feature-wise with classic Chimera.

Sorry to disappoint!

PS: If you really need to use Chimera code in a Py3 project, maybe you can do something with their RESTServer interface.

bionicles commented 6 years ago

I'm agnostic to implementation -- I just have a big folder with subfolders for every human protein, and in each subfolder is every available .pdb for that protein. I would like to loop through the subfolders, nested-loop through the .pdbs, and generate publication-quality image and rotation movie for each one. that would be useful as training data for our AI system (maybe we can train a neural protein renderer using variational autoencoders, for example)

jrjhealey commented 6 years ago

That shouldn't be that difficult to do under any version. The chimera programmers guide has code for looking over folders and creating movies I think.

I have some logic in one of my files for looping over dirs and collecting PDBs:

https://github.com/jrjhealey/bioinfo-tools/blob/master/strucfit.py#L166-L169

You'll need to import the fnmatch module.

My suggestion would be to write a separate chunk of code that renders the movie as you want for a single protein, then you can call that code within something larger to handle all the looping and traversing.

I'd also create a preset for the publication style you want within chimera. See for example:

https://github.com/jrjhealey/chimera/blob/master/viz/print.preset.cmd

You can then have pychimera apply that preset during the code running fairly easily.

jaimergp commented 6 years ago

If you don't have any problems using Python 2.7, @jrjhealey's suggestions will work.

If you can't use Py2.7, write all the file traversing logic in Py3 and then run a separate Chimera to do the rendering. You have two options here:

A) Launch UCSF Chimera with the RESTServer running and use requests or something like that to communicate. The server will accept Chimera commands (not Python), which would be enough for your needs.

B) Run UCSF Chimera in a subprocess with --nogui mode. You can pass Python (2.7) scripts or Chimera commands to that instance via --script, which can accept arbitrary arguments. For example: chimera --nogui --script "render_movie.py structure.pdb".