Use pymol as a python library

The explanation will be given in the following environment. Linux: 3.13.0-37-generic #64-Ubuntu

Python 2.7.6

Display the path of the imported module

<module name>.path

>>> import pymol
>>> pymol.__path__
['/usr/lib/python2.7/dist-packages/pymol']

installation of biopython

[hnishi@hn python_pymol]$ sudo apt-get install python-biopython

View module help

help(<module name>)

>>> import Bio
>>> help(Bio)

Use pymol functions from regular python (CUI)

** pymol -c **: open pymol with CUI only

cui_pymol.py


import pymol
pymol.pymol_argv = ['pymol','-c'] 
pymol.finish_launching()
pymol.cmd.fetch("4m61")

Output result

[hnishi@hn python_pymol]$ python cui_pymol.py
 PyMOL(TM) Molecular Graphics System, Version 1.7.0.0.
 Copyright (c) Schrodinger, LLC.
 All Rights Reserved.

    Created by Warren L. DeLano, Ph.D.

    PyMOL is user-supported open-source software.  Although some versions
    are freely available, PyMOL is not in the public domain.

    If PyMOL is helpful in your work or study, then please volunteer
    support for our ongoing efforts to create open and affordable scientific
    software by purchasing a PyMOL Maintenance and/or Support subscription.

    More information can be found at "http://www.pymol.org".

    Enter "help" for a list of commands.
    Enter "help <command-name>" for information on a specific command.

 Hit ESC anytime to toggle between text and graphics.

 Command mode. No graphics front end.
 PyMOL: normal program termination.

With the option pymol -q, you can hide the version information etc. that appears at the beginning of the log (Quiet).

For options when starting pymol http://pymolwiki.org/index.php/Command_Line_Options reference

Get coordinate information of pymol object (molecule)

** pymol.cmd.iterate_state (\ <state >, \ <selection >, \ <expression >) **: pymol function and object information

iterate_state.py


#!/usr/bin/python2.7 -i

import sys, os

### pymol launching
import pymol
pymol.pymol_argv = ['pymol','-qc'] + sys.argv[1:]
pymol.finish_launching()
cmd = pymol.cmd

### read pdb
r = cmd.fetch("4m61","obj1")
print r
cmd.iterate_state(1, "obj1 and name CA and resi 3 and chai A", "print x,y,z")  #print coordinates

Output result

[hnishi@hn python_pymol]$ python iterate_state.py
obj1
9.97799968719 35.7999992371 20.9699993134

The mystery that there are 4 digits or less even though the value is up to 3 decimal places on the PDB file.

Source cui_pymol.py https://gist.github.com/hnishi/3b9a3247a4bc356e17c7.js

Launch pymol from python (GUI)

gui_pymol.py


#!/usr/bin/env python

# Tell PyMOL we don't want any GUI features.
# It runs PyMol fullscreen stereo, and disables the internal gui.
import __main__
__main__.pymol_argv = [ 'pymol', '-qei' ]  #$ pymol -qei

# Importing the PyMOL module will create the window.
import pymol

# Call the function below before using any PyMOL modules.
pymol.finish_launching()

[hnishi@hn python_pymol]$ python gui_pymol.py The pymol window launches in full screen. The internal GUI function is turned off. Instead, it's light enough to run slimy from the server via x-window.

Show methods and members of objects and modules

dir(<something>)

python2.7


>>> import Bio
>>> print dir(Bio)
['BiopythonDeprecationWarning', 'BiopythonExperimentalWarning', 'BiopythonParserWarning', 'BiopythonWarning', 'MissingExternalDependencyError', 'MissingPythonDependencyError', '__builtins__', '__doc__', '__docformat__', '__file__', '__name__', '__package__', '__path__', '__version__']

on hold

from multiprocessing import Pool a = range(100) a p = Pool()

Link

How to write a pymol script http://qiita.com/hnishi/items/e77b270ad1a6d574d6cc

reference

Use pymol from python http://pymolwiki.org/index.php/Launching_From_a_Script Extract object information in pymol http://www.pymolwiki.org/index.php/Simple_Scripting

Recommended Posts

Use pymol as a python library
Use blender as a python module
[Python] Use a string sequence
Use Remotte as a user
Use DynamoDB as a lock manager
Use fabric as is in python (fabric3)
How to use Requests (Python Library)
Use embeddable Python as Vim's Python 3 interface
[Python] Use JSON format data as a dictionary type object
Launch a Python script as a service
Generate a Python library download badge
A note about mock (Python mock library)
Use networkx, a library that handles graphs in python (Part 2: Tutorial)
Use youtube_dl as a python module. appendix) Nico Nico Douga HTTP 403 error
Use print in a Python2 lambda expression
Install Python as a Framework with pyenv
Use cryptography library cryptography with Docker Python image
[Python] Sorting collection types as a reference
Try HTML scraping with a Python library
Python as a strongly, dynamically typed language
Use Django from a local Python script
Let's use a scripting language for a comfortable C ++ life 6-How about developing a program as a library for Python?
Python 3.6 email library
Python ast library
Python Library notes
How to use hmmlearn, a Python library that realizes hidden Markov models
How to use the C library in Python
Use Azure ML Python SDK 2: Use dataset as input-Part 2
python memo: Treat lists as a set type
How to use Python Image Library in python3 series
A memorandum about the Python tesseract wrapper library
Use the e-paper module as a to-do list
Use a custom error page in python / tornado
Use python in Docker container as Pycharm interpreter
Use the LibreOffice app in Python (3) Add library
Use thingsspeak from python
A * algorithm (Python edition)
Use config.ini in Python
[Python] Take a screenshot
[Python] Use JSON with Python
Use fluentd from python
(Python) Treat integer values as a set of flags
Use dates in Python
Specify a subcommand as a command line argument in Python
Create a Python module
python algorithmic trading library
A python lambda expression ...
Use Valgrind in Python
Use MySQL from Python
Use mecab with Python3
Use LiquidTap Python Client ③
Use DynamoDB with Python
Use a Property Decorator?
I wanted to use the Python library from MATLAB
Daemonize a Python process
Install python external library
[Python] How to use the graph creation library Altair
Use Python 3.8 with Anaconda
Created a Python library DateTimeRange that handles time ranges
[Python] format methodical use
Use python with docker