CrySPY Utilityのサブセクション

Examplesのサブセクション

ase_chgnet_Sr4Co4O12

Download

ase_chgnet_RS_Sr4Co4O12.tar.gz

cryspy.in

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

[structure]
natot = 20
atype = Sr Co O
nat = 4  4  12
mindist_1 = 2.2  2.0  1.8
mindist_2 = 2.0  2.2  1.5
mindist_3 = 1.8  1.5  2.0

[ASE]
ase_python = chgnet_in.py

[option]

calc_in/

chgnet_in.py_1

from chgnet.model import StructOptimizer
from pymatgen.core import Structure


# ---------- input structure
# CrySPY outputs 'POSCAR' as an input file in work/xxxxxx directory
structure = Structure.from_file('POSCAR')

# ---------- relax
relaxer = StructOptimizer()
result = relaxer.relax(atoms=structure, 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
# ------ energy
traj = result['trajectory']
e = traj.compute_energy()   # eV/cell
with open('log.tote', mode='w') as f:
    f.write(str(e))
# ------ struc
opt_struc = result["final_structure"]
opt_struc.to(fmt='poscar', filename='CONTCAR')

job_cryspy

#!/bin/sh

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

# ---------- for error
if [ ! -f "log.tote" ]; then
    sed -i -e '3 s/^.*$/skip/' stat_job
    exit 1
fi

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

ase_Cu8_RS

Download

ase_Cu8_RS.tar.gz

cryspy.in

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

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

[ASE]
ase_python = ase_in.py

[option]

calc_in/

ase_in.py_1

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

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

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

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

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

job_cryspy

#!/bin/sh

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

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

soiap_Si8_RS

Download

soiap_Si8_RS.tar.gz

cryspy.in

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

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

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

[option]

calc_in/

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 1000 ! 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

job_cryspy

#!/bin/sh

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

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

soiap_Si8_RS_mindist

Download

soiap_Si8_RS_mindist.tar.gz

cryspy.in

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

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

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

[option]

calc_in/

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 1000 ! 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

job_cryspy

#!/bin/sh

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

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

vasp_Na8Cl8_RS

Download

vasp_Na8Cl8_RS.tar.gz

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]

calc_in/

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

job_cryspy

#!/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

vasp_Sr4O4_RS_pv_term

Download

vasp_Sr4O4_RS_pv_term.tar.gz

cryspy.in

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

[structure]
natot = 8
atype = Sr O
nat = 4 4

[VASP]
kppvol = 40 80

[option]

calc_in/

INCAR_1

SYSTEM = SrO
Algo = Fast
NSW = 60

LWAVE = .FALSE.
!LCHARG = .FALSE.

ISPIN =  1

ISMEAR = 0
SIGMA = 0.1

IBRION = 2
ISIF = 2

EDIFF = 1e-5
EDIFFG = -0.01

PSTRESS = 400

INCAR_2

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

ENCUT = 520

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


ISPIN =  1

ISMEAR = 0
SIGMA = 0.1

IBRION = 2
ISIF = 3

EDIFF = 1e-5
EDIFFG = -0.01

PSTRESS = 400

job_cryspy

#!/bin/sh
#$ -cwd
#$ -V -S /bin/bash
####$ -V -S /bin/zsh
#$ -N SrO_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

qe_Si8_RS

Download

qe_Si8_RS.tar.gz

cryspy.in

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

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

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

[option]

calc_in/

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

job_cryspy

#!/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

qe_benzene_2_RS_mol

Download

qe_benzene_2_RS_mol.tar.gz

cryspy.in

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

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

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

[option]

calc_in/

pwscf.in_1

 &control
    title = '2 benzene'
    calculation = 'relax'
    nstep = 30
    restart_mode = 'from_scratch',
    pseudo_dir = '/usr/local/pslibrary.1.0.0/pbe/PSEUDOPOTENTIALS/'
    outdir='./outdir/'
 /

 &system
    ibrav = 0
    nat = 24
    ntyp = 2
    ecutwfc = 35.00
    ecutrho = 300.00
    occupations = 'smearing'
    degauss = 0.01
 /

 &electrons
 /

 &ions
 /

 &cell
 /

