class NeighborList

Overview

“Half” neighbor lists for atoms. More…

#include <NeighborList.h>
 
class NeighborList {
public:
    // construction
 
    NeighborList(Atoms* a, double rCut, double driftfactor = 0.05, int defaultNeighborEstimate = 50);
    ~NeighborList();
 
    // methods
 
    bool CheckAndUpdateNeighborList();
    int GetNeighbors(int n, int* neighbors, Vec* diffs, double* diffs2, int& size, double r = -1.0) const;
    void UpdateSuperCell(const SuperCell* superCell);
    const int* GetList(int a, int& n);
    const Image& GetImage(int i);
    int MaxNeighborListLength() const;
    int GetNumberOfAtoms() const;
};

Detailed Documentation

“Half” neighbor lists for atoms.

This implements a “half neighbor list”, i.e. if atom a is on atom b’s neighbor list, atom b will NOT be on atom a’s neighbor list.

GetNeighbors(…) returns “half” of the neighbors inside a sphere of radius rCut. CheckAndUpdateNeighborLists() must be called every time the positions change. If an atom has moved more than “drift”, CheckAndUpdateNeighborLists() will call MakeList(), and a new list is generated.

Construction

NeighborList(Atoms* a, double rCut, double driftfactor = 0.05, int defaultNeighborEstimate = 50)

Generate a neighbor list for atoms a with cutoff rCut.

The neighbor list will contain all neighbors within the distance rCut. The neighborlist can be reused until an atom has moved more than rCut*driftfactor.

Methods

bool CheckAndUpdateNeighborList()

Check if the neighbor list can still be reused, update if not.

int GetNeighbors(int n, int* neighbors, Vec* diffs, double* diffs2, int& size, double r = -1.0) const

Get all neighbors of atom n. The most important method :-)

Input values: n is the number of the atom. r (optional) is a cutoff, must be less than rCut in the constructor (not checked!).

In-out values: size contains the maximum space in the arrays. It is decremented by the number of neighbors placed in the arrays. It is an error to call GetNeighbors with too small a value of size.

Out values: neighbors[] contains the numbers of the atoms, diffs[] contains the relative positions of the atoms, diffs2[] contains the norms of the diffs vectors.

Return value: The number of neighbors.

void UpdateSuperCell(const SuperCell* superCell)

Inform the neighbor list that the supercell has changed.

Bug Changing the supercell while scaling the atomic positions has little effect on the interatomic distances, but that little effect should be included in the decision to update the neighborlist. That is not done, so currently this function doesn’t do anything.

const int* GetList(int a, int& n)

Low-level interface to the neighbor list.

Returns a const pointer to the internal list of neighbors of atom a, the length of the list is placed in n. The list will contain all neighbors within the cutoff radius, and some neighbors outside the cutoff. Some neighbors will be image atoms instead of real atoms (if they are neighbors thanks to the periodic boundaries), use GetImage to get the number of the real atom.

const Image& GetImage(int i)

Get the real atom corresponding to an image.

The input argument i is the number of the image counted from the first image. It is thus the number returned by GetList minus the number of atoms. The return value is a const reference to an Image.

int MaxNeighborListLength() const

Return the guaranteed maximal length of a single atom’s NB list.

Call this before using GetNeighbors() to make sure the arrays are big enough. The value may change when the neighbor list is updated.

int GetNumberOfAtoms() const

Get the number of atoms in the corresponding list of atoms.