read_data crashes ONLY in python not in lmp executable

Dear all,
I’m facing a problem that I had no luck to track down/debug yet.
When calling lammps via python library I get following error (in log.lammps):
ERROR: Unknown command: 43 (…/input.cpp:315)

I understand that this error should mean that my data file is wrong formatted, but I have no clue why/whats going on. These are my python commands:
from lammps import lammps
lmp_input = “units real \natom_style full \nbond_style harmonic \nangle_style charmm \ndihedral_style charmm \nimproper_style harmonic \npair_style lj/charmm/coul/long 7.5 8.0 \nkspace_style pppm 0.0001 \nboundary p p p \nread_data coord.par \ngroup mobile id 1:70 \nfix 1 mobile nvt temp 300 300 200 tchain 1 \n”
lmp = lammps(cmdargs=["-screen",“none”])
lmp.commands_string(lmp_input)

The strange thing for me is, that if I just place the “lmp_input” into text file as input script (in.lammps) for lammps and run it such as
lmp_g++_mpich < in.lammps

then nothing strange happens.
attached you find the coord.par, in.lammps and lammps.py files.
I tested Nov16 and Mar17 versions, compiled by me, using gcc.

I’ll be happy for any suggestions.
Regards,
stanislav.

coord.par (20.9 KB)

in.lammps (300 Bytes)

lammps.py (425 Bytes)

​yes, i can confirm this issue. it is caused by an incorrect nested use of
the strtok() library call.​
you can avoid it by applying the following ​patch to library.cpp in the 19
May 2017 version of LAMMPS.

axel.

diff --git a/src/library.cpp b/src/library.cpp
index 892818f..e1be5a7 100644
--- a/src/library.cpp
+++ b/src/library.cpp
@@ -277,12 +277,21 @@ void lammps_commands_string(void *ptr, char *str)

   BEGIN_CAPTURE
   {
- char *ptr = strtok(copy,"\n");
- if (ptr) concatenate_lines(ptr);
- while (ptr) {
- lmp->input->one(ptr);
- ptr = strtok(NULL,"\n");
- if (ptr) concatenate_lines(ptr);
+ char *ptr = copy;
+ for (int i=0; i < n-1; ++i) {

Thank you, I just confirm that it works for me.
stanislav.