ATOMIC_SPECIES
   H  1.008  H.pbe-kjpaw_psl.1.0.0.UPF
   C  12.01  C.pbe-n-kjpaw_psl.1.0.0.UPF

pwscf.in_2

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

 &system
    ibrav = 0
    nat = 24
    ntyp = 2
    ecutwfc = 46.00
    ecutrho = 326.00
    occupations = 'smearing'
    degauss = 0.01
 /

 &electrons
 /

 &ions
 /

 &cell
 /

ATOMIC_SPECIES
   H  1.008  H.pbe-kjpaw_psl.1.0.0.UPF
   C  12.01  C.pbe-n-kjpaw_psl.1.0.0.UPF

job_cryspy

#!/bin/sh
#$ -cwd
#$ -V -S /bin/bash
####$ -V -S /bin/zsh
#$ -N bz_CrySPY_ID
#$ -pe smp 20

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

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

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

qe_Sr4O4_RS_pv_term

Download

qe_Sr4O4_RS_pv_term.tar.gz

cryspy.in

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

[structure]
natot = 8
atype = Sr O
nat = 4 4

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

[option]

calc_in/

pwscf.in_1

 &control
    title = 'SrO'
    calculation = 'relax'
    nstep = 100
    restart_mode = 'from_scratch',
    pseudo_dir = '/usr/local/gbrv/all_pbe_UPF_v1.5/'
    outdir='./out.d/'
 /

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

 &electrons
 /

 &ions
 /

 &cell
    press = 400
 /

ATOMIC_SPECIES
  Sr  -1.0  sr_pbe_v1.uspp.F.UPF
   O  -1.0  o_pbe_v1.2.uspp.F.UPF

pwscf.in_2

 &control
    title = 'SrO'
    calculation = 'vc-relax'
    nstep = 200
    restart_mode = 'from_scratch',
    pseudo_dir = '/usr/local/gbrv/all_pbe_UPF_v1.5/'
    outdir='./out.d/'
 /

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

 &electrons
 /

 &ions
 /

 &cell
    press = 400
 /

ATOMIC_SPECIES
  Sr  -1.0  sr_pbe_v1.uspp.F.UPF
   O  -1.0  o_pbe_v1.2.uspp.F.UPF

job_cryspy

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

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

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

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

qe_Si16_LAQA

Download

qe_Si16_LAQA.tar.gz

cryspy.in

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

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

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

[LAQA]
nselect_laqa = 4

[option]

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

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

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

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

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

Scriptsのサブセクション

extract_struc.py

2023 April 16 update

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

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]

repeat_cryspy

cryspyを何度も実行するのが面倒な時は,下記の自動スクリプトが便利. これは5分間に1回cryspyを実行する例.

#!/bin/bash

set -e

while :
do
    cryspy -n
    LOG_LASTLINE=`tail -n 1 log_cryspy`
    if  [ "$LOG_LASTLINE" = "Done all structures!" ]
    then
        exit 0
    # ---------- for EA
    elif [ "${LOG_LASTLINE:0:17}" = "Reached maxgen_ea" ]
    then
        exit 0
    elif [ "$LOG_LASTLINE" = "EA is ready" ]
    then
        cryspy -n    # EA
        LOG_LASTLINE=`tail -n 1 log_cryspy`
        if [ "${LOG_LASTLINE:0:17}" = "Reached maxgen_ea" ]
        then
            exit 0
        fi
        cryspy -n    # submit jobs
    # ---------- for BO
    elif [ "${LOG_LASTLINE:0:21}" = "Reached max_select_bo" ]
    then
        exit 0
    elif [ "$LOG_LASTLINE" = "BO is ready" ]
    then
        cryspy -n    # selection
        LOG_LASTLINE=`tail -n 1 log_cryspy`
        if [ "${LOG_LASTLINE:0:21}" = "Reached max_select_bo" ]
        then
            exit 0
        fi
        cryspy -n    # submit jobs
    # ---------- for LAQA
    elif [ "$LOG_LASTLINE" = "LAQA is ready" ]
    then
        cryspy -n    # selection
        cryspy -n    # submit jobs
    fi
    sleep 300    # seconds
done