Skip to content

Commit

Permalink
Additional Matlab files
Browse files Browse the repository at this point in the history
  • Loading branch information
mlxd committed Dec 16, 2016
1 parent 901eea5 commit 75a55c0
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
21 changes: 21 additions & 0 deletions matlab/binData.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function [g6B,bin] = binData(g6C,binMax,bins)
%Bin the data returned from g6_struct into equi-separated partitions
% g6C: Matrix containing the g6 values output from g6_struct
% binMax: The maximum binning value
% bins: The number of bins to take
%Returns
% g6B: The binned g6 data
% bin: The bin values of g6B

bin = linspace(0,binMax,bins);
g6B = zeros(length(bin)-1,1);
for kk=1:(length(bin)-1)
idx = find( g6C(1,:) >= bin(kk) & g6C(1,:) < bin(kk+1) );
if length(idx) >0
g6B(kk) = sum(g6C(2,idx))./length(idx); %Average the values in a bin
else
g6B(kk) = 0;
end
end

end
8 changes: 8 additions & 0 deletions matlab/findNN.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function [neighbours,locations] = findNN(pos,X,Y,radius)
% Returns values and indices of nearest neighbours to location pos in
% positions X,Y within radius.

r = sqrt(bsxfun(@minus,pos(1),X).^2 + bsxfun(@minus,pos(2),Y).^2);
locations = find(r < radius & r~=0);
neighbours = [X(locations) Y(locations)];
end
31 changes: 31 additions & 0 deletions matlab/g6_struct.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function [g6C] = g6_struct(X,Y,rad)
%Determine the orientational correlation function between every pairing of
%points, and sorts the results based on distance between points. This gives
%g6(r).
% X,Y: Vectors of x,y values for points.
% rad: Radius in which to examine for neighbouring points.
%Return:
% g6C: Matrix of g6 values and parameters

%Determine all orientational order values for points
psi6p = zeros(length(X),1);
for ii=1:length(X)
psi6p(ii) = psi6([X(ii),Y(ii)],X,Y,rad);
end

%Calculate all n choose k pairings of points, and give distance between
%them, values for the respective orientational orders, and g6 values. Sort
%the values based on separated distance
S = uniqPairIdx_precalc([X,Y],psi6p);
[~,order] = sort([S(:).rabs],'ascend');
SSorted = S(order);

%Create output structure for next stage of calculation
for ii=1:size(SSorted,2)
g6S(ii).r = SSorted(ii).rabs;
psi6_1 = SSorted(ii).cor0;
psi6_2 = SSorted(ii).cor1;
g6S(ii).val = abs(conj(psi6_1)*conj(psi6_1));
end
g6C = cell2mat(squeeze(struct2cell(g6S)));
end
12 changes: 12 additions & 0 deletions matlab/psi6.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function [psi6_pos,nn] = psi6(pos,X,Y,radius)
[nn,idx] = findNN(pos,X,Y,radius);
psi6_pos = 0;

if size(nn,1) > 0
for ii=1:size(nn,1)
psi6_pos = psi6_pos + exp(6*1i*getAngle2(pos, [X(idx(ii)), Y(idx(ii))] ));
end
psi6_pos = psi6_pos./length(nn);
end
nn=length(nn);
end
19 changes: 19 additions & 0 deletions matlab/uniqPairIdx_precalc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function [S] = uniqPairIdx_precalc(R,psi6p)
%Calculate all unique pairings of the orientational correlations, and
%create a struct to return that holds the distance between paired elements,
%and the respective orientational order values.
% R: Vectors of R=[X Y] values for points.
% psi6p: Orientational order values defined over the range of points
%Return:
% S: Struct of orientational corder values cor0,cor1 and distance
% between elements
count = 0;
for ii=1:(size(R,1)-1)
for jj=ii+1:size(R,1)
count = count +1;
S(count).cor0 = psi6p(ii);
S(count).cor1 = psi6p(jj);
S(count).rabs = sqrt( sum( (R(ii,:) - R(jj,:) ).^2 ) );
end
end
end

0 comments on commit 75a55c0

Please sign in to comment.