PyPI version PyPI version

ドキュメント

CrySPY(クリスピー)は機械学習を利用したPython製の結晶構造探索ツールであり,クリスピーと読む. 難しい操作を必要とせず,入力ファイルを準備するだけで以下の事が自動で行える.

  • 構造生成
  • 構造最適化のジョブの実行
  • 構造最適化データの収集
  • 機械学習による候補の選択

pip install csp-cryspyでインストールできる.

fig_csp fig_csp

最新バージョン

CrySPY 1.4.0 (2025年6月17日)

ニュース

Discussions

Discussions in GitHub (質問やコメント)

ライセンス

CrySPY is distributed under the MIT License
Copyright (c) 2018 CrySPY Development Team

コード開発貢献者

  • 山下 智樹および研究室メンバー (長岡技術科学大学)
  • 佐藤 暢哉 (産業技術総合研究所)
  • 木野 日織 (物質・材料研究機構)
  • 寺山 慧 (横浜市立大学)
  • 澤端 日華瑠 (金沢大学)
  • 兼平 慎一 (大阪大学)

関連文献

  • CrySPY(ソフトウェア)

    • T. Yamashita, S. Kanehira, N. Sato, H. Kino, H. Sawahata, T. Sato, F. Utsuno, K. Tsuda, T. Miyake, and T. Oguchi,
      “CrySPY: a crystal structure prediction tool accelerated by machine learning”,
      Sci. Technol. Adv. Mater. Meth. 1, 87 (2021). Link
  • ベイズ最適化

    • T. Yamashita, N. Sato, H. Kino, T. Miyake, K. Tsuda, and T. Oguchi,
      “Crystal structure prediction accelerated by Bayesian optimization”,
      Phys. Rev. Mater. 2, 013803 (2018). Link
    • N. Sato, T. Yamashita, T. Oguchi, K. Hukushima, and T. Miyake,
      “Adjusting the descriptor for a crystal structure search using Bayesian optimization”,
      Phys. Rev. Mater. 4, 033801 (2020). Link
  • ベイズ最適化と進化的アルゴリズム

    • T. Yamashita, H. Kino, K. Tsuda, T. Miyake, and T. Oguchi,
      “Hybrid algorithm of Bayesian optimization and evolutionary algorithm in crystal structure prediction”,
      Sci. Technol. Adv. Mater. Meth. 2, 67 (2022). Link
  • LAQA

    • K.Terayama, T. Yamashita, T. Oguchi, and K. Tsuda,
      Fine-grained optimization method for crystal structure prediction",
      npj Comput. Mater. 4, 32 (2018). Link
    • T. Yamashita and H. Sekine,
      “Improvement of look ahead based on quadratic approximation for crystal structure prediction”,
      Sci. Technol. Adv. Mater. Meth. 2, 84 (2022). Link

GitHub repo GitHub discussions CrySPY utility

のサブセクション

バージョン情報のサブセクション

Version 1.4.0

Important change

New algorithm: EA-vc

インタラクティブモード

EA

  • EAではtot_strucを不使用にした.第1世代の構造数もn_popを利用するように変更

構造最適化後の原子間距離チェック

  • cryspy.inの[option]セクションにcheck_mindist_optを追加.
  • デフォルトでcheck_mindist_opt = True
  • 構造最適化後に最小原子間距離の制限を満たしているかチェックする.

Common

  • cryspy.innatotを廃止
  • Ctrl_extの廃止

Fixed

  • BOでscoreTSを使うときのバグを修正
  • その他いくつかマイナー修正

Version 1.3.0

Important change

Common

  • workingディレクトリ名の変更
    work000000 –> work0
  • いくつかのデータをタプルにまとめてpickle化して保存していたが,それぞれ個別にデータをpickle化するように変更
    For example, rs_id_data.pkl –> id_queueing.pkl and id_running.pkl

BO

Fixed

soiap

  • 最近のpymatgenで動くように修正

Added

  • ランダム構造生成と進化的アルゴリズムによる構造生成はライブラリとして使用可能に.see Features > As library

for developer

  • グローバル変数を廃止 (rin), 入力変数にはdataclassを採用
  • リストとして使っていた入力変数の多くはタプルに変更

Version 1.2.5

Bug fix

  • simple bug fix

Version 1.2.2

エンタルピー

VASPとQEでは全エネルギーの代わりにエンタルピーが利用可能.

See also

Version 1.2.1

ASE interface

Bug fixed for multiple stages.

Version 1.1.1

spg_errorのバグ修正

ランダム構造生成時,ある空間群で構造生成ができない時にsgp_errorという変数にその空間群番号を記録し,以降その番号はスキップするようにしていたが,ごく稀に間違って登録されてしまうバグが見つかった.よってこのspg_errorという機能は削除した.

Version 1.1.0

MPI並列

MPIを用いたランダム構造生成が利用可能.

詳細は下記を参照.

LAQA

ストレス項を考慮に入れたスコアが利用できるように更新 (T. Yamashita and H. Sekine, Sci. Technol. Adv. Mater. Meth. 2, 84 (2022).).

詳細は下記を参照.

Backup

日付でディレクトリを作ることでバックアップの履歴が残るように変更. 詳細はfeatures/backup

Version 1.0.0

Install and run

CrySPY is now available in PyPI. You can install by

pip install csp-cryspy

The executable script, cryspy is automatically installed in your PATH. To run CrySPY, just type cryspy:

cryspy &

CrySPY stops once before going to next selection (BO, LAQA) or next generation (EA). For example, EA case:

[old version]

  • cryspy run
    • check jobs (finish current generation?)
    • structure generation by EA automatically starts

[CrySPY 1.0.0]

  • cryspy run
    • check jobs (finish current generation?)
    • stop
  • cryspy run
    • auto backup
    • structure generation by EA automatically starts

Auto and manual backup

Automatically backup:

  • before going to next selection or next generation
  • structure generation

To manually back up:

cryspy -b

See features/backup in detail.

Clean

cryspy -c

See features/clean in detail.

Directory tree

Changed the directory tree.

  • genstruc/RS –> RS/
  • genstruc/EA –> EA/
  • genstruc/struc_util.py –> util/
  • utility.py –> util/

IO

  • Fixed standard output file and standard error file: log_cryspy and err_cryspy
  • cryspy.out is obsoleted

Moved to CrySPY Utility

With the change in installation method, examples and cal_fingerprint have been moved to the CrySPY Utility.

COMBO

The python library COMBO is now optional in CrySPY. If you do not use Bayesian optimizaion, you do not need to install it.

New calc_code

  • ext: Deprecated in version 1.4.0.

cryspy.in

fppath

New input variable for cal_fingerprint. See Instllation/cryspy/cryspy_1.0

fwpath

New input variable for find_wy. See Instllation/requirements/find_wy

mindist

  • mindist can be omitted in cryspy.in
  • mindist_ea is obsoleted
  • added mindist_mol_bs and mindist_mol_bs_factor in cryspy.in

Version 0.10.3 or earlier

  • [2022 May 17] version 0.10.3 released
    • Bug fixed: LAMMPS IO.
  • [2022 January 24] version 0.10.2 released
    • Added nrot: maximum number of times to rotate molecules in mol_bs
  • [2021 September 30] version 0.10.1 released
    • Fixed the problem of numpy.random.seed in multiprocessing
  • [2021 July 25] version 0.10.0 released
    • Support PyXtal 0.2.9 or later
    • LAQA can be used with QE
    • Upper and lower limits of energy for EA and BO
  • [2021 July 13] paper published
    • Our paper on CrySPY software has been published in STAM:Methods
  • [2021 March 18] version 0.9.2 released
    • Support pymatgen v2022.
  • [2021 February 7] version 0.9.0 released
    • Interfaced with OpenMX
    • Employ PyXtal library to generate initial structures
    • If you use PyXtal (default), find_wy program is not required
    • LAQA can be used with soiap
    • Change the name: [lattice] section –> [structure] section
    • Several input variables move to [structure] section
      • natot: [basic] –> [structure]
      • atype: [basic] –> [structure]
      • nat: [basic] –> [structure]
      • maxcnt: [option] –> [structure]
      • symprec: [option] –> [structure]
      • spgnum: [option] –> [structure]
    • New features
      • Molecular crystal structure generation
      • Scale volume
  • [2020 March 19] paper published
  • [2020 February 16] version 0.8.0 released
    • Migrate to Python 3
    • CrySPY logo created
    • Change several variable names and data formats
    • Change style of output for energy: eV/cell –> eV/atom
    • IDs of working directories corresponds to structure IDs
    • New features
      • recalculation
      • manual select in BO
  • [2018 December 5] version 0.7.0 released
    • New features
      • Evolutionary algorithm
  • [2018 August 20] version 0.6.4 released
  • [2018 July 2] version 0.6.3 released
  • [2018 June 26] Version 0.6.2 released
  • [2018 March 1] Version 0.6.1 released
  • [2018 January 9] paper published

インストールのサブセクション

動作環境のサブセクション

Python

Python

CrySPY 1.3.0 or later

  • Python >= 3.8
    • PyXtal (>= 0.5.3)
    • (optional) mpi4py
    • (optional, required if algo is BO) PHYSBO (Not COMBO)
    • (optional, required if algo is BO) dscribe
    • (optional) nglview

pipでcsp-cryspyをインストールすると,必須ライブラリのPyXtal,pymatgen,ASEなどは自動的にインストールされる. インストールの詳細はこちら Installation > CrySPY

2025/06/17 以下の環境で動作確認済み(pip install csp-cryspyでインストールされるもの)

  • python 3.13.5
  • CrySPY 1.4.0
  • numpy 1.26.4 (with physbo) and 2.3.0(without physbo. physbo requires numpy < 2.0)
  • pandas 2.3.0
  • pymatgen 2025.6.14
  • pyxtal 1.0.9
  • scipy 1.15.3

Quick install

pip install csp-cryspy

BOを使う場合は追加で

pip install dscribe physbo

CrySPY 1.1.0 or 1.2.5

  • Python >= 3.8
    • PyXtal (>= 0.5.3)
    • (optional) mpi4py
    • (optional, required if algo is BO) COMBO

If you install cryspy with pip, necessary libraries such as PyXtal will be installed automatically. Go to Installation > CrySPY. Manual installation of COMBO is required when using Bayesian optimization.

CrySPY 1.0.0

  • Python >= 3.8
    • PyXtal (>= 0.5.3)
    • (optional, required if algo is BO) COMBO
情報

[2023 April 22] PyXtal (pyshtools)をarm64のMacOSにインストールする方法がわかった.Arm64 on MacOS (without Rosseta 2)を参照.
[2023 March 15] MacOSのarm64環境でのpyxtalのインストールが難しいので,Rosetta 2を使用してx86_64環境での利用が推奨.

CrySPY 0.10.0 – 0.10.3

Tested with Homebrew Python 3.8.x and 3.9.x on Mac and Python 3.8.x on Linux.

CrySPY 0.9.2

Tested with Homebrew Python 3.8.x and 3.9.x on Mac and Python 3.8.x on Linux.

情報

[2021 July 15] PyXtal 0.2.9以上を使う場合は,CrySPYを0.10.0以上にアップデートすること.

情報

[2021 March 18] pymatgen 2022.x.x.でbreaking changeがあって,importの書き方等が変わった. CrySPY 0.9.2とPyXtal 0.2.2はpymatgen 2022をサポート.

情報

[2021 Feb. 5] PyXtalを使うにはnumbaが必要だが,numbaは現在のところPython 3.9に対応していないのでしばらくはPython 3.9ではなくPython 3.8を利用する.
[2021 March 18] numbaがPython 3.9.xをサポート.CrySPYもPython 3.9で動作可能

情報

[2021 Feb. 7] PyXtalではSciPyが使われているが, 最新のSciPy(v1.6.0)ではdeepcopyを使うとバグが出る. SciPyはv1.5.4を利用する.
[2021 March 18] 上記バグはSciPy 1.6.1で修正された.

CrySPY 0.9.0 – 0.9.1

CrySPY 0.8.0 or earlier

CrySPY本体に同梱されている古いドキュメントを見ること.

構造最適化ソフト

構造最適化ソフト

少なくとも1つは必要.

find_wy (オプション)

CrySPYではこれまで,任意の空間群(対称性)持つ構造を生成するためにfind_wyを利用してきた.しかし,CrySPY 0.9.0からはデフォルトではPyXtalライブラリを採用している. CrySPY 0.9.0 以上で構造生成にPyXtalを使う場合は,find_wyのインストールはスキップできる. 従来通りfind_wyを利用することももちろん可能である. CrySPY 0.8.0 以前のものでは,空間群を考慮した構造生成にはfind_wyのインストールが必要となる.

情報

CrySPY 0.9.0 以上ではfind_wyのインストールはスキップできる.

find_wyのインストール

m_tspace

find_wyをコンパイルするためには,まずはm_tspaceをコンパイルして,ライブラリを生成する必要がある.詳細は以下のm_tspaceのサイトを参照すること.

m_tspace のソースをgitでダウンロードしてくる.ダウンロード先は例えば

$ mkdir -p ~/local
$ cd ~/local
$ git clone https://github.com/nim-hrkn/m_tspace.git

m_tspace のコンパイルにはさらに二つのファイルが必要となる.

TSPASE から下記ファイルを~/local/m_tspaceにダウンロードする:

$ cd m_tspace
$ wget http://phoenix.mp.es.osaka-u.ac.jp/~tspace/tspace_main/tsp07/tsp98.f
$ wget http://phoenix.mp.es.osaka-u.ac.jp/~tspace/tspace_main/tsp07/prmtsp.f

makefileをコンパイラに合わせて編集して,makeする. コンパイラにifortを使う場合は,-check allオプションを消さないとうまく動かない.また-O2オプションを設定する.

$ emacs makefile
$ head -n 4 makefile
#FC=gfortran
#FFLAGS=-g -cpp -DUSE_GEN -ffixed-line-length-255
FC=ifort
FFLAGS=-O2 -g -traceback -cpp -DUSE_GEN -132
$ make

gfortranを使う場合は,以下のようなエラーに遭遇するかもしれない.

tsp98.f:9839:32:

       CALL SUBGRP(MG,JG,MGT,JGT,NTAB,IND)
                                1
Error: Actual argument contains too few elements for dummy argument 'ntab' (12/48) at (1)
make: *** [tsp98.o] Error 1

その時はtsp98.fを以下のように書き換える(9925行目):

Before:

9913: C SUBROUTINE SUBGRP ====*====3====*====4====*====5====*====6====*====7
9914: C
9915: C    IF (JG(I),I=1,MG) IS A SUBGROUP OF (JGT(J),J=1,MGT) THEN
9916: C          TABLE (NTAB(I),I=1,MG) IS MADE HERE AND IND=0
9917: C    ELSE
9918: C          IND=-1
9919: C
9920: C                 1993/12/25
9921: C                   BY  S.TANAKA AND A. YANASE
9922: C---*----1----*----2----*----3----*----4----*----5----*----6----*----7
9923: C
9924:       SUBROUTINE SUBGRP(MG,JG,MGT,JGT,NTAB,IND)
9925:       DIMENSION NTAB(48),JG(48),JGT(48)

After:

9913: C SUBROUTINE SUBGRP ====*====3====*====4====*====5====*====6====*====7
9914: C
9915: C    IF (JG(I),I=1,MG) IS A SUBGROUP OF (JGT(J),J=1,MGT) THEN
9916: C          TABLE (NTAB(I),I=1,MG) IS MADE HERE AND IND=0
9917: C    ELSE
9918: C          IND=-1
9919: C
9920: C                 1993/12/25
9921: C                   BY  S.TANAKA AND A. YANASE
9922: C---*----1----*----2----*----3----*----4----*----5----*----6----*----7
9923: C
9924:       SUBROUTINE SUBGRP(MG,JG,MGT,JGT,NTAB,IND)
9925:       DIMENSION NTAB(12),JG(48),JGT(48)

コンパイルに成功すればm_tsp.aというライブラリができる.

find_wy

詳細はfind_wyのサイトをチェックすること:

find_wyのソースをgitでクローンしてくる.例えば:

$ mkdir -p ~/local
$ cd ~/local
$ git clone https://github.com/nim-hrkn/find_wy.git

make.incを編集して,先ほど用意したm_tsp.aのパスを設定する.

$ cd find_wy
$ emacs make.inc
$ head -n 4 make.inc
TSPPATH=~/local/m_tspace
#INCPATH = -I $(TSPPATH)
TSP=$(TSPPATH)/m_tsp.a

ここでも-check allを削除して-O2オプションを付けた方が良い. 準備できたらmakeする.

$ make

コンパイルできてfind_wyの実行ファイルが得られたら,実行してテストする.

$ ./find_wy input_sample/input_si4o8.txt

問題なければPOS_WY_SKEL_ALL.jsonなどのファイルが生成される.

find_wyの実行ファイル

CrySPY 1.0.0 or later

PATHが通ったところにfind_wyの実行ファイルを置く.もしくは下記のようにcryspy.inで実行ファイルのpathを指定する.

[structure]
use_find_wy = True
fwpath = /xxx/xxx/xxx/find_wy

CrySPY 0.10.3 or earlier

CrySPYでfind_wyを構造生成に用いる場合は所定の位置にfind_wyの実行ファイルを置いておく必要がるので,CrySPY本体をダウンロード後にfind_wyの実行ファイルをコピーしておく.CrySPYは任意のディレクトリに設置できるので,例えば~/CrySPY_root/CrySPY-x.x.x/CrySPY/find_wy/find_wy

CrySPYのサブセクション

CrySPY 1.3.0 or later

CrySPY

pip

pip install csp-cryspy

PyPIではcryspyではなく,csp-cryspyという名前なので注意. pipでインストールすると,実行スクリプトのcryspyが自動的にPATHが通ったところにインストールされる. 下記コマンドでチェックできる.

which cryspy

編集可能モード

CrySPYのソースコードを編集したい時は,pipの編集可能モード(-e オプション)を使うのが便利.

git clone https://github.com/Tomoki-YAMASHITA/CrySPY.git
pip install -e ./CrySPY

git cloneの代わりに,release pageから圧縮ファイルをダウンロードしてもよい.

PHYSBO and DScribe (optional)

ベイズ最適化を使う場合は, PHYSBODScribeが必要.

pip install physbo dscribe
情報

cal_fingerprint program and COMBO are obsolete.

mpi4py (optional)

MPI並列化を用いたランダム構造生成を行う場合は,mpi4pyが必要.

pip install mpi4py

Jupyter and nglview (optional)

ローカルPCでの解析やインタラクティブモードにはJupyterが必要. インタラクティブモードで結晶構造を可視化する時にnglviewを使いたい場合はインストールしておく.

pip install nglview

CrySPY 1.0.0 -- 1.2.5

CrySPY

pip

CrySPY 1.0.0以降はpipを使ってインストール可能になった.

pip install csp-cryspy

pipでインストールすると,実行スクリプトのcryspyが自動的にPATHが通ったところにインストールされる. 下記コマンドでチェックできる.

which cryspy

編集可能モード

CrySPYのソースコードを編集したい時は,pipの編集可能モード(-e オプション)を使うのが便利.

git clone https://github.com/Tomoki-YAMASHITA/CrySPY.git
pip install -e ./CrySPY

git cloneの代わりに,release pageから圧縮ファイルをダウンロードしてもよい.

cal_fingerprint (optional)

cal_fingerprintプログラムは構造記述子を計算するためのもので,アルゴリズにベイズ最適化を使う場合は必須. CrySPY 1.0.0からはcal_fingerprintプログラムはCrySPY utilityに含まれている. コンパイルについてはこちらを参照:Instllation/CrySPY_utility/Compile cal_fingerprint

実行ファイルcal_fingerprintをPATHが通ったところに置く,もしくは下記のようにcryspy.inで実行ファイルのpathを指定する.

[BO]
fppath = /xxx/xxx/xxx/cal_fingerprint

Arm64 on MacOS (without Rosseta 2)

情報

PyXtalではversion 0.6.3からpyshtoolsが必須ではなくなったので,最近のバージョンのpyxtalを使う場合は以下に書いてあることは無視して良い

  1. miniforge3をインストール(homebrew pythonでpyshtoolsをインストールする方法が今のところ不明)
  2. condaでpymatgen,pyshtoolsをインストール(最近のバージョンのpyshtoolsはconda-forgeからインストール可能になった)
conda install pymatgen
conda install pyshtools
  1. CrySPYをインストール
pip3 install csp-cryspy

CrySPY 0.10.3 or earlier

CrySPYのインストールはシンプルで,ダウンロードするだけで良い.

ダウンロード

CrySPYは任意の場所に置いて良い.ここでは例として~/CrySPY_root/CrySPY-x.x.x (x.x.x はバージョン番号)にダウンロードすることにする. gitコマンドを使うか,リリースページから圧縮ファイルをダウンロードする.

Git

mkdir ~/CrySPY_root
cd ~/CrySPY_root
git clone https://github.com/Tomoki-YAMASHITA/CrySPY.git CrySPY-x.x.x

zip or tar.gz file

