Getting cp2k to work with ASE

515 views
Skip to first unread message

Hasan Al-Mahayni

unread,
May 21, 2020, 4:08:39 PM5/21/20
to cp2k
Hi all,

I am just starting to use ASE, and I was wondering if anyone had already made CP2K work with ASE because I could not. These are the steps i took (after installing ASE): 

I included this on top of my ASE code:
    from ase.calculators.cp2k import CP2K

Then I did the following command  :
    export ASE_CP2K_COMMAND="ssh your-compute-host.com \"mpirun -np 2 /path/to/cp2k_shell.popt\""

When I run a simple calculation on H2O with ASE, i get this error:

AssertionError
/home/hasan99/.local/lib/python3.7/site-packages/ase/calculators/cp2k.py:486: RuntimeWarning: CP2K-shell not ready, sending SIGTERM.
  warn("CP2K-shell not ready, sending SIGTERM.", RuntimeWarning)




Any thoughts? 

Thank you,

Hasan.


Maxime Van den Bossche

unread,
May 22, 2020, 5:35:42 AM5/22/20
to cp2k
Dear Hasan,

Are you using OpenMPI? If so, you may try the "-mca btl ^openib" option, i.e.:

mpirun -np 2 -mca btl ^openib cp2k_shell.popt 

That's something I need to do get the ASE interface to work. It might also be prudent to first
check that it works via a regular session on your remote machine, before trying via SSH.

Best,
Maxime

Hasan Al-Mahayni

unread,
May 23, 2020, 2:46:19 PM5/23/20
to cp...@googlegroups.com
Dear Maxime,

Thank you for your answer. I am really new to this.  The line of code you sent me; should it be written in the submission file or the ASE python code? Also, yes, I do use OpenMPI.

Thanks,

Hasan. 

--
You received this message because you are subscribed to the Google Groups "cp2k" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cp2k+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cp2k/b76cb734-0ac5-47f8-b10f-dee1a6aeac50%40googlegroups.com.

Maxime Van den Bossche

unread,
May 26, 2020, 1:03:32 AM5/26/20
to cp2k
OK, let's take it from the beginning -- after logging in to your remote machine
(which needs to have ASE and CP2K installed), please try the example
shown on https://www.cp2k.org/tools:ase, substituting the /path/to/cp2k_shell.popt
with the actual path to that executable on your machine:

export ASE_CP2K_COMMAND="mpirun -np 2 /path/to/cp2k_shell.popt"
python
>>> from ase.calculators.cp2k import CP2K
>>> from ase.build import molecule
>>> calc = CP2K()
>>> atoms = molecule('H2O', calculator=calc)
>>> atoms.center(vacuum=2.0)
>>> print(atoms.get_potential_energy())

If this raises an AssertionError like the one you got earlier, then try to exclude that openib component in OpenMPI:

export ASE_CP2K_COMMAND="mpirun -np 2 -mca btl ^openib /path/to/cp2k_shell.popt"

and try the python commands again.

Hasan Al-Mahayni

unread,
May 26, 2020, 1:08:37 AM5/26/20
to cp...@googlegroups.com
Hello,

Firstly, thank you for taking the time to help me! I have been trying to run the cp2k example that you showed me actually, but I can't seem to find that path "path/to/cp2k_shell.popt"; is it the cp2k.py file that is in ase.calculators? 

--
You received this message because you are subscribed to the Google Groups "cp2k" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cp2k+uns...@googlegroups.com.

Yuvam Bhateja

unread,
May 26, 2020, 1:09:05 AM5/26/20
to cp...@googlegroups.com
Sir,
I wanted to link cp2k with ase too. But I want to use the GPU of google colab.

How can I do that to accelerate my calculation using the GPU?

Regards
Yuvam Bhateja

--
You received this message because you are subscribed to the Google Groups "cp2k" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cp2k+uns...@googlegroups.com.

Maxime Van den Bossche

unread,
May 26, 2020, 5:16:29 AM5/26/20
to cp2k
@Hasan: you need to replace "/path/to/cp2k_shell.popt" with the actual path
to the cp2k_shell.popt executable on your (remote) machine. That path depends
on how CP2K was installed. If you compiled CP2K yourself, just look in the "exe"
directory of your main CP2K folder, as described here: https://www.cp2k.org/howto:compile
If you didn't compile CP2K yourself, ask your system administrator.

@Yuvam: ASE just provides a Python framework/interface; if you want GPU
acceleration in CP2K you first need to compile with CUDA support:
For GPU/CUDA-specific questions, however, better start a separate thread.

Hasan Al-Mahayni

unread,
May 26, 2020, 2:06:41 PM5/26/20
to cp...@googlegroups.com
Hi again,

So the path seems to be this 


So i did this command, then i ran the python commands


And it gave me the same error, so i did this:

export ASE_CP2K_COMMAND="mpirun -np 2 -mca btl ^openib /cvmfs/soft.computecanada.ca/easybuild/modules/2017/avx512/MPI/intel2018.3/openmpi3.1/cp2k/4.1.lua"

