Home > Programming > PyMOLで分子をpngファイルに描画した後、pngファイルにテキストを入れる方法

PyMOLで分子をpngファイルに描画した後、pngファイルにテキストを入れる方法

PyMOLはPythonで書かれており、Pythonスクリプトを使って色々と操作することが可能です。

PyMOLで色々操作した後でpngで画像を出力することも可能なのですが、さらにその画像に文字を入れたいとします。
そういうときはどうするか?(Pythonはあまり使ったことがないのでイマイチ文法などがわかりません。そのため変なところがあるかも)
こちらを参考にさせていただきました。
サンボマスタージェネレータ

ちなみに、私はMacPortsでPython 2.5をインストールしている状況です。
そのほかに必要なものはPIL (Python Image Library) なのでこれもMacPortsであらかじめインストールしておきます。

#!/opt/local/bin/python2.5
# -*- encoding: utf-8 -*-

import pymol
import ImageDraw, ImageFont, Image

pymol.cmd.load("PDBのファイル名")

png_file_name = "pngファイル名"
pymol.cmd.png(png_file_name)

font_file = "/Library/Fonts/Microsoft/Gill Sans MT.ttf"
font_size = 24
font = ImageFont.truetype(font_file, font_size)

image = Image.open(png_file_name).convert("RGB")

draw = ImageDraw.Draw(image)draw.text((10, 10), "描画するテキスト", font = font, fill = (255, 255, 255))

image.save(png_file_name)

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://www.cocoalife.net/2008/08/post_679.html/trackback
Listed below are links to weblogs that reference
PyMOLで分子をpngファイルに描画した後、pngファイルにテキストを入れる方法 from cocoa*life
blog comments powered by Disqus

Home > Programming > PyMOLで分子をpngファイルに描画した後、pngファイルにテキストを入れる方法

Feeds
Meta

Return to page top