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は省略可能.
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.inのatypeと同じように指定する.
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