-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMaskMaker.py
More file actions
4565 lines (3742 loc) · 201 KB
/
Copy pathMaskMaker.py
File metadata and controls
4565 lines (3742 loc) · 201 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from math import sin, cos, pi, floor, acos, atan, degrees, radians
from numpy import linspace
import random
from numpy import sqrt
from . import sdxf
from .alphanum import alphanum_dict
class MaskError:
"""MaskError is an exception to be raised whenever invalid parameters are
used in one of the MaskMaker functions, value is just a string"""
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
# ===============================================================================
# POINT-WISE OPERATIONS
# ===============================================================================
def distance(tuple1, tuple2):
dx = tuple1[0] - tuple2[0]
dy = tuple1[1] - tuple2[1]
return sqrt(dx ** 2 + dy ** 2)
def ang2pt(direction, distance):
theta = pi * direction / 180
dx = distance * cos(theta)
dy = distance * sin(theta)
return (dx, dy)
def rotate_pt(p, angle, center=(0, 0)):
"""rotates point p=(x,y) about point center (defaults to (0,0)) by CCW angle (in degrees)"""
dx = p[0] - center[0]
dy = p[1] - center[1]
theta = pi * angle / 180.
return (center[0] + dx * cos(theta) - dy * sin(theta), center[1] + dx * sin(theta) + dy * cos(theta))
def rotate_pts(points, angle, center=(0, 0)):
"""Rotates an array of points one by one using rotate_pt"""
return [rotate_pt(p, angle, center) for p in points]
def translate_pt_by_r(p, r, deg):
"""Translate point p=(x,y) by r in direction"""
theta = pi * deg / 180
return (p[0] + cos(theta) * r, p[1] + sin(theta) * r)
def translate_pt(p, offset):
"""Translates point p=(x,y) by offset=(x,y)"""
return (p[0] + offset[0], p[1] + offset[1])
def translate_pts(points, offset):
"""Translates an array of points one by one using translate_pt"""
return [translate_pt(p, offset) for p in points]
def orient_pt(p, angle, offset):
"""Orient_pt rotates point p=(x,y) by angle (in degrees) and then translates it to offset=(x,y)"""
return translate_pt(rotate_pt(p, angle), offset)
def orient_pts(points, angle, offset):
"""Orients an array of points one by one using orient_pt"""
return [orient_pt(p, angle, offset) for p in points]
def scale_pt(p, scale):
"""Scales p=(x,y) by scale"""
return (p[0] * scale[0], p[1] * scale[1])
def scale_pts(points, scale):
"""Scales an array of points one by one using scale_pt"""
return [scale_pt(p, scale) for p in points]
def mirror_pt(p, axis_angle, axis_pt):
"""Mirrors point p about a line at angle "axis_angle" intercepting point "axis_pt" """
theta = axis_angle * pi / 180.
return (axis_pt[0] + (-axis_pt[0] + p[0]) * cos(2 * theta) + (-axis_pt[1] + p[1]) * sin(2 * theta),
p[1] + 2 * (axis_pt[1] - p[1]) * cos(theta) ** 2 + (-axis_pt[0] + p[0]) * sin(2 * theta))
def mirror_pts(points, axis_angle, axis_pt):
"""Mirrors an array of points one by one using mirror_pt"""
return [mirror_pt(p, axis_angle, axis_pt) for p in points]
def middle(point1, point2):
"""Returns the point inbetween the two points"""
return [(point1[0] + point2[0]) / 2., (point1[1] + point2[1]) / 2.]
# ===============================================================================
# MASK- and CHIP GENERATION
# ===============================================================================
class WaferMask(sdxf.Drawing):
"""Mask class for placing chips on a wafer with a flat.
Contains functions which:
- layout the chips,
- add chips to the mask
- create a manifest of the mask.
- etchtype 'False' allows you to make a chip without the dicing borders for a positive mask
- etchtype 'True' is the standard version with dicing borders
"""
def __init__(self, name, diameter=50800., flat_angle=90., flat_distance=24100., wafer_padding=2000,
chip_size=(7000., 2000.), dicing_border=200, textsize=(800, 800),
etchtype=True, wafer_edge=True, dashed_dicing_border=0,
two_layer=False, solid=False):
sdxf.Drawing.__init__(self)
name = name.upper()
self.name = name
self.fileName = name + ".dxf"
self.diameter = diameter
self.flat_angle = flat_angle
self.flat_distance = flat_distance # - sin(flat_angle) * flat_angle #Hence when the flat_angle is 90, the chip flips. -Ge
self.textsize = textsize
self.border_width = 200 # width of line used to align wafer edge
self.chip_size = chip_size
self.dicing_border = dicing_border
self.die_size = (chip_size[0] + dicing_border, chip_size[1] + dicing_border)
self.wafer_padding = wafer_padding
self.buffer = self.wafer_padding # + self.dicing_border/2
self.etchtype = etchtype
self.dashed_dicing_border = dashed_dicing_border
self.solid = solid
start_angle = flat_angle + 180. / pi * acos(2. * flat_distance / diameter)
stop_angle = flat_angle - 180. / pi * acos(2. * flat_distance / diameter)
iradius = (diameter - self.border_width) / 2.
oradius = (diameter + self.border_width) / 2.
starti = rotate_pt((iradius, 0.), start_angle)
starto = rotate_pt((oradius, 0.), start_angle)
stopi = rotate_pt((iradius, 0.), stop_angle)
stopo = rotate_pt((oradius, 0.), stop_angle)
# print "wafer info: iradis=%f, oradius=%f, start_angle=%f, stop_angle=%f" %(iradius,oradius,start_angle,stop_angle)
stop_angle += 360
opts = arc_pts(start_angle, stop_angle, oradius)
ipts = arc_pts(stop_angle, start_angle, iradius)
pts = opts
pts.append(opts[0])
pts.append(ipts[-1])
pts.extend(ipts)
pts.append(opts[0])
# Writes the waffer shape
if wafer_edge:
self.append(sdxf.PolyLine(pts))
# self.append(sdxf.Arc((0.,0.),iradius,start_angle,stop_angle))
# self.append(sdxf.Line( [ stopi,stopo]))
# self.append(sdxf.Arc((0.,0.),oradius,start_angle,stop_angle))
# self.append(sdxf.Line( [ starti,starto]))
# self.append(sdxf.PolyLine([stopi,starti,starto,stopo]))
self.chip_points = self.get_chip_points()
self.chip_slots = self.chip_points.__len__()
self.current_point = 0
self.manifest = []
self.num_chips = 0
def randomize_layout(self, seed=124279234):
"""Shuffle the order of the chip_points array so that chips will be inserted (pseudo-)randomly"""
random.seed(seed)
for ii in range(10000):
i1 = rnd.randrange(self.chip_points.__len__())
i2 = rnd.randrange(self.chip_points.__len__())
tp = self.chip_points[i1]
self.chip_points[i1] = self.chip_points[i2]
self.chip_points[i2] = tp
def save_layout(self):
open(self.name + '_order.txt', 'w').writelines(
["%f, %f" % (x, y) for x, y in self.chip_points])
def load_layout(self, fname=None):
if not fname:
fname = self.name + '_order.txt'
self.chip_points = \
[map(float, line.split(',')) for line in open(fname, 'r').readlines()]
def randomize_layout_seeded(self):
"""Shuffle the order of the chip_points array so that chips will be inserted (pseudo-)randomly"""
rnd = random.Random()
rnd.seed(124279234)
for ii in range(10000):
i1 = rnd.randrange(self.chip_points.__len__())
i2 = rnd.randrange(self.chip_points.__len__())
tp = self.chip_points[i1]
self.chip_points[i1] = self.chip_points[i2]
self.chip_points[i2] = tp
# def label_chip(self,chip,pt,maskid,chipid):
# """Labels chip on wafer at position pt where pt is the bottom left corner of chip"""
# AlphaNumText(self,maskid,chip.textsize,pt)
# AlphaNumText(self,chipid,chip.textsize,pt)
def add_chip(self, chip, copies, label=False, savechip=True):
"""Adds chip design 'copies' times into mask. chip must have a unique name as it will be inserted as a block"""
if self.etchtype:
ChipBorder(chip, self.dicing_border / 2.)
if self.dashed_dicing_border > 0:
dashlayer = 'gap' if chip.two_layer else '0'
DashedChipBorder(chip, self.dicing_border / 2., layer=dashlayer, solid=self.solid)
if chip.two_layer:
for c, l in enumerate(['gap', 'pin', 'via']):
layer = sdxf.Layer(name=l, color=c + 1)
self.layers.append(layer)
self.blocks.append(chip.__dict__[l + '_layer'])
if chip not in self.blocks:
self.blocks.append(chip)
slots_remaining = self.chip_points.__len__() - self.current_point
for ii in range(copies):
if self.current_point >= self.chip_points.__len__():
raise MaskError(
"MaskError: Cannot add %d copies of chip '%s' Only %d slots on mask and %d remaining." % (
copies, chip.name, self.chip_points.__len__(), slots_remaining))
p = self.chip_points[self.current_point]
print(p, end=' ')
self.current_point += 1
self.append(sdxf.Insert(chip.name, point=p))
if chip.two_layer:
for c, l in enumerate(['gap', 'pin', 'via']):
self.append(sdxf.Insert(chip.name + l, point=p, layer=l))
if label:
chip.label_chip(self, maskid=self.name, chipid=chip.name + ' ' + str(100 + ii + 1)[-2:],
author=chip.author, offset=p)
self.num_chips += 1
self.manifest.append({'chip': chip, 'name': chip.name, 'copies': copies, 'short_desc': chip.short_description(),
'long_desc': chip.long_description()})
# print "%s\t%d\t%s" % (chip.name,copies,chip.short_description())
if savechip:
chip.save(fname=self.name + "-" + chip.name, maskid=self.name, chipid=chip.name, do_label=label)
def save_manifest(self, name=None):
if name is None: name = self.name
if name[-4:] != ".txt": name += "_manifest.txt"
f = open(name, 'w')
f.write("Mask:\t%s\tTotal Chips:\t%d\n" % (self.name, self.current_point))
f.write("ID\tCopies\tShort Description\tChip Type\tChip Info\n")
for m in self.manifest:
f.write("%(name)s\t%(copies)d\t%(short_desc)s\n" % m)
for m in self.manifest:
f.write("______________________\n%(name)s\t%(copies)d\t%(long_desc)s\n\n" % m)
f.close()
def save_dxf(self, name=None):
if name is None: name = self.name
if name[-4:] != ".dxf": name += ".dxf"
# print name
f = open(name, 'w')
f.write(str(self))
f.close()
def save(self, name=None):
# print "Saving mask"
self.save_dxf(name)
self.save_manifest(name)
def point_inside(self, pt):
"""True if point is on wafer"""
if self.flat_angle > 180:
return (pt[0] ** 2 + pt[1] ** 2 < (self.diameter / 2. - self.buffer) ** 2) and (
pt[1] > - self.flat_distance + self.buffer)
else:
return (pt[0] ** 2 + pt[1] ** 2 < (self.diameter / 2. - self.buffer) ** 2) and (
pt[1] < self.flat_distance - self.buffer)
# print(- self.flat_distance + self.buffer, "*******")
def die_inside(self, pt):
"""Tell if chip of size self.chip_size is completely on the wafer"""
return self.point_inside(pt) and self.point_inside(
translate_pt(pt, (self.die_size[0], 0))) and self.point_inside(
translate_pt(pt, (self.die_size[0], self.die_size[1]))) and self.point_inside(
translate_pt(pt, (0, self.die_size[1])))
def get_chip_points(self):
"""Get insertion points for all of the chips (layout wafer)"""
max_cols = int((self.diameter - 2 * self.buffer) / self.die_size[0])
max_rows = int((self.diameter - 2 * self.buffer) / self.die_size[1])
print("Maximum number of rows={:d} and cols={:d}".format(max_rows, max_cols))
# figure out offset for chips (centered on chip or between chips)
xoffset = -max_cols / 2. * self.die_size[0]
yoffset = -max_rows / 2. * self.die_size[1]
# if max_cols%2==1:
# print "offset X"
# xoffset+=self.chip_size[0]/2.
# if max_rows%2==1:
# yoffset+=self.chip_size[1]/2.
chip_points = []
for ii in range(max_rows):
for jj in range(max_cols):
pt = (xoffset + jj * self.die_size[0], yoffset + ii * self.die_size[1])
if self.die_inside(pt):
chip_points.append(translate_pt(pt, (self.dicing_border / 2., self.dicing_border / 2.)))
print("Room for %d chips on wafer." % chip_points.__len__())
return chip_points
class Chip(sdxf.Block):
"""Chip is a class which contains structures
Perhaps it will also be used to do some error checking
"""
def __init__(self, name, author='', size=(7000., 1900.), mask_id_loc=(0, 1800), chip_id_loc=(0, 0),
author_loc=(6900, 100), textsize=(160, 160), two_layer=False, layer=None, solid=False, segments=30,
**kwargs):
"""size is a tuple size=(xsize,ysize)"""
name = name.upper()
self.two_layer = two_layer
if two_layer:
self.gap_layer = Chip(name + "gap", size, mask_id_loc, chip_id_loc,
textsize, layer='gap', solid=solid, segments=segments)
self.pin_layer = Chip(name + "pin", size, mask_id_loc, chip_id_loc,
textsize, layer='pin', solid=solid, segments=segments)
self.via_layer = Chip(name + "via", size, mask_id_loc, chip_id_loc,
textsize, layer='via', solid=solid, segments=segments)
# self.rest_layer = Chip(name, size, mask_id_loc, chip_id_loc,
# textsize, layer='rest', solid=solid)
# self.append = self.rest_layer.append
# else:
if layer:
sdxf.Block.__init__(self, name, layer=layer)
else:
sdxf.Block.__init__(self, name)
self.size = size
self.solid = solid
self.mask_id_loc = mask_id_loc
self.chip_id_loc = chip_id_loc
self.author_loc = author_loc
self.author = author
self.name = name
self.textsize = textsize
# we leave the left and right intact right now.
self.left_midpt = (0, size[1] / 2.)
self.right_midpt = (size[0], size[1] / 2.)
self.midpt = (size[0] / 2., size[1] / 2.)
self.top_midpt = (size[0] / 2., size[1])
self.topleft_corner = (0, size[1])
self.topright_corner = (size[0], size[1])
# self.top_mid_left_mid_left_midpt = middle(self.topleft_corner, self.top_mid_left_midpt)
# self.top_mid_right_midpt = middle(self.topright_corner, self.top_midpt)
# self.top_mid_right_mid_right_midpt = middle(self.topright_corner, self.top_mid_right_midpt)
self.bottom_midpt = (size[0] / 2., 0)
self.bottomleft_corner = (0, 0)
self.bottomright_corner = (size[0], 0)
self.center = (size[0] / 2., size[1] / 2.)
self.top_left = (self.top_midpt[0] - 2500.0, self.top_midpt[1])
self.top_right = (self.top_midpt[0] + 2500.0, self.top_midpt[1])
self.bottom_left = (self.bottom_midpt[0] - 2500.0, self.bottom_midpt[1])
self.bottom_right = (self.bottom_midpt[0] + 2500.0, self.bottom_midpt[1])
self.top_left_midpt = middle(self.top_left, self.top_midpt)
self.top_right_midpt = middle(self.top_right, self.top_midpt)
self.bottom_left_midpt = middle(self.bottom_left, self.bottom_midpt)
self.bottom_right_midpt = middle(self.bottom_right, self.bottom_midpt)
self.top_left_mid_left = middle(self.top_left_midpt, self.top_left)
self.top_left_mid_right = middle(self.top_left_midpt, self.top_midpt)
self.top_right_mid_left = middle(self.top_right_midpt, self.top_midpt)
self.top_right_mid_right = middle(self.top_right_midpt, self.top_right)
self.bottom_left_mid_left = middle(self.bottom_left_midpt, self.bottom_left)
self.bottom_left_mid_right = middle(self.bottom_left_midpt, self.bottom_midpt)
self.bottom_right_mid_left = middle(self.bottom_right_midpt, self.bottom_midpt)
self.bottom_right_mid_right = middle(self.bottom_right_midpt, self.bottom_right)
def label_chip(self, drawing, maskid, chipid, author, offset=(0, 0)):
"""Labels chip in drawing at locations given by mask_id_loc and chip_id_loc with an optional offset.
Note that the drawing can be a drawing or a Block including the chip itself"""
if self.two_layer:
layer = 'gap'
else:
layer = '0'
AlphaNumText(drawing, maskid, self.textsize, translate_pt(self.mask_id_loc, offset), layer=layer)
AlphaNumText(drawing, chipid, self.textsize, translate_pt(self.chip_id_loc, offset), layer=layer)
AlphaNumText(drawing, author, self.textsize,
translate_pt(self.author_loc, offset=(-self.textsize[0] * len(author), 0)), layer=layer)
def save(self, fname=None, maskid=None, chipid=None, do_label=True):
"""Saves chip to .dxf, defaults naming file by the chip name, and will also label the chip, if a label is specified"""
if fname is None:
fname = self.name + '.dxf'
if fname[-4:] != '.dxf':
fname += '.dxf'
d = sdxf.Drawing()
if self.two_layer:
self.label_chip(self.gap_layer, maskid, chipid, self.author)
for color, l in enumerate(['gap', 'pin', 'via']):
# object is not subscritable. use __dict__ or __get_item__ instead.
layer = self.__dict__[l + '_layer']
d.layers.append(sdxf.Layer(name=l, color=color + 1))
d.blocks.append(layer)
d.append(sdxf.Insert(layer.name, point=(0, 0), layer=l))
# print(d.layers)
# print(self.gap_layer.layer)
# print(self.pin_layer.layer)
else:
if do_label:
self.label_chip(self, maskid, chipid, self.author)
else:
pass
d.blocks.append(self)
d.append(sdxf.Insert(self.name, point=(0, 0)))
# self.label_chip(d,maskid,chipid,self.author)
d.saveas(fname)
def short_description(self):
try:
return self.__doc__
except:
return "No description"
def long_description(self):
return self.short_description()
class Structure(object):
"""Structure keeps track of current location and direction,
defaults is a dictionary with default values that substructures can call
"""
def __init__(self, chip, start=(0, 0), direction=0, layer="structures", color=1,
defaults={}):
if chip.two_layer:
self.gap_layer = Structure(chip.gap_layer, start, direction, 'gap',
1, defaults)
self.pin_layer = Structure(chip.pin_layer, start, direction, 'pin',
2, defaults)
self.via_layer = Structure(chip.via_layer, start, direction, 'via',
3, defaults)
self.chip = chip
self.start = start
self.last = start
self.last_direction = direction
self.layer = layer
self.color = color
self.defaults = defaults.copy()
self.structures = []
try:
self.pinw = chip.pinw
except AttributeError:
try:
self.pinw = self.defaults['pinw']
except KeyError:
pass # print 'no pinw for chips',chip.name, 'at initialization'
try:
self.gapw = chip.gapw
except AttributeError:
try:
self.gapw = self.defaults['gapw']
except KeyError:
pass # print 'no gapw for chips',chip.name, 'at initialization'
self.pinw2 = None
try:
self.center_gapw = self.defaults['center_gapw']
except KeyError:
pass # print 'no center_gapw for chips',chip.name, 'at initialization'
def move(self, distance, direction=None):
if direction == None: direction = self.last_direction
self.last = translate_pt(self.last, ang2pt(direction, distance))
def append(self, shape):
"""gives a more convenient reference to the chips.append method"""
self.chip.append(shape)
def __setattr__(self, name, value):
if hasattr(self, "chip") and self.chip.two_layer:
if name is "last":
self.gap_layer.last = value
self.pin_layer.last = value
if name is "last_direction":
self.gap_layer.last_direction = value
self.pin_layer.last_direction = value
object.__setattr__(self, name, value)
# ===============================================================================
# Primitives
# ===============================================================================
class Ellipses:
def __init__(self, structure, center, major, minor, angle=0, segments=20):
s = structure
elipses = [(cos(ang + angle / 360.) * major + center[0], sin(ang + angle / 360.) * minor + center[1]) for ang in
linspace(0, 2 * pi, segments + 1)]
s.append(sdxf.PolyLine(elipses))
# todo: need clean up, shouldn't be in primitives section.
def ellipse_arcpts(center, major, minor, angle_start=0, angle_stop=2 * pi, angle=0, segments=20):
ellipse = [(cos(ang + angle / 360.) * major + center[0], sin(ang + angle / 360.) * minor + center[1]) for
ang in linspace(angle_start, angle_stop, segments + 1)]
return ellipse
# ===============================================================================
# CPW COMPONENTS
# ===============================================================================
class Launcher:
def __init__(self, structure, flipped=False, pad_length=250, taper_length=250, pad_to_length=500, pinw=None,
gapw=None):
s = structure
if pinw is None: pinw = s.__dict__['pinw']
if gapw is None: gapw = s.__dict__['gapw']
padding = pad_to_length - pad_length - taper_length
if padding < 0:
padding = 0
self.length = pad_length + taper_length
else:
self.length = pad_to_length
self.pinw = 150
self.gapw = 75
if not flipped:
# input launcher
CPWStraight(s, length=self.gapw, pinw=0, gapw=self.gapw + self.pinw / 2.)
CPWStraight(s, length=pad_length - self.gapw, pinw=self.pinw, gapw=self.gapw)
CPWLinearTaper(s, length=taper_length, start_pinw=self.pinw,
start_gapw=self.gapw, stop_pinw=pinw, stop_gapw=gapw)
CPWStraight(s, length=padding)
else:
CPWStraight(s, length=padding)
CPWLinearTaper(s, length=taper_length, start_pinw=pinw,
start_gapw=gapw, stop_pinw=self.pinw, stop_gapw=self.gapw)
CPWStraight(s, length=pad_length - self.gapw, pinw=self.pinw, gapw=self.gapw)
CPWStraight(s, length=self.gapw, pinw=0, gapw=self.gapw + self.pinw / 2.)
try:
s.gap_layer.last = s.last
except AttributeError:
pass
try:
s.pin_layer.last = s.last
except AttributeError:
pass
try:
s.gap_layer.last_direction = s.last_direction
except AttributeError:
pass
try:
s.pin_layer.last_direction = s.last_direction
except AttributeError:
pass
def Inductive_Launcher(
structure,
pinw=25,
gapw=20,
padw=200,
padl=300,
num_loops=4,
handedness='right',
launch=True):
s = structure
bend_angle = 90 if handedness is 'right' else - 90
shift = num_loops * pinw + (num_loops + 1) * gapw
s.last = translate_pt_by_r(s.last, shift, s.last_direction)
CPWStraight(s, padl, pinw=padw, gapw=gapw)
s.pinw = pinw
s.gapw = gapw
s.radius = pinw / 2. + gapw
s.last = translate_pt_by_r(s.last, padw / 2. - pinw / 2., s.last_direction - bend_angle)
for i in range(num_loops):
# CPWStraight(s, gapw, pinw, gapw)
CPWBend(s, bend_angle, segments=5)
CPWStraight(s, padw - (pinw + gapw), pinw, gapw)
CPWBend(s, bend_angle, segments=5)
CPWStraight(s, padl, pinw, gapw)
CPWBend(s, bend_angle, segments=5)
CPWStraight(s, padw, pinw, gapw)
CPWBend(s, bend_angle, segments=5)
CPWStraight(s, padl, pinw, gapw)
s.radius += pinw + gapw
if not launch: return;
CPWBend(s, bend_angle, segments=5)
exit_radius = pinw / 2. + gapw
CPWStraight(s, padw / 2. - (pinw + gapw) - exit_radius * 1., pinw, gapw)
CPWBend(s, -bend_angle, radius=exit_radius, segments=5)
# ===============================================================================
# CPW COMPONENTS
# ===============================================================================
class Box:
"""A one layer box that can be launched asymetrically. Appends a box to the
structure designated.
Method "align" allows on to append alignment marks to the pattern.
Personally I think the syntax is pretty awesome.
Ge
"""
def __init__(self, structure, length, width, offset=None, solid=False):
if length == 0 or width == 0: return
s = structure;
self.s = s
self.solid = solid
if offset == None:
start = structure.last;
else:
start = translate_pt(structure.last, rotate_pt(offset, s.last_direction, (0, 0)))
self.start = start
self.box0 = self.box(length, width, start)
items = [self.box0]
self.rotNadd(s, items)
start = structure.last;
stop = rotate_pt((start[0] + length, start[1]), s.last_direction, start)
s.last = stop
def rotNadd(self, s, items):
for item in items:
item = rotate_pts(item, s.last_direction, self.start)
if self.solid:
s.append(sdxf.Solid(item[:-1], layer=s.layer))
else:
s.append(sdxf.PolyLine(item, layer=s.layer))
def align(self, align_spacing, align_size):
l, w = align_spacing
box = self.box0
### now draw virtual boxes around each corner of the original BOX0
a0 = self.box_center(l, w, center=box[0])
a1 = self.box_center(l, w, center=box[1])
a2 = self.box_center(l, w, center=box[2])
a3 = self.box_center(l, w, center=box[3])
### then draw the real alignment boxes at these locations.
### This style reduces coding error significantly
l, w = align_size
items = []
items.append(self.box_center(l, w, center=a0[0]))
items.append(self.box_center(l, w, center=a1[1]))
items.append(self.box_center(l, w, center=a2[2]))
items.append(self.box_center(l, w, center=a3[3]))
self.rotNadd(self.s, items)
def box(self, length, width, start):
### Drawing
box = [translate_pt(start, (0, width / 2.)),
translate_pt(start, (0, -width / 2.)),
translate_pt(start, (length, -width / 2.)),
translate_pt(start, (length, width / 2.)),
translate_pt(start, (0, width / 2.))
]
return box
def box_center(self, length, width, center):
### Drawing
box = [translate_pt(center, (-length / 2., width / 2.)),
translate_pt(center, (-length / 2., -width / 2.)),
translate_pt(center, (length / 2., -width / 2.)),
translate_pt(center, (length / 2., width / 2.)),
translate_pt(center, (-length / 2., width / 2.))
]
return box
class CoupledStraight:
def __init__(self, structure, length, pinw=None, gapw=None, center_gapw=None):
if length == 0: return
if length < 0:
print("Warning -- Negative length straight section")
s = structure
if pinw is None: pinw = structure.__dict__['pinw']
if gapw is None: gapw = structure.__dict__['gapw']
if center_gapw is None:
try:
center_gapw = structure.center_gapw
except KeyError:
print("Missing center_gapw argument!")
# center_gapw = 1
pinw, gapw, center_gapw = float(pinw), float(gapw), float(center_gapw)
if s.chip.two_layer:
CoupledStraight(s.gap_layer, length, 0, 0, center_gapw + (pinw + gapw) * 2)
CoupledStraight(s.pin_layer, length, center_gapw / 2., pinw, 0)
assert s.gap_layer.last == s.pin_layer.last
s.last = s.gap_layer.last
else:
start = structure.last
gap1 = [(start[0], start[1] + pinw + center_gapw / 2.),
(start[0] + length, start[1] + pinw + center_gapw / 2.),
(start[0] + length, start[1] + pinw + center_gapw / 2. + gapw),
(start[0], start[1] + pinw + center_gapw / 2. + gapw),
(start[0], start[1] + pinw + center_gapw / 2.)
]
gap2 = [(start[0], start[1] - pinw - center_gapw / 2.),
(start[0] + length, start[1] - pinw - center_gapw / 2.),
(start[0] + length, start[1] - pinw - center_gapw / 2. - gapw),
(start[0], start[1] - pinw - center_gapw / 2. - gapw),
(start[0], start[1] - pinw - center_gapw / 2.)
]
gap3 = [(start[0], start[1] - center_gapw / 2.),
(start[0] + length, start[1] - center_gapw / 2.),
(start[0] + length, start[1] + center_gapw / 2.),
(start[0], start[1] + center_gapw / 2.),
(start[0], start[1] - center_gapw / 2.)
]
gap1 = rotate_pts(gap1, s.last_direction, start)
gap2 = rotate_pts(gap2, s.last_direction, start)
gap3 = rotate_pts(gap3, s.last_direction, start)
stop = rotate_pt((start[0] + length, start[1]), s.last_direction, start)
s.last = stop
# if pinw == 0 and gapw == 0:#gets rid of the thin unecessary lines
# return # Placed behind the previous condition because
# we need the assertion of the last point.
if s.chip.solid:
if gapw != 0:
s.append(sdxf.Solid(gap1[:-1]))
s.append(sdxf.Solid(gap2[:-1]))
if center_gapw != 0:
s.append(sdxf.Solid(gap3[:-1]))
else:
if gapw != 0:
s.append(sdxf.PolyLine(gap1))
s.append(sdxf.PolyLine(gap2))
if center_gapw != 0:
s.append(sdxf.PolyLine(gap3))
s.pinw = pinw
s.gapw = gapw
s.center_gapw = center_gapw
class CPWStraight:
"""A straight section of CPW transmission line"""
def __init__(self, structure, length, pinw=None, gapw=None):
""" Adds a straight section of CPW transmission line of length = length to the structure"""
if length == 0: return
if length < 0:
print("Warning -- Negative length straight section")
s = structure
if pinw is None: pinw = structure.__dict__['pinw']
if gapw is None: gapw = structure.__dict__['gapw']
pinw, gapw = float(pinw), float(gapw)
if s.chip.two_layer:
CPWStraight(s.gap_layer, length, 0, pinw / 2. + gapw)
CPWStraight(s.pin_layer, length, 0, pinw / 2.)
assert s.gap_layer.last == s.pin_layer.last
s.last = s.gap_layer.last
return
else:
start = structure.last
gap1 = [(start[0], start[1] + pinw / 2),
(start[0] + length, start[1] + pinw / 2),
(start[0] + length, start[1] + pinw / 2 + gapw),
(start[0], start[1] + pinw / 2 + gapw),
(start[0], start[1] + pinw / 2)
]
gap2 = [(start[0], start[1] - pinw / 2),
(start[0] + length, start[1] - pinw / 2),
(start[0] + length, start[1] - pinw / 2 - gapw),
(start[0], start[1] - pinw / 2 - gapw),
(start[0], start[1] - pinw / 2)
]
if pinw == 0:
gap1 = [(start[0], start[1] - pinw / 2 - gapw),
(start[0] + length, start[1] - pinw / 2 - gapw),
(start[0] + length, start[1] + pinw / 2 + gapw),
(start[0], start[1] + pinw / 2 + gapw),
(start[0], start[1] - pinw / 2 - gapw)]
gap1 = rotate_pts(gap1, s.last_direction, start)
gap2 = rotate_pts(gap2, s.last_direction, start)
stop = rotate_pt((start[0] + length, start[1]), s.last_direction, start)
s.last = stop
if pinw == 0 and gapw == 0: # gets rid of the thin unecessary lines
return # Placed behind the previous condition because
# we need the assertion of the last point.
if s.chip.solid:
s.append(sdxf.Solid(gap1[:-1]))
if pinw != 0:
s.append(sdxf.Solid(gap2[:-1]))
s.append(sdxf.PolyLine(gap1))
if pinw != 0:
s.append(sdxf.PolyLine(gap2))
class CPWs2p:
def __init__(self, s, endpoint, pinw=None, gapw=None):
length = distance(endpoint, s.last)
if length == 0: return
CPWStraight(s, length, pinw=pinw, gapw=gapw)
self.length = length
class Coupled2p:
def __init__(self, s, endpoint, pinw=None, gapw=None, center_gapw=None):
length = distance(endpoint, s.last)
if length == 0: return
CoupledStraight(s, length, pinw=pinw, gapw=gapw, center_gapw=center_gapw)
self.length = length
class CPWConnect:
def __init__(self, s1, s2, pinw=None, gapw=None):
CPWs2p(s1, s2.last, pinw, gapw)
class CoupledConnect:
def __init__(self, s1, s2, pinw=None, gapw=None, center_gapw=None):
Coupled2p(s1, s2.last, pinw, gapw, center_gapw)
class CPWQubitBox:
"""A straight section of CPW transmission line with fingers in the ground plane to add a capacitor"""
def __init__(self, structure, fingerlen, fingerw, finger_gapw, finger_no, int_len=10, pinw=None, gapw=None,
align=True, small=10, medium=20, big=50):
""" Adds a straight section of CPW transmission line of length = length to the structure"""
self.fingerlen = fingerlen
self.fingerw = fingerw
self.finger_gapw = finger_gapw
self.finger_no = finger_no
# This is just the length of one comb of fingers
length = self.finger_no * self.fingerw + (self.finger_no + 1) * (self.fingerw + 2 * self.finger_gapw)
self.comb_length = length
self.total_length = 2 * length + int_len
self.interior_length = int_len
self.s = structure
start = structure.last
if pinw is None: pinw = structure.__dict__['pinw']
if gapw is None: gapw = structure.__dict__['gapw']
self.pinw = pinw
self.gapw = gapw
self.top = [(start[0], start[1] + pinw / 2.),
(start[0], start[1] + pinw / 2. + gapw + self.fingerlen)
]
self.bot = [(start[0], start[1] - pinw / 2.),
(start[0], start[1] - pinw / 2. - gapw - self.fingerlen)
]
for n in range(finger_no):
self.add_pin(n)
self.top.extend([(start[0] + length, start[1] + pinw / 2. + gapw + self.fingerlen),
(start[0] + length, start[1] + pinw / 2. + gapw),
(start[0] + length + int_len / 2., start[1] + pinw / 2. + gapw)
])
self.bot.extend([(start[0] + length, start[1] - pinw / 2. - gapw - self.fingerlen),
(start[0] + length, start[1] - pinw / 2. - gapw),
(start[0] + length + int_len / 2., start[1] - pinw / 2. - gapw)
])
self.pin = [(start[0], start[1] + pinw / 2.),
(start[0] + length - fingerw - 2 * finger_gapw, start[1] + pinw / 2.),
(start[0] + length - fingerw - 2 * finger_gapw, start[1] - pinw / 2.),
(start[0], start[1] - pinw / 2.)
]
self.top = rotate_pts(self.top, self.s.last_direction, start)
self.bot = rotate_pts(self.bot, self.s.last_direction, start)
self.pin = rotate_pts(self.pin, self.s.last_direction, start)
stop = rotate_pt((start[0] + length + int_len / 2., start[1]), self.s.last_direction, start)
midpt = stop
self.s.last = stop
self.s.append(sdxf.PolyLine(self.top))
self.s.append(sdxf.PolyLine(self.bot))
self.s.append(sdxf.PolyLine(self.pin))
self.top = rotate_pts(self.top, 180, stop)
self.bot = rotate_pts(self.bot, 180, stop)
self.pin = rotate_pts(self.pin, 180, stop)
stop = rotate_pt((start[0] + 2 * length + int_len, start[1]), self.s.last_direction, start)
self.s.last = stop
self.s.append(sdxf.PolyLine(self.top))
self.s.append(sdxf.PolyLine(self.bot))
self.s.append(sdxf.PolyLine(self.pin))
# Adds the proper alignment marks
# s1 = Structure(self,start=start,color=3,direction=0)
small_box = [(-small / 2., -small / 2.),
(-small / 2., +small / 2.),
(+small / 2., +small / 2.),
(+small / 2., -small / 2.),
(-small / 2., -small / 2.)
]
medium_box = [(-medium / 2., -medium / 2.),
(-medium / 2., +medium / 2.),
(+medium / 2., +medium / 2.),
(+medium / 2., -medium / 2.),
(-medium / 2., -medium / 2.)
]
large_box = [(-big / 2., -big / 2.),
(-big / 2., +big / 2.),
(+big / 2., +big / 2.),
(+big / 2., -big / 2.),
(-big / 2., -big / 2.)
]
if small == 0:
small_box = []
if medium == 0:
medium_box = []
if big == 0:
large_box = []
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(small_box, (
start[0] + small / 2., start[1] + small / 2. + pinw / 2. + gapw + self.fingerlen + 2 * small)),
self.s.last_direction, center=start)))
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(medium_box, (start[0] + self.total_length / 4., start[
1] + small / 2. + pinw / 2. + gapw + self.fingerlen + 2 * small + 400)),
self.s.last_direction, center=start)))
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(large_box, (start[0] + self.total_length / 2., start[
1] + small / 2. + pinw / 2. + gapw + self.fingerlen + 2 * small + 800)),
self.s.last_direction, center=start)))
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(medium_box, (start[0] + 3 * self.total_length / 4., start[
1] + small / 2. + pinw / 2. + gapw + self.fingerlen + 2 * small + 400)),
self.s.last_direction, center=start)))
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(small_box, (start[0] + self.total_length - small / 2.,
start[
1] + small / 2. + pinw / 2. + gapw + self.fingerlen + 2 * small)),
self.s.last_direction, center=start)))
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(small_box, (
start[0] + small / 2., start[1] - small / 2. - pinw / 2. - gapw - self.fingerlen - 2 * small)),
self.s.last_direction, center=start)))
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(medium_box, (start[0] + self.total_length / 4., start[
1] - small / 2. - pinw / 2. - gapw - self.fingerlen - 2 * small - 400)),
self.s.last_direction, center=start)))
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(large_box, (start[0] + self.total_length / 2., start[
1] - small / 2. - pinw / 2. - gapw - self.fingerlen - 2 * small - 800)),
self.s.last_direction, center=start)))
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(medium_box, (start[0] + 3 * self.total_length / 4., start[
1] - small / 2. - pinw / 2. - gapw - self.fingerlen - 2 * small - 400)),
self.s.last_direction, center=start)))
self.s.append(sdxf.PolyLine(rotate_pts(translate_pts(small_box, (start[0] + self.total_length - small / 2.,
start[
1] - small / 2. - pinw / 2. - gapw - self.fingerlen - 2 * small)),
self.s.last_direction, center=start)))
def add_pin(self, n):
'''"This adds the nth pin to gap1 and gap2'''
start = self.s.last
self.top.extend([(start[0] + (2 * n + 1) * self.fingerw + 2 * (n + 1) * self.finger_gapw,
start[1] + self.pinw / 2. + self.gapw + self.fingerlen),
(start[0] + (2 * n + 1) * self.fingerw + 2 * (n + 1) * self.finger_gapw,
start[1] + self.pinw / 2. + self.gapw),
(start[0] + 2 * (n + 1) * self.fingerw + 2 * (n + 1) * self.finger_gapw,
start[1] + self.pinw / 2. + self.gapw),
(start[0] + 2 * (n + 1) * self.fingerw + 2 * (n + 1) * self.finger_gapw,