ランダムサーチ (RS)

情報

最初はASEから始めるのが簡単なのでお勧めです.CrySPY (csp-cryspy)をインストールすると,ASEも自動的にインストールされます.

入力ファイルの準備

下記のどれか一つを従って,その後"CrySPYを実行"のセクションに移ってください.

CrySPY実行

  1. Check cryspy.in
  2. (version 0.10.3 or earlier) Script to run
  3. First run
  4. Submit job
  5. Check results
  6. Append structures
  7. Analysis and visualization

Loading external data

calc_code == extを使う場合のみ.

ランダムサーチ (RS)のサブセクション

ASE in your local PC

2023 July 10

ASEは様々なコードのインターフェースを提供しているPythonライブラリであり, Pure Python EMT calculatorというシンプルなEMTの計算も実行できる.CrySPYさえインストールしてあれば,精度はともかく簡単に計算できるので,CrySPYのテストにちょうど良い.

このチュートリアルでは,MacやLinuxなどのOSのローカルPCを用いてCu 8原子の構造探索を試す.

Assumption

ここでは次のような条件を想定している:

  • CrySPY 1.2.0 or later in your local PC
  • CrySPY job filename: job_cryspy
  • ase input filename: ase_in.py

Input files

どこか適当なワーキングディレクトリに移動して,まずはexampleをコピーしてくる.下記のどちらからコピーしてきても良い.

cd ase_Cu8_RS
tree
.
├── calc_in
│   ├── ase_in.py_1
│   └── job_cryspy
└── cryspy.in

cryspy.in

cryspy.inはCrySPYの入力ファイル.

[basic]
algo = RS
calc_code = ASE
tot_struc = 5
nstage = 1
njob = 2
jobcmd = zsh
jobfile = job_cryspy

[structure]
natot = 8
atype = Cu
nat = 8

[ASE]
ase_python = ase_in.py

[option]

[basic] セクションのjobcmd = zshは環境に合わせてjobcmd = shjobcmd = bash等に変更する. CrySPYは内部でバックグラウンドジョブとしてzsh job_cryspyを実行する.

ASEを使う場合は,[ASE]セクションが必要. 下記の二つのファイル名は好きなように変えても良い.

  • jobfile: job_cryspy
  • ase_python: ase_in.py

他の入力変数については後で説明を行う.

calc_in directory

ASEのジョブファイルや入力ファイルはこのディレクトリに準備する.

Job file

ジョブファイルの名前はcryspy.injobfileに一致させる必要がある. ジョブファイルの例は下記の通り.

#!/bin/sh

# ---------- ASE
python3 ase_in.py

# ---------- CrySPY
sed -i -e '3 s/^.*$/done/' stat_job

ase_in.pyというファイル名も自由に変えられるが, cryspy.inase_pythonの値と一致させておく必要がある. CrySPYではジョブファイルの最後の行はsed -i -e '3 s/^.*$/done/' stat_jobとしておくルールになっている.

メモ

ジョブファイルの最後の行はsed -i -e '3 s/^.*$/done/' stat_jobと書いておく.

ヒント

CrySPYのジョブファイルのCrySPY_IDという文字列は自動的に構造IDに置き換わるようになっている. PBSやSLURMといったジョブスケジューラーを使う場合,ジョブ名にCrySPY_IDと書いておくとどの構造のジョブなのかが分かり便利である. 例えば,PBSでは#PBS -N Si_CrySPY_IDのように書いておくと,ジョブをサブミットする際,#PBS -N Si_10のように置き換わる. 注意点として,ジョブ名を数字から始めるとエラーとなることが多いので,Si_のように何か文字列を頭につけておくこと.

Input for ASE

ステージ数(nstage in cryspy.in)に応じた数のインプットファイルが必要となる. インプットファイル名の語尾に_xをつけて準備する. ここでxはステージ数.

ASEのチュートリアルではnstage = 1を用いるので,ASEのインプットファイルはase_in.py_1の一つだけが必要. ase_in.py_1は例えば下記の通り(ASEの使い方の詳細は公式のドキュメントを見ること).

from ase.constraints import ExpCellFilter, StrainFilter
from ase.calculators.emt import EMT
from ase.calculators.lj import LennardJones
from ase.optimize.sciopt import SciPyFminCG
from ase.optimize import BFGS
from ase.spacegroup.symmetrize import FixSymmetry
import numpy as np
from ase.io import read, write

# ---------- input structure
# CrySPY outputs 'POSCAR' as an input file in work/xxxxxx directory
atoms = read('POSCAR', format='vasp')

# ---------- setting and run
atoms.calc = EMT()
atoms.set_constraint([FixSymmetry(atoms)])
atoms = ExpCellFilter(atoms, hydrostatic_strain=False)
opt = BFGS(atoms)
#opt=SciPyFminCG(atoms)
opt.run()

