0
0

CIF, POSCAR, structure, atomsのファイル変換まとめ

Last updated at Posted at 2024-04-16

第一原理計算などを行う際にpythonを使って結晶構造ファイルの処理をする必要があるのだが、結晶構造のファイル形式には以下の4種類がある。

  • CIF:Crystallographic Information File。ICSDなどでもこの形式
  • POSCAR:VASPに入力する際のファイル形式(.vasp)
  • structure:pythonライブラリであるpymatgenの形式
  • atoms:pythonライブラリであるASEの形式

計算したい内容などによってpymatgenやASEを使い分けたり、場合によっては両方使ったりする。その度にいちいち変換の仕方を調べているのでまとめる。

1. atomsとPOSCARの変換

atoms ⇒ POSCAR

ase.io.writeを使う。

from ase.io import write
write('POSCAR.vasp', images=atoms, format='vasp', direct=True, vasp5=True, sort=False)

POSCAR ⇒ atoms

from ase.io import read
atoms = read('POSCAR.vasp', format="vasp")

詳しくはこちらを参照。
https://wiki.fysik.dtu.dk/ase/ase/io/formatoptions.html#vasp

2. atomsとstructureの変換

どちらの変換もpymatgen.io.ase.AseAtomsAdaptorを使う。
https://pymatgen.org/pymatgen.io.ase.html

atoms ⇒ structure

from pymatgen.io.ase import AseAtomsAdaptor
structure = AseAtomsAdaptor.get_structure(atoms)

structure ⇒ atoms

from pymatgen.io.ase import AseAtomsAdaptor
atoms = AseAtomsAdaptor.get_atoms(structure)

3. CIFとstructureの変換

pymatgenのStructureを使う。すごい簡単。

CIF ⇒ strucutre

from pymatgen.core.structure import Structure
structure = Structure.from_file("./xxx.cif")

strucutre ⇒ CIF

structure.to(filename="xxx.cif")

4. POSCARとstructureの変換

pymatgenのPoscarを使う。

POSCAR ⇒ strucutre

from pymatgen.io.vasp import Poscar
poscar = Poscar.from_file('POSCAR.vasp')
structure = poscar.structure

strucutre ⇒ POSCAR

from pymatgen.io.vasp import Poscar
poscar = Poscar(structure)
poscar.write_file(filename="POSCAR.vasp",significant_figures=16)

5. CIFとPOSCARの変換

VESTAを使ってもよいが、python上で変換する場合は以下の通り。
他にも良い方法がありそう・・・。

POSCAR ⇒ CIF

from pymatgen.io.vasp import Poscar
from pymatgen.io.cif import CifWriter
p = Poscar.from_file('POSCAR')
w = CifWriter(p.structure)
w.write_file('xxx.cif')

CIF ⇒ POSCAR

parser = CifParser('xxx.cif')
struct = parser.get_structures(primitive=primitive)[0]
poscar = Poscar(structure)
poscar.write_file(filename="POSCAR.vasp",significant_figures=16)

6. CIFとatomsの変換

atomsとPOSCARの変換の時と同じくASEのreadとwriteを使う。

CIF ⇒ atoms

from ase.io import read
atoms = read('xxx.cif', format="cif")

atoms ⇒ CIF

from ase.io import write
write('xxx.cif', images=atoms, format='cif')

変換方法は上記に示したもの以外もあるのでよりおすすめの方法があれば教えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0