Molby

Interactive Molecular Modeling Software
with Integrated Ruby Interpreter

Version 1.1.0

Toshi Nagata

http://molby.osdn.jp/index-en.html

Molby

対話型分子モデリングソフトウェア
(Ruby インタプリタ内蔵)

Version 1.1.0

永田 央

http://molby.osdn.jp/index.html


Table of Contents

目次

Introduction

はじめに

What is Molby?

Molby is an application to visualize and build molecular models interactively through 3D display. It provides the following capability:

Molbyとは?

Molby は、分子を 3D 表示して、画面上で分子モデルを構築するためのアプリケーションです。以下のような機能があります。

Installation

1. Supported Platforms

Molby runs on the following platforms.

Installation procedures are described below for each of these platforms.

2. Get the Software

Download from the official distribution web site, http://en.osdn.jp/projects/molby/.

3. Installation

3-1. Microsoft Windows

The Windows version is provided either as a zip archive (MolbyWin32.zip, MolbyWin64.zip) or a standard setup package (SetupMolbyWin32.exe, SetupMolbyWin.exe).

To use the zip archive, expand all contents in your favorite place, and double-click the "Molby" icon.

To install on your PC, start the setup package, and follow the instructions. After installation is finished, you will find the Molby application registered in the "Start" menu under the item "All Programs."

3-2. Mac OS X

The Mac version is provided as a zip archive (MolbyMac.zip, MolbyMacLegacy.zip for MacOS 10.6 to 10.11). Double-click the archive, and you will get a folder including the Molby application. Drag it to the "Applications" folder in your hard drive.

4. Uninstallation

4-1. Microsoft Windows

If you install Molby, use the uninstaller in the Molby folder. You can access the Molby folder from the "Start" menu (Start -> All Programs -> Molby).

4-2. Mac OS X

Trash the Molby application in the "Applications" folder.

インストール

1. サポートするプラットフォーム

Molbyは以下のプラットフォームで動作します。

それぞれのプラットフォームでのインストール方法を、以下に説明します。

2. ソフトウェアの入手

公式配布サイト http://osdn.jp/projects/molby/ から最新版をダウンロードしてください。

3. インストール

3-1. Microsoft Windows

Windows版は、zip アーカイブ(MolbyWin32.zip:32 ビット版, MolbyWin64.zip: 64ビット版)、または標準のセットアップパッケージ (SetupMolbyWin32.exe: 32ビット版、SetupMolbyWin64.exe: 64ビット版) で配布されています。

Zip アーカイブを使う時は、最初に内容をすべて展開してください。展開したフォルダの中に Molby アプリケーションがあるので、ダブルクリックして起動してください。

セットアップパッケージを使う時は、ダブルクリックして指示に従ってください。インストールが終了したら、「スタート」メニューの「すべてのプログラム」の中に Molby が入っているはずです。

3-2. Mac OS X

Mac版は、zip アーカイブ (MolbyMac.zip, MolbyMacLegacy.zip [10.6〜10.11用]) で配布されています。アーカイブをダブルクリックすると、内容が展開されて新しいフォルダができます。Molby アプリケーションがその中にありますので、ハードディスクの「アプリケーション」フォルダにドラッグコピーしてください。

4. アンインストール

4-1. Microsoft Windows

インストールした Molby を PC から除きたい時には、Molbyフォルダの中のアンインストーラを使ってください。「スタート」メニューで「すべてのプログラム」-> Molby とたどってください。

4-2. Mac OS X

「アプリケーション」フォルダの中の Molby アプリケーションをゴミ箱に捨てます。

Copyright and License

1. Copyright Notice

Molby is a copyrighted product of Toshi Nagata.

Copyright (C) 2008-2022 Toshi Nagata

I ask for citation of the following paper in published works that utilize Molby:

Toshi Nagata, "Molby - Graphical Molecular Modeling Software with Integrated Ruby Interpreter,"
Bull. Chem. Soc. Jpn. 2014, 87, 902-904. DOI:10.1246/bcsj.20140093

Molby includes the following softwares, which are copyrighted products as described below:

2. License

Molby is distributed under the GNU General Public License (version 3).

Molby: Interactive Molecular Modeling Software with Integrated Ruby Interpreter

Copyright (C) 2008-2022 Toshi Nagata

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

著作権とライセンス

1. 著作権表示

Molby の著作権は永田 央が保持しています。

Copyright (C) 2008-2022 Toshi Nagata

Molby を利用した成果を発表される際は、以下の論文を引用していただくようお願いします。

Toshi Nagata, "Molby - Graphical Molecular Modeling Software with Integrated Ruby Interpreter,"
Bull. Chem. Soc. Jpn. 2014, 87, 902-904. DOI:10.1246/bcsj.20140093

Molby は以下のソフトウェアを含んでいます。それぞれの著作権表示は下の通りです。

2. ライセンス

Molby は GNU General Public License (GNU 一般公衆利用許諾契約書, version 3) に従って配布します。

Molby: 対話型分子モデルソフトウェア(Ruby インタプリタ内蔵)

Copyright (C) 2008-2022 Toshi Nagata

このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェア財団によって発行された GNU 一般公衆利用許諾契約書(バージョン3か、希望によってはそれ以降のバージョンのうちどれか)の定める条件の下で再頒布または改変することができます。

このプログラムは有用であることを願って頒布されますが、*全くの無保証* です。商業可能性の保証や特定の目的への適合性は、言外に示されたものも含め全く存在しません。詳しくはGNU 一般公衆利用許諾契約書をご覧ください。

参考のため、GNU 一般公衆利用許諾契約書の非公式日本語訳を添付します。ただし、正式な文書は英語版の方です。

Tutorials

チュートリアル

Step One: Draw a New Molecule

1. Create a Molecule

Start up Molby. You will see a blank window like below. This is the main window to manipulate your molecule.

Suppose you want a benzene molecule. Double-click on the black area, and you will be asked to "enter formula". Type "C6H6" and hit "OK".

Then you see a benzene molecule in the black area. The atoms and bonds are drawn in red, which means these atoms and bonds are "selected". On the left to this area, there is a table, which shows in numbers the positions of all atoms, and other useful information. We will get into this part in more details later.

2. Rotate the Molecule

You can rotate the molecule around by use of the three bars on the both sides and the bottom of the black area. Press the left button of the mouse on one of these bars, and try dragging.

Next, look at the buttons above the black area. The left-most button "Rot" is now selected. This means the window is in the "Rotation" mode. In this case, you can drag in the black area to rotate freely the whole molecule.

Note: Be careful not to start drag from a very near point to the molecule. If you start drag on a selected atom or bond, the selected part will move along the mouse, instead of the whole molecule to rotate.

3. Translate and Scale

Press the button "Trans" above the black area. The window is now in "Translate" mode. When you drag in the black area, the whole molecule moves along with the mouse movement.

Note: the functions of the rotation bars do not change.

Next, press the button "Scale". The window is now in "Scale" mode, and you can expand and shrink the molecule by dragging in the black area.

The "Fit to Screen" menu command, avaiable under the "View" menu, is a convenient way to fit the whole molecule to the window.

Now you have learned how to move the whole molecule around. In the next chapter, you will learn how to edit the molecule.

第一段階:新しい分子を描く

1. 分子を作る

Molbyを立ち上げてください。下のような空のウィンドウが現れます。このウィンドウが、分子を取り扱うためのメインウィンドウです。

ベンゼン分子を作ってみたいとします。画面の黒いところ(編集エリア)をダブルクリックすると、"enter formula" と指示が出ます。"C6H6" とタイプして、OK を押します。

編集エリアにベンゼン分子が現れます。原子と結合は赤色で描かれていますが、これは「選択されている」という表示です。左側には表があり、原子の位置などの情報を数値で表示しています。この部分については、あとで詳しい使い方が出てきます。

2. 分子を回転させる

編集エリアの両側と下には、分子を回転させるバーがあります。このバーでマウスボタンを押し、そのままドラッグしてみてください。

次に、編集エリアの上にあるボタンを見てください。一番左の "Rot" が選択されています。これは、このウィンドウが現在「回転 (Rotation)」モードにあることを示しています。この場合、編集エリアでマウスをドラッグすると、分子全体を自由に回転させることができます。

注: 分子に近すぎるところからドラッグを始めないように注意してください。選択している原子・結合の上でドラッグを始めると、選択部分がマウスについて動いてしまい、分子全体を動かすことができません。

3. Translate and scale

"Trans" と書かれたボタンを押してください。ウィンドウは「並進 (Translate)」モードになります。編集エリアでマウスをドラッグすると、分子全体を平行移動させることができます。

注: 回転バーの機能は変わりません。

次に、"Scale" と書かれたボタンを押してください。ウィンドウは「拡大縮小 (Scale)」モードになります。編集エリアでマウスをドラッグすると、分子全体を拡大・縮小することができます。

"View" メニューの中に "Fit to Screen" メニューコマンドがあります。このコマンドは、分子をウィンドウサイズに合わせて表示したいときに便利です。

分子を画面上で動かす方法がわかりました。次は、編集のやり方を説明します。

Step Two: Edit a Molecule

1. Append a Substituent

Suppose you have a benzene molecule now, and want to append a methyl substituent to give a toluene.

Press the button "Select", and click on the black area where no atom nor bond is present. The selection becomes canceled.

Select one of the hydrogen atoms. There are two ways to do this. You can click on the target atom, or you can drag to select atoms within a rectangular region.

Double-click on the hydrogen atom. This time, be sure to hit the selection! Then you will see the dialog "enter formula" as shown below. Type "CH3" in the text box and hit "OK".

Now you get toluene.

You want to save the result to a file. Select "Save as..." from the File menu, choose the file format, enter the filename, and hit "Save".

The "native" file format in Molby is "mbsf", i.e. Molby Structure File. The mbsf format is a private format with no compatibility with any existing file format for chemistry. Nevertheless, it is a plain text file that is reasonably compact and easy to read. Unless you have a particular reason to choose other formats, it is recommended that you save the structues as a "mbsf" file.

2. Manipulate Molecular Fragments

After building a molecule, you may want to move some part of a molecule. Here are examples how you can do it.

Select the methyl group of the toluene, if you have not done so yet (Tip: you can add to the current selection by shift-clicking). Press the left rotation bar (marked "3" in the previous page), and drag up and down. You will see the methyl group rotates to the right and left.

The same manipulation can be achieved by selecting one bond and dragging the left rotation bar. In this case, you can also rotate the benzene ring (with the methyl group fixed) by pressing Option (Mac) or Alt (Win) key when dragging.

The selected atoms can be dragged to give a translational move. Use this feature with care, because it may result in a chemically unnatural structure.

3. Adding and Deleting Atoms

We have already learned one way to add atoms: double-clicking on the selected part of the molecule (or on the black area where nothing is present), and type-in the formula. Actually, this is the most convenient way to add atoms in Molby. However, there are also other ways to add atoms.

Look at our familiar toluene molecule. Suppose we want to convert it to indane.

indane

Rotate the molecule so that its orientation matches the chemical structure. We will start from C3, add two carbons, and then close the ring.

Press the "Erase" button above the black area. Click on the "H3" hydrogen. The hydrogen atom and the bond between C3 and H3 disappear.

Press the "Bond" button. Drag from the C3 atom to the right-bottom, and release the mouse button. A new atom and a bond to C3 are created. Drag from the new atom to the right-up, and another atom and bond are created.

Press the "Erase" button again, and erase one hydrogen from the methyl group. Press the "Select" button, select the benzene-methylene bond, and rotate the methylene group as appropriate for the five-membered ring, by use of the left rotation bar.

Now you can close the ring. Press the "Bond" button, and drag from the methylene carbon. When the mouse cursor comes close enough to the target carbon, the new atom will snap to the target and make a new bond. Then release the mouse button.

Finally, you want to add hydrogens to the newly created carbons. Press the "Select" button, and select these two carbons. Go to the "Edit" menu, and select the "Add Hydrogen" -> "Tetrahedral sp3" menu command.

Here is the result.

A similar result can be achieved by selecting the hydrogen ortho to the methyl group, double-click it, type "CH2CH3" in, erase one hydrogen atom from each of the methyl groups, and make a bond. This is better because the newly created methylenes have reasonable bond lengths and angles as methylene groups. The above example is just for explanation of the editing features.

第二段階:分子を編集する

1. 置換基をつける

ベンゼン分子があり、これにメチル基をつけてトルエンを作りたいとします。

"Select"ボタンを押して、編集エリアの原子や結合がないところをクリックします。選択が解除され、分子の表示が赤から原子ごとの色に変わります。

水素原子の一つを選択します。やり方は二つあります。選択したい原子をクリックするか、またはドラッグで現れる四角い領域の中の原子を選択します。

水素原子の上でダブルクリックします。このとき、選択部分の上でダブルクリックするように注意してください。"Enter formula"というダイアログが出てきます。"CH3"と入力し、"OK"を押します。

トルエンができました。

ファイルに保存しておきたい時は、通常通り File メニューから "Save as..." を選び、ファイルフォーマットを選び、ファイル名をタイプして "Save" を押します。

Molby の標準ファイルフォーマットは "mbsf" (Molby Structure File) です。Mbsf フォーマットは独自のもので、既存の化学ファイルフォーマットとは互換性がありません。しかし、mbsfはテキストファイルであり、比較的コンパクトで、読みやすいものです。他のフォーマットで保存する積極的な理由がない場合は、"mbsf"フォーマットで保存しておくことをおすすめします。

2. 分子の一部を操作する

分子を組み立てたら、その一部を動かしたくなることがあります。ここでは、そのやり方の例を示します。

トルエンのメチル基を選択します(コツ:シフトキーを押しながらクリックすると、現在の選択範囲に原子を付け加えることができます)。左の回転バー(前ページで③と書かれていたもの)でマウスボタンを押し、上下にドラッグしてください。メチル基が右左に回転するのがわかります。

同じ操作は、結合を1つ選択して左の回転バーをドラッグしてもできます。この場合、メチル基を固定してベンゼン環の方を回すこともできます。ドラッグの時にOptionキー(Mac)、Altキー(Win)を押してください。

選択した原子をドラッグすると平行移動できます。化学的に不自然な構造になりますので、注意が必要です。

3. 原子を追加する・削除する

原子を追加する方法はすでに一つ説明しました。選択部分または編集エリアの何もないところをダブルクリックして、構造式をタイプする方法です。実際、Molbyで原子を追加するにはこれが最も便利です。しかし、他の方法もありますので、それを紹介します。

先ほどのトルエン分子を使います。これをインダンに変えたいとします。

インダン

分子を回転させて、化学構造式と同じ向きになるようにします。C3から始めて、炭素原子を2つ追加し、環を閉じることにします。

編集エリアの上の"Erase"ボタンを押します。"H3"水素をクリックします。この水素原子と、C3-H3の結合が消えます。

"Bond"ボタンを押します。C3原子から右下にドラッグし、マウスボタンを離します。新しい原子と、その原子とC3の間の結合が新しく作られます。新しい原子から右上にドラッグすると、もう一つの原子と結合が作られます。

