Inconsistency in how "pair_style hybrid" reports errors

Dear users and developers,

The inconsistency in error reporting of "pair_style hybrid" is as
follows. Suppose we use a "pair_style hybrid" command with 2 pair
styles. Then, if there is a typo in the name of the 2nd pair style,
the error message that would be issued by LAMMPS on an attempt to run
such a script would misleadingly indicate that there is a problem with
the 1st of the two pair styles.

In general, if there are more than 2 pair styles defined in
"pair_style hybrid" command, and if there is a typo in the name of the
i-th pair style, then the error message would mark the (i-1)-th pair
style as the one causing a problem.

Here are some test cases (I'm attaching the complete files; they are
based on the in.lj file from /bench directory). I tested them on the
latest version of LAMMPS (1 Jul 2013).

1. Notice a typo in the 2nd pair style (it should read coul/cut):
...
pair_style hybrid/overlay lj/cut 2.5 coul/cu 2.5 lj/cut/coul/cut 2.5
pair_coeff 1 1 lj/cut 1.0 1.0 2.5
pair_coeff 1 1 coul/cut 2.5
pair_coeff 1 1 lj/cut/coul/cut 1.0 1.0 2.5
...
The error message for the above case is pointing to the 1st pair style:
ERROR: Illegal pair_style command (../pair_lj_cut.cpp:430)

2. Now the typo is in the 3rd pair style
...
pair_style hybrid/overlay lj/cut 2.5 coul/cut 2.5 lj/cut/cou/cut 2.5
pair_coeff 1 1 lj/cut 1.0 1.0 2.5
pair_coeff 1 1 coul/cut 2.5
pair_coeff 1 1 lj/cut/coul/cut 1.0 1.0 2.5
...
The error message is pointing to the 2nd pair style, instead of the 3rd.
ERROR: Illegal pair_style command (../pair_coul_cut.cpp:149).

Of course, one has to be careful when creating an input script, but an
appropriate error message may save him from spending several hours
trying to figure out what is wrong with the settings or with the
source code of a correctly specified/implemented pair style.

I hope someone of the main developers can find some time to look into
the above problem.

Best regards,
Pavel

in.lj-typo-in-2nd-pair-style (633 Bytes)

in.lj-typo-in-3rd-pair-style (634 Bytes)

In general, if there are more than 2 pair styles defined in
"pair_style hybrid" command, and if there is a typo in the name of the
i-th pair style, then the error message would mark the (i-1)-th pair
style as the one causing a problem.

dear pavel,

this is a problem, that cannot be easily solved without changing the
syntax of pair_style hybrid and introduce a "separation character"
that tells LAMMPS where one pair style starts and where the next ends.

right now LAMMPS splits the command line based on which words are
recognized as a pair style, which leads to the scenario you describe
that in case of a typo the pair style will be added as a keyword to
the previous style.

to illustrate what i mean, here is a hypothetical example:

pair_style hybrid/overlay {lj/cut 2.5 } {coul/cu 2.5}
{lj/cut/coul/cut 2.5}

and here another, simpler possibility:

pair_style hybrid/overlay lj/cut 2.5 | coul/cu 2.5 | lj/cut/coul/cut 2.5

or another variant:

pair_style hybrid/overlay 1: lj/cut 2.5 2: coul/cu 2.5 3:
lj/cut/coul/cut 2.5

this one would have the benefit to refer to the individual pair styles
via numbers for the pair_coeff statements and make the disambiguation
simpler in case of having multiple instanced of the same pair style as
substyles.

i suppose that each option (or a combination of them) could be
implemented with moderate effort and would likely make the parser code
simpler. it also would break backward compatibility. so it all boils
down to convincing steve that this is a change worth implementing and
dealing with people complaining that their inputs don't work anymore.

ciao,
    axel.