cell_class module

Implementation of a class to represent the cell cortex.

class cell_class.Cell(initial_guesses, identifier='A', verbose=True, param_dict=None, **cell_kwargs)[source]

Bases: object

Class that represents the apical cell cortex and holds all variables and functions to manipulate it.

The class stores cortex variables x, y, theta, theta’ (called c), theta’’ (called d) and alpha (called gamma, here).

Note

Due to old naming conventions, some variables are different to the published names: (name here = published name), kappa = kappa^2, gamma = alpha, prestrain = prestretch, s = S_0.

activate_fast_adhesions(on_off)[source]

(De)activates the forces coming from fast adhesions

Parameters

on_off (bool) – Set whether fast adhesions exert forces on the cortex.

adaptive_mesh_update(coarsen=True, refine=True, nodes_to_keep={})[source]

refine and coarsen mesh based on curvature

Parameters
  • coarsen (bool) – (Default value = True) Whether to apply coarsening by removing nodes.

  • refine (bool) – (Default value = True) Whether to apply refinement by adding nodes.

  • nodes_to_keep (set) – (Default value = set()) A list of nodes that cannot be removed.

build_adhesion_tree(build_polygon=False)[source]

Builds a kdtree of the possible adhesion locations from self.adhesion_point_coords

Parameters

build_polygon (bool) – (Default value = False) Set whether the adhesion polygon will be built. (It’s not used much anymore)

bvp_bcs(ya, yb)[source]

Check how close we are to periodic BCS for cortex variables. Used for solving BVP

Parameters
  • ya (list) – The current value of the cortex variables at the first index: [theta[0], gamma[0], x[0], y[0], C[0], D[0]]

  • yb (list) – The current value of the cortex variables at the first index: [theta[-1], gamma[-1], x[-1], y[-1], C[-1], D[-1]]

Returns

A list of the differences between the enp-point variables (theta is mod 2pi).

Return type

np.array

check_if_cell_intersects_adhesion_boundary(x=None, y=None)[source]

Check if any cortex node intersects the adhesion boundary

Parameters
  • x (list) – (Default value = None) x coords for cell cortex points. Can default to use stored values.

  • y (list) – (Default value = None) y coords for cell cortex points. Can default to use stored values.

Returns

If the boundary intersects.

Return type

bool

clear_adhesion_points()[source]

Remove all stored possible adhesion points.

coarsen_mesh(method='spacing', nodes_to_keep={})[source]

Removes nodes in the mesh that are no longer needed.

Parameters
  • method (string) – (Default value = ‘spacing’) Method to determine which nodes are removed. spacing or curvature

  • nodes_to_keep (set) – (Default value = set()) A set of nodes that can’t be removed.

create_apposed_cortex()[source]

Creates an additional cell cortex within this class.

decimate_all_variables_onto_new_grid(factor, use_scipy=False, new_s=None)[source]

Change the grid and interpolate all variables onto it

Parameters
  • factor – Scaling factor for removing nodes.

  • factor – int

  • use_scipy – (Default value = False) Whether to use Scipy’s version of the function.

  • use_scipy – bool

  • new_s – (Default value = None) The new undeformed mesh, S_0., which the decimated grid can be interpolated onto.

  • new_s – list

double_mesh()[source]

put new mesh points at mean locations of current

funcForScipyBVPSolver(s, U)[source]

Function to pass to Scipy’s BVP solver; returns the cortex equilibrium equations from the force balance. U = [theta, gamma, x, y, D, C]

Parameters
  • s (np.array) – S_0 cortex coordintes (the undeformed mesh).

  • U – A list of the cortex variables [theta, gamma, x, y, C, D] (passed as arrays; unintuitive ordering)

Returns

The first derivative of the cortex variables, which will be solved by Scipy.

Return type

list

get_adhesion_nodes_connected_to_xy(nodes, sort_by_distance=True)[source]

Calculate the adhesions that will be connected to given a list of (x,y) coordinates.