zip または tar.gz ファイルをここからダウンロードする. GitHub release .
ダウンロードして展開したソースを~/CrySPY_root/CrySPY-x.x.xに置く.

ディレクトリ構成

~/CrySPY_root/CrySPY-x.x.x/のディレクトリ構成:

CrySPY-x.x.x
├── CHANGELOG.md
├── CrySPY/
│   ├── BO/
│   ├── EA/
│   ├── IO/
│   ├── LAQA/
│   ├── RS/
│   ├── __init__.py
│   ├── calc_dscrpt/
│   ├── f-fingerprint/
│   ├── find_wy/
│   ├── gen_struc/
│   ├── interface/
│   ├── job/
│   └── start/
│   └── utility.py
├── LICENSE
├── README.md
├── cryspy.py
├── docs/
├── example/
└── utility/
情報

cryspy.pyがメインスクリプト.

セットアップ (オプション)

find_wy (オプション)

find_wyを使う時は,find_wyの実行ファイルを(例えば)~/CrySPY_root/CrySPY-x.x.x/CrySPY/find_wy/以下に置く必要がある. つまり~/CrySPY_root/CrySPY-x.x.x/CrySPY/find_wy/find_wy.

cd ~/CrySPY_root/CrySPY-x.x.x/CrySPY/find_wy
cp ~/local/find_wy/find_wy .

cal_fingerprintのコンパイル (オプション)

ベイズ最適化を使う場合は,構造の記述子を計算するためのプログラムであるcal_fingerpirntをコンパイルする必要がある.

cd ~/CrySPY_root/x.x.x/CrySPY/f-fingerprint
emacs Makefile
make

cal_fingerprintの実行ファイルが例えば~/CrySPY_root/x.x.x/CrySPY/f-fingerprint/以下にあるようにする. コンパイルすれば自動的にそうなるはず.

CrySPYユーティリティ (オプション)

ローカルPCにPython環境を構築しておくと,計算結果の解析および可視化を行うのに便利である. jupyter notebookやPythonスクリプトなどのユーティリティツールが利用できる. 入力ファイルのexamplesもCrySPYユーティリティに含まれている.

情報

ユーティリティツールを使うには以下のライブラリ等が必要になる.

ユーティリティツールのダウンロード

Git

$ git clone https://github.com/Tomoki-YAMASHITA/CrySPY_utility.git

zip

CrySPY utilityへ飛んで,緑のCodeと書かれたボタンをクリック,Download ZIPを選んでダウンロード.

チュートリアルのサブセクション

ランダムサーチ (RS)

情報

ASE は初心者にとって始めやすいツールである. CrySPYのインストール時に,ASEも自動的にインストールされるためである. 高い精度はないが,非常に軽量で高速な原子間ポテンシャルを備えており,ノートPCなどの低スペックな環境でも動作確認に適している.

入力ファイルの準備

下記のどれか一つに従い,その後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

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

ASE on your local PC

2026年6月16日 更新

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 = 5
jobcmd = zsh
jobfile = job_cryspy

[structure]
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 FixSymmetry
from ase.filters import FrechetCellFilter
from ase.calculators.emt import EMT
from ase.optimize import BFGS
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)])
cell_filter = FrechetCellFilter(atoms, hydrostatic_strain=False)
opt = BFGS(cell_filter)
opt.run(fmax=0.01, steps=2000)

# ---------- 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 = cell_filter.atoms.get_total_energy()
with open('log.tote', mode='w') as f:
    f.write(str(e))

# ------ write structure
opt_atoms = cell_filter.atoms.copy()
opt_atoms.set_constraint(None)    # remove constraint for pymatgen
write('CONTCAR', opt_atoms, format='vasp', direct=True)

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

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

CrySPY実行

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

soiap on your local PC

2025年3月6日 更新

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]
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

2025年3月6日 更新

このチュートリアルでは,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]
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

2025年3月6日 更新

このチュートリアルでは,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]
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.

Check cryspy.in

2025年6月16日 更新

詳細は 入力ファイルのページも見ること.

cryspy.inをもう一度チェックしてみよう.ここでの例は選んだcalc_codeに応じて,準備したものと少し異なるかもしれない.

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

[structure]
atype = Cu
nat = 8

[ASE]
ase_python = ase_in.py

[option]

[basic] section

  • algo: アルゴリズム.ランダムサーチの場合はRSを使う.
  • calc_code: 構造最適化のコード. VASP, QE, OMX, soiap, LAMMPS, ASEから選択.
  • tot_struc: 構造数.この場合初回実行で5構造ランダムに生成される.
  • nstage: ステージ数
  • njob: 同時にサブミットするジョブの数.この例では2つのスロットを設定,言い換えると,2構造ずつ最適化を行う.
  • jobcmd: ジョブを実行または投入するコマンド. bash, zsh, qsubなど
  • jobfile: ジョブファイルのファイル名

[structure] section

  • atype: Atom type. Na8Cl8の例: atype = Na Cl.
  • nat: atypeに応じた原子数. 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

2025 March 6, updated

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:

[2025-03-06 18:52:21,495][cryspy_init][INFO] 


Start CrySPY 1.4.0


[2025-03-06 18:52:21,495][cryspy_init][INFO] # ---------- Library version info
[2025-03-06 18:52:21,495][cryspy_init][INFO] pandas version: 2.2.2
[2025-03-06 18:52:21,495][cryspy_init][INFO] pymatgen version: 2025.1.24
[2025-03-06 18:52:21,495][cryspy_init][INFO] pyxtal version: 1.0.6
[2025-03-06 18:52:21,495][cryspy_init][INFO] # ---------- Read input file, cryspy.in
[2025-03-06 18:52:21,496][write_input][INFO] [basic]
[2025-03-06 18:52:21,496][write_input][INFO] algo = RS
[2025-03-06 18:52:21,496][write_input][INFO] calc_code = ASE
[2025-03-06 18:52:21,496][write_input][INFO] tot_struc = 5
[2025-03-06 18:52:21,496][write_input][INFO] nstage = 1
[2025-03-06 18:52:21,496][write_input][INFO] njob = 2
[2025-03-06 18:52:21,496][write_input][INFO] jobcmd = zsh
[2025-03-06 18:52:21,496][write_input][INFO] jobfile = job_cryspy
...
(omitted)
...
[2025-03-06 18:52:21,497][rs_gen][INFO] # ---------- Initial structure generation
[2025-03-06 18:52:21,497][rs_gen][INFO] # ------ mindist
[2025-03-06 18:52:21,498][struc_util][INFO] Cu - Cu: 1.32
[2025-03-06 18:52:21,498][rs_gen][INFO] # ------ generate structures
[2025-03-06 18:52:21,519][gen_pyxtal][INFO] Structure ID      0: (8,) Space group:  31 -->  31 Pmn2_1
[2025-03-06 18:52:21,525][gen_pyxtal][INFO] Structure ID      1: (8,) Space group: 198 --> 198 P2_13
[2025-03-06 18:52:21,554][gen_pyxtal][INFO] Structure ID      2: (8,) Space group:   4 -->   4 P2_1
[2025-03-06 18:52:21,580][gen_pyxtal][INFO] Structure ID      3: (8,) Space group: 193 --> 191 P6/mmm
[2025-03-06 18:52:21,581][gen_pyxtal][WARNING] Compoisition [8] not compatible with symmetry 172:     spg = 172 retry.
[2025-03-06 18:52:21,625][gen_pyxtal][INFO] Structure ID      4: (8,) Space group:  64 -->  64 Cmce
[2025-03-06 18:52:22,013][cryspy_init][INFO] Elapsed time for structure generation: 0:00:00.516183

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.

[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]
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

解析と可視化

データのダウンロード

ここでは,CrySPYのデータをローカルPCで解析・可視化することを前提としている. CrySPYをスーパーコンピュータやワークステーションで使用している場合は,データをローカルPCにダウンロードすること. workbackup ディレクトリは,ファイルサイズが非常に大きくなる可能性があるため,不要であれば削除してよい.

Jupyter notebook

先ほどダウンロードした結果の中にある data/ ディレクトリに移動する. その後,CrySPY utilityがローカルにダウンロード してある場合は cryspy_analyzer_RS.ipynb をコピーする. またはGitHubから直接ダウンロードしてくる(CrySPY_utility/notebook/). Jupyter を起動し(VScode,Jupyter Lab,Jupyter Notebook など), セルを順番に実行するだけで,以下のような図を得ることができる.

Cu8_RS Cu8_RS

進化的アルゴリズム(EA)

情報

入力ファイルの準備

下記のどれか一つに従い,その後CrySPY実行のセクションに移ること.

CrySPY実行

進化的アルゴリズム(EA)のサブセクション

ASE on your local PC

2025年4月5日

ここで利用しているファイルはCrySPY_utility/examples/ase_Cu8Au8_EAからダウンロードできる. このチュートリアルでは,計算が軽いASEのPure Python EMT calculatorを用いてローカルPCで動作確認を行う.対象となるシステムはCu8Au8.

cryspy.in

cryspy.inの例.

[basic]
algo = EA
calc_code = ASE
nstage = 1
njob = 5
jobcmd = zsh
jobfile = job_cryspy

[structure]
atype = Cu Au
nat = 8 8

[EA]
n_pop = 10
n_crsov = 5
n_perm = 2
n_strain = 2
n_rand = 1
n_elite = 1
n_fittest = 5
slct_func = TNM
t_size = 2
maxgen_ea = 0

[ASE]
ase_python = ase_in.py

[option]

calc_in/

calc_in/以下はチュートリアル > ランダムサーチ(RS) > ASE in your local PCと同様

calc_in/ase_in.py_1

from ase.constraints import FixSymmetry
from ase.filters import FrechetCellFilter
from ase.calculators.emt import EMT
from ase.optimize import BFGS
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)])
cell_filter = FrechetCellFilter(atoms, hydrostatic_strain=False)
opt = BFGS(cell_filter)
opt.run(fmax=0.01, steps=2000)

# ---------- 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 = cell_filter.atoms.get_total_energy()
with open('log.tote', mode='w') as f:
    f.write(str(e))

# ------ write structure
opt_atoms = cell_filter.atoms.copy()
opt_atoms.set_constraint(None)    # remove constraint for pymatgen
write('CONTCAR', opt_atoms, format='vasp', direct=True)

calc_in/job_cryspy

#!/bin/sh

# ---------- ASE
python3 ase_in.py > out.log

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

次世代の生成

2025年4月6日

初回実行

cryspyを実行すると,構造生成モードになり,第一世代のランダム構造が生成されて,一旦プログラムは終了する.

cryspy

出力

...
[2025-04-06 09:15:34,720][ea_init][INFO] # ---------- Initialize evolutionary algorithm
[2025-04-06 09:15:34,720][ea_init][INFO] # ------ Generation 1
[2025-04-06 09:15:34,720][ea_init][INFO] 10 structures by random

cryspy.statを見ると,EAでは現在の世代の情報が追加されている.

[status]
generation = 1
id_queueing = 0 1 2 3 4 5 6 7 8 9

構造最適化

何度かcryspyを実行して,第一世代の構造最適化を終わらせると,下記のように出力される.

...
[2025-04-06 09:20:26,218][ctrl_job][INFO] Done generation 1
[2025-04-06 09:20:26,218][ctrl_job][INFO] 
EA is ready

次世代生成

準備ができた状態でもう一度cryspyを実行すると,バックアップが実行されてから,次世代構造の生成が始まる.

cryspy
...
[2025-04-06 09:35:11,546][cryspy_restart][INFO] read input, cryspy.in
[2025-04-06 09:35:11,554][ctrl_job][INFO] # ---------- job status
[2025-04-06 09:35:11,554][ctrl_job][INFO] Done generation 1
[2025-04-06 09:35:11,554][utility][INFO] Backup data
[2025-04-06 09:35:11,611][ea_next_gen][INFO] # ---------- Evolutionary algorithm
[2025-04-06 09:35:11,611][ea_next_gen][INFO] Generation 2
[2025-04-06 09:35:11,613][ea_next_gen][INFO] # ------ natural selection
[2025-04-06 09:35:11,687][ea_next_gen][INFO] ranking without duplication (including elite):
[2025-04-06 09:35:11,687][ea_next_gen][INFO] Structure ID      1, fitness:   -0.00530
[2025-04-06 09:35:11,687][ea_next_gen][INFO] Structure ID      3, fitness:    0.01490
[2025-04-06 09:35:11,687][ea_next_gen][INFO] Structure ID      4, fitness:    0.04485
[2025-04-06 09:35:11,687][ea_next_gen][INFO] Structure ID      7, fitness:    0.11501
[2025-04-06 09:35:11,687][ea_next_gen][INFO] Structure ID      8, fitness:    0.15254
[2025-04-06 09:35:11,687][ea_next_gen][INFO] # ------ Generate children
[2025-04-06 09:35:11,687][ea_child][INFO] # -- mindist
[2025-04-06 09:35:11,689][struc_util][INFO] Cu - Cu: 1.32
[2025-04-06 09:35:11,689][struc_util][INFO] Cu - Au: 1.34
[2025-04-06 09:35:11,689][struc_util][INFO] Au - Au: 1.36
[2025-04-06 09:35:11,740][crossover][INFO] Structure ID     10 (8, 8) was generated from      3 and      1 by crossover. Space group:   1 P1
[2025-04-06 09:35:11,764][crossover][WARNING] remove_within_mindist: some atoms within mindist. retry.
[2025-04-06 09:35:11,774][crossover][INFO] Structure ID     11 (8, 8) was generated from      3 and      1 by crossover. Space group:   1 P1
[2025-04-06 09:35:11,789][crossover][INFO] Structure ID     12 (8, 8) was generated from      1 and      4 by crossover. Space group:   1 P1
[2025-04-06 09:35:11,833][crossover][INFO] Structure ID     13 (8, 8) was generated from      1 and      3 by crossover. Space group:   1 P1
[2025-04-06 09:35:11,852][crossover][WARNING] mindist in _add_border_line: Cu - Cu, 0.567032320824818. retry.
[2025-04-06 09:35:11,861][crossover][INFO] Structure ID     14 (8, 8) was generated from      7 and      1 by crossover. Space group:   1 P1
[2025-04-06 09:35:11,875][permutation][INFO] Structure ID     15 (8, 8) was generated from      1 by permutation. Space group: 146 R3
[2025-04-06 09:35:11,888][permutation][INFO] Structure ID     16 (8, 8) was generated from      3 by permutation. Space group:   1 P1
[2025-04-06 09:35:11,890][strain][WARNING] mindist in strain: Cu - Cu, 1.3050485787603692. retry.
[2025-04-06 09:35:11,903][strain][INFO] Structure ID     17 (8, 8) was generated from      3 by strain. Space group:   1 P1
[2025-04-06 09:35:11,917][strain][INFO] Structure ID     18 (8, 8) was generated from      1 by strain. Space group:   1 P1
[2025-04-06 09:35:12,513][ea_child][INFO] # ------ Random structure generation
[2025-04-06 09:35:12,513][rs_gen][INFO] # ------ mindist
[2025-04-06 09:35:12,515][struc_util][INFO] Cu - Cu: 1.32
[2025-04-06 09:35:12,515][struc_util][INFO] Cu - Au: 1.34
[2025-04-06 09:35:12,515][struc_util][INFO] Au - Au: 1.36
[2025-04-06 09:35:12,516][rs_gen][INFO] # ------ generate structures
[2025-04-06 09:35:12,530][gen_pyxtal][INFO] Structure ID     19: (8, 8) Space group:  86 -->  86 P4_2/n
[2025-04-06 09:35:12,533][ea_next_gen][INFO] # ------ Select elites
[2025-04-06 09:35:12,533][ea_next_gen][INFO] Structure ID      9 keeps as the elite

あとはcryspyの実行を繰り返せば,探索が進む.

結果の確認

cryspy_rslt

以下は第3世代まで計算を終えたcryspy_rsltの例である.EAでは世代の情報(Gen)も追加される.

    Gen  Spg_num Spg_sym  Spg_num_opt Spg_sym_opt  E_eV_atom  Magmom      Opt
0     1      214  I4_132          230       Ia-3d   1.168743     NaN  no_file
1     1      198   P2_13          198       P2_13  -0.005303     NaN  no_file
2     1       95  P4_322           95      P4_322   0.389566     NaN  no_file
3     1       27    Pcc2           27        Pcc2   0.014898     NaN  no_file
4     1       60    Pbcn           60        Pbcn   0.044852     NaN  no_file
5     1      116   P-4c2          116       P-4c2   0.403246     NaN  no_file
6     1      187   P-6m2          187       P-6m2   1.054706     NaN  no_file
7     1      161     R3c          160         R3m   0.115009     NaN  no_file
8     1      146      R3          146          R3   0.152535     NaN  no_file
9     1       60    Pbcn           47        Pmmm  -0.005676     NaN  no_file
10    2        1      P1            1          P1   0.026070     NaN  no_file
11    2        1      P1            7          Pc   0.005898     NaN  no_file
12    2        1      P1            1          P1   0.005208     NaN  no_file
13    2        1      P1            1          P1   0.005506     NaN  no_file
14    2        1      P1            1          P1   0.024364     NaN  no_file
15    2      146      R3          146          R3   0.011525     NaN  no_file
16    2        1      P1            1          P1   0.014590     NaN  no_file
17    2        1      P1            1          P1   0.015236     NaN  no_file
18    2        1      P1            2         P-1  -0.012335     NaN  no_file
19    2       86  P4_2/n          140      I4/mcm   0.274548     NaN  no_file
20    3        1      P1            1          P1   0.013611     NaN  no_file
21    3        1      P1           10        P2/m  -0.014166     NaN  no_file
22    3        1      P1            1          P1   0.019472     NaN  no_file
23    3        1      P1            1          P1   0.011641     NaN  no_file
24    3        1      P1            1          P1   0.000297     NaN  no_file
25    3        1      P1            1          P1   0.005596     NaN  no_file
26    3        1      P1            1          P1   0.013374     NaN  no_file
27    3        1      P1            2         P-1   0.005055     NaN  no_file
28    3        2     P-1           12        C2/m  -0.012396     NaN  no_file
29    3      182  P6_322          182      P6_322   0.711472     NaN  no_file

ea_info

各世代ごとに用いたEAのパラメーターがea_infoに出力される.

Gen Population Crossover Permutation Strain Random Elite crs_lat slct_func
  1         10         0           0      0     10     0  random       TNM
  2         10         5           2      2      1     1  random       TNM
  3         10         5           2      2      1     1  random       TNM

ea_origin

構造生成手法や親個体の情報が,ea_originに出力される.

Gen Struc_ID   Operation   Parent
  1        0      random     None
  1        1      random     None
  1        2      random     None
  1        3      random     None
  1        4      random     None
  1        5      random     None
  1        6      random     None
  1        7      random     None
  1        8      random     None
  1        9      random     None
  2       10   crossover   (3, 1)
  2       11   crossover   (3, 1)
  2       12   crossover   (1, 4)
  2       13   crossover   (1, 3)
  2       14   crossover   (7, 1)
  2       15 permutation     (1,)
  2       16 permutation     (3,)
  2       17      strain     (3,)
  2       18      strain     (1,)
  2       19      random     None
  2        9       elite    elite
  3       20   crossover (18, 12)
  3       21   crossover  (12, 9)
  3       22   crossover (12, 18)
  3       23   crossover  (18, 9)
  3       24   crossover (13, 18)
  3       25 permutation    (18,)
  3       26 permutation     (9,)
  3       27      strain    (18,)
  3       28      strain    (18,)
  3       29      random     None
  3       18       elite    elite

解析と可視化

データのダウンロード

ここでは,CrySPYのデータをローカルPCで解析・可視化することを前提としている. CrySPYをスーパーコンピュータやワークステーションで使用している場合は,データをローカルPCにダウンロードすること. workbackup ディレクトリは,ファイルサイズが非常に大きくなる可能性があるため,不要であれば削除してよい.

Jupyter notebook

先ほどダウンロードした結果の中にある data/ ディレクトリに移動する. その後,CrySPY utilityがローカルにダウンロード してある場合は cryspy_analyzer_EA.ipynb をコピーする. またはGitHubから直接ダウンロードしてくる(CrySPY_utility/notebook/). Jupyter を起動し(VScode,Jupyter Lab,Jupyter Notebook など), セルを順番に実行するだけで,以下のような図を得ることができる.

Cu8Au8_EA Cu8Au8_EA

組成可変型進化的アルゴリズム(EA-vc)

情報
情報

動作環境

入力ファイルの準備

下記のどれか一つに従い,その後CrySPY実行のセクションに移ること.

CrySPY実行

組成可変型進化的アルゴリズム(EA-vc)のサブセクション

ASE on your local PC (Cu-Ag-Au)

2025年6月16日

ここで利用しているファイルはCrySPY_utility/examples/ase_Cu-Ag-Au_EA-vcからダウンロードできる. このチュートリアルでは,計算が軽いASEのPure Python EMT calculatorを用いてローカルPCで動作確認を行う.対象となるシステムは3元系のCu-Ag-Au.

cryspy.in

