|
37 | 37 | },
|
38 | 38 | {
|
39 | 39 | "cell_type": "code",
|
40 |
| - "execution_count": null, |
41 | 40 | "id": "9c1f4e9e",
|
42 | 41 | "metadata": {},
|
43 |
| - "outputs": [], |
44 | 42 | "source": [
|
45 | 43 | "# Upload files to this folder\n",
|
46 | 44 | "FOLDER_PATH = \"./uploads\"\n",
|
|
51 | 49 | "USE_FILE_NAME_NO_EXTENSION = False\n",
|
52 | 50 | "# If set to true, the supported formats will be printed below\n",
|
53 | 51 | "SHOW_SUPPORTED_FORMATS = False"
|
54 |
| - ] |
| 52 | + ], |
| 53 | + "outputs": [], |
| 54 | + "execution_count": null |
55 | 55 | },
|
56 | 56 | {
|
57 | 57 | "cell_type": "markdown",
|
|
63 | 63 | },
|
64 | 64 | {
|
65 | 65 | "cell_type": "code",
|
66 |
| - "execution_count": null, |
67 | 66 | "id": "ef2b38a5-de7e-419e-b605-110e9e0095f5",
|
68 | 67 | "metadata": {
|
69 | 68 | "trusted": true
|
70 | 69 | },
|
71 |
| - "outputs": [], |
72 | 70 | "source": [
|
73 | 71 | "import sys\n",
|
74 | 72 | "if sys.platform == \"emscripten\":\n",
|
75 | 73 | " import micropip\n",
|
76 | 74 | " await micropip.install('mat3ra-api-examples', deps=False)\n",
|
77 |
| - "from utils.jupyterlite import install_packages\n", |
78 |
| - "await install_packages(\"import_materials_from_files.ipynb\",\"../../config.yml\")" |
79 |
| - ] |
| 75 | + " from utils.jupyterlite import install_packages\n", |
| 76 | + " await install_packages(\"import_materials_from_files.ipynb\")" |
| 77 | + ], |
| 78 | + "outputs": [], |
| 79 | + "execution_count": null |
80 | 80 | },
|
81 | 81 | {
|
82 | 82 | "cell_type": "markdown",
|
|
90 | 90 | },
|
91 | 91 | {
|
92 | 92 | "cell_type": "code",
|
93 |
| - "execution_count": null, |
94 | 93 | "id": "b1ee775d1476f884",
|
95 | 94 | "metadata": {
|
96 | 95 | "collapsed": false,
|
97 | 96 | "trusted": true
|
98 | 97 | },
|
99 |
| - "outputs": [], |
100 | 98 | "source": [
|
101 | 99 | "import os\n",
|
102 | 100 | "from pathlib import Path\n",
|
|
118 | 116 | " print(e)\n",
|
119 | 117 | " unreadable_files.append(file_name)\n",
|
120 | 118 | " continue"
|
121 |
| - ] |
| 119 | + ], |
| 120 | + "outputs": [], |
| 121 | + "execution_count": null |
122 | 122 | },
|
123 | 123 | {
|
124 | 124 | "cell_type": "markdown",
|
|
130 | 130 | },
|
131 | 131 | {
|
132 | 132 | "cell_type": "code",
|
133 |
| - "execution_count": null, |
134 | 133 | "id": "0e34472a",
|
135 | 134 | "metadata": {},
|
136 |
| - "outputs": [], |
137 | 135 | "source": [
|
138 | 136 | "print(f\"Successfully read {len(materials)} files\")\n",
|
139 | 137 | "print(f\"Unreadable files: {unreadable_files}. \")\n"
|
140 |
| - ] |
| 138 | + ], |
| 139 | + "outputs": [], |
| 140 | + "execution_count": null |
141 | 141 | },
|
142 | 142 | {
|
143 | 143 | "cell_type": "markdown",
|
|
149 | 149 | },
|
150 | 150 | {
|
151 | 151 | "cell_type": "code",
|
152 |
| - "execution_count": null, |
153 | 152 | "id": "a771a36a",
|
154 | 153 | "metadata": {},
|
155 |
| - "outputs": [], |
156 | 154 | "source": [
|
157 | 155 | "# Uncomment to see the list of supported formats and their file extensions\n",
|
158 | 156 | "from ase.io.formats import ioformats\n",
|
|
163 | 161 | " data = [[frmt.name, frmt.extensions, frmt.description] for frmt in ioformats.values()]\n",
|
164 | 162 | " dataframe = pd.DataFrame(data, columns=[\"Format Name\", \"File Extensions\", \"Description\"])\n",
|
165 | 163 | " print(dataframe.to_markdown())"
|
166 |
| - ] |
| 164 | + ], |
| 165 | + "outputs": [], |
| 166 | + "execution_count": null |
167 | 167 | },
|
168 | 168 | {
|
169 | 169 | "cell_type": "markdown",
|
|
175 | 175 | },
|
176 | 176 | {
|
177 | 177 | "cell_type": "code",
|
178 |
| - "execution_count": null, |
179 | 178 | "id": "c41fb68c6d25fe48",
|
180 | 179 | "metadata": {
|
181 | 180 | "collapsed": false,
|
182 | 181 | "trusted": true
|
183 | 182 | },
|
184 |
| - "outputs": [], |
185 | 183 | "source": [
|
186 |
| - "from src.utils import ase_to_poscar\n", |
| 184 | + "import io\n", |
| 185 | + "from ase import Atoms\n", |
| 186 | + "from ase.io import write\n", |
187 | 187 | "from express import ExPrESS\n",
|
188 | 188 | "\n",
|
| 189 | + "def ase_to_poscar(atoms: Atoms):\n", |
| 190 | + " \"\"\"\n", |
| 191 | + " Converts ase.Atoms object to POSCAR format\n", |
| 192 | + "\n", |
| 193 | + " Args:\n", |
| 194 | + " atoms (ase.Atoms): ase.Atoms object\n", |
| 195 | + "\n", |
| 196 | + " Returns:\n", |
| 197 | + " str: POSCAR string\n", |
| 198 | + " \"\"\"\n", |
| 199 | + " output = io.StringIO()\n", |
| 200 | + " write(output, atoms, format=\"vasp\")\n", |
| 201 | + " content = output.getvalue()\n", |
| 202 | + " output.close()\n", |
| 203 | + "\n", |
| 204 | + " return content\n", |
| 205 | + "\n", |
189 | 206 | "def convert_ase_entry_to_esse(ase_entry):\n",
|
190 | 207 | " poscar = ase_to_poscar(ase_entry)\n",
|
191 | 208 | " kwargs = {\n",
|
|
201 | 218 | " return esse\n",
|
202 | 219 | "\n",
|
203 | 220 | "esse_entries = list(map(convert_ase_entry_to_esse, materials))"
|
204 |
| - ] |
| 221 | + ], |
| 222 | + "outputs": [], |
| 223 | + "execution_count": null |
205 | 224 | },
|
206 | 225 | {
|
207 | 226 | "cell_type": "markdown",
|
|
213 | 232 | },
|
214 | 233 | {
|
215 | 234 | "cell_type": "code",
|
216 |
| - "execution_count": null, |
217 | 235 | "id": "860b5c1b",
|
218 | 236 | "metadata": {},
|
219 |
| - "outputs": [], |
220 | 237 | "source": [
|
221 |
| - "from src.utils import poscar_to_ase\n", |
222 |
| - "from ase.visualize import view\n", |
223 |
| - "from ase.io import write\n", |
224 |
| - "from ase.build import make_supercell\n", |
225 |
| - "from IPython.display import Image\n", |
| 238 | + "from utils.visualize import visualize_materials\n", |
| 239 | + "from mat3ra.made.material import Material\n", |
226 | 240 | "\n",
|
227 |
| - "def visualize_material(material, index: int, number_of_repetitions: int = 3):\n", |
228 |
| - " \"\"\"\n", |
229 |
| - " Visualize the material using ASE's visualization tool\n", |
230 |
| - " Repeat the unit cell to make it easier to see.\n", |
| 241 | + "materials = [Material(esse_entry) for esse_entry in esse_entries]\n", |
231 | 242 | "\n",
|
232 |
| - " Args:\n", |
233 |
| - " material: The material to visualize (Ase.Atoms object)\n", |
234 |
| - " index: The index of the material\n", |
235 |
| - " number_of_repetitions: The number of unit cell repetitions to visualize\n", |
236 |
| - " \"\"\"\n", |
237 |
| - " # Set the number of unit cell repetition for the structure to make it easier to see\n", |
238 |
| - " n = number_of_repetitions\n", |
239 |
| - " material_repeat = make_supercell(material, [[n,0,0],[0,n,0],[0,0,n]])\n", |
240 |
| - " filename = f\"material-{index}.png\"\n", |
241 |
| - " write(filename, material_repeat)\n", |
242 |
| - " img = Image(filename=filename)\n", |
243 |
| - " print(filename, \"-\", material.symbols)\n", |
244 |
| - " display(img)\n", |
245 |
| - "\n", |
246 |
| - "for idx, material in enumerate(materials):\n", |
247 |
| - " visualize_material(material, idx)" |
248 |
| - ] |
| 243 | + "visualize_materials(materials)" |
| 244 | + ], |
| 245 | + "outputs": [], |
| 246 | + "execution_count": null |
249 | 247 | },
|
250 | 248 | {
|
251 | 249 | "cell_type": "markdown",
|
|
257 | 255 | },
|
258 | 256 | {
|
259 | 257 | "cell_type": "code",
|
260 |
| - "execution_count": null, |
261 | 258 | "id": "00b187ab",
|
262 | 259 | "metadata": {},
|
263 |
| - "outputs": [], |
264 | 260 | "source": [
|
265 |
| - "from utils.jupyterlite import set_data\n", |
| 261 | + "from utils.jupyterlite import set_materials\n", |
266 | 262 | "\n",
|
267 |
| - "output_materials = esse_entries\n", |
268 |
| - "set_data(\"materials\", output_materials)" |
269 |
| - ] |
| 263 | + "set_materials(materials)" |
| 264 | + ], |
| 265 | + "outputs": [], |
| 266 | + "execution_count": null |
270 | 267 | }
|
271 | 268 | ],
|
272 | 269 | "metadata": {
|
|
0 commit comments