def estimatebox(mols,maxs,dim): delta = 0.125 box = list(maxs) box[dim] /= 2 dist0 = rdf.calc(mols, maxs, binw=delta*2, cutoff=cutoff) #print dist0 zeros = 0 while dist0[zeros] == 0.0: zeros += 1 maxs[dim] = box[dim] + zeros*delta*2 #tune x while delta > 0.00001: dist0 = rdf.calc(mols, maxs, binw=delta*2, cutoff=cutoff) #print dist0 best = 0 bestsize = 0.0 while box[dim] < maxs[dim]: dist = rdf.calc(mols, box, binw=delta*2, cutoff=cutoff) count = 0 n = min(len(dist),len(dist0)) for i in range(n): if (dist[i] ==0 and dist0[i] == 0): count += 1 if best < count: best = count bestsize = box[dim] #print best,bestsize,dist box[dim] += delta delta /= 2 box[dim] = bestsize - delta*2 maxs[dim] = bestsize + delta*4 maxs[dim] = bestsize return bestsize
cutoff = float(sys.argv[1]) while True: # read a line, anyway line = sys.stdin.readline() if len(line) == 0: break columns = line.split() # look up tags tag = columns[0] if tag in ("@BOX3",): line = sys.stdin.readline() columns = line.split() box = map(float, columns[0:3]) elif tag in ("@WTG6", "@WTG3", "@NX4A", "@NX3A"): # get the first line == number of molecules line = sys.stdin.readline() columns = line.split() nmol = int(columns[0]) mols = [] for i in range(nmol): line = sys.stdin.readline() columns = line.split() xyz = map(float, columns[0:3]) for dim in range(3): xyz[dim] -= math.floor(xyz[dim] / box[dim]) * box[dim] mols.append(xyz) dist = rdf.calc(mols, box, binw=0.5, cutoff=cutoff) print dist