SpiceEditor

class PyLTSpice.SpiceEditor.SpiceEditor(netlist_file, encoding='autodetect')[source]

Bases: SpiceCircuit

This class implements interfaces to manipulate SPICE netlist files. The class doesn’t update the netlist file itself. After implementing the modifications the user should call the “write_netlist” method to write a new netlist file. :param netlist_file: Name of the .NET file to parse :type netlist_file: str :param encoding: Forcing the encoding to be used on the circuit netlile read. Defaults to ‘autodetect’ which will call a function that tries to detect the encoding automatically. This however is not 100% fool proof. :type encoding: str, optional

add_instruction(instruction: str) None[source]

Serves to add SPICE instructions to the simulation netlist. For example:

.tran 10m ; makes a transient simulation
.meas TRAN Icurr AVG I(Rs1) TRIG time=1.5ms TARG time=2.5ms" ; Establishes a measuring
.step run 1 100, 1 ; makes the simulation run 100 times
Parameters:

instruction (str) – Spice instruction to add to the netlist. This instruction will be added at the end of the netlist, typically just before the .BACKANNO statement

Returns:

Nothing

add_instructions(*instructions) None[source]

Adds a list of instructions to the SPICE NETLIST. Example:

LTC.add_instructions(
    ".STEP run -1 1023 1",
    ".dc V1 -5 5"
)
Parameters:

instructions (list) – Argument list of instructions to add

Returns:

Nothing

static find_subckt_in_lib(library, subckt_name) SpiceEditor[source]

Finds returns a Subckt from a library file

Parameters:
  • library (str) – path to the library to search

  • subckt_name – Subcircuit to search for

remove_instruction(instruction) None[source]

Usage a previously added instructions. Example:

LTC.remove_instruction(".STEP run -1 1023 1")

:param instructions The list of instructions to remove. Each instruction is of the type ‘str’ :type instruction: str :returns: Nothing TODO: This only works with a full line instruction. Make it more inteligent so it recognizes .models, .param and .subckt

reset_netlist() None[source]

Removes all previous edits done to the netlist, i.e. resets it to the original state.

Returns:

Nothing

write_netlist(run_netlist_file: str) None[source]

Writes the netlist will all the requested updates into a file named <run_netlist_file>. :param run_netlist_file: File name of the netlist file. :type run_netlist_file: str :return Nothing