# ---------- opt. structure and energy
# [rule in ASE interface]
# output file for energy: 'log.tote' in eV/cell
#                         CrySPY reads the last line of 'log.tote'
# output file for structure: 'CONTCAR' in vasp format
e = atoms.atoms.get_total_energy()
with open('log.tote', mode='w') as f:
    f.write(str(e))

write('CONTCAR', atoms.atoms, format='vasp')

ASEはVASPやQEなどと違って,入力ファイル(python script)は自分で書くことになるので自由度がある. CrySPYでは2つのルールを設けている.

  1. エネルギーはeV/cellの単位でlog.toteというファイルに出力する.CrySPYはこのファイルの最後の行を読む.
  2. 最適化後の構造データはCONTCARというファイルにVASPフォーマットで出力する.

CrySPY実行

ここまで準備ができたらCrySPY実行へ進む.

soiap in your local PC

2024年4月21日 日本語化

soiapは原子間ポテンシャルを使用した計算ができるソフトウェアであり,計算が軽いのでCrySPYのテストにちょうど良い. soiapのインストールや詳細はinstructionsを参照.

このチュートリアルでは,MacやLinuxのローカルPC上でCrySPYを試す. テストシステムはSi 8原子.

Assumption

ここでは次のような条件を想定している:

  • (only version 0.10.3 or earlier) CrySPY main script: ~/CrySPY_root/CrySPY-0.9.0/cryspy.py
  • CrySPY job filename: job_cryspy
  • soiap executable file: ~/local/soiap-0.3.0/src/soiap
  • soiap input filename: soiap.in
  • soiap output filename: soiap.out
  • soiap input structure filename: initial.cif

Input files

どこか適当なワーキングディレクトリに移動して,まずはexampleをコピーしてくる.下記のどちらからコピーしてきても良い.

  • Download from cryspy_utility/examples/soiap_Si8_RS
  • Copy from CrySPY utility that you installed
  • (only version 0.10.3 or earlier) cp -r ~/CrySPY_root/CrySPY-0.9.0/example/v0.9.0/soiap_RS_Si8 .
cd soiap_RS_Si8
tree
.
├── calc_in
│   ├── job_cryspy
│   └── soiap.in_1
└── cryspy.in

cryspy.in

cryspy.inがCrySPYの入力ファイル.

[basic]
algo = RS
calc_code = soiap
tot_struc = 5
nstage = 1
njob = 2
jobcmd = zsh
jobfile = job_cryspy

[structure]
natot = 8
atype = Si
nat = 8

[soiap]
soiap_infile = soiap.in
soiap_outfile = soiap.out
soiap_cif = initial.cif

[option]

[basic] セクションのjobcmd = zshは環境に合わせてjobcmd = shjobcmd = bash等に変更する. CrySPYは内部でバックグラウンドジョブとしてzsh job_cryspyを実行する.

soiapを使う場合は[soiap]セクションが必要となる.下記のファイル名は好きなように変えても良い.

  • jobfile
  • soiap_infile
  • soiap_outfile
  • soiap_cif

他の入力変数については後で説明を行う.

calc_in directory

soiapのジョブファイルや入力ファイルはこのディレクトリに準備する.

Job file

ジョブファイルの名前はcryspy.injobfileに一致させる必要がある. ジョブファイルの例は下記の通り.

#!/bin/sh

# ---------- soiap
EXEPATH=/path/to/soiap
$EXEPATH/soiap soiap.in 2>&1 > soiap.out

# ---------- CrySPY
sed -i -e '3 s/^.*$/done/' stat_job

/path/to/soiapはsoiapの実行ファイルのpathに変えること. 入力ファイル(soiap.in)と出力ファイル(soiap.out)はcryspy.inで指定したsoiap_infilesoiap_outfileに合わせること. 最後の行以外は普段使っているようなジョブスクリプトで良いが, CrySPYではジョブファイルの最後の行はsed -i -e '3 s/^.*$/done/' stat_jobとしておくルールになっている.

メモ

ジョブファイルの最後の行はsed -i -e '3 s/^.*$/done/' stat_jobと書いておく.

ヒント

CrySPYのジョブファイルのCrySPY_IDという文字列は自動的に構造IDに置き換わるようになっている. PBSやSLURMといったジョブスケジューラーを使う場合,ジョブ名にCrySPY_IDと書いておくとどの構造のジョブなのかが分かり便利である. 例えば,PBSでは#PBS -N Si_CrySPY_IDのように書いておくと,ジョブをサブミットする際,#PBS -N Si_10のように置き換わる. 注意点として,ジョブ名を数字から始めるとエラーとなることが多いので,Si_のように何か文字列を頭につけておくこと.

Input for soiap

ステージ数(nstage in cryspy.in)に応じた数のインプットファイルが必要となる. インプットファイル名の語尾に_xをつけて準備する. ここでxはステージ数.

