/
structure_library.py
140 lines (128 loc) · 5.2 KB
/
structure_library.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- coding: utf-8 -*-
# Copyright 2017-2022 The diffsims developers
#
# This file is part of diffsims.
#
# diffsims is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# diffsims is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with diffsims. If not, see <http://www.gnu.org/licenses/>.
class StructureLibrary:
"""
A dictionary containing all the structures and their associated rotations
in the .struct_lib attribute.
Attributes
----------
identifiers : list of strings/ints
A list of phase identifiers referring to different atomic structures.
structures : list of diffpy.structure.Structure objects.
A list of diffpy.structure.Structure objects describing the atomic
structure associated with each phase in the library.
orientations : list
A list over identifiers of lists of euler angles (as tuples) in the rzxz
convention and in degrees.
"""
def __init__(self, identifiers, structures, orientations):
if len(identifiers) != len(structures):
raise ValueError(
"Number of identifiers ({}) and structures ({}) must be the same.".format(
len(identifiers), len(structures)
)
)
if len(identifiers) != len(orientations):
raise ValueError(
"Number of identifiers ({}) and orientations ({}) must be the same.".format(
len(identifiers), len(orientations)
)
)
self.identifiers = identifiers
self.structures = structures
self.orientations = orientations
# Create the actual dictionary
self.struct_lib = dict()
for ident, struct, ori in zip(identifiers, structures, orientations):
self.struct_lib[ident] = (struct, ori)
@classmethod
def from_orientation_lists(cls, identifiers, structures, orientations):
"""
Creates a structure library from "manual" orientation lists
Parameters
----------
identifiers : list of strings/ints
A list of phase identifiers referring to different atomic structures.
structures : list of diffpy.structure.Structure objects.
A list of diffpy.structure.Structure objects describing the atomic
structure associated with each phase in the library.
orientations : list of lists of tuples
A list over identifiers of lists of euler angles (as tuples) in the rzxz
convention and in degrees.
Returns
-------
StructureLibrary
"""
return cls(identifiers, structures, orientations)
@classmethod
def from_crystal_systems(
cls, identifiers, structures, systems, resolution, equal="angle"
):
"""
Creates a structure library from crystal system derived orientation lists
Parameters
----------
identifiers : list of strings/ints
A list of phase identifiers referring to different atomic structures.
structures : list of diffpy.structure.Structure objects.
A list of diffpy.structure.Structure objects describing the atomic
structure associated with each phase in the library.
systems : list
A list over indentifiers of crystal systems
resolution : float
resolution in degrees
equal : str
Default is 'angle'
Raises
------
NotImplementedError:
"This function has been removed in version 0.3.0, in favour of creation from orientation lists"
"""
raise NotImplementedError(
"This function has been removed in version 0.3.0, in favour of creation from orientation lists"
)
def get_library_size(self, to_print=False):
"""
Returns the the total number of orientations in the
current StructureLibrary object. Will also print the number of orientations
for each identifier in the library if the to_print==True
Parameters
----------
to_print : bool
Default is 'False'
Returns
-------
size_library : int
Total number of entries in the current StructureLibrary object.
"""
size_library = 0
for i in range(len(self.orientations)):
if len(self.orientations[i]) == 1:
size_library += 1
else:
size_library += len(self.orientations[i])
if to_print == True:
print(
self.identifiers[i],
"has",
len(self.orientations[i]),
"number of entries.",
)
if to_print == True:
print("\nIn total:", size_library, "number of entries")
return size_library