LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
Re: [lammps-users] LAMMPS library: Gather specific atoms and insert small molecules
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lammps-users] LAMMPS library: Gather specific atoms and insert small molecules


From: Axel Kohlmeyer <akohlmey@...24...>
Date: Thu, 31 Aug 2017 21:46:53 -0400



On Thu, Aug 31, 2017 at 10:46 AM, Stephan Grein <stephan.grein@...5733...> wrote:
Dear LAMMPS users,
dear Steve and Axel,

I'm following up on this old post on the list.
Trying to get all coordinates for a given
type, e.g. 2, I put this in my LAMMPS script:

group MYGRP type 2
variable MYCOORDS atom x
variable MYCOUNT equal count(MYGRP)

Using the functions from library.cpp by

double* pnatoms = (double*) lammps_extract_variable(lmp, "MYCOUNT", NULL);
                                                                                                int natoms = (int)(*pnatoms);
                                                                                                                                                                double* coords = (double*)
lammps_extract_variable(lmp, "MYCOORDS", "MYGRP");

However, coords contains only zeros, e.g. 0.0, 0.0, 0.0.
Apparently I'm doing something wrong, but I'm not sure what.

it ​works for me. here is a complete(!) test example based on the "crack" example.

axel.

#include <stdio.h>
#include <inttypes.h>
#include "library.h"

int main (int argc, char **argv)

{
    void *lmp;
    int i,gatoms;
    int64_t natoms;

    lammps_open_no_mpi(0,NULL,&lmp);
    lammps_file(lmp,"in.crack");
    lammps_command(lmp,"group MYGRP type 2");
    lammps_command(lmp,"variable MYCOORDS atom x");
    lammps_command(lmp,"variable MYCOUNT equal count(MYGRP)");

    natoms = *(int64_t *)lammps_extract_global(lmp,"natoms");
    gatoms = (int) *(double *)lammps_extract_variable(lmp, "MYCOUNT", NULL);
    printf("total atoms = %ld  atoms in group = %d\n",natoms,gatoms);
    double *coords = (double *)lammps_extract_variable(lmp,"MYCOORDS","MYGRP");
    for (i=0; i < natoms; ++i) {
        printf("x[%03d]=%10.4f\n",i,coords[i]);
    }
    lammps_free((void *)coords);
    lammps_close(lmp);
    return 0;
}    
 

Maybe somebody can point me in the right direction.

Best regards,
Stephan

Am 13/04/16 um 17:00 schrieb Steve Plimpton:
> Just see the variable doc page for all the syntax.
> My email was just meant to be an idea, not
> all the details of the correct syntax.  Ditto
> for the lib interface function you need to use
> to eval a variable.
>
> Steve
>
> On Tue, Apr 12, 2016 at 9:50 AM, Stephan Grein
> <stephan.grein@...7108.....frankfurt.de
> <mailto:stephan.grein@...7107...uni-frankfurt.de>> wrote:
>
>     Dear Steve,
>
>     thanks so much!
>
>     Am 12/04/16 um 17:27 schrieb Steve Plimpton:
>     > variable equal x x[id][0]
>
>     This sounds interesting.
>     I'm not sure how to define this
>     in my script, sorry!
>
>     Would I do like that:
>     myAtomNameToTrack equal x x[myAtomId][0]
>
>     Then using:
>     lammps_extract_variable(lmp, "myAtomNameToTrack", NULL);
>
>     Right? TIA.
>
>     Best,
>     S.
>
>




--
Dr. Axel Kohlmeyer  akohlmey@...24...  http://goo.gl/1wk0
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.