gdstk.Library
- class gdstk.Library(name='library', unit=1e-6, precision=1e-9)
GDSII/OASIS library.
The library is a container for multiple cells which keeps track of the units used to generate the design.
- Parameters:
name – Library name.
unit – User units in meters.
precision – Desired precision to store the units once written to a GDSII/OASIS file.
Examples
>>> lib = gdstk.read_gds("filename.gds") >>> num_cells = len(lib) >>> cell = lib["CELL_NAME"]
Notes
Although cells can be accessed by name this is not a cached operation. If many queries are expected, using a cell dictionary is more efficient, for example: >>> cells = {c.name for c in lib.cells} >>> cells[“CELL_NAME”]
See also
Methods
add
(*cells)Add cells to this library.
delete_property
(name)Delete the first property of this element matching a name.
get_property
(name)Return the values of the first property of this element matching a name.
Return a set of tuples with the layer and data types in the library.
Return a set of tuples with the layer and text types in the library.
new_cell
(name)Create a new cell and add it to this library.
remap
(layer_type_map)Remap layers and data/text types for all elements in this library.
remove
(*cells)Remove cells from this library.
rename_cell
(old_name, new_name)Rename a cell in this library, updating any references that use the old name with the new one.
replace
(*cells)Add cells to this library, replacing any cells with the same name.
set_property
(name, value)Set a property for this element.
Return the top-level cells in the library.
write_gds
(outfile[, max_points, timestamp])Save this library to a GDSII file.
write_oas
(outfile[, compression_level, ...])Save this library to an OASIS file.
Attributes
List of library cells.
Library name.
Library precision.
Properties of this element.
Library unit.
- add(*cells) self
Add cells to this library.
Examples
>>> polygon = gdstk.rectangle((0, 0), (1, 1)) >>> cell = gdstk.Cell("MAIN") >>> cell.add(polygon) >>> lib = gdstk.Library() >>> lib.add(cell)
Notes
This method does not check whether cell names are duplicated in the library. If duplicates are found in the library, the resulting file will be invalid.
See also
- cells
List of library cells.
Notes
This attribute is read-only.
- delete_property(name) self
Delete the first property of this element matching a name.
- Parameters:
name (str) – Property name.
- get_property(name) list
Return the values of the first property of this element matching a name.
- Parameters:
name (str) – Property name.
- Returns:
List of property values. If no property is found,
None
is returned.- Return type:
list or None
- layers_and_datatypes() set
Return a set of tuples with the layer and data types in the library.
- layers_and_texttypes() set
Return a set of tuples with the layer and text types in the library.
- name
Library name.
- new_cell(name) gdstk.Cell
Create a new cell and add it to this library.
- Parameters:
name (str) – Name of the new cell.
Examples
>>> lib = gdstk.Library() >>> cell = lib.new_cell("MAIN") >>> polygon = gdstk.rectangle((0, 0), (1, 1)) >>> cell.add(polygon)
- precision
Library precision.
- properties
Properties of this element.
Properties are represented as a list of lists, each containing the property name followed by its values.
- remap(layer_type_map) self
Remap layers and data/text types for all elements in this library.
- Parameters:
layer_type_map – Dictionary mapping existing (layer, type) tuples to desired (layer, type) tuples.
- remove(*cells) self
Remove cells from this library.
- rename_cell(old_name, new_name) self
Rename a cell in this library, updating any references that use the old name with the new one.
- Parameters:
old_name (str or Cell) – Cell or name of the cell to be renamed.
new_name (str) – New cell name.
- replace(*cells) self
Add cells to this library, replacing any cells with the same name.
References to any removed cells are also replaced with the new cell.
Examples
>>> polygon = gdstk.rectangle((-10, -10), (10, 10)) >>> cell = gdstk.Cell("Alignment Mark") >>> cell.add(polygon) >>> lib = gdstk.read_gds("layout.gds") >>> lib.replace(cell)
- set_property(name, value) self
Set a property for this element.
The property name does not have to be unique. Multiple properties can have the same name.
- Parameters:
name (str) – Property name.
value (str, bytes, number, or sequence of those) – Values associated with the property.
Notes
These properties can be used to associate custom metadata with an element, but general properties are not supported by GDSII files, only OASIS. Use the specific methods to access GDSII properties.
- top_level() list
Return the top-level cells in the library.
Top-level cells are cells that do not appear as dependency of any other cells in the library.
- unit
Library unit.
- write_gds(outfile, max_points=199, timestamp=None) None
Save this library to a GDSII file.
- Parameters:
outfile (str or pathlib.Path) – Name of the output file.
max_points – Maximal number of vertices per polygon. Polygons with more vertices that this are automatically fractured.
timestamp (datetime object) – Timestamp to be stored in the GDSII file. If
None
, the current time is used.
See also
- write_oas(outfile, compression_level=6, detect_rectangles=True, detect_trapezoids=True, circletolerance=0, standard_properties=False, validation=None) None
Save this library to an OASIS file.
- Parameters:
outfile (str or pathlib.Path) – Name of the output file.
compression_level – Level of compression for cells (between 0 and 9). Setting to 0 will disable cell compression, 1 gives the best speed and 9, the best compression.
detect_rectangles – Store rectangles in compressed format.
detect_trapezoids – Store trapezoids in compressed format.
circle_tolerance – Tolerance for detecting circles. If less or equal to 0, no detection is performed. Circles are stored in compressed format.
validation ("crc32", "checksum32", None) – type of validation to include in the saved file.
standard_properties – Store standard OASIS properties in the file.
Notes
The standard OASIS options include the maximal string length and integer size used in the file, maximal numbers of polygon and path vertices, cell bounding boxes and cell offsets inside the file. Some of these properties are computationally expensive to calculate. Use only when required.
See also