soiapのチュートリアルではnstage = 1を用いるので,インプットファイルはsoiap.in_1の一つだけが必要. soiap.in_1は例えば下記の通り.

crystal initial.cif ! CIF file for the initial structure
symmetry 1 ! 0: not symmetrize displacements of the atoms or 1: symmetrize

md_mode_cell 3 ! cell-relaxation method
               ! 0: FIRE, 2: quenched MD, or 3: RFC5
number_max_relax_cell 100 ! max. number of the cell relaxation
number_max_relax 1 ! max. number of the atom relaxation
max_displacement 0.1 ! max. displacement of atoms in Bohr

external_stress_v 0.0 0.0 0.0 ! external pressure in GPa

th_force 5d-5 ! convergence threshold for the force in Hartree a.u.
th_stress 5d-7 ! convergence threshold for the stress in Hartree a.u.

force_field 1 ! force field
              ! 1: Stillinger-Weber for Si, 2: Tsuneyuki potential for SiO2,
              ! 3: ZRL for Si-O-N-H, 4: ADP for Nd-Fe-B, 5: Jmatgen, or
              ! 6: Lennard-Jones

1行目に書く初期構造ファイル(initial.cif)はcryspy.insoiap_cifの値と揃える.

CrySPY実行

ここまで準備ができたらCrySPY実行へ進む.

VASP

2024 April 24

このチュートリアルでは,PBSなどのジョブスケジューラーを備えたPCクラスターを想定してCrySPYを試す.第一原理計算のVASPを用いて,Na8Cl8(16原子)の構造探索を行う.

Assumption

ここでは次のような条件を想定している:

  • CrySPY 1.2.0 or later in your PC cluster
  • CrySPY job command: qsub
  • CrySPY job filename: job_cryspy
  • executable file, vasp_std in your PC cluster

Input files

どこか適当なワーキングディレクトリに移動して,まずはexampleをコピーしてくる.下記のどちらからコピーしてきても良い.

cd vasp_Na8Cl8_RS
tree
.
├── calc_in
│   ├── INCAR_1
│   ├── INCAR_2
│   ├── POTCAR
│   ├── POTCAR_is_dummy
│   └── job_cryspy
└── cryspy.in

cryspy.in

cryspy.inはCrySPYの入力ファイル.

[basic]
algo = RS
calc_code = VASP
tot_struc = 5
nstage = 2
njob = 2
jobcmd = qsub
jobfile = job_cryspy

[structure]
natot = 16
atype = Na Cl
nat = 8 8
mindist_1 = 2.5 1.5
mindist_2 = 1.5 2.5

[VASP]
kppvol = 40 80

[option]

[basic] セクションのjobcmd = qsubは環境に合わせて変更する. CrySPYは内部でバックグラウンドジョブとしてqsub job_cryspyを実行する. 下記のファイル名は好きなように変えても良い.

  • jobfile

構造最適化計算はステージ制を採用しており,ここではnstage = 2を用いている. 例えば,最初のステージでは,セルを固定し内部座標だけ緩和する設定で,k点も少ない計算を実行し,2ステージ目でセルも含めてフルに構造緩和して,精度も高めるようなことが可能となっている.

VASPを使う場合は,[VASP]セクションが必要. ここでは各ステージにおけるk点のグリッド密度(Å^-3)をkppvolに指定する必要がある.

情報

kppvolの詳細はこちら –> Input file > Kpoint

他のインプット変数に関しては後ほど説明する.

calc_in directory

ジョブファイルやVASPのインプットをこのディレクトリに置く.

Job file

ジョブファイルの名前はcryspy.injobfileに一致させる必要がある. ジョブファイルの例は下記の通り.

#!/bin/sh
#$ -cwd
#$ -V -S /bin/bash
####$ -V -S /bin/zsh
#$ -N Na8Cl8_CrySPY_ID
#$ -pe smp 20
####$ -q ibis1.q
####$ -q ibis2.q
####$ -q ibis3.q
####$ -q ibis4.q

# ---------- vasp
VASPROOT=/usr/local/vasp/vasp.6.4.2/bin
mpirun -np $NSLOTS $VASPROOT/vasp_std

# ---------- CrySPY
sed -i -e '3 s/^.*$/done/' stat_job

VASPROOTは環境に合わせて変更する.普段VASPのジョブを流しているジョブファイルを使えば良い.ただし,CrySPYではジョブファイルの最後の行はsed -i -e '3 s/^.*$/done/' stat_jobとしておくルールになっている.

メモ

ジョブファイルの最後の行はsed -i -e '3 s/^.*$/done/' stat_jobと書いておく.

ヒント

