SST Lab Dokuwiki Header header picture

ユーザ用ツール

サイト用ツール


misc:tips

文書の過去の版を表示しています。


Tips and Chips

General

macOS

Linux

Error Handling

  • Use_https:Security Token did not match. Possible CSRF attack.
    • httpsを使え!

大文字小文字変換

Tue, 10 Nov 2009 13:17:16 +0000

アルファベットの大文字小文字の混ざったファイルの中身を小文字のみに統一する。

$ tr [A-Z] [a-z] < 混在ファイル名 > 小文字のみファイル名

確かに、sedやawkの使い方を覚えるよう指導しているが、こんな作業はtrコマンドで一発。

iPhoneのパケット通信を禁止する

Tue, 10 Nov 2009 12:06:32 +0000

以下のファイルをダウンロードし、解凍してできた「APN disabler.mobileconfig」をメールの添付ファイルとしてiphoneに送信する。

mobileconfigファイル(zipにて圧縮済)

jailbreakしたiphone 3Gに普通のソフトバンクモバイル(SMB)のSIMをさしてこの設定をして使う。常時無線LAN環境下に居られる人向き。ホワイトプランで通話相手がSBMだけだと、これで本当に「毎月980円でiPhone」が実現する。

From NetCDF to XYZ

Mon, 09 Nov 2009 13:06:28 +0000

#!/usr/bin/env python
import os
import tempfile
from optparse import OptionParser
 
from Dacapo import Dacapo
from ASE.Trajectories.NetCDFTrajectory import NetCDFTrajectory
from ASE.IO.xyz import WriteXYZ
 
cmd = OptionParser(usage = '%prog [-r R1 R2 R3] input_nc_file output_xyz_file')
cmd.add_option('-r', '--repeat', type = 'int', nargs = 3,
               help = 'Repeat R1, R2, R3 times along the three axes',
               metavar = 'R1 R2 R3')
 
(opt, argv) = cmd.parse_args()
 
if len(argv) != 2:
    cmd.print_help()
    raise SystemExit
 
ncfile = argv[0]
xyzfile = argv[1]
 
try:
  model = Dacapo.ReadAtoms(ncfile, index = 1)
  trajectory = True
except IndexError:
  trajectory = False
 
if not trajectory:
  model = Dacapo.ReadAtoms(ncfile)
  WriteXYZ(xyzfile, atoms = model, repeat = opt.repeat, id = ncfile)
else:
  model = Dacapo.ReadAtoms(ncfile, index = 0) 
  model.SetCalculator(None)
  tmpfile = tempfile.mktemp()
  xyzpath = NetCDFTrajectory(tmpfile, model)
  xyzpath.Update()
 
  frame = 0 
  error = False
  while not error: 
    frame += 1
    try: 
        atoms = Dacapo.ReadAtoms(ncfile, index = frame) 
        model.SetCartesianPositions(atoms.GetCartesianPositions())
        xyzpath.Update()
    except IndexError: 
        error = True
 
  xyzpath.Close()    
  xyzpath = NetCDFTrajectory(tmpfile)
  WriteXYZ(xyzfile, trajectory = xyzpath, repeat = opt.repeat, id = ncfile)
  os.remove(tmpfile)

From NetCDF to DOS

Tue, 10 Nov 2009 13:51:22 +0000

#!/usr/bin/env python
from optparse import OptionParser
from Dacapo import Dacapo
from ASE.Utilities.DOS import DOS
cmd = OptionParser(usage = '%prog [-r] input_nc_file output_text_file')
cmd.add_option('-r', '--reverse', action = "store_true", default = False,
help = 'reverse out put for minor spin states')
(opt, argv) = cmd.parse_args()
 
if len(argv) != 2:
  cmd.print_help()
  raise SystemExit
 
  ncfile = argv[0]
  textfile = argv[1]
  sfmt0 = '%-15s %-15s\n'
  sfmt1 = '%-15s %-15s %-15s %-15s\n'
  efmt0 = '%15.7E %15.7E\n'
  efmt1 = '%15.7E %15.7E %15.7E %15.7E\n'
  atoms = Dacapo.ReadAtoms(ncfile)
  calc = atoms.GetCalculator()
  isSpinPolarized = calc.GetSpinPolarized()
  dos = DOS(calc)
  x0 = dos.GetEnergies()
  if isSpinPolarized:
    y0 = dos.GetDOS(0)
    y1 = dos.GetDOS(1)
    fp = open(textfile, 'w')
    if opt.reverse:
      fp.write(sfmt1 % ('Energy', 'DOS0', 'DOS1', 'DIFF'))
    else:
      fp.write(sfmt1 % ('Energy', 'DOS0', 'DOS1', 'TOTAL'))
      for i in range(len(x0)):
        if opt.reverse:
          fp.write(efmt1 % (x0[i], y0[i], -y1[i], y0[i] - y1[i]))
        else:
          fp.write(efmt1 % (x0[i], y0[i],  y1[i], y0[i] + y1[i]))
      fp.close()
  else:
    y0 = dos.GetDOS(0)
    fp = open(textfile, 'w')
    fp.write(sfmt0 % ('Energy', 'DOS'))
    for i in range(len(x0)):
      fp.write(efmt0 % (x0[i], y0[i]))
    fp.close()

