cesmix-mit / LAMMPS.jl

MIT License
33 stars 11 forks source link

Macro for wrapping input lines #25

Closed stefanbringuier closed 3 months ago

stefanbringuier commented 2 years ago

Does anyone have some thoughts on a macro to wrap lammps input script lines with command(lmp,line), something along the lines of:

macro command(lmp,lines)
    lmpcmds = quote
        for l in $(lines)
            command($(lmp),l)
        end
    end
    return lmpcmds
end

In particular, say we already have an input script we want to use, so we read it in and wrap it with the macro and then add additional commands when that are needed.

vchuravy commented 2 years ago

Sounds reasonable, do you want to open a PR for this?

stefanbringuier commented 2 years ago

Sounds reasonable, do you want to open a PR for this?

Yep, will work on it.

stefanbringuier commented 2 years ago

Sounds reasonable, do you want to open a PR for this?

Yep, will work on it.

Tried to give this a try but seems there is some async behavior with LMP(), or at least I think this is the issue since its spawning a lammps instance for each command before it fails:

image

Note the same example works fine when using the standard approach, ex, command(lmp,lammps-input-line). The digest(example) function call just formats a string with into a Vector{String} and removes \n and \t etc.

vchuravy commented 3 months ago

command can now parse multiline statements. Maybe that's enough?