"Erase"ボタンをもう一度押して、メチル基の原子を一つ消します。"Select"ボタンを押して、ベンゼン環とメチレン炭素(今水素原子を一つ消したところ)の間の結合を選択します。左の回転バーを使って、五員環に適切な向きになるようにメチレン基を回転させます。

環を閉じます。"Bond"ボタンを押し、メチレン炭素原子から右下の炭素原子へドラッグします。マウスカーソルが目標の炭素原子に近づくと、ドラッグしてできた結合が炭素原子にくっつきます。ここでマウスボタンを離します。

最後に、新しく作った二つの炭素原子に水素原子を付加します。"Select"ボタンを押して、マウスを使って二つの炭素原子を選択します。"Edit"メニューから、"Add Hydrogen"->"Tetrahedral sp3"コマンドを実行します。

結果はこのようになります。

トルエンからインダンは次のような操作でも作ることができます。メチル基のオルト位の水素原子を選択、ダブルクリック、ダイアログが出たら"CH2CH3"と入力、二つのメチル基からそれぞれ水素原子を一つ削除、結合回転で向きを調整、結合を作成。この方法の方が、新しく作ったメチレン基の結合距離・結合角が正しくなるため、よりよい結果になります。上の例は、編集操作の説明のためのものと考えてください。

Step Three: Edit a Molecule: Cut/Copy/Paste

Like any other decent "editing" applications, Molby has a capability of cut/copy/paste by use of a clipboard. These functions (especially copy and paste) are also quite useful for building complex molecules.

We start from the toluene molecule again. Select the methyl group and do copy.

Unselect the methyl group, and do paste. Another methyl group appears, with no connection to the existing atoms. This is how "paste" works when nothing is selected beforehand.

Now we will see what happens when something is selected before pasting. As described above, start with the toluene molecule, select the methyl group, and copy it. Unselect the methyl group, and this time select the hydrogen atom that is "ortho" to the methyl group.

Do paste. The selected hydrogen atom is replaced with the pasted methyl group. Note that a new bond is created between the pasted methyl carbon and the ortho carbon, with an acceptable bond length and angles.

The dihedral angle may not be acceptable. In that case, you can rotate the pasted fragment by use of the left rotation bar until the dihedral angle looks good.

This "select and paste" technique is very useful for building large molecules. Suppose we want to build an oligobenzamide.

Create a "monomer", i.e. N-methyl-4-acetamidobenzamide. This is done by (1) create a benzene, (2) select H1, double-click, and enter "CONHCH3", (3) select H4, double-click, and enter "NHCOCH3". After entering each formula, you need to rotate the fragment to make the dihedral angle appropriate.

Select the whole molecule except for the COCH3 group at the left. Do copy.

Select the NHCH3 group at the right. Do paste.

A new amide bond is created and the dimer is formed.

Select "Fit to Screen" from the "Show" menu, to make the whole molecule visible.

Repeat these procedures to make the tetramer.

Make one more iteration to make the octamer.

第三段階:分子を編集する:カット・コピー・ペースト

他のアプリケーションと同様に、Molby もクリップボードを使ってカット・コピー・ペーストを行う機能があります。これらの機能、特にコピー・ペーストは複雑な分子を作るときにたいへん有用です。

ふたたびトルエン分子から始めます。メチル基を選択して、コピーします。

メチル基の選択を解除して、ペーストを実行します。他の原子と結合していないメチル基がもう一つ現れます。原子が選択されていない状態で「ペースト」すると、このような動作になります。

今度は、ペーストする前に原子が選択されているときにどうなるかを見てみます。上と同じように、トルエンから始めて、メチル基を選択して、コピーします。メチル基の選択を解除して、今度はメチル基のオルト位の水素原子を選択します。

ペーストを実行します。選択された水素原子がメチル基に置き換わります。オルト位の炭素とメチル基の間に新しい結合ができ、その長さと結合角が適切なものになっていることがわかります。

二面角は適切でないこともあります。その場合は、ペーストされたグループを左の回転バーを使って回転させて、適切な二面角にします。

この「選択してペースト」のテクニックは、大きな分子を作るときにたいへん役に立ちます。たとえば、オリゴベンズアミドを作りたいとします。

まず、「モノマー」となる N-メチル-4-アセトアミドベンズアミドを作ります。次のようにします:(1) ベンゼンを作る、(2) H1 を選択してダブルクリックし、「CONHCH3」とタイプする、(3) H4 を選択してダブルクリックし、「NHCOCH3」とタイプする。化学式をタイプしたあとは、作成したフラグメントを回転させて二面角を調整しておきます。

左端の COCH3 以外全部を選択し、コピーします。

右端の NHCH3 を選択し、「ペースト」を実行します。

新しくアミド結合が作られ、二量体ができます。

"Show" メニューから "Fit to Screen" を選び、分子全体が見えるようにします。

この操作を繰り返して、四量体を作ります。

もう一度繰り返して、八量体を作ります。

Step Four: Ring Fusion

1. Ring fusion by double-click and type-in

Molby has a capability to create a fused ring structure. As an example, here is presented yet another method to make indane. This time, we start from a benzene.

Choose "select" mode, and select C1 and C2 by clicking on the C1-C2 bond.

Double-click on the selection, and enter "cyclopentane" in the dialog box.

After pressing "OK", you will see a five-membered ring fused to the benzene ring.

Ring fusion also works when three or more atoms are selected in the original structure. For example, select the consecutive three carbons in indane as follows.

Double-click on the selection, and enter "C6H6" (or "benzene").

Now we have acenaphthene...almost.

As shown in the above figure, there is an extra, leftover hydrogen atom on one bridgehead carbon. After all, Molby is not so smart --- it just removes one hydrogen from each terminal carbon atoms in the selection, and connect a portion of the fusing fragment ("benzene" in this case) so that the newly created ring has the same number of atoms. Consequently, the stereochemistry may become strange when sp3 carbons are present either in the original structure or in the fusing fragment. You may need to remove/append hydrogen atoms and clean up structures (see "Energy Minimization" for detail).

2. Ring fusion by copy-and-paste

There is another way to make a ring fused structure, which includes copy and paste. Starting again from a benzene.

Open the "File" menu, and select "Open Predefined" → "Alicyclic" → "cyclopentane".

A new window named "*cyclopentane*" opens with one cyclopentane molecule. Select a portion containing three CH2 groups, and copy it by command-C or ctrl-C.

Return to the benzene molecule again, and this time select H1 and H2 (not C1 and C2).

Do paste by command-V or ctrl-V. You now get a indane molecule.

This "copy-and-paste" actually works in a similar way to previously described example (see "Cut/Copy/Paste"). When both the current selection and the fragment in the pasteboard have two terminals, they are connected and ring fusion takes place. This method of ring fusion is slightly more complicated than the "double-click and type-in" method, but it may be easier to understand.

第四段階:縮環構造の作成

1. ダブルクリック/キー入力による縮環

Molby は縮環構造を作るための機能を持っています。例として、インダンを作るもう一つの方法を紹介します。今回は、ベンゼンから始めます。

"Select" モードにして、C1-C2 結合をクリックして C1 と C2 を選択します。

選択部分をダブルクリックして、ダイアログボックスに "cyclopentane" と入力します。

"OK" を押すと、5員環がベンゼン環に縮環します。

選択部分が3個以上の原子を含んでいても、縮環は可能です。例えば、インダンで図のように3つの連続した炭素原子を選択してみます。

選択部分をダブルクリックして、"C6H6"(または "benzene")と入力します。

そうすると、アセナフテンができます...だいたい。

上の図に示したように、橋頭位の炭素に1つ余分な水素原子が残ってしまいます。実のところ、Molby はあんまり賢くありません。選択部分の両端の原子から水素原子を1つずつ取り除いて、縮環する分子(この場合はベンゼン)の一部をかわりに結合して、生成する環の原子数が一致するようにしているだけです。このため、元の選択部分または縮環する分子が sp3 炭素を含んでいると、立体化学が変になることがあります。水素原子を除いたり付け加えたりして、さらに構造を最適化する必要があるでしょう(詳しくは「エネルギー最小化」を見てください)。

2. コピー/ペーストによる縮環

縮環構造を作るには、コピー/ペーストを使ったもう一つの方法があります。またベンゼンから始めましょう。

"File" メニューを開き、"Open Predefined" → "Alicyclic" → "cyclopentane" を選んでください。

"*cyclopentane*"という名前の新しいウィンドウが開き、シクロペンタン分子が入っています。3つのメチレン基を選択して、コマンド-C またはコントロール-C でコピーしてください。

ベンゼン分子に戻って、今度は H1 と H2(C1 と C2 ではなく)を選択してください。

コマンド-V またはコントロール-V でペーストしてください。インダンができます。

この「コピー/ペースト」は、実は前に説明したのと (カット/コピー/ペースト) 同じように機能しています。現在の選択部分とクリップボードの内容がともに「2つの末端」を持っているとき、末端同士がつなぎあわされ、縮環したように見えるのです。この方法による縮環は「ダブルクリック/入力」の方法よりも少し複雑ですが、何が起きているかはこちらの方が理解しやすいかもしれません。

Step Five: Edit a Molecule: Using a Property Table

1. The Property Table of a Molecule

A molecule has many properties. It has a set of atoms and bonds. An atom has a name, an atom type, an element, a weight (which can be derived from the element), a charge, coordinates, and so on. According to the custom in the biomolecular modeling, atoms are grouped in "residues." It also has a set of parameters used in molecular mechanics. Molby also has a limited support for quantum chemical calculations. In relation to that, a molecule in Molby can retain extra information such as MO coefficients.

Many of these information are accessible via the property table. The table is on the left side of the model window.

The table now shows the properties of each atom, namely its name, type, element, "residue" name and index, coordinates and partial charge. The property can be edited by double-clicking on the text.

When return (enter) or tab key is pressed, the edited value is finalized, and editing will continue on another cell. Pressing return, shift-return, tab, or shift-tab should cause editing of the bottom, above, right, or left cell, respectively. If you want to finish editing, use option- (or alt-) return key combination.

Several points are worth mentioning here.

(1) The atom index (the leftmost column) cannot be edited. If you want to change the order of the atoms, try using a "drag-and-drop" feature, as shown in the figure below.

(2) The residue column shows the residue name and index separated by a period. Manual editing of this cell may lead to a surprising result. For example, if you change the residue name of atom 0 from "RES" to "XXX", all atoms having residue index "1" will also have the new residue name "XXX".

This behavior is based on the principle that all residue names and indices should be consistent, i.e. the atoms having the same residue index should have the same residue name. This is sometimes convenient, but in many cases it causes confusion.

A more recommended way to change the residue name and index is to use the menu command "Assign Residue...", in the "Script" menu, after selecting atoms you want to assign one residue name and index.

    

2. The Bond/Angle/Dihedral/Improper Table

The property table can also show other information. The type of information can be selected at the popup menu.

The bond, angle, dihedral, and improper tables show the indices, names, and types of the constituent atoms. In addition, the quantities (bond lengths, angles, etc.) and the molecular mechanics parameters (only after MM/MD calculation is performed) are also shown.

The bonds, angles, etc. are not editable in the property table. At present, the only way to create/delete bonds from GUI is to use the mouse operation "Bond" or "Erase".

3. The Parameter Table

The parameter table shows the molecular mechanics parameters in one table.

The parameters are grouped in several classes, namely "VDWs", "Bonds", "Angles", "Dihedrals", "Impropers", and "VDW Pairs".

The "VDWs" parameters are for the van der Waals nonbonding interaction, described by "eps" (the energy at the potential minimum in kcal/mol), "r" (the van der Waals radius in Å, which is half of the interatomic distance at the equilibrium state), "eps14", "r14" (eps and r for the pair of atoms separated by exactly three bonds. In many applications, the same parameters with the ordinary pair are used with a specific factor multiplied), "atomNo" (the atomic number), "weight" (the atomic weight). The last two are usually overridden by the atom parameters.

The "Bonds" parameters consist of "k" (the force constant in kcal/mol/Å2) and "r0" (the equilibrium bond length). The "Angles" parameters consist of "k" (the force constant in kcal/mol/radian2) and "a0" (the equilibrium bond angle). The "Dihedrals" and "Impropers" parameters consist of "k" (the force constant in kcal/mol/radian2), "period" (the periodicity), and "phi0" (the equilibrium torsion angle in degree). The "VDW Pairs" parameters are (rarely) used to describe pair-specific van der Waals interactions, and consist of "eps", "r", "eps14", and "r14".

There is another important property for each parameter, that is, whether the parameter is taken from the "global" source (i.e. not specific to this molecule), or it is "local" (specific to this molecule), or "undefined". This property is shown by the color of the row. The global parameters are shown in white cells, the local ones in pale yellow, and the undefined ones in red.

You can edit the parameters (although you need to be familiar with MM parameters and to know what you are doing!), but only if they are "local" or "undefined" parameters. The "global" parameters cannot be edited because it may be also used in other molecules, where the edited parameters may not be appropriate. If you want to modify some parameters but they are "global", then you can make them "local" by copying the parameters and the pasting.

Another way to create a "local" parameter is to use the "Create New Parameter" menu command in the Edit menu. You can choose the parameter type in the submenu.

If some parameters are not to be used for calculation, you can "cut" the parameters from the table. This feature is useful when you have many duplicated parameters having different force constants. (In actual calculation, the parameter appearing later in the table will be used.)

第五段階:分子を編集する:属性テーブルを使う

1. 分子の属性テーブル

分子はいろいろな属性を持っています。まず原子と結合があります。原子は名前、原子タイプ、元素、原子量(元素が決まれば決まる)、電荷、座標、など。また、生化学の習慣に従い、原子は「残基」でグループ化されています。分子はまた、分子力学のパラメータを持っています。Molby はまた量子化学計算も部分的にサポートします。それと関連して、分子に分子軌道係数などの情報を持たせることができます。

これらの情報の多くは「属性テーブル」で見ることができます。属性テーブルは、分子モデルのウィンドウの左半分にあります。

図では、テーブルは原子の属性を表示しています。名前、原子タイプ、元素、残基名と残基番号、座標、部分電荷です。これらの属性はダブルクリックして編集することができます。

リターン(エンター)またはタブキーを押すと、編集した値は確定され、別のセルが編集状態になります。リターン、シフト+リターン、タブ、シフト+タブでそれぞれ下・上・右・左のセルに移動します。編集を終了したい時は、オプション(Windows では Alt)+リターンを使ってください。

いくつか注意点があります。

(1) 原子のインデックス(一番左の列)は編集できません。原子の順序を変えたい時は、下の図にあるように「ドラッグ・アンド・ドロップ」操作を使ってください。

(2) 残基の列には、残基の名前と残基番号がピリオドでつないで表示されています。このセルを編集すると、妙なことが起きて驚くかもしれません。たとえば、原子0の残基名を "RES" から "XXX" に変えると、残基番号が "1" であるすべての原子の残基名が "XXX" に変わります。

