PyChimera: use UCSF Chimera modules in any Python 2.7 project

PyChimera: use UCSF Chimera modules in any Python 2.7 project Abstract Motivation UCSF Chimera is a powerful visualization tool remarkably present in the computational chemistry and structural biology communities. Built on a C++ core wrapped under a Python 2.7 environment, one could expect to easily import UCSF Chimera’s arsenal of resources in custom scripts or software projects. Nonetheless, this is not readily possible if the script is not executed within UCSF Chimera due to the isolation of the platform. UCSF ChimeraX, successor to the original Chimera, partially solves the problem but yet major upgrades need to be undergone so that this updated version can offer all UCSF Chimera features. Results PyChimera has been developed to overcome these limitations and provide access to the UCSF Chimera codebase from any Python 2.7 interpreter, including interactive programming with tools like IPython and Jupyter Notebooks, making it easier to use with additional third-party software. Availability and implementation PyChimera is LGPL-licensed and available at https://github.com/insilichem/pychimera. Contact jaime.rodriguezguerra@uab.cat or jeandidier.marechal@uab.cat Supplementary information Supplementary data are available at Bioinformatics online. 1 Introduction Python is one of the most used programming languages in science due to its readability, smooth learning curve and excellent availability of packages dedicated to data analysis and numeric computing. A lot of scientific software is being either developed in, converted to or wrapped under Python, most of the time as open-source projects, which leads to higher reproducibility and collaborative efforts. This is also true in molecular modeling, either for structural biology, computational chemistry or anything in between like visualization tools [PyMol (Sanner, 1999)], protein-ligand docking software [AutoDock Vina (Trott and Olson, 2010)], molecular dynamics simulations [OpenMM (Eastman et al., 2013)] or trajectory analysis [MDTraj (McGibbon et al., 2015)]. UCSF Chimera (Pettersen et al., 2004) is one peculiar project that falls within several categories at the same time: a powerful visualization engine that also doubles as a versatile molecular modeling toolkit thanks to advanced features like multiformat input parsers and output writers, hydrogen bonds detection, analysis of steric clashes or hydrophobic interactions, construction of peptides, energy minimization or trajectory analysis. UCSF Chimera is written in both C++ and Python and distributed as a stand-alone application that ships its own versions of Python and other packages to achieve a robust, fail-proof behavior in every major platform. Although this ensures that every user will get the same experience no matter their system environment, it also creates a barrier for those who want to call UCSF Chimera functions from their Python scripts by forcing the user to run it from within UCSF Chimera’s process. In bigger projects, it can also slow down the development process. For example, configuring an Integrated Development Environment or text editor can represent a real tour de force if you want to use autocompletion, automated testing or inline documentation. In addition, most modern Python development tools are not distributed by default with UCSF Chimera, and installing them with the proper version can be struggling. For example, latest UCSF Chimera version (1.12) ships its own version of NumPy (van der Walt et al., 2011), but is not updated (v1.7.2, released in 2013) and causes compatibility problems with modern data analysis packages like Scipy. Here, we present PyChimera, a Python project built to evade the limitations of UCSF Chimera’s isolated framework and use it under any Python 2.7 interpreter. This contributes to increasing the position of UCSF Chimera in the Python scientific ecosystem and should allow the rapid development of new applications and proof-of-concept ideas for molecular modeling tools. 2 Materials and methods UCSF Chimera isolation works by modifying several environment variables with its own pre-launcher. After patching the environment, the pre-launcher will find and use UCSF Chimera’s own Python interpreter, neglecting the existence of any other system distribution, to run the initialization code. PyChimera code is written in Python to mimic this patch-and-launch scheme. First, PyChimera will try to find the installation path of UCSF Chimera with several alternative strategies: (1) Check if the environment variable $CHIMERADIR has been defined by the user, (2) try to locate the chimera binary in the directories listed under $PATH and (3) search the default locations for the platform in use for directories that contain the name ‘chimera’ and find the chimera executable under the bin subdirectory. After finding a valid UCSF Chimera installation, PyChimera will modify the library paths and other environment variables to include both the modifications that the initialization code is expecting, and the ones given by the current user execution environment. This strategy allows to install new packages in a virtual environment and then use them together with UCSF Chimera’s own packages in any software project. To make the changes available to the running Python interpreter, the new environment is injected through an os.execve call that will restart the process in situ. After the restart, UCSF Chimera initialization routines (chimeraInit.init) can be executed normally. 3 Results PyChimera is distributed as a command line application with support for major Linux distributions (tested on Ubuntu 14.04, CentOS 6, Arch Linux), Mac OS X (tested on 10.11 and 10.12), and Windows 7+, with UCSF Chimera 1.10+. For PyChimera to work, UCSF Chimera must be installed before-hand. The PyChimera installation itself can be performed with the same command in the three platforms: pip install pychimera. The only drawback is that, since UCSF Chimera uses Python 2.7, PyChimera will only run from a Python 2.7 interpreter. Virtual or conda environments are recommended to solve compatibility problems. The installation procedure is detailed in the accompanying Supplementary Material. 3.1 Usage Running pychimera in the terminal will launch system’s Python interpreter with the ability to import any UCSF Chimera module. This command also supports some of the standard interpreter flags, like -m to run a module or -c to run a single line of code. A --gui flag is also available, which will launch a patched UCSF Chimera with graphic interface. This can be useful to use extensions that depend on third-party packages not available in the UCSF Chimera distribution. PyChimera can also be used to run normal Python scripts directly, especially if they rely on any UCSF Chimera module. The syntax is straightforward: pychimera script.py. 3.1.1 IPython and Jupyter notebook integrations By enhancing the native Python interpreter with additional interactive features, IPython (Perez and Granger, 2007) has obtained a golden place in development environments. Its success also led to the creation of IPython Notebooks, later renamed as Jupyter Notebooks, which wrap a web-based interface around a running Python process, allowing the display of dynamic content (plots, images, animations or even molecular visualizations) with JavaScript. To take advantage of these useful resources, two subcommands are included: pychimera ipython and pychimera notebook. The first subcommand will launch a patched IPython instance, while the second will launch a Jupyter server that will pre-populate notebooks with a cell that gives support for all UCSF Chimera modules and visualization tools not originally available in UCSF Chimera: (1) a wrapper around NGL Viewer (Rose and Hildebrand, 2015) to preview molecules loaded with the UCSF Chimera parsers, and (2) a WebGL 3D model of the canvas. USCF Chimera commands can also be run directly with the call %chimera_run. PyChimera is opening new horizons for the development of projects that benefit from UCSF Chimera as a dependency. Combined with a package manager like pip or conda, using UCSF Chimera along the scientific Python stack is no longer a problem. In fact, PyChimera was born during the development of GaudiMM (Rodríguez-Guerra Pedregal et al., 2017) and we can only hope that this small but powerful tool will also help other researchers to use UCSF Chimera in custom scripts or applications. Acknowledgements The authors want to thank the UCSF Chimera’s team, and more particularly Greg Couch, for the ideas and inputs on the chimera-dev mailing list. Funding The authors are thankful for the support given by the Spanish MINECO (project CTQ2014-54071-P) and the Generalitat de Catalunya (project 2014SGR989). Support of COST Action CM1306 is kindly acknowledged. Research grant to JRGP (Generalitat de Catalunya, 2017FI_B2_00168) is acknowledged. Conflict of Interest: none declared. References Eastman P. et al.   ( 2013) OpenMM 4: a reusable, extensible, hardware independent library for high performance molecular simulation. J. Chem. Theory Comput ., 9, 461– 469. Google Scholar CrossRef Search ADS PubMed  McGibbon R.T. et al.   ( 2015) MDTraj: a modern open library for the analysis of molecular dynamics trajectories. Biophys. J ., 109, 1528– 1532. Google Scholar CrossRef Search ADS PubMed  Perez F., Granger B.E. ( 2007) IPython: a system for interactive scientific computing. Comput. Sci. Eng ., 9, 21– 29. Google Scholar CrossRef Search ADS   Pettersen E.F. et al.   ( 2004) UCSF Chimera–a visualization system for exploratory research and analysis. J. Comput. Chem ., 25, 1605– 1612. Google Scholar CrossRef Search ADS PubMed  Rodríguez-Guerra Pedregal J. et al.   ( 2017) GaudiMM: a modular multi-objective platform for molecular modeling. J. Comput. Chem ., 38, 2118– 2126. Google Scholar CrossRef Search ADS PubMed  Rose A.S., Hildebrand P.W. ( 2015) NGL Viewer: a web application for molecular visualization. Nucleic Acids Res ., 43, W576– W579. Google Scholar CrossRef Search ADS PubMed  Sanner M.F. ( 1999) Python: a programming language for software integration and development. J. Mol. Graph. Model ., 17, 57– 61. Google Scholar PubMed  Trott O., Olson A.J. ( 2010) AutoDock Vina: improving the speed and accuracy of docking with a new scoring function, efficient optimization, and multithreading. J. Comput. Chem ., 31, 455– 461. Google Scholar PubMed  van der Walt S. et al.   ( 2011) The NumPy array: a structure for efficient numerical computation. Comput. Sci. Eng ., 13, 22– 30. Google Scholar CrossRef Search ADS   © The Author(s) 2018. Published by Oxford University Press. All rights reserved. For Permissions, please e-mail: journals.permissions@oup.com This article is published and distributed under the terms of the Oxford University Press, Standard Journals Publication Model (https://academic.oup.com/journals/pages/about_us/legal/notices) http://www.deepdyve.com/assets/images/DeepDyve-Logo-lg.png Bioinformatics Oxford University Press

