draw_bravais_lattice プログラム仕様

ブラベー格子の単位格子と格子点を3Dで可視化するスクリプト。

このスクリプトは、指定された格子定数と結晶系に基づいて、 ブラベー格子の単位格子、格子点、格子ベクトル、およびオプションで補助線や基本格子を3Dで描画します。 Matplotlibを使用して3Dプロットを生成し、結果を画像ファイルとして保存し、表示します。

関連リンク: プログラムドキュメント: draw_bravais_lattice.py

class crystal.draw_bravais_lattice.Arrow3D(xs, ys, zs, *args, **kwargs)

ベースクラス: FancyArrowPatch

MatplotlibのFancyArrowPatchを継承し、3D空間に矢印を描画するためのクラス。

このクラスは、3D座標の矢印を2Dのスクリーン座標に投影し、 Matplotlibの3D軸上に適切に描画することを可能にします。

do_3d_projection(renderer=None)

3D投影を計算し、描画順序のためのZ深度を返します。

矢印の3D座標を2Dスクリーン座標に変換し、最小のZ深度を返して、 Matplotlibの3Dレンダリングにおける描画順序を適切に処理します。

パラメータ:

renderer (matplotlib.backend_bases.RendererBase or None) -- 描画に使用されるレンダラーオブジェクト(オプション)。

戻り値:

変換されたZ座標の最小値。

戻り値の型:

float

draw(renderer)

矢印をレンダラーに描画します。

3D座標を2Dスクリーン座標に変換し、変換された座標に基づいて矢印を描画します。

パラメータ:

renderer (matplotlib.backend_bases.RendererBase) -- 描画に使用されるレンダラーオブジェクト。

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, antialiased=<UNSET>, arrowstyle=<UNSET>, capstyle=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, connectionstyle=<UNSET>, edgecolor=<UNSET>, edgegapcolor=<UNSET>, facecolor=<UNSET>, fill=<UNSET>, gid=<UNSET>, hatch=<UNSET>, hatch_linewidth=<UNSET>, hatchcolor=<UNSET>, in_layout=<UNSET>, joinstyle=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, mutation_aspect=<UNSET>, mutation_scale=<UNSET>, patchA=<UNSET>, patchB=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, positions=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

a.set(a=A, b=B, c=C)

is equivalent to

a.set_a(A)
a.set_b(B)
a.set_c(C)

In addition to the full property names, aliases are also supported, e.g. set(lw=2) is equivalent to set(linewidth=2), but it is an error to pass both simultaneously.

The order of the individual setter calls matches the order of parameters in set(). However, most properties do not depend on each other so that order is rarely relevant.

Supported properties are

Properties:

agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: float or None animated: bool antialiased or aa: bool or None arrowstyle: [ '-' | '<-' | '->' | '<->' | '<|-' | '-|>' | '<|-|>' | ']-' | '-[' | ']-[' | '|-|' | ']->' | '<-[' | 'simple' | 'fancy' | 'wedge' ] capstyle: .CapStyle or {'butt', 'projecting', 'round'} clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None color: :mpltype:`color` connectionstyle: [ 'arc3' | 'angle3' | 'angle' | 'arc' | 'bar' ] edgecolor or ec: :mpltype:`color` or None edgegapcolor: :mpltype:`color` or None facecolor or fc: :mpltype:`color` or None figure: ~matplotlib.figure.Figure or ~matplotlib.figure.SubFigure fill: bool gid: str hatch: {'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'} hatch_linewidth: unknown hatchcolor: :mpltype:`color` or 'edge' or None in_layout: bool joinstyle: .JoinStyle or {'miter', 'round', 'bevel'} label: object linestyle or ls: {'-', '--', '-.', ':', '', ...} or (offset, on-off-seq) linewidth or lw: float or None mouseover: bool mutation_aspect: float mutation_scale: float patchA: .patches.Patch patchB: .patches.Patch path_effects: list of .AbstractPathEffect picker: None or bool or float or callable positions: unknown rasterized: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None transform: ~matplotlib.transforms.Transform url: str visible: bool zorder: float

crystal.draw_bravais_lattice.draw_unit_cell_with_lattice(a, b, c, alpha, beta, gamma, lattice_points=None, dashed_lines=None, basis_vectors=None)

指定された格子定数と格子点を用いて、ブラベー単位格子を3Dで描画します。

