Create your first GDSII file in Python using gdspy

Introduction

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

GDS file structure

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. ,

What has changed since gdspy 1.4 and 1.5

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) ~~.

Precautions when handling GDS files with Python / Gdspy

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

Create your first GDSII file in Python using gdspy
Create a GIF file using Pillow in Python
Create a MIDI file in Python using pretty_midi
Create a binary file in Python
Create your own Linux commands in Python
[LLDB] Create your own command in Python
[GPS] Create a kml file in Python
Email attachments using your gmail account in python.
Create wav file from GLSL shader using python3
File operations in Python
File processing in Python
Create SpatiaLite in Python
File operations in Python
Create your own Big Data in Python for validation
Upload JPG file using Google Drive API in Python
Collectively register data in Firestore using csv file in Python
[Python] Create an infrastructure diagram in 3 minutes using diagrams
Create a function in Python
Create a dictionary in Python
Download the file in Python
Create gif video in Python
Create JIRA tickets using Python
Translate using googletrans in Python
Using Python mode in Processing
GUI programming in Python using Appjar
File / folder path manipulation in Python
Precautions when using pit in Python
First simple regression analysis in Python
[Python] logging in your own module
Create a python GUI using tkinter
Create a DI Container in Python
Linebot creation & file sharing in Python
Try using LevelDB in Python (plyvel)
Create an Excel file with Python3
Create your own graph structure class and its drawing in python
Prepare your first Python development environment
Create Gmail in Python without API
Using global variables in python functions
Create Python project documentation in Sphinx
Try to log in to Netflix automatically using python on your PC
Let's see using input in python
Infinite product in Python (using functools)
Extract the targz file using python
Edit videos in Python using MoviePy
Create a Kubernetes Operator in Python
ORC, Parquet file operations in Python
Handwriting recognition using KNN in Python
Create a random string in Python
Try using Leap Motion in Python
The first step in Python Matplotlib
Depth-first search using stack in Python
[Python] File operation using if statement
When using regular expressions in Python
Easily create homemade RPA using Python
Create and read messagepacks in Python
GUI creation in python using tkinter 2
Test & Debug Tips: Create a file of the specified size in Python
Create a record with attachments in KINTONE using the Python requests module
[Python] [Word] [python-docx] Try to create a template of a word sentence in Python using python-docx
A useful note when using Python for the first time in a while
Generate a first class collection in Python