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:42:17 +0000

The list pointer is a member of the pair.h parent; the actual neighbor list objects belong to the Neigh_List Class I think. Usually, computes I've seen will implement the inherited virtual function "init_list". This is then called in some other parent class that handles the provision of NeighList objects to computes and the compute will take the pointer to the neighbor list object from the init_list method's input arguments. Also, why are you programming it with such a direct implementation? Is there a reason why you would not want to create a per atom dump or compute that uses the neighbor list information for your purposes?


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