Working with a big ol' archive of SPICE models & subcircuits

Steve Armour alerted me to this big archive of SPICE models/subcircuits. I had some problems using it because the PySpice parser found errors in some of the files and that caused it to abort and not read the rest of the files (even though they were correct). Also, the archive has a tool for searching for models, but it’s not integrated with PySpice so it’s a bit inconvenient.

I forked PySpice and made some modifications to get around my problems. Now I can work with the model archive as follows:

  • First, install the archive:
    git clone https://github.com/kicad-spice-library/KiCad-Spice-Library
  • The directory with the models is Kicad-Spice-Library/Models.
  • In Python, I can read in all the models:
    from PySpice.Spice.Library import SpiceLibrary as spl
    lib = spl('KiCad-Spice-Library/Models')
    len(lib._models.keys())
        1487
    len(lib._subcircuits.keys())
        9658
  • I can search for a model of a 2N2222 transistor:
    qs = lib.search('.*2222.*')
    qs.keys()
        dict_keys(['q2n2222a', '2N2222', 'PN2222', 'VN2222LL', 'VN2222', 'SMBT2222As', 'SXT2222As', 'PZT2222s', 'PZT2222As', 'MPS2222', 'MPS2222A', 'YTS2222', 'YTS2222A', 'VN2222NC'])
  • I can find the file for a particular model:
    qs['2N2222'].path
        'KiCad-Spice-Library/Models/uncategorized/IdealDiode.lib'
    q = BJT(model='2N2222')
  • When I generate the netlist in SKiDL, I pass the root directory of the archive and it will find the models it needs:
    circuit = generate_netlist(libs='KiCad-Spice-Library/Models')

You’ll need to install my fork if you want these features. I submitted a PR, so maybe they’ll eventually show up in the official PySpice.

1 Like