Parameters
  • nodes (list) – The list of coordinates that will look for adhesion connections.

  • sort_by_distance (bool) – (Default value = True) Sort the return list by distance.

Returns

The distances that the nodes have to the adhesion boundary, and the indices matching the output distances to the input nodes.

Return type

(list, list)

get_area(x=None, y=None)[source]

Calculate the signed area of the cell

Parameters
  • x (np.array) – (Default value = None) x-coordinates to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordinates to use. Defaults to stored cortex y variable.

Returns

The area enclosed by the cortex.

Return type

float

get_centroid(x=None, y=None)[source]

Get the perimeter-based centroid. This is important if the spacing becomes non-uniform then the mean of node positions becomes biased to where nodes are most dense.

Parameters
  • x (np.array) – (Default value = None) x-coordinates to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordinates to use. Defaults to stored cortex y variable.

Returns

The (x,y) coords of the centroid.

Return type

tuple

get_cortex_forces()[source]

Get the total forces exerted by the cortex (against adhesion), summed of normal and tang dirs.

Returns

Total force acting across cortex.

Return type

np.array

get_effective_pressure()[source]

Isotropic part of cell-level stress

Returns

Trace of the stress tensor

Return type

float

get_fast_adhesion_forces_across_cortex(x=None, y=None, sort_by_distance=True)[source]

Query the adhesion tree to get indices of neighouring cortices within the max adhesion length. Then calculate the distance to each point and calculate the force.

Parameters
  • x (np.array) – (Default value = None) x-coordintes to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordintes to use. Defaults to stored cortex y variable.

  • sort_by_distance (bool) – (Default value = True) Organise the adhesions by distance.

Returns

A list of the adhesion forces acting across the cortex.

Return type

np.array

get_first_derivative_of_cortex_variables(x=None, y=None, theta=None, gamma=None, C=None, D=None, s=None)[source]

Get the first derivative of all cortex variables. (Note, return order differs to input order odo)

Parameters
  • x (np.array) – (Default value = None) x-coordinates to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordinates to use. Defaults to stored cortex y variable.

  • theta (np.array) – (Default value = None) cortex angles to use. Defaults to stored cortex theta variable.

  • gamma (np.array) – (Default value = None) cortex stretches to use. Defaults to stored cortex gamma variable.

  • C (np.array) – (Default value = None) theta’ to use. Defaults to stored cortex C variable.

  • D (np.array) – (Default value = None) theta’’ to use. Defaults to stored cortex D variable.

  • s (np.array) – (Default value = None) S_0-coordintes to use. Defaults to stored cortex S_0 variable.

Returns

A list of arrays, where each array is the first deriv of a cortex variable.

Return type

list

get_intersection_indices(points)[source]

Get at list of the idxs, from given points, that intersect adhesion boundaries. DEPRECIATED

Parameters

points (list) – The coords of points to check

Return indices

The indices of the points that intersected the boundary.

get_length()[source]

Get total length cortex

Returns

The integrated deformed mesh spacing.

Return type

float

get_length_of_adhesions(rerun_distance_calculation=True)[source]

Get the lengths of all connected adhesions.

Parameters
  • rerun_distance_calculation – (Default value = True) Whether to re-check the lengths of adhesions.

  • rerun_distance_calculation – bool

Returns

The lengths of the adhesions

Return type

np.array

get_length_of_cortex_with_active_contractility()[source]

Get the total length of the cortex that has active contractility

Returns

The summed cortex segments that have active contractility.

Return type

float

get_length_of_longest_adhesion(rerun_distance_calculation=True)[source]

Length of the longest connected adhesion.

Parameters
  • rerun_distance_calculation – (Default value = True) Whether to update the adhesions.

  • rerun_distance_calculation – bool

Returns

The length of the longest adhesion.

Return type

float

get_length_of_shortest_adhesion(rerun_distance_calculation=True)[source]
Parameters
  • rerun_distance_calculation – (Default value = True) Whether to update the adhesions.

  • rerun_distance_calculation – bool