この挙動は、すべての残基名と残基番号は統一されていなければならない、という原理によります。つまり、同じ残基番号を持つ原子の残基名は同じでなければなりません。時にはこの挙動が便利に使えますが、混乱を招くことも多くあります。

残基名と残基番号を変更するお勧めの方法は、変更したい原子を選択して "Script" メニューの "Assign Residue..." コマンドを使うことです。

    

2. Bond/Angle/Dihedral/Improper テーブル

属性テーブルは他の情報も表示することができます。テーブルの種類はポップアップメニューで選択できます。

Bond, angle, dihedral, improper テーブルは、それぞれ結合・結合角・二面角・improper 二面角の構成原子のインデックス、名前、原子タイプを表示します。また、現在の値(結合長、角度、など)と、分子力学パラメータ(MM/MD 計算を行った直後に限られますが)も表示されます。

このテーブルで、結合、結合角などを編集することはできません。現在、画面上のインターフェイスを使って結合を作ったり削除したりする唯一の方法は、"Bond", "Erase" のマウス操作を使うことです。

3. パラメータテーブル

パラメータテーブルは、分子力学パラメータを表示します。

パラメータはいくつかの種類にグループ分けされています。"VDWs", "Bonds", "Angles", "Dihedrals", "Impropers", そして "VDW Pairs" です。

"VDWs" パラメータは、van der Waals 相互作用のためのもので、必要な値は "eps"(ポテンシャル極小値、kcal/mol)、"r"(van der Waals 半径、Å。ポテンシャル極小状態での原子間距離の 1/2)、"eps14", "r14"(結合3つで隔てられた2つの原子間の eps と r。多くの分子力学パッケージでは、通常の原子間と同じパラメータに一定の係数をかけて用いることが多い)、"atomNo"(原子番号)、"weight"(原子量)。最後の2つは、ふつうは各原子のパラメータで上書きされます。

"Bonds" パラメータは、"k"(結合の力の定数、kcal/mol/Å2)、"r0"(平衡結合長さ、Å)から成ります。"Angles" パラメータは、"k"(結合角の力の定数、kcal/mol/radian2)、"a0"(平衡結合角、degree)から成ります。'Dihedrals", "Impropers" パラメータは、"k"(力の定数、kcal/mol/radian2)、"period"(周期)、"phi0"(平衡二面角、degree)から成ります。"VDW Pairs" パラメータは滅多に使われませんが、ある原子の組み合わせに特有の van der Waals 相互作用を記述するもので、"eps", "r", "eps14", "r14" から成ります。

それぞれのパラメータにはもう一つ重要な特性があります。それは、そのパラメータが「グローバル」なのか(つまり、他の分子にも使われる共通の値なのか)、または「ローカル」なのか(この分子に特有)、または「未定義」なのか、です。この特性は、テーブルの行の色で区別できます。「グローバル」なパラメータは白、「ローカル」はうすい黄色、「未定義」は赤色のセルです。

パラメータは編集することができます(あなたが分子力学パラメータに詳しくて、何をしているかわかっていればの話だけど!)。ただし、パラメータが「ローカル」「未定義」の場合だけです。「グローバル」パラメータは、他の分子でも使われている可能性があるため、編集できません。「グローバル」なパラメータを編集したい時は、そのパラメータをコピー・ペーストすることで「ローカル」パラメータにすることができます。

「ローカル」なパラメータを作るもう1つの方法は、"Edit" メニューの "Create New Parameter" コマンドを使うことです。パラメータの種類をサブメニューから選ぶことができます。

もしあるパラメータは計算に使わないという場合には、そのパラメータをテーブルから削除することができます。この機能は、同じパラメータで異なる値を持つものが複数ある場合に有用です。(実際の計算では、テーブルの後ろの方にあるパラメータが優先されます。)

Step Six: Energy Minimization by Molecular Mechanics

1. About Molecular Mechanics Implementation in Molby

The molecular models built by hand generally include unnatural bond lengths, bond angles, van der Waals contacts, and so on. Molecular mechanics is a useful technique to remove such unnatural structures.

Molby implements molecular mechanics calculation by use of basic force fields, including bond stretching, angle bending, dihedral rotation, improper torsions, van der Waals interaction, and electrostatic interaction. With the exception of the electrostatic interaction, the parameters are taken from the predefined table by looking up the "atom types" assigned to the atoms.

By default, Molby uses gaff parameter set. Gaff, "General AMBER Force Field", is a part of AMBER molecular dynamics package; the force field parameters are made public domain by courtesy of the AMBER developers. Molby also includes parm99 parameter set, another AMBER force field that is widely used for biomolecules.

The troublesome part in using force fields is how to assign atom types. The AMBER developers provides a useful set of programs to take care of this problem. Thanks again to the AMBER developers, these programs, named AmberTools, are now made public (open source under GPLv2). Molby includes some of these programs, and calls and imports the results.

Following are the original papers published by the AMBER team. Please be sure to refer to them in your publication when you use the AMBER parameters or AmberTools.

2. Energy Minimization How-to

Now we try energy minimization. We use 2,2'-dimethoxybiphenyl as an example.

2,2'-dimethoxybiphenyl

Build this molecule. The easiest way is, (1) double-click the empty editing area and type "C6H5C6H5", (2) select one ortho hydrogen, double-click, and type "OCH3", (3) repeat (2) for another ortho hydrogen on the other ring.

Open the "MM/MD" menu, and select "Guess MM/MD Parameters..." command.

A dialog like below shows up. This is for execution of Antechamber on the current molecule. Turn off the "Calculate partial charges" checkbox, and turn on the "Guess atom types" checkbox. The "log" directory is used by AmberTools for storing intermediate files; the default value would be acceptable, but you can change it here.

After pressing "OK", two dialog boxes appear in turn. They disappear so quickly that you may not recognize what they are saying; actually, the first one says "Running antechamber" and the second one "Running parmchk." These are programs included in AmberTools. In the present case, both programs complete successfully, and the following dialog appears.

Press "OK", and you will return to the molecule window. Do you notice what change has been made? It is the atom types that are modified. Specifically, the types of the atoms 0 and 10 are changed from "ca" to "cp".

If you are wondering what "ca" or "cp" mean, look at the global parameter table (MM/MD → View Global Parameters...), and find comment(s) in the "vdw" record.

Return to the molecule, and select MM/MD → Minimize.

A setting dialog opens. "Steps per frame" means the screen is updated every this number of steps. "Number of frames" means the maximum number of "frames" (i.e. screen updates) to calculate. If the minimization completes before this number of frames, the calculation will stop. The numbers 10 and 200 are reasonable choice in many cases.

Press "OK", and minimization starts. As you expect, the dihedral angle between the two phenyl rings becomes large. The calculation will stop after 200 frames. You can see the number "200" at the right bottom of the window, and the slider at the bottom of the window is now active. Move the slider, and you can see how the molecular structure changed during the minimization.

If you save this molecule at this stage, all the frames will be also saved (when you select the "mbsf" format), and the resulting file may be very large. If you do not want this, then you can remove all the frames by use of "Delete Frames..." command in the "Script" menu.

3. Handling electrostatic interaction

The above description is sufficient for initial cleanup of the molecular structure. However, we should go one further step to take electrostatic interaction into consideration. This is particularly important in molecules with polar functional groups (such as carbonyl).

Continue our study on 2,2'-dimethoxybiphenyl. Open "MM/MD" → "Guess MM/MD Parameters...", and this time turn on the top checkbox. Also make sure the net molecular charge is correct.

Press "OK", and calculation starts. This time the calculation should take much longer than before, because semi-empirical calculation is carried out for optimizing the structure and getting the partial charges.

When calculation is done, the molecular structure may change, because structure optimization has been done by semi-empirical calculation. However, even more important is the "charge" values. You can see the charge values by scrolling the table to the right. By use of these "charge" values, interaction energies of the polar functional groups can be taken into account.

Note that the atomic charges given in the above method are derived from semi-empirical quantum chemical calculations. On the other hand, it is generally considered that the charges derived from ab initio calculations are better. Molby does not have capability to perform ab initio calculations, but it can help creating necessary input files for external quantum chemical programs. This will be described elsewhere in this User's Manual.

第六段階:分子力学計算によるエネルギー最小化

1. Molby の分子力学計算について

手作業で作成した分子モデルは、不自然な結合長、結合角、van der Waals 接触などを含んでいます。このような不自然な構造を修正するには、分子力学のテクニックが便利です。

Molby の分子力学計算は、基本的な分子力場(結合の伸縮、結合角のたわみ、二面角の回転、improper torsion、van der Waals 相互作用、静電相互作用)に基づいています。静電相互作用以外については、パラメータのセットが用意してあり、原子に与えられた「原子タイプ」から必要なパラメータを取り出して計算に使います。

デフォルトでは、Molby は gaff パラメータセットを使います。Gaff は "General AMBER Force Field" の略で、AMBER 分子動力学パッケージの一部です。AMBER 開発者の好意により、分子力場パラメータはパブリックドメインとされています。なお、Molby は parm99 パラメータセットも同梱しています。これも AMBER の分子力場であり、生体分子の計算に広く使われています。

分子力場を使うときに厄介なのは、原子タイプをどうやって指定するかです。AMBER には、このための便利なプログラム AmberTools が含まれています。これもまた AMBER 開発者の好意により、AmberTools はフリーソフトウェア(GPLv2)として公開されています。Molby は AmberTools のプログラムの一部を同梱しています。

以下の論文は AMBER 開発チームによるものです。AMBER パラメータや AmberTools プログラムの機能を使った場合は、発表論文にこれらの論文を引用してください。

2. エネルギー最小化の方法

さて、エネルギー最小化をやってみましょう。例として 2,2'-ジメトキシビフェニルを使うことにします。

2,2'-ジメトキシビフェニル

この分子のモデルを作ってください。簡単なやり方は、(1) 空の編集エリアでダブルクリックして "C6H5C6H5" とタイプする。(2) オルト位の水素原子を1つ選択し、ダブルクリックして "OCH3" とタイプする。(3) もう1つの環のオルト位の水素原子について、(2) を繰り返す。

"MM/MD"メニューを開き、"Guess MM/MD Parameters..." コマンドを実行します。

下のようなダイアログが現れます。これは現在の分子に対して Antechamber を実行するためのものです。一番上のチェックボックス "Calculate partial charge" をオフ、その下の "Guess Atom Types" をオンにしてください。"Log" ディレクトリは、AmberTools のプログラムが中間ファイルを保存するのに使います。デフォルトの位置で問題はないでしょうが、変更してもかまいません。

"OK"を押すと、2つのダイアログが順に現れます。すぐに消えてしまうので、何と書いてあるか読めないかも知れません。最初のものは "Running antechamber", 2つめのものは "Running parmchk" と書いてあります。これらは AmberTools に含まれているプログラムです。今の場合は、両方とも正しく実行され、次のダイアログが現れます。

"OK"を押して、分子のウィンドウに戻ってください。何が変わったかわかるでしょうか? 変わったのは原子タイプです。具体的には、原子0と原子10のタイプが "ca" から "cp" に変わっています。

"ca" や "cp" が何の意味か知りたければ、"MM/MD" メニューから "View Global Parameters..." を選んでみてください。Molby に同梱されているパラメータの一覧表が出てきます。"vdw" (van der Waals パラメータの意味ですが、原子タイプの定義も兼ねています)の中で "ca", "cp" を見つけて、表の右端にあるコメントを見てみてください。

分子のウィンドウに戻り、"MM/MD" → "Minimize" を選んでください。

設定ダイアログが開きます。"Steps per frame" は、構造最適化計算がこのステップ数進んだところで画面を更新する、という意味です。"Number of frames" は、この数だけ画面を更新したら計算を止める、という意味です。その前に構造最適化が終了すれば、その時点で計算は止まります。下の図にある 10, 200 を入れておけば、たいていの場合はよいでしょう。

"OK" を押すと、構造最適化が始まります。この分子の場合、期待される通り、2つのベンゼン環の間の二面角がだんだん大きくなります。指定通り、200回画面が更新されると計算は止まります。ウィンドウの右下に "200" という数字があり、ウィンドウの下辺にあるスライダーが有効になっています。更新された画面は、それぞれ独立したフレームとして保存されており、このスライダーを動かすと、初期状態からどのように構造が変わって行くかを再現することができます。

この時点で分子を "mbsf" フォーマットで保存すると、全部のフレームの情報が保存され、ファイルがとても大きくなります。これが好ましくない場合は、現在表示されている以外のフレームを削除することもできます。"Script" メニューから "Delete Frames..." コマンドを使ってください。

3. 静電相互作用の取り扱い

上の説明は、分子構造のひずみを取り除く最初の段階としては十分です。しかしながら、次の段階として、静電相互作用を考慮しなければなりません。特に、カルボニル基などの極性官能基が含まれている場合は、これは重要です。

2,2'-ジメトキシビフェニルについて検討を続けましょう。"MM/MD" → "Guess MM/MD Parameters...", を開き、今度は一番上のチェックボックスをオンにします。そして、分子の総電荷が正しいことを確認してください。この場合は中性分子なので、"0" で結構です。

"OK" を押すと、計算が始まります。今度は、前回よりもずっと長く計算時間がかかります。半経験的分子軌道法により、構造最適化と部分電荷の計算を行うからです。

計算が終了すると、分子構造は少し変化することがあります。半経験的分子軌道計算で構造最適化が行われたからです。また、"charge" の値が設定されていることがわかります。テーブルを右にスクロールすると、与えられた電荷の値を見ることができます。この電荷の値を用いて静電相互作用の計算を行うことにより、極性官能基の相互作用エネルギーをより正しく見積もることができます。

上の方法で計算した電荷は、半経験的分子軌道計算によるものです。一方、一般的には ab initio 計算で求めた電荷の方が良いと考えられています。Molby は ab initio 計算を行う機能を持っていませんが、外部の量子化学計算プログラムへの入力ファイルを作成する機能があります。これは、このマニュアルの別のところで解説します。

Step Seven: Molecular Dynamics (MD) Calculation

1. MD Calculation within Molby

Molby implements molecular dynamics (MD) calculation which uses the same force fields as the energy minimization by molecular mechanics (MM). This implementation is suitable only for preliminary calculations (to check parameters quickly, etc.); for production runs, it is strongly recommended that you use one of the established software packages.

An example of preliminary MD run is presented here. We use 2,2'-dimethoxybiphenyl again. In a similar way as in the step six, create a model and assign MM parameters (including the partial charges on the atoms).

Select MM/MD → Molecular Dynamics. A setting dialog opens. Although this dialog resembles that in MM minimization, it shows different parameters that are relevant to the MD calculation.

The "timestep" parameter defines the minimum time increment in solving the equation of motions. The "target temperature" defines the temperature of the system. Before running the MD calculation, all atoms are let to have random velocities with the Boltzmann distribution corresponding to the target temperature. In addition, the velocities are modified so that the temperature is kept constant. The "steps per frame" and "number of frames" parameters have the same meaning as in the MM minimization. The screenshot shows 10 as the "steps per frame"; this is an appropriate value for MM minimization, however for MD calculations a larger value would be more appropriate (like 100).

