python-klayout
create layout
ly = db.Layout()
ly.dbu = 0.001
define layer
AA = ly.layer(1, 1,“AA”)
Create a cell
BitCell_Unit= ly.create_cell(“BitCell_Unit”)
setup CT060 instance and insert CT as instance
CT060 = ly.create_cell(“CT060”)
width = CD_CT060
height = CD_CT060
pt = db.DPoint(0, 0)
box_CT060 = db.DBox(pt, pt + db.DVector(width, height))
CT060.shapes(CT).insert(box_CT060)
xPosition= (Len_AA_BL - CD_CT040)/2
yPosition= CD_CT040/2*-1
xPitch=0
yPitch=Width_AA_BL
CTBL = db.DCellInstArray(
CT040.cell_index(),
db.DTrans(db.DTrans.R0, xPosition, yPosition),
db.DVector(0, yPitch),
db.DVector(xPitch, 0),
2,
2
)
BitCell_Unit.insert(CTBL)
Insert a layer
width = 0.1
length = 10
xPosition=0
yPosition=0
pt = db.DPoint(xPosition,yPosition)
box_M1_BL = db.DBox(pt, pt + db.DVector(length, width))
BitCell_Unit.shapes(M1).insert(box_M1_BL)
copy an instance
BitCell1_Unit= ly.create_cell(“BitCell1_Unit”)
BitCell1_Unit.copy_tree(BitCell_Unit)
flatten an instance and delete a layer
BitCell1_Unit.flatten(-1)
BitCell1_Unit.clear(CT)
write to a GDS
ly.write(“TEST.gds”)
boolean
structure= ly.create_cell(“test”)
structure.shapes(M1).insert(box_CT040)
structure.shapes(M2).insert(box_CT060)
r1=db.Region.new(structure.shapes(M1))
r2=db.Region.new(structure.shapes(M2))
r3=r2-r1
structure.shapes(NW).insert(r3)
read a gds
ly.read(“xxx.gds”)
Operation for all top cell in a gds
topnames = list()
for cell in ly.top_cells():
name_cell = cell.name
pattern = r"Main"
if re.findall(pattern, name_cell):
topnames.append(name_cell)
Delete a layer from all the cells
for cell in ly.each_cell():
cell.shapes(DummyLOTA1).clear()
clear a cell
ly.cell(‘xxx’).clear
delete a cell
ly.cell(‘xxx’).delete
Copy and replace
ly.read(“MTP_Merged_Vcm_ForDRC_Modify.gds”)
ly1.read(“a.gds”)
ly1.read(“b.gds”)
for cell in ly.each_cell():
name_cell = str(cell.name)
pattern = r"Main"
if re.findall(pattern, name_cell):
cell.prune_subcells()
cell.clear()
exec ('cell .copy_tree( ly1.cell("' + str(name_cell ) + '"))')
Path
path_layer = db.DPath([(-1,1),(0,1),(3,4),(5,4)],1)
Top.shapes(AA).insert(path_layer)
for cells in ly.top_cells():
for index in cells.each_child_cell():
for ii in ly.cell(index).each_child_cell():
for shape in ly.cell(ii).each_shape(AA):
print(shape)