orca_mapspc→gnuplotでIRスペクトル画像生成

ORCAには標準出力ファイルからスペクトルの描画用ファイルを生成するツール(orca_mapspc)があります。で、これとgnuplotを使えば、さくっとスペクトルのpng画像を作れます。バッチファイルの一例。

:ir_start
if '%1'=='' goto end
set winpath=%~dpn1
for /f %%i in ('wsl wslpath "%winpath%"') do set linpath=%%i
set /A filecount=%filecount%+1
cd /D %~dp1 > nul
bash -c "/mnt/c/orca/orca_mapspc %linpath%.out ir

(
echo set title "Calculated %gtitle%"
echo set xlabel "Wavenumber [cm-1]"
echo unset key
echo set xrange[4000:500]
echo set yrange[:1050]
echo unset ytics
echo set terminal pngcairo
echo set output "%linpath%.%spectrum%.png"
echo plot "%linpath%.out.%spectrum%.dat" w l lt rgb "red"
)> temp_%spectrum%.plt

bash -c "gnuplot temp_ir.plt"
del /Q temp_ir.plt

shift
goto ir_start

:end
exit
AcN3_opt.ir
Fig. gnuplotで生成したIRスペクトルの画像例

gnuplotはWSL側にインストールしてます。orca_mapspcで、.outファイルから.out.ir.dat (と.out.ir.stk)が生成し、そのうちdatファイルを使ってプロットしています。
IR以外にもUV/Vis (abs)、ラマン(raman)、CD (cd)スペクトルが作成できますので、各々向けにブロックを書いてスイッチする形にすれば、どれにも対応できる形になると思います。

ちなみに、実測のIRスペクトルは2000 cm-1を境に低波数側と高波数側で軸の幅が変わる仕様が多いので、それに合わせた形で出力する場合は例えば以下のようなgnuplotのコマンドで処理します。

# common setting
set terminal pngcairo
set output "IR.png"
set lmargin 0
set rmargin 0
set tmargin 0
set bmargin 0
unset key
set multiplot

# title and x-axis tics/label
set title "IR spectrum
set size 0.8, 0.7
set origin 0.1, 0.2
set xrange [0:5]
set yrange [-500:1050]
unset border
set xtics ('4000' 0, '3000' 1, '2000' 2, '1500' 3, '1000' 4, '500' 5)
unset ytics
set xlabel "wavenumber [cm-1]"
unset ylabel
plot 1000 w l lt rgb "white"

# large wavenumber side
unset title
set size 0.32, 0.7
set origin 0.1, 0.2
set xrange [4000:2000]
set yrange [-500:1050]
unset xtics
unset ytics
unset ylabel
unset xlabel
set border 7
plot "xxx.out.ir.dat" w l lt rgb "red"

# small wavenumber side
unset title
set size 0.48, 0.7
set origin 0.42, 0.2
set xrange [2000:500]
set yrange [-500:1050]
unset xtics
unset ytics
unset ylabel
unset xlabel
set border 13
plot "xxx.out.ir.dat" w l lt rgb "red"

unset multiplot

以下のようなグラフが出力されます。

4種のスペクトル対応版batファイル
@echo off
title Drawing spectrum from ORCA output
set filecount=0

rem 処理するスペクトルデータの種類
echo 1=IR, 2=UV/Vis, 3=Raman, 4=CD
set /P userinput="出力するスペクトルの種類を選んでください:"
if %userinput%==1 (
 set spectrum=ir
 set gtitle=IR spectrum
 goto ir_start
) else if %userinput%==2 (
 set spectrum=abs
 set gtitle=UV/Vis spectrum
 goto abs_start
) else if %userinput%==3 (
 set spectrum=raman
 set gtitle=Raman spectrum
 goto raman_start
) else if %userinput%==4 (
 set spectrum=cd
 set gtitle=CD spectrum
 goto cd_start
) else (
 echo ※上記4種類以外のスペクトルは扱えません
 goto end
)

:ir_start
if '%1'=='' goto end
set winpath=%~dpn1
for /f %%i in ('wsl wslpath "%winpath%"') do set linpath=%%i
set /A filecount=%filecount%+1
cd /D %~dp1 > nul
bash -c "/mnt/e/Programs/orca/bin410_ls/orca_mapspc %linpath%.out %spectrum%"

