Dear Freud Users,
I am new to Freud and trying to compute rdf between two particles, A and A1, which are present in my system. However, I am getting a blank plot, i.e., no values at x and y axes. My script is attached below, please help me in fixing this problem.
import freud
import pickle
import gsd.hoomd
import matplotlib.pyplot as plt
import numpy as np
def snap_molecule_indices(snap):
system = freud.AABBQuery.from_system(snap)
num_query_points = num_points = snap.particles.N
query_point_indices = snap.bonds.group[:, 0]
point_indices = snap.bonds.group[:, 1]
distances = system.box.compute_distances(
system.points[query_point_indices], system.points[point_indices]
)
nlist = freud.NeighborList.from_arrays(
num_query_points, num_points, query_point_indices, point_indices, distances
)
cluster = freud.cluster.Cluster()
cluster.compute(system=system, neighbors=nlist)
return cluster.cluster_idx
def intermolecular_rdf(
gsdfile = "s2.gsd",
A_name = "A",
B_name = "A",
start=0,
stop=None,
r_max=10,
r_min=0,
bins=100,
exclude_bonded=True,
):
with gsd.hoomd.open(gsdfile) as trajectory:
snap = trajectory[0]
if r_max is None:
# Use a value just less than half the maximum box length.
r_max = np.nextafter(
np.max(snap.configuration.box[:3]) * 0.5, 0, dtype=np.float32
)
rdf = freud.density.RDF(bins=bins, r_max=r_max, r_min=r_min)
type_A = snap.particles.typeid == snap.particles.types.index(A_name)
type_B = snap.particles.typeid == snap.particles.types.index(B_name)
if exclude_bonded:
molecules = snap_molecule_indices(snap)
molecules_A = molecules[type_A]
molecules_B = molecules[type_B]
for snap in trajectory[start:stop]:
A_pos = snap.particles.position[type_A]
if A_name == B_name:
B_pos = A_pos
exclude_ii = True
else:
B_pos = snap.particles.position[type_B]
exclude_ii = False
box = snap.configuration.box
system = (box, A_pos)
aq = freud.locality.AABBQuery.from_system(system)
nlist = aq.query(
B_pos, {"r_max": r_max, "exclude_ii": exclude_ii}
).toNeighborList()
if exclude_bonded:
pre_filter = len(nlist)
indices_A = molecules_A[nlist.point_indices]
indices_B = molecules_B[nlist.query_point_indices]
nlist.filter(indices_A != indices_B)
post_filter = len(nlist)
rdf.compute(aq, neighbors=nlist, reset=False)
# normalization = post_filter / pre_filter if exclude_bonded else 1
# rdf, normalization = intermolecular_rdf(gsdfile, A_name, B_name, r_max=6, exclude_bonded=False)
# print(f"Normalization for bonded pair exclusion: {normalization:.5f}")
return rdf
plt.plot(rdf.bin_centers, rdf.rdf)
plt.xlabel("r (A.U.)")
plt.ylabel("g(r)")
plt.show()
Any suggestions will be of great importance to me. Thanks in advance!
-Arpita Srivastava