/
structure_library.py
114 lines (104 loc) · 4.15 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
# -*- coding: utf-8 -*-
# Copyright 2017-2024 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/>.
__all__ = [
"StructureLibrary",
]
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)
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