SpiceEditor

Class used for manipulating SPICE netlists. Inherits from SpiceCircuit.

class PyLTSpice.editor.spice_editor.SpiceEditor(netlist_file: Union[str, Path], 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.

Parameters:
  • netlist_file (str or Path) – Name of the .NET file to parse

  • encoding (str, optional) – 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.

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

property circuit_file: Path

This is only here to avoid breaking compatibility with the BaseEditor superclass. It will always return ‘’

static find_subckt_in_lib(library, subckt_name) Optional[SpiceCircuit][source]

Finds returns a Subckt from a library file.

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

  • subckt_name (str) – sub-circuit to search for

Returns:

Returns a SpiceCircuit instance with the sub-circuit found or None if not found

Return type:

SpiceCircuit

remove_instruction(instruction) None[source]

Usage a previously added instructions. Example:

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

This only works if the instruction exactly matches the line on the netlist. This means that space characters, and upper case and lower case differences will not match the line.

Parameters:

instruction (str) – The list of instructions to remove. Each instruction is of the type ‘str’

Returns:

Nothing

reset_netlist() None[source]

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

Returns:

Nothing

run(wait_resource: bool = True, callback: Optional[Callable[[str, str], Any]] = None, timeout: float = 600, run_filename: Optional[str] = None, simulator=None)[source]

(Deprecated)

Convenience function for maintaining legacy with legacy code.

write_netlist(run_netlist_file: Union[str, Path]) None[source]

Writes the netlist will all the requested updates into a file named <run_netlist_file>.

Parameters:

run_netlist_file (Path or str) – File name of the netlist file.

Returns:

Nothing