CrySPYのジョブファイルのCrySPY_IDという文字列は自動的に構造IDに置き換わるようになっている. PBSやSLURMといったジョブスケジューラーを使う場合,ジョブ名にCrySPY_IDと書いておくとどの構造のジョブなのかが分かり便利である. 例えば,PBSでは#PBS -N Si_CrySPY_IDのように書いておくと,ジョブをサブミットする際,#PBS -N Si_10のように置き換わる. 注意点として,ジョブ名を数字から始めるとエラーとなることが多いので,Si_のように何か文字列を頭につけておくこと.

Input for VASP

ステージ数(nstage in cryspy.in)に応じた数のインプットファイルが必要となる. インプットファイル名の語尾に_xをつけて準備する. ここでxはステージ数.

今はnstage = 2を用いているので,INCAR_1INCAR_2が必要となる. ここでは,INCAR_1はセルを固定して内部座標だけ緩和する設定,INCAR_2はセルも含めてフルに緩和する設定になっている.

INCAR_1

SYSTEM = NaCl
!!!LREAL = Auto
Algo = Fast
NSW = 40

LWAVE = .FALSE.
!LCHARG = .FALSE.

ISPIN =  1

ISMEAR = 0
SIGMA = 0.1

IBRION = 2
ISIF = 2

EDIFF = 1e-5
EDIFFG = -0.01

INCAR_2

SYSTEM = NaCl
!!LREAL = Auto
Algo = Fast
NSW = 200

ENCUT = 341

!!LWAVE = .FALSE.
!!LCHARG = .FALSE.


ISPIN =  1

ISMEAR = 0
SIGMA = 0.1

IBRION = 2
ISIF = 3

EDIFF = 1e-5
EDIFFG = -0.01

CrySPYはPOSCARKPOINTSファイルを自動生成する. POTCARファイルはユーザーが準備する必要がある. このexampleに含まれているPOTCARは空のファイルなので,各自で準備すること.

警告

exampleに含まれているPOTCARは空のファイル.配布できない.

CrySPY実行

ここまで準備ができたらCrySPY実行に進む.

QE

2024 April 24,日本語化

このチュートリアルでは,PBSなどのジョブスケジューラーを備えたPCクラスターを想定してCrySPYを試す.第一原理計算のQUANTUM ESPRESSOを用いて,Si 8原子の構造探索を行う.

Assumption

ここでは次のような条件を想定している:

  • CrySPY job command: qsub
  • CrySPY job filename: job_cryspy
  • QE executable file: /usr/local/qe-6.5/bin/pw.x
  • QE input filename: pwscf.in
  • QE output filename: pwscf.out

Input files

どこか適当なワーキングディレクトリに移動して,まずはexampleをコピーしてくる.下記のどちらからコピーしてきても良い.

cd QE_RS_Si8
tree
.
├── calc_in
│   ├── job_cryspy
│   ├── pwscf.in_1
│   └── pwscf.in_2
└── cryspy.in

cryspy.in

cryspy.inはCrySPYの入力ファイル.

[basic]
algo = RS
calc_code = QE
tot_struc = 5
nstage = 2
njob = 2
jobcmd = qsub
jobfile = job_cryspy

[structure]
natot = 8
atype = Si
nat = 8

[QE]
qe_infile = pwscf.in
qe_outfile = pwscf.out
kppvol =  40  80

[option]

[basic] セクションのjobcmd = qsubは環境に合わせて変更する. CrySPYは内部でバックグラウンドジョブとしてqsub job_cryspyを実行する.

構造最適化計算はステージ制を採用しており,ここではnstage = 2を用いている. 例えば,最初のステージでは,セルを固定し内部座標だけ緩和する設定で,k点も少ない計算を実行し,2ステージ目でセルも含めてフルに構造緩和して,精度も高めるようなことが可能となっている.

QEを使う場合は,[QE]セクションが必要. ここでは各ステージにおけるk点のグリッド密度(Å^-3)をkppvolに指定する必要がある.

情報

kppvolの詳細はこちら –> Input file > Kpoint

下記のファイル名は好きなように変えても良い.

  • jobfile
  • qe_infile
  • qe_outfile

他のインプット変数に関しては後ほど説明する.

calc_in directory

ジョブファイルやQEのインプットをこのディレクトリに置く.

Job file

ジョブファイルの名前はcryspy.injobfileに一致させる必要がある. ジョブファイルの例は下記の通り.

#!/bin/sh
#$ -cwd
#$ -V -S /bin/bash
####$ -V -S /bin/zsh
#$ -N Si8_CrySPY_ID
#$ -pe smp 20
####$ -q ibis1.q
####$ -q ibis2.q

mpirun -np $NSLOTS /path/to/pw.x < pwscf.in > pwscf.out


if [ -e "CRASH" ]; then
    sed -i -e '3 s/^.*$/skip/' stat_job
    exit 1
fi

sed -i -e '3 s/^.*$/done/' stat_job

