/
structure.py
111 lines (85 loc) · 3.74 KB
/
structure.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
from ray_tracing.rt import RTSurface
from solcore.structure import Layer
class Structure(list):
# both interfaces and bulk layers
def __init__(self, *args, **kwargs):
super(Structure, self).__init__(*args)
self.__dict__.update(kwargs)
self.labels = [None] * len(self)
# def append(self, new_layer, layer_label=None, repeats=1):
# # Pass the arguments to the superclass for extending
# for i in range(repeats):
# # Extend the structure labels
# self.labels.append(layer_label)
# super(Structure, self).append(new_layer)
#
# def append_multiple(self, layers, layer_labels=None, repeats=1):
#
# assert type(layers) == type([]), "`append_multiple` only accepts lists for the first argument."
#
# if layer_labels is not None:
# assert len(layers) == len(
# layer_labels), "When using `layer_labels` keyword a label must be specified for each layer added i.e. layers and layer_labels must have the same number of elements. Either fix this or simply do not assign any labels (i.e. layer_labels=None)."
#
# for i in range(repeats):
# # Extend the structure by appending layers
# self.extend(layers)
#
# # Extend the structure labels by appending an equal number of None values
# # or by appending the actual labels.
# if layer_labels is None:
# self.labels.extend([None] * len(layers))
# else:
# self.labels.extend(layer_labels)
def __str__(self):
layer_info = [" {} {}".format(
layer,
self.labels[i] if self.labels[i] is not None else "",
) for i, (layer, label) in enumerate(zip(self, self.labels))]
return "<Structure object\n{}\n{}>".format(str(self.__dict__), "\n".join(layer_info))
class BulkLayer:
""" Class that stores the information about layers of materials, such as thickness and composition.
It is the building block of the 'Structures' """
def __init__(self, width, material, **kwargs):
""" Layer class constructor.
"""
self.width = width
self.material = material
self.__dict__.update(kwargs)
class Interface:
def __init__(self, method, layers=[], texture=None, prof_layers=[], coherent=True, **kwargs):
""" Layer class constructor.
"""
self.method = method
self.__dict__.update(kwargs)
self.layers = layers
self.texture = texture # for ray tracing
self.prof_layers = prof_layers # in which layers of the interface (1-indexed) should absorption be calculated?
self.materials = []
self.n_depths = []
self.widths = []
self.coherent = coherent
cum_width = 0
if layers is not None:
for i, element in enumerate(layers):
if type(element) == Layer:
cum_width = cum_width + element.width*1e6
self.materials.append(element.material)
#self.n_depths.append(element.n_depths)
self.widths.append(element.width)
else:
self.widths.append(element[0])
self.materials.append(element[1:3])
#if texture is not None:
# Points = texture.Points
# Points[:, 2] = Points[:, 2] - cum_width
# self.texture = RTSurface(Points)
class Texture:
def __init__(self, texture):
self.texture = texture
class RTgroup:
def __init__(self, textures, materials=[], widths=[], depth_spacing=1):
self.materials = materials
self.textures = textures
self.widths = widths
self.depth_spacing = depth_spacing