Returns

The length of the shortest adhesion.

Return type

float

get_mesh_spacing()[source]

Get the spacing between nodes in the undeformed configuration

Returns

The current undeformed mesh spacing

Return type

np.array

get_neighbours()[source]

Get the identities of neighbouring cells

get_normal_and_tangential_components_of_cortex_forces()[source]

Get normal and tangential components of force gradient exerted by cortex. This is sum of adhesion and pressure in equilibrium

Returns

Cortex forces in the normal and tangential directions

Return type

(np.array, np.array)

get_prestrains(shape=None)[source]

Returns an array of the calculated prestrethc (called prestrain) at every mesh point, using the fast adhesion methods

Parameters

shape (int) – (Default value = None) The desired return shape (used when solving bvp with collocation nodes).

Returns

The prestretch across the cortex.

Return type

np.array

get_protrusion_force(x, y)[source]
Make a protrusion pointing to another cell and get a list of the forces acting across the cortex due to it

(this will mostly be a sparse list of [0,0] except where the protrusion is) odo this is old might not work anymore

Parameters
  • x (np.array) – (Default value = None) x-coordintes to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordintes to use. Defaults to stored cortex y variable.

Returns

A list of the forces acting across the cortex due to protrusions.

Return type

np.array

get_sdk_forces_across_cortex(x, y, s)[source]

Get a vector len(self.s) of the total force on each cortex node due to sdk

Parameters
  • x (np.array) – (Default value = None) x-coordintes to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordintes to use. Defaults to stored cortex y variable.

  • s (np.array) – (Default value = None) S_0-coordintes to use. Defaults to stored cortex S_0 variable.

Returns

A list of the sidekick adhesion forces acting across the cortex.

Return type

np.array

get_shape_tensor()[source]

Get cell shape tensor

Returns

2x2 shape tensor.

Return type

np.array

get_slow_adhesion_forces_across_cortex(x=None, y=None)[source]

Calculate a vector len(self.s) giving the total force at every cortexz node coming from the population of slow adhesions.

Parameters
  • x (np.array) – (Default value = None) x-coordintes to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordintes to use. Defaults to stored cortex y variable.

Returns

A list of the slow adhesion forces acting across the cortex.

Return type

np.array

get_stress_tensor()[source]

Calculate cell stress tensor

Returns

The 2x2 stress tensor

Return type

np.array

get_total_adhesion_force_across_cortex(x=None, y=None, s=None)[source]

Get the total adhesion force, with fast, sdk and slow adhesions

Parameters
  • x (np.array) – (Default value = None) x-coordintes to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordintes to use. Defaults to stored cortex y variable.

  • s (np.array) – (Default value = None) S_0-coordintes to use. Defaults to stored cortex S_0 variable.

Returns

A list of the sidekick adhesion forces acting across the cortex.

Return type

np.array

get_total_adhesion_force_from_adhesion_indices(coord, adhesion_index, is_intersection=False)[source]

For fast adhesions. Given (x,y) coord on this cortex and index (adhesion_idx) in adhesion list that it is connected to, calculate vector force. Note self.adhesion_connections[adhesion_index] can be a list of multiple connections.

Parameters
  • coord – The (x,y) coord to get the adhesion force for.

  • is_intersection (bool) – (Default value = False). Unused now. If it is intersecting the adhesion boundary, the force is reversed.

Returns

The distances that the nodes have to the adhesion boundary, and the indices matching the output distances to the input nodes.

Return type

(list, list)

get_xy_segment_lengths(x=None, y=None)[source]
Parameters
  • x (np.array) – (Default value = None) x-coordinates to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordinates to use. Defaults to stored cortex y variable.

interpolate_variable_onto_new_grid(variable, current_grid, new_grid)[source]

Interpolates a given cortex variable from old_grid to new_grid

Parameters
  • variable (list) – The cortex variable (or any array) to be interpolated onto a new grid..

  • current_grid (list) – The current undeformed mesh spacing, S_0.

  • new_grid (list) – The new mesh grid that the variable will be interpolated to.