cryspy.inの例.

[basic]
algo = EA-vc
calc_code = ASE
nstage = 1
njob = 5
jobcmd = zsh
jobfile = job_cryspy

[structure]
atype = Cu Ag Au
ll_nat = 0 0 0
ul_nat = 8 8 8

[ASE]
ase_python = ase_in.py

[EA]
n_pop = 20
n_crsov = 5
n_perm = 2
n_strain = 2
n_rand = 2
n_add = 3
n_elim = 3
n_subs = 3
target = random
n_elite = 2
n_fittest = 10
slct_func = TNM
t_size = 2
end_point = 0.0 0.0 0.0
maxgen_ea = 0

[option]

calc_in/

calc_in/以下はチュートリアル > ランダムサーチ(RS) > ASE in your local PCと同様

calc_in/ase_in.py_1

from ase.constraints import FixSymmetry
from ase.filters import FrechetCellFilter
from ase.calculators.emt import EMT
from ase.optimize import BFGS
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)])
cell_filter = FrechetCellFilter(atoms, hydrostatic_strain=False)
opt = BFGS(cell_filter)
opt.run(fmax=0.01, steps=2000)

# ---------- 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 = cell_filter.atoms.get_total_energy()
with open('log.tote', mode='w') as f:
    f.write(str(e))

# ------ write structure
opt_atoms = cell_filter.atoms.copy()
opt_atoms.set_constraint(None)    # remove constraint for pymatgen
write('CONTCAR', opt_atoms, format='vasp', direct=True)

calc_in/job_cryspy

#!/bin/sh

# ---------- ASE
python3 ase_in.py > out.log

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

ASE-CHGNet(Cu-Au)

2025年6月16日

情報

CHGNetのインストールが必要

ここで利用しているファイルはCrySPY_utility/examples/ase_chgnet_Cu-Au_EA-vcからダウンロードできる. このチュートリアルでは,機械学習ポテンシャルのCHGNetを用いてジョブスケジューラーを備えた計算機クラスタで行うことを想定している. 手持ちのPCでも十分動作するので,そうしたい場合は入力を適宜変更すること. 対象となるシステムは2元系のCu-Au.

事前計算

EA-vcではcryspy.inend_pointとして,各元素単体の1原子当たりのエネルギーを基準として用いるため,事前に計算する必要がある. exampleファイルの中に二つのディレクトリがあるはず.

Au-fcc
├── POSCAR
├── chgnet_in.py
└── job_cryspy
Cu-fcc
├── POSCAR
├── chgnet_in.py
└── job_cryspy

結晶構造データ(POSCAR)とその構造最適化を行いエネルギーを求めるpythonスクリプト(chgnet_in.py)およびジョブスクリプト(job_cryspy)があるので適宜使用する計算機の環境に合わせて編集すること.

ジョブを実行する(ジョブサブミットのコマンドは適宜読み替えること).

cd Au-fcc
qsub job_cryspy
cd ../Cu-fcc
qsub job_cryspy
cd ..

計算が無事に終わったら,それぞれのディレクトリにend_pointというファイルができており,ここに構造最適化後の1原子あたりのエネルギー(eV/atom)が出力されている.

cat Au-fcc/end_point
-3.2357187271118164
cat Cu_fcc/end_point
-4.083529472351074

これらをcryspy.inでの入力に用いる.

cryspy.in

cryspy.inの例.

[basic]
algo = EA-vc
calc_code = ASE
nstage = 1
njob = 20
jobcmd = qsub
jobfile = job_cryspy

[structure]
atype = Cu Au
ll_nat = 0 0
ul_nat = 8 8

[ASE]
ase_python = chgnet_in.py

[EA]
n_pop = 20
n_crsov = 5
n_perm = 2
n_strain = 2
n_rand = 2
n_add = 3
n_elim = 3
n_subs = 3
target = random
n_elite = 2
n_fittest = 10
slct_func = TNM
t_size = 2
maxgen_ea = 0
end_point = -4.08352709  -3.23571777

[option]

calc_in/

calc_in/以下はチュートリアル > ランダムサーチ(RS) > ASE in your local PCと同様であるが,少しだけCHGNet用に変更している. ジョブスクリプトのpython本体のpathも計算機環境に合わせること.

calc_in/chgnet_in.py_1

# ---------- import
from ase.constraints import FixSymmetry
from ase.filters import FrechetCellFilter
from ase.io import read, write
from ase.optimize import FIRE, BFGS, LBFGS
from chgnet.model import CHGNetCalculator

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

# ---------- set up
atoms.calc = CHGNetCalculator()
atoms.set_constraint([FixSymmetry(atoms)])
cell_filter = FrechetCellFilter(atoms)
opt = BFGS(cell_filter, trajectory='opt.traj')

# ---------- run
opt.run(fmax=0.01, steps=2000)

# ---------- write structure
write('opt_struc.vasp', cell_filter.atoms, format='vasp', direct=True)

# ---------- 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
# ------ energy
e = cell_filter.atoms.get_total_energy()    # eV/cell
with open('log.tote', mode='w') as f:
    f.write(str(e))

# ------ struc
opt_atoms = cell_filter.atoms.copy()
opt_atoms.set_constraint(None)    # remove constraint for pymatgen
write('CONTCAR', opt_atoms, format='vasp', direct=True)

calc_in/job_cryspy

#!/bin/sh
#$ -cwd
#$ -V -S /bin/bash
####$ -V -S /bin/zsh
#$ -N CuAu_CrySPY_ID
#$ -pe smp 2

# ---------- OpenMP
export OMP_NUM_THREADS=2

# ---------- ASE
/usr/local/Python-3.10.13/bin/python3 chgnet_in.py > out.log

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

次世代の生成

2025年6月16日

初回実行

cryspyを実行すると,構造生成モードになり,第一世代のランダム構造が生成されて,一旦プログラムは終了する.

cryspy

出力をみると,ll_natul_natの範囲の原子数で構造が生成されているのが確認できる.

...
[2025-06-16 10:04:45,648][cryspy_init][INFO] # ---------- Initial structure generation
[2025-06-16 10:04:45,648][rs_gen][INFO] # ------ mindist
[2025-06-16 10:04:45,650][struc_util][INFO] Cu - Cu: 1.32
[2025-06-16 10:04:45,650][struc_util][INFO] Cu - Ag: 1.385
[2025-06-16 10:04:45,650][struc_util][INFO] Cu - Au: 1.34
[2025-06-16 10:04:45,650][struc_util][INFO] Ag - Ag: 1.45
[2025-06-16 10:04:45,650][struc_util][INFO] Ag - Au: 1.405
[2025-06-16 10:04:45,650][struc_util][INFO] Au - Au: 1.36
[2025-06-16 10:04:45,650][rs_gen][INFO] # ------ generate structures
[2025-06-16 10:04:45,659][gen_pyxtal][WARNING] Compoisition [1 4] not compatible with symmetry 34:     spg = 34 retry.
[2025-06-16 10:04:45,662][gen_pyxtal][WARNING] Compoisition [ 2  2 12] not compatible with symmetry 39:     spg = 39 retry.
[2025-06-16 10:04:45,691][gen_pyxtal][INFO] Structure ID      0: (3, 1, 2) Space group:  82 --> 119 I-4m2
[2025-06-16 10:04:45,694][gen_pyxtal][WARNING] Compoisition [6 6 2] not compatible with symmetry 57:     spg = 57 retry.
[2025-06-16 10:04:45,749][gen_pyxtal][INFO] Structure ID      1: (1, 8, 5) Space group:  71 -->  71 Immm
[2025-06-16 10:04:45,857][gen_pyxtal][INFO] Structure ID      2: (3, 7, 8) Space group: 174 --> 174 P-6
...

cryspy.statを見ると,EAでは現在の世代の情報が追加されている.

[status]
generation = 1
id_queueing = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

構造最適化

何度かcryspyを実行して,第一世代の構造最適化を終わらせると,下記のように出力される.

...
[2025-06-16 10:25:56,962][ctrl_job][INFO] Done generation 1
[2025-06-16 10:25:56,962][ctrl_job][INFO] Calculate convex hull for generation 1
[2025-06-16 10:25:57,854][ctrl_job][INFO] 
EA is ready

凸包

この時点で,./data/convex_hull/にhull distanceの情報とconvex hullのグラフが出力されている.

  • hull_dist_all_gen_1
    ID    hull distance (eV/atom)    Num_atom
     7                   0.000000    (0, 2, 6)
    14                   0.036510    (1, 7, 6)
    17                   0.064702    (0, 1, 5)
    19                   0.113649    (0, 0, 8)
    16                   0.168530    (6, 4, 8)
     9                   0.186497    (8, 4, 6)
     1                   0.187379    (1, 8, 5)
    11                   0.233893    (4, 5, 4)
     3                   0.273365    (6, 5, 5)
    10                   0.326759    (1, 4, 4)
     2                   0.330749    (3, 7, 8)
     8                   0.359543    (6, 2, 7)
     4                   0.404169    (4, 4, 2)
    18                   0.422989    (0, 6, 8)
    13                   0.428456    (0, 6, 3)
     5                   0.444792    (7, 4, 7)
     6                   0.464305    (7, 7, 7)
    12                   0.556654    (3, 0, 0)
    15                   0.560062    (6, 7, 1)
     0                   0.644278    (3, 1, 2)
  • conv_hull_gen_1.svg conv_hull_gen_1.svg conv_hull_gen_1.svg

次世代生成

準備ができた状態でもう一度cryspyを実行すると,バックアップが実行されてから,次世代構造の生成が始まる.

cryspy
...
[2025-06-16 10:37:19,860][ctrl_job][INFO] Done generation 1
[2025-06-16 10:37:20,136][utility][INFO] Backup data
[2025-06-16 10:37:20,173][ea_next_gen][INFO] # ---------- Evolutionary algorithm
[2025-06-16 10:37:20,174][ea_next_gen][INFO] Generation 2
[2025-06-16 10:37:20,174][ea_next_gen][INFO] # ------ natural selection
[2025-06-16 10:37:20,177][ea_next_gen][INFO] ranking without duplication (including elite):
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID      7, fitness:    0.00000
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID     14, fitness:    0.03651
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID     17, fitness:    0.06470
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID     19, fitness:    0.11365
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID     16, fitness:    0.16853
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID      9, fitness:    0.18650
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID      1, fitness:    0.18738
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID     11, fitness:    0.23389
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID      3, fitness:    0.27336
[2025-06-16 10:37:20,177][ea_next_gen][INFO] Structure ID     10, fitness:    0.32676
[2025-06-16 10:37:20,177][ea_next_gen][INFO] # ------ Generate children
[2025-06-16 10:37:20,177][ea_child][INFO] # -- mindist
[2025-06-16 10:37:20,179][struc_util][INFO] Cu - Cu: 1.32
[2025-06-16 10:37:20,179][struc_util][INFO] Cu - Ag: 1.385
[2025-06-16 10:37:20,179][struc_util][INFO] Cu - Au: 1.34
[2025-06-16 10:37:20,179][struc_util][INFO] Ag - Ag: 1.45
[2025-06-16 10:37:20,179][struc_util][INFO] Ag - Au: 1.405
[2025-06-16 10:37:20,179][struc_util][INFO] Au - Au: 1.36
[2025-06-16 10:37:20,217][crossover][INFO] Structure ID     20 (0, 4, 7) was generated from     19 and     14 by crossover. Space group:   1 P1
[2025-06-16 10:37:20,219][crossover][INFO] Structure ID     21 (0, 1, 7) was generated from      7 and     17 by crossover. Space group:   1 P1
[2025-06-16 10:37:20,221][crossover][INFO] Structure ID     22 (3, 0, 8) was generated from     16 and     19 by crossover. Space group:   1 P1
[2025-06-16 10:37:20,225][crossover][INFO] Structure ID     23 (0, 1, 7) was generated from      7 and     17 by crossover. Space group:   1 P1
...
[2025-06-16 10:37:20,809][ea_next_gen][INFO] # ------ Select elites
[2025-06-16 10:37:20,809][ea_next_gen][INFO] Structure ID      7 keeps as the elite
[2025-06-16 10:37:20,809][ea_next_gen][INFO] Structure ID     14 keeps as the elite

あとはcryspyの実行を繰り返せば,探索が進む.

結果の確認

ここでは,EAと異なるところを中心に述べる.

cryspy_rslt

以下は第3世代まで計算を終えたcryspy_rsltの例である.EA-vcでは,形成エネルギー(Ef_eV_atom)と原子数(Num_atom)も追加される.

    Gen  Spg_num Spg_sym  Spg_num_opt Spg_sym_opt  E_eV_atom  Ef_eV_atom   Num_atom  Magmom      Opt
0     1      119   I-4m2          119       I-4m2   0.639865    0.639865  (3, 1, 2)     NaN  no_file
1     1       71    Immm           71        Immm   0.182650    0.182650  (1, 8, 5)     NaN  no_file
2     1      174     P-6          187       P-6m2   0.324864    0.324864  (3, 7, 8)     NaN  no_file
3     1       71    Immm           71        Immm   0.269227    0.269227  (6, 5, 5)     NaN  no_file
4     1       12    C2/m           65        Cmmm   0.401521    0.401521  (4, 4, 2)     NaN  no_file
7     1      123  P4/mmm          123      P4/mmm  -0.009930   -0.009930  (0, 2, 6)     NaN  no_file
10    1      107    I4mm          107        I4mm   0.320875    0.320875  (1, 4, 4)     NaN  no_file
5     1      121   I-42m          121       I-42m   0.439643    0.439643  (7, 4, 7)     NaN  no_file
6     1      115   P-4m2          115       P-4m2   0.459892    0.459892  (7, 7, 7)     NaN  no_file
8     1       81     P-4           81         P-4   0.354247    0.354247  (6, 2, 7)     NaN  no_file
9     1       11  P2_1/m           11      P2_1/m   0.182084    0.182084  (8, 4, 6)     NaN  no_file
11    1       10    P2/m           10        P2/m   0.229819    0.229819  (4, 5, 4)     NaN  no_file

nat_data

原子数の情報はnat_dataにも出力される.

    ID    ('Cu', 'Ag', 'Au')
     0    (3, 1, 2)
     1    (1, 8, 5)
     2    (3, 7, 8)
     3    (6, 5, 5)
     4    (4, 4, 2)
     5    (7, 4, 7)
     6    (7, 7, 7)
     7    (0, 2, 6)
     8    (6, 2, 7)
     9    (8, 4, 6)
    10    (1, 4, 4)
...

hull_dist_all_gen_x

例えば第3世代終了時点のhull distanceのデータは./convex_hull/hull_dist_all_gen_3というファイルに出力される.

    ID    hull distance (eV/atom)    Num_atom
    43                   0.000000    (0, 2, 5)
    42                   0.000000    (0, 5, 5)
    48                   0.000000    (0, 1, 5)
    46                   0.000009    (0, 1, 5)
    28                   0.000011    (0, 1, 5)
    41                   0.000360    (0, 4, 6)
    47                   0.001838    (0, 1, 5)
    36                   0.001992    (1, 1, 6)
    21                   0.002544    (0, 1, 7)
    23                   0.002551    (0, 1, 7)
    24                   0.002795    (0, 4, 7)

conv_hull_gen_x.svg

例えば第3世代終了時点の凸包プロットの画像データは./convex_hull/conv_hull_gen_3.svgに出力される. デフォルトはsvg形式であるが,入力ファイルでfig_formatを変更していればpdfやpngで出力される. conv_hull_gen_3.svg conv_hull_gen_3.svg

解析と可視化

凸包の自動プロット

EA-vcでは2元系および3元系の探索シミュレーションの場合,凸包のグラフは各世代の計算終了時に自動プロットされる. 自分でもっと編集したい場合はJupyterでカスタマイズできる. 4元系の時はJupyterを用いたplotly(pymatgenに必要なのでインストールされているはず)の可視化が利用可能. ここではいくつか例を示しておく.

2元系

conv_hull_gen_3_with_desc.svg conv_hull_gen_3_with_desc.svg

上図は3世代まで探索した時の例で,赤文字は説明のために追加した. 凸包プロットに関する入力ファイルの設定は以下が関係する.括弧内はデフォルト値.

  • show_max:y軸上限(0.2)
  • label_stable:安定相の組成を表示するかどうか(True)
  • vmax:右のカラーバーの最大値(0.2)
  • bottom_margin:最小値とy軸下限の間のマージン(0.02).
  • fig_format:図のファイルフォーマット.svg, png, pdfに対応.(svg)

マーカー上の十字の印は最新世代の探索結果を示している.

3元系

conv_hull_gen_3_with_desc.svg conv_hull_gen_3_with_desc.svg

上図は3世代まで探索した時の例で,赤文字は説明のために追加した. 凸包プロットに関する入力ファイルの設定は以下が関係する.括弧内はデフォルト値.

  • show_max:hull distanceがshow_max以下のものだけをプロット(0.2)
  • label_stable:安定相の組成を表示するかどうか(True)
  • vmax:右のカラーバーの最大値(0.2)
  • bottom_margin:3元系では無関係
  • fig_format:図のファイルフォーマット.svg, png, pdfに対応.(svg)

マーカーの十字の印は最新世代の探索結果を示している.

データのダウンロード

ここでは,CrySPYのデータをローカルPCで解析・可視化することを前提としている. CrySPYをスーパーコンピュータやワークステーションで使用している場合は,データをローカルPCにダウンロードすること. workbackup ディレクトリは,ファイルサイズが非常に大きくなる可能性があるため,不要であれば削除してよい.

Jupyter notebook

先ほどダウンロードした結果の中にある data/ ディレクトリに移動する. その後,CrySPY utilityがローカルにダウンロード してある場合は cryspy_analyzer_EA-vc.ipynb をコピーする. またはGitHubから直接ダウンロードしてくる(CrySPY_utility/notebook/).

Jupyter notebookファイルには,CrySPYのコードと同じ関数が書かれており,自由に凸包のプロットをカスタマイズできる. 適宜順番に実行していき,下記のどちらかを選ぶと自動プロットと同じものが得られる

  • Binary system, matplotlib
  • Ternary system, matplotlib

途中にある

  • Interactive plot using Plotly

では,2元系,3元系および4元系において,Plotlyを用いたインタラクティブプロットができる. プロット例はCrySPY > チュートリアル > インタラクティブモード(Jupyter Notebook) #Interactive plot using Plotlyを参考にすること.

Bayesian Optimization (BO)

BO

LAQA

May 15th, 2023

情報

CrySPYの基本的な使い方に関してははじめにTutorial > Random Search (RS)を見ること.
ここではCrySPY 1.1.0以上を想定している.

ここで利用しているファイルはCrySPY_utility/examples/qe_Si16_LAQAからダウンロードできる. このチュートリアルでは,50個だけ初期構造を生成しているが,本来LAQAでは,もっと多くの構造を生成しておいてそこから良い候補を選択することでシミュレーションを進める.

Input

cryspy.in

cryspy.inの例.

[basic]
algo = LAQA
calc_code = QE
tot_struc = 50
nstage = 1
njob = 10
jobcmd = qsub
jobfile = job_cryspy

[structure]
atype = Si
nat = 16
mindist_1 = 1.5

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

[LAQA]
nselect_laqa = 4

[option]
  • LAQAではnstageは1にする必要がある.
  • [LAQA]セクションのnselect_laqaだけ新しく設定する必要がある. nselect_laqaは一回の選択で選ばれる候補の数.

下記のようにwfwsを指定すれば,LAQAのスコアにおける重みも変えられる. 省略した場合,デフォルトでは0.1と10.0がそれぞれ使われる. スコアの詳細についてはSearch algorithms > LAQAを見ること.

[LAQA]
nselect_laqa = 4
wf = 0.1
ws = 10.0

calc_in/pwscf.in_1

&control
    calculation = 'vc-relax'
    pseudo_dir = '/usr/local/gbrv/all_pbe_UPF_v1.5/'
    outdir='./outdir/'
    nstep = 10
/

&system
    ibrav = 0
    nat = 16
    ntyp = 1
    ecutwfc = 40
    ecutrho = 200
    occupations = 'smearing'
    degauss = 0.01
/

&electrons
/

&ions
/

&cell
/

ATOMIC_SPECIES
  Si -1.0 si_pbe_v1.uspp.F.UPF
  • nstepで1回の選択で何ステップ構造最適化を進めるかをコントロールする.(VASPではNSW)

calc_in/job_cryspy

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

mpirun -np $NSLOTS pw.x -nk 4 < 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
  • ジョブスクリプトはいつも使っているものと同じ

Run

ヒント

自動化スクリプトも用意してある.このページの最下部参照.

cryspyと打って1回目の実行.

cryspy &

この入力ファイルではまず50構造生成されるのでlog_cryspyを見て確認する.

2023/05/13 13:02:07
CrySPY 1.1.0
Start cryspy.py
Number of MPI processes: 1

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

