variable up11 atom x
variable up111 atom ''v_up11 > 1''
ERROR: Input line quote not followed by white-space (../input.cpp:508)
Last command: variable up111 atom ''v_up11 > 1''
The manual explains: An end quote must be followed by white-space.
But I really don’t understand what this means? I tried all the white-space positions, but failed.
My above settings are consistent with the description in the group command in the manual:
compute 1 all pe/atom
compute 2 all reduce sum c_ one
thermo_ style custom step temp pe c_ two
run 0
variable eatom atom "c_1 > -3.0"
group hienergy variable eatom
When you properly format the input here with triple backquotes (```), you can better see what the problem is.
What originally looks like double quotes isn’t. You probably used cut-n-paste from a web browser or PDF viewer and those tend replace ASCII characters with non-ASCII (most of the time extended UTF-8 characters) to make it look better. Some web pages also use some javascript code with the same purpose and effect. If run with a properly up-to-date version of LAMMPS, you will get a warning like this about it:
WARNING: Detected non-ASCII characters in input. Will try to continue by replacing with ASCII equivalents where known. (src/input.cpp:462)
ERROR: Input line quote not followed by white-space (src/input.cpp:539)
Last command: variable up111 atom ‘‘v_up11 > 1’’
LAMMPS requires ASCII input. This is documented behavior. As you can see, its parser gets confused if you do something different. We have added some code to replace known UTF-8 lookalike characters with their ASCII equivalents, but that cannot be done everywhere, and - as demonstrated here - does not always work, when the number of characters changes.
variable up12 atom “-27.15 < y < -10.86”||“92.31 < y < 108”
This creates the same problem. What’s more, when I use Blockquote, the original English double quotation marks have changed into Chinese double quotation marks.
I had advised you to use triple backquotes (```) for quoting text from inputs.
I am getting tired of having to explain the same things again and again and you complaining about errors that are correctly pointing out mistakes in your input because it violates documented behavior. Before you post another such case, please also provide a reference to the documentation where it explains that this input would be correct.
…and for the last time: please always report your LAMMPS version. I am having the suspicion that part of your problems is due to using an old version of LAMMPS but looking at the documentation for the latest patch release.
variable up11 atom "-27.15 < y < -10.86"||"92.31 < y < 108"
I am using the latest version 2022Jun23.
For my question just now, I have read a lot of contents in the manual, but still can’t find it. Maybe I didn’t read it carefully enough, but I think the manual should remind one of the most likely mistakes in a more obvious position.
This is not a likely mistake. You are the first that I have seen to do this kind of input link and it is - frankly - a bit crazy and illogical. Why not just quote the entire string (and use parenthesis for grouping)? Or leave out the blanks and quotes altogether?
The documentation says at the very beginning of the variable command the syntax is:
variable <name> atom <formula>
I also says that <formula> either must not contain any whitespace or must be enclosed in quotes.
Your line has:
variable <name> atom <quoted formula><logical operator><quoted formula>
That is clearly not allowed syntax. As the error message says, after a quoted string there must be a blank, but your input does not have it. And adding a blank before and after the “||” would still violate the required syntax.
If you would just logically think through what the error messages mean and compare to the documentation, instead of insisting that your input is correct and that LAMMPS is at fault, you would save yourself (and us) a lot of trouble.
Anyway, I have corrected the error about quotation, but I need to make some suggestions.
Instead of pointing out that there should be a white-sapce after the closing quotation mark, why not directly say that you can only use double quotation marks once at most? Either in the error indication or in the lammps manual. It’s hard to find the real problem. At least, when I saw this error, I just added a space after all the closing quotation marks without realizing that I used double quotation marks more than once, which is not allowed by lammps. The reason why I use double quotation marks many times is that I think one more quotation mark is like one more bracket, which has no effect. It is difficult to guarantee that other users will not have similar ideas.
Another point is that the following reference will not generate errors but will generate incorrect values that do not conform to the user’s intentions:
variable a atom "1<y<5"
But variable a atom "1<y&&y<5" is correct. It took me a lot of time to find this, because there were no errors occured. It’s kind of unbelievable, but that’s the truth.
Due to the differences between the lammps rule and the user’s habitual thinking, perhaps the lammps manual can do a better job in explaining the most likely mistakes in the most concise and understandable words in the most obvious places.
This feels like an issue with “the user’s habitual thinking”.
In your second example, “1<y<5” is computed left-to-right: 1<y is either true or false, which evaluates to 1 or 0, respectively. Thus, since 0<5 and 1<5 are both true, the statement is always true. This is the case in many programming languages, including C++, which LAMMPS is based on. Most basic/low-level languages don’t have support for complex logic like you’re trying to write, instead relying on a combination of unary and binary operations.
Likewise, in most programming languages, quotation marks do not act like brackets of any kind, instead converting the contents into a string. This is what LAMMPS does, allowing the formula to be expressed with whitespace, and where the interpreter would otherwise find separate arguments, the formula is treated as a single argument.
Finally, if you feel like you could explain this more concisely/clearly, you can feel free to contribute to the docs or add additional conditions to the error-checking, as LAMMPS is by and large a contributed software.