[CP2K-user] [CP2K:13720] Re: Running CP2K calc with ASE
Hasan Al-Mahayni
hasanal... at gmail.com
Tue Aug 4 17:12:03 UTC 2020
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 <
maxime.cp.... 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 cp... 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/20200804/2181c73c/attachment.htm>
-------------- next part --------------
#imports
import numpy as np
from ase.build import molecule
from ase.calculators.emt import EMT
from ase.optimize import QuasiNewton, LBFGS
from ase.vibrations import Vibrations
from ase.thermochemistry import HarmonicThermo
from ase.calculators.cp2k import CP2K
from ase.io import read
from ase import io
inp= """
! &EXT_RESTART
! RESTART_FILE_NAME cp2k-1.restart
! &END
&GLOBAL
RUN_TYPE GEO_OPT
EXTENDED_FFT_LENGTHS .TRUE. !Get more libraries
FFTW_PLAN_TYPE ESTIMATE !Quick estimate, no runtime measurements.
PREFERRED_FFT_LIBRARY FFTW3 !Preferred library
&TIMINGS SILENT !Specify % of CPUTIME above which the contribution will be inserted in the final timing report
THRESHOLD 1e-08
&END TIMINGS
&END GLOBAL
&MOTION
&GEO_OPT
MAX_ITER 400
OPTIMIZER LBFGS ! Better than LBFGS for small systems!!
MAX_DR 5e-04 !Convergence criterion for the maximum geometry change between the current and the last optimizer iteration.
&END GEO_OPT
&PRINT
&TRAJECTORY
FORMAT XYZ
&END TRAJECTORY
&END PRINT
&CONSTRAINT
&FIXED_ATOMS
COMPONENTS_TO_FIX XYZ
LIST 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
&END FIXED_ATOMS
&END CONSTRAINT
&END MOTION
&FORCE_EVAL
&PRINT
&STRESS_TENSOR
&END STRESS_TENSOR
&END PRINT
&DFT
UKS .TRUE. !Requests a spin-polarized calculation using alpha and beta orbitals, i.e. no spin restriction is applied
CHARGE 0 !Total charge
MULTIPLICITY 1 ! Two times the total spin plus one. 2 is for a doublet for an odd number of electrons
WFN_RESTART_FILE_NAME cp2k-RESTART.kp
&MGRID
NGRIDS 5
RELATIVE_CUTOFF 50
&END MGRID
&QS
EPS_DEFAULT 1.0E-12
METHOD GPW
EXTRAPOLATION USE_GUESS
&END QS
&SCF
EPS_SCF 1.0E-7
SCF_GUESS RESTART !Use the RESTART file as an initial guess (and ATOMIC if not present).
ADDED_MOS 200
CHOLESKY OFF
&OUTER_SCF F
EPS_SCF 1.0E-7
MAX_SCF 50
&END OUTER_SCF
&SMEAR T
METHOD FERMI_DIRAC
ELECTRONIC_TEMPERATURE 3.0000000000000000E+02
&END SMEAR
&MIXING T
METHOD BROYDEN_MIXING
ALPHA 4.0000000000000002E-01
BETA 1.5000000000000000E+00
NMIXING 5
NBUFFER 8
&END MIXING
&END SCF
&XC
FUNCTIONAL_ROUTINE NEW
DENSITY_CUTOFF 1.0e-12
GRADIENT_CUTOFF 1.0e-12
TAU_CUTOFF 1.0e-12
&XC_FUNCTIONAL
&END XC_FUNCTIONAL
&XC_GRID
USE_FINER_GRID .TRUE.
&END XC_GRID
&END XC
&POISSON
POISSON_SOLVER PERIODIC
PERIODIC XYZ
&END POISSON
&KPOINTS
SCHEME MONKHORST-PACK 3 3 1
FULL_GRID .TRUE.
&END KPOINTS
&END DFT
&SUBSYS
&END SUBSYS
&END FORCE_EVAL
"""
slab=io.read('slab.xyz')
slab.set_cell([10.22390,10.22390,30.17390,90,90,120])
slab.set_pbc(True)
slab.set_calculator(CP2K(print_level='MEDIUM',xc='PBE',cutoff=6122.564129652 ,max_scf=100,poisson_solver='none' ,potential_file='GTH_POTENTIALS',inp=inp))
dyn=LBFGS(slab,trajectory='slab.traj', restart='restart.pckl')
dyn.run(fmax=0.005)
print('Energy is ' , slab.get_potential_energy())
More information about the CP2K-user
mailing list