From aa3f4b76905bb014516b960bd2b68161d57ce2a9 Mon Sep 17 00:00:00 2001
From: Axel Kohlmeyer <akohlmey@gmail.com>
Date: Thu, 29 Jun 2017 16:09:23 -0400
Subject: [PATCH] change the handling of reading "extra XXX per atom", so that
 the final choice is the larger of the value in the file and the keyword

---
 src/read_data.cpp | 20 +++++++++++++++-----
 src/read_data.h   | 16 ++++++++--------
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/read_data.cpp b/src/read_data.cpp
index e44c6b7417..b1a42608c0 100644
--- a/src/read_data.cpp
+++ b/src/read_data.cpp
@@ -968,6 +968,7 @@ void ReadData::header(int firstpass)
     // search line for header keyword and set corresponding variable
     // customize for new header lines
     // check for triangles before angles so "triangles" not matched as "angles"
+    int extra_flag_value = 0;
 
     if (strstr(line,"atoms")) {
       sscanf(line,BIGINT_FORMAT,&natoms);
@@ -1029,17 +1030,26 @@ void ReadData::header(int firstpass)
         atom->nimpropertypes = nimpropertypes + extra_improper_types;
 
     // these settings only used by first data file
+    // also, these are obsolescent. we parse them to maintain backward
+    // compatibility, but the recommended way is to set them via keywords
+    // in the LAMMPS input file. In case these flags are set in both,
+    // the input and the data file, we use the larger of the two.
 
     } else if (strstr(line,"extra bond per atom")) {
-      if (addflag == NONE) sscanf(line,"%d",&atom->extra_bond_per_atom);
+      if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
+      atom->extra_bond_per_atom = MAX(atom->extra_bond_per_atom,extra_flag_value);
     } else if (strstr(line,"extra angle per atom")) {
-      if (addflag == NONE) sscanf(line,"%d",&atom->extra_angle_per_atom);
+      if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
+      atom->extra_angle_per_atom = MAX(atom->extra_angle_per_atom,extra_flag_value);
     } else if (strstr(line,"extra dihedral per atom")) {
-      if (addflag == NONE) sscanf(line,"%d",&atom->extra_dihedral_per_atom);
+      if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
+      atom->extra_dihedral_per_atom = MAX(atom->extra_dihedral_per_atom,extra_flag_value);
     } else if (strstr(line,"extra improper per atom")) {
-      if (addflag == NONE) sscanf(line,"%d",&atom->extra_improper_per_atom);
+      if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
+      atom->extra_improper_per_atom = MAX(atom->extra_improper_per_atom,extra_flag_value);
     } else if (strstr(line,"extra special per atom")) {
-      if (addflag == NONE) sscanf(line,"%d",&force->special_extra);
+      if (addflag == NONE) sscanf(line,"%d",&extra_flag_value);
+      force->special_extra = MAX(force->special_extra,extra_flag_value);
 
     // local copy of box info
     // so can treat differently for first vs subsequent data files
diff --git a/src/read_data.h b/src/read_data.h
index 5463c86f08..5f83b78c61 100644
--- a/src/read_data.h
+++ b/src/read_data.h
@@ -472,8 +472,8 @@ outside a non-periodic simulation box.
 
 E: Subsequent read data induced too many bonds per atom
 
-See the create_box extra/bond/per/atom or read_data "extra bond per
-atom" header value to set this limit larger.
+See the create_box extra/bond/per/atom or the read_data
+extra/bond/per/atom keyword to set this limit larger.
 
 E: Bonds assigned incorrectly
 
@@ -482,8 +482,8 @@ This means there is something invalid about the topology definitions.
 
 E: Subsequent read data induced too many angles per atom
 
-See the create_box extra/angle/per/atom or read_data "extra angle per
-atom" header value to set this limit larger.
+See the create_box extra/angle/per/atom or the read_data
+extra/angle/per/atom keyword to set this limit larger.
 
 E: Angles assigned incorrectly
 
@@ -493,8 +493,8 @@ definitions.
 
 E: Subsequent read data induced too many dihedrals per atom
 
-See the create_box extra/dihedral/per/atom or read_data "extra
-dihedral per atom" header value to set this limit larger.
+See the create_box extra/dihedral/per/atom or the read_data
+extra/dihedral/per/atom keyword to set this limit larger.
 
 E: Dihedrals assigned incorrectly
 
@@ -504,8 +504,8 @@ definitions.
 
 E: Subsequent read data induced too many impropers per atom
 
-See the create_box extra/improper/per/atom or read_data "extra
-improper per atom" header value to set this limit larger.
+See the create_box extra/improper/per/atom or the read_data
+extra/improper/per/atom keyword to set this limit larger.
 
 E: Impropers assigned incorrectly
 
-- 
GitLab