Python ase-CP2K communication stalls

172 views
Skip to first unread message

Ioachim Dusa

unread,
Jan 2, 2026, 5:27:10 AMJan 2
to cp2k
Dear cp2k community, 

happy new year!

I am having trouble with the calculator implementation of cp2k in ase, which I use for structure relaxation of a system with about 200 atoms. Here, after a few relaxation steps the program freezes, without yielding any errors. In a nutshell I am using the cp2k ase calculator coupled with BFGSLineSearch: (see attached relax.py script)

cp2k_calc = CP2K(

    print_level="LOW",

    debug=True,

    auto_write=True,

    set_pos_file=True,

    basis_set=None,

    inp=cp2k_inp,

    command="srun --cpus-per-task=8 cp2k_shell.psmp",

    max_scf=30,                

    basis_set_file=None,      

    potential_file=None,       

    pseudo_potential=None,    

    xc=None

)


# ATTACH THE CALCULATOR 

ecf = UnitCellFilter(atoms, mask=[1, 1, 0, 0, 0, 1], scalar_pressure=pressure * to_eV_per_A3)

opt = BFGSLineSearch(ecf, trajectory=f"{seed}-opt.traj", logfile=f"{seed}-opt.log")

conv = opt.run(fmax=2e-4, steps=2000)



This yields the log file: 
.....

BFGSLineSearch:   25[ 42] 22:35:49   -11251.564792       0.0208

BFGSLineSearch:   26[ 44] 22:37:14   -11251.564866       0.0243

BFGSLineSearch:   27[ 46] 22:38:34   -11251.564972       0.0113

BFGSLineSearch:   28[ 48] 22:39:57   -11251.564986       0.0129

BFGSLineSearch:   29[ 49] 22:40:49   -11251.565118       0.0148

BFGSLineSearch:   30[ 55] 22:43:39   -11251.565136       0.0148


where at this point the computation freezes. 
At first I thought that the problem might be related to these posts (https://groups.google.com/g/cp2k/c/QJ7AvFvWxio, https://groups.google.com/g/cp2k/c/2C7_YEHFKPg/m/DfUyEZo9AwAJ), where the issues came from the communication of the positions over stdin stdout, which made troubles with the openMPI library. However, as seen above, I am using the set_pos_file option and also the debugging output seems to point out that the program is waiting for the energy to be transferred: 

Writing restart to:  cp2k 

system_changes: ['cell', 'positions']

Sending: UNITS_EV_A

Received: * READY

Sending: SET_CELL 1

Sending: 1.461098823523022006e+01 -4.272432504248221269e-02 0.000000000000000000e+00

Sending: 4.368728107838069918e-02 1.478971208354484723e+01 0.000000000000000000e+00

Sending: 0.000000000000000000e+00 0.000000000000000000e+00 1.500000000000000000e+01

Received: * READY

Sending: SET_POS_FILE cp2k.pos 1

Received: 5.9071093868361E-02

Received: * READY

Sending: EVAL_EF 1

Received: * READY

Sending: GET_E 1


Regarding the cp2k output file (see attached) it is stuck after the SCF convergence at the line 

 Total energy:                               -414.00490349713448


Any help is appreciated, thank you very much! 
Best,
Ioachim
cp2k.out
relax.py
debugging.out

Ioachim Dusa

unread,
Jan 3, 2026, 3:05:40 AMJan 3
to cp2k
In addition to above: I have added to the cp2k.py send function a flush, i.e. : 

        self._child.stdin.write(line + '\n')

        self._child.stdin.flush()


The programme is still stuck, however it is now waiting for the forces to be transferred. 

Sending: GET_E 1

Received: -1.1265646679912E+04

Received: * READY

Sending: GET_F 1


Ioachim Dusa

unread,
Jan 5, 2026, 9:20:05 AMJan 5
to cp2k
To provide further information: I have also built in some printing on the cp2k_shell side yielding 

2026-01-05 12:37:11.335 INFO: GET_E arg1: 1

2026-01-05 12:37:11.335 INFO: env_id=1 (from "1")

2026-01-05 12:37:11.335 OUT: GET_E:   -1.1265646594004E+04

2026-01-05 12:37:11.335 OUT: * READY


However on the python-ase side I obtain: 

Time-py: 2026-01-05 12:37:11.335682 Received: -1.1265646594004E+04

Time-py: 2026-01-05 12:37:11.375882 Received: * READY

Time-py: 2026-01-05 12:37:11.376014 Sending: GET_F 1

Time-py: 2026-01-05 12:37:11.376104 Sending done

Time-py: 2026-01-05 12:37:11.376195 Flushing done


From which I infer that the GET_F command is for sure sent by ase but it never arrives at the cp2k_shell. Does anyone have any idea of how I could proceed and resolve the issue?
Reply all
Reply to author
Forward
0 new messages