Published: Mar 25, 2021 by Emi Minamitani
実際にAiiDAを使う目的は、自分の場合、どちらかというとQuantum-espressoやVASPなどの第一原理計算コードで大量に似たような計算するのを計算機任せにしたいということです。 そのために必要な、計算コードの設定や外部計算機の設定と、実際にジョブを流すまでを試した結果をまとめます。
Quantum-Espressoでの例
フリーの第一原理計算コードQuantum-espressoの場合はAiiDA用のプラグインが既に準備されています。
pip install aiida-quantumespresso
reentry scan
もしも、daemonが起動している状態でプラグインを追加した場合には
verdi daemon restart --reset
と再起動しないといけません。
自分の環境に合わせて、aiida-quantumespresso
の一部を変更した場合にも、daemonを再起動しないと
変更が反映されません。
quantum-espressoのプラグインでどのようなものが入っているかは
$ verdi plugin list aiida.calculations
で確認できます。例えば以下の様な感じになります。
Registered entry points for aiida.calculations:
* arithmetic.add
* quantumespresso.cp
* quantumespresso.create_kpoints_from_distance
* quantumespresso.dos
* quantumespresso.epw
* quantumespresso.matdyn
* quantumespresso.namelists
* quantumespresso.neb
* quantumespresso.ph
* quantumespresso.pp
* quantumespresso.projwfc
* quantumespresso.pw
* quantumespresso.pw2gw
* quantumespresso.pw2wannier90
* quantumespresso.pwimmigrant
* quantumespresso.q2r
* quantumespresso.seekpath_structure_analysis
* templatereplacer
のようになっていて、scf計算のプラグインquantumespresso.pw
とかが入っていれば成功です。
AiiDAがインストールされている計算機上でのコードを動かす場合
この場合は、その計算機自体の情報と、コードをAiiDAのnodeとして登録して、それを呼び出して計算する形になります。
AiiDAがインストールされている計算機をlocalhost
という名称で登録してみましょう。
対話的にも処理が出来るのですが、どんな設定をしたかを後日すぐに確認できるようにするために、自分はyaml形式のファイルを読み込んで設定する方法を使いました。
つかったlocalhost.yamlの中身の例は以下のようなものです。
---
label: "localhost"
hostname: "localhost"
transport: local
scheduler: "direct"
work_dir: "/home/hoge/aiida_run"
mpirun_command: "mpirun -np {tot_num_mpiprocs}"
mpiprocs_per_machine: "2"
prepend_text: |
このyamlファイルを使ってlocalhost
コンピュータを登録します。
verdi computer setup --config localhost.yaml
このコンピュータに計算を投げられるようにするために
verdi computer configure local localhost
という手順で認証を行います。
擬ポテンシャルのデータ整備
AiiDAでは擬ポテンシャルのデータも各計算時にデータベースに記録されます。これを扱うためのプラグインがaiida-pseudo
です。
https://github.com/aiidateam/aiida-pseudo これを使うと、SSSP(https://www.materialscloud.org/discover/sssp)やPseudo-dojo(http://www.pseudo-dojo.org/)などでチェック済みの擬ポテンシャルデータをダウンロード&記録することができます。
pip install aiida-pseudo
reentry scan
aiida-pseudo install sssp
aiida-pseudo install pseudo-dojo
こうすると、標準的な設定(PBE+Scalar Rerativistic)のポテンシャルが得られます。ノンコリニアの計算に必要なFull relrativisticなポテンシャルがほしいときには、オプションで指定します。
aiida-pseudo install pseudo-dojo -x PBE -r FR -f upf
がその一例です。
コードの登録
Quantum-Espresso内のpw.x
なども個別に登録する必要があります。
これもyaml
形式のファイルを作ってそれを読み込む形にしました。ファイル名はqe-code.yaml
にしています。
中身の例はこんな感じです。いまは先程登録したlocalhost(Aiidaを動かしているサーバー)上にコンパイルしたpw.xを登録することを想定しています。
---
label: "qe-pw"
description: "quantum_espresso"
input_plugin: "quantumespresso.pw"
on_computer: true
remote_abs_path: "/home/emi/espresso/qe-6.5/bin/pw.x"
computer: "localhost"
prepend_text: " "
append_text: " "
verdi code setup --condig qe-code.yaml
SCF計算を動かしてみる
ひとまずSiのSCF計算を動かしてみましょう。 今回は、面倒だったので手元にあったSiのインプットから構造などを読み込みます。 Si.scf.inの中身は
&control
calculation='scf'
restart_mode='from_scratch',
pseudo_dir = './'
outdir='./tmp'
prefix='Si'
tprnfor = .true., !calculate force or not
tstress = .true. !calculate stress or not
/
&system
ibrav=0,
celldm(1)=1.00000
nat=2, ntyp=1, !number of atom & number of type of atom
nspin = 1,
ecutwfc = 40.0, !planewave cutoff
ecutrho=400.0
occupations='smearing', smearing='fermi-dirac', degauss=0.02
/
&electrons
conv_thr = 1.0e-8
mixing_beta = 0.7
/
CELL_PARAMETERS {alat}
-5.450 0.000000 5.450
0.000000 5.450 5.450
-5.450 5.450 0.00000
ATOMIC_SPECIES
Si 28.0855 Si.pz-n-rrkjus_psl.0.1.UPF
ATOMIC_POSITIONS {crystal}
Si 0.00 0.00 0.00
Si 0.25 0.25 0.25
K_POINTS {automatic}
16 16 16 0 0 0
です。普段はこれを準備して、ポテンシャルのファイルも移動して…とやるのですが、Aiidaの場合は以下のスクリプトを実行することになります。
ファイル名はSi_pw.py
としておきましょう。
#!/usr/bin/env runaiida
# -*- coding: utf-8 -*-
###########################################################################
# Si bulk phonon calculation
###########################################################################
from aiida.orm import Code, StructureData
from aiida.plugins import DataFactory
from ase.io import read
from aiida import orm
from aiida.plugins import CalculationFactory
from aiida.engine import launch
from aiida.orm import load_group
codename = 'qe-pw@localhost'
code = Code.get_from_string(codename)
parameters = {
'CONTROL': {
'calculation': 'scf',
'wf_collect': True,
},
'SYSTEM': {
'ecutwfc': 80.,
'ecutrho': 320.,
'nbnd': 12,
}
}
#structure
si=read("Si.scf.in",format="espresso-in")
s = StructureData(ase=si)
#kpoint
KpointsData = DataFactory('array.kpoints')
kpoints = KpointsData()
kpoints.set_kpoints_mesh([12, 12, 12])
#pseudo
########### my aiida setup
#Label Type string Count
#----------------------- ------------------ -------
#SSSP/1.1/PBE/efficiency pseudo.family.sssp 85
##########
family = load_group('SSSP/1.1/PBE/efficiency')
inputs = {
'code': code,
'structure': s,
'pseudos': family.get_pseudos(structure=s),
'kpoints': kpoints,
'parameters': orm.Dict(dict=parameters),
'metadata': {
'options': {
'resources': {'num_machines': 1,'tot_num_mpiprocs':2},
'max_wallclock_seconds': 60*60,
'withmpi': True,
},
}
}
job=launch.submit(CalculationFactory('quantumespresso.pw'), **inputs)
print('launched WorkChain<{}> for structure {}'.format(job.pk, s.get_formula()))
print("Use `verdi process list` or `verdi process show {}` to check the progress".format(job.pk))
1行目の#!/usr/bin/env runaiida
はAiidaの環境下で実行するためのオプションです。
これを入れておくと
chmod +x Si_pw.py
で実行可能な状態にしておくと、
./Si_pw.py
でAiidaの各種機能が読み込まれた上で実行されます。 pythonファイルとして実行したい場合には
#!/usr/bin/env python
from aiida import load_profile
load_profile()
を最初に書いて、profileやdaemonの情報が取得されるようにしてやる必要があります。
スクリプトを実行すると最後の二行を反映して
launched WorkChain<4055> for structure Si2
Use `verdi process list` or `verdi process show 4055` to check the progress
のような何番目のnodeとして計算が実行されているかが出てきます。
verdi process show 4055
を実際に行うと以下のような結果が出てきます。
Property Value
----------- ------------------------------------
type PwCalculation
state Finished [0]
pk 4055
uuid 55fc17b3-7994-4456-8298-50e7291a25b1
label
description
ctime 2021-03-25 08:28:32.130701+00:00
mtime 2021-03-25 08:29:09.092721+00:00
computer [2] localhost
Inputs PK Type
---------- ---- -------------
pseudos
Si 81 UpfData
code 1414 Code
kpoints 4053 KpointsData
parameters 4054 Dict
structure 4052 StructureData
Outputs PK Type
----------------- ---- --------------
output_band 4062 BandsData
output_parameters 4064 Dict
output_trajectory 4063 TrajectoryData
remote_folder 4056 RemoteData
retrieved 4061 FolderData
標準出力の結果は
verdi calcjob outputcat 4055
で取得できますが、これだと操作しにくいですよね。
verdi process show 4055
の結果を眺めると、node4064番にアウトプットの情報が辞書型のデータ(Dict)で保存されていることがわかります。
verdi data dict show 4064
とすると、SCF計算結果のまとめがズラーッと出てきます。
{
"beta_real_space": false,
"charge_density": "./charge-density.dat",
"constraint_mag": 0,
"convergence_info": {
"scf_conv": {
"convergence_achieved": true,
"n_scf_steps": 4,
"scf_error": 5.4587806064037e-08
}
},
"creator_name": "pwscf",
"creator_version": "6.5",
"dft_exchange_correlation": "PBE",
"do_magnetization": true,
"do_not_use_time_reversal": false,
"energy": -310.5035380855,
...
特定の情報をさっと抜き出したい場合には
verdi shell
でipythonの環境を立ち上げて、そこで
In [1]: calc=load_node(4055)
In [2]: calc.outputs.output_parameters['energy']
Out[2]: -310.5035380855
のような操作をするのが一番楽かと思います。