LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
[lammps-users] Extracting neighbor list in LAMMPS C++ library
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lammps-users] Extracting neighbor list in LAMMPS C++ library

From: "Rohskopf, Andrew D" <drew.rohskopf@...123...>
Date: Tue, 14 Nov 2017 02:38:09 +0000


I'm trying to extract a neighbor list array for every atom using the LAMMPS C++ library, in a similar way that pair styles access the neighbor list during force and energy calculation. Here's a minimum example of code:

#include <iostream>
#include "mpi.h"
#include "lammps.h" 
#include "input.h"
#include "atom.h"
#include "library.h"

using namespace LAMMPS_NS;
char *args1[] = {
    (char *) "lmp",
    (char *) "-screen",
    (char*) "none",
LAMMPS *lmp;

int main(int argc, char **argv) 

    int color,key,global,local;
    MPI_Comm comm;

    /* Initialize MPI */

    /* Split the communicators so that multiple instances of LAMMPS can be run */
    MPI_Comm_rank(MPI_COMM_WORLD, &global);
    color = global / 1; // Change "1" to 2 in order to use 2 procs per instance, etc..
    key = global; 
    MPI_Comm_split(MPI_COMM_WORLD, color, key, &comm);

    /* Create LAMMPS object */
    lmp = new LAMMPS(3,args1,comm);

    /* Set up system */
    lmp->input->one("neighbor 0.0 bin");
    lmp->input->one("boundary p p p ");
    lmp->input->one("units metal");  
    lmp->input->one("atom_style atomic");
    lmp->input->one("atom_modify map array");
    lmp->input->one("region box prism 0 1 0 1 0 1 0 0 0 units lattice"); 
    lmp->input->one("create_box 1 box");  
    lmp->input->one("create_atoms 1 random 100 10101 NULL"); 

    /* Get neighbors for every atom */
    /* ????? How to do this ????? */

    /* Delete LAMMPS object */
    delete lmp;

    /* Close MPI */
    int MPI_Comm_free(MPI_Comm *comm);

This short script can be compiled with the attached Makefile (just set the LAMMPS directory and shared library paths). 

After creating the LAMMPS pointer, I set up a simple system of 100 randomly placed atoms in a simple box. I can easily access per-atom quantities now via lmp->atom, for example. But how can I compute and access the neighbor list for every atom in this system? I don't necessarily even want to declare a pair style, even though it may be necessary. For example, the 2-body neighbor list in the Morse pair style is accessed via:

  inum = list->inum;
  ilist = list->ilist;
  numneigh = list->numneigh;
  firstneigh = list->firstneigh;

But I don't have access to the "list" pointer in my code, nor do I know how to build a neighbor list using the C++ library. 

I've thought about making a custom pair style that just gets the neighbor list, and then retrieving that list with via pointer in my main code. I was just wondering if there was a more simple solution.

Thanks for your time. 

Drew Rohskopf

Atomistic Simulation & Energy Group

Georgia Institute of Technology


Attachment: Makefile
Description: Makefile