/path/to/pw.xは環境に合わせて変更する. 入力(pwscf.in)出力(pwscf.out)ファイルの名前は好きに変えて良いが,cryspy.inqe_infileqe_outfileに合わせる必要がある. 普段VASPのジョブを流しているジョブファイルを使えば良い.ただし,CrySPYではジョブファイルの最後の行はsed -i -e '3 s/^.*$/done/' stat_jobとしておくルールになっている.

メモ

ジョブファイルの最後の行はsed -i -e '3 s/^.*$/done/' stat_jobと書いておく.

ヒント

CrySPYのジョブファイルのCrySPY_IDという文字列は自動的に構造IDに置き換わるようになっている. PBSやSLURMといったジョブスケジューラーを使う場合,ジョブ名にCrySPY_IDと書いておくとどの構造のジョブなのかが分かり便利である. 例えば,PBSでは#PBS -N Si_CrySPY_IDのように書いておくと,ジョブをサブミットする際,#PBS -N Si_10のように置き換わる. 注意点として,ジョブ名を数字から始めるとエラーとなることが多いので,Si_のように何か文字列を頭につけておくこと.

Input for QE

ステージ数(nstage in cryspy.in)に応じた数のインプットファイルが必要となる. インプットファイル名の語尾に_xをつけて準備する. ここでxはステージ数.

今はnstage = 2を用いているので,pwscf.in_1pwscf.in_2が必要となる. ここでは,pwscf.in_1はセルを固定して内部座標だけ緩和する設定,pwscf.in_2はセルも含めてフルに緩和する設定になっている.

pwscf.in_1

 &control
    title = 'Si8'
    calculation = 'relax'
    nstep = 100
    restart_mode = 'from_scratch',
    pseudo_dir = '/usr/local/pslibrary.1.0.0/pbe/PSEUDOPOTENTIALS/'
    outdir='./out.d/'
 /

 &system
    ibrav = 0
    nat = 8
    ntyp = 1
    ecutwfc = 44.0
    occupations = 'smearing'
    degauss = 0.01
 /

 &electrons
 /

 &ions
 /

 &cell
 /

ATOMIC_SPECIES
  Si  28.086  Si.pbe-n-kjpaw_psl.1.0.0.UPF

pwscf.in_2

 &control
    title = 'Si8'
    calculation = 'vc-relax'
    nstep = 200
    restart_mode = 'from_scratch',
    pseudo_dir = '/usr/local/pslibrary.1.0.0/pbe/PSEUDOPOTENTIALS/'
    outdir='./out.d/'
 /

 &system
    ibrav = 0
    nat = 8
    ntyp = 1
    ecutwfc = 44.0
    occupations = 'smearing'
    degauss = 0.01
 /

 &electrons
 /

 &ions
 /

 &cell
 /

ATOMIC_SPECIES
  Si  28.086  Si.pbe-n-kjpaw_psl.1.0.0.UPF

pseudo_dirは各自の環境に合わせて変更する. Inputs for structure data and k-point such as インプットファイルのATOMIC_POSITIONSK_POINTSはCrySPYがpymatgenを用いて自動生成するのでユーザーが書く必要はない.

CrySPY実行

ここまで準備ができたらCrySPY実行に進む.

OpenMX

Coming soon.

LAMMPS

Coming soon.

External program

Available from CrySPY 0.11.0.

If you use an external program not supported by CrySPY, the optimized energy and structure data can be loaded semi-manually in CrySPY. You have to prepare two files, ext_opt_struc_data.pkl and ext_energy_data.pkl.

Assumption

Here, we assume the following conditions:

  • (version 0.10.3 or earlier) CrySPY main script: ~/CrySPY_root/CrySPY-0.11.0/cryspy.py

(calc_in directory is not required.)

Input files

Move to your working directory, and copy input example files.

  • version 1.0.0 or later
    • Copy from CrySPY utility
  • version 0.10.3 or earlier
    • cp -r ~/CrySPY_root/CrySPY-0.9.0/example/ext_Si8_RS .
cd ext_Si8_RS
tree
.
└── cryspy.in

cryspy.in

cryspy.in is the input file of CrySPY.

[basic]
algo = RS
calc_code = ext
tot_struc = 5

[structure]
natot = 8
atype = Si
nat = 8

[option]

If calc_code == ext, nstage, njob, jobcmd, and jobfile are ignored.

Running CrySPY

This mode is different from the normal use of CrySPY. Go to Load external data.

Check cryspy.in

See Input file in detail.

Let’s take a look at cryspy.in again. This may be slightly different depending on calc_code you chose.

[basic]
algo = RS
calc_code = soiap
tot_struc = 5
nstage = 1
njob = 2
jobcmd = zsh
jobfile = job_cryspy

[structure]
natot = 8
atype = Si
nat = 8

[soiap]
soiap_infile = soiap.in
soiap_outfile = soiap.out
soiap_cif = initial.cif

[option]

