I want to plot a xyz graph and also get clusters from the array of my data; can someone help please. Atoms are linked by indices. (attaching the sheet for reference)

1 回表示 (過去 30 日間)
I have combined the information from the bonds file and xyz file and want to plot a graph with various clusters (based on how the indices are connected). Is there a code to get this done with?
  3 件のコメント
ANINDYA GANGULY
ANINDYA GANGULY 2021 年 9 月 11 日
4000 rows are the 4000 atoms (2000 C and 2000 H) and the 23 columns have the position of the atoms along the x, y and z coordinates, then the heading of the 4000 atoms listed; how the indices are connected to each other (defining clusters); bond order (bo) values, bond order of the indexed atom; charge of the atom; lone pair of the atom.
If you open the .xlsx file; all the informatiom is provided in the topmost row.
Regards
J
ANINDYA GANGULY
ANINDYA GANGULY 2021 年 9 月 11 日
And id refers to the indices of the atoms. Some indices (C) are connected 1, some with 2, some with 3 atoms (can be H/C) and so on.
Regards
J

サインインしてコメントする。

回答 (1 件)

Chetan
Chetan 2024 年 5 月 2 日
I understand you wish to plot a 3D graph for clusters from an array of data. To visualize a 3D graph of atoms and identify clusters based on the connectivity defined by indices, MATLAB's graph and clustering functions can be utilized.
Step 1: Import Data
filename = 'Testfile3.xlsx'; % Update this with the actual file name
data = readtable(filename);
Step 2: Create Graph
Assuming the `id` columns represent the atom indices and `id_1` to `id_5` signify connections (with zeros indicating no connections), you can construct an edge list and create a graph.
% Initialize an empty array for edges
edges = [];
% Assuming 'id_of_atom' is the unique identifier for atoms
% and connections are in 'id_1' to 'id_5' columns
for i = 1:30
atomId = data.idOfAtom(i);
for j = 11:15 % Assuming id_1 to id_5 are in columns 11 to 15
connectedAtomId = data{i,j};
if ~isnan(connectedAtomId) % Check if there is a connection
edges = [edges; atomId, connectedAtomId];
end
end
end
% Create the graph
G = graph(edges(:,1),edges(:,2));
Step 3: Plotting
To plot the graph in 3D, the x, y, and z coordinates of each atom are required.
figure;
hold on;
% Plot edges
for i = 1:size(edges,1)
atomIndex1 = find(data.idOfAtom == edges(i,1));
atomIndex2 = find(data.idOfAtom == edges(i,2));
x = [data.x_axis(atomIndex1); data.x_axis(atomIndex2)];
y = [data.y_axis(atomIndex1); data.y_axis(atomIndex2)];
z = [data.z_axis(atomIndex1); data.z_axis(atomIndex2)];
plot3(x, y, z, 'k-'); % 'k-' for black lines
end
% Plot atoms on top of the edges
scatter3(data.x_axis, data.y_axis, data.z_axis, 36, 'filled');
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Graph of Atoms and Bonds');
hold off;
Step 4: Clustering
To identify clusters based on connectivity:
% Find connected components (clusters)
clusters = conncomp(G);
% Number of clusters
numClusters = max(clusters);
% Display number of clusters
disp(['Number of clusters: ', num2str(numClusters)]);
For further information, refer to the following documentation:
Thanks
Chetan

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by