PyChimera: use UCSF Chimera modules in any Python 2.7 project

Loading next page...
 
/lp/ou_press/pychimera-use-ucsf-chimera-modules-in-any-python-2-7-project-jZ9a4dPrVg
Publisher
Oxford University Press
Copyright
© The Author(s) 2018. Published by Oxford University Press. All rights reserved. For Permissions, please e-mail: journals.permissions@oup.com
ISSN
1367-4803
eISSN
1460-2059
D.O.I.
10.1093/bioinformatics/bty021
Publisher site
See Article on Publisher Site

Abstract

Abstract Motivation UCSF Chimera is a powerful visualization tool remarkably present in the computational chemistry and structural biology communities. Built on a C++ core wrapped under a Python 2.7 environment, one could expect to easily import UCSF Chimera’s arsenal of resources in custom scripts or software projects. Nonetheless, this is not readily possible if the script is not executed within UCSF Chimera due to the isolation of the platform. UCSF ChimeraX, successor to the original Chimera, partially solves the problem but yet major upgrades need to be undergone so that this updated version can offer all UCSF Chimera features. Results PyChimera has been developed to overcome these limitations and provide access to the UCSF Chimera codebase from any Python 2.7 interpreter, including interactive programming with tools like IPython and Jupyter Notebooks, making it easier to use with additional third-party software. Availability and implementation PyChimera is LGPL-licensed and available at https://github.com/insilichem/pychimera. Contact jaime.rodriguezguerra@uab.cat or jeandidier.marechal@uab.cat Supplementary information Supplementary data are available at Bioinformatics online. 1 Introduction Python is one of the most used programming languages in science due to its readability, smooth learning curve and excellent availability of packages dedicated to data analysis and numeric computing. A lot of scientific software is being either developed in, converted to or wrapped under Python, most of the time as open-source projects, which leads to higher reproducibility and collaborative efforts. This is also true in molecular modeling, either for structural biology, computational chemistry or anything in between like visualization tools [PyMol (Sanner, 1999)], protein-ligand docking software [AutoDock Vina (Trott and Olson, 2010)], molecular dynamics simulations [OpenMM (Eastman et al., 2013)] or trajectory analysis [MDTraj (McGibbon et al., 2015)]. UCSF Chimera (Pettersen et al., 2004) is one peculiar project that falls within several categories at the same time: a powerful visualization engine that also doubles as a versatile molecular modeling toolkit thanks to advanced features like multiformat input parsers and output writers, hydrogen bonds detection, analysis of steric clashes or hydrophobic interactions, construction of peptides, energy minimization or trajectory analysis. UCSF Chimera is written in both C++ and Python and distributed as a stand-alone application that ships its own versions of Python and other packages to achieve a robust, fail-proof behavior in every major platform. Although this ensures that every user will get the same experience no matter their system environment, it also creates a barrier for those who want to call UCSF Chimera functions from their Python scripts by forcing the user to run it from within UCSF Chimera’s process. In bigger projects, it can also slow down the development process. For example, configuring an Integrated Development Environment or text editor can represent a real tour de force if you want to use autocompletion, automated testing or inline documentation. In addition, most modern Python development tools are not distributed by default with UCSF Chimera, and installing them with the proper version can be struggling. For example, latest UCSF Chimera version (1.12) ships its own version of NumPy (van der Walt et al., 2011), but is not updated (v1.7.2, released in 2013) and causes compatibility problems with modern data analysis packages like Scipy. Here, we present PyChimera, a Python project built to evade the limitations of UCSF Chimera’s isolated framework and use it under any Python 2.7 interpreter. This contributes to increasing the position of UCSF Chimera in the Python scientific ecosystem and should allow the rapid development of new applications and proof-of-concept ideas for molecular modeling tools. 2 Materials and methods UCSF Chimera isolation works by modifying several environment variables with its own pre-launcher. After patching the environment, the pre-launcher will find and use UCSF Chimera’s own Python interpreter, neglecting the existence of any other system distribution, to run the initialization code. PyChimera code is written in Python to mimic this patch-and-launch scheme. First, PyChimera will try to find the installation path of UCSF Chimera with several alternative strategies: (1) Check if the environment variable $CHIMERADIR has been defined by the user, (2) try to locate the chimera binary in the directories listed under $PATH and (3) search the default locations for the platform in use for directories that contain the name ‘chimera’ and find the chimera executable under the bin subdirectory. After finding a valid UCSF Chimera installation, PyChimera will modify the library paths and other environment variables to include both the modifications that the initialization code is expecting, and the ones given by the current user execution environment. This strategy allows to install new packages in a virtual environment and then use them together with UCSF Chimera’s own packages in any software project. To make the changes available to the running Python interpreter, the new environment is injected through an os.execve call that will restart the process in situ. After the restart, UCSF Chimera initialization routines (chimeraInit.init) can be executed normally. 3 Results PyChimera is distributed as a command line application with support for major Linux distributions (tested on Ubuntu 14.04, CentOS 6, Arch Linux), Mac OS X (tested on 10.11 and 10.12), and Windows 7+, with UCSF Chimera 1.10+. For PyChimera to work, UCSF Chimera must be installed before-hand. The PyChimera installation itself can be performed with the same command in the three platforms: pip install pychimera. The only drawback is that, since UCSF Chimera uses Python 2.7, PyChimera will only run from a Python 2.7 interpreter. Virtual or conda environments are recommended to solve compatibility problems. The installation procedure is detailed in the accompanying Supplementary Material. 3.1 Usage Running pychimera in the terminal will launch system’s Python interpreter with the ability to import any UCSF Chimera module. This command also supports some of the standard interpreter flags, like -m to run a module or -c to run a single line of code. A --gui flag is also available, which will launch a patched UCSF Chimera with graphic interface. This can be useful to use extensions that depend on third-party packages not available in the UCSF Chimera distribution. PyChimera can also be used to run normal Python scripts directly, especially if they rely on any UCSF Chimera module. The syntax is straightforward: pychimera script.py. 3.1.1 IPython and Jupyter notebook integrations By enhancing the native Python interpreter with additional interactive features, IPython (Perez and Granger, 2007) has obtained a golden place in development environments. Its success also led to the creation of IPython Notebooks, later renamed as Jupyter Notebooks, which wrap a web-based interface around a running Python process, allowing the display of dynamic content (plots, images, animations or even molecular visualizations) with JavaScript. To take advantage of these useful resources, two subcommands are included: pychimera ipython and pychimera notebook. The first subcommand will launch a patched IPython instance, while the second will launch a Jupyter server that will pre-populate notebooks with a cell that gives support for all UCSF Chimera modules and visualization tools not originally available in UCSF Chimera: (1) a wrapper around NGL Viewer (Rose and Hildebrand, 2015) to preview molecules loaded with the UCSF Chimera parsers, and (2) a WebGL 3D model of the canvas. USCF Chimera commands can also be run directly with the call %chimera_run. PyChimera is opening new horizons for the development of projects that benefit from UCSF Chimera as a dependency. Combined with a package manager like pip or conda, using UCSF Chimera along the scientific Python stack is no longer a problem. In fact, PyChimera was born during the development of GaudiMM (Rodríguez-Guerra Pedregal et al., 2017) and we can only hope that this small but powerful tool will also help other researchers to use UCSF Chimera in custom scripts or applications. Acknowledgements The authors want to thank the UCSF Chimera’s team, and more particularly Greg Couch, for the ideas and inputs on the chimera-dev mailing list. Funding The authors are thankful for the support given by the Spanish MINECO (project CTQ2014-54071-P) and the Generalitat de Catalunya (project 2014SGR989). Support of COST Action CM1306 is kindly acknowledged. Research grant to JRGP (Generalitat de Catalunya, 2017FI_B2_00168) is acknowledged. Conflict of Interest: none declared. References Eastman P. et al.   ( 2013) OpenMM 4: a reusable, extensible, hardware independent library for high performance molecular simulation. J. Chem. Theory Comput ., 9, 461– 469. Google Scholar CrossRef Search ADS PubMed  McGibbon R.T. et al.   ( 2015) MDTraj: a modern open library for the analysis of molecular dynamics trajectories. Biophys. J ., 109, 1528– 1532. Google Scholar CrossRef Search ADS PubMed  Perez F., Granger B.E. ( 2007) IPython: a system for interactive scientific computing. Comput. Sci. Eng ., 9, 21– 29. Google Scholar CrossRef Search ADS   Pettersen E.F. et al.   ( 2004) UCSF Chimera–a visualization system for exploratory research and analysis. J. Comput. Chem ., 25, 1605– 1612. Google Scholar CrossRef Search ADS PubMed  Rodríguez-Guerra Pedregal J. et al.   ( 2017) GaudiMM: a modular multi-objective platform for molecular modeling. J. Comput. Chem ., 38, 2118– 2126. Google Scholar CrossRef Search ADS PubMed  Rose A.S., Hildebrand P.W. ( 2015) NGL Viewer: a web application for molecular visualization. Nucleic Acids Res ., 43, W576– W579. Google Scholar CrossRef Search ADS PubMed  Sanner M.F. ( 1999) Python: a programming language for software integration and development. J. Mol. Graph. Model ., 17, 57– 61. Google Scholar PubMed  Trott O., Olson A.J. ( 2010) AutoDock Vina: improving the speed and accuracy of docking with a new scoring function, efficient optimization, and multithreading. J. Comput. Chem ., 31, 455– 461. Google Scholar PubMed  van der Walt S. et al.   ( 2011) The NumPy array: a structure for efficient numerical computation. Comput. Sci. Eng ., 13, 22– 30. Google Scholar CrossRef Search ADS   © The Author(s) 2018. Published by Oxford University Press. All rights reserved. For Permissions, please e-mail: journals.permissions@oup.com This article is published and distributed under the terms of the Oxford University Press, Standard Journals Publication Model (https://academic.oup.com/journals/pages/about_us/legal/notices)

Journal

BioinformaticsOxford University Press

Published: Jan 11, 2018

There are no references for this article.

You’re reading a free preview. Subscribe to read the entire article.


DeepDyve is your
personal research library

It’s your single place to instantly
discover and read the research
that matters to you.

Enjoy affordable access to
over 18 million articles from more than
15,000 peer-reviewed journals.

All for just $49/month

Explore the DeepDyve Library

Search

Query the DeepDyve database, plus search all of PubMed and Google Scholar seamlessly

Organize

Save any article or search result from DeepDyve, PubMed, and Google Scholar... all in one place.

Access

Get unlimited, online access to over 18 million full-text articles from more than 15,000 scientific journals.

Your journals are on DeepDyve

Read from thousands of the leading scholarly journals from SpringerNature, Elsevier, Wiley-Blackwell, Oxford University Press and more.

All the latest content is available, no embargo periods.

See the journals in your area

DeepDyve

Freelancer

DeepDyve

Pro

Price

FREE

$49/month
$360/year

Save searches from
Google Scholar,
PubMed

Create lists to
organize your research

Export lists, citations

Read DeepDyve articles

Abstract access only

Unlimited access to over
18 million full-text articles

Print

20 pages / month

PDF Discount

20% off