From NetCDF to CUBE (1)

Tue, 10 Nov 2009 13:55:13 +0000

Total density of states

#!/usr/bin/env python
import string
from math import log10
from optparse import OptionParser
 
from Dacapo import Dacapo
from ASE.IO.Cube import WriteCube
 
cmd = OptionParser(usage = '%prog input_nc_file output_cube_file')
 
(opt, argv) = cmd.parse_args()
 
if len(argv) != 2:
  cmd.print_help()
  raise SystemExit
 
ncfile = argv[0]
cubefile = argv[1]
basename = string.split(cubefile, '.cube')
 
model = Dacapo.ReadAtoms(ncfile)
calculator = model.GetCalculator()
 
if not calculator.GetSpinPolarized():
  filename_total= basename[0] + '.cube'
else:
  filename_total= basename[0] + '_total.cube'
  filename_diff= basename[0] + '_diff.cube'
  filename_spin0= basename[0] + '_spin0.cube'
  filename_spin1= basename[0] + '_spin1.cube'
  density0 = calculator.GetDensityArray(spin = 0)
  density1 = calculator.GetDensityArray(spin = 1)
  WriteCube(model, density0, filename_spin0)
  WriteCube(model, density1, filename_spin1)
  diff = density1 - density0
  WriteCube(model, diff, filename_diff)
 
density = calculator.GetDensityArray()
WriteCube(model, density, filename_total)

jmolテスト

Thu, 24 Dec 2009 06:28:00 +0000

<div class=“jmol” id=“sample_applet”> <img src=“wp-content/uploads/2009/12/ordered.png” onLoad=“insertJmol('sample_applet',400,400,'uploads/2009/12/ordered.xyz')” alt=“In/Si(111)4×1-8×2”/> </div>

<a href=“http://www.openscience.org/”>The OpenScience project</a>のサイトを参考にjmolアプレットを仕込んでみた。サンプルはSb吸着Si(111)表面の4×1構造と8×2構造の間の原子位置の変遷をアニメーションにしたもの。ただし、現実には、こんな風に動くことは絶対にありません。リアルなアニメーションはどこかの研究会でお見せできるでしょう。マウスでグリグリ動かしたり、拡大したり、アニメーションしたりできる。是非、いろいろ遊んでみて。(ヒント:マウスの右ボタンとホイール)

<strong>!!!警告!!!</strong> jmolアプレットを使う投稿記事を編集する際には、投稿編集画面で決して「ビジュアル」モードにしてはならない。必ずHTMLモードで編集し保存すること。

手順 <ol> <li>jmolアプレットJmolApplet.jarに相対パスwp-content/jmol/JmolApplet.jarでアクセスできるようにjmolのアーカイブを解凍し、移動させ、適当にシンボリックリンクを張ったりなんかする。</li> <li>テーマファイルのheader.phpに

<script type="text/javascript">
<!--
function insertJmol(me,width,height,myMolecule) {
   document.getElementById(me).innerHTML = '<applet width="'
   +width+'" height="'+height+
   '" code="JmolApplet" archive="wp-content/jmol/JmolApplet.jar">'
   +'<param name="progressbar" value="true">'
   +'<param name="load" value="wp-content/'
   +myMolecule+'">';
 }
//-->
</script>

を付け加える。</li> <li>xyzファイルやpdbファイルを画像ファイルや書庫ファイルなどと同じようにアップロードできるようにwp-includes/functions.phpを

function wp_ext2type( $ext ) {
...
- 'text' =&gt; array('txt'),
+ 'text' =&gt; array('txt', 'text', 'pdb', 'xyz', 'cube'),
...
function get_allowed_mime_types() {
...
+ 'text|pdb|xyz|cube' =&gt; 'text/plain',

のように編集する。</li> <li>ダミーの画像ファイル(ここではordered.png)とjmolに表示させるファイル(ここではordered.xyz)をアップロードしサーバー上での相対パス名を確認する。</li> <li>以下のような“jmol” classのdivエレメントを記入する。

<div id="sample_applet" class="jmol">
<img src="wp-content/uploads/2009/12/ordered.png" onLoad="insertJmol('sample_applet',400,400,'uploads/2009/12/ordered.xyz')"  alt="In/Si(111)4x1-8x2"/>
</div>

</li> </ol> 注意 <ul> <li>srcに指定するパス名とonLoadに指定するinsertJmol関数の引数のパス名のprefixが異なっている。</li> <li>imgエレメントは一行で記述しなければならない。</li> </ul>

これで、講義資料もwordpressに移せるかな。

MySQLに新しいデータベース

Thu, 04 Feb 2010 03:33:53 +0000

MySQLシステムに新しいデータベースを作成する。

$ mysql -p -u root
Enter password:
...
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
...
mysql> create database Name_of_database;
...
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
...
...
| Name_of_database   |
...
...
mysql> QUIT
Bye
$

セミコロンをつけるのをすぐ忘れるんよなあ、QUITにはいらんけど。

showコマンドとcreateコマンドとでdatabaseに単数と複数の区別があるんだよねえ、まあ英語としては当たり前だけど。

misc/tips.1661760690.txt.gz · 最終更新: 2022/08/29 17:11 by kimi

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki