[Q-e-developers] Pluginization of CP

Paolo Giannozzi p.giannozzi at gmail.com
Wed Oct 7 23:29:01 CEST 2015


Looks fine to me. It would be preferrable to have the same set of environ
routines and of "hooks" for both CP and PW, but this is not going to be
easy.

Dead code and redundant stuff can (should) be removed

Paolo

On Tue, Oct 6, 2015 at 12:12 PM, Oliviero Andreussi <
oliviero.andreussi at usi.ch> wrote:

> Dear QE-developers and, in particular, CP-developers,
>
> I am in the process of interfacing with CP the module we are developing,
> Environ (www.quantum-environment.org), to model environment effects in
> first-principles simulations. I have been following the same strategy
> that was followed with PW, i.e. via the so-called plugins structure,
> which is meant to provide a more general platform for developers to
> introduce inside the code additional terms to the
> potential/energy/forces that may depend on the electronic density of the
> system (and thus need to be updated at each SCF/CP step). The idea is
> that a few calls are inserted in appropriate places inside the main
> programs (PW, and now CP) to plugin_#something# subroutines, which are
> empty subroutines that can then be patched by the external modules.
>
> Following what was done for PW (mostly by Layla and myself), I have now
> modified CP to allow the use of plugins. In particular, I have inserted
> in a few subroutines of CP a few calls to new plugin_#something#
> subroutines, I have created this new empy files and I have added them to
> the CPV/src/Makefile. Clearly, these modifications alone will/should not
> change the main program in any sensible way, apart from making it more
> ugly. Nonetheless, before commiting these changes, I would like to be
> sure that no harm is done and that the other developers of CP are ok
> with my modifications. At the bottom of this email I copy the diff of my
> development versions with respect to the svn files, the main changes are
> last, in the subroutine vofrho_x in file vofrho.f90. Please let me know
> if you have any comment/suggestion/request, if no remarks are done, I
> will commit what I have by the end of the week.
>
> A few side notes:
>
> 1) I also created a plugin_utilities.f90 file which contains a few
> subroutines that do some reciprocal-space calculations or are interfaces
> for subroutines that do so (compute an electrostatic potential, a
> gradient, forces, etc.). Although there are already subroutines that do
> something similar, unfortunately their structures are not general enough
> to be used by my modules and I had to create more general versions or
> interfaces that could be called with less arguments. In PW this
> subroutines were included in the appropriate files, (e.g. v_h_of_rho_r
> inside PW/src/v_of_rho.f90 to compute a Hartree potential from a density
> in real-space, or the external_gradient interface in
> PW/src/grad_corr.f90 to compute a gradient without the need of
> specifying reciprocal-space information). In CP this could also be done,
> but I am not sure it is really useful, so I decided to put everything
> inside a specific file. This way, it should be easier to clean it up or
> remove it, in case no one will need it anymore.
>
> 2) While looking for subroutines to do reciprocal-space calculations, I
> found the vofps_x and vofloc_x routines in potentials.f90 that are never
> called by CP and that are potentially buggy (the loops over g vectors
> run on the dense grid up to ngm, while rhops and vps are only defined on
> the smooth grid up to ngms). Maybe they should be removed from the code
> or fixed, if used by anyone.
>
> 3) Environ contains also the quantum-enthalpy and quantum-surface terms
> developed by Matteo Cococcioni and co-workers and that are already
> inside the CP code (vol_clu.f90 and related calls). In principles, it
> would be possible to remove these parts from the code and only leave
> them for Environ users.
>
> Best,
>
> Oliviero Andreussi
> Senior Postdoctoral Associate
> École Polytechnique Fédérale de Lausanne (EPFL) and
> Università della Svizzera Italiana (USI) of Lugano, Switzerland
> oliviero.andreussi at usi.ch
> oliviero.andreussi at epfl.ch
>
>
> Here is the list of empty, patchable, subroutines I plan to add to CPV/src/
>
> ?       plugin_clean.f90
> ?       plugin_init_ions.f90
> ?       plugin_get_potential.f90
> ?       plugin_print_info.f90
> ?       plugin_add_potential.f90
> ?       plugin_print_energies.f90
> ?       plugin_energy.f90
> ?       plugin_int_forces.f90
> ?       plugin_init_cell.f90
> ?       plugin_read_input.f90
> ?       plugin_utilities.f90
> ?       plugin_clock.f90
> ?       plugin_init_base.f90
>
> and here is the diff of the files I plan to commit with respect to SVN
> updated now
>
> ===================================================================
> --- cpr.f90    (revision 11775)
> +++ cpr.f90    (working copy)
> @@ -295,6 +295,10 @@
>        IF ( ( tfor .OR. tfirst ) .AND. tefield ) CALL efield_update( eigr )
>        IF ( ( tfor .OR. tfirst ) .AND. tefield2 ) CALL efield_update2(
> eigr )
>        !
> +     ! ... pass ions information to plugins
> +     !
> +     CALL plugin_init_ions( tau0 )
> +     !
>        IF ( lda_plus_u ) then
>           ! forceh    ! Forces on ions due to Hubbard U
>           forceh=0.0d0
> @@ -801,6 +805,8 @@
>              IF ( tefield )  CALL efield_update( eigr )
>              IF ( tefield2 ) CALL efield_update2( eigr )
>              !
> +           CALL plugin_init_ions( tau0 )
> +           !
>              lambdam = lambda
>              !
>              CALL move_electrons( nfi, tfirst, tlast, bg(:,1), bg(:,2),
> bg(:,3),&
> @@ -1128,6 +1134,8 @@
>     !
>     CALL print_clock( 'ALLTOALL' )
>     !
> +  CALL plugin_clock()
> +  !
>     CALL mp_report()
>     !
>   END SUBROUTINE terminate_run
>
> ===================================================================
> --- fromscra.f90    (revision 11775)
> +++ fromscra.f90    (working copy)
> @@ -116,6 +116,10 @@
>          CALL phbox( taub, iverbosity, eigrb )
>       END IF
>       !
> +    !     pass ions informations to plugins
> +    !
> +    CALL plugin_init_ions( tau0 )
> +    !
>       !     wfc initialization with random numbers
>       !
>       CALL wave_rand_init( cm_bgrp )
>
> ===================================================================
> --- restart_sub.f90    (revision 11775)
> +++ restart_sub.f90    (working copy)
> @@ -155,6 +155,8 @@
>      IF ( tefield  ) CALL efield_berry_setup( eigr, tau0 )
>      IF ( tefield2 ) CALL efield_berry_setup2( eigr, tau0 )
>      !
> +   CALL plugin_init_ions( tau0 )
> +   !
>      edft%eself = eself
>      !
>      IF( tzerop .or. tzeroe .or. tzeroc ) THEN
>
> ===================================================================
> --- input.f90    (revision 11775)
> +++ input.f90    (working copy)
> @@ -708,6 +708,11 @@
>         ! force pairing
>
>         force_pairing_ = force_pairing
> +
> +      ! ... having set all input keywords, read plugins' input file(s)
> +
> +      CALL plugin_read_input()
> +
>         !
>         ! ... the 'ATOMIC_SPECIES' card must be present, check it
>
> @@ -1133,6 +1138,8 @@
>         !
>         !   CALL sic_info()  ! maybe useful
>         !
> +      CALL plugin_print_info( )
> +      !
>         IF(tefield) call efield_info( )
>         IF(tefield2) call efield_info2( )
>
> ===================================================================
> --- init_run.f90    (revision 11775)
> +++ init_run.f90    (working copy)
> @@ -117,6 +117,10 @@
>     !
>     CALL init_dimensions()
>     !
> +  ! ... initialization of plugin variables and arrays
> +  !
> +  CALL plugin_init_base()
> +  !
>     ! ... initialize atomic positions and cell
>     !
>     CALL init_geometry()
>
> ===================================================================
> --- init.f90    (revision 11775)
> +++ init.f90    (working copy)
> @@ -419,5 +419,9 @@
>         !
>         call gcalb ( )
>         !
> +      !   pass new cell parameters to plugins
> +      !
> +      CALL plugin_init_cell( )
> +      !
>         return
>       end subroutine newinit_x
>
> ===================================================================
> --- energies.f90    (revision 11775)
> +++ energies.f90    (working copy)
> @@ -197,6 +197,8 @@
>                IF( textfor ) WRITE( stdout, 16 ) eextfor
>             END IF
>             !
> +          CALL plugin_print_energies()
> +          !
>   1         FORMAT(6X,'                total energy = ',F18.10,' Hartree
> a.u.')
>   2         FORMAT(6X,'              kinetic energy = ',F18.10,' Hartree
> a.u.')
>   3         FORMAT(6X,'        electrostatic energy = ',F18.10,' Hartree
> a.u.')
>
> ===================================================================
> --- stop_run.f90    (revision 11775)
> +++ stop_run.f90    (working copy)
> @@ -26,6 +26,8 @@
>     !
>     IF ( lconstrain ) CALL deallocate_constraint()
>     !
> +  CALL plugin_clean()
> +  !
>     CALL mp_global_end()
>     !
>   END SUBROUTINE stop_run
>
> ===================================================================
> --- vofrho.f90    (revision 11775)
> +++ vofrho.f90    (working copy)
> @@ -62,6 +62,8 @@
>         USE tsvdw_module,     ONLY: EtsvdW,UtsvdW,FtsvdW,HtsvdW
>         USE mp_global,        ONLY: me_image
>         USE exx_module,       ONLY: dexx_dh, exxalfa  ! exx_wf related
> +
> +      USE plugin_variables, ONLY: plugin_etot
>
>         IMPLICIT NONE
>   !
> @@ -143,6 +145,16 @@
>   !
>         if (abivol.or.abisur) call vol_clu(rhor,rhog,sfac,nfi)
>         !
> +      !     compute plugin contributions to the potential, add it later
> +      !
> +      CALL plugin_get_potential(rhor,nfi)
> +      !
> +      !     compute plugin contributions to the energy
> +      !
> +      plugin_etot = 0.0_dp
> +      !
> +      CALL plugin_energy(rhor,plugin_etot)
> +      !
>         ttsic = ( ABS( self_interaction ) /= 0 )
>         !
>         IF( ttsic ) ALLOCATE( self_vloc( ngm ) )
> @@ -413,6 +425,11 @@
>           END IF
>           !
>         END IF
> +      !
> +      !     add plugin contributions to potential here...
> +      !
> +      CALL plugin_add_potential( rhor )
> +      !
>   !
>   !     rhor contains the xc potential in r-space
>   !
> @@ -499,6 +516,11 @@
>               fion = fion + fion1
>               !fion=fion+FtsvdW
>            END IF
> +         !
> +         !     plugin patches on internal forces
> +         !
> +         CALL plugin_int_forces(fion)
> +
>         END IF
>
>         DEALLOCATE( fion1 )
> @@ -625,6 +647,10 @@
>         if (abivol) etot = etot + P_ext*volclu
>         if (abisur) etot = etot + Surf_t*surfclu
>         !
> +      !     Add possible external contribution from plugins to the energy
> +      !
> +      etot = etot + plugin_etot
> +      !
>         IF( tpre ) THEN
>            !
>            detot6 = dekin6 + dh6 + dps6 + dsr6
>
>
> _______________________________________________
> Q-e-developers mailing list
> Q-e-developers at qe-forge.org
> http://qe-forge.org/mailman/listinfo/q-e-developers
>



-- 
Paolo Giannozzi, Dept. Chemistry&Physics&Environment,
Univ. Udine, via delle Scienze 208, 33100 Udine, Italy
Phone +39-0432-558216, fax +39-0432-558222
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.quantum-espresso.org/pipermail/developers/attachments/20151007/a8ddcec3/attachment.html>


More information about the developers mailing list