From cdc9712261c2ced95eb1b9597d47b17ce46a635b Mon Sep 17 00:00:00 2001
From: sjplimp <sjplimp@f3b2605a-c512-4ea7-a41b-209d697bcdaa>
Date: Thu, 7 Jul 2016 14:39:49 +0000
Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15270
 f3b2605a-c512-4ea7-a41b-209d697bcdaa

---
 src/molecule.cpp | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/molecule.cpp b/src/molecule.cpp
index 91557b32ba..5e9aa292d0 100644
--- a/src/molecule.cpp
+++ b/src/molecule.cpp
@@ -463,7 +463,8 @@ void Molecule::read(int flag)
 
   // error checks
 
-  if (natoms < 1) error->all(FLERR,"No count or invalid atom count in molecule file");
+  if (natoms < 1) 
+    error->all(FLERR,"No count or invalid atom count in molecule file");
   if (nbonds < 0) error->all(FLERR,"Invalid bond count in molecule file");
   if (nangles < 0) error->all(FLERR,"Invalid angle count in molecule file");
   if (ndihedrals < 0)
@@ -590,13 +591,16 @@ void Molecule::read(int flag)
       error->all(FLERR,"Molecule file has no Body Doubles section");
   }
 
-  // auto-generate special bonds
+  // auto-generate special bonds if needed and not in file
+  // set maxspecial on first pass, so allocate() has a size
 
-  if (bondflag && !specialflag) {
-    specialflag = 1;
-    nspecialflag = 1;
+  if (bondflag && specialflag == 0) {
     maxspecial = atom->maxspecial;
-    if (flag) special_generate();
+    if (flag) {
+      special_generate();
+      specialflag = 1;
+      nspecialflag = 1;
+    }
   }
 
   // body particle must have natom = 1
-- 
GitLab