Skip to content

Commit 2e5530d

Browse files
authored
Merge pull request #187 from cadenmyers13/ase-adapter
feat: Add functions for getting information from `Structure`
2 parents 8935b1f + 65d2729 commit 2e5530d

File tree

3 files changed

+463
-68
lines changed

3 files changed

+463
-68
lines changed

news/ase-adapter.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
**Added:**
2+
3+
* Added ``Structure.get_lattice_vectors()`` method to return the lattice vectors.
4+
* Added ``Structure.get_lattice_vector_angles()`` method to return the angles between the lattice vectors.
5+
* Added ``Structure.get_isotropic_displacement_parameters()`` method to return the isotropic displacement parameters.
6+
* Added ``Structure.get_anisotropic_displacement_parameters()`` method to return the anisotropic displacement parameters.
7+
* Added ``Structure.get_occupancies()`` method to return the occupancies of the sites.
8+
* Added ``Structure.get_cartesian_coordinates()`` method to return the Cartesian coordinates of the sites.
9+
* Added ``Structure.get_fractional_coordinates()`` method to return the fractional coordinates of the sites.
10+
* Added ``Structure.get_chemical_symbols()`` method to return the chemical symbols of the sites.
11+
12+
**Changed:**
13+
14+
* <news item>
15+
16+
**Deprecated:**
17+
18+
* <news item>
19+
20+
**Removed:**
21+
22+
* <news item>
23+
24+
**Fixed:**
25+
26+
* <news item>
27+
28+
**Security:**
29+
30+
* <news item>

src/diffpy/structure/structure.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,135 @@ def get_last_atom(self):
236236
last_atom = self[-1]
237237
return last_atom
238238

239+
def get_chemical_symbols(self):
240+
"""Return list of chemical symbols for all `Atoms` in this
241+
structure.
242+
243+
Returns
244+
-------
245+
list of str
246+
The list of chemical symbols for all `Atoms` in this structure.
247+
"""
248+
symbols_with_charge = [a.element for a in self]
249+
symbols = [atom_bare_symbol(sym) for sym in symbols_with_charge]
250+
return symbols
251+
252+
def get_fractional_coordinates(self):
253+
"""Return array of fractional coordinates of all `Atoms` in this
254+
structure.
255+
256+
Returns
257+
-------
258+
numpy.ndarray
259+
The array of fractional coordinates of all `Atoms` in this structure
260+
in the same order as `Structure.get_chemical_symbols()`.
261+
"""
262+
coords = numpy.array([a.xyz for a in self])
263+
return coords
264+
265+
def get_cartesian_coordinates(self):
266+
"""Return array of Cartesian coordinates of all `Atoms` in this
267+
structure.
268+
269+
Returns
270+
-------
271+
numpy.ndarray
272+
The array of Cartesian coordinates of all `Atoms` in this structure
273+
in the same order as `Structure.get_chemical_symbols()`.
274+
"""
275+
cartn_coords = numpy.array([a.xyz_cartn for a in self])
276+
return cartn_coords
277+
278+
def get_anisotropic_displacement_parameters(self, return_array=False):
279+
"""Return the anisotropic displacement parameters for all atoms.
280+
281+
Parameters
282+
----------
283+
return_array : bool, optional
284+
If True, return anisotropic displacement parameters as a numpy array instead of a dictionary.
285+
286+
Returns
287+
-------
288+
dict
289+
The dictionary of anisotropic displacement parameters for all atoms in this structure.
290+
Keys are of the form 'Element_i_Ujk', e.g. 'C_0_11', 'C_0_12'.
291+
"""
292+
if return_array:
293+
aniso_adps = numpy.array([a.U for a in self])
294+
return aniso_adps
295+
else:
296+
adp_dict = {}
297+
for i, atom in enumerate(self):
298+
element = atom_bare_symbol(atom.element)
299+
adp_dict[f"{element}_{i}_11"] = self.U11[i]
300+
adp_dict[f"{element}_{i}_22"] = self.U22[i]
301+
adp_dict[f"{element}_{i}_33"] = self.U33[i]
302+
adp_dict[f"{element}_{i}_12"] = self.U12[i]
303+
adp_dict[f"{element}_{i}_13"] = self.U13[i]
304+
adp_dict[f"{element}_{i}_23"] = self.U23[i]
305+
return adp_dict
306+
307+
def get_isotropic_displacement_parameters(self, return_array=False):
308+
"""Return a the isotropic displacement parameters for all atoms.
309+
310+
Parameters
311+
----------
312+
return_array : bool, optional
313+
If True, return isotropic displacement parameters as a numpy array instead of a dictionary.
314+
Default is False.
315+
316+
Returns
317+
-------
318+
dict
319+
The dictionary of isotropic displacement parameters for all atoms in this structure.
320+
Keys are of the form 'Element_i_Uiso', e.g. 'C_0_Uiso'.
321+
"""
322+
if return_array:
323+
iso_adps = numpy.array([a.Uisoequiv for a in self])
324+
return iso_adps
325+
else:
326+
iso_dict = {}
327+
for i, atom in enumerate(self):
328+
element = atom_bare_symbol(atom.element)
329+
iso_dict[f"{element}_{i+1}_Uiso"] = self.Uisoequiv[i]
330+
return iso_dict
331+
332+
def get_occupancies(self):
333+
"""Return array of occupancies of all `Atoms` in this structure.
334+
335+
Returns
336+
-------
337+
numpy.ndarray
338+
The array of occupancies of all `Atoms` in this structure.
339+
"""
340+
occupancies = numpy.array([a.occupancy for a in self])
341+
return occupancies
342+
343+
def get_lattice_vectors(self):
344+
"""Return array of lattice vectors for this structure.
345+
346+
Returns
347+
-------
348+
numpy.ndarray
349+
The array of lattice vectors for this structure.
350+
"""
351+
lattice_vectors = self.lattice.base
352+
return lattice_vectors
353+
354+
def get_lattice_vector_angles(self):
355+
"""Return array of lattice vector angles for this structure.
356+
357+
Returns
358+
-------
359+
numpy.ndarray
360+
The array of lattice vector angles for this structure.
361+
"""
362+
a, b, c = self.lattice.base
363+
alpha = self.lattice.angle(b, c)
364+
beta = self.lattice.angle(a, c)
365+
gamma = self.lattice.angle(a, b)
366+
return numpy.array([alpha, beta, gamma])
367+
239368
def assign_unique_labels(self):
240369
"""Set a unique label string for each `Atom` in this structure.
241370

0 commit comments

Comments
 (0)