draw_unit_cell プログラム仕様
単位格子を描画するスクリプト。
- 概要:
結晶学における単位格子を3Dで可視化する機能を提供します。
- 詳細説明:
任意の格子定数と角度から単位格子の形状を計算し、Matplotlibを使用して描画します。 基本ベクトル(a, b, c)の描画には、パースペクティブを考慮したカスタム3D矢印クラスを使用します。
- 関連リンク:
draw_unit_cell_usage
- class crystal.draw_unit_cell.Arrow3D(xs, ys, zs, *args, **kwargs)
ベースクラス:
FancyArrowPatch- 概要:
Matplotlibの3Dプロットでカスタムの3D矢印を描画するためのクラス。
- 詳細説明:
FancyArrowPatch を継承し、3D空間内の座標を2Dスクリーン座標に変換して描画することで、 常に適切なパースペクティブで矢印が表示されるようにします。
- do_3d_projection(renderer=None)
- 概要:
3Dプロジェクションを実行し、矢印の深度を計算します。
- 詳細説明:
3D座標を2Dスクリーン座標に変換し、Z軸方向の最小値(深度)を返すことで、 3Dビューにおけるオブジェクトの描画順序を適切に管理します。
- 引数:
- param renderer:
Matplotlibのレンダラーオブジェクト(オプション)。
- type renderer:
matplotlib.backend_bases.RendererBase
- 戻り値:
- returns:
矢印のZ軸方向の最小値(深度)。
- rtype:
numpy.float
- draw(renderer)
- 概要:
矢印をレンダリングします。
- 詳細説明:
3D座標を2Dスクリーン座標に変換し、変換された座標を使用して矢印を描画します。
- 引数:
- param renderer:
Matplotlibのレンダラーオブジェクト。
- type renderer:
matplotlib.backend_bases.RendererBase
- 戻り値:
- returns:
なし
- rtype:
None
- 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>, facecolor=<UNSET>, fill=<UNSET>, gid=<UNSET>, hatch=<UNSET>, hatch_linewidth=<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.
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 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 in_layout: bool joinstyle: .JoinStyle or {'miter', 'round', 'bevel'} label: object linestyle or ls: {'-', '--', '-.', ':', '', (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_unit_cell.draw_unit_cell_plot(a, b, c, alpha, beta, gamma, elev=5.9, azim=-67.55, fontsize=24, color='blue')
- 概要:
指定された格子定数と角度を持つ単位格子を3Dで描画します。
- 詳細説明:
lattice_vectors 関数を使用して基本格子ベクトルを計算し、それらから単位格子の8つの頂点を生成します。 その後、Matplotlibを用いて単位格子の辺、頂点、および基本格子ベクトルを3D空間に描画します。
- 引数:
- param a:
格子定数aの長さ。
- type a:
float
- param b:
格子定数bの長さ。
- type b:
float
- param c:
格子定数cの長さ。
- type c:
float
- param alpha:
b軸とc軸の間の角度(度数)。
- type alpha:
float
- param beta:
a軸とc軸の間の角度(度数)。
- type beta:
float
- param gamma:
a軸とb軸の間の角度(度数)。
- type gamma:
float
- param elev:
3Dビューの仰角(度数)。デフォルトは5.90。
- type elev:
float
- param azim:
3Dビューの方位角(度数)。デフォルトは-67.55。
- type azim:
float
- param fontsize:
ラベルのフォントサイズ。デフォルトは24。
- type fontsize:
int
- param color:
ベクトルの色。デフォルトは 'blue'。
- type color:
str
- 戻り値:
- returns:
なし(グラフを表示し、PNGとして保存します)
- rtype:
None
- crystal.draw_unit_cell.draw_vector(ax, vec, color, label, fontsize)
- 概要:
3D空間にベクトルと対応するラベルを描画します。
- 詳細説明:
Arrow3D クラスを利用して、原点から指定されたベクトルまでの矢印を描画し、 ベクトルの先端にラベルを配置します。
- 引数:
- param ax:
3DプロットのAxesオブジェクト。
- type ax:
matplotlib.axes.Axes
- param vec:
描画するベクトルの3D座標([x, y, z])。
- type vec:
numpy.ndarray
- param color:
矢印とラベルの色。
- type color:
str
- param label:
ベクトルに付けるラベル。
- type label:
str
- param fontsize:
ラベルのフォントサイズ。
- type fontsize:
int
- 戻り値:
- returns:
なし
- rtype:
None
- crystal.draw_unit_cell.lattice_vectors(a, b, c, alpha, beta, gamma)
- 概要:
格子定数と角度から基本格子ベクトルを計算します。
- 詳細説明:
結晶学で用いられる格子定数 (a, b, c) と軸間角 (alpha, beta, gamma) を用いて、 直交座標系における3つの基本格子ベクトル (va, vb, vc) を計算します。
- 引数:
- param a:
格子定数aの長さ。
- type a:
float
- param b:
格子定数bの長さ。
- type b:
float
- param c:
格子定数cの長さ。
- type c:
float
- param alpha:
b軸とc軸の間の角度(度数)。
- type alpha:
float
- param beta:
a軸とc軸の間の角度(度数)。
- type beta:
float
- param gamma:
a軸とb軸の間の角度(度数)。
- type gamma:
float
- 戻り値:
- returns:
3つの基本格子ベクトル (va, vb, vc)。各ベクトルは [x, y, z] の形式の numpy.ndarray。
- rtype:
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
- crystal.draw_unit_cell.main()
- 概要:
メインの実行ルーチン。特定の格子定数で単位格子を描画します。
- crystal.draw_unit_cell.set_equal_aspect(ax, points)
- 概要:
3Dプロットのアスペクト比を均等に設定し、描画範囲を調整します。
- 詳細説明:
描画される点の最大・最小座標に基づいて、X, Y, Z軸の表示範囲を同じにします。
- 引数:
- param ax:
3DプロットのAxesオブジェクト。
- type ax:
matplotlib.axes.Axes
- param points:
描画される全ての点のNumpy配列。形状は (N, 3)。
- type points:
numpy.ndarray
- 戻り値:
- returns:
なし
- rtype:
None