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: Stephan Grein <stephan.grein@...5733...>
Date: Sat, 2 Sep 2017 01:14:58 +0200

Dear Axel,

thanks for your excellent help!

I used gatoms in the for loop, not natoms.
Now the question is, how could I get only
the x coord of the three atoms in the group
without checking for inequality with 0.0?

Best regards,
Stephan

Am 02/09/17 um 00:20 schrieb Axel Kohlmeyer:
> 
> 
> On Fri, Sep 1, 2017 at 5:38 PM, Stephan Grein
> <stephan.grein@...5733...
> <mailto:stephan.grein@...5733...>> wrote:
> 
>     Dear Axel,
> 
>     thanks for the example.
>     I'm using the lammps stable branch.
> 
>     When I run your code with my LAMMPS
>     input script, again, I'm getting only zeros.
> 
> 
> ​are you sure you don't miss the real data. how many atoms are in the
> selected group?
> perhaps you should prefix the test print​, so it prints out only the
> non-zero numbers, e.g. like this:
> 
>     for (i=0; i < natoms; ++i) {
>         if (coords[i] != 0.0)
>             printf("x[%03d]=%10.4f\n",i,coords[i]);
>     }
> 
> i've taken your input and then used the data file from the LAMMPS
> peptide example, and i get - with the modification from above - the
> following output.
> 
> 
> LAMMPS (17 Aug 2017)
> OMP_NUM_THREADS environment is not set. Defaulting to 1 thread.
> (../comm.cpp:90)
>   using 1 OpenMP thread(s) per MPI task
> Reading data file ...
>   orthogonal box = (36.8402 41.0137 29.7681) to (64.2116 68.3851 57.1395)
>   1 by 1 by 1 MPI processor grid
>   reading atoms ...
>   2004 atoms
>   reading velocities ...
>   2004 velocities
>   scanning bonds ...
>   3 = max bonds/atom
>   scanning angles ...
>   6 = max angles/atom
>   scanning dihedrals ...
>   14 = max dihedrals/atom
>   scanning impropers ...
>   1 = max impropers/atom
>   reading bonds ...
>   1365 bonds
>   reading angles ...
>   786 angles
>   reading dihedrals ...
>   207 dihedrals
>   reading impropers ...
>   12 impropers
> Finding 1-2 1-3 1-4 neighbors ...
>   special bond factors lj:   0          0          0         
>   special bond factors coul: 0          0          0         
>   4 = max # of 1-2 neighbors
>   7 = max # of 1-3 neighbors
>   14 = max # of 1-4 neighbors
>   18 = max # of special neighbors
> 3 atoms in group NTGRP
> 3 atoms in group MYGRP
> total atoms = 2004  atoms in group = 3
> x[001]=   45.1039
> x[068]=   47.7078
> x[079]=   49.3779
> Total wall time: 0:00:00
> 
> this looks perfectly alright to me. 3 atoms in the group -> 3 non-zero
> x-coordinates in the variable.
> 
> axel.
> 
>  
> 
> 
>     I suspect maybe that my input script is wrong,
>     thus I'm attaching it here:
> 
>     units           real
>     neigh_modify    delay 2 every 1
> 
>     atom_style      full
>     bond_style      harmonic
>     angle_style     charmm
>     dihedral_style  charmm
>     improper_style  harmonic
> 
>     pair_style      lj/charmm/coul/long 8 10
>     pair_modify     mix arithmetic
>     kspace_style    pppm 1e-4
> 
>     read_data       protein.data
> 
>     special_bonds   charmm
>     fix             1 all nve
>     velocity        all create 0.0 1504301625 dist uniform
> 
>     thermo          1
>     thermo_style    multi
>     timestep        0.005
> 
>     dump            1 all atom 10 protein.dump
>     dump_modify     1 image yes scale yes
>     group           NTGRP type 2
>     variable        NT atom x
>     variable        NTCOUNT equal count(NTGRP)
> 
>     Is there anything fishy here?
>     Thanks in advance.
> 
>     Best regards,
>     Stephan
> 
> 
>     Am 01/09/17 um 03:46 schrieb Axel Kohlmeyer:
>     >
>     >
>     > On Thu, Aug 31, 2017 at 10:46 AM, Stephan Grein
>     > <stephan.grein@...5733...
>     <mailto:stephan.grein@...5733...>
>     > <mailto:stephan.grein@...5733...
>     <mailto: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@...5733...
>     <mailto:stephan.grein@...5733...>
>     >     <mailto:stephan.grein@...5733...
>     <mailto:stephan.grein@...5733...>>
>     >     > <mailto:stephan.grein@...5733...
>     <mailto:stephan.grein@...5733...>
>     >     <mailto:stephan.grein@...5733...
>     <mailto:stephan.grein@...5733...>>>> 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... <mailto:akohlmey@...29....>
>     <mailto:akohlmey@...24... <mailto:akohlmey@...24...>>
>     >  http://goo.gl/1wk0
>     > College of Science & Technology, Temple University, Philadelphia
>     PA, USA
>     > International Centre for Theoretical Physics, Trieste. Italy.
> 
> 
> 
> 
> 
> -- 
> Dr. Axel Kohlmeyer  akohlmey@...24... <mailto:akohlmey@...24...>
>  http://goo.gl/1wk0
> College of Science & Technology, Temple University, Philadelphia PA, USA
> International Centre for Theoretical Physics, Trieste. Italy.


Attachment: signature.asc
Description: OpenPGP digital signature