And then the python commands, gives me the same error "Assertion error"...




--
You received this message because you are subscribed to the Google Groups "cp2k" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cp2k+uns...@googlegroups.com.

Hasan Al-Mahayni

unread,
May 26, 2020, 2:09:24 PM5/26/20
to cp...@googlegroups.com
The error is this:

Traceback (most recent call last):
  File "run.py", line 6, in <module>
    calc = CP2K()
  File "/home/hasan99/.local/lib/python3.7/site-packages/ase/calculators/cp2k.py", line 180, in __init__
    self._shell = Cp2kShell(self.command, self._debug)
  File "/home/hasan99/.local/lib/python3.7/site-packages/ase/calculators/cp2k.py", line 454, in __init__
    assert 'cp2k_shell' in command

AssertionError
/home/hasan99/.local/lib/python3.7/site-packages/ase/calculators/cp2k.py:486: RuntimeWarning: CP2K-shell not ready, sending SIGTERM.
  warn("CP2K-shell not ready, sending SIGTERM.", RuntimeWarning)
Exception ignored in: <function Cp2kShell.__del__ at 0x7f885d5145f0>
Traceback (most recent call last):
  File "/home/hasan99/.local/lib/python3.7/site-packages/ase/calculators/cp2k.py", line 487, in __del__
    self._child.terminate()
AttributeError: 'NoneType' object has no attribute 'terminate'
Message has been deleted

Hasan Al-Mahayni

unread,
May 27, 2020, 1:52:12 AM5/27/20
to cp...@googlegroups.com
Hi Travis and thanks for the answer, 

I opened the module file it looks like this :

help([==[

Description
===========
CP2K is a freely available (GPL) program, written in Fortran 95, to perform atomistic and molecular
simulations of solid state, liquid, molecular and biological systems. It provides a general framework for different
methods such as e.g. density functional theory (DFT) using a mixed Gaussian and plane waves approach (GPW), and
classical pair and many-body potentials.


More information
================
- Homepage: http://www.cp2k.org/
]==])

whatis([==[Description: CP2K is a freely available (GPL) program, written in Fortran 95, to perform atomistic and molecular
simulations of solid state, liquid, molecular and biological systems. It provides a general framework for different
methods such as e.g. density functional theory (DFT) using a mixed Gaussian and plane waves approach (GPW), and
classical pair and many-body potentials. ]==])
whatis([==[Homepage: http://www.cp2k.org/]==])

local root = "/cvmfs/soft.computecanada.ca/easybuild/software/2017/avx512/MPI/intel2018.3/openmpi3.1/cp2k/4.1"

conflict("cp2k")

depends_on("imkl/2018.3.222")

prepend_path("PATH", pathJoin(root, "bin"))
setenv("EBROOTCP2K", root)
setenv("EBVERSIONCP2K", "4.1")
setenv("EBDEVELCP2K", pathJoin(root, "easybuild/avx512-MPI-intel2018.3-openmpi3.1-cp2k-4.1-easybuild-devel"))

setenv("CP2K_DATA_DIR", "/cvmfs/soft.computecanada.ca/easybuild/software/2017/avx512/MPI/intel2018.3/openmpi3.1/cp2k/4.1/data")
-- Built with EasyBuild version 3.7.0


Is the path to the executable ("local root') :

Because i tried that, and it did not work...

On Tue, May 26, 2020 at 4:24 PM Travis <polla...@gmail.com> wrote:
Hi,

This looks like you're giving a path to a module file, not the cp2k executable. If you open that module file in a text editor it should tell you the actual path to the executable.

-T


--
You received this message because you are subscribed to the Google Groups "cp2k" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cp2k+uns...@googlegroups.com.

Maxime Van den Bossche

unread,
May 27, 2020, 8:03:21 AM5/27/20
to cp2k
Hi Hasan -- that "/cvmfs/....../cp2k/4.1" path is CP2K's "root" directory.
The CP2K binaries will be in the "bin" subdirectory of that folder.

But after you "module load" this module, you will see that this "....../bin"
directory will have been added to your $PATH, and so you can just set:

export ASE_CP2K_COMMAND="mpirun -np 2 -mca btl ^openib cp2k_shell.popt"

(assuming that there is indeed a "cp2k_shell.popt" executable
in that "/cvmfs/....../cp2k/4.1/bin" folder)

Hasan Al-Mahayni

unread,
May 27, 2020, 10:54:53 AM5/27/20
to cp...@googlegroups.com
Thank you for your reply, 

It finally worked. However if i submit it through a job on my cluster (on the queue), I get the same assertion error... I will look into that with the support team I guess. 



--
You received this message because you are subscribed to the Google Groups "cp2k" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cp2k+uns...@googlegroups.com.

Sarah-K

unread,
Jun 4, 2021, 10:46:12 AM6/4/21
to cp2k
Hi,

Are you using CP2K on compute canada? If yes, I have some questions regarding the run script and I'd appreciate it if you could share some of your experience on submitting CP2K jobs on CC.

Best,
Sarah
Reply all
Reply to author
Forward
0 new messages