[basic] section

  • algo: Algorithm. Set RS for Random Search.
  • calc_code: Structure optimizer. Choose from VASP, QE, OMX, soiap, LAMMPS
  • tot_struc: The total number of structures. In this case, 5 random structures are generated at 1st run.
  • nstage: The number of stages. It’s up to you.
  • njob: The number of jobs running at the same time. In this example, CrySPY sets 2 slots for structure optimization, in other words, optimizes every 2 structures.
  • jobcmd: Command for jobs. Use bash, zsh, qsub, and so on.
  • jobfile: File name of the job file.

[structure] section

  • natot: The total number of atoms. e.g. for Na8Cl8: natot = 16.
  • atype: Atom type. e.g. for Na8Cl8: atype = Na Cl.
  • nat: The number of each atom. e.g. for Na8Cl8: nat = 8 8

Script to run

メモ

For version 1.0.0 or later, skip this page. The executable script is automatically installed.

Assumption

Here, we assume the following condition:

  • CrySPY main script: ~/CrySPY_root/CrySPY-0.9.0/cryspy.py

Make script

Let’s make a convenient shell script to avoid typing long commands over and over again. Here, we create the script, cryspy (any file name will do).

$ emacs cryspy
$ chmod 744 cryspy
$ cat cryspy
#!/bin/sh

python3 -u ~/CrySPY_root/CrySPY-0.9.0/cryspy.py 1>> log 2>> err

-u option (unbuffered option) can be omitted.

You can put this script in your $PATH, or just use like bash ./cryspy.

Firsrt run

2023 July 10, update

Make sure you have the following in your working directory.

  • calc_in/
  • (cryspy)
  • cryspy.in
$ ls
calc_in/  cryspy.in

Then, run CyrSPY!

cryspy

If you use old version (0.10.3 or earlier):

bash ./cryspy

At the first run, CrySPY goes into structure generation mode. CrySPY stops after 5 structure generation.

If it worked properly, the following output appears on the screen:

[2023-07-10 18:40:54,389][cryspy_init][INFO] 


Start CrySPY 1.2.0


[2023-07-10 18:40:54,389][cryspy_init][INFO] # ---------- Read input file, cryspy.in
[2023-07-10 18:40:54,390][read_input][INFO] Save input data in cryspy.stat
[2023-07-10 18:40:54,391][cryspy_init][INFO] # ---------- Initial structure generation
[2023-07-10 18:40:54,391][cryspy_init][INFO] Number of MPI processes: 1
[2023-07-10 18:40:54,391][gen_init_struc][INFO] # ------ mindist
[2023-07-10 18:40:54,395][struc_util][INFO] Cu - Cu: 1.32
[2023-07-10 18:40:54,395][gen_init_struc][INFO] # ------ generate structures
[2023-07-10 18:40:54,481][gen_pyxtal][INFO] Structure ID      0 was generated. Space group:   1 -->   1 P1
[2023-07-10 18:40:54,493][gen_pyxtal][INFO] Structure ID      1 was generated. Space group:  28 -->  28 Pma2
[2023-07-10 18:40:54,498][gen_pyxtal][INFO] Structure ID      2 was generated. Space group:  29 -->  29 Pca2_1
[2023-07-10 18:40:54,704][gen_pyxtal][INFO] Structure ID      3 was generated. Space group: 137 --> 137 P4_2/nmc
[2023-07-10 18:40:54,725][gen_pyxtal][INFO] Structure ID      4 was generated. Space group: 212 --> 214 I4_132
[2023-07-10 18:40:54,800][cryspy_init][INFO] Elapsed time for structure generation: 0:00:00.408367
cryspy  4.35s user 1.04s system 145% cpu 3.697 total

Several output files are also generated.

  • (cryspy.out): Short log. only version 0.10.3 or earlier.
  • cryspy.stat: Status file.
  • data/init_POSCARS: Initial struture file in POSCAR format. You can open this file using VESTA
  • data/pkl_data: Directory to save pickled data.
  • log_cryspy: log.
  • err_cryspy: error and warning.

Let’s take a look at cryspy.stat file.

...
(omit)
...
[status]
id_queueing = 0 1 2 3 4

Structure ID 0 – 4 are queueing because we just generated structures, and have not submitted yet.

ヒント

Check the initial structures, if the distance between atoms is too close, you should set the mindist in cryspy.in.

Submit job

2024年4月21日更新,日本語化

計算再開

CrySPYはcryspy.statファイルがあれば自動的に計算を再開する.

ヒント

crypy.statがあれば続きから再開.
はじめから計算をしたければcryspy.statを削除する.

ジョブの投入

cryspyをもう一度実行する.

cryspy

画面かlog_cryspyファイルに下記のように出力される.

[2023-07-10 18:52:51,859][cryspy_restart][INFO] 


Restart CrySPY 1.2.0


[2023-07-10 18:52:51,869][ctrl_job][INFO] # ---------- job status
[2023-07-10 18:52:51,904][ctrl_job][INFO] ID      0: submit job, Stage 1
[2023-07-10 18:52:51,931][ctrl_job][INFO] ID      1: submit job, Stage 1

