Shortest paths PBC calculation: Difference between revisions

From Micro and Nano Mechanics Group
Jump to navigation Jump to search
(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 ...")
 
Line 39: Line 39:
<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,bond_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>



Revision as of 20:29, 17 October 2016

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 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

% Load CGSD structure
filename = '0_percent_strain_x500';
[cn,bnds,vol] = read_cgsd(filename);

cn(:,end+1) = [1:size(cn,1)]';

% Merge cross-linked nodes
[cn,bnds] = merge_cross_links(cn,bnds);
% Calculate bonds physical lengths
bnds(:,end+1) = all_segments_length(cn,bnds,vol);

ndir = 2; % replicate in the y-direction
[cn1,bnds1,vol1] = replicate_volume(cn,bnds,vol,ndir);

bond_weight = bnds1(:,4); %use chain length as bond weight
bond_weight = bnds1(:,end); %use physical distance as bond weight

plot_structure(cn1,bnds1,vol1,'r');

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,bond_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');

Final script