python - How can I set a minimum distance constraint for generating points with numpy.random.rand? -


i trying generate efficient code generating number of random position vectors use calculate pair correlation function. wondering if there straightforward way set constraint on minimum distance allowed between 2 points placed in box.

my code follows:

def pointrun(number, dr): """ compute 3d pair correlation function random distribution of 'number' particles placed 1.0x1.0x1.0 box. """ ## create array of distances on calculate.        r = np.arange(0., 1.0+dr, dr)  ## generate list of arrays define positions of points, ##    , calculate number density.     = np.random.rand(number, 3)     numberdensity = len(a)/1.0**3  ## find reference points within desired region avoid edge effects.      b = [s s in if all(s > 0.4) , all(s < 0.6) ]  ## compute pairwise correlation each reference particle     dist = scipy.spatial.distance.cdist(a, b, 'euclidean')     alldists = dist[(dist < np.sqrt(3))]  ## create histogram generate radial distribution function, (rdf) or r(r)     rr, bins = np.histogram(alldists, bins=r, density=false)  ## make empty containers hold radii , pair density values.     radii = []     rhor = []  ## normalize rdf values distance , shell volume pair density.     in range(len(rr)):         y = (r[i] + r[i+1])/2.         radii.append(y)         x = np.average(rr[i])/(4./3.*np.pi*(r[i+1]**3 - r[i]**3))         rhor.append(x)  ## generate normalized pair density function, total number density     gr = np.divide(rhor, numberdensity)     return radii, gr 

i have tried using loop calculated distances each point made , accepted or rejected. method slow if use lot of points.

as understood, you're looking algorithm create many random points in box such no 2 points closer minimum distance. if problem, can take advantage of statistical physics, , solve using molecular dynamics software. moreover, need molecular dynamics or monte carlo obtain exact solution of problem.

you place n atoms in rectangular box, create repulsive interaction of fixed radius between them (such shifted lennard-jones interaction), , run simulation time (untill see points spread out uniformly throughout box). laws of statistical physics can show positions of points maximally random given constraint points cannot close distance. this not true if use iterative algorithm, such placing points one-by-one , rejecting them if overlap

i estimate runtime of several seconds 10000 points, , several minutes 100k. use openmm moelcular dynamics simulations.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -