Plugin API Reference¶
API for the RKViewer GUI and model. Allows viewing and modifying the network model.
-
class
rkviewer.plugin.api.
CompartmentData
(index: int, id: str, net_index: int, nodes: List[int], volume: float, position: rkviewer.canvas.geometry.Vec2, size: rkviewer.canvas.geometry.Vec2, fill_color: rkviewer.config.Color, border_color: rkviewer.config.Color, border_width: float)[source] -
index
Compartment index. Despite the name, this is the value that acts as the constant identifier for compartments. ID, on the other hand, may be modified.
-
id
Compartment ID. Note: NOT constant; see index for constant identifiers.
-
net_index
The index of the network that this is in.
-
nodes
Indices for nodes that are within this compartment.
-
volume
Size (i.e. length/area/volume/…) of the container, for simulation purposes.
-
position
Position of the top-left corner of the bounding box, (x, y).
-
size
Size of the bounding box, as (w. h).
-
fill_color
The fill color of the compartment.
-
border_color
The border color of the compartment.
-
border_width
The border width of the compartment.
-
-
class
rkviewer.plugin.api.
CustomNone
[source] Used for default parameters where ‘None’ is a valid and possible input.
-
class
rkviewer.plugin.api.
NodeData
(net_index: int, id: str, position: rkviewer.canvas.geometry.Vec2 = (0, 0), size: rkviewer.canvas.geometry.Vec2 = (0, 0), comp_idx: int = -1, index: int = -1, floating_node: bool = True, lock_node: bool = False, original_index: int = -1, shape_index: int = 0, shape: rkviewer.canvas.data.CompositeShape = <factory>, concentration: float = 0.0, node_name: str = '', node_SBO: str = '')[source] Class that holds all the necessary data for a Node.
-
index
Node index. Despite the name, this is the value that acts as the constant identifier for nodes. ID, on the other hand, may be modified. If this is -1, it means that this Node is not currently part of a network.
-
id
Node ID. Note: NOT constant; see index for constant identifiers.
-
net_index
The index of the network that this node is in.
-
position
The top-left position of the node bounding box as (x, y).
-
size
The size of the node bounding box as (w, h).
-
comp_idx
The index of the compartment that this node is in, or -1 if it is in the base compartment.
-
floating_node
Set true if you want the node to have floating status or false for boundary status (default is floating)
-
lock_node
Set false if you want the node to move or true for block (default is false)
-
original_index
If this is an alias node, this is the index of the original node. Otherwise this is -1.
-
shape_index
The composite shape index of the node. 0 for rectangle, 1 for circle, and so on. For the full list of shapes, view iodine.py
-
shape
The CompositeShape object of the node. This is guaranteed to match the shape as indicated by shape_index. This field is present for convenient access of the shape’s properties, including the primitives contained within and the properties of the primitive.
-
concentration
The concentration of the node. Default to zero, must not be negative.
-
node_name
The name of the node.
-
node_SBO
The SBO of the node.
- Parameters
net_index (
int
) –id (
str
) –position (
Vec2
) –size (
Vec2
) –comp_idx (
int
) –index (
int
) –floating_node (
bool
) –lock_node (
bool
) –original_index (
int
) –shape_index (
int
) –shape (
CompositeShape
) –concentration (
float
) –node_name (
str
) –node_SBO (
str
) –
-
-
class
rkviewer.plugin.api.
ReactionData
(id: str, net_index: int, fill_color: rkviewer.config.Color, line_thickness: float, sources: List[int], targets: List[int], center_pos: Optional[rkviewer.canvas.geometry.Vec2] = None, rate_law: str = '', using_bezier: bool = True, index: int = -1, modifiers: Set[int] = <factory>, modifier_tip_style: rkviewer.canvas.data.ModifierTipStyle = <ModifierTipStyle.CIRCLE: 'circle'>)[source] Class that bolds the data of a Reaction, except for stoich information (TODO?).
-
index
reaction index. Despite the name, this is the value that acts as the constant identifier for reactions. ID, on the other hand, may be modified.
-
id
Reaction ID. Note: NOT constant; see index for constant identifiers.
-
net_index
The index of the network that this node is in.
-
fill_color
reaction fill color.
-
line_thickness
Bezier curve thickness.
-
rate_law
reaction rate law.
-
sources
The source (reactant) node indices.
-
targets
The target (product) node indices.
- Parameters
id (
str
) –net_index (
int
) –fill_color (
Color
) –line_thickness (
float
) –sources (
List
[int
]) –targets (
List
[int
]) –center_pos (
Optional
[Vec2
]) –rate_law (
str
) –using_bezier (
bool
) –index (
int
) –modifiers (
Set
[int
]) –modifier_tip_style (
ModifierTipStyle
) –
-
property
centroid
The position of the centroid of this reaction
- Return type
-
property
real_center
The position of the reaction center circle.
If the center has been manually moved by the user, then this would be equal to center_pos. Otherwise this is equal to the dynamically computed centeroid position.
- Return type
-
-
rkviewer.plugin.api.
add_alias
(net_index, original_index, position=None, size=None)[source] Adds an alias node to the network.
The node indices are assigned in increasing order, regardless of deletion.
- Parameters
net_index (
int
) – The network index.original_index (
int
) – The index of the original node, from which to create an aliasposition (
Optional
[Vec2
]) – The position of the alias, or leave as None to use default, (0, 0).size (
Optional
[Vec2
]) – The size of the alias, or leave as None to use default, (0, 0).
- Returns
The index of the alias that was added.
-
rkviewer.plugin.api.
add_compartment
(net_index, id, fill_color=None, border_color=None, border_width=None, position=None, size=None, volume=None, nodes=None)[source] Adds a compartment.
The Compartment indices are assigned in increasing order, regardless of deletion.
- Parameters
- Return type
int
- Returns
The index of the compartment that was added.
-
rkviewer.plugin.api.
add_node
(net_index, id, fill_color=None, border_color=None, border_width=None, position=None, size=None, comp_idx=- 1, floating_node=True, lock_node=False, shape_index=0, concentration=0.0, node_name='', node_SBO='')[source] Adds a node to the given network.
The node indices are assigned in increasing order, regardless of deletion.
- Parameters
net_index (
int
) – The network index.id (
str
) – The ID of the node.fill_color (
Optional
[Color
]) – The fill color of the node, or leave as None to use current theme.border_color (
Optional
[Color
]) – The border color of the node, or leave as None to use current theme.border_width (
Optional
[float
]) – The border width of the node, or leave as None to use current theme.position (
Optional
[Vec2
]) – The position of the node, or leave as None to use default, (0, 0).size (
Optional
[Vec2
]) – The size of the node, or leave as None to use default, (0, 0).comp_idx (
int
) – The index of the compartment that the node is in, default as -1.shape_index (
int
) – The index of the CompositeShape of the node. 0 (rectangle) by default.concentration (
float
) – The concentration of the node, or leave as None to use default, 0.0.node_name (
str
) – The name of the node.node_SBO (
str
) – The SBO of the node.floating_node (
bool
) –lock_node (
bool
) –
- Return type
int
- Returns
The index of the node that was added.
-
rkviewer.plugin.api.
add_reaction
(net_index, id, reactants, products, fill_color=None, line_thickness=None, rate_law='', handle_positions=None, center_pos=None, use_bezier=True, modifiers=None)[source] Adds a reaction.
The reaction indices are assigned in increasing order, regardless of deletion. See ReactionData for more documentation on the fields.
- Parameters
net_index (
int
) – The network index.id (
str
) – The ID of the reaction.reactants (
List
[int
]) – The list of reactant node indices.products (
List
[int
]) – The list of product node indices.fill_color (
Optional
[Color
]) – The fill color of the reaction line, or leave as None to use current theme.line_thickness (
Optional
[float
]) – The thickness of the reaction line, or leave as None to use current theme.rate_law (
str
) – The reaction rate law; defaults to empty string.handle_positions (
Optional
[List
[Vec2
]]) – The initial positions of the Bezier handlescenter_pos (
Optional
[Vec2
]) – The position of the reaction center. If None, the center position will be automatically set as the centroid of all the species and will dynamically move as nodes are moved.use_bezier (
bool
) – If specified, whether to use Bezier curves when drawing the reaction. If False, simply use straight lines.modifiers (
Optional
[Set
[int
]]) – The set of reaction of modifiers, defaulting to None. If None, no modifiers will be added.
- Return type
int
- Returns
The index of the reaction that was added.
-
rkviewer.plugin.api.
canvas_scale
()[source] Return the zoom scale of the _canvas.
- Return type
float
-
rkviewer.plugin.api.
clear_network
(net_index)[source] Clear the given network.
- Parameters
net_index (
int
) –
-
rkviewer.plugin.api.
compartments_count
(net_index)[source] Returns the number of compartments in the given network.
- Parameters
net_index (
int
) –- Return type
int
-
rkviewer.plugin.api.
compute_centroid
(net_index, reactants, products)[source] Compute the centroid of the given sets of reactant and product nodes.
The centroid is used as the position of the center circle of reactions.
- Parameters
net_index (
int
) – The network index.reactants (
List
[int
]) – The list of reactant node indices.products (
List
[int
]) – The list of product node indices.
-
rkviewer.plugin.api.
cur_net_index
()[source] The current network index.
- Return type
int
-
rkviewer.plugin.api.
default_handle_positions
(net_index, reaction_index)[source] Return the default Bezier handle positions for the given reaction.
See Reaction for more details on the format of this list.
- Parameters
net_index (
int
) – The network index.reaction_index (
int
) – The index of the reaction.
- Return type
List
[Vec2
]
-
rkviewer.plugin.api.
delete_compartment
(net_index, comp_index)[source] Delete a node with the given index in the given network.
Nodes that are within this compartment are dropped to the base compartment (index -1).
- Parameters
net_index (
int
) – The network index.comp_index (
int
) – The compartment index.
- Raises
CompartmentIndexError – If the given node does not exist in the network.
-
rkviewer.plugin.api.
delete_node
(net_index, node_index)[source] Delete a node with the given index in the given network.
If the node does not exist, return False; otherwise return True. This method does not throw an error when the given node is missing, because the user may potentially be deleing nodes in a loop, and if an original node is deleted before its aliases, when the alias is reached it would no longer be in the network.
If you want to make certain that a node does exist, use the return value of this function.
- Parameters
net_index (
int
) – The network index.node_index (
int
) – The node index.
- Return type
bool
- Returns
True if and only if a node was deleted.
- Raises
NetIndexError – If the given network does not exist
NodeNotFreeError – If the given node is part of a reaction.
-
rkviewer.plugin.api.
delete_reaction
(net_index, reaction_index)[source] Delete a reaction with the given index in the given network.
- Parameters
net_index (
int
) – The network index.reaction_index (
int
) – The reaction index.
- Raises
ReactionIndexError – If the given reaction does not exist in the network.
-
rkviewer.plugin.api.
get_application_position
()[source] Return the absolute position of thetop left corner of the applcition
- Return type
-
rkviewer.plugin.api.
get_canvas
()[source] Obtain the Canvas instance.
This is for advanced use cases that require direct access to the Canvas, for operations that have not been implmented in the API.
- Return type
Optional
[Canvas
]
-
rkviewer.plugin.api.
get_compartment_by_index
(net_index, comp_index)[source] Given an index, return the compartment that it corresponds to.
- Parameters
net_index (int) – The network index.
comp_index (int) – The compartment index.
- Return type
CompartmentData
- Returns
The node that corresponds to the given indices.
-
rkviewer.plugin.api.
get_compartment_indices
(net_index)[source] Get the set of compartment indices (immutable).
- Parameters
net_index (
int
) –- Return type
Set
[int
]
-
rkviewer.plugin.api.
get_compartment_of_node
(net_index, node_index)[source] Return the compartment that the node is in, or -1 if it is in the base compartment.
- Parameters
net_index (
int
) –node_index (
int
) –
- Return type
int
-
rkviewer.plugin.api.
get_compartments
(net_index)[source] Returns the list of all compartments in a network.
Note
Modifying elements of this list will not update the _canvas.
- Return type
List
[CompartmentData
]- Returns
The list of compartments.
- Parameters
net_index (
int
) –
-
rkviewer.plugin.api.
get_default_arrow_tip
()[source] Gets the default arrow tip.
- Return type
-
rkviewer.plugin.api.
get_network_bounds
(net_index)[source] Return the rectangular bounds of a network.
- Parameters
net_index (
int
) –
-
rkviewer.plugin.api.
get_node_by_index
(net_index, node_index)[source] Given an index, return the node that it corresponds to.
- Parameters
net_index (int) – The network index.
node_index (int) – The node index.
- Return type
NodeData
- Returns
The node that corresponds to the given indices.
-
rkviewer.plugin.api.
get_node_indices
(net_index)[source] Get the set of node indices (immutable).
- Parameters
net_index (
int
) –- Return type
Set
[int
]
-
rkviewer.plugin.api.
get_nodes
(net_index)[source] Returns the list of all nodes in a network.
Note
Modifying elements of this list will not update the _canvas.
- Return type
List
[NodeData
]- Returns
The list of nodes.
- Parameters
net_index (
int
) –
-
rkviewer.plugin.api.
get_nodes_in_compartment
(net_index, comp_index)[source] Return the list node indices in the given compartment.
- Parameters
net_index (
int
) –comp_index (
int
) –
- Return type
List
[int
]
-
rkviewer.plugin.api.
get_product_stoich
(net_index, product_index, node_index)[source] Returns the stoichiometry of a product node.
- Parameters
net_index (
int
) – The network index.reaction_index – The index of the reaction.
node_index (
int
) – The index of the node which must be a product of the reaction.product_index (
int
) –
- Raises
NodeIndexError – If the given node index does not match any existing node.
ValueError – If the given node index exists but is not a product of the reaction.
- Return type
float
-
rkviewer.plugin.api.
get_reactant_stoich
(net_index, reaction_index, node_index)[source] Returns the stoichiometry of a reactant node.
- Parameters
net_index (
int
) – The network indexreaction_index (
int
) – The index of the reaction.node_index (
int
) – The index of the node which must be a reactant of the reaction.
- Raises
NodeIndexError – If the given node index does not match any existing node.
ValueError – If the given node index exists but is not a reactant of the reaction.
- Return type
float
-
rkviewer.plugin.api.
get_reaction_by_index
(net_index, reaction_index)[source] Given an index, return the reaction that it corresponds to.
- Parameters
net_index (int) – The network index.
reaction_index (int) – The reaction index.
- Return type
ReactionData
- Returns
The reaction that corresponds to the given indices.
-
rkviewer.plugin.api.
get_reaction_center_handle
(net_index, reaction_index)[source] Get the position of the Bezier handle at the center of the given reaction.
- Parameters
net_index (
int
) – The network index.reaction_index (
int
) – The index of the reaction whose center Bezier handle position to get.handle_pos – The new position of the Bezier handle.
- Raises
- Return type
-
rkviewer.plugin.api.
get_reaction_indices
(net_index)[source] Get the set of reaction indices (immutable).
- Parameters
net_index (
int
) –- Return type
Set
[int
]
-
rkviewer.plugin.api.
get_reaction_node_handle
(net_index, reaction_index, node_index, is_source)[source] Get the position of the reaction Bezier handle associated with a node.
- Parameters
net_index (
int
) – The network index.reaction_index (
int
) – The reaction index.node_index (
int
) – The index of the node whose Bezier handle position to get.is_source (
bool
) – Whether the node is a source node. If a node is both a source and a target node, it would have two Bezier handles, hence the distinction.
- Raises
NodeIndexError – If the given node index is not found
ValueError – If the given node is found but it is not an indicated node of the reaction.
- Return type
-
rkviewer.plugin.api.
get_reactions
(net_index)[source] Returns the list of all reactions in a network.
Note
Modifying elements of this list will not update the _canvas.
- Return type
List
[ReactionData
]- Returns
The list of reactions.
- Parameters
net_index (
int
) –
-
rkviewer.plugin.api.
get_reactions_as_product
(net_index, node_index)[source] Get the set of reactions (indices) of which this node is a product.
- Parameters
net_index (
int
) –node_index (
int
) –
- Return type
Set
[int
]
-
rkviewer.plugin.api.
get_reactions_as_reactant
(net_index, node_index)[source] Get the set of reactions (indices) of which this node is a reactant.
- Parameters
net_index (
int
) –node_index (
int
) –
- Return type
Set
[int
]
-
rkviewer.plugin.api.
get_selected_compartment_indices
()[source] Return the set of selected compartment indices.
- Return type
Set
[int
]
-
rkviewer.plugin.api.
get_selected_node_indices
(net_index)[source] Return the set of selected node indices.
- Parameters
net_index (
int
) –- Return type
Set
[int
]
-
rkviewer.plugin.api.
get_selected_reaction_indices
()[source] Return the set of selected reaction indices.
- Return type
Set
[int
]
-
rkviewer.plugin.api.
group_action
()[source] Context manager for doing a group operation in the _controller, for undo/redo purposes.
Examples
As shown here, calls to the API within the group_action context are considered to be within one single group as far as undoing/redoing is concerned.
>>> with api.group_action(): >>> for node in some_node_list: >>> api.update_node(...) >>> api.update_reaction(...) >>> api.update_node(...) # This is now a new action.
-
rkviewer.plugin.api.
init_api
(canvas, controller)[source] Initializes the API; for internal use only.
- Parameters
canvas (
Canvas
) –controller (
IController
) –
-
rkviewer.plugin.api.
is_product
(net_index, node_index, reaction_index)[source] Return whether the given node is a product of the given reaction.
This runs linearly to the number of products of the given reaction. If your reaction is very very large, then construct a set from its products and test for membership manually.
- Parameters
net_index (
int
) –node_index (
int
) –reaction_index (
int
) –
- Return type
bool
-
rkviewer.plugin.api.
is_reactant
(net_index, node_index, reaction_index)[source] Return whether the given node is a reactant of the given reaction.
This runs linearly to number of reactants of the given reaction. If your reaction is very very large, then construct a set from its reactants and test for membership manually.
- Parameters
net_index (
int
) –node_index (
int
) –reaction_index (
int
) –
- Return type
bool
-
rkviewer.plugin.api.
logger
()[source] Return the logger for plugins. Use this for logging inside plugins.
- Return type
Logger
-
rkviewer.plugin.api.
move_compartment
(net_index, comp_index, position)[source] Change the position of a compartment.
- Parameters
net_index (
int
) –comp_index (
int
) –position (
Vec2
) –
-
rkviewer.plugin.api.
move_node
(net_index, node_index, position, allowNegativeCoordinates=False)[source] Change the position of a node.
- Parameters
net_index (
int
) –node_index (
int
) –position (
Vec2
) –allowNegativeCoordinates (
bool
) –
-
rkviewer.plugin.api.
node_count
(net_index)[source] Returns the number of nodes in the given network.
- Parameters
net_index (
int
) –- Return type
int
-
rkviewer.plugin.api.
reaction_count
(net_index)[source] Returns the number of reactions in the given network.
- Parameters
net_index (
int
) –- Return type
int
-
rkviewer.plugin.api.
refresh_canvas
()[source] Tell the canvas to redraw itself.
This does not need to be called manually when there are changes to the model, since the model automatically updates the canvas. But if changes are made only to CanvasElements, then this is required to reflect the changes.
-
rkviewer.plugin.api.
resize_node
(net_index, node_index, size)[source] Change the size of a node.
- Parameters
net_index (
int
) –node_index (
int
) –size (
Vec2
) –
-
rkviewer.plugin.api.
selected_node_indices
()[source] Returns the set of indices of the selected nodes.
- Return type
Set
[int
]- Returns
The set of selected nodes’ indices.
-
rkviewer.plugin.api.
selected_nodes
()[source] Returns the list of selected nodes.
Note
Modifying elements of this list will not update the _canvas.
- Return type
List
[NodeData
]- Returns
The list of selected nodes.
-
rkviewer.plugin.api.
selected_reaction_indices
()[source] Returns the set of indices of the selected reactions.
- Return type
Set
[int
]- Returns
The set of selected reactions’ indices.
-
rkviewer.plugin.api.
set_arrow_tip
(value)[source] Set the arrow tip to a given one.
- Parameters
given ArrowTip to set to. (The) –
value (
ArrowTip
) –
-
rkviewer.plugin.api.
set_compartment_of_node
(net_index, node_index, comp_index)[source] Move the node to the given compartment. Set comp_index to -1 to move it to the base compartment.
- Parameters
net_index (
int
) –node_index (
int
) –comp_index (
int
) –
-
rkviewer.plugin.api.
set_node_shape_property
(net_index, node_index, primitive_index, prop_name, prop_value)[source] Set a property of the node’s composite shape, e.g. fill color.
NOTE specify -1 for primitive_index to modify the text primitive of the node.
For this, one needs to specify a particular primitive inside the composite shape. For example, if a node is composed of two circles, there are two circle primitives (CirclePrim) inside the node’s shape. One can only update the property of one primitive at a time, e.g. primitive_index = 0 for the first circle, and primitive_index = 1 for the second.
One also must specify the property name (prop_name), which is a string. Some common property names are ‘fill_color’, ‘border_color’, ‘border_width’. Each particular primitive may have other properties. For more details, see the subclasses of Primitive in rkviewer/canvas/data.py.
As an example, for node with index 5 in network 0 with two circles in its CompositeShape, to set the fill color of circle 1 to red, do `set_node_shape_property(0, 5, 1, ‘fill_color’, Color(255, 0, 0)).
Note that an error will be thrown if there is a mismatch between the supplied prop_value and the expected type. For example, you cannot assign 1 to ‘fill_color’, only objects of type Color. Also an error will be thrown if the primitive index is out of bounds on the current shape that the node has. Therefore, you should make sure that the node has the shape (or at least the primitive count and primitive properties) that you expect before calling this function.
- Parameters
net_index (
int
) – The network index.node_index (
int
) – The index of the node.primitive_index (
int
) – The index of the shape primitive whose property to update. To set the text properties of the node, specify -1 here.prop_name (
str
) – The name of the property whose value to set.prop_value (
Any
) – The new value of the property.
-
rkviewer.plugin.api.
set_parameter_value
(net_index, param_id, param_value)[source] Adds a parameter to a model, or updates parameter value if model already contains parameter
- Parameters
net_index (
int
) –param_id (
str
) –param_value (
float
) –
-
rkviewer.plugin.api.
set_product_stoich
(net_index, reaction_index, node_index, stoich)[source] Sets the product’s stoichiometry.
- Parameters
net_index (
int
) – The network index.reaction_index (
int
) – The index of the reaction.node_index (
int
) – The index of the node which must be a product of the reaction.stoich (
int
) – The new stoichiometry value.
- Raises
NodeIndexError – If the given node index does not match any existing node.
ValueError – If the given node index exists but is not a reactant of the reaction.
-
rkviewer.plugin.api.
set_reactant_stoich
(net_index, reaction_index, node_index, stoich)[source] Set the stoichiometry of a reactant node.
- Parameters
net_index (
int
) – The network indexreaction_index (
int
) – The index of the reaction.node_index (
int
) – The index of the node which must be a reactant of the reaction.stoich (
int
) – The new stoichiometry value.
- Raises
NodeIndexError – If the given node index does not match any existing node.
ValueError – If the given node index exists but is not a reactant of the reaction.
-
rkviewer.plugin.api.
set_reaction_center_handle
(net_index, reaction_index, handle_pos)[source] Set the position of the Bezier handle at the center of the given reaction.
- Parameters
net_index (
int
) – The network index.reaction_index (
int
) – The index of the reaction whose center Bezier handle to move.handle_pos (
Vec2
) – The new position of the Bezier handle.
- Raises
-
rkviewer.plugin.api.
set_reaction_node_handle
(net_index, reaction_index, node_index, is_source, handle_pos)[source] Set the position of the reaction Bezier handle associated with a node.
- Parameters
net_index (
int
) – The network index.reaction_index (
int
) – The reaction index.node_index (
int
) – The index of the node whose Bezier handle to move.is_source (
bool
) – Whether the node is a source node. If a node is both a source and a target node, it would have two Bezier handles, hence the distinction.handle_pos (
Vec2
) – The new position of the Bezier handle.
- Raises
NodeIndexError – If the given node index is not found
ValueError – If the given node is found but it is not an indicated node of the reaction.
-
rkviewer.plugin.api.
set_zoom_level
(level, anchor)[source] Set the zoom level of the _canvas.
See zoom_level() for more details.
- Parameters
level (
int
) – The zoom level to set.anchor (
Vec2
) – A point on the window whose position will remain the same after zooming. E.g. when the user zooms by scrolling the mouse, the anchor is the center of the window.
-
rkviewer.plugin.api.
translate_network
(net_index, offset, check_bounds=True)[source] Translate the given network by a fixed amount.
- Parameters
net_index (
int
) – The network index.offset (
Vec2
) – The offset to shift the network.check_bounds (
bool
) – If True, check to ensure that everything will be within bounds after the shift. Defaults to True, and this is recommended unless you have already performed that check yourself.
- Return type
bool
-
rkviewer.plugin.api.
uninit_api
()[source] Uninitialize the API; for internal use only.
-
rkviewer.plugin.api.
update_canvas
()[source] Update the canvas immediately. Useful if you want to redraw before a group action ends.
-
rkviewer.plugin.api.
update_compartment
(net_index, comp_index, id=None, fill_color=None, border_color=None, border_width=None, volume=None, position=None, size=None)[source] Update one or multiple properties of a compartment.
- Parameters
net_index (
int
) – The network index.comp_index (
int
) – The compartment index of the compartment to modify.id (
Optional
[str
]) – If specified, the new ID of the node.fill_color (
Optional
[Color
]) – If specified, the new fill color of the compartment.border_color (
Optional
[Color
]) – If specified, the new border color of the compartment.border_width (
Optional
[float
]) – If specified, the new border width of the compartment.volume (
Optional
[float
]) – If specified, the new volume of the compartment.position (
Optional
[Vec2
]) – If specified, the new position of the compartment.size (
Optional
[Vec2
]) – If specified, the new size of the compartment.
- Raises
ValueError – If ID is empty or if any one of border_width, position, and size is out of range.
Note
This is not an atomic function, meaning if we failed to set one specific property, the previous changes to model in this function will not be undone, even after the exception is caught. To go around that, make one calls to update_node() for each property instead.
-
rkviewer.plugin.api.
update_node
(net_index, node_index, id=None, fill_color=None, border_color=None, border_width=None, position=None, size=None, floating_node=True, lock_node=False, shape_index=None, concentration=None, node_name=None, node_SBO=None)[source] Update one or multiple properties of a node.
- Parameters
net_index (
int
) – The network index.node_index (
int
) – The node index of the node to modify.id (
Optional
[str
]) – If specified, the new ID of the node.fill_color (
Optional
[Color
]) – If specified, the new fill color of the node.border_color (
Optional
[Color
]) – If specified, the new border color of the node.border_width (
Optional
[float
]) – If specified, the new border width of the node.position (
Optional
[Vec2
]) – If specified, the new position of the node.size (
Optional
[Vec2
]) – If specified, the new size of the node.floating_node (
bool
) – If specified, the floating status of the node.lock_node (
bool
) – If specified, whether the node is locked.shape_index (
Optional
[int
]) – If specified, the new shape of the node.concentration (
Optional
[float
]) – If specified, the new concentration of the node.node_name (
Optional
[str
]) – If specified, the new node name.node_SBO (
Optional
[str
]) – If specified, the new node SBO.
Note
This is not an atomic function, meaning if we failed to set one specific property, the previous changes to model in this function will not be undone, even after the exception is caught. To go around that, make one calls to update_node() for each property instead.
Also note the behavior if the given node_index refers to an alias node. The properties ‘position’, ‘size’, and ‘lock_node’ pertain to the alias node itself. But all other properties pertain to the original node that the alias refers to. For example, if one sets the ‘position’ of an alias node, the position of the alias is updated. But if one sets the ‘id’ of an alias node, the ID of the original node is modified (and that of the alias node is updated to reflect that).
- Raises
ValueError – If ID is empty or if any one of border_width, position, and size is out of range.
-
rkviewer.plugin.api.
update_reaction
(net_index, reaction_index, id=None, fill_color=None, thickness=None, ratelaw=None, handle_positions=None, center_pos=<rkviewer.plugin.api.CustomNone object>, use_bezier=None, modifiers=None, modifier_tip_style=<ModifierTipStyle.CIRCLE: 'circle'>)[source] Update one or multiple properties of a reaction.
- Parameters
net_index (
int
) – The network index.reaction_index (
int
) – The reaction index of the reaction to modify.id (
Optional
[str
]) – If specified, the new ID of the reaction.fill_color (
Optional
[Color
]) – If specified, the new fill color of the reaction.thickness (
Optional
[float
]) – If specified, the thickness of the reaction.ratelaw (
Optional
[str
]) – If specified, the rate law of the reaction.handle_positions (
Optional
[List
[Vec2
]]) – If specified, the list of handles of the reaction. See add_reaction() for details on the format.center_pos (
Union
[Vec2
,None
,CustomNone
]) – The position of the reaction center. If None, the center position will be automatically set as the centroid of all the species and will dynamically move as nodes are moved.use_bezier (
Optional
[bool
]) – If specified, whether to use Bezier curves when drawing the reaction. If False, simply use straight lines.modifiers (
Optional
[Set
[int
]]) – If specified, the set of reaction modifiersThe modifier tip style. (modifier_tip_style) –
Note
This is not an atomic function, meaning if we failed to set one specific property, the previous changes to model in this function will not be undone, even after the exception is caught. To go around that, make one calls to update_node() for each property instead.
- Raises
ValueError – If ID is empty or if thickness is less than zero.
- Parameters
modifier_tip_style (
ModifierTipStyle
) –
-
rkviewer.plugin.api.
window_position
()[source] Return the position of the topleft corner on the _canvas.
- Return type
-
rkviewer.plugin.api.
window_size
()[source] Return the size of the window (visible part of the _canvas).
- Return type
-
rkviewer.plugin.api.
zoom_level
()[source] The zoom level of the _canvas (Ranges from -10 to 10, with 0 being the default zoom).
This is a discrete value that corresponds to the zoom slider to the bottom-right of the _canvas window.
- Return type
int
-
class
rkviewer.plugin.api.
Vec2
(x=None, y=None)[source] Class that represents a 2D vector. Supports common vector operations like add and sub.
Note
Vec2 objects are immutable, meaning one cannot modify elements of the vector.
-
elem_abs
()[source] Return the Vec2 obtained by taking the element-wise absolute value of this Vec2.
- Return type
-
elem_div
(other)[source] Return the resulting Vec2 by performing element-wise division.
Examples
>>> c = a.elem_div(b) # is equivalent to... >>> c = Vec2(a.x / b.x, a.y / b.y)
-
elem_mul
(other)[source] Return the resulting Vec2 by performing element-wise multiplication.
Examples
>>> c = a.elem_mul(b) # is equivalent to... >>> c = Vec2(a.x * b.x, a.y * b.y)
-
map
(op)[source] Map the given operation across the two elements of the vector.
- Parameters
op (
Callable
[[Union
[float
,int
]],Any
]) –- Return type
-
classmethod
repeat
(val=1)[source] Return the Vec2 obtained by repeating the given scalar value across the two elements.
Examples
>>> print(Vec2.repeat(5.4)) (5.4, 5.4)
- Parameters
val (
Union
[float
,int
]) –- Return type
-
swapped
(i, val)[source] Return a Vec2 equal to this one but with the ith element swapped for val.
- Parameters
i (
int
) –val (
Union
[float
,int
]) –
-
to_wx_point
()[source] Convert this to wx.Point; return the result.
- Return type
Point
-
-
class
rkviewer.plugin.api.
Rect
(pos, size)[source] Class that represents a rectangle by keeping a position and a size.
-
aligned
()[source] Return rectangle aligned to the pixel coordinate system.
Note
See https://github.com/evilnose/PyRKViewer/issues/12 for why this is necessary.
- Return type
-
contains
(other)[source] Returns whether self contains the other rectangle entirely.
- Parameters
other (
Rect
) –- Return type
bool
-
nth_vertex
(n)[source] Return the nth vertex of the rectangle.
The top-left vertex is the 0th vertex, and subsequence vertices are indexed in clockwise fashion.
- Parameters
n (
int
) –
-