static make_heatmap_from_array(input_array, cmap='coolwarm')[source]

Given an array of values, generate a heatmap

Parameters
  • input_array (list) – Input array of values to base the cmap on.

  • cmap (sring) – (Default value = ‘coolwarm’) Name of a Matplotlib cmap.

Returns

An rgba colourmap.

Return type

mpl cmap

move_cortex_nodes_to_equilibrium_dist(scaling=1, neighbours_moving=True)[source]

Enforces that the cortex is no closer than delta to any neighbouring cortex

Parameters
  • scaling (float) – (Default value = 1) Additional scaling relative to delta that the cortex nodes will sit from neighbours.

  • neighbours_moving (bool) – (Default value = True) An additional check if the neighbouring cortices will move.

Returns

Wether we were successful.

Return type

bool

pickle_self(SAVE_DIR=None, name=None)[source]

Pickles instance of this class

Parameters
  • SAVE_DIR (string) – (Default value = None) Location to save.

  • name (string) – (Default value = None) Name of the pickled file.

plot_adhesion_points(ax=None, plot_forces=True, plot_adhesion_at_specific_locations=False)[source]

Plot the adhesions on the cortex

Parameters
  • ax – (Default value = None)

  • plot_forces – (Default value = True)

  • plot_adhesion_at_specific_locations – (Default value = False)

plot_cortex(ax=None, x=None, y=None, plot_tension=False, cortex_width=2, col='k', max_strain=0.002)[source]

Plot the cortex (outline) of the cell.

Parameters
  • ax – (Default value = None)

  • x – (Default value = None)

  • y – (Default value = None)

  • plot_tension – (Default value = False)

  • cortex_width – (Default value = 2)

  • col – (Default value = ‘k’)

  • max_strain – (Default value = .002)

plot_cortex_variables(ax=None, linestyle='-', plot_legend=True, plot_strain=False)[source]

Function to plot the data on 3 plot_3panels

Parameters
  • ax – (Default value = None)

  • linestyle – (Default value = ‘-‘)

  • plot_legend – (Default value = True)

  • plot_strain – (Default value = False)

plot_medial_pressure(ax=None)[source]

Plot the adhesions on the cortex

Parameters

ax – (Default value = None)

plot_principal_axes_of_shape(ax=None)[source]

Plot pricipal axes of shape

Parameters

ax – (Default value = None)

plot_protrusion_force(ax=None, colour='C0')[source]

Plot the protrusion on the cortex

Parameters
  • ax – (Default value = None)

  • colour – (Default value = ‘C0’)

plot_stress(plot_stress_axis=False, ax=None, sim_type='single')[source]

Plot the adhesions on the cortex

Parameters
  • plot_stress_axis – (Default value = False)

  • ax – (Default value = None)

  • sim_type – (Default value = ‘single’)

plot_xy_on_trijunction(ax=None, col='k', equalAx=True, plotAdhesion=True, cortexwidth=2, plot_adhesion_forces=True, plot_adhesion_at_specific_locations=False, lagrangian_tracking=False, plot_pressure=False, plot_tension=False, label=None, plot_stress=False, plot_stress_axis=False, sim_type='single', plot_shape=False, label_size=26)[source]

Plot the ys x for the junction and reflect/rotate if necessary.

Parameters
  • ax – (Default value = None)

  • col – (Default value = ‘k’)

  • equalAx – (Default value = True)

  • plotAdhesion – (Default value = True)

  • cortexwidth – (Default value = 2)

  • plot_adhesion_forces – (Default value = True)

  • plot_adhesion_at_specific_locations – (Default value = False)

  • lagrangian_tracking – (Default value = False)

  • plot_pressure – (Default value = False)

  • plot_tension – (Default value = False)

  • label – (Default value = None)

  • plot_stress – (Default value = False)

  • plot_stress_axis – (Default value = False)

  • sim_type – (Default value = ‘single’)

  • plot_shape – (Default value = False)

  • label_size – (Default value = 26)