cryspy.statでステータスが確認できる.

...
(omit)
...
[status]
id_queueing = 2 3 4
id      0 = Stage 1
id      1 = Stage 1

cryspy.innjob = 2に設定されているので,CrySPYは構造ID 0と1の二つのジョブをサブミットした. 計算はworkディレクトリの中で行われる.各構造IDのディレクトリが作られる.

tree -d work
work
├── 000000
├── 000001
└── fin

二つのジョブが終了したら,もう一度cryspyを実行する.

cryspy
[2023-07-10 18:55:01,053][cryspy_restart][INFO] 


Restart CrySPY 1.2.0


[2023-07-10 18:55:01,058][ctrl_job][INFO] # ---------- job status
[2023-07-10 18:55:01,058][ctrl_job][INFO] ID      0: Stage 1 Done!
[2023-07-10 18:55:01,093][ctrl_job][INFO]     collect results: E = -0.00696997755502915 eV/atom
[2023-07-10 18:55:01,132][ctrl_job][INFO] ID      1: Stage 1 Done!
[2023-07-10 18:55:01,133][ctrl_job][INFO]     collect results: E = 0.4934076667166454 eV/atom
[2023-07-10 18:55:01,144][cryspy][INFO] 

recheck 1

[2023-07-10 18:55:01,145][ctrl_job][INFO] # ---------- job status
[2023-07-10 18:55:01,153][ctrl_job][INFO] ID      2: submit job, Stage 1
[2023-07-10 18:55:01,161][ctrl_job][INFO] ID      3: submit job, Stage 1

もしnstage = 2のようにnstageを2以上に設定していれば,ID 0と1のstage 2のジョブがサブミットされる. 今回はnstage = 1なので,ID 0と1の計算データを収集して,次のIDのジョブをサブミットする. 計算が終わった構造のディレクトリはfinディレクトリに移動される.

5構造全ての計算が終わるまでcryspyを繰り返し実行する. すべての計算が終わって,計算結果の詳細が必要なければworkディレクトリを削除しても良い.

何度も何度もcryspyを繰り返し実行する時は,自動スクリプト(repeat_cryspy)が役に立つ.

Check results

Move to data directory. There should be a few more files.

$ cd data
$ ls
cryspy_rslt  cryspy_rslt_energy_asc  init_POSCARS  opt_POSCARS  pkl_data/
  • cryspy_rslt: Result file.
  • cryspy_rslt_energy_asc: Result file sorted in energy ascending order.
  • init_POSCARS: Initial struture file in POSCAR format.
  • opt_POSCARS: Optimized structure file in POSCAR format.
  • pkl_data/: Directory to save pickled data.

The results are written to text files, cryspy_rslt and cryspy_rslt_energy_asc (and also saved in pickle data in pkl_data directory).

Each result appends to cryspy_rslt file in the order in which one finished earlier.

cat cryspy_rslt
   Spg_num Spg_sym  Spg_num_opt Spg_sym_opt  E_eV_atom  Magmom      Opt
0      139  I4/mmm          139      I4/mmm  -3.000850     NaN     done
1       98  I4_122           12        C2/m  -3.978441     NaN  not_yet
2       16    P222           16        P222  -3.348616     NaN  not_yet
3       36  Cmc2_1           36      Cmc2_1  -3.520306     NaN  not_yet
4       36  Cmc2_1            4        P2_1  -3.304168     NaN  not_yet
情報

Not ID order in cryspy_rslt

In cryspy_rslt_energy_asc file, the results are sorted in energy ascending order.

cat cryspy_rslt_energy_asc
   Spg_num Spg_sym  Spg_num_opt Spg_sym_opt  E_eV_atom  Magmom      Opt
1       98  I4_122           12        C2/m  -3.978441     NaN  not_yet
3       36  Cmc2_1           36      Cmc2_1  -3.520306     NaN  not_yet
2       16    P222           16        P222  -3.348616     NaN  not_yet
4       36  Cmc2_1            4        P2_1  -3.304168     NaN  not_yet
0      139  I4/mmm          139      I4/mmm  -3.000850     NaN     done

Spg_num and Spg_sym show space group information on initial structures. Spg_num_opt and Spg_sym_opt are those of optimized structures. The last column Opt indicates whether or not optimization reached required accuracy.

Append structures

Of course only 5 structures are not enough to find stable structures. You can append structures whenever you want. Here let’s append more 5 structures.

For Si-Si mindist, the default value of 1.11 Å is used in the first structure generation (see log_cryspy), which is a little too close. Let us try to set the mindist to 2.0 Å.

Edit cryspy.in and change the value of tot_struc into 10, and add mindist_1 = 2.0