この関数は、単位格子の辺、頂点、格子ベクトル、格子点、オプションで補助線、 および基本格子を描画し、結果を画像ファイルとして保存した後、画面に表示します。 ユーザーがプロットを操作すると、現在の視点角度 (elev, azim) がコンソールに出力されます。

パラメータ:
  • a (float) -- 格子定数aの長さ。

  • b (float) -- 格子定数bの長さ。

  • c (float) -- 格子定数cの長さ。

  • alpha (float) -- 角度α(bとcの間の角度、度数)。

  • beta (float) -- 角度β(aとcの間の角度、度数)。

  • gamma (float) -- 角度γ(aとbの間の角度、度数)。

  • lattice_points (list[list[float]] or None) -- 格子点を表す係数のリスト。各要素は [u, v, w] 形式で u*va + v*vb + w*vc と計算されます。 Noneの場合、格子点は描画されません。

  • dashed_lines (list[tuple[tuple[float, float, float], tuple[float, float, float]]] or None) -- 補助線(破線)の始点と終点を表す係数のリスト。各要素は ([u1, v1, w1], [u2, v2, w2]) 形式です。 Noneの場合、補助線は描画されません。

  • basis_vectors (list[list[float]] or None) -- 基本格子ベクトルを表す係数のリスト。各要素は [u, v, w] 形式です。 Noneの場合、基本格子は描画されません。

戻り値:

なし

crystal.draw_bravais_lattice.draw_vector(ax, vec, color, label, fontsize)

指定された3Dベクトルを矢印としてMatplotlibの3D軸に描画します。

矢印は原点(0,0,0)から指定されたベクトルまで描画され、 ベクトルの先端にはラベルが表示されます。

パラメータ:
  • ax (mpl_toolkits.mplot3d.axes3d.Axes3D) -- 矢印を描画する3D軸オブジェクト。

  • vec (numpy.ndarray) -- 矢印の終点となる3Dベクトル。

  • color (str) -- 矢印とラベルの色。

  • label (str) -- 矢印のラベル文字列。

  • fontsize (int) -- ラベルのフォントサイズ。

戻り値:

なし

crystal.draw_bravais_lattice.lattice_vectors(a, b, c, alpha, beta, gamma)

単位格子の格子定数から3つの基本格子ベクトルを計算します。

計算は、a軸をx軸に沿わせ、b軸をxy平面に置き、c軸をz軸正方向に向ける形で 座標系を設定して行われます。

パラメータ:
  • a (float) -- 格子定数aの長さ。

  • b (float) -- 格子定数bの長さ。

  • c (float) -- 格子定数cの長さ。

  • alpha (float) -- 角度α(bとcの間の角度、度数)。

  • beta (float) -- 角度β(aとcの間の角度、度数)。

  • gamma (float) -- 角度γ(aとbの間の角度、度数)。

戻り値:

3つの基本格子ベクトル (va, vb, vc)。

戻り値の型:

tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]

crystal.draw_bravais_lattice.main()

プログラムのエントリポイント。コマンドライン引数を解析し、ブラベー単位格子の描画を実行します。

コマンドライン引数に基づいて、描画する結晶系と表示オプション(格子ベクトル、補助線、基本格子)を 設定し、`draw_unit_cell_with_lattice`関数を呼び出して単位格子を描画します。 引数が指定されない場合は、デフォルト値が使用されます。

使用方法:

python draw_bravais_lattice.py [cell_type] [draw_lattice_vectors] [draw_support_lines] [draw_primitive_cell]

  • cell_type (str): 描画する結晶系 ('SC', 'ST', 'SO', 'SR', 'SH', 'FC', 'FO', 'BC', 'BT', 'BO', 'CO', 'SM', 'STri', 'CM'など)。

  • draw_lattice_vectors (int): 格子ベクトルを描画するか (1: はい, 0: いいえ)。

  • draw_support_lines (int): 補助線を描画するか (1: はい, 0: いいえ)。

  • draw_primitive_cell (int): 基本格子を描画するか (1: はい, 0: いいえ)。

戻り値:

なし

crystal.draw_bravais_lattice.set_equal_aspect(ax, points)

Matplotlibの3Dプロットの軸のアスペクト比を等しく設定します。

描画される全ての点の範囲に基づいて、x, y, z軸の表示範囲を調整し、 立体が歪まないように真のアスペクト比を維持します。

パラメータ:
  • ax (mpl_toolkits.mplot3d.axes3d.Axes3D) -- 軸のアスペクト比を設定する3D軸オブジェクト。

  • points (numpy.ndarray) -- 描画される全ての点のNumpy配列。

戻り値:

なし