How to generate a fcc crystal matrice?
22 views (last 30 days)
Show older comments
I would like to generate a fcc crystal lattice with its atomic positions in a matrice of 3 columns. I tried to expand the crystal by translating the unit cell, but I struggle with the translation vectors and loops. Can someone suggest me a fast method? Thanks!
4 Comments
Accepted Answer
John D'Errico
on 10 Jul 2017
Edited: John D'Errico
on 10 Jul 2017
Easy enough if all you need are the FCC nodes in an unstructured sequence.
fccbase = [dec2bin(0:7) - '0';.5 .5 0;.5 .5 1;.5 0 .5;.5 1 .5;0 .5 .5;1 .5 .5];
[latx,laty,latz] = ndgrid(0:2,0:2,0:2);
latxyz = [latx(:),laty(:),latz(:)];
latxyz = repmat([latx(:),laty(:),latz(:)],14,1);
latxyz = latxyz + reshape(permute(repmat(fccbase,[1,1,prod(size(latx))]),[3 1 2]),[],3);
latxyz = unique(latxyz,'rows');
plot3(latxyz(:,1),latxyz(:,2),latxyz(:,3),'o')
The basic idea should be clear. I've taken advantage of one nice fact, that unique will be exactly able to locate numbers that are integers, or integers plus 0.5. All of those numbers are exactly representable in double precision. So there is no need even to use a tolerance.
More Answers (2)
Jose Martinez
on 26 May 2019
function FCCLattice = FCCMake(a,V)
% "a" is the Lattice Parameter:
a = a;
%Set the Volume of the cube in variable V:
V = V; %This means your cube will be of dimensions VxVxV.
%%%----Code-----%%%
%Create an array that stores all your coordinates:
%First you will need to establish the number of atoms
%that the array will have, we will do this by establishing
%the known number of atoms, in this case FCC 4xVxVxV.
N = V*V*V*4;
%This array will gives is a matrix of Nx3, that will store data.
FCCLattice = zeros(N,3);
%Create the vectors for the atoms position in the FCC Lattice:
FCCatoms = [0 0 0;(a/2) (a/2) 0;(a/2) 0 (a/2);0 (a/2) (a/2)];
%Set a variable to change rows in the array storing the coordinates:
n = 0;
%Create 3 For loops to mix the positions between xyz
for x = 0:V-1
for y = 0:V-1
for z = 0:V-1
for i = 1:4
%Create a vector that translate your location in the
%coordinate system into the position in the crystal:
coordinatestranslation = a*[x y z];
%Add 1 to move one row down in the array:
n = n+1;
FCCLattice(n,:) = coordinatestranslation +FCCatoms(i,:);
end
end
end
end
end
I have created this code for my undergraduate research if it works!
1 Comment
Muthukumar
on 5 Feb 2024
I tried this code I couldn't get the expected results. I could use some help
Jean-Marie Becker
on 23 Dec 2020
Edited: Walter Roberson
on 5 Feb 2024
%Here is a simple solution:
k=4; a=1/2;
[X,Y,Z]=meshgrid(0:k);
x=X(:);x=[x;x+a;x+a;x];
y=Y(:);y=[y;y;y+a;y+a];
z=Z(:);z=[z;z+a;z;z+a];
plot3(x,y,z,'or');view(-40,20);
0 Comments
See Also
Categories
Find more on Crystals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!