Convert SurfaceEvolver mesh to force network¶
The .txt files generated using the previous notebook can be run through Surface Evolver. Here, we will use the .txt file outputs of Surface Evolver as an input for DLITE
First, let’s import some general classes
[1]:
import pandas as pd
import seaborn as sns
import numpy as np
import pickle
import os
import sys
import pylab
import matplotlib.pyplot as plt
Now, we import DLITE classes
[2]:
from DLITE.cell_describe import node, edge, cell, colony
from DLITE.ManualTracingMultiple import ManualTracingMultiple
from DLITE.SurfaceEvolver import SurfaceEvolver
from DLITE.PlottingFunctions import PlottingFunctions
The main class we will be using here is the SurfaceEvolver class.
SurfaceEvolver can read txt files of the form (name_first + number + name_end), where the number refers to the timepoint.
For example, name_first = ‘voronoi_very_small_44_edges_tension_edges_20_30_’, number = 0.9, name_end = ‘.fe.txt’ is a txt file with the name ‘voronoi_very_small_44_edges_tension_edges_20_30_0.9.fe.txt’.
Here, we have 7 timepoints.
[3]:
os.chdir(r'../Notebooks/data/Synthetic_data/Fig_5')
timepoints = [int(i)/10 for i in np.linspace(10, 3, 7)]
name_first = 'voronoi_very_small_44_edges_tension_edges_20_30_'
name_end = '.fe.txt'
[4]:
timepoints
[4]:
[1.0, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3]
Let’s instantiate the class
[5]:
SurfaceEvolverInstance = SurfaceEvolver(name_first, name_end)
Now we can compute tensions!
[6]:
colonies = SurfaceEvolverInstance.computation_based_on_prev_surface_evolver(timepoints, colonies = None, index = None,
old_dictionary = None, maxiter = 60*1000, solver = 'DLITE')
Name is voronoi_very_small_44_edges_tension_edges_20_30_1.0.fe.txt
Number of fit edges: 25
Number of cells 2 2
guess tension is [0.05, 0.4, 0.32, 0.56, 0.62, 0.27, 0.64, 0.63, 0.02, 0.67, 0.22, 0.86, 0.57, 0.76, 0.13, 0.69, 0.58, 0.59, 0.18, 0.15, 0.51, 0.69, 0.14, 0.85, 0.55]
Function value 0.010564751266176809
Solution [0.5906006 0.59448586 0.58950839 0.5910959 0.58886322 0.59049502
0.59077354 0.59265611 0.58294638 0.58747962 0.58740277 0.57787733
0.59664487 0.58997209 0.58971762 0.60107719 0.59142384 0.58738081
0.58263115 0.57916037 0.58373003 0.58518747 0.5963707 0.58050469
0.593009 ]
-----------------------------
guess pressure is [0.0013469521308886317, 0.0013469521308886317]
Function value 3.612207055816619e-23
Solution [0.00080376 0.00189014]
-----------------------------
Solver is DLITE
First colony {'0': <DLITE.cell_describe.colony object at 0x12158bfd0>}
Number now is 0.8
Number of fit edges: 25
Number of cells 2 2
guess tension is [0.5906005951578338, 0.5944858590115113, 0.5895083877052775, 0.5910958952848561, 0.5888632247837902, 0.5904950208325342, 0.5907735390118571, 0.5926561076511513, 0.5829463841839659, 0.5874796189140419, 0.5874027659525328, 0.5778773277004409, 0.5966448717780733, 0.5899720902732151, 0.5897176229728793, 0.6010771902739411, 0.5914238390507752, 0.5873808101496643, 0.5826311474463217, 0.5791603690849926, 0.583730026707228, 0.5851874711677938, 0.5963706957590085, 0.5805046937318045, 0.5930089992112969]
Function value 0.016589203674446378
Solution [0.64440368 0.64839285 0.64323368 0.64769014 0.64301419 0.64496486
0.6453491 0.523239 0.50252109 0.51291553 0.51237001 0.49718004
0.52026067 0.51151533 0.51131935 0.52692716 0.64146231 0.63875997
0.63455675 0.63093299 0.63630337 0.63622616 0.64818426 0.63319609
0.64568251]
-----------------------------
guess pressure is [0.0018901409750441633, 0.0018901409750441633]
Function value 1.1119354089624381e-20
Solution [-0.00268732 0.0064676 ]
-----------------------------
Next colony number 1
Number now is 0.7
Number of fit edges: 25
Number of cells 2 2
guess tension is [0.6444036802330669, 0.6483928530110233, 0.643233675491657, 0.6476901374517382, 0.643014193889299, 0.6449648579432758, 0.6453490999936778, 0.5232390034656325, 0.5025210900756865, 0.5129155304201621, 0.5123700083426492, 0.49718003549076417, 0.520260666675704, 0.5115153292640442, 0.511319354056589, 0.5269271562818959, 0.6414623129237784, 0.6387599688062275, 0.6345567451368602, 0.6309329921340514, 0.6363033712241879, 0.6362261639941057, 0.6481842597839841, 0.6331960915977957, 0.6456825069217287]
Function value 0.034501898250229604
Solution [0.67040953 0.67445663 0.66920415 0.67680521 0.66867024 0.67118521
0.67351363 0.48423328 0.45421618 0.46932497 0.46994378 0.45042802
0.4791102 0.46876338 0.46289535 0.48316141 0.67201292 0.66698251
0.66053785 0.65680531 0.66264926 0.66170456 0.67391708 0.65979708
0.67182732]
-----------------------------
guess pressure is [0.006467600216051871, 0.006467600216051871]
Function value 4.2083513718287017e-20
Solution [-0.00055244 0.01348764]
-----------------------------
Next colony number 2
Number now is 0.6
Number of fit edges: 25
Number of cells 2 2
guess tension is [0.670409528125721, 0.674456632582163, 0.6692041461611553, 0.6768052100111528, 0.6686702372510009, 0.6711852128046705, 0.6735136300061285, 0.48423328354222744, 0.4542161795711275, 0.46932497453742783, 0.4699437766191812, 0.45042801624458445, 0.4791102032632195, 0.46876337707969834, 0.46289535181458075, 0.4831614077115946, 0.6720129207627475, 0.6669825147371686, 0.6605378479964233, 0.6568053071947183, 0.6626492605374144, 0.6617045592490817, 0.6739170847835255, 0.6597970831814902, 0.6718273178161015]
/Users/ritvikvasan/Documents/repos/DLITE/DLITE/cell_describe.py:1321: RuntimeWarning: invalid value encountered in double_scalars
objective = objective + resid_mag + coeff * resid_mag/np.sum(tension_vec_mags)
Function value nan
Solution [0.69540747 0.69938424 0.69394773 0.70371372 0.6930407 0.69591471
0.70173339 0.44312165 0.39976676 0.42024854 0.41820683 0.39867514
0.43912928 0.42380423 0.40866694 0.43839442 0.70602351 0.68808368
0.68563306 0.68208895 0.68476566 0.68332437 0.69875497 0.67924683
0.69369673]
-----------------------------
guess pressure is [0.01348763982042462, 0.01348763982042462]
Function value 7.188086959911588e-20
Solution [0.00383134 0.02314393]
-----------------------------
Next colony number 3
Number now is 0.5
Number of fit edges: 25
Number of cells 2 2
guess tension is [0.6954074653879426, 0.6993842442265817, 0.6939477315829097, 0.7037137153494123, 0.6930407040664117, 0.695914708922071, 0.7017333872035864, 0.4431216478093743, 0.3997667595452548, 0.4202485446167898, 0.41820682833702066, 0.39867514159900735, 0.4391292759272465, 0.4238042292481564, 0.4086669366526904, 0.4383944228942818, 0.7060235131793807, 0.6880836810126325, 0.6856330630118087, 0.6820889460328711, 0.6847656591017327, 0.6833243678770988, 0.6987549693672399, 0.6792468336518135, 0.6936967304993374]
Function value 0.13937838844912748
Solution [0.72059436 0.72643562 0.71712663 0.72967892 0.71443587 0.71842569
0.72483076 0.41040312 0.35000129 0.36549345 0.39762115 0.35059039
0.4054764 0.39364359 0.3684011 0.39471788 0.74525394 0.68946962
0.6995497 0.69828302 0.69958358 0.69638847 0.71329592 0.68932177
0.7026 ]
-----------------------------
guess pressure is [0.023143931209064716, 0.023143931209064716]
Function value 4.1718889722980056e-20
Solution [0.01109371 0.03519415]
-----------------------------
Next colony number 4
Number now is 0.4
Number of fit edges: 25
Number of cells 2 2
guess tension is [0.7205943637038693, 0.726435616879815, 0.7171266274212498, 0.7296789196796885, 0.7144358703183495, 0.7184256935480202, 0.7248307568744365, 0.41040312380519556, 0.3500012896981675, 0.3654934547496788, 0.39762115187037006, 0.35059038919233093, 0.40547640331301354, 0.39364359149317113, 0.3684011031383019, 0.3947178807264756, 0.7452539416844675, 0.6894696249571152, 0.6995497036192633, 0.698283018452051, 0.6995835822328081, 0.6963884692705451, 0.7132959209495026, 0.6893217719555971, 0.7026000014199447]
Function value nan
Solution [0.77707661 0.78714947 0.76162265 0.77064505 0.75356515 0.75987678
0.76723721 0.33407666 0.25999474 0.31818442 0.42765743 0.27048027
0.35536155 0.37821992 0.3684145 0.32980792 0.72248674 0.72144288
0.67911468 0.68243767 0.67890259 0.67384479 0.69300489 0.68300369
0.67494589]
-----------------------------
guess pressure is [0.03519414715251604, 0.03519414715251604]
Function value 5.682187824675782e-20
Solution [0.01997679 0.0504115 ]
-----------------------------
Next colony number 5
Number now is 0.3
node a = node b, possible topological change
Number of fit edges: 24
Number of cells 1 2
guess tension is [0.7770766143415813, 0.7871494655695296, 0.761622653189994, 0.7706450522658457, 0.7535651510145299, 0.7598767756322923, 0.7672372057081261, 0.3340766578861697, 0.2599947373606797, 0.31818442044290796, 0.4276574313332843, 0.270480270936885, 0.35536154586870433, 0.3782199202788791, 0.3684145017568612, 0.32980792310221774, 0.7224867439836529, 0.6791146835468593, 0.6824376743683044, 0.6789025886493426, 0.6738447927733754, 0.6930048924910167, 0.6830036932551953, 0.6749458929527151]
Function value 0.40998352179252484
Solution [0.79048641 0.79828848 0.77506325 0.78223214 0.76690276 0.77511409
0.78541095 0.26965848 0.19956261 0.25300689 0.46440563 0.21172878
0.37690293 0.33964385 0.3712721 0.30697806 0.71334506 0.67661507
0.68441574 0.67275529 0.66606796 0.69008421 0.67740318 0.66979726]
-----------------------------
guess pressure is [0.05041149648960301, 0.05041149648960301]
Function value 2.982619360672023e-20
Solution [0.03285081 0.06797218]
-----------------------------
Next colony number 6
The output is a dictionary containing colonies at every time point
[7]:
colonies
[7]:
{'0': <DLITE.cell_describe.colony at 0x12158bfd0>,
'1': <DLITE.cell_describe.colony at 0x1235e9fd0>,
'2': <DLITE.cell_describe.colony at 0x123603fd0>,
'3': <DLITE.cell_describe.colony at 0x123639f98>,
'4': <DLITE.cell_describe.colony at 0x123691e48>,
'5': <DLITE.cell_describe.colony at 0x123699438>,
'6': <DLITE.cell_describe.colony at 0x121571198>}
Now, we need to do a little post processing
We want to store all the information contained in every colony. We do this in 3 dataframes
nodes_dataframe has node related information like tension residuals, numbers of connected edges, average curvature of connected edges etc.
edges_dataframe has edge related information like edge tension, stochasticity in tension, edge curvature etc.
cells_dataframe has cell related information like cell pressure, area, perimeter etc.
To do this, let’s import the PlottingFunctions class in DLITE
[8]:
PlottingFunctionsInstance = PlottingFunctions()
[9]:
# We first find labels of edges that are present in all the colonies
common_edge_labels = PlottingFunctionsInstance.get_repeat_edge(colonies)
common_cell_labels = PlottingFunctionsInstance.get_repeat_cell(colonies)
Call these functions to make the dataframes
[10]:
#Make the dataframes
edges_dataframe, cells_dataframe = PlottingFunctionsInstance.seaborn_plot(None, colonies,
common_edge_labels,
common_cell_labels,
ground_truth = True)
nodes_dataframe = PlottingFunctionsInstance.seaborn_nodes_dataframe(colonies, None)
Once we have the dataframes, we can start plotting the results
Since we are doing SurfaceEvolver simulations, we know the ground truth. So we can plot them side by side
[11]:
tension_table = edges_dataframe.pivot_table(
values='Local_normalized_tensions',
index=['Edge_Labels'],
columns='Time')
ground_truth_tension_table = edges_dataframe.pivot_table(
values='Ground_truth',
index=['Edge_Labels'],
columns='Time')
[12]:
sns.set_context('poster')
%matplotlib inline
fig, axn = plt.subplots(1, 2, figsize = (8,10),sharey=True)
cbar_ax = fig.add_axes([1.1, .15, .01, .7], title = 'Tension')
for i, ax in enumerate(axn.flat):
if i == 0:
df = ground_truth_tension_table
title = 'Ground_truth'
elif i == 1:
df = tension_table
title = 'DLITE'
ax.set_title(title)
sns.heatmap(df, ax=ax,
cbar=i == 0, vmin=0, vmax=3, cmap = 'jet',
cbar_ax=None if i else cbar_ax)
We can also plot colony colormaps using something like this
[13]:
# Plot
import pylab
import matplotlib.pyplot as plt
sns.set(style="white")
sns.set_context("paper", font_scale = 2.5)
total = 5
fig, axn = plt.subplots(1, total, figsize = (20,20),sharey=True)
nums= [0,1,2,3,4]
for i, ax in enumerate(axn.flat):
col = colonies[str(nums[i])]
tensions = [e.tension for e in col.tot_edges]
mean_ten = np.mean(tensions)
tensions = [e/mean_ten for e in tensions]
col.plot_tensions(ax, fig, tensions, min_x=450, max_x=550, min_y=430, max_y=550,
min_ten = 0, max_ten = 3, specify_color = 'jet',cbar = 'no', lw = 3)
plt.setp(ax.get_yticklabels(), visible=False)
plt.setp(ax.get_xticklabels(), visible=False)
ax.set(xlim = [450,550], ylim = [430,540], aspect = 1)
Movies are possible too. Just make sure you have ffmpeg installed
[15]:
sns.set(style="darkgrid")
sns.set_context("talk", font_scale=0.75)
fig, ax = plt.subplots(1,1, figsize = (6,4))
PlottingFunctionsInstance.plot_tensions(fig, ax, colonies,min_x=450, max_x=550, min_y=430, max_y=550,
min_ten=0,max_ten=3, specify_aspect=None,specify_color='jet' ,
type=None, lw = 2)