It looks like you're new here. If you want to get involved, click one of these buttons!
Hello.
I have a layout consisting of squares located at various positions and would like to apply distortion to this pattern based on an equation.
I have done the following until now using KLayout 0.27.6.
1. Created a gds file consisting of squares using python macro. t.gds
2. Apply second order distortion based on the equation.
3. Write the result of the distorted file. t_distort.gds
When I check the distorted file, I do not see any distortion applied.
I am not used to python or scripting and was looking for some suggestions on how to do this. The code used in the example below is from the help and searching on internet. I do not find much help in the assistant though.
Any help/suggestion is appreciated.
Best regards
Vikram
Here is the code that I worked on.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
import pya
import numpy as np
a = 10
b = 2
c = 15
d = 30
e = 25
f = 10
layout = pya.Layout()
top = layout.create_cell("TOP")
l1=layout.layer(1,0)
top.shapes(l1).insert(pya.Box(5, 5, 25, 25))
top.shapes(l1).insert(pya.Box(95, 35, 105, 45))
top.shapes(l1).insert(pya.Box(35, 95, 45, 105))
top.shapes(l1).insert(pya.Box(35, 895, 45, 905))
top.shapes(l1).insert(pya.Box(95, 955, 105, 965))
top.shapes(l1).insert(pya.Box(895, 955, 905, 965))
top.shapes(l1).insert(pya.Box(955, 895, 965, 905))
top.shapes(l1).insert(pya.Box(955, 95, 965, 105))
top.shapes(l1).insert(pya.Box(895, 35, 905, 45))
top.shapes(l1).insert(pya.Box(495, 35, 505, 45))
top.shapes(l1).insert(pya.Box(35, 495, 45, 505))
top.shapes(l1).insert(pya.Box(495, 955, 505, 965))
layout.write("c:/users/vikram passi/KLayout/pymacros/t.gds")
def apply_second_order_distortion(layout, a, b, c, d, e, f):
cell = layout.cell("TOP")
for shape in cell.each_shape(1):
for i in range(shape.num_points()):
x,y = shape.point(i)
print("The value of X is", x)
print("The value of y is", y)
x_distorted = axx + bxy + cyy + dx + ey + f
y_distorted = ayy + bxy + cxx + ex + dy + f
shape.set_point(i, x_distorted, y_distorted)
layout.read("c:/users/vikram passi/KLayout/pymacros/t.gds")
apply_second_order_distortion(layout, a, b, c, d, e, f)
layout.write("c:/users/vikram passi/KLayout/pymacros/t_distort.gds")
Comments
Hi @Vikram,
a single line with three backticks before after your code do magic. This forum provides Markdown - the same thing you use on GitHub to format code. Python is not readable without the indents.
From what I can guess, you should take a look at the documentation: https://www.klayout.de/doc-qt5/programming/database_api.html#h2-1068. There is an explanation of the concept of the Shape object. It is not necessarily a polygon. You cannot set a point directly on the shape. A quick research in the documentation (https://www.klayout.de/doc-qt5/code/class_Shape.html) will tell you that there is no "set_point" method in the "Shape" class. And "point" will give you the Point object if the shape is a point.
ChatGPT isn't a good advisor.
Matthias