LoginSignup
8
7

More than 3 years have passed since last update.

pythonのpymatgenの使い方を頑張ってまとめてみる②

Last updated at Posted at 2019-06-12

はじめに

今回も前回に引き続き、pymatgenの使い方をまとめていきたいと思います。それでは始めていきましょう。


structureオブジェクトの色々な使い方

今回は、ICSDのデータを使用していきます。

import pymatgen as mg

structure = mg.Structure.from_file('data_1-ICSD.cif')
print(structure.species)
print(structure.species_and_occu)

[Specie Cr3+, Specie Cr3+, Specie Cr3+, Specie Cr3....]
[Comp: Cr1, Comp: Cr1, Comp: Cr1, Comp: Cr1,....]

今回使用したcifファイルの中身はCr2Te4O11 となっています。まず、Structure.from_fileでcifファイルをstructureオブジェクトに変換しています。structureオブジェクトのspecisとspecies_and_occuには、上記のような原子の種類や位置のデータが格納されています。また以下のように使うこともできます。

structure = mg.Structure.from_file('data_1-ICSD.cif')
for x in structure.species_and_occu:
    print(x.num_atoms)

1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0
1.0

このように、原子の各サイトの占有率を調べることができます。欠陥がなければ、すべて1になります。
また、以下のようにstructureオブジェクトをjson形式で保存することもできます。

structure = mg.Structure.from_file('data_1-ICSD.cif')
with open('structure.json', 'w') as f:
    json.dump(structure.as_dict(), f)

structureオブジェクトのas_dictメソッドを用いることでstructureメソッドの情報を辞書型に変換し、jsonモジュールのdumpメソッドを用いることでjson形式で保存することができます。このように作成したjson形式のファイルは、Structure.from_file()を用いることで再びstructureオブジェクトに変換することができます。また、以下のようにjsonファイルをロードした後に、Structure.from_dictを用いることでstrucutureオブジェクトに変換することも可能です。

with open('structure.json', 'r')as f:
    d = json.load(f)
    structure = mg.Structure.from_dict(d)

structureオブジェクトのパラメーター

structureオブジェクトの様々なパラメーターをみていきましょう。

print(structure.atomic_numbers)
print(structure.cart_coords)
print(structure.composition)

[24, 24, 24, 24, 52, 52, 52, 52, 52, 52, ...
[[ 2.20755584 7.5306645 8.22454971]
[ 4.70834591 3.7581645 5.18653584]....]
Cr3+4 Te4+8 O2-22

atomic_numbersには各々のサイトの原子番号が、cart_coordsには各々の原子の位置が、compositionには原子の価数と数が格納されています。

print(structure.charge)
print(structure.density)
print(structure.formula)

0.0
5.171142245525924 g cm^-3
Cr4 Te8 O22

chargeには分子全体の電荷が、densityには分子の密度が、formulaには分子の中の原子の種類と数が格納されています。

print(structure.lattice)
print(structure.frac_coords)
print(structure.volume)

6.915902 0.000000 -1.180914
0.000000 7.545000 0.000000
0.000000 0.000000 9.728000

[[0.3192 0.9981 0.8842]
[0.6808 0.4981 0.6158]...]

507.6116970440605

latticeには分子の単位格子のベクトルが格納されています。frac_coordsには分子中の原子の位置を単位格子のベクトルに対しての相対的な位置で表したものが格納されています。つまり、各原子位置のベクトルを単位格子のベクトルで除したものなので、必ず0と1の間になります。volumeには分子の体積が格納されています。


今回はここまでとなります。さらに細かいpymatgenの使い方を次回で解説します。お疲れさまでした。
pythonのpymatgenの使い方を頑張ってまとめてみる①
pythonのpymatgenの使い方を頑張ってまとめてみる③

8
7
1

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