Skip to content

Commit 7428353

Browse files
committed
update: use made
1 parent 30c0e22 commit 7428353

File tree

1 file changed

+38
-58
lines changed

1 file changed

+38
-58
lines changed

other/materials_designer/import_material_from_jarvis_db_entry.ipynb

Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@
3535
},
3636
{
3737
"cell_type": "code",
38-
"execution_count": 2,
3938
"id": "9c1f4e9e",
4039
"metadata": {},
41-
"outputs": [],
4240
"source": [
4341
"# Note: JVASP-670 is an entry for MoTe2 and JVASP-6838 is an entry for GaTe\n",
4442
"JARVIS_IDS = [\n",
4543
" \"JVASP-670\",\n",
4644
" \"JVASP-6838\",\n",
4745
"]"
48-
]
46+
],
47+
"outputs": [],
48+
"execution_count": null
4949
},
5050
{
5151
"cell_type": "markdown",
@@ -57,20 +57,23 @@
5757
},
5858
{
5959
"cell_type": "code",
60-
"execution_count": null,
6160
"id": "ef2b38a5-de7e-419e-b605-110e9e0095f5",
6261
"metadata": {
6362
"trusted": true
6463
},
65-
"outputs": [],
6664
"source": [
6765
"import sys\n",
66+
"\n",
6867
"if sys.platform == \"emscripten\":\n",
6968
" import micropip\n",
69+
"\n",
7070
" await micropip.install('mat3ra-api-examples', deps=False)\n",
71-
"from utils.jupyterlite import install_packages\n",
72-
"await install_packages(\"import_material_from_jarvis_db_entry.ipynb\",\"../../config.yml\")"
73-
]
71+
" from utils.jupyterlite import install_packages\n",
72+
"\n",
73+
" await install_packages(\"import_material_from_jarvis_db_entry.ipynb\")"
74+
],
75+
"outputs": [],
76+
"execution_count": null
7477
},
7578
{
7679
"cell_type": "markdown",
@@ -84,13 +87,11 @@
8487
},
8588
{
8689
"cell_type": "code",
87-
"execution_count": null,
8890
"id": "b1ee775d1476f884",
8991
"metadata": {
9092
"collapsed": false,
9193
"trusted": true
9294
},
93-
"outputs": [],
9495
"source": [
9596
"import pandas as pd\n",
9697
"from jarvis.db.figshare import data\n",
@@ -99,8 +100,10 @@
99100
"dft_3d = data(\"dft_3d\")\n",
100101
"dataframe_2d = pd.DataFrame(dft_2d)\n",
101102
"dataframe_3d = pd.DataFrame(dft_3d)\n",
102-
"dataframe= pd.concat([dataframe_2d, dataframe_3d])"
103-
]
103+
"dataframe = pd.concat([dataframe_2d, dataframe_3d])"
104+
],
105+
"outputs": [],
106+
"execution_count": null
104107
},
105108
{
106109
"cell_type": "markdown",
@@ -112,13 +115,13 @@
112115
},
113116
{
114117
"cell_type": "code",
115-
"execution_count": null,
116118
"id": "0e34472a",
117119
"metadata": {},
118-
"outputs": [],
119120
"source": [
120121
"dataframe"
121-
]
122+
],
123+
"outputs": [],
124+
"execution_count": null
122125
},
123126
{
124127
"cell_type": "markdown",
@@ -130,18 +133,18 @@
130133
},
131134
{
132135
"cell_type": "code",
133-
"execution_count": null,
134136
"id": "a771a36a",
135137
"metadata": {},
136-
"outputs": [],
137138
"source": [
138139
"import json\n",
139140
"from express import ExPrESS\n",
140141
"\n",
141142
"dataframe_entries_for_jarvis_ids = dataframe[(dataframe[\"jid\"].isin(JARVIS_IDS))]\n",
142143
"dataframe_entries_as_json = dataframe_entries_for_jarvis_ids.to_json(orient=\"records\")\n",
143144
"jarvis_db_entries = json.loads(dataframe_entries_as_json)"
144-
]
145+
],
146+
"outputs": [],
147+
"execution_count": null
145148
},
146149
{
147150
"cell_type": "markdown",
@@ -153,13 +156,11 @@
153156
},
154157
{
155158
"cell_type": "code",
156-
"execution_count": null,
157159
"id": "c41fb68c6d25fe48",
158160
"metadata": {
159161
"collapsed": false,
160162
"trusted": true
161163
},
162-
"outputs": [],
163164
"source": [
164165
"def convert_jarvis_entry_to_esse(jarvis_db_entry):\n",
165166
" jarvis_db_entry_json = json.dumps(jarvis_db_entry)\n",
@@ -173,9 +174,12 @@
173174
" poscar = handler.parser.jarvis_db_entry_json_to_poscar(jarvis_db_entry_json)\n",
174175
" return (esse, poscar)\n",
175176
"\n",
177+
"\n",
176178
"esse_entries = list(map(lambda e: convert_jarvis_entry_to_esse(e)[0], jarvis_db_entries))\n",
177179
"poscars = list(map(lambda e: convert_jarvis_entry_to_esse(e)[1], jarvis_db_entries))"
178-
]
180+
],
181+
"outputs": [],
182+
"execution_count": null
179183
},
180184
{
181185
"cell_type": "markdown",
@@ -187,45 +191,22 @@
187191
},
188192
{
189193
"cell_type": "code",
190-
"execution_count": null,
191194
"id": "860b5c1b",
192195
"metadata": {},
193-
"outputs": [],
194196
"source": [
195-
"from src.utils import poscar_to_ase\n",
196-
"from ase.visualize import view\n",
197-
"from ase.io import write\n",
198-
"from ase.build import make_supercell\n",
199-
"from IPython.display import Image\n",
197+
"from utils.visualize import visualize_materials\n",
198+
"from mat3ra.made.tools.convert import from_poscar\n",
199+
"from mat3ra.made.material import Material\n",
200200
"\n",
201201
"# Uncomment to see the JSON\n",
202202
"# print(json.dumps(data, indent=4))\n",
203203
"\n",
204+
"materials = [Material(from_poscar(poscar)) for poscar in poscars]\n",
204205
"\n",
205-
"materials = list(map(lambda p: poscar_to_ase(p), poscars))\n",
206-
"\n",
207-
"def visualize_material(material, index: int, number_of_repetitions: int = 3):\n",
208-
" \"\"\"\n",
209-
" Visualize the material using ASE's visualization tool\n",
210-
" Repeat the unit cell to make it easier to see.\n",
211-
"\n",
212-
" Args:\n",
213-
" material: The material to visualize (Ase.Atoms object)\n",
214-
" index: The index of the material\n",
215-
" number_of_repetitions: The number of unit cell repetitions to visualize\n",
216-
" \"\"\"\n",
217-
" # Set the number of unit cell repetition for the structure to make it easier to see\n",
218-
" n = number_of_repetitions\n",
219-
" material_repeat = make_supercell(material, [[n,0,0],[0,n,0],[0,0,n]])\n",
220-
" filename = f\"material-{index}.png\"\n",
221-
" write(filename, material_repeat)\n",
222-
" img = Image(filename=filename)\n",
223-
" print(filename, \"-\", material.symbols)\n",
224-
" display(img)\n",
225-
"\n",
226-
"for idx, material in enumerate(materials):\n",
227-
" visualize_material(material, idx)"
228-
]
206+
"visualize_materials(materials)"
207+
],
208+
"outputs": [],
209+
"execution_count": null
229210
},
230211
{
231212
"cell_type": "markdown",
@@ -237,16 +218,15 @@
237218
},
238219
{
239220
"cell_type": "code",
240-
"execution_count": null,
241221
"id": "00b187ab",
242222
"metadata": {},
243-
"outputs": [],
244223
"source": [
245-
"from utils.jupyterlite import set_data\n",
224+
"from utils.jupyterlite import set_materials\n",
246225
"\n",
247-
"output_materials = esse_entries\n",
248-
"set_data(\"materials\", output_materials)"
249-
]
226+
"set_materials(materials)"
227+
],
228+
"outputs": [],
229+
"execution_count": null
250230
}
251231
],
252232
"metadata": {

0 commit comments

Comments
 (0)