{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial 2: Molecular crystal module in PyXtal\n", "\n", "Source code: https://github.com/qzhu2017/PyXtal\n", "\n", "Created by Qiang Zhu (2020/11/23)\n", "\n", "Last updated: 2022/08/11\n", "\n", "\n", "# 2.1 Generate a random crystal\n", "\n", "To use the code, just import the following module\n", "```python\n", "from pyxtal import pyxtal\n", "s = pyxtal(molecular=True)\n", "```\n", "\n", "Ideally, one just needs to define the following parameters:\n", "- dimension: 1, 2 or 3\n", "- group: integer number from 1 to 230\n", "- molecules: a list of molecules, e.g. ['H2O']\n", "- number of molecules: a list of numbers, e.g. [4]\n", "\n", "More details can be found at the following [link](https://pyxtal.readthedocs.io/en/latest)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "------Crystal from random------\n", "Dimension: 3\n", "Composition: [h2o]4\n", "Group: P 21 21 21 (19)\n", " 3.8693, 7.5272, 6.8579, 90.0000, 90.0000, 90.0000, orthorhombic\n", "Wyckoff sites:\n", "\tH2O1 @ [ 0.8354 0.0503 0.6503] WP [4a] Site [1] Euler [ 138.9 -51.6 46.1]\n" ] } ], "source": [ "from pyxtal import pyxtal\n", "\n", "h2o = pyxtal(molecular=True)\n", "h2o.from_random(3, 19, [\"h2o\"], [4])\n", "print(h2o)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#display the structure\n", "h2o.show()\n", "\n", "#The crystal can also be exported to pymatgen or ase structure.\n", "#pmg_struc = h2o.to_pymatgen()\n", "#ase_struc = h2o.to_ase()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# It is also fun to check how the structure is generated from a simple animation\n", "h2o.show(size=(400, 300), animation=True, interval=1000)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2.2 Crystal with molecules at the special Wyckoff positions\n", "\n", "In addition to the general `Wyckoff positions` (WP), there are also special WPs which have the `site symmetries` more than the identify operation. If the `molecular symmetry` is compatible with the site symmetry, the molecules can also take the special WPs. In that event, the molecules have less degree of freedom and they can only rotate in a limited range. `PyXtal` takes care of this when dealing the structural manipulation.\n", "\n", "Below is an example to show the water molecules occupy the 4a site in space group Cmc21(36)." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "------Crystal from random------\n", "Dimension: 3\n", "Composition: [h2o]4\n", "Group: P 21 21 21 (19)\n", " 3.8693, 7.5272, 6.8579, 90.0000, 90.0000, 90.0000, orthorhombic\n", "Wyckoff sites:\n", "\tH2O1 @ [ 0.8354 0.0503 0.6503] WP [4a] Site [1] Euler [ 138.9 -51.6 46.1]\n" ] } ], "source": [ "from pyxtal import pyxtal\n", "\n", "h2o_36 = pyxtal(molecular=True)\n", "h2o_36.from_random(3, 36, [\"H2O\"], [4])\n", "print(h2o)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d9b4b4c208e64d938cdaa1712474ec19", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(IntSlider(value=0, description='id:', max=3), Output()), _dom_classes=('widget-interact'…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Below is a script to show how the molecules rotate around the allowed axis\n", "ax = h2o_36.mol_sites[0].orientation.axis\n", "\n", "strucs = []\n", "for angle in [90, 180, 270, 360]:\n", " struc = h2o_36.copy()\n", " struc.mol_sites[0].rotate(ax_vector=ax, angle=angle)\n", " strucs.append(struc)\n", "\n", "from pyxtal.viz import display_mol_crystals\n", "\n", "display_mol_crystals(strucs, axis=2*ax)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2.3 2D and 1D Crystals " ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h2o_1D = pyxtal(molecular=True)\n", "h2o_1D.from_random(1, 75, [\"H2O\"], [12])\n", "#print(h2o_1D)\n", "h2o_1D.show(supercell=(1,1,3))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "h2o_2D = pyxtal(molecular=True)\n", "h2o_2D.from_random(2, 25, [\"H2O\"], [4], thickness=0)\n", "#print(h2o_2D)\n", "h2o_2D.show(supercell=(2,2,1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2.4 Subgroup" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "------Crystal from Seed------\n", "Dimension: 3\n", "Composition: [aspirin]4\n", "Group: P 1 21/c 1 (14)\n", " 11.2330, 6.5440, 11.2310, 90.0000, 95.8900, 90.0000, monoclinic\n", "Wyckoff sites:\n", "\tH8C9O4 @ [ 0.2414 0.5782 0.0168] WP [4e] Site [1] Euler [ 0.0 0.0 0.0]\n" ] }, { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pyxtal import pyxtal\n", "\n", "C1 = pyxtal(molecular=True)\n", "C1.from_seed(seed=\"aspirin.cif\", molecules=[\"aspirin\"])\n", "print(C1)\n", "C1.show()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "------Crystal from subgroup------\n", "Dimension: 3\n", "Composition: [aspirin]4\n", "Group: P 1 c 1 (7)\n", " 11.2330, 6.5440, 11.2310, 90.0000, 95.8900, 90.0000, monoclinic\n", "Wyckoff sites:\n", "\tH8C9O4 @ [ 0.2414 0.3282 0.0168] WP [2a] Site [1] Euler [ 0.0 0.0 0.0]\n", "\tH8C9O4 @ [ 0.7586 0.8282 0.4832] WP [2a] Site [1] Euler [ 0.0 0.0 0.0]\n" ] }, { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "C2 = C1.subgroup_once(H=7, eps=0, mut_lat=False)\n", "print(C2)\n", "C2.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2.5 Cell Transformation" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "------Crystal from Seed------\n", "Dimension: 3\n", "Composition: [aspirin]4\n", "Group: P 1 21/c 1 (14)\n", " 11.2330, 6.5440, 11.2310, 90.0000, 95.8900, 90.0000, monoclinic\n", "Wyckoff sites:\n", "\tH8C9O4 @ [ 0.2414 0.5782 0.0168] WP [4e] Site [1] Euler [ 0.0 0.0 0.0]\n" ] }, { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pyxtal import pyxtal\n", "\n", "C1 = pyxtal(molecular=True)\n", "C1.from_seed(seed=\"aspirin.cif\", molecules=[\"aspirin\"])\n", "print(C1)\n", "C1.show()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "------Crystal from Seed------\n", "Dimension: 3\n", "Composition: [aspirin]4\n", "Group: P 1 21/n 1 (14)\n", " 11.2330, 6.5440, 15.0474, 90.0000, 47.9393, 90.0000, monoclinic\n", "Wyckoff sites:\n", "\tH8C9O4 @ [ 0.2246 0.5782 0.0168] WP [4e] Site [1] Euler [ 0.0 0.0 0.0]\n" ] }, { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Now we apply the cell transformation\n", "C1.transform([[1,0,0],[0,1,0],[1,0,1]])\n", "print(C1)\n", "C1.show()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "------Crystal from Seed------\n", "Dimension: 3\n", "Composition: [aspirin]4\n", "Group: P 1 21/c 1 (14)\n", " 11.2330, 6.5440, 11.2310, 90.0000, 95.8900, 90.0000, monoclinic\n", "Wyckoff sites:\n", "\tH8C9O4 @ [ 0.2414 0.5782 0.0168] WP [4e] Site [1] Euler [ 0.0 0.0 0.0]\n" ] }, { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# We can always use the optimize_lattice function to\n", "# change it to a cell reprentation that has an inclination\n", "# angle close to 90 degree\n", "\n", "C1.optimize_lattice()\n", "print(C1)\n", "C1.show()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "------Crystal from random------\n", "Dimension: 3\n", "Composition: [BIPHEN]12\n", "Group: P m -3 (200)\n", " 15.1676, 15.1676, 15.1676, 90.0000, 90.0000, 90.0000, cubic\n", "Wyckoff sites:\n", "\tH10C12 @ [ 0.5000 0.6120 0.1863] WP [12k] Site [m..] Euler [-180.0 -62.4 -0.0]\n" ] } ], "source": [ "BIPHEN = pyxtal(molecular=True)\n", "#BIPHEN.from_random(3, 200, ['BIPHEN'], [24])\n", "BIPHEN.from_random(3, 200, [\"BIPHEN\"], [12], sites=[[\"12k\"]])\n", "print(BIPHEN)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "application/3dmoljs_load.v0": "
\n

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n jupyter labextension install jupyterlab_3dmol

\n
\n", "text/html": [ "
\n", "

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n", " jupyter labextension install jupyterlab_3dmol

\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "BIPHEN.show(size=(400, 300), animation=True, interval=1000)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.12" } }, "nbformat": 4, "nbformat_minor": 2 }