Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert Entire GDS File #68

Closed
dorianherle opened this issue Oct 18, 2018 · 7 comments
Closed

Invert Entire GDS File #68

dorianherle opened this issue Oct 18, 2018 · 7 comments

Comments

@dorianherle
Copy link

Hi !

Is it possible to invert a complex gds file (to change resist toner) ?
Thanks.

@heitzmann
Copy link
Owner

Yes, you'll have to do a Boolean operation to subtract the existing geometry from a large enough rectangle (or whatever shape you prefer). Keep in mind that Boolean operations are computationally expensive, so it could take a long time to process depending on the number of vertices and polygons in the file.

Here is an example:

import gdspy

# Sample GDSII
c0 = gdspy.Cell('REF')
c0.add(gdspy.Rectangle((-2, -2), (2, 2)))

c1 = gdspy.Cell('MAIN')
c1.add(gdspy.Round((0, 0), 10, inner_radius=8))
c1.add(gdspy.Rectangle((0, 0), (20, 10)))
c1.add(gdspy.CellReference(c0, magnification=2))
c1.add(gdspy.CellArray(c0, 5, 5, (10, 10), (0, -20), rotation=45))

# Find bounding box and expand it by `margin`
margin = 2
p0, p1 = c1.get_bounding_box()
p0 = (p0[0] - margin, p0[1] - margin)
p1 = (p1[0] + margin, p1[1] + margin)

# Invert cell MAIN
c2 = gdspy.Cell('INV')
c2.add(gdspy.fast_boolean(gdspy.Rectangle(p0, p1), c1.get_polygons(), 'not'))

gdspy.LayoutViewer()

@dorianherle
Copy link
Author

dorianherle commented Oct 18, 2018

Dear Lucas

thanks a lot for your answer. In my case, my gds file contains many cells and cell arrays. This is done as to create a memory efficient gds file. Here is an example:

import numpy
import gdspy

# parameters
diameter = 2
period = 4
N = 16

    
# initializing cells
unit_cell = gdspy.Cell('circle_unit_cell')    
array_cell = gdspy.Cell('circle_array_cell')

# unit_cell (1 circle)
unit_circle = gdspy.Round((0, 0), diameter/2, layer=1)
unit_cell.add(unit_circle)

# array_of unit_cels (N x N circles)
circle_array = gdspy.CellArray(unit_cell, N, N, (period, period))
array_cell.add(circle_array)


gdspy.LayoutViewer()

Then... how can I invert it ?

@heitzmann
Copy link
Owner

The example I showed before includes reference arrays. It works for any GDS layout.
Did you try to run it?

@dorianherle
Copy link
Author

dorianherle commented Oct 18, 2018

Oh, please excuse me... I somehow missed that. Thanks a lot !! Yes ! It works ! Very nice ! Just one more follow up question: As you can see in your example there is a lot of space added when inverting the gds, because we apply the boolean to a simple rectangle. Do you think that it would be possible to create a border which traces along the shape of the gds file and then to use that to invert it ? Do you see what I mean ?

@heitzmann
Copy link
Owner

It's hard to properly define a border and guarantee connectivity, if that's what you're looking for. You can use the offset function if connectivity is not an issue:

import gdspy

# Sample GDSII
c0 = gdspy.Cell('REF')
c0.add(gdspy.Rectangle((-2, -2), (2, 2)))

c1 = gdspy.Cell('MAIN')
c1.add(gdspy.Round((0, 0), 20, inner_radius=10))
c1.add(gdspy.Rectangle((0, 0), (20, 10)))
c1.add(gdspy.CellReference(c0, magnification=2))
c1.add(gdspy.CellArray(c0, 5, 5, (10, 10), (0, -20), rotation=45))

# Create an envolope by offseting the whole geometry
envelope = gdspy.offset(c1.get_polygons(), 2, join_first=True, layer=3)

# Invert cell MAIN
c2 = gdspy.Cell('INV')
c2.add(gdspy.fast_boolean(envelope, c1.get_polygons(), 'not'))
c1.add(envelope)

gdspy.LayoutViewer()

Otherwise, you should first get the convex hull of the geometry, and use that for inversion (with a proper offset, as well):

import gdspy
import numpy
import scipy.spatial

# Sample GDSII
c0 = gdspy.Cell('REF')
c0.add(gdspy.Rectangle((-2, -2), (2, 2)))

c1 = gdspy.Cell('MAIN')
c1.add(gdspy.Round((0, 0), 20, inner_radius=10))
c1.add(gdspy.Rectangle((0, 0), (20, 10)))
c1.add(gdspy.CellReference(c0, magnification=2))
c1.add(gdspy.CellArray(c0, 5, 5, (10, 10), (0, -20), rotation=45))

# Find convex hull and offset it by some amount
allpoints = numpy.vstack(c1.get_polygons())
hull = scipy.spatial.ConvexHull(allpoints)
envelope = gdspy.offset([allpoints[hull.vertices, :]], 2)

# Invert cell MAIN
c2 = gdspy.Cell('INV')
c2.add(gdspy.fast_boolean(envelope, c1.get_polygons(), 'not'))

gdspy.LayoutViewer()

@dorianherle
Copy link
Author

Wow ! I am very impressed by your capabilities and your code ! Very nice.

If I compare it:

  1. Using Offset:
    offset

  2. Using Convex Hull:
    convex_hull

--> Convex Hull was what I was looking for ! :)
Thank you so much for helping me and creating this amazing package! 🥇

@heitzmann
Copy link
Owner

No problem! I hope it works well for your case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants