Place copies of an element based on coordinates from text file.

Hi

I want to create a metamaterial that has a few unique geometries (8-16) and they are repeated throughout the wafer hundreds of times.
Since this cannot be done manually or by array ( not periodic structures), scripting is the only way to do it but i have no clue. I tried to follow some other similar topics that have been answered here but i cant get it working.

I dont mind the language it is written (python,ruby) on and every element is on the same layer.
Lets say i have a square of 2 um x,y size. And it has a free surrounding area of 1 um x,y. So its a element of 3x3 um. I then want to place exact copies of that element in many differnt coordinates that will be written on a text file. And finally i want to repeat this process for every unique element(8-16 times). I can manually repeat the process by adjusting the variables in the script, no big deal.

I assume this has to be done by instancing the original element? The number of elements is high 100.000 usually.

Apologies for asking the "same" question again but i couldnt get the script working.

Here are the similar topics i tried to follow.
https://www.klayout.de/forum/discussion/1647/instancing-based-on-a-list-of-coordinates-and-angles
https://www.klayout.de/forum/discussion/370/is-it-possible-to-place-many-instances-of-a-cell-to-a-text-list-of-x-y-coordinates

Comments

  • edited May 2022

    @chaoscrum These are too few details and I will not provide a ready-to-use solution, but I can give your the bits and pieces for you do solve your problem.

    First thing is you need to define the parts. I assume you can define the part's geometries through Python code. The parts will be put into cells and those cells are then placed in a large top cell in order to generate your layout.

    First thing is that you will need a layout object which provides the framework. I assume you need one layer, so we will create one with layer 1, datatype 0:

    import pya
    
    ly = pya.Layout()
    ly.dbu = 0.001   # the basic resolution is 1nm
    
    layer = ly.layer(1, 0)
    

    Next thing is we need to define the parts. These are cells which have a name and geometry put into them. I use polygons here and put them on the one layer we have created:

    # Create a new cell called "PART1". "cell1" will be a Cell object:
    cell1 = ly.create_cell("PART1")
    
    # Create a triangle for example with points (0,0 -> 0,2 -> 2,0). Units are µm:
    pts = [ pya.DPoint(0, 0), pya.DPoint(0, 2), pya.DPoint(2, 0) ]
    cell1.shapes(layer).insert(pya.DPolygon(pts))
    

    You can add any number of polygons and repeat the process for the other parts (cells).

    Then we can create the new top cell:

    top = ly.create_cell("TOP")
    

    With this, we can now place the cells at the desired locations. Here I place a single instance of the cell we just created:

    # Coordinate to place the cell to. Units are µm:
    x = 17.0
    y = 42.0
    top.insert(pya.DCellInstArray(cell1.cell_index(), pya.DTrans(x, y)))
    

    You can repeat this process any many times you need at different coordinates and with different cells.

    And finally, this is how the result is written:

    ly.write("output.gds")
    

    Matthias

  • Thank you for your reply Matthias.
    I will try to solve this combing it with the other topics for reading the data from the txt file. Forgot to mention that i am clueless to Python, i am just an optics guy that uses matlab for calculations.

  • @Matthias I have a few questions/observations.

    1) I assume i create a simple py file. And i dont need to create any layout /layers manually or cell manually, correct?

    2) cell1.shapes(layer).insert(pya.DPolygon(pts)) gives an error
    NoneType' object has no attribute 'shapes' (eval):1

    Same for
    top.insert(pya.DCellInstArray(cell1.cell_index(), pya.DTrans(x, y)))
    NoneType' object has no attribute 'insert' (eval):1

    3) Am i supposed to see the creation of the layer , cell and triangle as i run these commands in console? Commands are printed blue ( i believe that means accepted) compared to the ones from 2) when i run 1 by 1 in console.
    Nothing happens visually

    Apologies if these are stupid questions.

  • @chaoscrum No worries, no stupid questions exist :)

    1.) Yes, this "sample" (or rather recipe) creates a layout entirely. No interaction needed.
    2.) Sorry, my fault. The functions should be "create_cell" to create a cell. I have edited the text above.
    3.) No, the script will write a file (last step) which you can then load into the application. This is the easiest solution if that is acceptable. You can basically change the script such that it creates a layout inside the application, but that is more complex and I assume you initially like to focus on the basic generation. If you are familiar with command line you can also run the script in batch mode without user interaction ("klayout -b -r yourscript.py")

    Matthias

Sign In or Register to comment.