> For the complete documentation index, see [llms.txt](https://docs.hackerfab.org/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hackerfab.org/home/fab-toolkit/electronic-design-automation/klayout-nmos-array-generation.md).

# KLayout NMOS Array Generation

This script automates the generation of NMOS transistor arrays in KLayout for testing diffusion-to-diffusion spacing variation. It instantiates a grid of NMOS devices with systematically varied horizontal spacing between cells, enabling process characterization of contact formation across different diffusion separations.

#### How It Works

The script places a 4-row × 5-column array of NMOS devices by calling the existing NMosfet PCell from the design library. Each row contains 5 instances with increasing diffusion-to-diffusion spacing: **2, 4, 6, 8, 10 µm.**

For each device instance, contact holes are automatically inserted into both the source and drain diffusion regions. Contacts are placed at fixed local offsets (±4.5 µm from the center) and tiled along the channel width direction at a pitch of 2 µm.

**Device parameters used:**

| Parameter               | Value           |
| ----------------------- | --------------- |
| Channel Length (L)      | 5 µm            |
| Channel Width (W)       | 50 µm           |
| Diffusion Length        | 40 µm           |
| Contact size            | 0.4 µm × 0.4 µm |
| Contact pitch (along W) | 2 µm            |
| Row spacing (Y)         | 100 µm          |

#### Usage

1. Open KLayout and load your layout with the NMOSFET [PCell library](https://drive.google.com/file/d/1JijkHoVu9quq9iSQ7Mib-bWBgk_0gCtn/view?usp=sharing) loaded
2. Open the Ruby macro editor (Macros → Macro Development)
3. Paste the script — [Array.lym](https://drive.google.com/file/d/1sHIxVvulFolX-yR0vw4UT16fFuowBmVC/view?usp=drive_link)
4. Modify the spacing parameters at the top of the script to suit your experiment:

all\_spacings = \[\
\[2.0, 4.0, 6.0, 8.0, 10.0], # Row 0\
\[2.0, 4.0, 6.0, 8.0, 10.0], # Row 1\
\[2.0, 4.0, 6.0, 8.0, 10.0], # Row 2\
\[2.0, 4.0, 6.0, 8.0, 10.0], # Row 3\
]

5. Run the script. The layout will be cleared and regenerated as `CONTACT_MASK_DESIGN`

#### Output

The script produces a single top cell named `CONTACT_MASK_DESIGN` containing the full array. The view automatically fits to the generated layout upon completion.

<figure><img src="https://2353182699-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXgXjz6D0Vz2o0EOp8JO5%2Fuploads%2F4qcYE6FxQsYOe5H986QM%2F%E6%88%AA%E5%B1%8F2026-05-01%20%E4%B8%8B%E5%8D%884.00.25.png?alt=media&amp;token=d7061524-7da0-4797-8a41-0d5054eb4c43" alt=""><figcaption></figcaption></figure>

#### Limitations

* Contact positions are hardcoded relative to the cell center and may need adjustment if the PCell geometry changes.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hackerfab.org/home/fab-toolkit/electronic-design-automation/klayout-nmos-array-generation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
