libAtoms / matscipy

Materials science with Python at the atomic-scale
http://libatoms.github.io/matscipy/
GNU Lesser General Public License v2.1
188 stars 55 forks source link

Search of (A-B)-(A-B)-(...) rings in ring_statistics #86

Closed yunai2384 closed 3 years ago

yunai2384 commented 3 years ago

Hello, I was searching for rings in compound AB2, and the only type of rings i need is (A-B)-(A-B)-(...). I modified functions step_colser(), step_away() and find_shortest_distances() with type[j] != type[j], but it say "Distance map and graph do not match". How can i do with it ? Best regard, yunai

jameskermode commented 3 years ago

Perhaps generating all rings and then filtering based on type afterwards would be a simpler approach?

yunai2384 commented 3 years ago

Perhaps generating all rings and then filtering based on type afterwards would be a simpler approach?

Thanks for reply, i think the shortest path of A-A-A... rings and A-B-A-B... rings should be different, and a little modification of the shortest path algorithm forA-B-A-B rings should be better?

jameskermode commented 3 years ago

Thinking about this a little more, I think you could actually do it with no modifications to the shortest path algorithm, just by passing a custom cutoff dictionary to neighbour_list. If you leave out A-A and B-B from the dictionary they will never considered to be neighbours.

pastewka commented 3 years ago

You can also explicitly remove A-A and B-B- neighbors from the neighbor list. Try the following (untested):

import _matscipy
from matscipy.neighbours import neighbour_list

i, j, r = neighbour_list('ijD', a, cutoff)
n = a.numbers
mask = a[i] != a[j]  # True for differing elements
i = i[mask]
j = j[mask]
r = r[mask]
d = _matscipy.distances_on_graph(i, j)
ring =_matscipy.find_sp_rings(i, j, r, d, maxlength)
yunai2384 commented 3 years ago

Thanks a lot, i checked the rings in my 816 atoms in AB2, and the rings i get are all A-B-A-B, it helps me a lot. Best regards and keep healthy!