pairwise interactions

40 views
Skip to first unread message

Walid Tariq

unread,
Jun 11, 2025, 12:08:56 PM6/11/25
to kmcos-users

Dear kmcos developers

Could you please give me an explanation of this script?

# fetch a lot of coordinates
coords = kmc_model.lattice.generate_coord_set(size=[2, 2, 2],
                                       layer_name='simplecubic_2d')

# fetch all nearest neighbor coordinates
nn_coords = [nn_coord for i, nn_coord in enumerate(coords)
             if 0 < (np.linalg.norm(nn_coord.pos - center.pos)) <= A]

Best regards
Walid

Walid Tariq

unread,
Jun 11, 2025, 7:43:26 PM6/11/25
to kmcos-users
Dear kmcos developers

Could you please give me an explanation of this script? from this example (please see: https://github.com/kmcos/kmcos/blob/master/examples/pairwise_interaction__build.py)


# fetch a lot of coordinates
coords = kmc_model.lattice.generate_coord_set(size=[2, 2, 2],
                                       layer_name='simplecubic_2d')

# fetch all nearest neighbor coordinates
nn_coords = [nn_coord for i, nn_coord in enumerate(coords)
             if 0 < (np.linalg.norm(nn_coord.pos - center.pos)) <= A]

Best regards
Walid

kmcos-users

unread,
Jun 11, 2025, 7:58:18 PM6/11/25
to kmcos-users
I will try to answer, though I did not make this example, and I have not been making such geometry tasks for a long time. 

Below, I write my understanding of what I see and you can try to figure out if it is correct.

For this example, the layer is defined as having a simple cubic structure:

layer = kmc_model.add_layer(name='simplecubic_2d')

This creates a set of coordinates:


# fetch a lot of coordinates
coords = kmc_model.lattice.generate_coord_set(size=[2, 2, 2],
                                       layer_name='simplecubic_2d')

You can print that out.


This other line defines a python variable, A:
A = 1.  # lattice const


This is actually relative to the sites. This is a relative coordinate. I believe it is related to a single site, and the positions are defined in these relative coordinates, for this example. Normally, I think it is relative to the unit cell, but I think the unit cell here is just one site.

This line defines what the variable "center" is:
center = kmc_model.lattice.generate_coord('a')

Since we have only one site in the unit cell, it is also the center of the unit cell.

For the lines below, the first line is iterating across all the coordinates in the variable I noted above.


nn_coords = [nn_coord for i, nn_coord in enumerate(coords)
             if 0 < (np.linalg.norm(nn_coord.pos - center.pos)) <= A]


The second line is computing the distance, and if the distance is "less than or equal to A", then it is within 1 distance.  So this is applying a radial cutoff definition.

The final list nn_coords will contain all coordinates from coords that are within a distance of A from the center of the unit cell.

I wouldn't write those lines this way, but they are probably a good way to write the lines. In my case, I asked Microsoft copilot what the key lines were doing, then with the answer from Microsoft copilot and my knowledge of kmcos I was able to give the above reasonable guess.
Reply all
Reply to author
Forward
0 new messages