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

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


From: "Diaz,Adrian" <adriandiaz@...1447...>
Date: Tue, 14 Nov 2017 05:55:08 +0000

pardon, the NeighLists belong to the Neighbor class. This is also one of the pointers inherited by almost every class and thus should be one of the members defined in the lammps class; thus calling something like lmp->Neighbor->nlist to get the number of lists and lmp->Neighbor->lists would give you the set of lists. You can then dereference the list of lists to get the desired list if you find the right one. This can then be used just like in the pair styles, although I'm hazy on how to find the specific list you might want without looking into it more. This might then let you do it in that top level fashion you were trying in the main function.


From: Rohskopf, Andrew D <drew.rohskopf@...123...>
Sent: Monday, November 13, 2017 9:38:09 PM
To: lammps-users@lists.sourceforge.net
Subject: [lammps-users] Extracting neighbor list in LAMMPS C++ library
 

Hello,


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",
     0};
LAMMPS *lmp;

int main(int argc, char **argv) 
{

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

    /* Initialize MPI */
    MPI_Init(&argc,&argv);

    /* 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);
    MPI_Comm_rank(comm,&local);

    /* 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);
    MPI_Finalize();
}


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

(404)403-0313