Error using the lammpsrun calculator in the Python ASE module

I am attempting to connect LAMMPS to the ASE Python module using the LAMMPSRun calculator. While everything seems to be set up correctly, ASE is unable to retrieve thermodynamic data from the LAMMPS log file.

I am using Windows 11, LAMMPS (2 Aug 2023 - Update 4), and the ReaxFF potential for atomic interactions.

When I run my Python script, it creates a tempDir folder containing several files, including in_lammps*, ffield, control, data_lammps*, log_lammps*, and trj_lammps*.bin.

ERROR

Traceback (most recent call last):
  File "D:\hobby\python\ASE\globalOptimization\lmpCalculator.py", line 29, in <module>
    print("Energy ", atoms.get_potential_energy())
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\hobby\python\ASE\globalOptimization\venv\Lib\site-packages\ase\atoms.py", line 755, in get_potential_energy
    energy = self._calc.get_potential_energy(self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\hobby\python\ASE\globalOptimization\venv\Lib\site-packages\ase\calculators\abc.py", line 24, in get_potential_energy
    return self.get_property(name, atoms)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\hobby\python\ASE\globalOptimization\venv\Lib\site-packages\ase\calculators\calculator.py", line 538, in get_property
    self.calculate(atoms, [name], system_changes)
  File "D:\hobby\python\ASE\globalOptimization\venv\Lib\site-packages\ase\calculators\lammpsrun.py", line 250, in calculate
    self.run()
  File "D:\hobby\python\ASE\globalOptimization\venv\Lib\site-packages\ase\calculators\lammpsrun.py", line 419, in run
    raise RuntimeError("Failed to retrieve any thermo_style-output")
RuntimeError: Failed to retrieve any thermo_style-output

PYTHON SCRIPT

import os
os.environ["ASE_LAMMPSRUN_COMMAND"] = r"C:\Program Files\LAMMPS 64-bit 2Aug2023\bin\lmp.exe"
print("ASE_LAMMPSRUN_COMMAND:", os.environ.get("ASE_LAMMPSRUN_COMMAND"))


from ase.io.lammpsdata import read_lammps_data
from ase.calculators.lammpsrun import LAMMPS

parameters = {
    'atom_style': 'charge',
    'units': 'real',
    'pair_style': 'reax/c control checkqeq yes safezone 4.8 mincap 200',
    'pair_coeff': ['* * ffield Ni'],
    'fix': ['fix_qeq_reax all qeq/reax  1 0.0 10.0 1.0e-6 reax/c'],
}

files = ['ffield', 'control']

atoms=read_lammps_data("ni210.dat", sort_by_id=True, units="real", atom_style="charge")

calc=LAMMPS(
    files=files,
    **parameters,
    keep_tmp_files=True,
    tmp_dir="tempDir",
)
atoms.calc=calc
print("Energy ", atoms.get_potential_energy())

MY FOLDERS AND FILES

rasm

in_lammps - input file created by ASE*

clear
variable dump_file string "D:\hobby\python\ASE\globalOptimization\tempDir\trj_lammps000001htmwusct.bin"
variable data_file string "D:\hobby\python\ASE\globalOptimization\tempDir\data_lammps0000017hpp8og_"
atom_style charge 
units real
boundary p p p 
box tilt large 
atom_modify sort 0 0.0 

read_data D:\hobby\python\ASE\globalOptimization\tempDir\data_lammps0000017hpp8og_

### interactions
pair_style reax/c control checkqeq yes safezone 4.8 mincap 200 
pair_coeff * * ffield Ni 
mass 1 58.693400 

### run
fix fix_nve all nve
fix fix_qeq_reax all qeq/reax  1 0.0 10.0 1.0e-6 reax/c
dump dump_all all custom 1 D:\hobby\python\ASE\globalOptimization\tempDir\trj_lammps000001htmwusct.bin id type x y z vx vy vz fx fy fz
thermo_style custom step temp press cpu pxx pyy pzz pxy pxz pyz ke pe etotal vol lx ly lz atoms
thermo_modify flush yes format float %23.16g
thermo 1
run 0
print "__end_of_ase_invoked_calculation__" 
log /dev/stdout

Any suggestions on how to resolve this issue would be greatly appreciated.

@kmehmonov I don’t think this is a LAMMPS issue. For that you have to prove that LAMMPS doesn’t work as intended by itself. Otherwise, you have to discuss with the ASE developers which is why I have re-categorized your post there.

The ASE-LAMMPS interface seems to be entirely file based, which is a bit strange, since LAMMPS has for many years now a well maintained python module, which also includes a mechanism to retrieve thermodynamic data directly without parsing the log file. The latter can be an issue on Windows due to its mechanisms to prohibit access to files opened for writing.

I agree with your opinion. I don’t think the error is related to LAMMPS.
I checked the lammpsrun.py file inside the ASE module. It shows that log data is written to /dev/stdout. However, /dev does not exist in Windows.

    ...
    ase_parameters: Dict[str, Any] = dict(
        specorder=None,
        atorder=True,
        always_triclinic=False,
        reduce_cell=False,
        keep_alive=True,
        keep_tmp_files=False,
        no_data_file=False,
        tmp_dir=None,
        files=[],  # usually contains potential parameters
        verbose=False,
        write_velocities=False,
        binary_dump=True,  # bool - use binary dump files (full
                           # precision but long long ids are casted to
                           # double)
        lammps_options="-echo log -screen none -log /dev/stdout",
        trajectory_out=None,  # file object, if is not None the
                              # trajectory will be saved in it
    )

   ...

If you agree, then why post your topic in the LAMMPS category and not in ASE??

It is my bad. Actually, I wanted to label both categories to get a quicker response to my issue.

Online Forums that are run by volunteers don’t work that way. When posting to the wrong forum and even more when cross-posting you just manage to irritate or even upset people.

I will definitely take your consideration into account in the future. Thank you.