# --------- Generate initial structures
# ------ mindist
Si - Si 1.5
Structure ID      0 was generated. Space group: 165 --> 165 P-3c1
Structure ID      1 was generated. Space group:  66 -->  66 Cccm
Structure ID      2 was generated. Space group: 146 --> 146 R3
Structure ID      3 was generated. Space group:  82 -->  82 I-4
Structure ID      4 was generated. Space group: 162 --> 162 P-31m
...
...
...
Structure ID     47 was generated. Space group:  90 -->  90 P42_12
Structure ID     48 was generated. Space group: 214 --> 214 I4_132
Structure ID     49 was generated. Space group:  23 -->  23 I222

Elapsed time for structure generation: 0:00:10.929030


# ---------- Initialize LAQA
# ---------- Selection 0
selected_id: 50 IDs

LAQAでは,はじめに全ての初期構造の最適化ジョブを実行する. 完全に最適化を終わらせるわけではなく,ここではnstep = 10にしているので,10ステップだけ実行される. cryspyコマンドを繰り返して,初期構造全てについて10ステップの最適化を完了させる. 必要であれば,njobの値を上げておけば一度に多くのジョブがサブミットされる.

初めの最適化が全て終わると, log_cryspyの最後にLAQA is readyと表示される.

2023/05/13 13:23:31
CrySPY 1.1.0
Restart cryspy.py
Number of MPI processes: 1



# ---------- job status
ID     41: Stage 1 Done!

LAQA is ready

この状態でcryspy を実行すると,最初の選択が始まる.

2023/05/13 13:23:33
CrySPY 1.1.0
Restart cryspy.py
Number of MPI processes: 1



# ---------- job status

Backup data

# ---------- Selection 1
selected_id: 37 8 10 48

nselect_laqaで設定された構造の数だけ選択される. cryspyをもう一度実行するとそれらのジョブ(次の10ステップ)がサブミットされる.

cryspy &
2023/05/13 13:23:36
CrySPY 1.1.0
Restart cryspy.py
Number of MPI processes: 1



# ---------- job status
ID     37: submit job, Stage 1
ID      8: submit job, Stage 1
ID     10: submit job, Stage 1
ID     48: submit job, Stage 1

あとはこれを何度も繰り返し行うことでスコアに応じて選択された構造の最適化が10ステップずつ進行する. ある程度の構造の最適化が完全に完了するまで進めて,止めたいタイミングでストップする.

Status

シミュレーションの途中でスコアの確認がしたければ次のファイルを見ると良い:

  • ./data/LAQA_status

他にもLAQAに関数ファイルがいくつか出力される:

  • ./data_LAQA_bias
  • ./data_LAQA_energy
  • ./data_LAQA_score
  • ./data_LAQA_selected_id
  • ./data_LAQA_step

Analysis and visualization

ここではCrySPYのデータをローカルPCで解析する. スパコンやワークステーションで計算を行ったら,ローカルPCにデータをダウンロードしておく. 今後必要なければ,ファイルサイズが大きいworkbackupディレクトリは削除しておいて良い. pklデータはgzipしておくとファイルサイズを減らすことができる.

jupyter notebook

ダウンロードした結果のdata/ディレクトリに移動して,cryspy_analyzer_LAQA.ipynbCrySPY utilityからコピーする.

このjupyter notebookを順番に実行していけば下記のようなグラフとgif画像が作成できる. この例では,アニメーションのために全ての構造の最適化を完全に完了させた. (全て最適化を完了させるとランダムサーチと計算量が変わらないのでLAQAの優位性はない)

fig_LAQA fig_LAQA

このグラフはエネルギーを最適化ステップの関数として示している. 赤い線は最終的にエネルギーが低かった3つの構造を表しており,中でも一番安定だった構造はダイアモンド構造に到達している. 安定になる構造はかなり早い段階で選択されて構造最適化が完了していることがわかる.

情報

algo = LAQAでは[option]セクションの下記の二つは自動的にTrueになる.

  • force_step_flag = True
  • stress_step_flag = True

原子に働く力とストレスのデータは1ステップごとに収集される. エネルギーと構造データは1ステップごとではなく,選択ごとに収集される. つまり,この場合は10ステップおきにエネルギーと構造データは保存される. もし1ステップごとのデータが欲しいのであれば,手動で下記の設定を追加すること.

[option]
energy_step_flag = True
struc_step_flag = True

Auto script

何度も繰り返しcryspyを実行するのは面倒に感じたかもしれない. 下記のようなスクリプトを使えば自動化できる.

repeat_cryspy

Molecular crystal structure prediction

情報

First, see Tutorial > Random Search (RS) for basic usage of CrySPY.

In this section, we give a tutorial on the molecular structure generation part only. Since version 0.9.0, CrySPY has been able to generate random molecular crystal structures using PyXtal.

