{"id":26917116,"url":"https://github.com/georgtree/spicegentcl","last_synced_at":"2026-01-08T20:49:05.454Z","repository":{"id":262166554,"uuid":"829123004","full_name":"georgtree/SpiceGenTcl","owner":"georgtree","description":"Package provides Tcl interface to different SPICE and SPICE-like simulator, Ngspice, Xyce, etc","archived":false,"fork":false,"pushed_at":"2025-03-18T00:32:37.000Z","size":73212,"stargazers_count":6,"open_issues_count":29,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T01:28:24.222Z","etag":null,"topics":["ngspice","spice","spice-simulation","tcl","tcloo","xyce"],"latest_commit_sha":null,"homepage":"https://georgtree.github.io/SpiceGenTcl/","language":"Tcl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/georgtree.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-15T20:05:05.000Z","updated_at":"2025-03-18T00:32:41.000Z","dependencies_parsed_at":"2025-01-16T00:30:48.192Z","dependency_job_id":"065ab421-3300-4ed0-a52c-2723eb07df20","html_url":"https://github.com/georgtree/SpiceGenTcl","commit_stats":null,"previous_names":["georgtree/spicegentcl"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgtree%2FSpiceGenTcl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgtree%2FSpiceGenTcl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgtree%2FSpiceGenTcl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgtree%2FSpiceGenTcl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/georgtree","download_url":"https://codeload.github.com/georgtree/SpiceGenTcl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246706619,"owners_count":20820785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ngspice","spice","spice-simulation","tcl","tcloo","xyce"],"created_at":"2025-04-01T19:51:28.199Z","updated_at":"2026-01-08T20:49:05.448Z","avatar_url":"https://github.com/georgtree.png","language":"Tcl","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cimg src=\"docs/assets/img/spicegentcl_logo.svg\" alt=\"drawing\" width=\"700\"/\u003e\n\nThis package provides Tcl interface to different SPICE and SPICE-like simulator, Ngspice, Xyce.\nIt was inspired by [PySpice](https://github.com/PySpice-org/PySpice) project, object-oriented interface to\nSPICE-like simulators written in Python.\n\n![Static Badge](https://img.shields.io/badge/version-0.71-blue)\n\n![Static Badge](https://img.shields.io/badge/license-MIT-blue)\n\n![Static Badge](https://img.shields.io/badge/Tcl_version-9.0-blue)\n\n![Static Badge](https://img.shields.io/badge/Kubuntu_24.04-pass-green)\n\n![Static Badge](https://img.shields.io/badge/Windows_11-pass-green)\n\n![Static Badge](https://img.shields.io/badge/coverage-93.83%25-green)\n\n## General concept\nThe general concept of the package is to build a netlist using Tcl scripts. It is based on the TclOO\nobject-oriented system, where everything is represented by objects, including elements, models, analyses,\nwaveforms, and netlists. After defining the netlist, you can run the simulation, read the resulting data, and then\nprocess or display the data using the Tcl scripting language.\n\nThis approach differs from the [Tclspice](https://ngspice.sourceforge.io/tclspice.html) extension, which comes\nbundled with Ngspice and is tightly bound to the simulator's internal structures. SpiceGenTcl offers a more\nflexible approach that can be extended to work with different simulators that use netlists with similar syntax.\n\n## Usage examples\nSpiceGenTcl can be used if you need:\n- automate some repetitive simulation tasks, and you don't like\n  [Nutmeg](https://ngspice.sourceforge.io/ngspice-control-language-tutorial.html) syntax (SPICE standard scripting\n  language)\n- postprocess output waveforms and data\n- change netlist structure on the fly\n- simulate different models in the same circuit setup\n- run circuit optimization with parameters variations as well as variations in circuit topology\n- parse existing netlist and gain control over all circuit elements with Tcl\n\nCurrently, there are range of examples for common analyses (DC, AC, transient) for all simulators, and advanced examples\nfor some of them:\n- [Monte-Carlo example](https://georgtree.github.io/SpiceGenTcl/index-Advanced.html#::Advanced-Monte-Carlo%20simulation):\n  Ngspice, Xyce and LTspice\n- [Diode parameters extraction via fitting](https://georgtree.github.io/SpiceGenTcl/index-Advanced.html#::Advanced-Parameters%20extraction%20of%20diode%20model%20parameters):\n  Ngspice, Xyce and LTspice\n- Example of creating custom Verilog-A magnetic core model and simulating transformer with saturation: Ngspice\n- [Inverter power optimization](https://georgtree.github.io/SpiceGenTcl/index-Advanced.html#::Advanced-Inverter%20performance%20optimization):\n  Ngspice\n\n## Supported simulators\n- [Ngspice](https://ngspice.sourceforge.io/download.html) - Linux and Windows\n- [Xyce](https://xyce.sandia.gov/downloads/executables/) - Linux and Windows\n- [LTspice](https://www.analog.com/en/resources/design-tools-and-calculators/ltspice-simulator.html) - Windows and Linux\n  (wine)\n\n## Installing\nYou have two ways: install from git repo (convinient for Linux users) or from archive package release.\n\n### From git repo\nRun following commands:\n- `git clone https://github.com/georgtree/SpiceGenTcl.git`\n- `./configure`\n- `sudo make install`\n\nDuring installing it installs manpages, and local html documentation in `/usr/local/share/SpiceGenTcl/doc`.\n\nFor test package in place run `make test`.\n\nFor package uninstall run `sudo make uninstall`.\n\n### From archive\nTo install the package you should extract archive with source code and add path of the package folder to `auto_path`\nvariable:\n```tcl\nlappend auto_path \"path to SpiceGenTcl package\"\n```\n\n## Dependencies\nPackage is written in pure Tcl with relying on multiple libraries, tcl version is 9.0. \n\n- [Tcllib](https://www.tcl.tk/software/tcllib/)\n- [argparse](https://github.com/georgtree/argparse)\n- [ticklecharts](https://github.com/nico-robert/ticklecharts)\n- [tclmeasure](https://github.com/georgtree/tclmeasure)\n\nFor some examples you also need these packages:\n\n- [tclinterp](https://github.com/georgtree/tclinterp)\n- [tclopt](https://github.com/georgtree/tclopt)\n- [NgspiceTclBridge](https://github.com/georgtree/NgspiceTclBridge)\n\nAfter simulator installation add path to executable to `PATH` environment variable.\n\nFor code coverage test [nagelfar](https://nagelfar.sourceforge.net/) is used, commit 845924 of master branch.\n\nFor view test coverage diffs [eskil](http://eskil.tcl.tk/index.html/doc/trunk/htdocs/index.html) is used.\n\n## Documentation and tutorials\n\nDocumentation could be found [here](https://georgtree.github.io/SpiceGenTcl/). \n\nTutorials describing different examples could be found [here](https://georgtree.github.io/SpiceGenTcl/index-Tutorials.html).\n\nGood tutorial for Tcl language could be found [here](http://tcl.tk/man/tcltutorial/html/tcltutorial.html)\n\nDocumentation was generated with [ruff!](https://ruff.magicsplat.com/).\n\nTcl syntax highlighting was done with [hl_tcl](https://github.com/aplsimple/hl_tcl).\n\n## Supported platforms\n\nI personally use Kubuntu 24.04, and I also tested package on Windows 11. \nOn Kubuntu I use Tcl/Tk 9.0 compiled from sources, as well as Ngspice and Xyce.\nOn Windows I use [Magicsplat](https://www.magicsplat.com/tcl-installer/) distribution of Tcl/Tk 9.0. For\nNgspice and Xyce I use precompilled binaries.\n\n\u003cfont color=\"red\"\u003e**Note**\u003c/font\u003e: on Windows by default Ngspice save raw file into ascii format, to pass all tests\n(because of different numbers formatting - scientific by default) you need to set binary format by default in .spiceinit\nby this line:\n```spice\nset filetype=binary\n```\n\nTcl is a cross-platform language, and because this package is written in pure Tcl, \nyou can practically run it on any platform, including Windows, Linux (all flavors), and FreeBSD. \nNgspice is available as pre-compiled binaries for Linux and Windows, but it can also be compiled on FreeBSD.\nXyce is availible as pre-compiled for Windows, RHEL and MacOS, but can be compiled to any other platform.\n\n## Quick start\n\n- \u003cfont color=\"red\"\u003e **Important note 1**\u003c/font\u003e: internally, all device names, parameters, nodes, types, \nreference names, and data vector's names are converted to lowercase after object instantiation. While you can enter\nthem in any case, they can only be accessed by their lowercase names. This approach aligns with the fact that most\nSPICE simulators are case-insensitive. To prevent ambiguity in Tcl code, where the simulator treats mixed-case\nnames as identical, we convert everything to lowercase. This ensures that we can detect and resolve any duplicate\nnames in the top-level circuit before generating the netlist.\n- \u003cfont color=\"red\"\u003e **Important note 2**\u003c/font\u003e: this package is not designed to be used with the `.control`\nsection in Ngspice, the .step statement in LTspice, or multiple DC sweeps, and it does not support reading\nparametric sweeps from raw data. The idea of the package is to handle all such tasks within a Tcl script, \neliminating the need to use the simulator's internal scripting capabilities, and dependence on each simulator\nunique ways of handling parametric sweeps, that compromises compatibility. But it is could be done easily in\nprinciple to realize special objects and reading of raw files with parametric sweeps.\n- \u003cfont color=\"red\"\u003e **Important note 3**\u003c/font\u003e: in this package the following aliases for commands are defined:\n```tcl\ninterp alias {} dget {} dict get\ninterp alias {} @ {} lindex\ninterp alias {} = {} expr\ninterp alias {} dexist {} dict exists\ninterp alias {} dcreate {} dict create\ninterp alias {} dset {} dict set\ninterp alias {} dappend {} dict append\ninterp alias {} dkeys {} dict keys\ninterp alias {} dvalues {} dict values\n```\n- \u003cfont color=\"red\"\u003e **Important note 4**\u003c/font\u003e: source code follows the pattern, if method or variable name\nof the class starts from capital letter, it is intended to be private and not directly accessible from outside the \nobject. Even if variable defined as a `property` (you can access it with `configure` method) and start from capital \nletter, it is better to not try to access it directly.\n### Packages imports\n\nThe first step is import of package:\n```tcl\npackage require SpiceGenTcl\n```\nImport all commands from ::SpiceGenTcl:\n```tcl\nnamespace import ::SpiceGenTcl::*\n```\nOne of the commands is [::SpiceGenTcl::importNgspice]. By calling this command, we can import all commands related\nto the Ngspice simulator, eliminating the need to add the `::SpiceGenTcl::Ngspice` prefix before any command. \nHere's how to do it:\n```tcl\nimportNgspice\n```\nTo plot results of simulation we also import package `ticklecharts`:\n```tcl\npackage require ticklecharts\n```\n\n### Circuit definition\n\nLet's try to define simple resistor divider circuit with following netlist:\n```\nvoltage divider netlist\nv1 in 0 1\nr1 in out 1e3\nr2 out 0 2e3\n.dc v1 0 5 0.1\n```\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"docs/assets/img/resistor_divider_cir_black_github.png\"\u003e\n  \u003cimg alt=\"\" src=\"docs/assets/img/resistor_divider_cir_white.png\" width=50% height=50%\u003e\n\u003c/picture\u003e\n\n\nFirst step is creating circuit object:\n```tcl\nset circuit [Circuit new {voltage divider netlist}]\n```\nThe `Circuit` command creates a new object of the `::SpiceGenTcl::Circuit` class, which is imported from the \n`::SpiceGenTcl` namespace and represents the top-level circuit. \nThe only argument we provide is the name of the circuit, which will be printed on the first line of the netlist.\n\nThe next step is building netlist by addding elements to top circuit object:\n```tcl\n$circuit add [Vdc new 1 in 0 -dc 1]\n$circuit add [R new 1 in out -r 1e3]\n$circuit add [R new 2 out 0 -r 2e3]\n$circuit add [Dc new -src v1 -start 0 -stop 5 -incr 0.1]\n```\nAn instance of the `::SpiceGenTcl::Circuit` class, referenced by the `circuit` variable, has an\n`::SpiceGenTcl::Circuit::add` method that appends the references of argument objects to it. The object-creating\ncommands `Vdc`, `R`, and `Dc` — which represent a DC voltage source, a basic resistor, and a DC analysis,\nrespectively — are imported from the `::SpiceGenTcl::Ngspice::Sources`, `::SpiceGenTcl::Ngspice::BasicElements`, \nand `::SpiceGenTcl::Ngspice::Analyses` namespaces.\n\nWhen using the `new` subcommand, you provide the basic arguments for the element. For example, in the `R` command,\nyou would supply the name '1', the name of the net connected to the positive node 'in', the name of the net\nconnected to the negative node '0' (which is the global ground), and the resistance value '1e3'.\n\nThe last necessary step is to create `::SpiceGenTcl::Simulator` object with command `Batch` from\n`::SpiceGenTcl::Ngspice` namespace and attach it to `::SpiceGenTcl::Circuit` object:\n```tcl\nset simulator [Batch new {batch1} {/usr/local/bin/}]\n$circuit configure -Simulator $simulator\n```\nNow we are ready to run simulation:\n```tcl\n$circuit runAndRead\n```\nAfter the simulation, we can read the resulting data. We use the `::SpiceGenTcl::Circuit::getDataDict` method to\nobtain a dictionary where the keys are the names of the result vectors:\n```tcl\nset data [$circuit getDataDict]\n```\nThe we can get vectors v(in) and v(out) from dictionary `data`:\n```tcl\nset axis [dict get $data v(in)]\nset trace [dict get $data v(out)]\n```\n\n### Plotting data\n\nTo plot results we use [`ticklecharts`](https://github.com/nico-robert/ticklecharts) package:\n```tcl\nforeach x $axis y $trace {\n    set x [format \"%.3f\" $x]\n    set y [format \"%.3f\" $y]\n    lappend xydata [list $x $y]\n}\nset chart [ticklecharts::chart new]\n$chart Xaxis -name \"v(in), V\" -minorTick {show \"True\"} -min 0 -max 5 -type \"value\" -splitLine {show \"True\"}\n$chart Yaxis -name \"v(out), V\" -minorTick {show \"True\"} -min 0 -max 3.5 -type \"value\" -splitLine {show \"True\"}\n$chart SetOptions -title {} -tooltip {trigger \"axis\"} -animation \"False\" -backgroundColor \"#212121\"\n$chart Add \"lineSeries\" -data $xydata -showAllSymbol \"nothing\"\nset fbasename [file rootname [file tail [info script]]]\n$chart Render -outfile [file normalize [file join .. html_charts $fbasename.html]]\n```\nTo view result, we should open rendered resistor_divider.html chart in browser.\n\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"docs/assets/img/resistor_divider_graph_black_github.png\"\u003e\n  \u003cimg alt=\"\" src=\"docs/assets/img/resistor_divider_graph_white.png\" width=100% height=100%\u003e\n\u003c/picture\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgtree%2Fspicegentcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeorgtree%2Fspicegentcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgtree%2Fspicegentcl/lists"}