PyGamLab 1.5.9__py3-none-any.whl → 1.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
PyGamLab/__init__.py CHANGED
@@ -43,11 +43,11 @@ Y88b. 88 Y88..88PP. 888 888 888 888...... Y88..88PP. 888 888
43
43
  '''
44
44
 
45
45
 
46
- __version__ = "1.5.9"
46
+ __version__ = "1.6.1"
47
47
 
48
48
 
49
49
 
50
- __all__ = ["Constants", "Converters", "Functions", "Data_Analysis","structure","database"]
50
+ __all__ = ["Constants", "Converters", "Functions", "Data_Analysis","structures","databases"]
51
51
 
52
52
 
53
53
 
@@ -0,0 +1,447 @@
1
+ from aflow import search, K
2
+
3
+
4
+
5
+
6
+ class Aflow_Explorer:
7
+ """
8
+ A unified interface to search and fetch various material properties from the AFLOW database.
9
+
10
+ This class allows searching by species or chemical formula, and fetching electronic, mechanical,
11
+ thermodynamic, and structural properties of materials using AFLOW keys.
12
+
13
+ Attributes
14
+ ----------
15
+ all_entries : list
16
+ Stores the results of the latest search query.
17
+ results : dict
18
+ Stores the latest fetched data for a material.
19
+
20
+ Examples
21
+ --------
22
+ >>> explorer = Aflow_Explorer()
23
+ >>> results = explorer.search_materials(formula="MoS2")
24
+ >>> explorer.fetch_electronic_properties("aflow-123")
25
+ {'formula': 'MoS2', 'bandgap': 1.23, ...}
26
+ >>> all_data = explorer.fetch_all_data("aflow-123")
27
+ >>> all_data['electronic_prop']['bandgap']
28
+ 1.23
29
+ """
30
+ def __init__(self):
31
+ """
32
+ Initialize the AFLOW Explorer.
33
+ """
34
+
35
+ self.all_entries = None
36
+ self.results = {
37
+ 'electronic_prop': {},
38
+ 'mechanical_prop': {},
39
+ 'thermo_prop': {},
40
+ 'structure': {},
41
+ 'meta_data': {}
42
+ }
43
+
44
+ def search_materials(self, species=None, formula=None, max_results=5, batch_size=10,description=True):
45
+ """
46
+ Search for materials in AFLOW by species or chemical formula.
47
+
48
+ Parameters
49
+ ----------
50
+ species : str or list[str], optional
51
+ Element(s) to search for.
52
+ formula : str, optional
53
+ Chemical formula to search for.
54
+ max_results : int, default 5
55
+ Maximum number of results to return.
56
+ batch_size : int, default 10
57
+ Number of entries retrieved per batch from AFLOW.
58
+ description : bool, default True
59
+ If True, returns detailed information for each entry.
60
+ If False, returns only AFLOW unique IDs (AUIDs).
61
+
62
+ Returns
63
+ -------
64
+ list of dict
65
+ List of results containing AUID and optionally detailed description.
66
+
67
+ Example
68
+ -------
69
+ >>> explorer = Aflow_Explorer()
70
+ >>> explorer.search_materials(formula="MoS2", max_results=3)
71
+ [{'auid': 'aflow-123', 'prototype': 'MoS2', 'spacegroup_relax': 187, ...}]
72
+ """
73
+ # -------------------- Clean .select() --------------------
74
+ self.batch_size=batch_size
75
+
76
+ query = (
77
+ search(batch_size=self.batch_size)
78
+ .select(
79
+ K.auid, K.compound, K.species, K.composition,
80
+
81
+ # Electronic
82
+ K.Egap, K.Egap_fit, K.Egap_type,
83
+ K.delta_electronic_energy_convergence, K.delta_electronic_energy_threshold,
84
+ K.ldau_TLUJ, K.dft_type,
85
+ K.bader_atomic_volumes, K.bader_net_charges,
86
+ K.spinD, K.spinF, K.spin_atom, K.spin_cell,
87
+ K.scintillation_attenuation_length,
88
+
89
+ # Mechanical
90
+ K.ael_bulk_modulus_reuss, K.ael_bulk_modulus_voigt, K.ael_bulk_modulus_vrh,
91
+ K.ael_shear_modulus_reuss, K.ael_shear_modulus_voigt, K.ael_shear_modulus_vrh,
92
+ K.ael_poisson_ratio, K.ael_elastic_anisotropy,
93
+ K.stress_tensor, K.forces,
94
+ K.Pulay_stress, K.pressure, K.pressure_residual,
95
+
96
+ # Thermodynamic
97
+ K.agl_acoustic_debye, K.agl_debye,
98
+ K.agl_gruneisen,
99
+ K.agl_heat_capacity_Cp_300K, K.agl_heat_capacity_Cv_300K,
100
+ K.agl_thermal_conductivity_300K, K.agl_thermal_expansion_300K,
101
+ K.agl_bulk_modulus_isothermal_300K, K.agl_bulk_modulus_static_300K,
102
+ K.eentropy_atom, K.eentropy_cell,
103
+ K.enthalpy_atom, K.enthalpy_cell,
104
+ K.enthalpy_formation_atom, K.enthalpy_formation_cell,
105
+ K.energy_atom, K.energy_cell, K.energy_cutoff,
106
+ K.entropic_temperature,
107
+
108
+ # Structural
109
+ K.Bravais_lattice_orig, K.Bravais_lattice_relax,
110
+ K.Pearson_symbol_orig, K.Pearson_symbol_relax,
111
+ K.lattice_system_orig, K.lattice_system_relax,
112
+ K.lattice_variation_orig, K.lattice_variation_relax,
113
+ K.spacegroup_orig, K.spacegroup_relax,
114
+ K.sg, K.sg2,
115
+ K.prototype, K.stoich, K.stoichiometry, K.geometry,
116
+ K.natoms, K.nspecies, K.nbondxx, K.species_pp, K.species_pp_ZVAL, K.species_pp_version,
117
+ K.positions_cartesian, K.positions_fractional,K.valence_cell_iupac, K.valence_cell_std,
118
+ K.volume_atom, K.volume_cell,K.density
119
+ )
120
+ )
121
+
122
+ self.batch_size = batch_size
123
+
124
+ # -------------------- Filters --------------------
125
+ if species:
126
+ if isinstance(species, list):
127
+ for el in species:
128
+ query = query.filter(K.species == el)
129
+ else:
130
+ query = query.filter(K.species == species)
131
+
132
+ if formula:
133
+ query = query.filter(K.compound == formula)
134
+
135
+ all_entries = []
136
+ try:
137
+ for i, entry in enumerate(query):
138
+ if i < max_results:
139
+ all_entries.append(entry)
140
+ else:
141
+ break
142
+ self.all_entries = all_entries
143
+
144
+ #return all_entries
145
+
146
+ if description==True:
147
+ results=[]
148
+ for entry in self.all_entries:
149
+ results.append({'auid':getattr(entry, 'auid', None),
150
+ 'prototype':getattr(entry, 'prototype', None),
151
+ 'spacegroup_relax':getattr(entry, 'spacegroup_relax', None),
152
+ 'dft_type':getattr(entry, 'dft_type', None),
153
+ 'spinD':getattr(entry, 'spinD', None),
154
+ 'spinF':getattr(entry, 'spinF', None),
155
+ 'enthalpy_formation_cell':getattr(entry, 'enthalpy_formation_cell', None),
156
+ 'natoms':getattr(entry, 'natoms', None)})
157
+ return results
158
+
159
+ else:
160
+ results=[]
161
+ for entry in self.all_entries:
162
+ results.append({'auid':getattr(entry, 'auid', None)})
163
+ return results
164
+
165
+ # return
166
+ except AssertionError:
167
+ print("No results found for this query.")
168
+ return
169
+
170
+ # -------------------- Electronic properties --------------------
171
+ def fetch_electronic_properties(self,auid):
172
+ """
173
+ Fetch electronic properties for a given AFLOW AUID.
174
+
175
+ Parameters
176
+ ----------
177
+ auid : str
178
+ AFLOW unique ID of the material.
179
+
180
+ Returns
181
+ -------
182
+ dict
183
+ Dictionary containing electronic properties such as bandgap, spin polarization, etc.
184
+
185
+ Example
186
+ -------
187
+ >>> explorer.fetch_electronic_properties("aflow-123")
188
+ {'formula': 'MoS2', 'bandgap': 1.23, ...}
189
+ """
190
+ if self.all_entries is None:
191
+ print("First use search_materials function")
192
+ return None
193
+
194
+ #entry = next((e for e in self.all_entries if e.get("auid") == auid), None)
195
+
196
+ for r in self.all_entries:
197
+ if r.auid==auid:
198
+ entry=r
199
+
200
+
201
+
202
+
203
+ if entry is None:
204
+ print(f"auid {auid} not found in current search results.")
205
+ return None
206
+
207
+
208
+
209
+ electronic_results={'formula': getattr(entry, 'compound', None),
210
+ 'bandgap': getattr(entry, 'Egap', None),
211
+ 'bandgap_fit': getattr(entry, 'Egap_fit', None),
212
+ 'bandgap_type': getattr(entry, 'Egap_type', None),
213
+ 'delta_elec_energy_convergence': getattr(entry, 'delta_electronic_energy_convergence', None),
214
+ 'delta_elec_energy_threshold': getattr(entry, 'delta_electronic_energy_threshold', None),
215
+ 'ldau_TLUJ': getattr(entry, 'ldau_TLUJ', None),
216
+ 'dft_type': getattr(entry, 'dft_type', None),
217
+ 'bader_atomic_volumes': getattr(entry, 'bader_atomic_volumes', None),
218
+ 'bader_net_charges': getattr(entry, 'bader_net_charges', None),
219
+ 'spinD': getattr(entry, 'spinD', None),
220
+ 'spinF': getattr(entry, 'spinF', None),
221
+ 'spin_atom': getattr(entry, 'spin_atom', None),
222
+ 'spin_cell': getattr(entry, 'spin_cell', None),
223
+ 'scintillation_attenuation_length': getattr(entry, 'scintillation_attenuation_length', None)}
224
+
225
+ self.results['electronic_prop'] = electronic_results
226
+ return electronic_results
227
+
228
+ # -------------------- Mechanical properties --------------------
229
+ def fetch_mechanical_properties(self,auid):
230
+ """
231
+ Fetch mechanical properties for a given AFLOW AUID.
232
+
233
+ Parameters
234
+ ----------
235
+ auid : str
236
+ AFLOW unique ID of the material.
237
+
238
+ Returns
239
+ -------
240
+ dict
241
+ Dictionary containing bulk modulus, shear modulus, elastic tensors, etc.
242
+ """
243
+ if self.all_entries is None:
244
+ print("First use search_materials function")
245
+ return None
246
+
247
+
248
+
249
+ #entry = next((e for e in self.all_entries if e.get("auid") == auid), None)
250
+
251
+ for r in self.all_entries:
252
+ if r.auid==auid:
253
+ entry=r
254
+
255
+ if entry is None:
256
+ print(f"auid {auid} not found in current search results.")
257
+ return None
258
+
259
+
260
+ mechanical_results={ 'formula': getattr(entry, 'compound', None),
261
+ 'bulk_modulus_reuss': getattr(entry, 'ael_bulk_modulus_reuss', None),
262
+ 'bulk_modulus_voigt': getattr(entry, 'ael_bulk_modulus_voigt', None),
263
+ 'bulk_modulus_vrh': getattr(entry, 'ael_bulk_modulus_vrh', None),
264
+ 'shear_modulus_reuss': getattr(entry, 'ael_shear_modulus_reuss', None),
265
+ 'shear_modulus_voigt': getattr(entry, 'ael_shear_modulus_voigt', None),
266
+ 'shear_modulus_vrh': getattr(entry, 'ael_shear_modulus_vrh', None),
267
+ 'poisson_ratio': getattr(entry, 'ael_poisson_ratio', None),
268
+ 'elastic_anisotropy': getattr(entry, 'ael_elastic_anisotropy', None),
269
+ 'stress_tensor': getattr(entry, 'stress_tensor', None),
270
+ 'forces': getattr(entry, 'forces', None),
271
+ 'Pulay_stress': getattr(entry, 'Pulay_stress', None),
272
+ 'pressure': getattr(entry, 'pressure', None),
273
+ 'pressure_residual': getattr(entry, 'pressure_residual', None)}
274
+
275
+ self.results['mechanical_prop'] = mechanical_results
276
+ return mechanical_results
277
+
278
+ # -------------------- Thermodynamic properties --------------------
279
+ def fetch_thermodynamic_properties(self,auid):
280
+ """
281
+ Fetch thermodynamic properties for a given AFLOW AUID.
282
+
283
+ Parameters
284
+ ----------
285
+ auid : str
286
+ AFLOW unique ID of the material.
287
+
288
+ Returns
289
+ -------
290
+ dict
291
+ Dictionary containing Debye temperature, heat capacity, enthalpy, and related properties.
292
+ """
293
+ if self.all_entries is None:
294
+ print("First use search_materials function")
295
+ return None
296
+
297
+
298
+ #entry = next((e for e in self.all_entries if e.get("auid") == auid), None)
299
+
300
+ for r in self.all_entries:
301
+ if r.auid==auid:
302
+ entry=r
303
+
304
+ if entry is None:
305
+ print(f"auid {auid} not found in current search results.")
306
+ return None
307
+
308
+
309
+ thermo_results={'formula': getattr(entry, 'compound', None),
310
+ 'acoustic_debye': getattr(entry, 'agl_acoustic_debye', None),
311
+ 'debye': getattr(entry, 'agl_debye', None),
312
+ 'gruneisen': getattr(entry, 'agl_gruneisen', None),
313
+ 'heat_capacity_Cp_300K': getattr(entry, 'agl_heat_capacity_Cp_300K', None),
314
+ 'heat_capacity_Cv_300K': getattr(entry, 'agl_heat_capacity_Cv_300K', None),
315
+ 'thermal_conductivity_300K': getattr(entry, 'agl_thermal_conductivity_300K', None),
316
+ 'thermal_expansion_300K': getattr(entry, 'agl_thermal_expansion_300K', None),
317
+ 'bulk_modulus_isothermal_300K': getattr(entry, 'agl_bulk_modulus_isothermal_300K', None),
318
+ 'bulk_modulus_static_300K': getattr(entry, 'agl_bulk_modulus_static_300K', None),
319
+ 'entropy_atom': getattr(entry, 'eentropy_atom', None),
320
+ 'entropy_cell': getattr(entry, 'eentropy_cell', None),
321
+ 'enthalpy_atom': getattr(entry, 'enthalpy_atom', None),
322
+ 'enthalpy_cell': getattr(entry, 'enthalpy_cell', None),
323
+ 'enthalpy_formation_atom': getattr(entry, 'enthalpy_formation_atom', None),
324
+ 'enthalpy_formation_cell': getattr(entry, 'enthalpy_formation_cell', None),
325
+ 'energy_atom': getattr(entry, 'energy_atom', None),
326
+ 'energy_cell': getattr(entry, 'energy_cell', None),
327
+ 'energy_cutoff': getattr(entry, 'energy_cutoff', None),
328
+ 'entropic_temperature': getattr(entry, 'entropic_temperature', None)}
329
+
330
+ self.results['thermo_prop'] = thermo_results
331
+ return thermo_results
332
+
333
+ # -------------------- Structural properties --------------------
334
+ def fetch_structure(self,auid):
335
+ """
336
+ Fetch structural properties for a given AFLOW AUID.
337
+
338
+ Parameters
339
+ ----------
340
+ auid : str
341
+ AFLOW unique ID of the material.
342
+
343
+ Returns
344
+ -------
345
+ dict
346
+ Dictionary containing lattice, space group, atomic positions, density, and valence info.
347
+ """
348
+ if self.all_entries is None:
349
+ print("First use search_materials function")
350
+ return None
351
+
352
+ # entry = next((e for e in self.all_entries if e.get("auid") == auid), None)
353
+ for r in self.all_entries:
354
+ if r.auid==auid:
355
+ entry=r
356
+
357
+ if entry is None:
358
+ print(f"auid {auid} not found in current search results.")
359
+ return None
360
+
361
+
362
+ structure_results={'formula': getattr(entry, 'compound', None),
363
+ 'Bravais_lattice_orig': getattr(entry, 'Bravais_lattice_orig', None),
364
+ 'Bravais_lattice_relax': getattr(entry, 'Bravais_lattice_relax', None),
365
+ 'Pearson_symbol_orig': getattr(entry, 'Pearson_symbol_orig', None),
366
+ 'Pearson_symbol_relax': getattr(entry, 'Pearson_symbol_relax', None),
367
+ 'lattice_system_orig': getattr(entry, 'lattice_system_orig', None),
368
+ 'lattice_system_relax': getattr(entry, 'lattice_system_relax', None),
369
+ 'lattice_variation_orig': getattr(entry, 'lattice_variation_orig', None),
370
+ 'lattice_variation_relax': getattr(entry, 'lattice_variation_relax', None),
371
+ 'spacegroup_orig': getattr(entry, 'spacegroup_orig', None),
372
+ 'spacegroup_relax': getattr(entry, 'spacegroup_relax', None),
373
+ 'sg': getattr(entry, 'sg', None),
374
+ 'sg2': getattr(entry, 'sg2', None),
375
+ 'prototype': getattr(entry, 'prototype', None),
376
+ 'stoich': getattr(entry, 'stoich', None),
377
+ 'stoichiometry': getattr(entry, 'stoichiometry', None),
378
+ 'geometry': getattr(entry, 'geometry', None),
379
+ 'natoms': getattr(entry, 'natoms', None),
380
+ 'nspecies': getattr(entry, 'nspecies', None),
381
+ 'nbondxx': getattr(entry, 'nbondxx', None),
382
+ 'composition': getattr(entry, 'composition', None),
383
+ 'compound': getattr(entry, 'compound', None),
384
+ 'species': getattr(entry, 'species', None),
385
+ "species_pp": getattr(entry, "species_pp", None),
386
+ "species_pp_ZVAL": getattr(entry, "species_pp_ZVAL", None),
387
+ "species_pp_version": getattr(entry, "species_pp_version", None),
388
+ "positions_cartesian": getattr(entry, "positions_cartesian", None),
389
+ "positions_fractional": getattr(entry, "positions_fractional", None),
390
+
391
+ # Valence info
392
+ "valence_cell_iupac": getattr(entry, "valence_cell_iupac", None),
393
+ "valence_cell_std": getattr(entry, "valence_cell_std", None),
394
+ "volume_atom": getattr(entry, "volume_atom", None),
395
+ "volume_cell": getattr(entry, "volume_cell", None),
396
+ "density": getattr(entry, "density", None)}
397
+
398
+ self.results['structure'] = structure_results
399
+ return structure_results
400
+ # -------------------- Aggregate all data --------------------
401
+ def fetch_all_data(self,auid):
402
+ """
403
+ Fetch all available data (electronic, mechanical, thermodynamic, structure) for a material.
404
+
405
+ Parameters
406
+ ----------
407
+ auid : str
408
+ AFLOW unique ID of the material.
409
+
410
+ Returns
411
+ -------
412
+ dict
413
+ Dictionary with keys: 'electronic_prop', 'mechanical_prop', 'thermo_prop', 'structure'.
414
+
415
+ Example
416
+ -------
417
+ >>> all_data = explorer.fetch_all_data("aflow-123")
418
+ >>> all_data['electronic_prop']['bandgap']
419
+ 1.23
420
+ """
421
+ if self.all_entries is None:
422
+ print('first use search_materials function')
423
+ return None
424
+
425
+ electro=self.fetch_electronic_properties(auid)
426
+ mechanical=self.fetch_mechanical_properties(auid)
427
+ thermo=self.fetch_thermodynamic_properties(auid)
428
+ structure=self.fetch_structure(auid)
429
+
430
+ return self.results
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+