[CP2K-user] [CP2K:13720] Re: Running CP2K calc with ASE

Sun Geng gengs... at gmail.com
Tue Aug 18 16:05:43 UTC 2020


Hi Aniruddha M Dive,
Below is the code that I changed a few lines in cp2k_shell.F and ase-cp2k 
calculator. ( You will see the lines I commented out)
Please note that the code is only tested wit cp2k-v6.1 (I found the most 
recent cp2k code revised cp2k_shell.F significantly).
The idea is that the python code will write a file " CP2K_POSITIONS" with 
coordinates instead of writing them into PIPE, 
and cp2k_shell will read the positions from the file instead of the PIPE.
Best,
Geng


        IF (para_env%mepos==para_env%source) THEN
           !READ (*,*,iostat=iostat) n_atom2
           !IF (iostat/=0) CPABORT('setpos read n_atom')
           !IF (n_atom2/=SIZE(pos)) THEN
           !   CALL my_assert(.FALSE.,'setpos invalid number of 
atoms',failure)
           !   DO i=1,n_atom
           !      READ(*,'(a)',iostat=iostat) cmdStr
           !      CALL compress(cmdStr,full=.TRUE.)
           !      CALL uppercase(cmdStr)
           !      IF (cmdStr=='*END') EXIT
           !   END DO
           !   GOTO 10
           !END IF
           !READ (*,*,iostat=iostat) pos
           !IF (iostat/=0) CPABORT('setpos read coord')
           inquire(unit=201,opened=unitalive)
           if (unitalive) CPABORT('UNIT 201 is being used')
           inquire(file="CP2K_POSITIONS",exist=filepresence)
           if (.not. filepresence) CPABORT('FILE CP2K_POSITIONS NOT EXIST')
           
open(201,action='READ',file="CP2K_POSITIONS",iostat=iostat,status='OLD',form='FORMATTED',ACCESS='SEQUENTIAL')
           if (iostat/=0) CPABORT('read CP2K_POSITIONS')
           READ(201,*,iostat=iostat) n_atom2
           IF (iostat/=0) CPABORT('setpos read n_atom2')
           IF (n_atom2/=SIZE(pos)) THEN
              CALL my_assert(.FALSE.,'setpos invalid number of 
atoms',failure)
              DO i=1,n_atom
                 READ(201,'(a)',iostat=iostat) cmdStr
                 CALL compress(cmdStr,full=.TRUE.)
                 CALL uppercase(cmdStr)
                 IF (cmdStr=='*END') EXIT
              END DO
              GOTO 10
           END IF
           READ (201,*,iostat=iostat) pos
           CLOSE(201)
           IF (iostat/=0) CPABORT('setpos read coord')
           pos(:) = pos(:)/pos_fact
           READ(*,'(a)',iostat=iostat) cmdStr
           CALL compress(cmdStr,full=.TRUE.)
           CALL uppercase(cmdStr)
           CALL my_assert(cmdStr=='*END',' missing *END',failure)
        END IF


---changes in ase cp2k calcualtor -----
        if 'positions' in system_changes:
            with open("CP2K_POSITIONS","w") as fp:
                fp.write("%d\n" % (3*n_atoms))
                for pos in self.atoms.get_positions():
                    fp.write('%.18e %.18e %.18e\n' % tuple(pos))
            self._shell.send('SET_POS %d' % self._force_env_id)
            #self._shell.send('%d' % (3 * n_atoms))
            #for pos in self.atoms.get_positions():
            #    self._shell.send('%.18e %.18e %.18e' % tuple(pos))
            self._shell.send('*END')
            max_change = float(self._shell.recv())
            assert max_change >= 0 # sanity check
            self._shell.expect('* READY')
            if os.path.isfile("CP2K_POSITIONS"):
                os.remove("CP2K_POSITIONS")

在2020年8月17日星期一 UTC-7 下午4:42:29<ani... at gmail.com> 写道:

> Thanks Geng,
>
> I went through your earlier post regarding the same issue. Can you send me 
> the respective cp2k_shell.F file that works for you. I would like to 
> incorporate it and check.
>
> Also can you send me the python script you used as well.
>
> Best Regards,
> Aniruddha M Dive
>
>
> On Monday, August 17, 2020 at 7:44:08 AM UTC-7, Sun Geng wrote:
>>
>> Dear Aniruddha,
>>
>> Sometimes ago, I have encountered a similar problem,
>> I think the reason is that the python code communicates positions/forces 
>> with the mpi cp2k_shell.popt. 
>> There is a problem when MPI code read the pipe: the MPI code will only 
>> read truncated data  (such as positions) from the pipe, not all of them.
>> So CP2K_shell.popt is still waiting for more coordinates and gets stuck.
>>
>> Best,
>> Geng
>>
>>
>>
>> 在2020年8月13日星期四 UTC-7 下午1:20:17<ani... at gmail.com> 写道:
>>
>>> Thanks Hasan,
>>>
>>> I was able to get the Cp2K working. However I face another issue. The 
>>> simulation runs well for few steps and after that I cannot see my output 
>>> file being updated. The simulation shows running however I am not able to 
>>> see any output being updated in the cp2k output file as well as the slurm 
>>> output file. I have attached my job submission script, python script as 
>>> well as the out files for reference. Could this be a memory issue? 
>>>
>>> Best,
>>> Aniruddha M Dive
>>>
>>>
>>> On Tuesday, August 4, 2020 at 10:12:17 AM UTC-7, Hasan Al-Mahayni wrote:
>>>
>>>> Hello,
>>>>
>>>> I had similar problems starting CP2K with ASE earlier this summer. I 
>>>> will attach an example of geometric optimization for a slab, I hope it 
>>>> helps. You need to copy paste a large portion of your cp2k input file in 
>>>> your python script, because ASE does not provide all the input parameters 
>>>> you will need to perform geo_opt. Please find an example attached below.
>>>>
>>>> Cheers,
>>>>
>>>> Hasan.
>>>>
>>>> On Tue, Aug 4, 2020 at 1:16 AM Maxime Van den Bossche <
>>>> maxi... at gmail.com> wrote:
>>>>
>>> Dear Aniruddha,
>>>>>
>>>>> Since you haven't provided a minimal example, nor the error message 
>>>>> you're getting
>>>>> from ASE or CP2K, I haven't looked into debugging the (bulky) example 
>>>>> you sent.
>>>>>
>>>>> But I don't think you can do the geometry optimization in this way. 
>>>>> ASE uses the cp2k_shell binary,
>>>>> which seems to only perform single-point calculations but not e.g. 
>>>>> geometry optimizations.
>>>>>
>>>>> The idea behind cp2k_shell is that the 'driver' (in this case ASE) is 
>>>>> the one moving the atoms
>>>>> around, and what CP2K does is e.g. calculating the energy and the 
>>>>> gradients for a given geometry.
>>>>>
>>>>> Here is a minimal example of a geometry optimization, and you can work 
>>>>> your way up
>>>>> from there:
>>>>>
>>>>> from ase.build import molecule
>>>>> from ase.calculators.cp2k import CP2K
>>>>> from ase.optimize import BFGS
>>>>>
>>>>> atoms = molecule('H2O')
>>>>> atoms.center(vacuum=2.0)
>>>>>
>>>>> calc = CP2K(command='cp2k_shell.sopt')
>>>>> atoms.set_calculator(calc)
>>>>>
>>>>> dyn = BFGS(atoms)
>>>>> dyn.run(fmax=0.05)
>>>>>
>>>>> Best regards,
>>>>> Maxime
>>>>>
>>>>> -- 
>>>>> 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 c... at googlegroups.com.
>>>>
>>>>
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/cp2k/df050a2d-1161-4e2c-98c9-0463adcb4c3do%40googlegroups.com 
>>>>> <https://groups.google.com/d/msgid/cp2k/df050a2d-1161-4e2c-98c9-0463adcb4c3do%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cp2k.org/archives/cp2k-user/attachments/20200818/5ae539b1/attachment.htm>


More information about the CP2K-user mailing list