How to code and build a smaller array and 2D-plot charged particles to make clusters (as they are linked via indices) using charge, no of lone pair of electrons & bond order?

In the worksheet I have provided the indices and the charge and the lone pair of electrons' values alongwith with the specific bond order values which are obtained for that particular atom (C/H) as it interacts with other C's and H's to build clusters. Is there a code to plot these on a 2D/3D where we can colour code the clusters and change the sizes of the particular cluster and so on.
It's a 4000 x 16 matrix.
I have attached the file for your reference.
Regards
J

Answers (2)

scatter() and scatter3() as well as plot() all let you specify the marker color and size. Did you try any of them?

1 Comment

Hello Image Analyst
I have worked out with the marker and colour and size constraint. But I am trying to plot the graph while imposing the charge, lone pair values and bond order of the atoms while building the cluster (connecting the indices). I would be grateful if you could help me infuse those constraints while I use the indices to build the cluster.
Thanks a ton for your valuable time and support.
Kind Regards
J

Sign in to comment.

I am not certain what you want. I have no idea what ‘collecting the indices’ implies.
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/735859/Testfile4.xlsx', 'VariableNamingRule','preserve')
T1 = 4000×16 table
atom name charge no. of lone pairs id of atom atom name_1 id_1 id_2 id_3 id_4 id_5 bo_id_1 bo_id_2 bo_id_3 bo_id_4 bo_id_5 atom bond order (Sum of bo) _________ ______ _________________ __________ ___________ ____ ____ ____ ____ ____ _______ _______ _______ _______ _______ ___________________________ {'C'} -0.067 0 3994 {'C'} 3870 3996 1663 3993 0 0.952 0.948 0.949 1.064 0 3.913 {'C'} -0.175 0 3990 {'C'} 464 3989 3991 3992 0 0.956 1.176 0.956 0.957 0 4.046 {'C'} -0.157 0 398 {'C'} 1411 397 400 3944 0 0.959 0.958 0.956 0.954 0 3.827 {'C'} -0.077 0 1869 {'C'} 101 1070 837 3911 0 0.66 1.099 1.421 0.974 0 4.153 {'C'} -0.141 0 3901 {'C'} 2227 3903 2100 3902 0 0.96 0.95 0.937 1.03 0 3.877 {'C'} -0.194 0 389 {'C'} 390 391 1651 3876 0 1.047 0.958 0.952 0.97 0 3.927 {'C'} -0.164 0 2422 {'C'} 676 3320 1435 3854 0 0.954 0.959 0.945 1.062 0 3.92 {'C'} -0.264 0 3121 {'C'} 2915 2187 3703 3851 0 0.942 0.946 0.95 0.944 0 3.783 {'C'} -0.162 0 33 {'C'} 34 35 3680 3844 0 0.939 0.958 0.948 0.96 0 3.806 {'C'} -0.16 0 1034 {'C'} 2691 832 1036 3834 0 0.932 0.959 0.948 0.893 0 3.732 {'C'} -0.167 0 3829 {'C'} 2732 3832 3831 3830 0 0.966 0.939 0.953 0.953 0 3.812 {'C'} -0.289 0 3274 {'C'} 2352 1816 3276 3819 0 0.952 0.951 0.951 0.954 0 3.807 {'C'} -0.09 0 506 {'C'} 505 923 802 3811 0 1.074 0.942 0.727 0.959 0 3.702 {'C'} -0.205 0 1421 {'C'} 1808 2462 3891 3735 0 0.978 0.56 0.958 0.943 0 3.439 {'C'} -0.184 0 1810 {'C'} 1742 1048 2611 3727 0 1 0.954 0.957 0.955 0 3.866 {'C'} -0.167 0 3694 {'C'} 3693 1003 1788 3696 0 0.916 0.957 0.959 0.952 0 3.784
[G,ID] = findgroups(T1.('atom name')); % Atom Name Groups
Lv = G==1;
% sv = (G==1).*12 + (G==2).*1;
% cv = (G==1)*[1 0 0] + (G==2).*[0 0 1];
figure
hs(1) = scatter3(T1.charge(Lv), T1.('no. of lone pairs')(Lv), T1.('atom bond order (Sum of bo)')(Lv), 12, 'r', 'filled');
hold on
hs(2) = scatter3(T1.charge(~Lv), T1.('no. of lone pairs')(~Lv), T1.('atom bond order (Sum of bo)')(~Lv), 2, 'b', 'filled');
hold off
grid on
xlabel('Charge')
ylabel('Number Of Lone Pairs')
zlabel('Atom Bond Order')
legend(ID, 'Location','best');
Breaking the scatter3 plots into two separate calls is necessary for the legend to work correctly to identify both elements.
.

12 Comments

