Coder Social home page Coder Social logo

gdsiistl's Introduction

gdsiistl

Converts GDSII files to STL files.

GDSII files are often large, complex 2D designs for integrated circuits and MEMS chips. 3D visualization of the designs can be very useful, but this is tricky due to the complexity of the files. This is a simple script that extrudes selected layers of the GDSII files into 3D and outputs them as separate 3D STL files for visualization in an external program.

Installation

Install git and Python 3 and its package manager (pip), then install:

pip install numpy
pip install gdspy
pip install numpy-stl
pip install triangle

The modules gdspy and triangle compile C libraries, which may cause trouble on Windows; it might require you to first install Microsoft Visual C++ Build Tools (e.g., from https://visualstudio.microsoft.com/downloads).

Finally:

git clone https://github.com/dteal/gdsiistl

Usage

Suppose you have a GDSII file called file.gds that is to be converted to a 3D STL format.

First, choose GDSII layers to export and their thicknesses by editing gdsiistl.py, specifically, by entering the desired GDSII layer numbers and z bounds in the layerstack variable around line 35.

Second, run python3 gdsiistl.py file.gds. The file will be processed and output files written to file.gds_layername1.stl, file.gds_layername2.stl, etc.

Concretely:

cd gdsiistl
python gdsiistl.py example/example.gds
# output files are example/example.gds_substrate.stl, etc.

Many programs are capable of viewing the output STL files. Blender (https://www.blender.org/) can import STL files, apply materials, and render very impressive visualizations.

Note

Due to a limitation of the library used to triangulate the polygonal boundaries of the GDSII geometry, the polygon borders (i.e., all geometry) are shifted slightly (by a hardcoded delta of about 0.01 units, or 10 nanometers in standard micron units) before export. Furthermore, due to another related limitation/bug (not yet completely understood; see source code comments), extra triangles are sometimes created covering holes in polygons.

So the output mesh is not guaranteed to be watertight, perfectly dimensioned, or retain all polygon holes, but it should be arbitrarily close and err on the side of extra triangles, so a program (e.g., Blender) can edit the mesh by deleting faces and produce a negligibly-far-from perfect visualization.

gdsiistl's People

Contributors

dteal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gdsiistl's Issues

ValueError: [GDSPY] Multiple cells with name <> in GDSII file

Dear Developers,
I recently met a problem when I was dealing with .gds files. I'm using a simulation software called Lumerical, and the gds files they generated could have multiple cells with the same name. Could you please help to think of a way to avoid such problem?
Thank you so much for providing this code. It works fine at situations other than that.

W. Edwards

Easily divided by zero in 45 degrees GDS patterns

Line 153 to 156:
length_ij = np.linalg.norm(normal_ij, axis=1)
length_ik = np.linalg.norm(normal_ik, axis=1)
normal_ij /= np.stack((length_ij, length_ij), axis=1)
normal_ik /= np.stack((length_ik, length_ik), axis=1)
The length_ij and length_ik are easily be zero in offgrid alogn the 45 degrees hypotenuse. Request to add 0.000000001 prevent divided by zero.
length_ij = np.linalg.norm(normal_ij, axis=1)+0.00000001
length_ik = np.linalg.norm(normal_ik, axis=1)+0.00000001
normal_ij /= np.stack((length_ij, length_ij), axis=1)
normal_ik /= np.stack((length_ik, length_ik), axis=1)
To do so, I can easily to translate irregular patterns.

Easily divided by zero in 45 degrees GDS patterns

Line 153 to 156:
length_ij = np.linalg.norm(normal_ij, axis=1)
length_ik = np.linalg.norm(normal_ik, axis=1)
normal_ij /= np.stack((length_ij, length_ij), axis=1)
normal_ik /= np.stack((length_ik, length_ik), axis=1)
The length_ij and length_ik are easily be zero in offgrid alogn the 45 degrees hypotenuse. Request to add 0.000000001 prevent divided by zero.
length_ij = np.linalg.norm(normal_ij, axis=1)+0.00000001
length_ik = np.linalg.norm(normal_ik, axis=1)+0.00000001
normal_ij /= np.stack((length_ij, length_ij), axis=1)
normal_ik /= np.stack((length_ik, length_ik), axis=1)
To do so, I can easily to translate irregular patterns.

Buffer error

Dear all,

The following error message pops up when i try to convert a gds file to stl:

Traceback (most recent call last):
  File "...\gdsiistl\gdsiistl.py", line 52, in <module>
    gdsii.read_gds(gdsii_file_path, units='import')
  File "...\Programs\Python\Python39\lib\site-packages\gdspy\library.py", line 2543, in read_gds
    for record in _record_reader(infile):
  File "...\Programs\Python\Python39\lib\site-packages\gdspy\gdsiiformat.py", line 80, in _record_reader
    struct.unpack(
struct.error: unpack requires a buffer of 616 bytes

I build my gds file in L-Edit, and this could be converted to stl for a while,
however now I get this error and its cause is unknown to me.

The number of bytes changes from time to time.

What could this mean, and how could this be resolved?

kind regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.