prune_adhesion_data()[source]

Remove all locally stored adhesion data. This data is usually permanently held by the Epithelium class.

refine_mesh(method='spacing')[source]

Refine the mesh by adding nodes in regions of high curvature or low spacing

Parameters

method (string) – (Default value = ‘spacing’) Method to use. Add mesh nodes based on their spacing or curvature.

scale_whole_cell_to_fit_adhesion_to_delta(stretch_factor=1.01, delta_tol=1.05, update_adhesion_lengths=True)[source]

Applies a homogenous isotropic stretch/compression to the cell such that the shortest adhesion is delta

Parameters
  • stretch_factor (float) – (Default value = 1.01) How much to scale the cortex x -> x * stretch_factor

  • delta_tol (float) – (Default value = 1.05) Tolerance range for delta.

  • update_adhesion_lengths (bool) – (Default value = True) Whether to perfrom an initial adhesion update.

smooth_variables(fac=40, poly_order=1)[source]

Apply a savgol filter to smooth the cortex variables

Parameters
  • fac (int) – (Default value = 40) Factor to determine window size, = num_nodes / fac, for smoothing.

  • poly_order (int) – (Default value = 1) Order of polynomial used for smoothing.

solve_bvp()[source]

Solve BVP for cortex variables using Scipy’s BVP solver

Returns

A tuple, whether solving was a success; a list, the new cortex variables: [s, theta, gamma, x, y, C, D]

Return type

(bool, list)

static truncate_colormap(cmap, minval=0.0, maxval=1.0, n=1000)[source]

Truncate a colourmap between 2 values

Parameters
  • cmap – A matplotlib colourmap.

  • cmap – mpl cmap

  • minval – (Default value = 0.0) New max value for the colourmap.

  • minval – (Default value = 0.0) float

  • maxval – (Default value = 1.0) New min value for colourmap.

  • maxval – (Default value = 1.0) float

  • n – (Default value = 1000) Number of values in cmap.

  • n – (Default value = 1000) int

Returns

The truncaetd cmap

Return type

mpl cmap

update_adhesion_distances_identifiers_and_indices(x=None, y=None, sort_by_distance=True, build_tree=False)[source]

Query the adhesion tree to build adhesion connections, storing the distance, id and index of the connection. The data is stored internally, with no output here.

Parameters
  • x (np.array) – (Default value = None) x-coordintes to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordintes to use. Defaults to stored cortex x variable.

  • sort_by_distance (bool) – (Default value = True) Whether to rganise the adhesion connections by distance.

  • build_tree (bool) – (Default value = False) Whether to fresh-build the adhesion tree.

update_adhesion_points(points, ids, spacing)[source]

Store points that fast adhesions can adhere to.

Parameters
  • points (list) – A list of (x,y) coordinates, which the cell cortex xan adhere to.

  • ids (list) – A list of the cell identifiers that those adhesion points came from.

  • spacing (list) – A list of the discretised spacing (on the other cortices) for those adhesion points.

update_deformed_mesh_spacing(x=None, y=None)[source]

Get the spacing between mesh nodes in the deformed configuration

Parameters
  • x (np.array) – (Default value = None) x-coordinates to use. Defaults to stored cortex x variable.

  • y (np.array) – (Default value = None) y-coordinates to use. Defaults to stored cortex y variable.

update_prestrains()[source]

Update the values of prestretches (called prestrain here based on the identity of (fast) adhesion connections

update_reference_configuration_to_current()[source]

Update the Lagrangian coordinate S_0 to the current configuration from the stretches and prestretches: S_0 <- s = S_0 * stretch * prestretch

upsample_all_variables_onto_new_grid(new_n)[source]

Change the grid and interpolate all variables onto it

Parameters

new_n (int) – The new number of discretised nodes for the cortex variabels.

verboseprint(*args)[source]

Function to print out details as code runs

Parameters

args – Information to be printed to console.