Segmentation error

in.square (1.6 KB)
data.box (149.4 KB)
data.box3 (168.1 KB)

Hello there,

I am trying to use add molecules on the existing molecules by using read.data.

read_data data.box3 add merge shift 0 500 0 fix molprop2 NULL Molecules

This gives ‘segmentation fault’ error.
Could you help to me to figure out the issue and how can I solve this problem?

data.box3 (151.2 KB)

One of attachment was wrong. This is the one I am using.

I would not use fix property/atom but rather atom_style hybrid sphere bond to introduce molecule IDs. That is a more commonly used path. Reading data for fixes from a data file is by construction rather fragile and I doubt that anybody has ever tested it with read_data_add.

There is another serious problem in your input. Have you noticed this line in the log file?

WARNING: One or more atoms are time integrated more than once (src/modify.cpp:292)

In most cases, this is an indication of a serious problem. The situations where it can be ignored are extremely rare (the fact they do exist is the reason that this is not an error).

Thank you a lot!
I have ignored the warning part, but I just fixed it.

@Dseo
I’ve dug a bit deeper into the code for reading data file sections from fix files and could identify and work around the bug that exists when using read_data add and causes a segmentation fault.

The following change (relative to the current development branch) should resolve it. I will be included in the next patch release of LAMMPS.

  diff --git a/src/fix_property_atom.cpp b/src/fix_property_atom.cpp
  index 24704a12ad..95e25c59b2 100644
  --- a/src/fix_property_atom.cpp
  +++ b/src/fix_property_atom.cpp
  @@ -325,12 +325,12 @@ void FixPropertyAtom::read_data_section(char *keyword, int n, char *buf, tagint
   }
   
   /* ----------------------------------------------------------------------
  -   return # of lines in section of data file labeled by keyword
  +   return # of lines in section of data file labeled by keyword. -1 signals use # of added atoms
   ------------------------------------------------------------------------- */
   
   bigint FixPropertyAtom::read_data_skip_lines(char * /*keyword*/)
   {
  -  return atom->natoms;
  +  return -1;
   }
   
   /* ----------------------------------------------------------------------
  diff --git a/src/read_data.cpp b/src/read_data.cpp
  index ee6399a2d3..5317a4217a 100644
  --- a/src/read_data.cpp
  +++ b/src/read_data.cpp
  @@ -875,10 +875,13 @@ void ReadData::command(int narg, char **arg)
           int i;
           for (i = 0; i < nfix; i++)
             if (strcmp(keyword, fix_section[i]) == 0) {
  -            if (firstpass)
  +            if (firstpass) {
                 fix(fix_index[i], keyword);
  -            else
  -              skip_lines(fix_index[i]->read_data_skip_lines(keyword));
  +            } else {
  +              auto nskip = fix_index[i]->read_data_skip_lines(keyword);
  +              if (nskip < 0) nskip = natoms;
  +              skip_lines(nskip);
  +            }
               break;
             }
           if (i == nfix)
  @@ -2225,6 +2228,7 @@ void ReadData::fix(Fix *ifix, char *keyword)
     int nchunk, eof;
   
     bigint nline = ifix->read_data_skip_lines(keyword);
  +  if (nline < 0) nline = natoms;
   
     bigint nread = 0;
     while (nread < nline) {

It works! Thank you so much!