Pressing the "Advanced..." button opens another dialog with other parameters. The meanings of the parameters are described in the embedded Ruby document, in the MDArena page.

Return to the original MD dialog (by pressing "Close" in the advanced settings dialog), and press "OK". The MD run starts, and new frames are accumulated. If you find something is wrong, or want to stop before getting the specified number of frames, you can stop the MD run by pressing Command-period (Mac) or Control-period (Windows).

2. Using Molby with AMBER: Creating Inputs and Importing Outputs

For production runs, you can create AMBER input files from Molby. More specifically, you can create "prmtop" and "inpcrd" files for the SANDER module.

Note: There is no guarantee that Molby creates the exactly same input as the official AMBER modeling tools, nor the generated files are valid inputs for the SANDER module. You may need to modify them by hand.

To creat SANDER input files, select "Create SANDER input..." command in the "MM/MD" menu.

You will be asked first for the file name for the "prmtop" file. Please be sure to add ".prmtop" extension. The other file, "inpcrd" file, is created as the same name with the ".prmtop" extension replaced by the ".inpcrd" extension.

Subsequently, you will be asked to select one of the two versions of the prmtop files. The older one, "AMBER8/NAMD", allows you to use the output file by NAMD (see below).

Now you can transfer your files to the workstation running SANDER. To perform the simulation, you still need to create the instruction file for SANDER, which you should already know if you are using AMBER.

After the simulation is over, you can get the trajectory file ("mdcrd" file) back and import to Molby. Use "Import..." command in the "File" menu, select "AMBER mdcrd file (*.crd; *.mdcrd)", and specify the file.

3. Using Molby with NAMD: Creating Inputs and Importing Outputs

