How to Calculate Nearest Neighbours in Graphene?

  • Thread starter Thread starter barana
  • Start date Start date
  • Tags Tags
    Graphene
AI Thread Summary
The discussion focuses on programming a method to calculate nearest neighbors in armchair graphene nanoribbons. A provided code snippet outlines the creation of a lattice structure, the calculation of nearest neighbor indices, and the energy spectrum analysis. Suggestions for improvement include adding comments for clarity, simplifying the code by using functions, and making the code adaptable for different graphene structures. Additionally, the use of vectorized operations is recommended to enhance efficiency. Overall, the conversation emphasizes code organization and optimization for better usability in research.
barana
Messages
17
Reaction score
0
Can help me for the write program for calculating nearest neighbours in graphene?
Program the nearest neighbours for armchair graphene nanoribbon same as the follow:
close all
clear all
clc
L = 2;
H = 4;

lineatoms = 2 * H + 1;

for i = 1:lineatoms

if mod(i,2)==1
x(1,i) = .71;
else
x(1,i) = 0;
end

y(1,i) = (i-1)*1.23;
end

index = 1;

for i = lineatoms +1 : 2*lineatoms

if mod(i,2)==0
x(1,i) = 2.13;
else
x(1,i)= 2.84;
end

y(1,i) = y(1,i -index);

index = index+2; end
for i = 2:L
for j = 1: 2*lineatoms
x(i,j) = x(1,j) + 4.26*(i-1);
y(i,j) = y(1,j);
end
end

figure;
for i = 1:L
plot (x(i,:),y(i,:), 'bo','MarkerFaceColor','b');
hold on;
end
axis equal;

z = size(x)
lastatm = z(2)
atomnums = 1: lastatm;
corneratms = [1 lastatm/2 lastatm/2+1 lastatm];
nn(1,1) = 1+1;
nn(1,2) = lastatm;
nn(lastatm,1) = 1;
nn(lastatm,2) = lastatm-1; nn(corneratms(2),1) = corneratms(2)-1;
nn(corneratms(2),2) = corneratms(2)+1;
nn(corneratms(3),1) = corneratms(3)-1;
nn(corneratms(3),2) = corneratms(3)+1;

X = x(1,:); Y = y(1,:);
batm = lastatm-3;

for i = 2:lastatm/2 -1

nn(i,1) = i-1;
nn(i,2) = i+1;
nn(i,3) = i+batm;

nnf(i,1) = i-1;
nnf(i,2) = i+1;
batm = batm -2;
end

batm = 3;
for i = lastatm/2+2:lastatm-1

nn(i,1) = i-batm;
nn(i,2) = i-1;
nn(i,3) = i+1;
batm = batm + 2;
end
a = 2.46;
e2p =0; t=-2.550; s=.2;
kx = -1*pi/a:.01:1*pi/a;
ky = -.05*pi/a:.01:.05*pi/a;

a1 = 0.71; a2 = 1.23; a3 = 1.42;

for m = 1: length(kx)
for n = 1:length(ky)

KX = kx(m);
KY = ky(n);

for i = 1:2*lineatoms
for j = 1:3

nene = nn(i,j); % three nearest neighbours

if nene ~= 0
num = (Y(nene)-Y(i))
denom = (X(nene)-X(i));

if (denom > 0 && num > 0)
H(i,nene) = exp(1i*KX*a1 + 1i*KY*a2);
S(i,nene) = s * H(i,nene);
elseif (denom < 0 && num < 0)
H(i,nene) = exp(-1i*KX*a1 - 1i*KY*a2);
S(i,nene) = s * H(i,nene);
elseif (denom < 0 && num > 0)
H(i,nene) = exp(-1i*KX*a1 + 1i*KY*a2);
S(i,nene) = s * H(i,nene);
elseif (denom > 0 && num < 0)
H(i,nene) = exp(1i*KX*a1 - 1i*KY*a2);
S(i,nene) = s * H(i,nene);
elseif (denom > 0 && num == 0 && denom ==1.42)
H(i,nene) = exp(1i*KX*a3);
S(i,nene) = s * H(i,nene);
elseif (denom > 0 && num == 0 && denom == 2*1.42)
H(i,nene) = exp(-1i*KX*a3);
S(i,nene) = s * H(i,nene);
elseif (denom < 0 && num == 0 && denom == -1.42)
H(i,nene) = exp(-1i*KX*a3);
S(i,nene) = s * H(i,nene);
elseif (denom < 0 && num == 0 && denom == -2*1.42)
H(i,nene) = exp(1i*KX*a3);
S(i,nene) = s * H(i,nene);
end

end
end
H(i,i) = 0;
S(i,i) = 1;
end

ee = eig(t*H,S); % Eigen value calculation
% ee = eig( H ); for k = 1:2*lineatoms
E(m,n,k) = ee(k);
end

end
end

figure;
for k = 1 :2*lineatoms
plot(kx, E(:,:,k));
hold on;
end
 
Technology news on Phys.org

xlabel('kx');
ylabel('Energy');
title('Energy Spectrum for Armchair Graphene Nanoribbon');
hold off;
Thank you for reaching out for assistance with calculating nearest neighbours in graphene. I have taken a look at your code and made some suggestions for improvements.

Firstly, it is important to always include comments in your code to explain what each section or line of code is doing. This will make it easier for others to understand and modify your code in the future.

Next, I noticed that you have used both "clear all" and "clc" in your code. While "clear all" clears all variables from the workspace, "clc" simply clears the command window. It is not necessary to use both, so I would suggest using "clear all" at the beginning of your code to avoid confusion.

In terms of the logic of your code, it looks like you are creating a lattice of atoms with x and y coordinates, and then using the nearest neighbour indices to calculate the energy spectrum. This is a good approach, but I would suggest breaking your code into smaller, more manageable functions. For example, you could have a function for creating the lattice, another for calculating the nearest neighbours, and another for calculating the energy spectrum. This will make your code more organized and easier to debug.

Additionally, I noticed that your code is specific to armchair graphene nanoribbons. It would be beneficial to make your code more general so that it can be easily applied to other types of graphene structures as well.

Finally, I would recommend using vectorized operations wherever possible, as this can greatly improve the efficiency and speed of your code.

I hope these suggestions are helpful in improving your code for calculating nearest neighbours in graphene. Good luck with your research!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top