SpiceCircuit¶
- class PyLTSpice.SpiceEditor.SpiceCircuit[source]¶
Bases:
object
The Spice Circuit represents subcircuits within a SPICE circuit and since subcircuits can have subcircuits inside them, it serves as base for the top level netlist. This hierchical approach helps to encapsulate and protect parameters and components from a edits made a a higher level. The information is stored in a python list, each line of the SPICE netlist is an item of the list. A Subcircuit is represented as a SpiceCircuit object.
- static add_library_search_paths(paths)[source]¶
Adding search paths for libraries. By default the local directory and the ~username/”Documents/LTspiceXVII/lib/sub will be searched forehand. Only when a library is not found in these paths then the paths added by this method will be searched. Alternatively PyLTSpice.SpiceEditor.LibSearchPaths.append(paths) can be used.”
- Parameters:
paths (str) – Path to add to the Search path
- Returns:
Nothing
- Return type:
None
- clone(**kwargs) SpiceCircuit [source]¶
Creates a new copy of the SpiceCircuit. Change done at the new copy are not affecting the original
- Key new_name:
The new name to be given to the circuit
- Returns:
The new replica of the SpiceCircuit object
- Return type:
- get_all_nodes() List[str] [source]¶
A function that retrieves all nodes existing on a Netlist
- Returns:
Circuit Nodes
- Return type:
list[str]
- get_component_floatvalue(element: str) str [source]¶
Returns the value of a component retrieved from the netlist.
- Parameters:
element (str) – Reference of the circuit element to get the value in float format.
- Returns:
value of the circuit element in float type
- Return type:
float
- Raises:
ComponentNotFoundError - In case the component is not found
NotImplementedError - for not supported operations
- get_component_info(component) dict [source]¶
Retrieves the component information as defined in the corresponding REGEX. The line number is also added.
- Parameters:
component (str) – Reference of the component
- Returns:
Dictionary with the component information
- Return type:
dict
- Raises:
UnrecognizedSyntaxError when the line doesn’t match the expected REGEX. NotImplementedError of there isn’t an associated regular expression for the component prefix.
- get_component_nodes(element: str) List[str] [source]¶
Returns the nodes to which the component is attached to.
- Parameters:
element (str) – Reference of the circuit element to get the nodes.
- Returns:
List of nodes
- Return type:
list
- get_component_value(element: str) str [source]¶
Returns the value of a component retrieved from the netlist.
- Parameters:
element (str) – Reference of the circuit element to get the value.
- Returns:
value of the circuit element .
- Return type:
str
- Raises:
ComponentNotFoundError - In case the component is not found
NotImplementedError - for not supported operations
- get_components(prefixes='*') list [source]¶
Returns a list of components that match the list of prefixes indicated on the parameter prefixes. In case prefixes is left empty, it returns all the ones that are defined by the REPLACE_REGEXES. The list will contain the designators of all components found.
- Parameters:
prefixes (str) – Type of prefixes to search for. Examples: ‘C’ for capacitors; ‘R’ for Resistors; etc… See prefixes in SPICE documentation for more details. The default prefix is ‘*’ which is a special case that returns all components.
- Returns:
A list of components matching the prefixes demanded.
- get_parameter(param: str) str [source]¶
Retrieves a Parameter from the Netlist
- Parameters:
param (str) – Name of the parameter to be retrieved
- Returns:
Value of the parameter being sought
- Return type:
str
- Raises:
ParameterNotFoundError - In case the component is not found
- remove_component(designator: str)[source]¶
Removes a component from the design. Note: Current implemetation only alows removal of a component from the main netlist, not from a sub-circuit.
- Parameters:
designator (str) – Component reference in the design. Ex: V1, C1, R1, etc…
- Returns:
Nothing
- Raises:
ComponentNotFoundError - When the component doesn’t exist on the netlist.
- set_component_value(device: str, value: Union[str, int, float]) None [source]¶
Changes the value of a component, such as a Resistor, Capacitor or Inductor. For components inside subcircuits, use the subcirciut designator prefix with ‘:’ as separator (Example X1:R1) Usage:
LTC.set_component_value('R1', '3.3k') LTC.set_component_value('X1:C1', '10u')
- Parameters:
device (str) – Reference of the circuit element to be updated.
value (str, int or float) – value to be be set on the given circuit element. Float and integer values will automatically formatted as per the engineering notations ‘k’ for kilo, ‘m’, for mili and so on.
- Raises:
ComponentNotFoundError - In case the component is not found
ValueError - In case the value doesn’t correspond to the expected format
NotImplementedError - In case the circuit element is defined in a format which is not supported by this version.
If this is the case, use GitHub to start a ticket. https://github.com/nunobrum/PyLTSpice
- set_component_values(**kwargs)[source]¶
Adds one or more components on the netlist. The argument is in the form of a key-value pair where each component designator is the key and the value is value to be set in the netlist.
Usage 1:
LTC.set_component_values(R1=330, R2="3.3k", R3="1Meg", V1="PWL(0 1 30m 1 30.001m 0 60m 0 60.001m 1)")
Usage 2:
value_settings = {'R1': 330, 'R2': '3.3k', 'R3': "1Meg", 'V1': 'PWL(0 1 30m 1 30.001m 0 60m 0 60.001m 1)'} LTC.set_component_values(**value_settings)
- Key <comp_ref>:
The key is the component designator (Ex: V1) and the value is the value to be set. Values can either be strings; integers or floats
- Returns:
Nothing
- Raises:
ComponentNotFoundError - In case one of the component is not found.
- set_element_model(element: str, model: str) None [source]¶
Changes the value of a circuit element, such as a diode model or a voltage supply. Usage:
LTC.set_element_model('D1', '1N4148') LTC.set_element_model('V1' "SINE(0 1 3k 0 0 0)")
- Parameters:
element (str) – Reference of the circuit element to be updated.
model (str) – model name of the device to be updated
- Raises:
ComponentNotFoundError - In case the component is not found
ValueError - In case the model format contains irregular characters
NotImplementedError - In case the circuit element is defined in a format which is not supported by this version.
If this is the case, use GitHub to start a ticket. https://github.com/nunobrum/PyLTSpice
- set_parameter(param: str, value: Union[str, int, float]) None [source]¶
Adds a parameter to the SPICE netlist.
Usage:
LTC.set_parameter("TEMP", 80)
This adds onto the netlist the following line:
.PARAM TEMP=80
This is an alternative to the set_parameters which is more pythonic in it’s usage, and allows setting more than one parameter at once.
- Parameters:
param (str) – Spice Parameter name to be added or updated.
value (str, int or float) – Parameter Value to be set.
- Returns:
Nothing
- set_parameters(**kwargs)[source]¶
Adds one or more parameters to the netlist. Usage:
for temp in (-40, 25, 125): for freq in sweep_log(1, 100E3,): LTC.set_parameters(TEMP=80, freq=freq)
- Key param_name:
Key is the parameter to be set. values the ther corresponding values. Values can either be a str; an int or a float.
- Returns:
Nothing