You need to use a pre-defined molecular by PyXtal’s database (see, https://pyxtal.readthedocs.io/en/latest/Usage.html?highlight=benzene#pyxtal-molecule-pyxtal-molecule)) or create molecule files that define molecular structures.

Pre-defined molecule

PyXtal currently supports C60, H2O, CH4, NH3, benzene, naphthalene, anthracene, tetracene, pentacene, coumarin, resorcinol, benzamide, aspirin, ddt, lindane, glycine, glucose, and ROY.

Let us generate molecular crystal structures that consist of 2 benzenes.

Move to your working directory, and copy input example files by one of the following methods.

Take a look at cryspy.in.

$ cat cryspy.in
[basic]
algo = RS
calc_code = QE
tot_struc = 6
nstage = 2
njob = 2
jobcmd = qsub
jobfile = job_cryspy

[structure]
struc_mode = mol
atype = H C
nat = 12 12
mol_file = benzene
nmol = 2

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

[option]

In generating molecular crystal structures, you have to set struc_mode = mol in the [structure] section. Molecule file(s) and the number of molecule(s) are specified as:

  • mol_file = benzene
  • nmol = 2

Run CrySPY and see the initial structures (./data/init_POSCARS).

User-defined molecule

Move to your working directory, and copy input example files for 2 formula units of Li3PS4.

  • 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/QE_Li3PS4_2fu_RS_mol .
$ cd QE_Li3PS4_2fu_RS_mol
$ ls
Li.xyz  PS4.xyz  calc_in/  cryspy.in

Molecule files of Li and PS4 are included. Supported formats in PyXtal are .xyz, .gjf, .g03, .g09, .com, .inp, .out, and pymatgen’s JSON serialized molecules.

$ cat Li.xyz
1
New structure
 Li  0.000  0.000  0.000
$ cat PS4.xyz
5
New structure
 P    0.000000    0.000000    0.000000
 S    1.200000    1.200000   -1.200000
 S    1.200000   -1.200000    1.200000
 S   -1.200000    1.200000    1.200000
 S   -1.200000   -1.200000   -1.200000

Check cryspy.in.

$ cat cryspy.in
[basic]
algo = RS
calc_code = QE
tot_struc = 4
nstage = 2
njob = 1
jobcmd = qsub
jobfile = job_cryspy

[structure]
struc_mode = mol
atype = Li P S
nat = 6 2 8
mol_file = ./Li.xyz  ./PS4.xyz
nmol = 6 2

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

[option]

A single atom (Li atom in this case) is treated as a molecule in the molecular crystal structure generation mode. In this example, a random molecular structure is composed of six Li molecules (atoms) and two PS4 molecules specified as:

  • mol_file = ./Li.xyz ./PS4.xyz
  • nmol = 6 2

In mol_file, set relative path of molecule files from cryspy.in. Here the molecule files are placed in the same directory.

Run CrySPY and see the initial structures (./data/init_POSCARS).

timeout_mol

Molecular crystal structure generation can be time consuming because PyXtal calculates the molecule directions according to a specified space group. Sometimes molecular crystal structure generation gets stuck. So we set a time limit on the single structure generation. The time limit (timeout_mol) is set to 120 seconds by default. If the limit is insufficient, you have to increase it as (see last line):

struc_mode = mol
atype = Li P S
nat = 6 2 8
mol_file = ./Li.xyz  ./PS4.xyz
nmol = 6 2
timeout_mol = 300.0

Volume of unit cell

You can control the volume of unit cells by changing the value(s) of scaling factor, vol_factor, in cryspy.in. By default, vol_factor is set to 1.0. It is also possible to specify a range of factors. Set minimum and maximum values as follows:

struc_mode = mol
atype = Li P S
nat = 6 2 8
mol_file = ./Li.xyz  ./PS4.xyz
nmol = 6 2
timeout_mol = 300.0
vol_factor = 0.8 1.5

Random structure generation with MPI

2023/10/21 update

情報

CrySPYの基本的な使い方に関してはチュートリアル > Random Search (RS)を見ること.

情報

動作環境:

  • CrySPY 1.1.0 1.2.3 or later
  • mpi4py
  • MPI library (Open MPI, Intel MPI, MPICH, etc.)
警告

1.1.0 <= CrySPY <=1.2.2ではバグがあった. MPIを使ったジョブをbashやzshで実行するとき(e.g., jobcmd = zsh, jobfile = job_cryspy),MPIのジョブが流れない. qsubやsbatchでジョブスケジューラーを使う場合は問題ない。 このバグはバージョン1.2.3で修正.

mpi4py

mpi4pyのインストールがまだであればインストールする.

pip install mpi4py

入力ファイル

cryspy.inはいつもと同じで変更する必要はない.ここでは下記の設定でMPIを使った構造生成を行う.

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

[structure]
atype = Si
nat = 8

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

[option]

tot_strucatypenat以外の変数は構造生成に関係がないのでここでは無視して良い.

実行

4並列で実行する場合,mpiexec -nを使う.-pオプションも必要.

mpiexec -n 4 cryspy -p

In 1.1.0 <= CrySPY <= 1.2.2では下記のコマンド (-pオプションは使用しない)

mpiexec -n 4 cryspy

ジョブスケジューラーなどにサブミットするときは自分でジョブファイルを作る.下記は一例.

#!/bin/sh
#$ -cwd
#$ -V -S /bin/bash
#$ -N n_nproc
#$ -pe smp 4

mpirun -np $NSLOTS ~/.local/bin/cryspy

実行スクリプトcryspyのpathなどは適宜編集すること.

結果

CrySPYはシンプルに構造生成タスクをプロセス数で分割している.

  • Rank 0: IDs 0 – 24
  • Rank 1: IDs 25 – 49
  • Rank 2: IDs 50 – 74
  • Rank 3: IDs 75 – 99

構造が生成された順番でログが出力される.

2023/04/24 22:47:51
CrySPY 1.1.0
Start cryspy.py
Number of MPI processes: 4

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

# --------- Generate initial structures
# ------ mindist
Si - Si 1.11
Structure ID     25 was generated. Space group: 138 --> 123 P4/mmm
Structure ID     75 was generated. Space group:  99 -->  99 P4mm
Structure ID      0 was generated. Space group: 127 --> 123 P4/mmm
Structure ID      1 was generated. Space group:  61 -->  61 Pbca
Structure ID     50 was generated. Space group:  38 -->  38 Amm2
Structure ID     51 was generated. Space group: 134 --> 123 P4/mmm
Structure ID     26 was generated. Space group: 111 --> 123 P4/mmm
Structure ID      2 was generated. Space group:   9 -->   9 Cc
Structure ID      3 was generated. Space group:  80 -->  80 I4_1
Structure ID      4 was generated. Space group: 107 --> 107 I4mm
Structure ID      5 was generated. Space group:  75 -->  75 P4
Structure ID     76 was generated. Space group: 108 --> 108 I4cm
Structure ID     77 was generated. Space group: 100 --> 100 P4bm
Structure ID     27 was generated. Space group: 207 --> 221 Pm-3m

しかし,init_POSCARSでは,構造生成が全て終わった後に出力しているのでID順になっている.

ID_0
1.0
   2.9636956737951818    0.0000000000000002    0.0000000000000002
   0.0000000000000000    2.9636956737951818    0.0000000000000002
   0.0000000000000000    0.0000000000000000    6.2634106638053080
Si
8
direct
  -0.1602734164607877   -0.1602734164607877   -0.0000000000000000 Si
   0.1602734164607877    0.1602734164607877    0.5000000000000000 Si
   0.6602734164607877    0.3397265835392123    0.7500000000000000 Si
   0.3397265835392122    0.6602734164607877    0.2500000000000000 Si
   0.4469739273741755    0.4469739273741755   -0.0000000000000000 Si
   0.5530260726258245    0.5530260726258244    0.5000000000000000 Si
   0.0530260726258245    0.9469739273741754    0.7500000000000000 Si
   0.9469739273741754    0.0530260726258245    0.2500000000000000 Si
ID_1
1.0
   7.2751506682509657    0.0000000000000004    0.0000000000000004
   0.0000000000000000    7.2751506682509657    0.0000000000000004
   0.0000000000000000    0.0000000000000000    5.1777634169924873
Si
8
direct
  -0.3845341807505553   -0.3845341807505553    0.4999999999999999 Si
   0.3845341807505553    0.3845341807505553    0.5000000000000000 Si
   0.3845341807505553   -0.3845341807505553    0.0000000000000000 Si
  -0.3845341807505553    0.3845341807505553   -0.0000000000000000 Si
   0.0000000000000000    0.5000000000000000    0.2500000000000000 Si
   0.5000000000000000    0.0000000000000000    0.7500000000000000 Si
   0.0000000000000000    0.5000000000000000    0.7500000000000000 Si
   0.5000000000000000    0.0000000000000000    0.2500000000000000 Si
ID_2
1.0
  -4.3660398676292269   -4.3660398676292269    0.0000000000000000
  -4.3660398676292269   -0.0000000000000003   -4.3660398676292269
   0.0000000000000000   -4.3660398676292269   -4.3660398676292269
Si
8
direct
   0.8700001548800920    0.8700001548800920    0.1299998451199080 Si
   0.1299998451199080    0.1299998451199080    0.8700001548800920 Si
   0.8700001548800920    0.1299998451199080    0.8700001548800920 Si
   0.1299998451199080    0.8700001548800920    0.1299998451199080 Si
   0.1299998451199080    0.8700001548800920    0.8700001548800920 Si
   0.8700001548800920    0.1299998451199080    0.1299998451199080 Si
   0.7500000000000000    0.7500000000000000    0.7500000000000000 Si
   0.2500000000000000    0.2500000000000000    0.2500000000000000 Si
メモ

ランダム構造生成以外の部分はMPIを使っても並列化されていないので意味はない.

インタラクティブモード (Jupyter Notebook)

2025年3月6日

情報

動作環境:

  • CrySPY 1.4.0以上
  • Jupyter
  • ASE対応の構造最適化計算ソフト(汎用機械学習ポテンシャルなど)
  • nglview (optional)

準備

CrySPYをインストールすればASEは自動的にインストールされている. ワークステーションやローカルPCでJupyterを使えるようにしておく. このチュートリアルでは,構造最適化にPure Python EMT calculatorを用いる.このEMTポテンシャルの精度は悪く,デモ用のものなので注意.

exampleのノートブックには汎用機械学習ポテンシャルのCHGNetを使用するコードも書いてあるので,CHGNetを試したい場合は事前にpipでインストールしておく.

入力ファイル

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

インタラクティブモードでも,cryspy.inを入力ファイルとして使用する. インタラクティブモードではcalc_inディレクトリは使用しない. input_examplesディレクトリの中に,いくつかの入力ファイル例が入っているので参考にしてほしい.

ここではEA-vcを用いた下記のcryspy.inを使用する.EA-vcについてはEA-vcのチュートリアルを見ること.

[basic]
algo = EA-vc
calc_code = ASE
nstage = 1
njob = 10
jobcmd = zsh
jobfile = job_cryspy

[structure]
atype = Cu Au
ll_nat = 0 0
ul_nat = 8 8

[ASE]
ase_python = ase_in.py

[EA]
n_pop = 20
n_crsov = 5
n_perm = 2
n_strain = 2
n_rand = 2
n_add = 3
n_elim = 3
n_subs = 3
target = random
n_elite = 2
n_fittest = 10
slct_func = TNM
t_size = 2
maxgen_ea = 5
end_point = 0.0 0.0

[option]

ノートブック

cryspy_interactive.ipynbを開いて,上から実行していく.

Check current working directory

最初のセルはファイルやcryspy.inの中身を確認しているだけ.

!pwd
print()
!ls
print()
!cat cryspy.in

Import

コメントアウトされているものは今回は無視して,CrySPYのインタラクティブモードで核となるライブラリをインポートするセルを実行する.

# ---------- import
from cryspy.interactive import action

Initialize CrySPY

このセルは通常の初回実行に対応している.cryspy.inを読み込んで初期構造が生成される.

# ---------- initial structure generation
action.initialize()

Set calculator

このセルでASEのcalculatorをセットする.ここではASEのEMTを用いる.

# ---------- EMT in ASE
from ase.calculators.emt import EMT
calculator = EMT()

# ---------- CHGNet
#from chgnet.model import CHGNetCalculator
#calculator = CHGNetCalculator()

Restart CrySPY

このセルを実行すると,先ほど生成した初期構造の最適化が始まる. インタラクティブモードでは一つ一つ順番に構造最適化計算を行う.その際に進捗バーも表示される.

# ---------- structure optimization
action.restart(
    njob=20,    # njob=0: njob in cryspy.in will be used
    calculator=calculator,
    optimizer='BFGS',    # 'FIRE', 'BFGS' or 'LBFGS'
    symmetry=True,       # default: True
    fmax=0.01,           # default: 0.01 eV/Å
    steps=2000,          # default: 2000
)
  • njob: 一度の実行で最適化計算を行う構造数.0の場合はcryspy.inに書いてある値が使用される.
  • calculator: 先に設定したcalculatorを代入
  • optimizer: FIRE, BFGS, LBFGSから選択.文字列で指定する.
  • symmetry: Trueなら対称性を維持した構造最適化を行う
  • fmax: 収束判定に使われる原子に働く力の最大値(eV/Å)
  • steps: 最大最適化ステップ数

njobの値を小さくしている場合は,何度かこのセルを実行して,全ての初期構造の最適化を終了させる. EA-vcを用いている場合,すべて終わると以下のように表示される.

EA is ready

もう一度このセルを実行すると世代交代が行われるので,次世代の構造生成が終了したら,あとは同様にこのセルの実行を繰り返す.

Show results

このセルを実行すると,cryspy_rslt_energy_ascなどのファイルを表示できる.

# ---------- show results
#!cat ./data/cryspy_rslt    # Order of structure optimization completion
!cat ./data/cryspy_rslt_energy_asc    # show energy ascending order
#!sed -n 2,4p ./data/cryspy_rslt    # show i--jth lines
#!tail -n 5 ./data/cryspy_rslt    # show last 5 lines

Structure visualization

初期構造や最適化済みの構造をインタラクティブに可視化できる.

from ase.visualize import view
atoms = action.get_atoms('opt', cid=0)    # 'init' or 'opt'
view(atoms, viewer='ngl')    # viewer = 'ngl', 'ase', or 'x3d'

action.get_atoms('opt', cid=0)のところでoptinitに変えると,初期構造が確認できる. cidで構造IDを指定する. ASEの機能を使用しているのでviewerにはngl, ase, x3dが利用できる. nglを使うにはnglviewのインストールが必要なのでpipでインストールしておく.

fig_struc_visu fig_struc_visu

Energy plot for RS, EA

ランダムサーチ(RS)や進化的アルゴリズム(EA)の場合,下記画像のようなエネルギーグラフを表示できる. EA-vcの場合は原子数が異なるので単純にエネルギーを比較できないので,後述のconvex hullプロットを使う.

fig, ax = action.plot_E(
              title=None,
              ymax=2.0,
              ymin=-0.5,
              markersize=12,
              marker_edge_width=1.0,
              marker_edge_color='black',
              alpha=1.0,
          )

fig_eplot fig_eplot

Convex hull plot for EA-vc

Interactive plot using Plotly

EA-vcの場合はPlotlyを用いたconvex hullのインタラクティブプロットが利用できる. CrySPYをインストールすればPlotlyは自動的にインストールされている. このconvex hullプロットはpymatgenの機能を用いている.

action.interactive_plot_convex_hull(cgen=None, show_unstable=0.2, ternary_style='2d')
  • cgen: どの世代までプロットするかを指定.Noneであれば最新の世代までプロットされる.
  • show_unstable: 描画するhull distanceの最大値.
  • ternary_style
    • 2元系: ternary_style = ‘2d’
    • 3元系: ternary_style = ‘2d’, ‘3d’
    • 4元系: ternary_style = ‘3d’

fig_convplot fig_convplot

2元系ではなく,3元系や4元系で計算しているときは下記のようなインタラクティブプロットが得られる. 左から順に,3元系(ternary_style = ‘2d’),3元系(ternary_style = ‘3d’),4元系(ternary_style = ‘3d’)のプロット

fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary

Binary system using matplotlib

このセルを実行すると,matplotlibを用いて2元系のconvex hullをプロットできる.

fig, ax = action.plot_convex_hull_binary(
              cgen=None,
              show_max=0.2,
              label_stable=True,
              vmax=0.2,
              bottom_margin=0.02,
          )
fig    # to show plot in jupyter
  • cgen: どの世代までプロットするかを指定.Noneであれば最新の世代までプロットされる.
  • show_max: 描画するhull distanceの最大値.
  • label_stable: 安定相のラベルを表示するかどうか.
  • vmax: カラーバーのhull distaceの最大値.
  • bottom_margin: y軸の下部のマージン.

fig_convplotmat fig_convplotmat

Ternary system using matplotlib

もし3元系の探索をしている場合は,このセルを実行することでmatplotlibを使ったconvex hullのプロットができる.

fig, ax = action.plot_convex_hull_ternary(
              cgen=None,
              show_max=0.2,
              label_stable=True,
              vmax=0.2,
          )
fig    # to show plot in jupyter
  • cgen: どの世代までプロットするかを指定.Noneであれば最新の世代までプロットされる.
  • show_max: 描画するhull distanceの最大値.
  • label_stable: 安定相のラベルを表示するかどうか.
  • vmax: カラーバーのhull distaceの最大値.

例えば以下のようなプロットが得られる.

fig_convplotmat fig_convplotmat

Interface

2025 June 16

CrySPYはエネルギー計算や構造最適化に外部のソフトウェアを利用する. 以下のソフトウェアを利用可能:

少なくともいずれか一つは必要.

アルゴリズム互換性

CrySPY 1.4.0
Developing additional interfaces for EA-vc.

RSEAEA-vcBOLAQA
VASP×
Quantum Espresso×
OpenMX××
soiap×
LAMMPS××
ASE×
Interactive (ASE)××

オプション互換性

energy_step_flagstruc_step_flagforce_step_flagstress_step_flag
VASP
Quantum Espresso
OpenMX××××
soiap
LAMMPS××××
ASE××××

探索アルゴリズムのサブセクション

Random search (RS)

under construction

進化的アルゴリズム (EA)

2025 April 2

背景

進化的アルゴリズム(EA)は,進化論に着想を得たメタヒューリスティックな手法である. EA は,これまでに探索された安定構造(親構造)の局所環境を受け継ぐことで,新たな構造(子個体)を効果的に生成することができる. Oganov グループの USPEX はよく知られたソフトウェアであり,そのほかにも XtalOpt などがある. 先行研究の例は以下の通り.

  • T. S. Bush, C. R. A. Catlow, and P. D. Battle, J. Mater. Chem. 5, 1269 (1995).
  • A. R. Oganov and C. W. Glass, J. Chem. Phys. 124, 244704 (2006).
  • A. R. Oganov, A. O. Lyakhov, and M. Valle, Acc. Chem. Res. 44, 227 (2011).
  • A. O. Lyakhov, A. R. Oganov, H. T. Stokes, and Q. Zhu, Comput. Phys. Commun. 184, 1172 (2013).

fig_EA_pes fig_EA_pes

手順

  1. 個体群(population)の初期化
  2. 適応度(fitness)の評価
  3. 自然選択
  4. 親個体の選択
  5. 次世代の生成
  6. ステップ2(適応度の評価)に戻り繰り返す

個体群(population)の初期化

第一世代では,n_pop で指定された数のランダム構造が生成される. EAおよびEA-vcにおいては,tot_struc は使用されない.

適応度(fitness)の評価

現在,CrySPYにおいて適応度として使用できるのはエネルギーのみである. fit_reverse = False に設定することで,最小値探索モードになるよう構成されている. この fit_reverse の設定は,将来的にエネルギー以外の物性を適応度として用いる場合に備えて用意されている.

自然選択

DFT計算では,まれに失敗して極端に不合理なエネルギー値が得られることがある. emax_ea および emin_ea を用いることで,極端に高い(または低い)エネルギーを持つ構造を除外することができる:    $$ \mathrm{emin\_ea} \le E \ (\mathrm{eV/atom}) \le \mathrm{emax\_ea} $$ たとえば,emin_ea を設定すると,その値よりも低いエネルギーを持つ構造は無視される.

自然選択では,まず現在の個体群と,過去の世代から保持されたエリート個体が,適応度に基づいてランク付けされる. ここで使用されるエリート個体の数は,n_eliteで指定される. 現在の個体群とエリート個体の中から,適応度の高い順に n_fittestの数の個体が選択され,それ以外は淘汰される. 自然選択の過程では,pymatgenStructureMatcher クラスにより重複を除去し,上位n_fittestの数の個体を選択している. n_fittest は,n_pop(個体群サイズ)の約半分に設定されることが多い. 現在の実装では,n_fittest = 0 の場合,すべての個体が保持される仕様になっている. 下の図はn_fittest = 5の場合の自然選択の例を示している.

fig_EA_natural_selection fig_EA_natural_selection

親個体の選択

親候補の個体の中から1つの親個体を選択するために,CrySPYでは2種類の選択手法が実装されている. いずれの手法も,適応度の高い個体がより高い確率で選ばれるように設計されている. slct_func = TNMを設定するとトーナメント選択が,slct_func = RLTを設定するとルーレット選択が使用される. トーナメント選択はパラメータが少なく,簡単に使用できる点が利点である.

次世代の生成

次世代は,親候補の個体に対して進化的操作を適用して生成された子個体と,一部のランダム構造から構成される. ランダム構造は,多様性を維持し,局所的最小からの脱出を促すために各世代で追加される.

進化的操作

ここでは,CrySPYに実装されている,組成固定型EAの進化的操作を紹介する.

個体群の数

crossover, permutation, strainおよびランダムに生成された構造数の合計がn_popと等しくなければならない.

  • n_pop = n_crsov + n_perm + n_strain + n_rand

進化的アルゴリズム (EA)のサブセクション

Crossover

概要

交叉(cross over)は,2つの親構造のスライスされた領域を交換することで,新たな構造(子個体)を生成する進化的操作である. この操作により,構造の多様性が促進され,局所的に安定な特徴が遺伝することが可能となる. 構造探索において低エネルギー構造を効率的に探索するための主要な手法のひとつである.

手順

  1. 親候補から異なる個体を2つ選択
  2. ランダムに並進操作
  3. 格子ベクトルをランダムに選択
  4. 中央付近で親構造を切断
  5. 切断された半分を交換
  6. 原子数の多い子構造を選択
  7. ボーダー付近で原子数の調整
  8. 最小原子間距離のチェック

fig_EA_crossover fig_EA_crossover

4. 中央付近で親構造を切断

切断ポイントは中央付近で,下記のように毎回少し変化させる.

slice_point = np.clip(np.random.normal(loc=0.5, scale=0.1), 0.3, 0.7)

以降のステップで失敗した場合,このステップ4に戻って再開する場合がある. ただし,再開可能な回数はmaxcnt_eaで上限が決められており,それを過ぎた場合は親の選択からやり直す.

5. 切断された半分を交換

crs_latrandomの時,子構造の格子ベクトルは2つの親構造のうちのどちらか一方をそのまま引き継ぐ. crs_latequalの場合は,親構造の格子ベクトルの平均を使う. デフォルトはrandom

6. 原子数の多い子構造を選択

親構造を入れ替えると,通常二つの原子数の異なる構造が得られる. とりあえず,原子数の多い構造を採用する.

fig_EA_crossover_natoms fig_EA_crossover_natoms

ただし,原子数が元の構造のものと大きく違う場合はステップ4(中央付近で親構造を切断)からやり直す. その許容量はnat_diff_toleで決める. デフォルト値は4で,その場合それぞれの元素において原子数の差が±4まで許容される. 上の図の場合,元の構造と比較すると,青の原子は-1で,緑の原子は+2になっている.

7. ボーダー付近で原子数の調整

削除

原子数を調整する際,まずは原子の削除から行う. 下の図に示すように,mindistで定義される最小原子間距離を満たしていない原子から優先的に削除される.

fig_EA_crossover_rm_mindist fig_EA_crossover_rm_mindist

以下のように,もし原子の削除が完了しても最小原子間距離の制限にかかる原子がある場合,ステップ4(中央付近で親構造を切断)からやり直す.

fig_EA_crossover_rm_mindist2 fig_EA_crossover_rm_mindist2

最小原子間距離の制限にかかる原子が無く,さらに原子を削除する必要がある場合は,下の図に示すようにボーダーから近い原子から削除する.切断ポイントに加えて内部座標が0のところもボーダーであることに注意.

fig_EA_crossover_rm_border fig_EA_crossover_rm_border

追加

原子が不足しているときは,その原子をボーダー付近に追加する. 選択されている軸に沿った内部座標は下記のように決める. ここでmeanは切断ポイントの座標か0である.

coords[axis] = np.random.normal(loc=mean, scale=0.08)

座標の残りの二つの成分はランダムに決められる. 最小原子間距離のチェックを行いながら,元の組成と一致するまで原子を追加する.

fig_EA_crossover_addition fig_EA_crossover_addition

Permutation

概要

置換(permutation)は,単一の構造内における異なる元素同士の配置を入れ替えることで,新たな構造(子個体)を生成する進化的操作である. この操作により,格子および全体の組成を変えることなく,異なる構造配置の探索が可能となる.

手順

異なる元素の原子の位置を入れ替える. 原子の入れ替えの回数はntimesで指定する.デフォルトは1回. 入れ替え後,最小原子間距離をチェックする.

fig_EA_permutation fig_EA_permutation

Strain

概要

歪み(strain)は,親構造の格子に対して小さなランダムな変形を加えることで,新たな構造(子個体)を生成する進化的操作である. この操作により,原子の接続関係や組成を保持しつつ,構造空間の近傍領域を探索することが可能となる. 構造候補の微調整や,局所的な最小値からの脱出にも有効である.

手順

以下の歪み行列を用いて,格子ベクトル $ \mathbf{a} $を変形させる.

$$ \mathbf{a}' = \begin{pmatrix} 1 + \eta_1 & \frac{1}{2} \eta_6 & \frac{1}{2} \eta_5 \\ \frac{1}{2} \eta_6 & 1 + \eta_2 & \frac{1}{2} \eta_4 \\ \frac{1}{2} \eta_5 & \frac{1}{2} \eta_4 & 1 + \eta_3 \end{pmatrix} \mathbf{a}. $$

ここで, $ \eta_i $はガウス分布 $ \mathcal{N}\left( 0, \ \sigma_{\mathrm{st}}^2 \right) $から決まる値で, $ \sigma_{\mathrm{st}} $は入力パラメーターsigma_stで指定できる(デフォルトはsigma_st = 0.5). 下の図に示すように,格子を変形させた後は,元の体積に戻す. 最後に最小原子間距離の制限をチェックする.

fig_EA_strain fig_EA_strain

トーナメント選択

概要

トーナメント選択は,適応度に基づいて候補の中から親個体を選ぶための手法である. この手法は,個体群内の選択圧と多様性のバランスをとるように設計されている. 下の図は,n_fittest = 10t_size = 3の場合の例を示す.

fig_EA_tournament fig_EA_tournament

手順

  1. 親個体候補から,所定の数(t_size)の個体をランダムに選択
  2. その中で,最も適応度の高い(すなわち,エネルギーが最も低い)個体が親として選ばれる
  3. この処理を繰り返し,必要な数の親個体が選ばれるまで続ける

利点

  • シンプルで効率的
  • パラメータは1つだけ (t_size)
  • t_sizeを変えることで選択圧を調整可能

注意

  • t_sizeはデフォルトで3
  • t_sizeが小さいと,多様性が促進される
  • t_sizeが大きいと,選択圧が増して,選択確率がより適応度に依存する
  • ルーレット選択とは異なり,トーナメント選択では下位の(t_size - 1)個の個体が選択されることはない

ルーレット選択

概要

ルーレット選択は,適応度に基づいて親候補の個体の中から親個体を選ぶための確率的手法である. ルーレット選択においては,各個体の選ばれる確率はその適応度に比例する.

手順

  1. fit_reverseFalse(デフォルト)に設定されている場合,これはエネルギーを適応度として用いる最小化モードに対応しており,親候補の適応度には –1 が掛けられる.
  2. 適応度 $ f_i $ は,以下の式により線形スケーリングされて $ f'_i $ に変換される.ここで, $ a $ および $ b $ は,それぞれ a_rlt および b_rlt で指定されるパラメータであり, $ a > b $ でなければならない.
    $$ f_i' = \frac{a - b}{f_{\mathrm{max}} - f_{\mathrm{min}}} f_i + \frac{b f_{\mathrm{max}} - a f_{\mathrm{min}}}{f_{\mathrm{max}} - f_{\mathrm{min}}} $$
  3. スケーリング後の適応度 $ f'_i $ は,次式により選択確率に変換される:
    $$ p_i = \frac{f_i'}{\sum_k f_k'} $$
    $ p_i $ は, $ i $ 番目の個体が選ばれる確率を表す.
  4. 親個体は, $ p_i $ に基づいてルーレット選択により1つずつ選ばれ,必要な数に達するまで繰り返される.

利点

  • すべての個体が非ゼロの確率で選ばれる可能性がある
  • 適応度のスケーリングによって選択圧を調整できる

注意

  • デフォルトでは a_rlt = 10.0b_rlt = 1.0
  • 意味のある選択圧を得るためには,適応度のスケーリングが重要である. 下の図は, $ a $ が比較的小さい場合(左)と比較的大きい場合(右)における $ p_i $ の例を示している.
    $ a $ が小さすぎると選択圧が弱くなり,適応度の高い個体が優先されにくくなる.

fig_EA_roulette fig_EA_roulette

組成可変型進化的アルゴリズム (EA-vc)

2025 April 4

概要

CrySPY 1.4.0 以降,組成固定型EAを拡張した組成可変型EA(EA-vc)が利用可能になった. サポートしているインターフェースはこちらを確認すること(インターフェース). 全体の流れは組成固定型EAと類似しているが,EA-vcでは異なる組成に対応するために,適応度の評価方法と子個体の生成方法が異なる. ここでは,元のEAから変更された部分について説明する.

手順

  1. 個体群(population)の初期化
  2. 適応度(fitness)の評価
  3. 自然選択
  4. 親個体の選択
  5. 次世代の生成
  6. ステップ2(適応度の評価)に戻り繰り返す

個体群(population)の初期化

第一世代では,n_pop で指定された数のランダム構造が生成される. EAおよびEA-vcでは tot_struc は使用されない. EA-vcでは,各原子種の原子数は,ユーザーが定義した範囲内でランダムに決定される. 各原子種ごとの原子数の最小値(ll_nat)および最大値(ul_nat)は,以下のように cryspy.in で指定することができる.

[structure]
atype = Cu Au
ll_nat = 0 0
ul_nat = 8 8

適応度(fitness)の評価

異なる原子数を持つ構造の全エネルギーを直接比較することには意味がないため,異なる組成間の相安定性を評価するために,形成エネルギーから計算された凸包(convex hull)が用いられる. 形成エネルギー,凸包,相図に関する情報はオンラインで参照できる. 例えば,Materials Project Documentation を参照のこと. EA-vcでは,適応度は energy above hull(hull distanceとも呼ばれる)として定義されている.

fig_EA-vc_phase_diagram_binary.svg fig_EA-vc_phase_diagram_binary.svg

形成エネルギー

形成エネルギーは,基準となる安定な単体のエネルギー(eV/atom)に基づいて計算され,これらは cryspy.inend_point で指定される. 例えば,Cu–Auの2元系の場合,end_point にはfcc-Cuおよびfcc-Auの1原子あたりのエネルギー(eV/atom)をこの順で記述する必要がある. 構造探索中に,end_point と同じ組成を持つ構造が見つかり,そのエネルギーが対応する end_point の値よりも低かったとしても,形成エネルギーの計算には依然として cryspy.in に定義された元の end_point の値が用いられることに注意すること.

凸包(Convex hull)

ある構造の形成エネルギーと,その組成におけるconvex hull上のエネルギーとの差は,energy above hull(hull distanceとも呼ばれる)と呼ばれる. この値は,同じ組成における最も安定な相の組み合わせと比べて,その構造の形成エネルギーがどれだけ高いかを示している. hull distanceが0の構造はconvex hull上にあり,熱力学的に安定である.

組成固定型EAとは異なり,EA-vcではconvex hullの計算時に構造の1原子あたりのエネルギーに基づいてフィルタリングを行い,以下の条件を用いる:    $$ \mathrm{emin\_ea} \le E \le \mathrm{emax\_ea} $$
このフィルタリングは形成エネルギーではなく,あくまで1原子あたりの全エネルギーに基づいて行われることに注意すること.

convex hullの計算には,pymatgenPhaseDiagramクラスを使用している. 形成エネルギーの場合とは異なり,end_point と同じ組成を持つ構造が対応する end_point の値よりも低いエネルギーを持っていた場合,その構造がconvex hullおよびhull distanceを計算する際の基準として使用される.

自然選択

下図に示すように,EA-vcではhull distanceが0の安定構造が複数得られる場合がある. このような場合,複数の個体がhull distanceにおいて同率の最上位ランクを占めることになる. n_eliteで指定されたエリート構造の数が,同率ランクの個体数より少ない場合,選択には任意性が生じる. 現在のところ,CrySPYではhull distanceが0.001 eV/atom未満の個体の中から,n_elite 個をランダムに選択している. hull distanceが 0.001 eV/atom未満の個体数が n_elite より少ない場合には,通常通り,適応度に基づくランキングによってエリート構造が選択される. エリート個体を選択する際にも,pymatgenStructureMatcherクラスを用いて重複構造を排除している.

fig_EA-vc_elite.svg fig_EA-vc_elite.svg

エリート個体は,過去の世代で得られた最良の構造に基づいて選択される. しかし,hull distanceは世代ごとに変化する可能性があるため,自然選択を行う前に,現在のconvex hullを用いてエリート個体のhull distanceを再計算している.

Convex hullセクションで述べたように,EA-vcでは,emin_eaおよびemax_eaは自然選択では使用されない.

親個体の選択

親個体の選択方法は組成固定型EAと同様である.

次世代の生成

進化的操作

crossover(vc)の操作は,組成固定型EAのものとわずかに異なるが,permutationおよびstrainは同一である. EA-vcでは,組成可変にするためにいくつかの新しい操作が導入されている.

個体群の数

crossover,permutation,strain,addition,elimination,substitution,およびランダム生成による構造の合計は,n_pop と等しくなければならない.

  • n_pop = n_crsov + n_perm + n_strain + n_add + n_elim + n_subs+ n_rand

組成可変型進化的アルゴリズム (EA-vc)のサブセクション

Crossover (vc)

組成可変型のcrossoverは,組成固定型のバージョンとほとんど同じであるが,原子数の調整が最小限に抑えられている点が異なる. 組成固定型crossoverのステップ6では,各原子種ごとの原子数の差を直接計算する. 一方,crossover(vc)では,ll_natul_nat で定義された許容範囲に基づいて原子数の差を計算する. 例えば,次のようになる:

ll_nat = [4, 4, 4]
ul_nat = [8, 8, 8]
offspring_nat = [2, 6, 12]
nat_diff = [-2, 0, 4]

上記の例でいう nat_diff にあたる原子数の差が,許容値 nat_diff_tole を超えている場合は,この操作はやり直される. そうでない場合は,原子数が ll_natul_nat で定義された範囲に収まるように調整される.

Addition

現在の原子数が ul_nat で指定された上限を超えない原子種をランダムに選択し,その原子をランダムな位置に1個追加する.

  • 原子を1個追加し,それが mindist で指定される最小原子間距離の制限を満たしていれば,その構造を採用する.
  • 距離の条件を満たさない場合は,別のランダムな位置に再配置する.この処理は最大 maxcnt_ea 回まで繰り返される.
  • 有効な子個体が得られなければ,体積を10%拡張して,同じ処理を最大 maxcnt_ea 回まで再試行する.
  • それでも失敗した場合は,体積を最大20%まで拡張して構造生成を試みる.それでもうまくいかない場合は,親個体を変更する.

fig_EA-vc_addition.svg fig_EA-vc_addition.svg

Elimination

現在の原子数が ll_nat で指定された下限を上回っている原子種をランダムに選択し,その原子を1個削除する.

fig_EA-vc_elimination.svg fig_EA-vc_elimination.svg

Substitution

Substitutionは,2つの異なる原子種をランダムに選択する操作である. 2つの異なる原子種の1つは,現在の原子数が ll_nat で指定された下限を上回っているもので,もう1つは ul_nat で指定された上限を下回っている原子種である. 前者の原子を1つ,後者の原子に置き換える. 最終的に,mindist で指定される最小原子間距離の制限をチェックし,問題がなければその構造を子個体として採用する.

fig_EA-vc_substitution.svg fig_EA-vc_substitution.svg

LAQA

選択型アルゴリズムの一つ.

fig_LAQA fig_LAQA

fig_LAQA fig_LAQA

Score $ L $

$$ L = -E + w_F \frac{F^2}{2\Delta F} + w_S S. $$
SymbolNote
$$ E $$エネルギー(eV/atom)
$$ w_F $$力の項の重み. Default: $ w_F = 0.1$
$$ F $$原子に働く力の平均ノルム(eV/Å)
$$ \Delta F $$一つ前のステップからの $ F $の差の絶対値.はじめのステップでは $ \Delta F = 1$$ \Delta F = 10^{-6}$ if $ \Delta F \le 10^{-6} $.
$$ w_S $$ストレス項の重み.Default: $ w_S = 10.0$
$$ S $$ストレステンソルにおける成分の絶対値平均(eV/Å^3).

Reference

構造生成のサブセクション

struc_mode = crystal

under construction

struc_mode = mol

under construction

struc_mode = mol_bs

CrySPY uses pyxtal in normal molecular crystal structure generation mode (struc_mode = mol). The molecules are arranged to fit a point group at a selected Wykoff position in the space group to keep the symmetry. (Sometimes it takes a long time to generate.)

In mol_bs mode (bs means break symmetry), dummy atoms are placed in Wykoff positions as in ordinary crystals, and then the dummy atoms are replaced by molecules without considering symmetry and rotated randomly. The structure generation is relatively fast.

under construction

機能のサブセクション

Logging

2023 July 10

CrySPY 1.2.0からPython標準ライブラリのloggingを採用. CrySPYのログは画面とファイル(log_cryspy and err_cryspy)の両方に出力される.

  • log –> screen and log_cryspy
  • error and warning –> screen and err_cryspy

ログの例:

[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

ログを画面に出力させたくないときは下記のように-n オプションをつけて実行する.

cryspy -n

バックアップ

2024 Dec. 22 updated

CrySPYはシンプルなバックアップ機能を備えている. バックアップの対象は以下のファイル:

  • cryspy.in
  • cryspy.stat
  • log_cryspy
  • err_cryspy
  • debug_cryspy
  • cryspy_interactive.ipynb
  • calc_in/*
  • data/*

work/* は含まれいないので注意.

  • (v1.1.0以降) 上記ファイルが日付と時間で名前づけられたディレクトリにコピーされる.以前のバックアップは自動的には削除されない.
  • (v1.0.0) バックアップは1世代分のみであり,それより古いものは削除される.

自動バックアップ

自動的にバックアップされるタイミングは次の通り:

  • 次の選択に移るとき(BO, LAQA)か世代交代を行うとき (EA)
  • 構造を追加するとき

手動バックアップ

手動でバックアップを行いたい場合は,-b または --backup オプションをつけて次のようにcryspyを実行する:

cryspy -b

このコマンドは通常の実行とは異なり,バックアップだけを行います.

クリーン

2024 Dec. 22 updated

CrySPYはシンプルなクリーン機能を備えている. 初めからやり直したい時に便利となる. 以下のファイルがクリーン(実際はファイルを移動するだけ)される.

  • cryspy.stat
  • log_cryspy
  • err_cryspy
  • lock_cryspy
  • data/*
  • work/*
  • tmp_gen_struc/*

クリーンする場合は-c または --clean オプションをつけてcryspyを実行する:

$ ls
calc_in  cryspy.in  cryspy.stat  data  err_cryspy  log_cryspy
$ cryspy -c
Are you sure you want to clean the data? 'yes' or 'no' [y/n]: y
$ ls
calc_in  cryspy.in  trash
$ ls trash
20230318_100728

calc_in/*cryspy.in 以外のファイルがtrashの中の日付と時間で名前づけられたディレクトリに移動します. 必要なければ手動で削除してください.

原子間距離の制限

2025年6月17日 更新

構造生成時に原子間距離の制限を行うことができる. 下記はA-B 2元系における[structure]セクションの最低原子間距離の設定例.

[structure]
natot = 8
atype = A B
nat = 4 4
mindist_1 = 2.0 1.8
mindist_2 = 1.8 1.5

原子A-A,B-BおよびA-B間の最低原子間距離がそれぞれ2.0,1.8および1.5 Åに設定されている. 原子間距離がこの値よりも小さい構造は自動的に棄却される.

3元系では mindist_1mindist_2およびmindist_3が必要になる. mindistの行列は対称行列でなければならない.

CrySPY 1.4.0以降では,この最低原子間距離のチェックは構造最適化後にも行われる. 導入した理由は,機械学習ポテンシャルなどでは時々原子がほぼ重なるような構造が得られてしまうため. cryspy.inで下記のようにすることでこの機能をオフにすることもできる(デフォルトはオン)

[option]
check_mindist_opt = False

Example: Na8Cl8

Without mindist

cryspy.in

[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

[VASP]
kppvol = 40 80

[option]

log_cryspy

[2024-04-23 13:46:28,598][cryspy_init][INFO] 


Start CrySPY 1.2.3


[2024-04-23 13:46:28,598][cryspy_init][INFO] # ---------- Read input file, cryspy.in
[2024-04-23 13:46:28,598][read_input][INFO] Save input data in cryspy.stat
[2024-04-23 13:46:28,599][gen_init_struc][INFO] # ------ mindist
[2024-04-23 13:46:28,601][struc_util][INFO] Na - Na: 1.66
[2024-04-23 13:46:28,602][struc_util][INFO] Na - Cl: 1.3399999999999999
[2024-04-23 13:46:28,602][struc_util][INFO] Cl - Cl: 1.02
...

fig_mindist fig_mindist

PyXtalのデフォルト設定では,上の図のように原子同士が近すぎる場合があるので,mindistを設定することをすすめる. DFT計算もやりやすくなるであろう.

With mindist

cryspy.in

[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]

log_cryspy

[2024-04-23 14:06:21,955][cryspy_init][INFO] 


Start CrySPY 1.2.3


[2024-04-23 14:06:21,955][cryspy_init][INFO] # ---------- Read input file, cryspy.in
[2024-04-23 14:06:21,956][read_input][INFO] Save input data in cryspy.stat
[2024-04-23 14:06:21,956][gen_init_struc][INFO] # ------ mindist
[2024-04-23 14:06:21,956][struc_util][INFO] Na - Na: 2.5
[2024-04-23 14:06:21,956][struc_util][INFO] Na - Cl: 1.5
[2024-04-23 14:06:21,956][struc_util][INFO] Cl - Cl: 2.5

イオン結晶のような場合には,カチオン同士,アニオン同士が離れるような設定をしておくと良い.

ジョブファイルのCrySPY_ID

CrySPYのジョブファイルで,“CrySPY_ID"という文字列は自動的に構造IDに置換される. PBSやSLURMなどのジョブスケジューラーを使う時,ジョブ名に構造IDを使うと便利である. 例えばPBSでは, #PBS -N Si_CrySPY_ID#PBS -N Si_10に置き換わる 大抵の場合,ジョブ名は数字から始められないことが多いので,Si_のように英字から始めておくと良い.

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

mpirun -np $NSLOTS pw.x -nk 4 -nb 2 < pwscf.in > pwscf.out


if [ -e "CRASH" ]; then
    exit 1
fi

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

MPI並列化を用いた構造生成

2023/10/21 update

CrySPYのバージョン1.1.0(1.2.3以上の利用を推奨)からは,MPIを用いたランダム構造生成が可能になった. MPIを使うにはPython環境にmpi4pyをインストールする必要がある. 当然,計算に利用するワークステーション等にMPIライブラリ(Open MPI,Intel MPI,MPICHなど)も必要である.

情報

MPIを使うのに下記が必要

  • CrySPY 1.1.0 1.2.3 or later
  • mpi4py
  • MPI library (Open MPI, Intel MPI, MPICH, etc.)
警告

1.1.0 <= CrySPY <=1.2.2ではバグがあった. MPIを使ったジョブをbashやzshで実行するとき(e.g., jobcmd = zsh, jobfile = job_cryspy),MPIのジョブが流れない. qsubやsbatchでジョブスケジューラーを使う場合は問題ない。 このバグはバージョン1.2.3で修正.

下の図にSi8原子1000構造をランダムに生成するのにかかった時間とMPIプロセス数の関係を示す.下記のセッティングを使った.

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

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

mindset_1 = 2.2のように厳し目に設定して,わざと時間がかかるようにしてある. それぞれのプロセス数において10回ずつ実行して,平均を線で結んでいる.

fig_MPI fig_MPI

Run

mpiexec -n 4 cryspy -p

Enthalpy

2023/10/18

情報

Requirements:

  • CrySPY 1.2.2 or later
  • VASP or QE

高圧化における構造探索を行う時に, エネルギーの代わりにエンタルピーを使うことができる. VASPとQE以外はまだ未対応.

cryspy_rsltcryspy_rslt_energy_ascE_eV_atomの箇所がエンタルピー(eV/atom)に変わる. 下記は40 GPaにおけるSr4O4の構造探索の結果の例. 高圧下ではCsCl型構造(ID 5)がNaCl型構造よりも安定になっている.

   Spg_num Spg_sym  Spg_num_opt Spg_sym_opt  E_eV_atom  Magmom      Opt
5       26  Pmc2_1          221       Pm-3m  -2.276790     NaN     done
6      225   Fm-3m          225       Fm-3m  -2.244800     NaN     done
1      101  P4_2cm          107        I4mm  -2.181115     NaN     done
4      123  P4/mmm          123      P4/mmm  -2.034509     NaN  not_yet
3       20  C222_1           63        Cmcm  -0.686541     NaN     done
2       75      P4           75          P4  -0.008713     NaN  not_yet
9       51    Pmma           47        Pmmm   0.096430     NaN     done
8       65    Cmmm          123      P4/mmm   1.099657     NaN     done
0      187   P-6m2          187       P-6m2   1.292124     NaN     done
7       53    Pmna           53        Pmna   5.153504     NaN  not_yet

VASP

CrySPYではOSZICARからエネルギー(エンタルピー)を読んでいる. これはPSTRESSINCAR_xで以下のようにセットされると自動的にエンタルピーに変わる:

PSTRESS = 400

cryspy.inでは特に何もする必要はない. energy_step_flagのオプションも使用可能でエンタルピーを読み込める.

Example: CrySPY utility > examples > qe_Sr4O4_RS_pv_term

QE

エンタルピーを読むためにはcryspy.inのQEセクションでpv_term = Trueをつける:

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

QEの入力ファイルでもpressの設定を忘れずに:

 &cell
    press = 400
 /
警告

QEではenergy_step_flagオプションでエンタルピーを読むことにまだ未対応.

As library

2024 May 31

情報

Requirements:

  • CrySPY 1.3.0 or later

Cryspy can be used as a library to generate random structures or structures by evolutionary algoritym. The jupyter notebook is available in CrySPY utility > notebook > as_library.

Random structure generation

####
#### when you change set_logger(), you need to restart the kernel
####
from cryspy.util.utility import set_logger    # optional
set_logger()    # optional
#set_logger(noprint=True, logfile='log_cryspy', errfile='err_cryspy')    # write log and err messages to files

from cryspy.RS.gen_struc_RS import gen_pyxtal

nstruc = 10
atype = ('Na', 'Cl')
nat = (4, 4)
mindist = ((2.0, 1.5),
           (1.5, 2.0))
spgnum = 'all'

init_struc_data = gen_pyxtal.gen_struc(
    nstruc=nstruc,
    atype=atype,
    nat=nat,
    mindist=mindist,
    spgnum=spgnum,
)

You can get init_struc_data (dict: {ID: pymatgen Strcture, …})

Structure generation by evolutionary algorithm

Situation: parent A (, parent B) –> child

Prepare two (one) parent structures as pymatgen Structure object.
In this example, just use the results of RS for Cu4Au4 (see, CrySPY utility > notebook > as_library).

import pickle
with open('./Cu4Au4_sample/opt_struc_data.pkl', 'rb') as f:
    opt_struc_data = pickle.load(f)

Crossover

from cryspy.EA.gen_struc_EA import crossover

# you can change parent_A and parent_B
parent_A = opt_struc_data[0]
parent_B = opt_struc_data[1]

atype = ('Cu', 'Au')
nat = (4, 4)
mindist = ((1.5, 1.5),
           (1.5, 1.5))

child = crossover.gen_child(
    atype=atype,
    nat=nat,
    mindist=mindist,
    parent_A=parent_A,
    parent_B=parent_B,
)

# child: pymatgen Structure

Permutation

from cryspy.EA.gen_struc_EA import permutation

# you can change parent_A
parent_A = opt_struc_data[0]

atype = ('Cu', 'Au')
nat = (4, 4)
mindist = ((1.5, 1.5),
           (1.5, 1.5))
ntimes = 1    # number of times to perform permutatio

child = permutation.gen_child(
    atype=atype,
    mindist=mindist,
    parent_A=parent_A,
    ntimes=ntimes,
)

# child: pymatgen Structure

Strain

from cryspy.EA.gen_struc_EA import strain

atype = ('Cu', 'Au')
nat = (4, 4)
mindist = ((1.5, 1.5),
           (1.5, 1.5))
sigma_st = 0.05    # standard deviation of strain

child = strain.gen_child(
    atype=atype,
    mindist=mindist,
    parent_A=parent_A,
    sigma_st=sigma_st,
)

Situation: parent group, fitness –> children

Data set

Prepare structure and fitness (energy) data as dict. The key is structure ID. In this example, just use the results of RS for Cu4Au4 (see, CrySPY utility > notebook > as_library)..

e.g.
struc_data = {0: (pymatgen Structure), 1: (pymatgen Structure), …}
fitness = {0: 0.019632287242441926, 1: -0.005437509701440302, …}

import pickle
with open('./Cu4Au4_sample/opt_struc_data.pkl', 'rb') as f:
    opt_struc_data = pickle.load(f)
with open('./Cu4Au4_sample/rslt_data.pkl', 'rb') as f:
    rslt_data = pickle.load(f)

struc_data = opt_struc_data    # dict
fitness = rslt_data['E_eV_atom'].to_dict()    # you may include None or np.nan for values

Survival of the fittest

from cryspy.EA.survival import survival_fittest
from cryspy.EA.gen_struc_EA.select_parents import SelectParents
from cryspy.EA.gen_struc_EA import crossover, permutation, strain

n_fittest = 5    # number of survivors

ranking, _, _ = survival_fittest(
    fitness=fitness,
    struc_data=struc_data,
    elite_struc=None,
    elite_fitness=None,
    n_fittest=n_fittest,
    fit_reverse=False,
    emax_ea=None,
    emin_ea=None,
)

# ranking <-- e.g. [2, 1, 0, 7, 9] without structure duplicaiton

Select parents class

sp = SelectParents(ranking)    # after set_xxx, we can use sp.get_parents(n_parent)
sp.set_tournament(t_size=2)

Crossover

atype = ('Cu', 'Au')
nat = (4, 4)
mindist = ((1.5, 1.5),
           (1.5, 1.5))
n_crsov = 5    # number of structures to be generated by crossover
#id_start = len(init_struc_data)  # next Structure ID
id_start = 10

co_children, co_parents, co_operation = crossover.gen_crossover(
    atype=atype,
    nat=nat,
    mindist=mindist,
    struc_data=struc_data,
    sp=sp,
    n_crsov=n_crsov,
    id_start=id_start,
)

# co_children <-- dict {ID: pymatgen Structure, ID: pymatgen Structure, ...}
# co_parents  <-- e.g. {10: (2, 7), 11: (2, 1), 12: (2, 1), 13: (0, 2), 14: (2, 1)}
# co_operation <-- e.g. {10: 'crossover', 11: 'crossover', ...}

Permutation

n_perm = 5    # number of structures to be generated by permutation
#id_start = len(init_struc_data) + n_crsov   # next Structure ID
id_start = 15
ntimes = 1    # number of times to perform permutation

pm_children, pm_parents, pm_operation = permutation.gen_permutation(
    atype=atype,
    mindist=mindist,
    struc_data=struc_data,
    sp=sp,
    n_perm=n_perm,
    id_start=id_start,
    ntimes=ntimes,
)

# pm_children <-- dict {ID: pymatgen Structure, ID: pymatgen Structure, ...}
# pm_parents  <-- e.g. {15: (2,), 16: (1,), 17: (2,), 18: (1,), 19: (1,)}
# pm_operation <-- e.g. {15: 'permutaion', 16: 'permutation', ...}

Strain

n_strain = 5    # number of structures to be generated by strain
#id_start = len(init_struc_data) + n_crsov + n_perm   # next Structure ID
id_start = 20
sigma_st = 0.05    # standard deviation of strain

st_children, st_parents, st_operation = strain.gen_strain(
    atype=atype,
    mindist=mindist,
    struc_data=struc_data,
    sp=sp,
    n_strain=n_strain,
    id_start=id_start,
    sigma_st=sigma_st,
)

# st_children <-- dict {ID: pymatgen Structure, ID: pymatgen Structure, ...}
# st_parents  <-- e.g. {20: (1,), 21: (2,), 22: (0,), 23: (2,), 24: (2,)}
# st_operation <-- e.g. {20: 'strain', 21: 'strain', ...}

Interactive mode

2025年3月6日

情報

動作環境:

  • CrySPY 1.4.0以上
  • Jupyter
  • ASE対応の構造最適化計算ソフト(汎用機械学習ポテンシャルなど)
  • nglview (optional)

PCクラスタやスパコンなどの利用に慣れてない人でも使えるように,Jupyter Notebookを用いたインタラクティブモードが利用可能になった. ASEを使った構造最適化計算を想定しているので,ASE対応の汎用機械学習ポテンシャルなどが使える.

詳細な使い方はチュートリアル > インタラクティブモード(Jupyter Notebook)を見ること.

fig_struc_visu fig_struc_visu fig_eplot fig_eplot fig_convplot fig_convplot

fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary fig_conv_plotly3d_ternary

fig_convplotmat fig_convplotmat fig_convplotmat fig_convplotmat

入力ファイルのサブセクション

File format

CrySPY uses the configparser module to read input file, cryspy.in . cryspy.in consists of sections, led by a [section] header and followed by name = value or name : value entries. Section names and values are case sensitive, but names are not. Lines beginning with # or ; are ignored and may be used to provide comments. Accepted bool values are 1, yes, true, and on, which cause this method to return True, and 0, no, false, and off, which cause it to return False. These string values for bool are checked in a case-insensitive manner. Some values are given in a space-separated manner.

情報

See configparser in detail.

メモ

section name: case sensitive
name: case insensitive
value: case sensitive except for bool

[basic] section

2025年3月6日 更新

NameValueDefaultDescription
algoRS, EA, EA-vc, BO, LAQAアルゴリズム
calc_codeVASP, QE, OMX, soiap, LAMMPS, ASE構造最適化の計算コード
tot_strucint構造数.EAやEA-vcの場合は使用されない.
nstageintステージ数
njobint同時に投入するジョブの数
jobcmdstrジョブを投入するコマンド,例えばqsubやsbatch
jobfilestrジョブファイルのファイル名

[structure] section

2025年3月6日 更新

NameValueDefaultDescription
struc_modecrystal, mol, mol_bscrystal構造生成モード
atypeatomic symbol [atomic symbol …]Atom type. e.g. atype = Na Cl. EA-vcでは使用されない.
natint [int …]atom typeに応じた原子数. e.g. nat = 8 8.
mindist (mindist_?)float [float …]None最小原子間距離の制限 [Å].
mindist_factorfloat1.0mindistのスケーリング係数
vol_factorfloat1.0体積スケーリング係数
vol_mufloatNone体積の平均.体積を指定したい場合に使用
vol_sigmafloatNone体積の標準偏差.体積を指定したい場合に使用
symprecfloat0.01対称性を見つける際の精度
spgnumall, space group number, 0all空間群の制限.allであれば1–230の全て.0であれば空間群情報のない(対称性のない)ランダム構造生成
use_find_wyboolFalsefind_wyを使用して構造生成する際のオプション

mindist


if algo is EA-vc

NameValueDefaultDescription
ll_natint [int …]natの下限. e.g. ll_nat = 0 0.
ul_natint [int …]natの上限. e.g. ul_nat = 8 8.

if struc_mode is mol or mol_bs

NameValueDefaultDescription
mol_filestr [str …]Path of molecule files or molecule names.
nmolint [int …]The number of molecules.
timeout_molfloatNoneTime out for molecular structure generation.
rot_molrandom, random_mol, random_wyckoffrandom_wyckoffOnly used in mol_bs. Mode for rotation of molecules.
nrotint20Only used in mol_bs. Maximum number of trials to rotate molecules.
mindist_mol_bs (mindist_mol_bs_?)float [float …]NoneOnly used in mol_bs. Constraint on minimum intermolecular distance [Å].
mindist_mol_bs_factorfloat1.0Only used in mol_bs. Scaling factor for mindist_mol_bs.

if use_find_wy is True or spgnum = 0

NameValueDefaultDescription
fwpathstrNoneOnly used with find_wy. Path of find_wy. If None, fwpath is automatically searched in your $PATH.
minlenfloatOnly used with find_wy or spgnum = 0. Minimum length of lattice vector [Å].
maxlenfloatOnly used with find_wy or spgnum = 0. Maximum length of lattice vector [Å].
danglefloatOnly used with find_wy or spgnum = 0. Delta angle for alpha, beta, and gamma in degree unit.
maxcntint50Only used with find_wy or spgnum = 0. Maximum number of trials to determine atom positions.

[VASP] section

VASPを使う場合は(calc_code = VASP)[VASP]セクションが必要になる.

NameValueDefaultDescription
kppvolint [int …]各ステージにおける逆格子空間でのÅ**(-3)あたりのグリッド密度.
force_gammaboolFalseTrueなら常にガンマ点を通るメッシュを使う.

kppvol and force gamma

[QE] section

[QE] section is required only if you use QE (calc_code = QE)

NameValueDefaultDescription
kppvolint [int …]Grid density per Å**(-3) of reciprocal cell in each stage
qe_infilestrFile name of QE input file.
qe_outfilestrFile name of QE output file.
pv_termboolFalseIf true, read enthalpy instead of total energy.

kppvol

pv_term

[OMX] section

[OMX] section is required only if you use OpenMX (calc_code = OMX)

NameValueDefaultDescription
kppvolint [int …]Grid density per Å**(-3) of reciprocal cell in each stage
OMX_infilestrFile name of OpenMX input file.
OMX_outfilestrFile name of OpenMX output file.
ValenceElectronsstr float float [str float float …]The number of initial charges for up and down spin states.

kppvol

ValenceElectrons

e.g. in NaCl: ValenceElectrons = Na 4.5 4.5 Cl 3.5 3.5.

[soaip] section

[soiap] section is required only if you use soiap (calc_code = soiap)

NameValueDefaultDescription
soiap_infilestrFile name of soiap input file.
soiap_outfilestrFile name of soiap output file.
soiap_cifstrFile name of soiap CIF-formatted initial structure.

[LAMMPS] section

[LAMMPS] section is required only if you use LAMMPS (calc_code = LAMMPS)

NameValueDefaultDescription
lammps_infilestrFile name of LAMMPS input file.
lammps_outfilestrFile name of LAMMPS output file.
lammps_potentialstr [str …], NoneNonePotential.
lammps_datastrFile name of LAMMPS data file.

[ASE] section

[ASE] section is required only if you use ASE (calc_code = ASE)

NameValueDefaultDescription
ase_pythonstrFile name of ASE input file.

[EA] section

2025年6月15日 更新

NameValueDefaultDescription
n_popintPopulation (see also Population size)
n_crsovintNumber of offspring created by crossover
n_permintNumber of offspring created by permutation
n_strainintNumber of offspring created by strain
n_randintNumber of structures created randomly
n_eliteintNumber of elite individuals (see also Natural selection)
fit_reverseboolFalseIf False, minimal search (see also Evaluate fitness)
n_fittestint0Number of individuals that remain natural selection. If set to 0, all individuals are retained.
slct_funcTNM, RLTFunction to select parents
t_sizeint3Tournament size. Used only used slct_func = TNM. (see also Tournament selection)
a_rltfloat10.0Parameter for linear scaling. Used only with slct_func = RLT. (see also Roulette selection)
b_rltfloat1.0Parameter for linear scaling. Used only with slct_func = RLT. (see also Roulette selection)
crs_latequal, randomrandomHow to mix lattice vectors (see also crossover > 5. Swap the sliced halves)
nat_diff_toleint4Tolerance for difference in the number of atoms in crossover. (see also crossover > 6. Select the offspring with more atoms)
ntimesint1Number of times in permutation.
sigma_stfloat0.5Standard deviation for strain.
maxcnt_eaint50Maximum number of trials in EA.
maxgen_eaint0Maximum generation. If set to 0, no upper limit is applied.
emax_eafloatNoneEnergy upper limit (eV/atom) for natural selection.
emin_eafloatNoneEnergy lower limit (eV/atom) for natural selection.

NameValueDefaultDescription
n_addintNumber of offspring created by addition.
n_elimintNumber of offspring created by elimination.
n_subsintNumber of offspring created by substitution.
targetstrrandomTarget. Only random for now.
end_point(float, …, float)Energy of end points for formation energy.
emax_eafloatNoneEnergy upper limit (eV/atom) for computing the convex hull.
emin_eafloatNoneEnergy lower limit (eV/atom) for computing the convex hull.
show_maxfloat0.2When plotting the convex hull, the maximum value of the y-axis (for binary systems) or the maximum hull distance (for ternary systems) is set by show_max.
lable_stableboolTrueWhether to show stable compositions when plotting the convex hull.
vmaxfloat0.2Maximum value of the colorbar representing hull distance.
bottom_marginfloat0.02Bottom margin of the y-axis for binary convex hull plot.
fig_formatstrsvgFigure format for convex hull plot: svg, png, or pdf.

[BO] section

2024 May 27th, updated

[BO] section is required only if you use BO (algo = BO)

NameValueDefaultDescription
nselect_bointThe number of structures to be selected at once.
scoreTS, EI, PIAcquisition function.
num_rand_basisint0If 0, Gaussian process. The number of basis function.
cdevfloat0.001Cutoff of deviation for standardization.
dscrptFPStructure descriptor.
max_select_boint0Maximum number of selection.
manual_select_boint [int …]NoneStructure IDs to be selected manually.
emax_bofloatNoneUpper limit of energy in BO.
emin_bofloatNoneLower limit of energy in BO.

if decrpt is FP

CrySPY 1.3.0 or later

fppath and fp_rmin are obsolete.

NameValueDefaultDescription
fp_rmaxfloat8.0Only used with dscrpt = FP. Maximum cutoff of r in fingerprint.
fp_npointsint20Only used with dscrpt = FP. Number of discretized points for each pair in fingerprint.
fp_sigmafloat0.7Only used with dscrpt = FP. Sigma parameter [Å] in Gaussian smearing function.

CrySPY 1.2.5 or earlyer

NameValueDefaultDescription
fppathstrNoneOnly used with dscrpt = FP. Path of cal_fingerprint. If None, fwpath is automatically searched in your $PATH.
fp_rminfloat0.5Only used with dscrpt = FP. Minimum cutoff of r in fingerprint.
fp_rmaxfloat5.0Only used with dscrpt = FP. Maximum cutoff of r in fingerprint.
fp_npointsint20Only used with dscrpt = FP. Number of discretized points for each pair in fingerprint.
fp_sigmafloat1.0Only used with dscrpt = FP. Sigma parameter [Å] in Gaussian smearing function.

[LAQA] section

LAQA (algo = LAQA)を使う場合,[LAQA]セクションが必要.

NameValueDefaultDescription
nselect_laqaint1度の選択で選ばれる構造の数.
wffloat0.1力の項の重み.
wsfloat10.0ストレス項の重み.
情報
情報

algo = LAQAでは[option]セクションの下記の二つは自動的にTrueになる.

  • force_step_flag = True
  • stress_step_flag = True

原子に働く力とストレスのデータは1ステップごとに収集される. エネルギーと構造データは1ステップごとではなく,選択ごとに収集される. つまり,この場合は10ステップおきにエネルギーと構造データは保存される. もし1ステップごとのデータが欲しいのであれば,手動で下記の設定を追加すること.

[option]
energy_step_flag = True
struc_step_flag = True

[option] section

NameValueDefaultDescription
check_mindist_optboolTrueIf True, a mindist constraint is checked after structure relaxation.
stop_chkptint0CrySPY stops at a specified check point.
load_struc_flagboolFalseIf True, load initial structures from ./data/pkl_data/init_struc_data.pkl.
stop_next_strucboolFalseIf True, CrySPY does not submit jobs for next structures, but jobs for next stage are submitted.
recalcint [int …](empty list)Specify structure IDs if you want to recalculate or continue optimization.
append_struc_eaboolFalseIf True, append structures by EA.
energy_step_flagboolFalseIf True, save energy_step_data in ./data/pkl_data/energy_step_data.pkl.
struc_step_flagboolFalseIf True, save struc_step_data in ./data/pkl_data/struc_step_data.pkl.
force_step_flagboolFalseIf True, save force_step_data in ./data/pkl_data/force_step_data.pkl.
stress_step_flagboolFalseIf True, save stress_step_data in ./data/pkl_data/stress_step_data.pkl.

Kpoint

2024年4月22日

CrySPYではk-pointのセッティングはpymatgenpymatgen.io.vasp.Kpoints.automatic_density_by_vol関数を使って自動生成している. 以下はcryspy.innstage = 2の場合の例:

[VASP]
kppvol = 40 120
  • stage 1: kppvol = 40
  • stage 2: kppvol = 120

kppvolは逆格子空間でのÅ ${}^{-3} $あたりのグリッド密度.
VASP:hexagonalとface-centeredセルではガンマ点を通るメッシュが使われ,それ以外ではMonkhorst-Packが使われる.
QE and OMX:kメッシュだけ利用,オフセットは設定しない.

kppvolの値はどれくらいが適切か?

下記を参考に.結晶構造の画像はVESTAを使用.

Primitive cell of diamond Si

fig_prim_diamond fig_prim_diamond

a = b = c = 3.836 Å

kppvolk-mesh
0[1, 1, 1]
20[4, 4, 4]
40[6, 6, 6]
60[7, 7, 7]
80[7, 7, 7]
100[8, 8, 8]
120[9, 9, 9]
140[9, 9, 9]
160[9, 9, 9]
180[10, 10, 10]
200[10, 10, 10]
400[13, 13, 13]
600[15, 15, 15]
800[17, 17, 17]

Conventional cell of diamond Si

fig_conv_diamond fig_conv_diamond

a = b = c = 5.431 Å

kppvolk-mesh
0[1, 1, 1]
20[3, 3, 3]
40[3, 3, 3]
60[4, 4, 4]
80[4, 4 ,4]
100[5, 5, 5]
120[5, 5, 5]
140[6, 6, 6]
160[6, 6, 6]
180[6, 6, 6]
200[6, 6, 6]
400[8, 8, 8]
600[9, 9, 9]
800[10, 10, 10]

Nd2Fe14B

fig_Nd2Fe12B fig_Nd2Fe12B

a = b = 8.804 Å
c = 12.205 Å

kppvolk-mesh
0[1, 1, 1]
20[1, 1, 1]
40[2, 2, 1]
60[2, 2, 2]
80[3, 3 ,2]
100[3, 3, 2]
120[3, 3, 2]
140[3, 3, 2]
160[3, 3, 2]
180[4, 4, 2]
200[4, 4, 3]
400[5, 5, 3]
600[6, 6, 4]
800[6, 6, 4]

データフォーマットのサブセクション

Common dataのサブセクション

Initial and optimized structure data

Initial and optimized structure data are saved in init_struc_data.pkl and opt_struc_data.pkl, respectively. pymatgen library is required to analyze these data files.

Data format

  • type: dict
    • key: structure ID
    • value: structure data
  • string form
    • {0: Structure Summary …,
      1: Structure Summary …,
      …}
  • structure data format

How to access

import pickle
with open('init_struc_data.pkl', 'rb') as f:
   init_struc_data = pickle.load(f)
with open('opt_struc_data.pkl', 'rb') as f:
   opt_struc_data = pickle.load(f)

# struc_step_data[ID]
#
#

# ---------- structure step data of ID 0
cid = 0      # ID
init_struc_data[cid]    # to show initial structure of ID 0
Structure Summary
Lattice
    abc : 5.727301 5.727301 4.405757
 angles : 90.0 90.0 90.0
 volume : 144.5175386563631
      A : 5.727301 0.0 0.0
      B : 0.0 5.727301 0.0
      C : 0.0 0.0 4.405757
PeriodicSite: Si (0.2506, 5.4767, 1.1014) [0.0438, 0.9562, 0.2500]
PeriodicSite: Si (2.6130, 3.1143, 1.1014) [0.4562, 0.5438, 0.2500]
PeriodicSite: Si (3.1143, 0.2506, 1.1014) [0.5438, 0.0438, 0.2500]
PeriodicSite: Si (5.4767, 2.6130, 1.1014) [0.9562, 0.4562, 0.2500]
PeriodicSite: Si (5.4767, 0.2506, 3.3043) [0.9562, 0.0438, 0.7500]
PeriodicSite: Si (3.1143, 2.6130, 3.3043) [0.5438, 0.4562, 0.7500]
PeriodicSite: Si (2.6130, 5.4767, 3.3043) [0.4562, 0.9562, 0.7500]
PeriodicSite: Si (0.2506, 3.1143, 3.3043) [0.0438, 0.5438, 0.7500]

Result data

Common result data such as space group, energies, etc. are saved in rslt_data.pkl. pandas library is required to analyze this data file.

Data format

  • type: pandas.core.frame.DataFrame
    • row lable: structure ID
  • string form
    • see blow

How to access

import pickle
with open('rslt_data.pkl', 'rb') as f:
   rslt_data = pickle.load(f)


# ---------- sort by Energy
# top 5
rslt_data.sort_values(by=['E_eV_atom']).head(5)
   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

Random Search (RS)

Table of contents

    Evolutionary algorithm (EA)

    Table of contents

      Bayesian Optimization (BO)

      Table of contents

        LAQA

        Table of contents

          オプションデータのサブセクション

          Energy step data

          Energy step data is saved in energy_step_data.pkl if you set energy_step_flag = True in [option] section of cryspy.in. NumPy library is required to analyze this data file.

          警告

          energy_step_flag = True is currently available only with VASP, QE, and soiap.

          情報

          In soiap, energy_step_data is collected only if loopa == 1. This is because other data (struc, force, and stress) are output only when loopa == 1. See, https://github.com/nbsato/soiap/blob/master/doc/instructions.md

          Data format

          • type: dict
            • key: structure ID
            • value: list of energy step data in each stage
          • string form
            • {0: [array([-3.4439912 , -3.55040935, -3.66697038, ..]), array([-4.0613393 , -4.05445631, -4.06159641, …]), …],
              1: [array([-2.68209823, -2.69012487, -2.68364907, ..]), array([-2.79140967, -2.79183827, -2.79206508, …]), …],
              …}
          • unit of energy
            • eV/atom

          How to access

          import pickle
          with open('energy_step_data.pkl', 'rb') as f:
              energy_step_data = pickle.load(f)
          
          # energy_step_data[ID][stage][step]
          # energy_step_data[ID][0] <-- stage 1
          # energy_step_data[ID][1] <-- stage 2
          #
          # in LAQA
          # energy_step_data[ID][selection][step]
          # energy_step_data[ID][0] <-- 1st selection
          # energy_step_data[ID][1] <-- 2nd selection
          
          # ---------- energy step data of ID 3, stage 1
          cid = 3      # ID
          stage = 1    # stage
          energy_step_data[cid][stage-1][:10]    # show only 10 enegies in jupyter
          
          array([-3.4439912 , -3.55040935, -3.66697038, -3.77192063, -3.84320717,
                 -3.80679245, -3.84633935, -3.87374706, -3.89123193, -3.90422926])
          

          Structure step data

          Structure step data is saved in struc_step_data.pkl if you set struc_step_flag = True in [option] section of cryspy.in. pymatgen library is required to analyze this data file.

          警告

          struc_step_flag = True is currently available only with VASP, QE, and soiap.

          情報

          struc_step_data includes initial structures. For example, struc_step_data[cid][0][0] is the initial structure of ID = cid.

          Data format

          • type: dict
            • key: structure ID
            • value: list of structure step data in each stage
          • string form
            • {0: [[Structure Summary …, Structure Summary, …], […], …],
              1: [[Structure Summary …, Structure Summary, …], […], …],
              …}
          • structure data format

          How to access

          import pickle
          with open('struc_step_data.pkl', 'rb') as f:
              struc_step_data = pickle.load(f)
          
          # struc_step_data[ID][stage][step]
          # struc_step_data[ID][0] <-- stage 1
          # struc_step_data[ID][1] <-- stage 2
          #
          #
          # in LAQA
          # struc_step_data[ID][selection][step]
          # struc_step_data[ID][0] <-- 1st selection
          # struc_step_data[ID][1] <-- 2nd selection
          
          # ---------- structure step data of ID 3, stage 1, step 4
          cid = 0      # ID
          stage = 1    # stage
          step = 0     # step index (start from 0)
          struc_step_data[cid][stage-1][step]    # to show initial structure of ID 0 at stage 1 in jupyter
          
          Structure Summary
          Lattice
              abc : 5.727301 5.727301 4.405757
           angles : 90.0 90.0 90.0
           volume : 144.5175386563631
                A : 5.727301 0.0 0.0
                B : 0.0 5.727301 0.0
                C : 0.0 0.0 4.405757
          PeriodicSite: Si (0.2506, 5.4767, 1.1014) [0.0438, 0.9562, 0.2500]
          PeriodicSite: Si (2.6130, 3.1143, 1.1014) [0.4562, 0.5438, 0.2500]
          PeriodicSite: Si (3.1143, 0.2506, 1.1014) [0.5438, 0.0438, 0.2500]
          PeriodicSite: Si (5.4767, 2.6130, 1.1014) [0.9562, 0.4562, 0.2500]
          PeriodicSite: Si (5.4767, 0.2506, 3.3043) [0.9562, 0.0438, 0.7500]
          PeriodicSite: Si (3.1143, 2.6130, 3.3043) [0.5438, 0.4562, 0.7500]
          PeriodicSite: Si (2.6130, 5.4767, 3.3043) [0.4562, 0.9562, 0.7500]
          PeriodicSite: Si (0.2506, 3.1143, 3.3043) [0.0438, 0.5438, 0.7500]
          

          Force step data

          Force step data is saved in force_step_data.pkl if you set force_step_flag = True in [option] section of cryspy.in. NumPy library is required to analyze this data file.

          警告

          force_step_flag = True is currently available only with VASP, QE, and soiap.

          Data format

          • type: dict
            • key: structure ID
            • value: list of force step data in each stage
          • string form
            • {0: [array([[ 0.26314927, -0.26314927, -0. ], […], …[…]]), array([[…], …, […]]), …],
              1: [array([[ 0. , 0. , 0. ], […], …[…]]), array([[…], …, […]]), …],
              …}
          • unit of force
            • eV/Å

          How to access

          import pickle
          with open('force_step_data.pkl', 'rb') as f:
              force_step_data = pickle.load(f)
          
          # force_step_data[ID][stage][step][atom]
          # force_step_data[ID][0] <-- stage 1
          # force_step_data[ID][1] <-- stage 2
          #
          # in LAQA
          # force_step_data[ID][selection][step][atom]
          # force_step_data[ID][0] <-- 1st selection
          # force_step_data[ID][1] <-- 2nd selection
          
          # ---------- force step data of ID 3, stage 1
          cid = 0      # ID
          stage = 1    # stage
          force_step_data[cid][stage-1][:3]    # to show only 3 steps in jupyter 
          
          [array([[ 0.26314927, -0.26314927, -0.        ],
                  [-0.26314927,  0.26314927, -0.        ],
                  [ 0.26314927,  0.26314927,  0.        ],
                  [-0.26314927, -0.26314927, -0.        ],
                  [-0.26314927,  0.26314927, -0.        ],
                  [ 0.26314927, -0.26314927,  0.        ],
                  [-0.26314927, -0.26314927, -0.        ],
                  [ 0.26314927,  0.26314927,  0.        ]]),
           array([[-0.12103692,  0.12103692,  0.        ],
                  [ 0.12103692, -0.12103692, -0.        ],
                  [-0.12103692, -0.12103692, -0.        ],
                  [ 0.12103692,  0.12103692,  0.        ],
                  [ 0.12103692, -0.12103692, -0.        ],
                  [-0.12103692,  0.12103692,  0.        ],
                  [ 0.12103692,  0.12103692,  0.        ],
                  [-0.12103692, -0.12103692, -0.        ]]),
           array([[-0.29801618,  0.29801618,  0.        ],
                  [ 0.29801618, -0.29801618, -0.        ],
                  [-0.29801618, -0.29801618, -0.        ],
                  [ 0.29801618,  0.29801618,  0.        ],
                  [ 0.29801618, -0.29801618, -0.        ],
                  [-0.29801618,  0.29801618,  0.        ],
                  [ 0.29801618,  0.29801618,  0.        ],
                  [-0.29801618, -0.29801618, -0.        ]])]
          
          step = 0     # step index (start from 0)
          atom = 2     # atom index (start from 0)
          force_step_data[cid][stage-1][step][atom]
          
          array([0.26314927, 0.26314927, 0.        ])
          

          Stress step data

          Stress step data is saved in stress_step_data.pkl if you set stress_step_flag = True in [option] section of cryspy.in. NumPy library is required to analyze this data file.

          警告

          stress_step_flag = True is currently available only with VASP, QE, and soiap.

          Data format

          • type: dict
            • key: structure ID
            • value: list of stress step data in each stage
          • string form
            • {0: [array([[-0.16770062, 0. , 0. ], […], […]]), array([[…], ]…], […]]), …],
              1: [array([[ 0.39260083, -0. , -0. ], […], […]]), array([[…], […], […]]), …],
              …}
          • unit of stress
            • eV/(Å**3)

          How to access

          import pickle
          with open('stress_step_data.pkl', 'rb') as f:
              stress_step_data = pickle.load(f)
          
          # stress_step_data[ID][stage][step][atom]
          # stress_step_data[ID][0] <-- stage 1
          # stress_step_data[ID][1] <-- stage 2
          #
          # in LAQA
          # stress_step_data[ID][selection][step][atom]
          # stress_step_data[ID][0] <-- 1st selection
          # stress_step_data[ID][1] <-- 2nd selection
          
          # ---------- stress step data of ID 3, stage 1
          cid = 0      # ID
          stage = 1    # stage
          stress_step_data[cid][stage-1][:3]    # to show only 3 steps in jupyter 
          
          [array([[-0.16770062,  0.        ,  0.        ],
                  [ 0.        , -0.16770062, -0.        ],
                  [ 0.        ,  0.        ,  0.21823358]]),
           array([[-0.16020785, -0.        , -0.        ],
                  [-0.        , -0.16020785,  0.        ],
                  [-0.        ,  0.        ,  0.18646321]]),
           array([[-0.13572003, -0.        ,  0.        ],
                  [-0.        , -0.13572003,  0.        ],
                  [-0.        ,  0.        ,  0.15953926]])]
          

          CrySPY utilityのサブセクション

          repeat_cryspy

          リンク: CrySPY_utility/script/repeat_cryspy

          cryspyを何度も手動で実行するのが面倒な時は,自動化スクリプトが利用できる.
          この自動化スクリプトはデフォルトで5分に1回cryspyを実行する. インターバルの時間はスクリプトの下記の部分を編集することで調整できます.

              sleep 300    # seconds
          

          使い方

          1. repeat_cryspyを作業ディレクトリにコピー
          2. (optional) インターバルの時間を変更
          3. repeat_cryspyを実行

          ログアウトしてもジョブを実行し続けるためには,nohupコマンドを使う.

          [bash]

          nohup ./repeat_cryspy &
          

          [zsh]

          nohup ./repeat_cryspy &!
          

          extract_struc.py

          2023 April 16 update

          Link: CrySPY_utility/script/extract_struc.py

          init_struc_data.pklopt_struc_data.pklから構造ごとにcifファイルを出力するスクリプト. ファイル出力せず,構造情報を画面にプリントすることも可能.

          -iオプションでインデックス(構造ID)を(複数)指定できる. -tオプションでエネルギーが低い順番に指定した構造数のcifファイルを出力可能. -aオプションの場合は全ての構造をcifファイルに出力する.数が多い場合はディレクトリを作成してそこに移動してから実行したほうが良い. -sオプションをつけると対称性(空間群)の情報を付けられる.ただし,セルや原子数が変わるので注意. 対称性の情をつける際,--toleranceオプションでtoleranceを変えられる(デフォルトは0.01). -pオプションをつけるとファイル出力せずに,画面にプリントする. gzipしたファイルもそのまま読み込み可能(e.g., opt_struc_data.pkl.gz).

          更新履歴

          • 2024 April 16: –tolerance option, gzip
          • 2023 July 21: –print option

          使い方

          python3 extract_struc.py -h
          

          このスクリプトをPATHが通ったところにおけばpython3を省略できる

          extract_struc.py -h
          
          usage: extract_struc.py [-h] [-p] [-a] [-i [INDEX ...]] [-t TOP] [-r] [-s] [--tolerance TOLERANCE] infile
          
          positional arguments:
            infile                input file
          
          options:
            -h, --help            show this help message and exit
            -p, --print           just print, e.g., extract_struc.py opt_struc_data.pkl -i 7 10 12 -ps
            -a, --all_id          all structures, e.g., extract_struc.py opt_struc_data.pkl -as
            -i [INDEX ...], --index [INDEX ...]
                                  structure ID, e.g., extract_struc.py opt_struc_data.pkl -i 7 10 12 -s
            -t TOP, --top TOP     top k structures, e.g. (k = 3), extract_struc.py opt_struc_data.pkl -t 3 -s
            -r, --rank            add rank in file names, e.g., extract_struc.py opt_struc_data.pkl -t 3 -rs
            -s, --symmetrized     symmetrized structure, e.g., extract_struc.py opt_struc_data.pkl -i 7 10 12 -s
            --tolerance TOLERANCE
                                  tolerance for symmetrization (default 0.01), e.g., extract_struc.py opt_struc_data.pkl -i 0 1 -s --tolerance 0.01
          

          プリント

          -pオプションは-s以外のオプションと組み合わせて使用することができる.

          extract_struc.py -p opt_struc_data.pkl -i 0 1
          
          ID 0
          Full Formula (Na8 Cl8)
          Reduced Formula: NaCl
          abc   :   6.823618   6.823618   7.566454
          angles:  90.000000  90.000000  96.650518
          pbc   :       True       True       True
          Sites (16)
            #  SP           a         b         c
          ---  ----  --------  --------  --------
            0  Na    0         0         1
            1  Na    0         0         0.5
            2  Na    0.704707  0.295293  0.75
            3  Na    0.295293  0.704707  0.25
            4  Na    0.5       0         1
            5  Na    0.5       0         0.5
            6  Na    0         0.5       0.5
            7  Na    0         0.5       0
            8  Cl    0.5       0.5       0
            9  Cl    0.5       0.5       0.5
           10  Cl    0.484753  0.515247  0.75
           11  Cl    0.515247  0.484753  0.25
           12  Cl    0.828247  0.171753  0.851096
           13  Cl    0.171753  0.828247  0.351096
           14  Cl    0.828247  0.171753  0.648904
           15  Cl    0.171753  0.828247  0.148904
          
          ID 1
          Full Formula (Na8 Cl8)
          Reduced Formula: NaCl
          abc   :   8.145021   8.145021   4.324235
          angles:  90.000000  90.000000 120.000000
          pbc   :       True       True       True
          Sites (16)
            #  SP            a          b         c
          ---  ----  ---------  ---------  --------
            0  Na     0.666667   0.333333  0.736206
            1  Na     0.666667   0.333333  0.263794
            2  Na     0.913147   0.086853  0.5
            3  Na     0.913147   0.826295  0.5
            4  Na     0.173705   0.086853  0.5
            5  Na     0.77711    0.22289   0
            6  Na     0.77711    0.55422   0
            7  Na     0.44578    0.22289   0
            8  Cl     0.027675   0.423376  0.5
            9  Cl    -0.423376  -0.395701  0.5
           10  Cl     0.395701  -0.027675  0.5
           11  Cl    -0.423376  -0.027675  0.5
           12  Cl     0.395701   0.423376  0.5
           13  Cl     0.027675  -0.395701  0.5
           14  Cl     0.333333   0.666667  0.5
           15  Cl     0          0         0
          

          構造ID

          extract_struc.py opt_struc_data.pkl -i 7 10 12
          

          以下のファイルが出力される.

          7.cif10.cif12.cif

          対称性の情報ありの場合は-sオプションをつける.

          extract_struc.py opt_struc_data.pkl -i 7 10 12 -s
          

          2024 April 16
          toleranceパラメーター(デフォルトは0.01)を指定する場合

          extract_struc.py opt_struc_data.pkl -i 7 10 12 -s --tolerance 0.01
          

          Top k 構造

          情報

          rslt_data.pkl がインプット(init_struc_data.pklopt_struc_data.pkl)と同じディレクトリに必要.

          ここでは以下のようにファイルが存在して,

          • ./data/pkl_data/opt_struc_data.pkl
          • ./data/pkl_data/rslt_data.pkl

          cryspy_rslt_energy_ascの中身が下記のものを仮定すると

              Spg_num     Spg_sym  Spg_num_opt Spg_sym_opt    E_eV_atom  Magmom      Opt
          9       110      I4_1cd          110      I4_1cd -1284.708037     NaN  not_yet
          16        4        P2_1            4        P2_1 -1284.693651     NaN     done
          97       92    P4_12_12           91      P4_122 -1284.692494     NaN     done
          8        57        Pbcm           57        Pbcm -1284.668504     NaN     done
          81       19  P2_12_12_1           19  P2_12_12_1 -1284.635684     NaN     done
          ...
          

          トップk (ここではk=3) の構造は下記コマンドで出力できる.

          extract_struc.py ./data/pkl_data/opt_struc_data.pkl -t 3
          

          ここではrlst_data.pkl./data/pkl_data/の中に存在しなければならない. 9.cif, 16.cif, 97.cifというファイルが出力される.

          -rオプションを使うと,ファイル名に順位を含めることができる.

          extract_struc.py ./data/pkl_data/opt_struc_data.pkl -t 3 -r
          

          ファイル名は1_9.cif, 2_16.cif, 3_97.cifのようになる.

          対称化されたcifの場合は下記のようにする.

          extract_struc.py ./data/pkl_data/opt_struc_data.pkl -t 3 -rs
          

          全構造

          構造が多い場合はディレクトリを先に作った方が良い.

          mkdir init_cifs
          cd init_cifs
          extract_struc.py /path/to/opt_struc_data.pkl -a
          

          対称化する場合,

          extract_struc.py /path/to/init_struc_data.pkl -as
          

          gzipファイル

          2024 April 16
          gzipされたファイル(拡張子が.gz)も読み込み可能:

          extract_struc.py opt_struc_data.pkl.gz -i 0 1 -s
          

          print_pkl.py

          2024 May 31

          data/pkl_data/にあるピクル化されたファイルをさっとチェックしたい時にprint_pkl.pyを使うと便利.

          Usage

          python3 print_pkl.py xxxx.pkl
          

          PATHが通っているところにこのpythonスクリプトを置いているならpython3は省略可能.

          print_pkl.py xxxx.pkl
          

          Example

          print_pkl.py init_struc_data.pkl
          
          Number of structures: 10
          dict_keys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
          
          print_pkl.py input_data.pkl 
          
          [basic]
          algo = RS
          calc_code = ASE
          tot_struc = 10
          nstage = 1
          njob = 5
          jobcmd = zsh
          jobfile = job_cryspy
          
          [structure]
          struc_mode = crystal
          natot = 8
          atype = ('Cu', 'Au')
          nat = (4, 4)
          mindist_factor = 1.0
          vol_factor = 1.1
          symprec = 0.01
          spgnum = all
          use_find_wy = False
          
          [option]
          stop_chkpt = 0
          load_struc_flag = False
          stop_next_struc = False
          append_struc_ea = False
          energy_step_flag = False
          struc_step_flag = False
          force_step_flag = False
          stress_step_flag = False
          
          [ASE]
          kpt_flag = False
          force_gamma = False
          ase_python = ase_in.py
          
          print_pkl.py elite_struc.pkl
          
          Number of structures: 2
          dict_keys([3, 6])
          
          print_pkl.py elite_fitness.pkl
          
          {3: -325.79973412221455, 6: -324.8381948581405}
          

          pos2pkl.py

          2023年7月23日更新

          あらかじめ用意した構造のテキストデータをinit_struc_data.pklに変換するスクリプト. 入力のデフォルトはinit_POSCARS形式.オプションでPOSCARやcifファイルなどのシングル構造データも変換可能. 出力はinit_struc_data.pkl. すでに存在するinit_struc_data.pklに構造データを追加することもできる. 構造IDは考慮されず,新しく割り振られる. 原子数が異なる場合はエラーが出る.

          init_struc_data.pklはCrySPYでシミュレーション開始時にロードすることが可能.

          -fオプションで原子種の削除とソートが可能.このオプションを指定しないとpymatgenが勝手に電気陰性度の順番で並び替えるので注意!

          使い方

          usage: pos2pkl.py [-h] [-s [SINGLE ...]] [-f [FILTER ...]] [-p] [infile ...]
          
          positional arguments:
            infile                input file: init_POSCARS
          
          options:
            -h, --help            show this help message and exit
            -s [SINGLE ...], --single [SINGLE ...]
                                  input file: single structure file (POSCAR, cif)
            -f [FILTER ...], --filter [FILTER ...]
                                  filter (sort): remove species and sort
            -p, --permit_diff_comp
                                  flag for permitting different composition
          

          init_POSCARS –> init_struc_data.pkl

          CrySPYで構造生成後に出力されるinit_POSCARSをスパコン等の別のマシンに移すような場合に使える.複数のファイルを変換可能.

          python3 pos2pkl.py init_POSCARS
          

          pos2pkl.pyをPATHが通ったところにおけば,python3は省略可能.

          pos2pkl.py init_POSCARS
          
          Composition: Na8 Cl8
          
          Converted. The number of structures: 4
          Save init_struc_data.pkl
          

          複数の入力ファイルの場合.

          python3 pos2pkl.py init_POSCARS init_POSCARS2 init_POSCARS3
          
          Composition: Na8 Cl8
          
          Converted. The number of structures: 12
          Save init_struc_data.pkl
          

          カレントディレクトリにすでにinit_struc_data.pklが存在し,それに追加する場合.

          python3 pos2pkl.py init_POSCARS
          
          init_struc_data.pkl already exists.
          Append to init_struc_data.pkl? [y/n]: y
          
          Load init_struc_data
          Composition: Na8 Cl8
          The number of structures: 12
          
          Converted. The number of structures: 16
          Save init_struc_data.pkl
          

          POSCAR or cif –> init_struc_data.pkl

          POSCARファイルやcifファイル等の構造が一つだけのデータも変換可能.-s/--singleオプションが必要.

          python3 pos2pkl.py -s POSCAR test.cif
          
          Composition: Na8 Cl8
          
          Converted. The number of structures: 2
          Save init_struc_data.pkl
          

          init_POSCARS, POSCAR –> init_struc_data.pkl

          python3 pos2pkl.py init_POSCARS -s POSCAR
          
          Composition: Na8 Cl8
          
          Converted. The number of structures: 5
          Save init_struc_data.pkl
          
          警告

          下記は間違い.init_POSCARSもシングル構造として取り扱われてしまう.

          python3 pos2pkl.py -s POSCAR init_POSCARS
          

          Filter (remove and sort)

          次のような組成のcifファイルを考える:Sr8 Co8 O20 X4.これはダミー原子(X4)を4原子含んでいる. -f/--filterオプションは原子種を削除したり,ソートするのに使える. cryspy.inatypeと同じように指定する.

          python3 pos2pkl.py -s Sr8Co8O20X4.cif -f Sr Co O
          
          Removed species: {'X0+'}
          Composition: Sr8 Co8 O20
          
          Converted. The number of structures: 1
          Save init_struc_data.pkl
          

          extract_struc.pyを使えば, init_struc_data.pklにどのように登録されたのか確認できる.

          python3 extract_struc.py init_struc_data.pkl -pa
          
          ID 0
          Full Formula (Sr8 Co8 O20)
          Reduced Formula: Sr2Co2O5
          ...
          

          -fオプションでソートもできる.

          python3 pos2pkl.py -s Sr8Co8O20X4.cif -f O Co 
          
          Removed species: {'Sr', 'X0+'}
          Composition: O20 Co8
          
          Converted. The number of structures: 1
          Save init_struc_data.pkl
          

          kpt_check.py

          kpt_check.pykppvolを入力した際にkメッシュがどれくらいになるかをチェックすることができる. POSCARCONTCAR,およびinit_struc_data.pklが読み込み可能. pymatgenライブラリが必要.

          初期構造を生成後に,kppvolの値をどれくらいにしたら良いか色々試すことができる.(下記の最後の例を参照)

          使い方

          python3 kpt_check.py -h
          

          このスクリプトをPATHが通ったところにおけばpython3を省略できる

          kpt_check.py -h
          
          usage: kpt_check.py [-h] [-w] [-n NSTRUC] infile kppvol
          
          positional arguments:
            infile                input file: POSCAR, CONTCAR, or init_struc_data.pkl
            kppvol                kppvol
          
          options:
            -h, --help            show this help message and exit
            -w, --write           write KPOINTS
            -n NSTRUC, --nstruc NSTRUC
                                  number of structure to check
          

          POSCARとkppvol

          kpt_check.py POSCAR 100
          
          a = 10.689217
          b = 10.689217
          c = 10.730846
              Lattice vector
          10.689217 0.000000 0.000000
          0.000000 10.689217 0.000000
          0.000000 0.000000 10.730846
          
          kppvol:  100
          k-points:  [2, 2, 2]
          

          KPOINTSファイルの生成

          POSCARおよびCONTCARを入力とする際は,-wオプションを使用することでKPOINTSファイルを生成できる.

          kpt_check.py -w POSCAR 100
          
          $ cat KPOINTS
          pymatgen 4.7.6+ generated KPOINTS with grid density = 607 / atom
          0
          Monkhorst
          2 2 2
          

          init_struc_data.pklとkppvol

          init_struc_data.pklの初期構造データに任意のkppvolの値を適用した場合のkメッシュを調べることが可能. デフォルト設定でははじめの5構造をチェックする. -nを使うとチェックする構造数も変えられる.

          kpt_check.py -n 3 init_struc_data.pkl 100
          
          # ---------- 0th structure
          a = 8.0343076893
          b = 8.03430768936
          c = 9.1723323373
              Lattice vector
          8.034308 0.000000 0.000000
          -4.017154 6.957915 0.000000
          0.000000 0.000000 9.172332
          
          kppvol:  100
          k-points:  [3, 3, 3]
          
          
          # ---------- 1th structure
          a = 9.8451944096
          b = 9.84519440959
          c = 6.8764313585
              Lattice vector
          9.845194 0.000000 0.000000
          -4.922597 8.526188 0.000000
          0.000000 0.000000 6.876431
          
          kppvol:  100
          k-points:  [3, 3, 4]
          
          
          # ---------- 2th structure
          a = 7.5760383679
          b = 7.57603836797
          c = 6.6507478296
              Lattice vector
          7.576038 0.000000 0.000000
          -3.788019 6.561042 0.000000
          0.000000 0.000000 6.650748
          
          kppvol:  100
          k-points:  [4, 4, 4]
          

          FAQのサブセクション

          シミュレーションの途中でnjobを変えることはできますか?

          2024年5月7日

          シミュレーションの途中でnjobを変えることはできますか?

          いつでも変えられます.

          下記はnjobを減らした時の例です.

          警告

          CriSPYのバージョンが1.2.3以下ではバグがあるので,njobを減らすのは避けること.

          今,njob = 4でID 0, 1, 2, 3のジョブが流れているところで,njobを4から2に変更したとする.

          $ cryspy
          [2024-04-28 18:27:41,847][cryspy_restart][INFO] 
          
          
          Restart CrySPY 1.2.4
          
          
          [2024-04-28 18:27:41,848][read_input][INFO] Changed njob from 4 to 2
          [2024-04-28 18:27:42,335][ctrl_job][INFO] # ---------- job status
          [2024-04-28 18:27:42,335][ctrl_job][INFO] ID      0: still queueing or running
          [2024-04-28 18:27:42,335][ctrl_job][INFO] ID      1: still queueing or running
          

          njobを2に減らしたので,ID 0, 1だけチェックして,ID 2, 3は無視.

          $ cryspy
          [2024-04-28 18:29:25,250][cryspy_restart][INFO] 
          
          
          Restart CrySPY 1.2.4
          
          
          [2024-04-28 18:29:25,744][ctrl_job][INFO] # ---------- job status
          [2024-04-28 18:29:25,744][ctrl_job][INFO] ID      0: Stage 1 Done!
          [2024-04-28 18:29:25,757][ctrl_job][INFO]     submitted job, ID      0 Stage 2
          [2024-04-28 18:29:25,758][ctrl_job][INFO] ID      1: Stage 1 Done!
          [2024-04-28 18:29:25,767][ctrl_job][INFO]     submitted job, ID      1 Stage 2
          

          ID 1, 2のジョブが終わったので,次の2つのジョブ(ID 2, 3)をチェックしに行く.

          $ cryspy
          [2024-04-28 18:31:30,830][cryspy_restart][INFO]
          
          
          Restart CrySPY 1.2.4
          
          
          [2024-04-28 18:31:31,329][ctrl_job][INFO] # ---------- job status
          [2024-04-28 18:31:31,329][ctrl_job][INFO] ID      0: Stage 2 Done!
          [2024-04-28 18:31:31,329][collect_vasp][WARNING]     Structure ID 0, could not obtain energy from OSZICAR
          [2024-04-28 18:31:31,333][ctrl_job][INFO]     collect results: E = nan eV/atom
          [2024-04-28 18:31:31,341][ctrl_job][INFO] ID      1: Stage 2 Done!
          [2024-04-28 18:31:31,341][collect_vasp][WARNING]     Structure ID 1, could not obtain energy from OSZICAR
          [2024-04-28 18:31:31,342][ctrl_job][INFO]     collect results: E = nan eV/atom
          [2024-04-28 18:31:31,347][cryspy][INFO] 
          
          recheck 1
          
          [2024-04-28 18:31:31,347][ctrl_job][INFO] # ---------- job status
          [2024-04-28 18:31:31,347][ctrl_job][INFO] ID      2: Stage 1 Done!
          [2024-04-28 18:31:31,358][ctrl_job][INFO]     submitted job, ID      2 Stage 2
          [2024-04-28 18:31:31,358][ctrl_job][INFO] ID      3: Stage 1 Done!
          [2024-04-28 18:31:31,368][ctrl_job][INFO]     submitted job, ID      3 Stage 2
          

          PNG (transparent background)

          logo_png1 logo_png1

          logo_png2 logo_png2

          logo_png3 logo_png3

          logo_png4 logo_png4

          JPG

          logo_jpg1 logo_jpg1

          logo_jpg2 logo_jpg2

          logo_jpg3 logo_jpg3

          logo_jpg4 logo_jpg4