0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

supercellモデルをvscode copilotで作れる?

Posted at

vscode copilot chatでCuのスラブモデル作ってみました。
なんか半分は教えたってる、という気分。

まあしかし、枠組みを作ってくれるので、ありがたいのはありがたい。
マニュアルを読む時代ではなくなってきたのかもしれないな。
あと5年もたてばかなりできるようになるんとちゃうかな。

# 必要なライブラリをインポート
from pymatgen.core import Structure, Lattice
from pymatgen.io.vasp import Poscar
import plotly.graph_objects as go
import numpy as np

# Cuのfcc構造を取得
lattice = Lattice.cubic(3.615)  # Cuの格子定数
cu_structure = Structure(lattice, ["Cu", "Cu", "Cu", "Cu"], 
                         [[0, 0, 0], [0.5, 0.5, 0], [0.5, 0, 0.5], [0, 0.5, 0.5]])

# スラブの厚みを2倍にし、スラブとスラブの距離をスラブの厚みの2倍に設定
slab_thickness = 2 * lattice.c
vacuum_thickness = 2 * slab_thickness

# 100方向のスラブを生成
slab_sites = []
for z in np.arange(0, slab_thickness, lattice.c / 2):
    for x in np.arange(0, lattice.a, lattice.a / 2):
        for y in np.arange(0, lattice.b, lattice.b / 2):
            if (x + y + z) % lattice.a == 0:
                slab_sites.append([x, y, z])

# スラブ構造を作成
slab_lattice = Lattice.from_parameters(a=lattice.a, b=lattice.b, c=slab_thickness + vacuum_thickness, alpha=90, beta=90, gamma=90)
slab_structure = Structure(slab_lattice, ["Cu"] * len(slab_sites), slab_sites, coords_are_cartesian=True)

# POSCARファイルを書き出し
poscar = Poscar(slab_structure)
poscar.write_file("POSCAR")

# プロットの初期化
fig = go.Figure()

# スラブをx, y, z方向に周期的に描画
nx, ny, nz = 2, 2, 3  # x, y, z方向の周期数
for i in range(nx):
    for j in range(ny):
        for k in range(nz):
            for site in slab_structure:
                fig.add_trace(go.Scatter3d(
                    x=[site.coords[0] + i * slab_structure.lattice.a],
                    y=[site.coords[1] + j * slab_structure.lattice.b],
                    z=[site.coords[2] + k * slab_structure.lattice.c],
                    mode='markers',
                    marker=dict(size=5, color='green'),
                    name='Cu Atoms'
                ))

# レイアウトを設定
fig.update_layout(
    scene=dict(
        xaxis_title='X',
        yaxis_title='Y',
        zaxis_title='Z',
        aspectmode='data',  # アスペクト比をデータに基づいて設定
        camera=dict(
            projection=dict(
                type='orthographic'  # 遠近法を使わない
            )
        )
    ),
    title='3D View of Cu Slab Model with Periodicity'
)
fig.update_layout(width=800, height=800)
#fig.update_layout(scene_aspectmode='cube')

# プロットを表示
fig.show()
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?