emacs cryspy.in
cat cryspy.in
[basic]
algo = RS
calc_code = soiap
tot_struc = 10
nstage = 1
njob = 2
jobcmd = zsh
jobfile = job_cryspy

[structure]
natot = 8
atype = Si
nat = 8
mindist_1 = 2.0

[soiap]
soiap_infile = soiap.in
soiap_outfile = soiap.out
soiap_cif = initial.cif

[option]

Then run cryspy, and check log_cryspy file.

cryspy &
cat log_cryspy
...
(omit)
...

2023/03/19 00:01:47
CrySPY 1.0.0
Restart cryspy.py


Changed tot_struc from 5 to 10
Changed mindist from None to [[2.0]]

Backup data

# ---------- Append structures
# ------ mindist
Si - Si 2.0
Structure ID      5 was generated. Space group: 218 --> 221 Pm-3m
Structure ID      6 was generated. Space group:  86 --> 129 P4/nmm
Structure ID      7 was generated. Space group: 129 --> 129 P4/nmm
Structure ID      8 was generated. Space group: 191 --> 191 P6/mmm
Structure ID      9 was generated. Space group:  31 -->  31 Pmn2_1

Remember that CrySPY goes into structure generation mode whenever you change the value of tot_struc. In this mode, CrySPY does not do any other action such as collecting data, submitting jobs, and so on.

メモ

Structure generation mode whenever you change the value of tot_struc.
From version 1.0.0, CrySPY automatically backs up when adding structures. See features/backup.

Repeat cryspy & several times until all appended structures are done. The auto script may help you.

repeat_cryspy

Analysis and visualization

Download the data

It is assumed here that you analyze and visualize CrySPY data in your local PC. If you use CrySPY in super computers or workstations, download the data in your local PC. You can delete the work and backup directory if you do not need it because the file size could be very large.

jupyter notebook

Move to the data/ directory in results you just download. Then copy cryspy_analyzer_RS.ipynb from CrySPY utility.

$ ls
calc_in/ cryspy.in cryspy.stat  data/  err_cryspy  log_cryspy
$ cd data
$ ls
cryspy_rslt  cryspy_rslt_energy_asc  init_POSCARS  opt_CIFS.cif  opt_POSCARS  pkl_data/
cp /path/to/CrySPY_utility/cryspy_analyzer_RS.ipynb .

Run jupyter. (VScode, jupyter lab, jupyter notebook, and so on.) You can get the following figure by simply running the steps in order.

RS for Si8 RS for Si8

Load external data

You need only cryspy.in.

$ ls
cryspy.in

Then, run CyrSPY.

cryspy &

At the first run, CrySPY goes into structure generation mode as usual. CrySPY stops after 5 structure generation.

If it worked properly, log_cryspy would look like this.

2022/07/14 19:41:41
CrySPY 1.0.0
Start cryspy.py

Read input file, cryspy.in
Write input data in cryspy.out
Save input data in cryspy.stat

# --------- Generate initial structures
# ------ mindist
Si - Si 1.11
Structure ID      0 was generated. Space group:  88 --> 141 I4_1/amd
Structure ID      1 was generated. Space group: 101 --> 101 P4_2cm
Structure ID      2 was generated. Space group: 204 --> 229 Im-3m
Structure ID      3 was generated. Space group: 199 --> 199 I2_13
Structure ID      4 was generated. Space group:  12 -->  12 C2/m

Unlike normal use, a directory named ext was created. Only the stat_job file exists in ext/.

$ cat ext/stat_job
out

If you run cryspy when “out” is written in the stat_job file, queueing structure files (cif format) are exported in ext/queue.

cryspy &
$ ls ext/queue
0.cif  1.cif  2.cif  3.cif  4.cif

The number in the file name is structure ID. The fist line of stat_job was automatically changed.

$ cat ext/stat_job
submitted

Perform structure optimization and energy evaluation in an external program using the output cif files. Once that calculation is done, prepare the optimized structure and energy data in the pickle data format, ext_opt_struc_data.pkl and ext_energy_data.pkl.

The data format of ext_opt_struc_data.pkl is the same as init_struc_data.pkl and opt_struc_data.pkl, see Data format/Initial and optimized structure data.

The data format of ext_energy_data.pkl is similar to ext_opt_struc_data.pkl. Just change the value from the structure data into the energy. An example of the energy data (dict type) is shown below.

  • key: structure ID
  • value: energy
{0: -0.7139331910805997,
 1: -0.5643404689832622,
 2: -0.5832404287259171,
 3: -0.535037327286169,
 4: -0.6316663459586607}

The ext/calc_data directory should be automatically generated, so put the two pickle files here.

$ ls ext/calc_data
ext_energy_data.pkl  ext_opt_struc_data.pkl

When ready, replace the first line of the stat_job file with “done” and run CrySPY.

$ emacs /ext/stat_job
$ cat /ext/stat_job
done
cryspy &

CrySPY collects the result data.