(
echo set title "Calculated %gtitle%"
echo set xlabel "wavenumber [cm-1]"
echo unset key
echo set xrange[4000:500]
echo set autoscale y
echo set y2range[] reverse
echo unset ytics
echo unset y2tics
echo unset x2tics
echo set xtics nomirror
echo set terminal pngcairo
echo plot "%linpath%.out.%spectrum%.dat" axis x1y1 w l lt rgb "red"
echo set output "%linpath%.%spectrum%.png"
echo replot "%linpath%.out.%spectrum%.stk" axis x1y2 w impulse lt rgb "gray50"
)> temp_%spectrum%.plt

bash -c "gnuplot temp_%spectrum%.plt"
del /Q temp_%spectrum%.plt

shift
goto ir_start

:abs_start
if '%1'=='' goto end
set winpath=%~dpn1
for /f %%i in ('wsl wslpath "%winpath%"') do set linpath=%%i
set /A filecount=%filecount%+1
cd /D %~dp1 > nul
bash -c "/mnt/e/Programs/orca/bin410_ls/orca_mapspc %linpath%.out %spectrum%"

(
echo set title "Calculated %gtitle%"
echo set xlabel "wavelength [nm]"
echo unset key
echo set xrange[250:1000]
echo unset ytics
echo unset y2tics
echo unset x2tics
echo set xtics nomirror
echo N=10000000
echo set terminal pngcairo
)> temp_%spectrum%.plt
echo plot "%linpath%.out.%spectrum%.dat" using (N/$1):2 axis x1y1 w l lt rgb "red" >> temp_%spectrum%.plt
echo set output "%linpath%.%spectrum%.png" >> temp_%spectrum%.plt
echo replot "%linpath%.out.%spectrum%.stk" using (N/$1):2 axis x1y2 w impulse lt rgb "gray50" >> temp_%spectrum%.plt

bash -c "gnuplot temp_%spectrum%.plt"
del /Q temp_%spectrum%.plt

shift
goto abs_start

:raman_start
if '%1'=='' goto end
set winpath=%~dpn1
for /f %%i in ('wsl wslpath "%winpath%"') do set linpath=%%i
set /A filecount=%filecount%+1
cd /D %~dp1 > nul
bash -c "/mnt/e/Programs/orca/bin410_ls/orca_mapspc %linpath%.out %spectrum%"

(
echo set title "Calculated %gtitle%"
echo set xlabel "wavenumber [cm-1]"
echo unset key
echo set xrange[4000:300]
echo unset ytics
echo unset y2tics
echo unset x2tics
echo set xtics nomirror
echo set terminal pngcairo
echo plot "%linpath%.out.%spectrum%.dat" axis x1y1 w l lt rgb "red"
echo set output "%linpath%.%spectrum%.png"
echo replot "%linpath%.out.%spectrum%.stk" axis x1y2 w impulse lt rgb "gray50"
)> temp_%spectrum%.plt

bash -c "gnuplot temp_%spectrum%.plt"
del /Q temp_%spectrum%.plt

shift
goto raman_start

:cd_start
if '%1'=='' goto end
set winpath=%~dpn1
for /f %%i in ('wsl wslpath "%winpath%"') do set linpath=%%i
set /A filecount=%filecount%+1
cd /D %~dp1 > nul
bash -c "/mnt/e/Programs/orca/bin410_ls/orca_mapspc %linpath%.out %spectrum%"

(
echo set title "Calculated %gtitle%"
echo set xlabel "wavelength [nm]"
echo unset key
echo set xrange[250:1000]
echo set autoscale y
echo unset logscale y
echo unset ytics
echo unset x2tics
echo set xtics nomirror
echo N=10000000
echo set terminal pngcairo
echo plot 0 w l lt rgb "black"
)> temp_%spectrum%.plt
echo replot "%linpath%.out.%spectrum%.dat" using (N/$1):2 w l lt rgb "red" >> temp_%spectrum%.plt
echo set output "%linpath%.%spectrum%.png" >> temp_%spectrum%.plt
echo replot "%linpath%.out.%spectrum%.stk" using (N/$1):2 w impulse lt rgb "gray50" >> temp_%spectrum%.plt

bash -c "gnuplot temp_%spectrum%.plt"
del /Q temp_%spectrum%.plt

shift
goto cd_start

:end
exit

Be the first to comment

Leave a Reply