This article is a continuation of Handling GDSII format in Python. Assuming that the gdspy library has been installed, let's create the first GDS file. First, at the time of writing the manuscript (February 16, 2020), the latest version of gdspy is 1.5.2. It seems that the design concept has changed ** a lot from 1.5, and the script created in the previous version ** does not work as it is **. Even the script in the official gdspy does not work properly at this time, so only the version that made it work quickly is listed below. ..
import gdspy
# The GDSII file is called a library, which contains multiple cells.
lib = gdspy.GdsLibrary()
# Geometry must be placed in cells.
cell = lib.new_cell('FIRST')
# Create the geometry (a single rectangle) and add it to the cell.
rect = gdspy.Rectangle((0, 0), (2, 1))
cell.add(rect)
# Save the library in a file called 'first.gds'.
lib.write_gds('first.gds')
# Optionally, save an image of the cell as SVG.
cell.write_svg('first.svg')
# Display all cells using the internal viewer.
gdspy.LayoutViewer (lib)
<-Only one line here changed from Official
For details on GDS files (GDS II format), please see the reference site [^ 1] [^ 2], but roughly speaking. Library ├ Cell ├ Geometry It is configured as. A library refers to an entire GDS file. Geometry is an individual figure (polygon, circle, etc, etc, ...), and a cell is a collection of geometry. Normally, GDS has a Cell named Top, which is the Cell that describes the entire library. The Top cell contains a reference to the library or other cells (called subcells). In other words, cells are allowed to have a hierarchical structure, so if they can be used properly, it will lead to more efficient file size. ,
Until 1.4, the GDS library to be handled was treated as a global class [^ 1], but after 1.5, it is clearly treated as a local class lib = gdspy.GdsLibrary ()
. Along with that, there are many codes that do not work as they are, including the official documentation. Of course, it is necessary to change it when passing it to a subroutine (function), and the usage of CellReference etc. has changed significantly.
Updates to gdspy 2.0 are planned in the future, and changes are expected to increase further. For more information, see the source on GitHub ~~ (that's it) ~~.
In the previous section, I mentioned that lib = gdspy.GdsLibrary ()
is treated as a local class, but there are many problems at the time of writing the manuscript. First, gdspy.GdsLibrary seems to have a constructor but no destructor.
In other words, if you execute lib = gdspy.GdsLibrary ()
multiple times in a for loop, an error will occur because the previous history remains. To avoid this error, when running in Spyder, run gdspy.GdsLibrary () only once in your Python script, and run the "console"-> "kernel each time you run the script. You should "reboot" [^ 4].
Recommended Posts