Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

smart way to get gds file properties

edited November 28 in Python scripting

Dear KL-Experts,
It sounds easy but I'm struggleing with a basic issue.
After creating my top layout I read 2 gds files (cellA and cellB) and need to know the cell name to derive the cell index, width and height.
from paya import *
top = layout.create_cell(mpw)
cellA = layout.read('a.gds')
cellB = layout.read('b.gds')

Target is to place this cells later on at the top level:
top.insert(pya.CellInstArray(cellA.cell_index,pya.Trans(pya.Point(xPos*dbu,yPos*dbu))))
top.insert(pya.CellInstArray(cellB.cell_index,pya.Trans(pya.Point(xPos*dbu,yPos*dbu))))

Thanks in advance for any hint.

Best Regards,
Andy

Comments

  • Hi Andy,

    Reading two GDS files into one sounds like a simple thing but in fact it's a very coarse way of merging layouts. In the worst case, both GDS files use the same name for their top cell. In this case, the layouts of both cells will be merged into one.

    Maybe this is desired. But reading two files into each other will also merge child cells if their names are identical. This imposes a considerable risk of damaging the layout.

    If you're willing to take this risk and the names of the top cells of your two layouts aren't the same and your two layouts have unique top cell names, you can get the names of the two top cells using layout.top_cells. You should get two then. Still you won't know which is one (maybe you don't care either).

    In general, the safer way is to load two separate layouts (A,B), create a fresh third one (C) with two (empty) target cells (TA,TB) and copy over the layouts from A to C and then B to C using TA.move_tree(A.top_cell) and TB.move_tree(B.top_cell).

    Matthias

  • Thanks a lot Matthias,
    there should be no conflict but your right - there might be a risk better to avoid.

    I tried your suggestion but run into an Error (latest release):

    Unexpected object type - expect class cell ... using the move_tree command.
    layout = pya.Layout()
    top = layout.create_cell('mpw')
    top = layout.top_cell()
    ta = layout.create_cell('ta')
    layoutA = pya.Layout()
    cellA = layoutA.read('a.gds')
    ta.move_tree(layoutA.top_cell)

    What works is to loop and move:
    for x in layoutA.top_cells():
    ta.move_tree(x)

    But this copied all hierarchies except the top cell.
    By the way I tried to create ta inside top but only manage to create a new cell beside the top. Is there a way to do so?

    Best Regards,
    Andy

  • edited November 29

    In Python, it has to be "ta.move_tree(layoutA.top_cell())" (note the round brackets after top_cell).

    To create a hierarchy to cells, create instances (not tested):

    very_top = layout.create_cell("very_top")
    ta = layout.create_cell("layout_a")
    very_top.insert(pya.CellInstArray(ta.cell_index(), pya.Trans()))
    tb = layout.create_cell("layout_b")
    very_top.insert(pya.CellInstArray(tb.cell_index(), pya.Trans()))
    
    ta.move_tree(layoutA.top_cell())
    tb.move_tree(layoutB.top_cell())
    

    Matthias

  • Hello Matthias,
    it works perfect - Thanks a lot for your expertise and feedback.
    Klayout is really awesome.
    A very good integration too is the Salt package manger. We now use it to distribute different Technologies and DRC rules local.

    Best Regards,
    Andy

  • Very good. Thanks for your feedback.

    Matthias

Sign In or Register to comment.