You can also use the NAMD software package for production run. NAMD is developed by the Theoretical Biophysics Group in the University of Illinois at Urbana-Champaign, and the official information is found at their web site (http://www.ks.uiuc.edu/Research/namd/). NAMD can use the AMBER "prmtop" as the input, by use of the instruction amber yes. See NAMD Users' Guide for details.

You can also import the NAMD output by importing the dcd file. The file format is also listed in the "Import..." file dialog.

4. Building Solvated Structures

When you want to perform MD simulations in explicit solvent, you need to build a box of solvent molecules around the target molecule. Molby can help creating solvated structures.

To build a solvated structure, you need to open the file containing the predefined box of the desired solvent. The following solvent box is included in the Molby package, and can be accessed from "File" → "Open Predefined" → "Solvent boxes" submenu. The tip3box was taken from the AmberTool package, and other solvent boxes were taken from Amber parameter database.

namesolventreference
tip3pbox water Jorgensen, W. L.; Chandrasekhar, J.; Madura, J.; Klein, M. L.
J. Chem. Phys. 1983, 79, 926.
chcl3box chloroform Cieplak, P.; Caldwell, J. W.; Kollman, P. A.
J. Comp. Chem. 2001, 22, 1048.
dmsobox dimethylsulfoxide Fox, T.; Kollman, P. A.
J. Phys. Chem. B 1998, 102, 8070.
meohbox methanol Caldwell, J. W.; Kollman, P. A.
J. Phys. Chem. 1995, 99, 6208.
nmabox N-methylacetamide Caldwell, J. W.; Kollman, P. A.
J. Phys. Chem. 1995, 99, 6208.

While keeping the solvent box open, create or open the target (solute) molecule in a separate window. With this solute molecule in the front window, select "Solvate..." command in the "MM/MD" menu.

A dialog box opens.

In the popup menu "Choose solvent box:", you will find the solvent box you opened earlier. Note that this popup menu lists all open molecules that have the associated periodic box (or unit cell). This can lead to a confusing situation that, if you have another solvated structure also open, that structure will also be listed in this popup menu, because a solvated structure always have a periodic box. Therefore, please take care so that you choose the right solvent box.

If you open the solvent box from the "Open Predefined" menu, you can easily recognize it in the popup menu, because the name has asterisks at the beginning and the end, like "*CHCl3*".

The "Box offset" parameters define the thickness of the solvent layer surrounding the solute molecule. More specifically, the periodic box of the solvated structure is determined as follows: the minimum cuboid that can surround the solute molecule is defined, and all the faces are offset by the "Box offset" distances to the outside direction. On the other hand, it is possible to define the size of the periodic box explicitly for any of the three (x, y, z) directions. If you wish to do this, give a negative number for that direction. (For example, if you want the periodic box to be 40 Å in the x direction, give -40 as the first "Box offset" parameter.)

The size of the periodic box can be checked by selecting "Xtal" → "Unit Cell..." menu command, or in the property table (the "unit cell" property).

The "Exclusion limit distance" defines the minimum allowed distance between the solvent and solute molecules. The solvent molecule is removed when it has atoms with smaller distances than this parameter from the solute molecule.

第七段階:分子動力学計算

1. Molby 組み込みの分子動力学 (MD) 計算

Molby は分子動力学 (MD) 計算を実装しています。これは分子力学によるエネルギー最小化と同じ分子力場を使います。この機能は、パラメータのチェックなどの予備的な計算に使うことを想定しています。本格的な計算には、実績のある他のソフトウェアパッケージを使うことを強くおすすめします。

予備的な MD 計算の例を示します。また 2,2'-ジメトキシビフェニルを使います。第六段階と同様に、モデルを作成して分子力場パラメータを決定してください(原子上の部分電荷も)。

MM/MD メニューの "Molecular Dynamics" を選ぶと、設定ダイアログが開きます。このダイアログは分子力場によるエネルギー最小化の時と似ていますが、MD 計算に使う他のパラメータを表示しています。

"Timestep" パラメータは、運動方程式を解くときの最小時間刻みを表します。"Target temperature" は系の温度を表します。MD 計算が始まる際に、すべての原子はこの温度に対応するボルツマン分布に従ってランダムな速度を与えられます。さらに、MD 計算中は温度が一定に保たれるように速度が調整されます。"Steps per frame" と "number of frames" パラメータは分子力学によるエネルギー最小化の時と同じ意味を持ちます。このスクリーンショットでは "steps per frame" が 10 になっています。これはエネルギー最小化では適切な値ですが、分子動力学の場合はもう少し大きな値(たとえば 100)の方がより適切です。

"Advanced..." ボタンを押すと、他のパラメータを持つ別のダイアログが開きます。これらのパラメータの意味は、内蔵 Ruby インタプリタのリファレンスで MDArena のページに書かれています。

元の MD 設定ダイアログに戻り(詳細設定ダイアログで "Close" ボタンを押す)、"OK" を押します。MD 計算が始まり、新しいフレームが追加されて行きます。何か問題があったり、指定したフレーム数よりも前に計算を止めたいときは、コマンド-ピリオド (Mac) かコントロール-ピリオド (Windows) を使ってください。

2. AMBER とともに使う:入力の作成と出力結果のインポート

本格的な計算を行うために、Molby で AMBER への入力ファイルを作成することができます。具体的には、SANDER モジュールの入力となる "prmtop" と "inpcrd" ファイルを作ることができます。

注: Molby が AMBER 付属のモデリングツールと同じ入力ファイルを作成する保証はありませんし、SANDER モジュールへの正しい入力になっている保証もありません。手作業で修正が必要な場合もあるかもしれません。

SANDER の入力ファイルを作るには、"MM/MD" メニューから "Create SANDER input..." コマンドを選んでください。

最初に "prmtop" ファイルの名前を聞かれます。必ず ".prmtop" 拡張子をつけるようにしてください。もう一つの "inpcrd" ファイルは、".prmtop" を ".inpcrd" に置き換えた名前で保存されます。

次に、prmtop ファイルの2つのバージョンのうち1つを選ぶように促されます。古い方、"AMBER8/NAMD" を使えば、NAMD ソフトウェアパッケージ(下記参照)でも使える入力ファイルができます。

これで、SANDER が走るワークステーションにファイルを転送することができます。シミュレーションを実行するためには、SANDER の命令ファイルを作らなければなりませんが、AMBER をお使いの方ならやり方はよくご存知でしょう。

計算が終了したら、トラジェクトリファイル ("mdcrd" ファイル) を取得して、Molby にインポートすることができます。"File" メニューの "Import..." コマンドを選び、ファイルタイプとして "AMBER mdcrd file (*.crd; *.mdcrd)" を選んで、ファイルを読み込んでください。

3. NAMD とともに使う:入力の作成と出力結果のインポート

本格的な計算を行うために NAMD を使うこともできます。NAMD はイリノイ大学アーバナ・シャンペーン校の理論生物物理グループが開発したソフトウェアパッケージです。公式ウェブサイトは http://www.ks.uiuc.edu/Research/namd/ です。NAMD は AMBER の "prmtop" を入力として使うことができます(amber yes 命令を使う)。詳しくは NAMD のユーザーズガイドをご覧ください。

NAMD の出力の dcd ファイルもインポートが可能です。"Import..." コマンドのファイルタイプで選択することができます。

4. 溶媒和構造の作成

明示的な溶媒中での MD シミュレーションを行うためには、目的分子の回りに溶媒分子の箱を作る必要があります。Molby でこのような溶媒和構造を作成することができます。

溶媒和構造を作るためには、まず使用する溶媒の箱を読み込む必要があります。以下の溶媒の箱が Molby に同梱されており、"File" → "Open Predefined" → "Solvent boxes" サブメニューから選ぶことができます。Tip3box は AmberTool パッケージから得たものであり、他の溶媒箱は Amber parameter database で公開されているものです。

namesolventreference
tip3pbox water Jorgensen, W. L.; Chandrasekhar, J.; Madura, J.; Klein, M. L.
J. Chem. Phys. 1983, 79, 926.
chcl3box chloroform Cieplak, P.; Caldwell, J. W.; Kollman, P. A.
J. Comp. Chem. 2001, 22, 1048.
dmsobox dimethylsulfoxide Fox, T.; Kollman, P. A.
J. Phys. Chem. B 1998, 102, 8070.
meohbox methanol Caldwell, J. W.; Kollman, P. A.
J. Phys. Chem. 1995, 99, 6208.
nmabox N-methylacetamide Caldwell, J. W.; Kollman, P. A.
J. Phys. Chem. 1995, 99, 6208.

溶媒箱を開いたまま、目的とする分子(溶質)を新しいウィンドウで開くか作成します。溶質分子のウィンドウを最前面にした状態で、"MM/MD" メニューから "Solvate..." コマンドを選びます。

ダイアログが開きます。

ポップアップメニュー "Choose solvent box:" には、さきほど開いた溶媒箱がリストされているはずです。注意していただきたいのは、このポップアップメニューには周期境界(または単位格子)を持つすべての分子がリストされることです。このため、紛らわしいことに、別の溶媒和構造を同時に開いていると、その構造もこのポップアップメニューに登場してしまいます(溶媒和構造は必ず周期境界を持っていますから)。ですから、正しい溶媒箱を選ぶように十分に注意してください。

"Open Predefined" メニューから選んで開いた溶媒箱はすぐに区別できます。名前の前後に * がついているからです ("*CHCl3*" のように)。

"Box offset" パラメータは、溶質分子の回りを囲む溶媒層の厚さを指定します。言い換えると、これから作成する溶媒和構造の周期境界は次のように決められます:まず溶質を囲む最小の直方体を算出し、それぞれの面を外側に向かって Box offsect パラメータ分だけ移動させます。一方、x, y, z のそれぞれの方向に対して、周期境界の大きさを決めたい場合もあります。このときは、その方向の Box offset パラメータに負の値を指定してください。(たとえば、x 方向の周期境界を大きさを 40 Å にしたい時は、"Box offset" の最初のパラメータを -40 にしてください。)

周期境界の箱の大きさは、"Xtal" → "Define Unit Cell" メニューを選ぶと見ることができます。また、属性テーブルの "unit cell" でも見られます。

"Exclusion limit distance" は、溶質分子と溶媒分子の原子間距離の最小値を定めます。溶媒分子のある原子が溶質分子からこの距離以内に近づいているとき、その溶媒分子は取り除かれます。

Step Eight: MM/MD Calculation of Coordination Compounds

1. Use of UFF (Universal Force Field) Parameters

Building molecular models of coordination compounds is often problematic. This is mainly due to the lack of appropriate MM parameters for metal atoms. One reasonable approach is to use UFF (universal force field) parameters developed by Rappé and coworkers (J. Am. Chem. Soc. 114, 10024-10035 (1992)). Although estimation of the UFF parameters from the molecular structure is rather complicated, it can be automated by computer programs. In the following, you will see how Molby can help modeling of coordination compounds with the UFF parameters.

Suppose we want to build a model of (terpy)PtCl, where terpy is 2,2':6',2"-terpyridine.

We need to build the molecular structure first. One approach is to build the organic part (terpy), and put metal atoms afterwards. Here, we will go through another route, namely start from the metal fragment and add ligands afterwards. In general, this approach should be more successful in building models of coordination compounds.

Select "Open Predefined..." menu item, and find "MX4 square-planar" like below.

A square planar fragment of "CuCl4" appears on the screen.

Choose the "Select" tool, double click on one of the chlorine atoms, and type "C6H5".

You see now a phenyl group is attached to the metal atom. The orientation of the phenyl ring needs to be fixed. Select the metal-C bond, and rotate the phenyl ring so that the ring is approximately coplanar with the metal-ligand plane.

Attach two other phenyl groups in a similay manner.

Remove the hydrogen atoms and create C-C bonds. Double-click on the carbon atoms connected to the metal, and change them to "N". Double-click on the metal atom and change it to "Pt".

Now the molecular structure is complete. Next we need to assign the MM parameters. To do this, select the "Guess UFF Parameters..." from the "MM/MD" menu.

A dialog like below opens up. Here are listed the atoms that are (1) the metal atoms, (2) the ligand atoms that are connected to the metal atoms, and (3) the ligand atoms that are connected to any of the atoms in (2). In other words, the atoms within "two-bonds" distances are shown in this dialog. The Pt atom is shown in red, because it does not have predefined MM parameters. The ligand atoms already have their MM parameters, but if you look closely not all atoms are correctly recognized. For example, the pyridine N atoms are incorrectly assigned as "n3", which is a sp3 nitrogen.

The UFF parameter estimation consists of two stages. The first stage is to assign the types of the ligand atoms. This is basically the same as the procedure described in Step 6, but this time we need to run Antechamber for the non-metal part only. By hitting the button "Run Antechamber for Non-Metal Fragment", Antechamber is executed for each non-metal fragments. You may need to assign the charge for each fragment; for example, if you are using catecholato ligand, that fragment should have charge of -2.

The fragment that are being assigned by Antechamber is shown in the main window as the selection. In this example, the first fragment contains only the chlorine atom, and the second fragment is the terpyridine ligand.

After running Antechamber, the table looks like below. Note that the values in the "type" column have been changed.

Next, we need to assign the "UFF types" to each atoms. In fact, the UFF types are already set in the previous stage. We still need to look at them, and correct the types if necessary. You can select the predefined UFF types from the popup menu.

Now we need to assign UFF parameters for the metal atoms. Click the button "Guess UFF Parameters for Bonds and Angles Including Metal Atoms".

Open the "Bonds" page, and check the columns "k" and "r0". You will find there the proposed values of force constant and equilibrium bond length, according to the UFF force field. If you find, by some reason, the values are not appropriate, then you can change them by hand.

You can check the "Angles" page as well. Check the columns "k" and "a0", for the force constant and equilibrium bond angle. Note that, in the case of square planar or octahedral metal center, there are "cis" and "trans" angles. The program will assign "trans" if the current bond angle is larger than 135 degree, and "cis" otherwise. So, if your starting geometry is not quite optimal, be careful to check the angle parameters.

Close this dialog, and go into MM/MD calculations as usual. For example, you can perform energy minimization and get the structure like below.

2. Compounds Containing Metal-π Bonds

Compounds containing metal-π bonds are also problematic in molecular mechanics calculations. The implementation of metal-π bonds in Molby is based on the proposal by Doman and coworkers (J. Am. Chem. Soc. 114, 7262-7272 (1992)). Herein we will see how to build a molecular model of ferrocene.

We start with the predefined structure "cyclopentadienyl."

Select the five carbon atoms, and do "Create Pi Anchor" menu command.

"Pi anchor" is a virtual atom, whose coordinates are defined as the center of mass of the "parent" atoms. In this case, the parent atoms of the pi anchor is the carbon atoms of the Cp ring. In the main screen, the pi anchor is shown as a green dot, and it is connected to the parent atoms by a green thin bonds.

Rotate the ring to show the "side view" of the ring, while keeping the pi anchor barely visible. Create a bond from the pi anchor to a new atom. Change the new atom to Fe.

Copy the cyclopentadienyl ring and the pi anchor, and paste in the same window. Place the new ring to the appropriate position, and bond the Fe atom and the new pi anchor.

Finally, make a bond between the two pi anchors. This is necessary to describe the barrier for ring rotation. The anchor-anchor bond is shown as a half-transparent green stick.

The ring rotation can be described as a dihedral term in the form of "ring atom"-"pi anchor"-"metal"-"X". However, in the case of a linear metallocene, "X" is the other pi anchor. Since the "pi anchor"-"metal"-"pi anchor" angle is always close to 180 degree, the dihedral angle cannot be defined. For this reason, the linear metallocene requires special treatment of the dihedral term in the form of "ring atom"-"pi anchor"-"pi anchor"-"ring atom". That is why we need to make a bond between two pi anchors. This is not the case for the bent metallocenes (like Cp2TiCl2), or half-sandwich complexes.

Now we can go on to the UFF dialog as before. This time, we skip the "non-metal fragments" part, because Antechamber cannot handle cyclopentadienyl anion. Our cyclopentadienyl ring already has correct atom types, so we will use them as they are.

Change the UFF type of the Fe atom to "Fe2+ octahedral".

Click on the "Bonds" label, and change the "r0" parameter of the two bonds of "##-fe" or "fe-##" type ("##" represents the pi anchor). This should be the metal-pi distance, which is 1.66 Å for ferrocene.

The "Angle" page should also be edited. The "a0" parameter is set to 90.0 for the "fe-##-ca" type angles (ten lines from the top), and 180.0 for the "##-fe-##" type angle (the last line).

Hit the "Guess UFF Parameters..." button to complete the calculation of the UFF parameters.

You can now try the MM/MD calculation. Energy minimization results in an eclipsed conformation. MD at 298K shows that the Cp rings freely rotate at this temperature.

第八段階:配位化合物のMM/MD計算

1. UFF (Universal Force Field) パラメータを使う

配位化合物の分子モデル作成にはいろいろ問題があります。主な問題は、金属原子の分子力学パラメータが用意されていないことです。一つの合理的な方法は、Rappéらによって提案された UFF (universal force field) パラメータを使うことです (J. Am. Chem. Soc. 114, 10024-10035 (1992))。 分子構造から UFF パラメータを見積もるのはやや複雑な作業ですが、プログラムによって自動化することは可能です。以下に、UFF を用いた配位化合物のモデルングに Molby がどのように利用できるかを示します。

例として、(terpy)PtCl の分子モデルを作ってみましょう。terpy は 2,2':6',2"-terpyridine です。

最初に分子構造を作らなくてはいけません。一つの方法は、まず有機分子の部分 (terpy) を作成し、金属を後から付け加えることです。ここでは、別の方法を使ってみます。つまり、最初に金属回りの配位構造から始め、あとで配位子を付け加えます。一般的には、こちらの方が配位化合物のモデリングには適しています。

"File" メニューから "Open Predefined..." を選び、下のように "MX4 square-planar" を見つけてください。

平面四配位の "CuCl4" 構造が現れます。

"Select" ツールを選び、塩素原子の1つをダブルクリックして、"C6H5" とタイプします。

金属原子にフェニル基が結合しました。環はこの向きではいけませんので、金属-炭素結合を選択して、フェニル基を回転させ、環が金属・配位子平面と同一平面になるようにします。

他の2つの塩素原子も同様にフェニル基に置き換えます。

水素原子を削除して炭素−炭素結合を作成します。それから、金属に結合している炭素原子をダブルクリックして、"N"原子に変えます。金属原子をダブルクリックして、 "Pt" に変えます。

これで分子構造はできあがりました。次に、分子力学パラメータを設定します。"MM/MD"メニューから "Guess UFF Parameters..." コマンドを選択します。

下のようなダイアログが開きます。表に原子が並んでいますが、この原子は (1) 金属原子、(2) 金属原子に結合している原子、(3) (2) の原子のいずれかに結合している原子、のどれかです。言い換えれば、金属原子から「結合2つ分」以内の原子が表示されています。Pt 原子の行は赤色で表示されています。分子力学パラメータが定義されていないことを表しています。配位子の原子はすでに分子力学パラメータを持っていますが、よく見ると、間違っているものもあります。例えば、ピリジンの N 原子は "n3" タイプになっていますが、これは sp3 窒素です。

UFF パラメータの作成はいくつかの段階を要します。最初に、配位子の原子タイプを正しく設定します。この作業は、第六段階 で行ったのとほぼ同じですが、今回は金属原子を除いた部分構造について Antechamber を実行する必要があります。"Run Antechamber for Non-Metal Fragment" ボタンを押すと、この作業が自動的に行われます。各部分構造について、電荷を与える必要があるかも知れません。例えば、カテコラト配位子を使っているなら、電荷は -2 となります。

Antechamber を走らせる部分構造は、メインウィンドウで選択されて表示されます。ここの例では、1番目の部分構造は塩素原子1個だけを含み、2番目の部分構造はターピリジンになります。

Antechamber を走らせると、表は下のようになります。"type" 列の値が変わっていることに注意してください。

次に、各原子の "UFF type" を設定します。前の段階で UFF type を仮に設定してありますが、一通り見直して、必要なら変更してください。UFF type はポップアップメニューで選択することができます。

今度は、金属原子のパラメータを設定します。"Guess UFF Parameters for Bonds and Angles Including Metal Atoms" ボタンを押してください。

"Bonds" ページを開いて、"k" と "r0" の列を見てください。UFF 分子力場から予測された「力の定数」と「結合長」が入っているはずです。何らかの理由で、値が適切ではないと考えた場合は、手動で変更することもできます。

"Angles" ページも同じようにチェックしてください。"k" と "a0" の列に「力の定数」と「結合角」が入っています。金属中心が、平面正方形、または八面体構造の場合は、"cis" と "trans" の角度があります。プログラムは、現在の結合角が 135度よりも大きければ "trans" とみなし、小さければ "cis" とみなします。現在の構造が理想的な構造から離れている場合は、角度のパラメータを注意深くチェックしてください。

このダイアログを閉じて、MM/MD 計算を通常のように進めます。例えば、エネルギー最小化を行うと、下のような構造が得られます。

2. 金属-π 結合を持つ化合物

分子力学計算では、金属-π結合を持つ化合物の取り扱いも厄介です。Molby は、Doman らの方法 (J. Am. Chem. Soc. 114, 7262-7272 (1992)) に準じて金属-π結合の分子力学計算を実装しています。ここでは、フェロセンの分子モデルを作成してみます。

"Open Predefined" から "cyclopentadienyl" を選びます。

5つの炭素原子を選択し、"Create Pi Anchor" メニューコマンドを実行します。

"Pi anchor" とは、「親」原子の重心を座標とする仮想的な原子です。今回は、シクロペンタジエニル環の5つの炭素原子(上で選択したもの)が pi anchor の親になります。スクリーン上では、pi anchor は緑色の小さな球で表し、親原子とは緑色の半透明の棒でつないで表示されます。

環を回転させて、横から見た向きにします。Pi anchor はぎりぎり見えるようにしておきます。Pi anchor から結合を出して、新しい原子を作ります。新しい原子を Fe に変えます。

シクロペンタジエニル環と pi anchor をコピーして、同じウィンドウ内にペーストします。新しい環を Fe 原子をはさんで反対側に移動し、新しい pi anchor と Fe 原子を結合させます。

最後に、2つの pi anchor の間に結合を作ります。これは、環の回転障壁を正しく見積もるために必要になります。Anchor 同士の結合は、半透明の緑色で示されます。

環の回転は「環の原子-pi anchor-金属-他の原子」という二面角項で表されます。メタロセンの場合、「他の原子」はもう一つの pi anchor になります。ところが、直線型のメタロセンだと、「pi anchor-金属-pi anchor」の角度は常に 180°付近であるため、二面角を正しく定義することができません。このため、直線型メタロセンでは、特別に「環の原子-pi anchor-pi anchor-環の原子」という二面角で環の回転を表現します。この理由で、2つの pi anchor の間に結合を作る必要があるのです。曲がったメタロセン (Cp2TiCl2 など) や、ハーフサンドイッチ型の錯体では、このような扱いは不必要です。

ここからは、前と同じように UFF のダイアログを使うことが出来ます。今回は、"non-metal fragments" の計算は省略します。Antechamber はシクロペンタジエニルアニオンを正しく取り扱うことができないためです。私たちのシクロペンタジエニル環はすでに正しい原子タイプを持っていますので、これをそのまま使います。

Fe の UFF タイプを "Fe2+ octahedral" に変更します。

"Bonds" ラベルをクリックし、"##-fe" または "fe-##" タイプの結合の "r0" パラメータの値を変更します("##" は pi anchor を意味します)。この値は金属-π結合の距離です。フェロセンの場合は 1.66 Å になります。

"Angles" ページも編集が必要です。今回は手動で金属原子を作成したため、角度が正しくなっていないからです。"fe-##-ca" タイプの角度は 90.0(上から10行分)、"##-fe-##" タイプの角度は 180.0(一番下の行)にします。

"Guess UFF Parameters..." ボタンを押して、UFF パラメータの計算を行います。

これで MM/MD 計算を試すことができます。エネルギー最小化を行うと、重なり型の配置が得られます。298K で MD を行うと、Cp 環がこの温度で自由回転していることがわかります。

Step Nine: Collaboration with Other Quantum Chemistry Softwares

Molby has a capability to export and import files for quantum chemistry softwares, namely Gaussian and GAMESS. At present, the capability is quite limited, and in many cases it would be much better to use other established softwares. Nevertheless, if you are already familiar with Molby, you may want to use Molby for creating input files for Gaussian and GAMESS and processing outputs. Here are instructions how to do it.

Needless to say, you need to have access to Gaussian or GAMESS program packages. They can be on the same machine or on other machines (workstations) than Molby. Please learn how to use these packages before using Molby as described in this section.

1. Using Gaussian

The Gaussian input can be created by selecting "Export..." command in the "File" menu. The file extension is either "gjf" (as is the convention in GaussianW) or "com" (as in UNIX version of Gaussian).

The output will look like this. Although Molby can create only one type of Gaussian input (optimize with PM3), it should be relatively easy to modify the generated input file by hand.

%Chk=benzene.chk # PM3 Opt unnamed1; created by Molby at Sat Feb 11 00:30:21 +0900 2012 0 1 C -0.653000 0.585000 -1.068000 H -1.158000 1.039000 -1.898000 C 0.729000 0.607000 -1.003000 H 1.295000 1.076000 -1.783000 C 1.382000 0.021000 0.069000 H 2.452000 0.038000 0.119000 C 0.651000 -0.586000 1.076000 H 1.156000 -1.039000 1.906000 C -0.732000 -0.607000 1.012000 H -1.298000 -1.077000 1.792000 C -1.384000 -0.021000 -0.060000 H -2.455000 -0.038000 -0.110000

When you do geometrical optimization, you may want to examine how the structure changes as the calculation proceeds. This can be done by importing the Gaussian output file. The extention should be either ".out" or ".log".

2. Using GAMESS

Creating GAMESS input can be more complicated than Gaussian, so that Molby provides a simple dialog to help creating GAMESS input. The dialog is accessible from the "Creating GAMESS input..." command in the "QChem" menu.

You can specify various settings in the dialog.

When the calculation of GAMESS is complete, you will find two output files, namely *.log and *.dat. Either format can be imported by use of the "Import..." menu command. Some informations are included in both (e.g. coordinates during structural optimization), but other informations are only in one of these files (e.g. the full description of gaussian functions is only in the *.log file, whereas the orbital coefficients with full precision are only in the *.dat file). You need to be familiar with the structure of the GAMESS output files to fully utilize the GAMESS import capability of Molby.

3. Using GAMESS for calculation of the RESP charges

We already saw how to assign partial charges for evaluation of electrostatic interactions in MM calculations. There we used semi-empirical calculations, although ab initio calculations will give better results if possible. Here are instructions how to do it using GAMESS.

Select "MM/MD" → "GAMESS/RESP...".

The following window pops up. As the first step, press the "Create GAMESS Input..." button.

The familiar GAMESS dialog opens up. It is most important to turn on the "Calculate electrostatic potential (ESP)" checkbox (it should be turned on if you follow the steps as described here, but please double-check). Also make sure that the charge and multiplicity are correct, and select a suitable basis set (6-31G(d) is recommended).

Press OK to create the GAMESS input, and send it to GAMESS. The calculation will take time, so that you can finish Molby (after saving the molecule as a msbf file!), and work on something else at this stage.

After the GAMESS calculation is complete, open the same molecule, and select "MM/MD" → "Tools" → "GAMESS/RESP..." again. This time, follow the second step by pressing the "Import GAMESS dat..." button.

Select the GAMESS dat file (which should be available when the GAMESS calculation ends successfully), and import it. When the import is complete, the "Run RESP..." button should be enabled. If it does not, the imported dat file does not have the electrostatic potential information. Start over from the step 1, and make sure that the "Calculate electrostatic potential (ESP)" checkbox is on.

Press the "Run RESP..." button, and the following dialog opens. This is almost the same as the dialog for Antechamber described before.

Press the "OK" button, and the RESP charge will be assigned to the atoms.

第九段階:他の量子化学ソフトウェアとの連携

Molby は量子化学計算ソフトウェア GaussianGAMESS のファイルを作成/読み込みする機能を持っています。現状では、Molby には極めて制限された機能しかないため、おそらく他の実績あるソフトウェアを使った方がよいでしょう。しかし、Molby の操作に慣れているなら、Gaussian や GAMESS の入力を作成して結果を読み込むのに Molby を使いたいことがあるかもしれません。どのようにすればよいかを説明します。

当然のことながら、Gaussian や GAMESS のプログラムパッケージが使えることが前提です。これらが走るのは、Molby と同じマシン上でも異なるマシン(ワークステーション)上でも構いません。この項で説明するやり方で Molby を使う前に、これらのプログラムパッケージをどのように使うかを学んでおいてください。

1. Gaussian を使う

Gaussian の入力は "File" → "Export..." コマンドを使えば作成することができます。ファイルの拡張子は "gjf"(GaussianW での習慣)、または "com"(UNIX 版での習慣)です。

できあがったファイルは次のようになります。Molby が作成できるのは、一種類の Gaussian 入力ファイル(PM3 による構造最適化)だけですが、Gaussian の入力ファイルを手作業で修正するのは比較的簡単です。

%Chk=benzene.chk # PM3 Opt unnamed1; created by Molby at Sat Feb 11 00:30:21 +0900 2012 0 1 C -0.653000 0.585000 -1.068000 H -1.158000 1.039000 -1.898000 C 0.729000 0.607000 -1.003000 H 1.295000 1.076000 -1.783000 C 1.382000 0.021000 0.069000 H 2.452000 0.038000 0.119000 C 0.651000 -0.586000 1.076000 H 1.156000 -1.039000 1.906000 C -0.732000 -0.607000 1.012000 H -1.298000 -1.077000 1.792000 C -1.384000 -0.021000 -0.060000 H -2.455000 -0.038000 -0.110000

構造最適化を行ったあとは、構造がどのように変化するか見てみたいと思うでしょう。これは、Gaussian 出力ファイルを読み込めば実現できます。拡張子は ".out" または ".log" でなくてはなりません。

2. GAMESS を使う

GAMESS の入力を作成するのは Gaussian よりもずっと複雑なので、専用のダイアログが用意されています。このダイアログは、"QChem" → "Creating GAMESS input..." コマンドで開くことができます。

このダイアログでは、いろいろな設定を決めることができます。

GAMESS の計算が終了すると、*.log と *.dat の2つのファイルができます。どちらも "Import..." コマンドで読み込むことができます。ある種の情報(たとえば構造最適化途中の座標)はどちらのファイルにも含まれていますが、その他の情報はどちらか一方にしか含まれません(たとえば、基底を構成する Gaussian 関数の完全な係数は *.log ファイルにしかなく、精度の高い軌道係数は *.dat にしかありません)。GAMESS 読み込み機能を十分に活用するには、GAMESS の出力が何を含んでいるかをよく理解する必要があります。

3. GAMESS を用いて RESP 電荷を計算する

分子力学計算で静電相互作用を評価するための部分電荷の計算についてはすでに説明しました。そこでは半経験的分子軌道計算を用いましたが、可能ならば ab initio 計算の方がよい結果を与えます。GAMESS を使って計算する方法を説明します。

メニューより "MM/MD" → "GAMESS/RESP..." を選びます。

次のウィンドウが開きます。第1のステップとして、"Create GAMESS Input..." ボタンを押します。

GAMESS のダイアログが開きます。大切なのは、"Calculate electrostatic potential (ESP)" チェックボックスをオンにすることです(ここの手順に従えば、自動的にオンになっているはずですが、一応確認してください)。分子の電荷・スピン多重度が正しいことを確かめ,基底関数 (6-31G(d) がおすすめ) を指定してください。

OK ボタンを押して GAMESS 入力を作成し、GAMESS で計算を実行してください。計算には時間がかかりますから、この時点で Molby を終了して他の作業をしていただいて構いません(ただし、分子ファイルを mbsf 形式で保存することを忘れないで!)。

GAMESS 計算が完了したら、同じ分子ファイルを開き、"MM/MD" → "Tools" → "GAMESS/RESP..." をもう一度選択してください。今度は、第2ステップの "Import GAMESS dat..." ボタンを押します。

GAMESS の dat ファイルを選択し(GAMESS の計算が成功すればこれができているはずです)、読み込んでください。読み込みが完了したら、"Run RESP..." ボタンが有効になっているはずです。もしそうならなかったら、読み込んだ dat ファイルに静電ポテンシャルのデータが含まれなかったということです。もう一度第1ステップからやり直し、特に "Calculate electrostatic potential (ESP)" チェックボックスがオンになっていることを確かめてください。

"Run RESP..." ボタンを押すと、次のダイアログが開きます。これは、前に説明した Antechamber のダイアログとほとんど同じです。

"OK"ボタンを押すと、RESP 部分電荷が各原子に対してアサインされます。

Step Ten: Working with Crystal Structures

Information obtained from single-crystal X-ray analysis is a very important source of molecular structure. Molby can import crystallographic information files (CIFs) and handle structural data included in them. Although Molby does not have capability of solving structures from diffraction data, it does provide convenient features for viewing and examining crystal structures.

1. Importing a CIF file

Select "Open..." menu command in the "File" menu, and choose "Crystallographic Information File (CIF)" as the file type.

Select a CIF file and hit "Open". If the molecule has crystallographic symmetry, it should have bonds including symmetry related atoms. In this case, a dialog like below is shown and you are asked how to handle such bonds.

If the molecule is discrete with an imposed crystallographic symmetry, the default selection (the second one) should work all right. In other cases, where the molecule is an infinite chain, the first choice may make more sense. Expansion by symmetry is also available as a separate command, so it is also safe to ignore extra bonds at this stage (the third choice) and do symmetry expansion later.

After expansion, the molecule looks like this. The atoms with darker colors are "expanded atoms."

Molby internally handles all atomic positions as cartesian coordinates. However, the fractional coordinates can be calculated "on-the-fly." In the property table, you can choose to display the fractional coordinates (together with the site occupancies and isotropic temperature factors) as below.

2. Examining the Crystal Structure

Commands for examining the crystal structure are available in the "Xtal" menu.

2-1. Unit Cell

The "Unit Cell" command is used to set the unit cell parameters. It is also possible to set the origin and the unit cell axes directly.

2-2. Symmetry Operation

The "Symmetry Operation" command is used to add/remove the symmetry operation, or change the space group.

Hitting the "Select..." button causes another dialog to open, where you can choose one of the predefined space groups. All 230 space groups are included with various origin and axis settings (not all possible choices are covered though).

2-3. Symmetry Expansion

The "Complete by Symmetry" command is used to expand the molecular fragment in the asymmetric unit. It is supposed to work similarly as the "expand fragments" option in loading CIFs, but the result may be different. (This is because, in the "Complete by Symmetry" command, the bonds between different asymmetric units are "guessed" based on interatomic distances instead of being read from the CIF file.)

The "Create Packing Diagram" command generates symmetry-related atoms within the given range of the fractional coordinates.

The "Show Periodic Image" command does not generate new atoms, but shows the periodic images of the present unit cell.

The "Remove Expanded Atoms" command removes the atoms generated by symmetry expansion. There are two options; one is to remove all expanded atoms, and the other is to remove only those atoms that are included in completely expanded fragments (i.e. the fragments containing at least one non-expanded atoms will be kept unchanged).

The result looks like below. Note that the periodic images are still shown, because they are not expanded atoms but just images shown on the screen.

2-4. Bonds, Angles, and Planes

The "Bonds and Angles with Sigma..." command is used to calculate the interatomic distances and angles with the standard deviations.

Hit "Add Bond" or "Add Angle" button to create a new entry, then select the atoms one by one in the main window. After adding one "bond" and one "angle", the window looks like below. Note that you can choose atoms that are not connected via chemical bonds.

To use the calculated information in other applications (like pasting into a word processor), select the table rows and hit "Export to Clipboard." The information is copied as a plain text (one line per row) that can be pasted into other applications.

The "Best-Fit Planes" command is used for calculating mean planes, angles between the planes, and distances of atoms from the plane. After the dialog is opened, the set of atoms can be assigned by selecting the atoms in the main window and hit one of the "Set Current Selection" buttons.

2-5. ORTEP Drawing

The "Show ORTEP" command open the dialog like below.

The ORTEP drawing is created by the bundled ORTEP-III program. The following citation should be made when using the output.

On this dialog, you can choose the appearance of the atoms and bonds. The orientation of the drawing is similar (although not completely the same) as in the main window. The drawing can be exported as an ORTEP input file or a graphic file (either as an encapsulated PostScript file, a PNG file or a TIFF file). When exporting to a bitmap file, the drawing is done at resolution of 360 dpi.

第十段階:結晶構造を取り扱う

単結晶X線構造解析は、分子構造の重要な情報源です。Molby は、結晶情報ファイル (CIF) を読み込み、構造データを取り扱うことができます。回折データから構造解析を行うことはできませんが、結晶構造を表示したり調べたりするのに便利な機能を持っています。

1. CIFデータの読み込み

"File" メニューから "Open..." コマンドを選び、ファイルタイプとして "Crystallographic Information File (CIF)" を選択します。

CIF を選んで "Open" を押します。CIF の中の分子は、対称操作で関連づけられた原子との間に結合を持っていることがあります。このような場合は、下のダイアログが表示されます。

分子が無限鎖でなく、自分自身の中に結晶学的な対称性を持っている場合は、2番目の選択肢(これが標準です)でうまくいきます。分子が無限鎖の場合は、1番目の選択肢の方が合理的です。また、対称操作で分子を拡大する機能は後でも使うことができますので、この段階では「外との結合」を無視する(3番目の選択肢)ことにしても構いません。

対称操作によって拡大すると、分子は下のようになります。暗い色で表示されているのは、対称操作によって作られた原子です。

Molby の内部では、すべての原子座標は直交座標で扱われています。しかし、単位格子内の部分座標も計算することができます。属性テーブルで "xtal coords" を選ぶと、部分座標と占有数・温度因子を表示できます。

2. 結晶構造を調べる

結晶構造を調べるためのコマンドは "Xtal" メニューにあります。

2-1. 単位格子

"Unit Cell" コマンドは、単位格子のパラメータを設定するのに使います。原点と単位格子の軸ベクトルを直接設定することもできます。

2-2. 対称操作

"Symmetry Operation" コマンドでは、対称操作を追加・削除したり、空間群を設定したりできます。

"Select..." ボタンを押すと、もう一つ別のダイアログが開きます。ここでは、あらかじめ定義された空間群を選択することができます。230 の空間群すべてがいろいろな原点・軸の設定で登録されています(すべての選択肢が網羅されている訳ではありませんが)。

2-3. 対称操作による拡大

"Complete by Symmetry" コマンドは、非対称単位内の分子の部分を対称操作によって拡大するために使います。これは、CIF を読み込む時のオプションと同様に機能しますが、結果は少し違うこともあります。(その理由は、"Complete by Symmetry" コマンドでは、異なる非対称単位中の原子間の結合の有無を、結合距離から推測するためです。CIF 読み込みの場合は、CIF に書かれた結合の情報を使います。)

"Create Packing Diagram" コマンドは、指定した部分座標の範囲(標準は単位格子全体)に存在する原子を対称操作によって生成します。

"Show Periodic Image" コマンドは、新しく原子を作るのではなく、単位格子の繰り返しイメージを画面上で表示するためのものです。

"Remove Expanded Atoms" コマンドは、対称操作によって生成された原子を削除します。2つのオプションがあります。1つは、すべての生成原子を削除するものです。もう1つは、拡張原子のみから成る部分分子を削除するものです(この場合、元の原子と同じ分子に属する拡張原子はそのまま残されます)。

結果は下のようになります。"Show Periodic Image" で表示している繰り返しイメージはまだ表示されていることに注意してください。これは拡張原子ではないため、削除はされません。(このイメージを消すには、"Show Periodic Image" コマンドで表示を無効にしてください。)

2-4. 結合・角度・最適平面

"Bonds and Angles with Sigma..." コマンドは、原子間の距離・角度を標準偏差付きで計算するものです。

"Add Bond" または "Add Angle" ボタンを押して新しいエントリーを作り、それからメインウィンドウで原子を1つずつクリックして指定します。例えば、"Bond" を1つ、"Angle" を1つ作ると、下のようになります。直接結合されていない原子を指定することもできます。

計算結果を他のソフトウェアで使うためには(例えばワードプロセッサにペーストする場合)、表の行を選択して "Export to Clipboard" ボタンを押してください。計算結果はプレーンテキストでコピーされ、他のアプリケーションにペーストできるようになります。

"Best-Fit Planes" コマンドは、最適平面を計算し、二面角や原子・平面間距離を計算するのに使います。ダイアログが開いたら、指定したい原子をメインウィンドウで選択して "Set Current Selection" ボタンを押してください。

2-5. ORTEP 描画

"Show ORTEP" コマンドは、下のようなウィンドウを開きます。

ORTEP 描画は、ORTEP-III プログラムで作成しています。この結果を使う時には、下のように引用してください。

このウィンドウで、原子や結合の表示方法を指定することができます。分子の向きは、メインウィンドウでの向きとだいたい同じです(完全に同じとは言えませんが)。描画結果は、ORTEP 入力ファイルで書き出すことができます。また、グラフィックファイル(EPS, PNG, TIFF)で書き出すこともできます。ビットマップ型 (PNG, TIFF) で書き出す時には、解像度は 360 dpi になります。

Step Eleven: Using Embedded Ruby Interpreter

One of the most useful features of Molby is the embedded Ruby interpreter. When working on molecular modeling, it is often necessary to modify the model according to some mathematical relations. It is also convenient if we can extract some molecular information by automated "scripts" (i.e. computer programs), and export as a text file that can be processed by graphing software. The embedded Ruby interpreter is very useful under these circumstances. Actually, many functions of Molby itself are implemented by Ruby scripts.

To use the embedded Ruby interpreter in Molby, you need to be familiar with the Ruby programming language. You can find several good on-line tutorials in the Internet. However, you can also get the idea by going through the following sections.

1. Using the Ruby Console

The Ruby console window is open when Molby starts up.

On this window, you can execute Ruby scripts in an interactive manner. Let us try something on it now. Make the console window active by clicking on it, and type "1+2" followed by hitting the Return key. You will find this:

% 1+2 --> 3 %

The Ruby interpreter calculated "1+2", and displayed the answer (3) in the following line.

You can give a longer expression including parenthesis.

% (13.0*13.0+7.0*7.0)/1.365 -->159.70695970696 %

Or use common mathematical functions.

% exp(-2.0) * (sin(0.25) + cos(0.25)) -->0.1646105219232536 %

Usually in Ruby, you need to say Math.exp or Math.sin when using these mathematical functions. In Molby, the prefix Math is not necessary, because Molby automatically "includes" the Math module on startup.

You can also use Strings, which is a series of characters.

% "C" + "32" -->"C32" %

The "32" here is not a number but a string, because it is surrounded by quotation marks. If you omit these quotation marks, what happens?

% "C" + 32

Molby complains with this error dialog. It says "no implicit conversion of Fixnum into String," which means the integer 32 cannot be added to a string "C". Such kind of "type mismatch" error occurs very often, so please get used to it and learn how to fix it.

Another useful feature of Ruby is an Array, which is an ordered collection of other Ruby objects. An array is expressed by comma-separated values surrounded by a pair of brackets.

% [1, 2, 3] -->[1, 2, 3] %

Any Ruby object can be stored in a variable. The name of variables should begin with a lowercase alphabet and should consist of alphabets, number characters and underline "_".

% a = ["apple", "orange", "grape"] -->["apple", "orange", "grape"] % a[0] # This shows how to access the array elements -->"apple"

2. How to Handle Molecules in Molby Scripts

The examples so far used only built-in types (Integer, String, Array) in Ruby, but you will definitely need to handle Molecules from your Molby scripts. Suppose we have a benzene molecule (again).

What if you want to convert it to chlorobenzene? There are two GUI ways; double-click on the H1 atom, and enter "Cl" into the dialog box, or double-click on the "H" text in the "element" column of the property table and change it to "Cl". But there is also a "Ruby" way, as follows:

% atoms[1].element = "Cl" -->"Cl" %

This short piece of code implies some important concepts for coding in Molby. First, atoms denotes the atoms in the current molecule, which is the molecule in the frontmost window (except for the console window). atoms is not really an Array (as in the Ruby terminology), but can be used in a similar way as Array in many aspects. Specifically, it can be "indexed" to extract a specific atom.

atoms[i] # Gives the i-th atom in the current molecule

Please make sure to say atoms[i], not atom[i]. This may be confusing, but it is because atoms is a collection of atoms and [] denotes "extraction of the i-th element."

The second point in the above example is .element = "Cl". In Ruby, a period (.) followed by a word (element) indicates a "method call." Method is a technical term in Ruby programming language; it is a function that is specific to an object. In this case, atoms[1] is an object, and it has a method named element= (including the last equal sign) whose meaning is "to change the element as indicated by the string value in the right side." In this way, the script atoms[1].element = "Cl" causes the element of the atom 1 changed to chlorine.

What if you want to change all hydrogen atoms to chlorine? Here is the code:

% natoms.times { |i| if atoms[i].element == "H"; atoms[i].element = "Cl"; end } -->12 %

This is far more complicated than the previous example. A step-by-step explanation follows.

natoms gives the number of atoms in the current molecule as an integer number. This is actually a method call (natoms is a method of a Molecule object). Why a method is called even though no period is preceding the word? It is because Ruby has a feature called "implicit method call." This will be explained in more detail later.

natoms # Gives 12

times is a method of Integer (which is a built-in class of Ruby), which causes the following code surrounded by a pair of braces to be repeated the given number of times.

natoms.times { ... } # { ... } is executed 12 times

The code within the braces is called "block" in Ruby terminology.

In the repeated code (or "block"), it is very likely that you want to know "how many times have I repeated?" This is achieved by declaring a variable name at the top of the block, surrounded by two vertical bars.

natoms.times { |i| ... } # In { ... }, the variable i indicates the number of repeats

The following piece of codes is often used for testing. (puts prints the arguments to the console.)

% natoms.times { |i| puts i } 0 1 2 3 4 5 6 7 8 9 10 11 -->12

The "12" in the last line is the "result value" of the method times, and the numbers 0 to 11 are the outputs from the puts method. Now you can see the block was executed 12 times with changing the variable i from 0 to 11.

In the block, there is an if statement:

if atoms[i].element == "H"; atoms[i].element = "Cl"; end

The if statement has the following general form:

if <condition>; <statements>; end

The <condition> is evaluated first, and if it is "true", the <statements> are executed; otherwise the <statements> are skipped.

Note: Ruby interprets only false and nil as non-true values. Other values are all "true". Specifically, the number 0 (zero) and an empty string ("") are evaluated to "true" (this is unlike other programming language such as Perl). Many Ruby methods returns nil in case of failure; such methods are suitable for the condition part.

Finally, the element method in the following code is different from the element= method that we previously used:

atoms[i].element == "H"

In this case, the following symbol is "==", which means "are these equal?". This is distinct from the symbol "=", which means "the right side is assigned to the left side." The element symbol is interpreted as the element= method only when it is followed by the assignment symbol "=". The above code is not the case, so that it is interpreted as the element method, which returns the present element symbol as a String.

After execution of the script, the molecule should look like this:

3. About the "Implicit" Method Call

In the preceding section, we saw that natoms was a method of a Molecule object.

natoms # 12, in case of benzene

Why this symbol natoms is regarded as a method call? Actually, when the Ruby interpreter finds a symbol beginning with a lowercase alphabet, it looks for a (local) variable first, and if none is found, then it assumes that the symbol is a method belonging to the "current object". Since Ruby is an object-oriented language, there is always a "current object", which is denoted as self. We can see it on our console:

% self -->Molecule["unnamed1"] %

This piece of code indicates that the "current object" is a Molecule object. In fact, the Molecule object corresponding to the frontmost window becomes the "current object" when a script is executed on the Molby console.

When no molecule is open, the "current object" is "main", which is the standard toplevel object in Ruby.

Sometimes you happen to define a variable with the same name as a method of Molecule. In that case, access to the variable is preferred and the method is no longer called.

% natoms = 2 # Define a variable -->2 % natoms # Now this is an access to the variable, not a method call -->2 %

In this situation, you can explicitly request a method call by specifying self.

% self.natoms # This is a method call -->12 %

A special case is the methods with the assignment symbol ("="). For example, a method show_hydrogens= can control whether the hydrogen atoms are shown or not. However, without specifying self, the expression is always regarded as the assignment to a local variable. Therefore, self should be always explicitly given.

% show_hydrogens = false # This does not change the Molecule's state, just changes a local variable -->false % self.show_hydrogens = false # This changes the Molecule's state -->false %

4. Executing a Ruby Script on a File

From the Ruby console, you can only execute a one-line script. For more complex scripts, or if you want to use the script many times over, it will be more convenient to store the script in a file and execute it. The "Execute Script..." command in the "Script" menu does this job.

There are endless possibilities for the script; here are presented only a few examples. The first script is to create a table of bond lengths including metal atoms (Fe):

# Create a bond table including Fe # Requires Molby fp = open("bond_table.txt", "w") # Create an output file atoms.each { |ap| # This is another way to repeat over all atoms; # ap points to the atom on each iteration if ap.element == "Fe" r1 = ap.r # The cartesian coordinate of Fe ap.connects.each { |n| # ap.connects is an array of atom indices connected to this atom ap2 = atoms[n] # The atom connected to Fe r2 = ap2.r # The cartesian coordinate of the atom d = (r - r2).length # The bond length fp.printf "%s-%s %.3f\n", ap.name, ap2.name, d # Write a table entry to the file } # End loop (ap.connects) end # End if } # End loop (atoms.each) fp.close # We are done with this file

Save this text to a file, select "Execute Script..." command (be sure that the target molecule is on the front), and choose the script file. After execution, a file named "bond_table.txt" will be generated in the same directory as the script file.

Here is another example, which works on a MD trajectory. For each frame, the molecule is reoriented so that the atom 0 is at the origin and atoms 1 and 2 are on the xy plane (with the atom 1 on the x-axis), and calculate the center of mass of the atoms 6 to 11. Such processing is useful to visualize how a particular part of the molecule moves around throughout the MD run.

# Reorient the molecule and extract center of some group # Requires Molby fp = open("extract_group.txt", "w") # Create an output file each_frame { |n| # This is an idiom to iterate over all frames rotate_with_axis(1, 2, 0) # Reorientation of the molecule is so frequently used # that the Molecule class has a method to do it r = center_of_mass(6..11) # Also has a method to calculate the center of mass fp.printf "%d %.6f %.6f %.6f\n", n, r.x, r.y, r.z # Write the coordinates } fp.close # We are done with this file

The last example generates a model of carbon nanotube with any chirality and length as you like.

# Create a model of carbon nanotube # Requires Molby r = 1.42 # The C-C bond length n = 10 # The default chirality index m = 5 # (ibid) aspect = 5.0 # The default aspect ratio (length / diameter) # Dialog to ask the chirality index and the aspect ratio h = Dialog.run("Create Carbon Nanotube") { layout(3, item(:text, :title=>"Chirality Index"), item(:textfield, :width=>80, :tag=>"n", :value=>n.to_s), item(:textfield, :width=>80, :tag=>"m", :value=>m.to_s), item(:text, :title=>"Aspect Ratio"), item(:textfield, :width=>160, :tag=>"aspect", :value=>sprintf("%.1f", aspect)), -1) } exit if h[:status] != 0 aspect = h["aspect"].to_f n = h["n"].to_i m = h["m"].to_i k = aspect / (PI * sqrt(3.0)) points = [] # The limiting points are (0, 0), (n, m), (k(n+2m), -k(2n+m)), (k(n+2m)+n, -k(2n+m)+n) # Search for the lattice points that are within the parallelogram # surrounded by the above points # det is the determinant of the matrix that converts the unit cell to the above parallelogram delta = 2 * k * (n * n + m * m + n * m) (0..(k * (n + 2 * m) + n).ceil).each { |s| ((-k * (2 * n + m)).floor..m).each { |t| [0, 2.0/3.0].each { |d| # For two lattice points within the unit cell ss = (k * (2 * n + m) * (s + d) + k * (n + 2 * m) * (t + d)) / delta tt = (m * (s + d) - n * (t + d)) / delta if ss >= 0.0 && ss < 1.0 && tt >= 0.0 && tt <= 1.0 points.push([ss, tt, s, t]) # This point is within the parallelogram end } } } # Create nanotube: line up [ss, tt] into cylindric shape rad = sqrt(3.0) * r * sqrt(n * n + m * m + n * m) / (2 * PI) len = rad * 2 * aspect mol = Molecule.new points.each { |p| ap = mol.create_atom ap.element = "C" ap.atom_type = "ca" ap.r = [rad * cos(2 * PI * p[0]), rad * sin(2 * PI * p[0]), len * p[1]] } mol.guess_bonds # Show the result in a new window mol2 = Molecule.open mol2.add(mol)

5. Where to Go from Here

The embedded Ruby capability is very strong, and cannot be fully explained in this short tutorial. If you are interested, read carefully the reference of the Ruby extension. There are also many scripts in the Molby application, which you can examine by opening the "Scripts" folder (which is within the Application package in Mac OS X, and in the same folder as the Molby application in Windows).

第十一段階:組み込み Ruby インタプリタを使う

Molby の最も有用な機能の1つは、内蔵の Ruby インタプリタです。分子モデリングを行うとき、ある数学的な規則に従ってモデルを変更したいことがしばしばあります。また、分子のある種の情報を自動化された「スクリプト」(コンピュータプログラム)で抽出してテキストとして書き出し、グラフ描画ソフトウェアで処理することも有用です。内蔵 Ruby インタプリタは、このような場合に威力を発揮します。実は、Molby の機能の多くの部分は Ruby スクリプトで実装されているのです。

Molby の内蔵 Ruby インタプリタを使うためには、プログラミング言語 Ruby の知識が必要です。インターネット上で良いオンラインチュートリアルを見つけてください。もっとも、以下の解説を読めば、ある程度のイメージはつかめるでしょう。

1. Ruby コンソールを使う

Molby が起動すると、Ruby の「コンソールウィンドウ」が開きます。

このウィンドウ上で、Ruby スクリプトを対話的に実行することができます。いくつか試してみましょう。コンソールウィンドウをクリックしてアクティブにして、"1+2"、続いてリターンキーをタイプしてください。次のようになります。

% 1+2 --> 3 %

Ruby インタプリタが "1+2" を計算し、答え (3) を次の行に表示したところです。

カッコを含む長い式も計算できます。

% (13.0*13.0+7.0*7.0)/1.365 -->159.70695970696 %

数学関数も使うことができます。

% exp(-2.0) * (sin(0.25) + cos(0.25)) -->0.1646105219232536 %

通常 Ruby では、これらの数学関数を使うときには Math.exp, Math.sin のように書かなくてはなりません。Molby では、Math という接頭辞は必要ありません。これは Molby が起動時に Math モジュールを "include" するためです。

文字列 (Strings) を使うこともできます。

% "C" + "32" -->"C32" %

ここの "32" は数ではなく文字列です。引用符で囲まれているからです。引用符を省略するとどうなるでしょう?

% "C" + 32

Molby はエラーメッセージ "no implicit conversion of Fixnum into String" を表示します。これは、「整数」32 を「文字列」"C" に足すことはできないことを意味しています。このような「型が違う」エラーはとてもよく起きるので、どのように直せばいいかをよく理解しておいてください。

Ruby のもう1つの便利な機能は「配列」(Array) です。これは、他の Ruby オブジェクトを順番に並べたものです。配列は、値をコンマで区切って角括弧 [] で囲むことで表します。

% [1, 2, 3] -->[1, 2, 3] %

Ruby のオブジェクトは「変数」に格納することができます。変数の名前は、小文字のアルファベットで始まり、数字またはアルファベット ("_" を含む) の並びでなくてはなりません。

% a = ["apple", "orange", "grape"] -->["apple", "orange", "grape"] % a[0] # 配列の要素を指定する -->"apple"

2. Molby スクリプトで分子を扱う

ここまでの例では、Ruby の組み込み型 Integer, String, Array を使ってきましたが、Molby スクリプトでは「分子」を扱うことが必要になります。ベンゼン分子があるとしましょう。

これをクロロベンゼンに変えたいとします。グラフィックインターフェイスでは2つのやり方があります。H1原子をダブルクリックしてダイアログボックスに "Cl" と入力するか、属性テーブルの "element" のセルで "H" を "Cl" に変えます。これを Ruby スクリプトで行うには、次のようにします。

% atoms[1].element = "Cl" -->"Cl" %

この短いコードに、Molby でのコーディングの重要な技法が含まれています。まず、atoms は「現在の分子」(コンソールウィンドウを除いて最も手前側にあるウィンドウの分子)に含まれる原子の並びを表します。atoms は Ruby の配列 (Array) ではありませんが、多くの点で配列と同じように使うことができます。特に、「添字」をつけて特定の原子を指定することができます。

atoms[i] # 現在の分子の i 番目の原子

atom[i] ではなく atoms[i] であることに注意してください。混乱しますが、これは atoms が原子の並びで [] が「…番目の要素を取り出す」という機能を表すためです。

次は .element = "Cl" です。Ruby では、ピリオド (.) に続けて単語 (element) を書くと、「メソッド呼び出し」になります。「メソッド」とはプログラミング言語 Ruby の用語で、ある対象(オブジェクト)に固有の動作を指します。この場合は、atoms[1] がオブジェクトで、element= という名前のメソッドを持っています(最後の '=' を含みます)。このメソッドは、「その原子の元素記号を右辺の文字列で表されたものに変える」という働きをします。このようにして、スクリプト atoms[1].element = "Cl" は、原子1の元素記号を Cl に変えます。

もし、全部の水素原子を塩素に変えたいとしたらどうでしょう? 次のようにします。

% natoms.times { |i| if atoms[i].element == "H"; atoms[i].element = "Cl"; end } -->12 %

これは前の例よりずっと複雑です。ステップごとに説明していきます。

natoms は、現在の分子の原子数を整数で返します。これは実はメソッド呼び出しで、Molecule 型オブジェクトのメソッド natoms を呼んでいます。ピリオドがないのにメソッドが呼び出されているのはなぜでしょう? これは Ruby 言語の仕様に、「暗黙のメソッド呼び出し」があるためです。あとでもう少し詳しく説明します。

natoms # 12 となる

times は、Integer (これは Ruby の組み込み型です)のメソッドです。その後ろの中括弧 {} で囲まれたコードを、指定した回数実行します。

natoms.times { ... } # { ... } が 12 回実行される

中括弧で囲んだコードを Ruby の用語で「ブロック」と呼びます。

繰り返すコード(ブロック)の中で、「今実行しているのは何回目?」かを知りたいことがあります。このためには、ブロックの先頭で、2本の縦棒 "|" で囲んで変数を指定します。

natoms.times { |i| ... } # { ... } の中で、変数 i は繰り返し回数を表す

次のようなコードがテストのためによく使われます。(puts は与えられたオブジェクトをコンソールに出力します。)

% natoms.times { |i| puts i } 0 1 2 3 4 5 6 7 8 9 10 11 -->12

最後の行の "12" は、times メソッドの「戻り値」です。その上の 0 から 11 の数は、puts メソッドからの出力です。ブロックが 12 回実行され、変数 i が 0 から 11 まで変化したことがわかりますね。

ブロックの中には、if 文があります。

if atoms[i].element == "H"; atoms[i].element = "Cl"; end

if 文の一般形は次の通りです。

if <条件>; <実行文>; end

まず <条件> が評価されます。それが「真」ならば、<実行文> が実行されます。条件が「真」でなければ、<実行文> はスキップされます。

注: Ruby は falsenil だけを「真でない」値とします。その他の値はすべて「真」です。特に、数値の 0(ゼロ)と空の文字列 ("") も「真」となります(これは Perl などの他のプログラミング言語とは異なります)。多くの Ruby メソッドは、失敗したときに nil を返します。これらのメソッドは条件部分にそのまま使えます。

最後に出てくる element メソッドは、先に出て来た element= メソッドとは違います。

atoms[i].element == "H"

この場合は、element の次に来る記号は "==" で、これは「2つの値は等しいか?」という意味です。この記号は "=" とは違います。後者は「右辺を左辺に代入する」という意味です。element という記号は、その次に "=" 記号が来るときに限って、"element=" メソッドとして解釈されます。この場合はそうではないので、element メソッドが呼び出されます。このメソッドは、現在の元素記号を String (文字列)として返します。

スクリプトを実行したら、分子は次のようになるはずです。

3. 暗黙のメソッド呼び出し

前の節で、natomsMolecule オブジェクトのメソッドであることを学びました。

natoms # 12 (ベンゼンの場合)

なぜこの natoms はメソッド呼び出しと見なされるのでしょう? 実は、Ruby インタプリタ(Ruby スクリプトを実行するプログラム)は小文字のアルファベットで始まる単語を見つけると、まず変数(ローカル変数)を探し、それが見つからなければ「現在のオブジェクト」に属するメソッドであると見なすのです。Ruby は「オブジェクト指向言語」なので、Ruby スクリプトの実行中は必ず「現在のオブジェクト」が存在しています。これを self と呼びます。コンソールで試してみましょう:

% self -->Molecule["unnamed1"] %

この結果は、「現在のオブジェクト」が "unnamed1" という分子を表す Molecule オブジェクトであることを示しています。Molby コンソールでスクリプトを実行する時は、最前面にあるウィンドウの分子に対応する Molecule オブジェクトが「現在のオブジェクト」になります。

分子のウィンドウが1つも開いていない時は、現在のオブジェクトは main になります。これは Ruby 起動時の「現在のオブジェクト」と同じものです。

ときどき、Molecule が持つメソッド名と同じ名前の変数を作ってしまうことがあります。この場合、変数へのアクセスが優先されますので、メソッドを呼び出すことはできなくなります。

% natoms = 2 # 変数 natoms を定義 -->2 % natoms # これは変数へのアクセスになり、メソッド呼び出しではない -->2 %

この場合でも、self を指定すればメソッドを呼び出すことができます。

% self.natoms # これはメソッド呼び出し -->12 %

特に注意が必要なのは、代入記号 ("=") を持つメソッドです。例えば、show_hydrogens= というメソッドは、水素原子を表示するかどうかを指定するものです。しかし、self を使わないと、ローカル変数への代入になってしまいます。従って、この場合は常に self を指定する必要があります。

% show_hydrogens = false # これはローカル変数への代入で、分子の状態は変わらない -->false % self.show_hydrogens = false # これはメソッド呼び出しで、分子の状態を変える -->false %

4. ファイル上の Ruby スクリプトを実行する

Ruby コンソール上では、1行のスクリプトしか実行できません。もっと複雑なスクリプトを実行したい時や、同じスクリプトを何度も実行したい時は、ファイルにスクリプトを格納して実行する方が便利です。"Script" メニューの "Execute Script..." コマンドでこれが実現できます。

スクリプトには無限の可能性があります。いくつかの例をここに示します。最初のものは、「鉄原子を含む結合長のテーブルを作る」スクリプトです。

# Create a bond table including Fe # Requires Molby fp = open("bond_table.txt", "w") # Create an output file atoms.each { |ap| # This is another way to repeat over all atoms; # ap points to the atom on each iteration if ap.element == "Fe" r1 = ap.r # The cartesian coordinate of Fe ap.connects.each { |n| # ap.connects is an array of atom indices connected to this atom ap2 = atoms[n] # The atom connected to Fe r2 = ap2.r # The cartesian coordinate of the atom d = (r - r2).length # The bond length fp.printf "%s-%s %.3f\n", ap.name, ap2.name, d # Write a table entry to the file } # End loop (ap.connects) end # End if } # End loop (atoms.each) fp.close # We are done with this file

このテキストをファイルに保存し、"Execute Script..." コマンドを実行し(目的の分子が一番前のウィンドウに表示されていることを確かめて)、スクリプトファイルを選びます。実行後、"bond_table.txt" というファイルが、スクリプトファイルと同じディレクトリに作成されています。

次の例は、MD トラジェクトリを処理するものです。各フレームに対して、原子 0 が原点、原子 1, 2 が xy 平面上(原子 1 が x 軸上)に来るように分子を再配向して、原子 6 から 11 の重心を計算します。このような処理は、MD の結果分子のある部分がどのように動くかを可視化するのに便利です。

# Reorient the molecule and extract center of some group # Requires Molby fp = open("extract_group.txt", "w") # Create an output file each_frame { |n| # This is an idiom to iterate over all frames rotate_with_axis(1, 2, 0) # Reorientation of the molecule is so frequently used # that the Molecule class has a method to do it r = center_of_mass(6..11) # Also has a method to calculate the center of mass fp.printf "%d %.6f %.6f %.6f\n", n, r.x, r.y, r.z # Write the coordinates } fp.close # We are done with this file

最後の例は、任意のキラリティ・長さのカーボンナノチューブのモデルを作成するスクリプトです。

# Create a model of carbon nanotube # Requires Molby r = 1.42 # The C-C bond length n = 10 # The default chirality index m = 5 # (ibid) aspect = 5.0 # The default aspect ratio (length / diameter) # Dialog to ask the chirality index and the aspect ratio h = Dialog.run("Create Carbon Nanotube") { layout(3, item(:text, :title=>"Chirality Index"), item(:textfield, :width=>80, :tag=>"n", :value=>n.to_s), item(:textfield, :width=>80, :tag=>"m", :value=>m.to_s), item(:text, :title=>"Aspect Ratio"), item(:textfield, :width=>160, :tag=>"aspect", :value=>sprintf("%.1f", aspect)), -1) } exit if h[:status] != 0 aspect = h["aspect"].to_f n = h["n"].to_i m = h["m"].to_i k = aspect / (PI * sqrt(3.0)) points = [] # The limiting points are (0, 0), (n, m), (k(n+2m), -k(2n+m)), (k(n+2m)+n, -k(2n+m)+n) # Search for the lattice points that are within the parallelogram # surrounded by the above points # det is the determinant of the matrix that converts the unit cell to the above parallelogram delta = 2 * k * (n * n + m * m + n * m) (0..(k * (n + 2 * m) + n).ceil).each { |s| ((-k * (2 * n + m)).floor..m).each { |t| [0, 2.0/3.0].each { |d| # For two lattice points within the unit cell ss = (k * (2 * n + m) * (s + d) + k * (n + 2 * m) * (t + d)) / delta tt = (m * (s + d) - n * (t + d)) / delta if ss >= 0.0 && ss < 1.0 && tt >= 0.0 && tt <= 1.0 points.push([ss, tt, s, t]) # This point is within the parallelogram end } } } # Create nanotube: line up [ss, tt] into cylindric shape rad = sqrt(3.0) * r * sqrt(n * n + m * m + n * m) / (2 * PI) len = rad * 2 * aspect mol = Molecule.new points.each { |p| ap = mol.create_atom ap.element = "C" ap.atom_type = "ca" ap.r = [rad * cos(2 * PI * p[0]), rad * sin(2 * PI * p[0]), len * p[1]] } mol.guess_bonds # Show the result in a new window mol2 = Molecule.open mol2.add(mol)

5. 次に学ぶべきこと

組み込み Ruby インタプリタは非常に強力であるため、この短いチュートリアルでは説明しきれません。興味があるなら、Ruby 拡張のリファレンス に目を通してください。また、Molby アプリケーション本体にはたくさんの Ruby スクリプトが内蔵されています。"Scripts" フォルダを参照してください(Mac OS X では Molby アプリケーションパッケージの中、Windows では Molby アプリケーションと同じフォルダにあります)。

Appendix

付録

Ruby Extension Reference

The following classes/module/exception are defined in the embedded Ruby interpreter in Molby. The methods defined in the module Kernel can be used as if they are builtin functions, like in the standard Ruby interpreter. All other classes and MolbyError exception are defined under the a module Molby. However, Molby:: prefix is not necessary because include Molby is invoked on startup.

On startup, include Math is also invoked, so that the methods and constants in the Math module can also be used without prefix.

It is recommended for you to read the document of the most important class Molecule. Follow the links as necessary, and you will understand how other classes are defined and used.

Classes

Module

Exception

Ruby 拡張リファレンス

以下のクラス/モジュール/例外が Molby 内蔵の Ruby インタプリタに組み込まれています。Kernel モジュールのメソッドは、通常の Ruby インタプリタと同様に組み込み関数のように使うことができます。その他のクラスと MolbyError 例外は Molby モジュールの下に定義されています。ただし、起動時に include Molby が呼び出されるため、Molby:: 接頭辞は必要ありません。

起動時には include Math も呼び出されるため、Math モジュールのメソッドや定数も接頭辞なしで使うことができます。

最も重要なクラスは Molecule なので、このドキュメントを最初に読むことをお勧めします。ここから必要に応じてリンクをたどっていけば、他のクラスがどのように定義され使われるかが理解しやすくなります。

Classes

Module

Exception

Filter Kit How-to

In the research of chemistry, we sometimes a simple processing of text files. Ruby is particularly suitable for such purposes. To make the use of Ruby easier, Molby provides a special capability called "filter kit" (version 0.6.4 and later). The name originates from the "UNIX" culture, where small programs for text processing are called "filters".

Here is a description of making a filter script. As a demonstration, the filter here is a very simple function; it appends a sequential line number on each line.

   

To write a filter, we create a new text file, with extention ".rb" or ".mrb". Former is conventional as a Ruby script, but latter may be useful to specify Ruby scripts for Molby.

We start from the following line:

Dialog.filter_kit("Filter Sample", "This is a sample filter.") { |args|

The method Dialog.filter_kit takes two arguments, the window title and the message. It also requires a block, which actually contains the main program.

When the user presses the "Select Files" button and choose files (which can be multiple), the block is executed with the array of the chosen file names as the argument. The block body is written as follows:

1 Dialog.filter_kit("Filter Sample", "This is a sample filter.") { |args| 2 args.each { |fname| 3 fp = open(fname, "r") 4 if fp == nil 5 error_message_box("Cannot open file: #{arg}") 6 next 7 end 8 puts fname 9 a = fp.readlines 10 fp.close 11 File.rename(fname, fname + "~") 12 fp2 = open(fname, "w") 13 a.each_with_index { |ln, n| 14 ln = (n + 1).to_s + " " + ln 15 fp2.print ln 16 } 17 fp2.close 18 }

The above text is saved as "filter_sample.rb" (the filename can be arbitrary except for the extension). Open it with Molby, and you will get the filter running.

Filter Kit の使い方

化学の研究では、テキストファイルに簡単な処理を加えたいことがときどきあります。Ruby はこの目的に特に適しています。Ruby を簡単に使えるようにするため、Molby は "filter kit" という特別な機能を持っています(バージョン 0.6.4 以降)。Filter という名前は "UNIX" の文化から来ており、テキストを処理する小さなプログラムのことを指します。

以下にフィルタスクリプトの作り方を解説します。説明のため、ごく単純な機能を持ったものを作ります。ファイルの各行に行番号をつけるものです。

   

フィルタを書くためには、新しいテキストファイルを作って、拡張子を ".rb" か ".mrb" とします。前者が Ruby スクリプトとして一般的なものですが、後者は Molby 専用のスクリプトを示すために使うことができます。

まず次の行から始めます。

Dialog.filter_kit("Filter Sample", "This is a sample filter.") { |args|

Dialog.filter_kit というメソッドは2つの引数をとります。ウィンドウのタイトルと、メッセージです。この他にブロックが必要で、その中にメインプログラムを置きます。

フィルタのユーザーが "Select Files" ボタンでファイルを選ぶと(複数のファイルを選択できます)、ブロックが実行され、選択されたファイル名の配列 (Array) が引数として渡されます。ブロックの本体は次のように書きます。

1 Dialog.filter_kit("Filter Sample", "This is a sample filter.") { |args| 2 args.each { |fname| 3 fp = open(fname, "r") 4 if fp == nil 5 error_message_box("Cannot open file: #{arg}") 6 next 7 end 8 puts fname 9 a = fp.readlines 10 fp.close 11 File.rename(fname, fname + "~") 12 fp2 = open(fname, "w") 13 a.each_with_index { |ln, n| 14 ln = (n + 1).to_s + " " + ln 15 fp2.print ln 16 } 17 fp2.close 18 }

上のテキストを "filter_sample.rb" として保存します(拡張子が正しければ、ファイル名は何でも構いません)。このファイルを Molby で開けば、フィルタとして使うことができます。