def update(self): '''Rebuild or recompute the neighbor lists Based on the changes of the atomic positions or due to calls to ``update_rcut`` and ``update_rmax``, the neighbor lists will be rebuilt from scratch. The heavy computational work is done in low-level C routines. The neighbor lists array is reallocated if needed. The memory allocation is done in Python for convenience. ''' with log.section('NLIST'), timer.section('Nlists'): assert self.rcut > 0 if self._need_rebuild(): # *rebuild* the entire neighborlist if self.system.cell.volume != 0: if self.system.natom / self.system.cell.volume > 10: raise ValueError('Atom density too high') # 1) make an initial status object for the neighbor list algorithm status = nlist_status_init(self.rmax) # The atom index of the first atom in pair is always at least # nlow. The following status initialization avoids searching # for excluded atom pairs in the neighbourlist build status[3] = self.nlow # 2) a loop of consecutive update/allocate calls last_start = 0 while True: done = nlist_build(self.system.pos, self.rcut + self.skin, self.rmax, self.system.cell, status, self.neighs[last_start:], self.nlow, self.nhigh) if done: break last_start = len(self.neighs) new_neighs = np.empty((len(self.neighs) * 3) // 2, dtype=neigh_dtype) new_neighs[:last_start] = self.neighs self.neighs = new_neighs del new_neighs # 3) get the number of neighbors in the list. self.nneigh = nlist_status_finish(status) if log.do_debug: log('Rebuilt, size = %i' % self.nneigh) # 4) store the current state to check in future calls if we # need to do a rebuild or a recompute. self._checkpoint() self.rebuild_next = False else: # just *recompute* the deltas and the distance in the # neighborlist nlist_recompute(self.system.pos, self._pos_old, self.system.cell, self.neighs[:self.nneigh]) if log.do_debug: log('Recomputed')
def update(self): '''Rebuild or recompute the neighbor lists Based on the changes of the atomic positions or due to calls to ``update_rcut`` and ``update_rmax``, the neighbor lists will be rebuilt from scratch. The heavy computational work is done in low-level C routines. The neighbor lists array is reallocated if needed. The memory allocation is done in Python for convenience. ''' with log.section('NLIST'), timer.section('Nlists'): assert self.rcut > 0 if self._need_rebuild(): # *rebuild* the entire neighborlist if self.system.cell.volume != 0: if self.system.natom/self.system.cell.volume > 10: raise ValueError('Atom density too high') # 1) make an initial status object for the neighbor list algorithm status = nlist_status_init(self.rmax) # 2) a loop of consecutive update/allocate calls last_start = 0 while True: done = nlist_build( self.system.pos, self.rcut + self.skin, self.rmax, self.system.cell, status, self.neighs[last_start:] ) if done: break last_start = len(self.neighs) new_neighs = np.empty((len(self.neighs)*3)/2, dtype=neigh_dtype) new_neighs[:last_start] = self.neighs self.neighs = new_neighs del new_neighs # 3) get the number of neighbors in the list. self.nneigh = nlist_status_finish(status) if log.do_debug: log('Rebuilt, size = %i' % self.nneigh) # 4) store the current state to check in future calls if we # need to do a rebuild or a recompute. self._checkpoint() self.rebuild_next = False else: # just *recompute* the deltas and the distance in the # neighborlist nlist_recompute(self.system.pos, self._pos_old, self.system.cell, self.neighs[:self.nneigh]) if log.do_debug: log('Recomputed')
def update(self): # Simply recompute distances, no need to rebuild nlist_recompute(self.system.pos, self.system.pos, self.system.cell, self.neighs[:self.nneigh])