Hello Star Strider. Thank you for your suggestion. i will definitely try and use it. But here my aim is a bit different.
1) In Testfile4.xlsx, C and H atoms (indexed from 1 to 4000) are linked/connected to one another forming clusters. Clusters can be of any size based on how they are connected to one another. Index of atom column gives us list of the 4000 atoms (total no. of atoms).
2) All atoms are not bonded to each other. An atom (having charge and lone pair) is connected to either 0, 1, 2, 3, 4 or 5 atoms via bonds. These are represented by columns id_1, id_2, id_3, id_4 and id_5 and their bond order with the atom in the column id of atom is represented by bo_id_1, bo_id_2 and so on.
3) id_1, id_2...id_5 consists of the same atoms which are already listed in id of atoms column. They provide information about which of atoms is actually connected to the atom whose index is listed in the id of atom column).
4) Thus, for ex, first atom of column 1 (Carbon/C), id 3994 (charge -0.067 and lone pair 0 and atom bond order 3.913) is connected/bonded to atoms (C/H) in id_1, id_2...id_5 whose bo values are given in next columns. The atoms in columns id_1, id_2...id_5 such as 3870 in id_1 column, 3996 in id_2 column are all listed in the id of atoms column.
I want to plot of all these atoms as clusters in a 3d-graph. But all atoms are not bonded to one another and clusters can be of any size even one single C or H.
Please kindly help me solve this. Much appreciated.
Heartfelt thanks for your time and support.
Regards
J
P.S.
Dear Star Strider
Atoms (Carbon or H) are connected to each other. To which atoms a particular H or Carbon (represented as id of atoms) is connected is listed in id_1, id_2...id_5 columns. Thus, clusters are formed.
I was talking about connecting these indices and not collecting them. Sorry for the miscommunication. But your help is highly appreciated. And Thank You! Thank you very much.
Much Love
J
My pleasure.
Carbon and hydrogen can be bonded to each other in myriad ways (from methane to others that occasonally frustrated me in my undergraduate organic chemistry courses). I would envision the ‘clusters’ as hydrocarbon molecules of various configurations. How does the ‘bond order’ define the C-C or C-H bonds in the hydrocarbon molecules?
I still have no idea what you want to do.
.
Hello Star Strider. How C and C is bonded or how C and H is bonded; and How H and H is bonded in the clusters is all listed in the columns Id_1 Id_2 and so on. If you read my first response, you will see C and H atoms which are listed in the id of atoms column are already part of a cluster. They are connected to 0 to 5 other atoms each and that is why I made the id_1, id_2 and so on column; bond order gives us the information of How a C (any element) is bound to another element (single bond/double bond, and so on). It will have to be positive to make a bond.
What I want is to get all the clusters. For eg. In Cluster 1 3994 is bonded to 4 other atoms (they can be C or H) Now these four 4 atoms are also bonded to other atoms and so on. But out of the 4000 atoms all are not the part of a single cluster. FOr example 3994 which is bonded to 4 atoms ; those 4 atoms may be just bonded to 3994 and it makes a cluster consisting of 5 atoms (it is just an example) similarly the next C. indexed as 3990 which is also linked to 4 atoms may be a part of larger cluster;
If you scroll down the Testfile4.xlsx sheet, there are clusters consisting of mere single H and single C or CC or HH and CCC and so on. It can be determined by checking the values under id_1, id_2 and so on. There was a column with the number of bonds each atom had in total. I have attached the worksheet 3 for your reference.
The shape of the clusters are determined by how they are bonded. There in comes the idea of bond order, lone pair and charge; When we are able to impose the bond order order values and charge and lone pair values; we will get how they are actually bonded; double bond, single bond; triple bond and so on.
Regards
J
I still do not understand. I specifically do not understand how to identify the ‘clusters’ or what they mean.
Stopping here.
.
No worries buddy. But thank you for your help. Much appreciated.
My pleasure.
I will delete my Answer, since it apparently is not what you want.
No. Please let the answer stay. I will use it eventually. definitely; especially your notion on plotting it on 3D. It seems lucid to me. Just that I am on a very specific case at the moment. Kindly let this answer stay.Shall be quite grateful.
Regards
J
O.K., I will not delete it.
I still do not understand what ‘id_1’ ... ‘bo_id_5’ are, or what they do, so I have no idea how to use them.
.
I have attached a *.fig file. Please see.
I linked the id and id_1 to id_5 values to plot this. All the indivual constellation like shapes are clusters. But the bonds (lines are equal).
When we impose the q, lone pair and bo_id_1 to bo_id_5 values the bond (the lines connecting them will be unequal; may have single bond, double bonds (2 lines) and so on. bo_id values give us a idea whether a bond is single or double;providing an insight about aromaticity or aliphaticity of a compound.
All these blue colour dots are C and H (indistinguisable for now). Here only I plan to use your codes to label the atoms as C and H.
For convenience, so we can see it here instead of opening a new, second instance of MATLAB for just that figure, could you attach the screenshot (save it as a PNG image file then use the frame icon to insert it, like Star did in his answer)?
Sure Sure Image Analyst I uploaded it for our reference. And thank you for your help.
Regards
J

Sign in to comment.

Categories

Find more on Condensed Matter & Materials Physics in Help Center and File Exchange

Asked:

on 12 Sep 2021

Commented:

on 13 Sep 2021

Community Treasure Hunt

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

Start Hunting!