Efficient management of interacting atoms based on their mutual distance
Dear all
Currently, I am dealing with a dataset, which I attach here in the "File.txt", file, where the first column is an atomic label ranging from 0 to 95900 (that it is, to the number of atoms-1). Each row represents the spatial coordinates of each i-th atom of the system, denoting the second, third, and fourth columns the coordinate values, in Angstroms, along x-, y-, and z-th directions. It is important to note that the fourth column, that it is, the z-th spatial coordinate, only can have two different values, 3.27645 and 9.82515. So basically, I have two monolayers at two different heights.
My goal is, for each atom, to loop over the first ten nearest interlayer atoms. That it is, for the i-th atom, to loop over the atoms with the lowest deviations in the xy plane from (xi,yi) and with different value of the z-th component. Importantly, if, for example, during the looping one founds that atom with id 4 and 560 have in common the atom with 1100 as one of the ten nearest neighbors to them, it would be very desirable that when looping in for 1100, the program knows, from the previous calculations, that atoms with label 4 and 560 are indeed two of the ten nearest neighbors to 1100.
I had in mind something like:
file=readmatrix(‘File.txt’);
counter=0;
for i=1:length(file(:,1))
indices=file(file(:,4)~=file(i,4));
atoms=file(indices,1:3);
for j=1:length(indices)
distances(j)=norm(atoms(j,2:3)-file(i,2:3)); % Angstroms
end
sorted_distances=unique(distances); % Angstroms
interacting_distances=sorted_distances(1:10); % Angstroms
interacting_atoms=find(distances<=max(interacting_distances));
for j=1:length(interacting_atoms(:,1))
counter=counter+1;
interaction_list(counter,1)=file(i,1); % i-th atom id
interaction_list(counter,2)=interacting_atoms(j,1); % j-th atom id
interaction_list(counter,3)=somevalue;
end
clear indices distances sorted_distances interacting_distances interacting_atoms
end
Obviously, this approach does not seem to be very fast/efficient. Also, this won’t meet one of the requirements I explained above: that if one finds that i-th atom interacts with j-th atom, one knows that j-th atom interacts with i-th atom (double counting). In that case, I would need to save in the interaction_list(counter,3)=-somevalue.
Any idea?Dear all
Currently, I am dealing with a dataset, which I attach here in the "File.txt", file, where the first column is an atomic label ranging from 0 to 95900 (that it is, to the number of atoms-1). Each row represents the spatial coordinates of each i-th atom of the system, denoting the second, third, and fourth columns the coordinate values, in Angstroms, along x-, y-, and z-th directions. It is important to note that the fourth column, that it is, the z-th spatial coordinate, only can have two different values, 3.27645 and 9.82515. So basically, I have two monolayers at two different heights.
My goal is, for each atom, to loop over the first ten nearest interlayer atoms. That it is, for the i-th atom, to loop over the atoms with the lowest deviations in the xy plane from (xi,yi) and with different value of the z-th component. Importantly, if, for example, during the looping one founds that atom with id 4 and 560 have in common the atom with 1100 as one of the ten nearest neighbors to them, it would be very desirable that when looping in for 1100, the program knows, from the previous calculations, that atoms with label 4 and 560 are indeed two of the ten nearest neighbors to 1100.
I had in mind something like:
file=readmatrix(‘File.txt’);
counter=0;
for i=1:length(file(:,1))
indices=file(file(:,4)~=file(i,4));
atoms=file(indices,1:3);
for j=1:length(indices)
distances(j)=norm(atoms(j,2:3)-file(i,2:3)); % Angstroms
end
sorted_distances=unique(distances); % Angstroms
interacting_distances=sorted_distances(1:10); % Angstroms
interacting_atoms=find(distances<=max(interacting_distances));
for j=1:length(interacting_atoms(:,1))
counter=counter+1;
interaction_list(counter,1)=file(i,1); % i-th atom id
interaction_list(counter,2)=interacting_atoms(j,1); % j-th atom id
interaction_list(counter,3)=somevalue;
end
clear indices distances sorted_distances interacting_distances interacting_atoms
end
Obviously, this approach does not seem to be very fast/efficient. Also, this won’t meet one of the requirements I explained above: that if one finds that i-th atom interacts with j-th atom, one knows that j-th atom interacts with i-th atom (double counting). In that case, I would need to save in the interaction_list(counter,3)=-somevalue.
Any idea? Dear all
Currently, I am dealing with a dataset, which I attach here in the "File.txt", file, where the first column is an atomic label ranging from 0 to 95900 (that it is, to the number of atoms-1). Each row represents the spatial coordinates of each i-th atom of the system, denoting the second, third, and fourth columns the coordinate values, in Angstroms, along x-, y-, and z-th directions. It is important to note that the fourth column, that it is, the z-th spatial coordinate, only can have two different values, 3.27645 and 9.82515. So basically, I have two monolayers at two different heights.
My goal is, for each atom, to loop over the first ten nearest interlayer atoms. That it is, for the i-th atom, to loop over the atoms with the lowest deviations in the xy plane from (xi,yi) and with different value of the z-th component. Importantly, if, for example, during the looping one founds that atom with id 4 and 560 have in common the atom with 1100 as one of the ten nearest neighbors to them, it would be very desirable that when looping in for 1100, the program knows, from the previous calculations, that atoms with label 4 and 560 are indeed two of the ten nearest neighbors to 1100.
I had in mind something like:
file=readmatrix(‘File.txt’);
counter=0;
for i=1:length(file(:,1))
indices=file(file(:,4)~=file(i,4));
atoms=file(indices,1:3);
for j=1:length(indices)
distances(j)=norm(atoms(j,2:3)-file(i,2:3)); % Angstroms
end
sorted_distances=unique(distances); % Angstroms
interacting_distances=sorted_distances(1:10); % Angstroms
interacting_atoms=find(distances<=max(interacting_distances));
for j=1:length(interacting_atoms(:,1))
counter=counter+1;
interaction_list(counter,1)=file(i,1); % i-th atom id
interaction_list(counter,2)=interacting_atoms(j,1); % j-th atom id
interaction_list(counter,3)=somevalue;
end
clear indices distances sorted_distances interacting_distances interacting_atoms
end
Obviously, this approach does not seem to be very fast/efficient. Also, this won’t meet one of the requirements I explained above: that if one finds that i-th atom interacts with j-th atom, one knows that j-th atom interacts with i-th atom (double counting). In that case, I would need to save in the interaction_list(counter,3)=-somevalue.
Any idea? fast and efficient double counting of data MATLAB Answers — New Questions