Shortest paths PBC calculation: Difference between revisions
(Created page with "= Shortest paths calculation in periodic CGSD simulation = == Introduction == This example shows how to compute the shortest path between a bead in a CGSD simulation and its ...") |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
<P ALIGN="CENTER">NetworCh manuals</P> |
|||
| ⚫ | |||
<P ALIGN="CENTER"><FONT SIZE="+2" color="darkred"><STRONG> |
|||
| ⚫ | |||
<DIV> |
|||
<P ALIGN="CENTER"><STRONG>Nicolas Bertin</STRONG></P> |
|||
</DIV> |
|||
<DIV> |
|||
<P ALIGN="CENTER">October 2016</P> |
|||
</DIV> |
|||
<HR> |
|||
== Introduction == |
== Introduction == |
||
| Line 5: | Line 15: | ||
== Loading and replicating the structure == |
== Loading and replicating the structure == |
||
The chain structure corresponding to a CGSD simulation is outputted in two files: a beads position file (e.g. <tt><simulationName>.cn</tt>) which contains the id and the spatial coordinates of every beads in the simulation, and a bond file (e.g. <tt><simulationName>.bnd</tt>) which contains the connectivity information between the beads. The structure can be loaded in Matlab using function <tt>read_cgsd</tt> by specifying the name of the simulation cn and bnd files (without their extension). For instance, files <tt>0_percent_strain_x500.cn</tt> and <tt>0_percent_strain_x500.bnd</tt> can be loaded with: |
|||
<pre> |
<pre> |
||
| Line 10: | Line 21: | ||
filename = '0_percent_strain_x500'; |
filename = '0_percent_strain_x500'; |
||
[cn,bnds,vol] = read_cgsd(filename); |
[cn,bnds,vol] = read_cgsd(filename); |
||
</pre> |
|||
By default, a cross-link is represented by a cross-link bond of zero length between two beads. To simplify the structure and reduce the computation time, one can merge the cross-linked beads into a single bead by using the <tt>merge_cross_links</tt> function: |
|||
cn(:,end+1) = [1:size(cn,1)]'; |
|||
<pre> |
|||
% Merge cross-linked nodes |
% Merge cross-linked nodes |
||
[cn,bnds] = merge_cross_links(cn,bnds); |
[cn,bnds] = merge_cross_links(cn,bnds); |
||
</pre> |
</pre> |
||
The physical length of each bond can be calculated using function <tt>all_segments_length</tt>: |
|||
<pre> |
<pre> |
||
% Calculate bonds physical lengths |
% Calculate bonds physical lengths |
||
bonds_length = all_segments_length(cn,bnds,vol); |
|||
</pre> |
|||
Since we are interseted in calculated the shortest path from a bead to its periodic image, we need to replicate our structure by periodicity. For instance, if we wish to calculate the shortest path between a bead and its replica along the y-direction, we can use function <tt>replicate_volume</tt> as follows: |
|||
<pre> |
|||
ndir = 2; % replicate in the y-direction |
ndir = 2; % replicate in the y-direction |
||
[cn1,bnds1,vol1] = replicate_volume(cn,bnds,vol,ndir); |
[cn1,bnds1,vol1] = replicate_volume(cn,bnds,vol,ndir); |
||
</pre> |
|||
where beads position array <tt>cn1</tt> will contain both the position of the beads in the primary volume <tt>vol</tt> in <tt>cn1(1:size(cn,1),:)</tt> and their replica in the y-direction in <tt>cn1(size(cn,1)+1:end,:)</tt> such that <tt>size(cn1,1) = 2*size(cn,1)</tt>. |
|||
| ⚫ | |||
| ⚫ | |||
plot_structure(cn1,bnds1,vol1,'r'); |
|||
<pre> |
|||
| ⚫ | |||
% or |
|||
| ⚫ | |||
</pre> |
</pre> |
||
| Line 39: | Line 64: | ||
<pre> |
<pre> |
||
n = size(cn,1); |
n = size(cn,1); |
||
np = ne-ns+1; |
|||
sp = zeros(np,1); |
|||
conn1 = generate_connectivity(size(cn1,1),bnds1); |
|||
A1 = adjacency(cn1,bnds1,bonds_weight); |
|||
[~,comp1] = find_components(conn1); |
|||
A1S = sparse(A1); |
|||
for i=1:np |
|||
if type == 2 |
|||
j = nid(i); |
|||
else |
|||
j = i+ns-1; |
|||
end |
|||
if bio_graph |
|||
[d,~,~] = graphshortestpath(A1S,j,j+n); |
|||
sp(i) = d; |
|||
else |
|||
[d,~] = shortest_path(conn1,A1,j,j+n,comp1); |
|||
sp(i) = d; |
|||
end |
|||
end |
|||
% Plot shortest paths distribution (only for cross-linked nodes) |
|||
nid = cn(nid,end-1); |
|||
output_data = [nid,sp,cn(:,end)]; |
|||
sp = output_data(output_data(:,3)==1,2); |
|||
figure(1); |
|||
hist(sp,20); |
|||
xlabel('shortest path length'); |
|||
</pre> |
</pre> |
||
Latest revision as of 20:20, 31 January 2018
NetworCh manuals
Shortest paths calculation in periodic CGSD simulation
Nicolas Bertin
October 2016
Introduction
This example shows how to compute the shortest path between a bead in a CGSD simulation and its periodic image using the NetworCh library. The scripts and data files corresponding to this tutorial can be found in directory <NetworChDir>/tests/shortest_path_pbc/.
Loading and replicating the structure
The chain structure corresponding to a CGSD simulation is outputted in two files: a beads position file (e.g. <simulationName>.cn) which contains the id and the spatial coordinates of every beads in the simulation, and a bond file (e.g. <simulationName>.bnd) which contains the connectivity information between the beads. The structure can be loaded in Matlab using function read_cgsd by specifying the name of the simulation cn and bnd files (without their extension). For instance, files 0_percent_strain_x500.cn and 0_percent_strain_x500.bnd can be loaded with:
% Load CGSD structure filename = '0_percent_strain_x500'; [cn,bnds,vol] = read_cgsd(filename);
By default, a cross-link is represented by a cross-link bond of zero length between two beads. To simplify the structure and reduce the computation time, one can merge the cross-linked beads into a single bead by using the merge_cross_links function:
% Merge cross-linked nodes [cn,bnds] = merge_cross_links(cn,bnds);
The physical length of each bond can be calculated using function all_segments_length:
% Calculate bonds physical lengths bonds_length = all_segments_length(cn,bnds,vol);
Since we are interseted in calculated the shortest path from a bead to its periodic image, we need to replicate our structure by periodicity. For instance, if we wish to calculate the shortest path between a bead and its replica along the y-direction, we can use function replicate_volume as follows:
ndir = 2; % replicate in the y-direction [cn1,bnds1,vol1] = replicate_volume(cn,bnds,vol,ndir);
where beads position array cn1 will contain both the position of the beads in the primary volume vol in cn1(1:size(cn,1),:) and their replica in the y-direction in cn1(size(cn,1)+1:end,:) such that size(cn1,1) = 2*size(cn,1).
bonds_weight = bnds1(:,4); %use chain length as bond weight % or bonds_weight = bnds1(:,end); %use physical distance as bond weight
Computing the shortest path between a bead and its periodic replica
Computing the periodic image shortest path distribution
n = size(cn,1);
np = ne-ns+1;
sp = zeros(np,1);
conn1 = generate_connectivity(size(cn1,1),bnds1);
A1 = adjacency(cn1,bnds1,bonds_weight);
[~,comp1] = find_components(conn1);
A1S = sparse(A1);
for i=1:np
if type == 2
j = nid(i);
else
j = i+ns-1;
end
if bio_graph
[d,~,~] = graphshortestpath(A1S,j,j+n);
sp(i) = d;
else
[d,~] = shortest_path(conn1,A1,j,j+n,comp1);
sp(i) = d;
end
end
% Plot shortest paths distribution (only for cross-linked nodes)
nid = cn(nid,end-1);
output_data = [nid,sp,cn(:,end)];
sp = output_data(output_data(:,3)==1,2);
figure(1);
hist(sp,20);
xlabel('shortest path length');