Tools and Examples - Part 1#

Assigning monomials to receptor model states and transitions#

The notebook in receptor_tools.ipynb (see Appendix) contains function definitions that will prove useful as we further explore receptor modeling. The command %run receptor_tools.ipynb loads these function definitions, and the remainder of this notebook illustrates how to use some of them. The focus is on tools that assign monomials to receptor model states and transitions (i.e., graph vertices and edges). Doing this makes the structure of a receptor model easier to understand. It also facilitates symbolic calculations that begin with the state-transition diagram of a receptor model.

%%capture
%run receptor_tools.ipynb

To begin we specify the states and transitions of a receptor model as an undirected graph. For simplicity, we will use a four-state model with one cycle.

pos = {0: (0, 0), 1: (1, 1.41), 2: (2, 0), 3: (4,0)} # vertex positions
G = Graph({0: [1, 2], 1: [2], 2: [3]},pos=pos)

G.show(figsize=4,graph_border=True)
G.show(figsize=4,graph_border=True,edge_labels=True)
_images/79e09dc306e56b2435fd19fd56320e4d13eefcfce06179717e46d93494690bdb.png _images/deed7d385503c95ffcce642602606087b08a91be6e2b4a2ab434d1129e60f43a.png

By default the vertices are integers and the edge labels are None. The method show() has a named parameter edge_lablels that is set to False by default (above left). To see the edge labels we repeat the show() command using edge_labels=True.

add_vertex_monomials#

The next function we will illustrate is add_vertex_monomials.

mydoc(add_vertex_monomials)

add_vertex_monomials(G=Graph on 0 vertices, method='integer', ring=False)

Add monomials to vertices of a graph.

The add_vertex_monomials function takes a graph G, as well as optional parameters method and ring. The function creates a new graph H with vertices labeled by monomials. The monomials are chosen based on the number of vertices in G. If the method parameter is set to ‘alpha’ and the number of vertices in G is less than or equal to 10, the monomials are chosen as alphabetical letters (‘a’ to ‘k’). Otherwise, the monomials are chosen as strings of the form ‘a0’, ‘a1’, …, ‘an-1’, where n is the number of vertices in G. The function then adds the vertices from G to H using the monomials as labels, and adds the edges from G to H using the monomials as endpoints. If the ring parameter is set to True, the function also creates a polynomial ring V with the chosen monomials and ‘invlex’ order, and returns both H and V. Otherwise, it returns only H.

INPUT:

  • G – graph object (default: Graph());

  • method – integer (default: integer);

OUTPUT:

  • The graph with monomials as vertices

H=add_vertex_monomials(G)
H.show(figsize=4)
_images/6b074f6955a49c3c05a2a348f91065d0b5d0e4dc55f4014b039859e4799195cc.png
H2=add_vertex_monomials(G,method='alpha')
H2.show(figsize=4)
_images/34250660665f187cf0663a79c86820ac91fb068714a71ff8ba8ee8f3c0e24c4a.png

add_edge_monomials()#

mydoc(add_edge_monomials)

add_edge_monomials(G0, method='integer', edge_vars=['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], ring=False, short_name=False)

Add monomials to edges of a graph.

The add_edge_monomials function takes a graph G, as well as optional parameters method, edge_vars, ring, and short_name. If method is set to ‘integer’, the function creates a polynomial ring using the given edge variables and assigns variables to the edges of the graph. The edge variables can be represented either as ‘e’ followed by the first vertex label or the first and second vertex labels concatenated. If the vertex labels are integers and the short_name parameter is set to True, the edge variables are created using only the first vertex label. If method is set to ‘alpha’, the function creates a polynomial ring using the given edge variables and assigns variables to the edges of the graph in reverse order. The number of edge variables used is determined by the size of the graph. The ring parameter, if set to True, injects the polynomial variables into the global namespace and returns the graph and the polynomial ring. Otherwise, it simply returns the graph.

INPUT:

  • G – graph object (default: Graph());

  • method – integer (default: integer);

OUTPUT:

  • The graph with monomials as edges

H3=add_edge_monomials(G)
H3.show(figsize=4,edge_labels=True)
_images/1d8982766a2dd1f00372be28df2a193026fc668a3a504865b761bba9cb3508e7.png

The function add_edge_monomials()also works when vertices are variables from a polynomial ring.

H4=add_edge_monomials(H)
H4.show(figsize=4,graph_border=True,edge_labels=True)
_images/7f93e7a75c211adc25cb2add950083b0b4cc16621843bd9b848a51c960aab4db.png

Using method='alpha' in add_edge_monomials() creates simpler edge labels

G = graphs.CycleGraph(4); G.add_edge(0,2)
G = add_edge_monomials(G,method='alpha')
G.show(figsize=4,graph_border=True,edge_labels=True)
_images/5016728f7d525d735884656907c7baf2d4a36d52495d4f7e36ebd17e3c968ded.png

Using ring=True in add_vertex_monomials() constructs a polynomial ring over the variables that label the vertices

(G,V) = add_vertex_monomials(graphs.HouseGraph(),ring=True)
show(V)
\(\displaystyle \newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z}[a_{0}, a_{1}, a_{2}, a_{3}, a_{4}]\)
V.inject_variables()
fv = (a0+a1)*(a0+a3+a4)^2
print(fv)
Defining a0, a1, a2, a3, a4
a1*a4^2 + a0*a4^2 + 2*a1*a3*a4 + 2*a0*a3*a4 + 2*a0*a1*a4 + 2*a0^2*a4 + a1*a3^2 + a0*a3^2 + 2*a0*a1*a3 + 2*a0^2*a3 + a0^2*a1 + a0^3

Using ring=True in add_edge_monomials() constructs a polynomial ring over the variables that label the edges

(G,E) = add_edge_monomials(graphs.HouseGraph(),method='alpha',ring=True)
show(E)
G.show(figsize=4,edge_labels=True)
\(\displaystyle \newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z}[b, c, d, e, f, g]\)
_images/3613964b146d764a1fc502a0c71c55de725d6f408feca33f76a4f81017f996ca.png
E.inject_variables()
fe = (b+c)*(b+e+f)^2
print(fe)
Defining b, c, d, e, f, g
c*f^2 + b*f^2 + 2*c*e*f + 2*b*e*f + 2*b*c*f + 2*b^2*f + c*e^2 + b*e^2 + 2*b*c*e + 2*b^2*e + b^2*c + b^3