removing bonds

16 views
Skip to first unread message

jude vishnu

unread,
Nov 14, 2022, 12:36:15 PM11/14/22
to freud-users
Dear all,
I have multiple bonded clusters in my system. I can use freud-analysis package to get the cluster_keys in each of these clusters.
I want to use these cluster_keys if possinble to remove the positions and bonds in my system.
Removing positions can be done  very easy and fast using np.delete.
But unfortunately to remove the corresponding bonds I am not sure whether there is s fast way available. From what I can think of I will have to search for the particle indices found from the cluster_keys in the array of bonds to remove them. I think this would be a very expensive step, if the cluster to be removed is large.
Is there a way in freud-analysis to remove both position and bonds of a bonded cluster quicker? Like are there any work arounds, if anyone could suggest.

Regards,
Jude

Tommy Waltmann

unread,
Nov 14, 2022, 1:40:54 PM11/14/22
to freud-users
Hi Jude,

There is no shortcut built into freud to do what you're asking for. The freud library does cluster calculations and gives the user the output data; what is done with the output data is up to the user.

The most efficient way to do what you're asking for would be with a composition of numpy operations. Think about the problem you are trying to solve and the smaller steps needed to achieve that goal. If you are trying to remove elements from an array of bonds, you may want to use `np.delete` or numpy's vectorized indexing, but either of those methods will need to know the indices you are trying to remove/keep from the array. Give some thought to how you will identify the indices in the bonds array you need to remove/keep given the `cluster_keys` from freud.

Remember that googling how to do things with numpy can be a useful tool to get the ball rolling. If you've thought about it for a while and still need help, you can ask again on here.

Best,
Tommy

jude vishnu

unread,
Nov 15, 2022, 3:14:16 AM11/15/22
to freud-users
Hi Tommy,
Well I tried using numpy.where. I want my biggest cluster to be removed. I get the id's to be removed using cl.cluster_keys[0]. Now I search for the bonds to be removed.
rembnd = np.empty(0,dtype=int)
for x in cl.cluster_keys[0]:
     rembnd= np.append(rembnd,np.where(bonds==x)[0] ) # This will give me row number
new_bonds  = np.delete(bonds,rembnd,axis=0)

But this method is extremely slow when I have 457632 particles in that cluster.
Is there a better way ? (I think the for loops slowing things down, if I am not mistaken )

Regards,
Jude

jude vishnu

unread,
Nov 15, 2022, 7:14:21 AM11/15/22
to freud-users
Hi,
Just wanted to update on my previous email. I found a faster way that could work:
sel - linear array of particle ids which will be deleted
tempbonds-2d array of bonds with particle indices

ix = np.in1d(tempbonds.ravel(), sel).reshape(tempbonds.shape) #Creates a boolean array in 1d with True value at locations in tempbonds where particle index in sel is present, and then    #reshape it back to 2d array
found = np.where(ix)[0] #Gives row ids
newbonds=np.delete(tempbonds,found,axis=0) #bonds after deleting

Regards,
Jude

--
You received this message because you are subscribed to a topic in the Google Groups "freud-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/freud-users/7GXNkY9UfeE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to freud-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/freud-users/98a567f1-8326-4f8a-bacf-b803a0ca77fcn%40googlegroups.com.


--
Yours truly,
Jude Ann Vishnu
Reply all
Reply to author
Forward
0 new messages