From 8a08cfc33b72261d6393d64d9f8e0519851616ba Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 1 Jul 2022 12:40:36 +0200 Subject: [PATCH] Saving MOs in TREXIO format --- configure | 1 + scripts/compilation/qp_create_ninja | 2 +- scripts/save_current_mos.sh | 45 -------- src/dummy/NEED | 48 --------- src/dummy/README.rst | 6 -- src/dummy/dummy.main.irp.f | 7 -- src/mo_basis/mo_class.irp.f | 28 +++-- src/mo_basis/mos.irp.f | 157 +++++++++++++++++++--------- src/mo_basis/utils.irp.f | 147 +++++++++++++++++--------- src/utils/EZFIO.cfg | 1 + 10 files changed, 225 insertions(+), 217 deletions(-) delete mode 100755 scripts/save_current_mos.sh delete mode 100644 src/dummy/NEED delete mode 100644 src/dummy/README.rst delete mode 100644 src/dummy/dummy.main.irp.f diff --git a/configure b/configure index 7dd91bf3..1c925432 100755 --- a/configure +++ b/configure @@ -204,6 +204,7 @@ EOF cd trexio-${VERSION} ./configure --prefix=\${QP_ROOT} make -j 8 && make -j 8 check && make -j 8 install + cp ${QP_ROOT}/include/trexio_f.f90 ${QP_ROOT}/src/ezfio_files EOF elif [[ ${PACKAGE} = gmp ]] ; then diff --git a/scripts/compilation/qp_create_ninja b/scripts/compilation/qp_create_ninja index c0ba8c6a..ad9a223b 100755 --- a/scripts/compilation/qp_create_ninja +++ b/scripts/compilation/qp_create_ninja @@ -40,7 +40,7 @@ from qp_path import QP_ROOT, QP_SRC, QP_EZFIO LIB = " -lz" EZFIO_LIB = join("$QP_ROOT", "lib", "libezfio_irp.a") -ZMQ_LIB = join("$QP_ROOT", "lib", "libf77zmq.a") + " " + join("$QP_ROOT", "lib", "libzmq.a") + " -lstdc++ -lrt -ldl" +ZMQ_LIB = join("$QP_ROOT", "lib", "libf77zmq.a") + " " + join("$QP_ROOT", "lib", "libzmq.a") + " -ltrexio -lstdc++ -lrt -ldl" ROOT_BUILD_NINJA = join("$QP_ROOT", "config", "build.ninja") ROOT_BUILD_NINJA_EXP = join(QP_ROOT, "config", "build.ninja") ROOT_BUILD_NINJA_EXP_tmp = join(QP_ROOT, "config", "build.ninja.tmp") diff --git a/scripts/save_current_mos.sh b/scripts/save_current_mos.sh deleted file mode 100755 index cf4c5471..00000000 --- a/scripts/save_current_mos.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -# This script is used by the MOs module, and should not be used by users. -# It copies the EZFIO/mo_basis directory in the save/EZFIO/mo_basis/xxx -# directory, where xxx is the corresponding mo_label. -# Wed Apr 2 14:35:15 CEST 2014 - - -if [[ -z ${QP_ROOT} ]] ; then - print "The QP_ROOT environment variable is not set." - print "Please reload the quantum_package.rc file." - exit -1 -fi - -EZFIO="$1" - -if [[ -z "${EZFIO}" ]] ; then - echo "Error in $0" - exit 1 -fi - -if [[ ! -f "${EZFIO}/mo_basis/mo_label" ]] ; then - LABEL='no_label' -else - LABEL=$(head -1 "${EZFIO}/mo_basis/mo_label" | xargs) #xargs trims the result -fi - -DESTINATION="save/mo_basis/${LABEL}" - -cd "${EZFIO}" - -if [[ ! -d save/mo_basis ]] ; then - mkdir -p save/mo_basis -fi - -BACKUP="${DESTINATION}.old" -if [[ -d "${BACKUP}" ]] ; then - rm -rf "${BACKUP}" -fi - -if [[ -d "${DESTINATION}" ]] ; then - mv "${DESTINATION}" "${BACKUP}" -fi - -cp -r mo_basis "${DESTINATION}" - diff --git a/src/dummy/NEED b/src/dummy/NEED deleted file mode 100644 index 3d5eb1f7..00000000 --- a/src/dummy/NEED +++ /dev/null @@ -1,48 +0,0 @@ -ao_basis -ao_one_e_ints -ao_two_e_erf_ints -ao_two_e_ints -aux_quantities -becke_numerical_grid -bitmask -cipsi -cis -cisd -davidson -davidson_dressed -davidson_undressed -density_for_dft -determinants -dft_keywords -dft_utils_in_r -dft_utils_func -dressing -electrons -ezfio_files -fci -functionals -generators_cas -generators_full -hartree_fock -iterations -kohn_sham -kohn_sham_rs -mo_basis -mo_guess -mo_one_e_ints -mo_two_e_erf_ints -mo_two_e_ints -mpi -nuclei -perturbation -pseudo -psiref_cas -psiref_utils -scf_utils -selectors_cassd -selectors_full -selectors_utils -single_ref_method -tools -utils -zmq diff --git a/src/dummy/README.rst b/src/dummy/README.rst deleted file mode 100644 index 6bdb2ca7..00000000 --- a/src/dummy/README.rst +++ /dev/null @@ -1,6 +0,0 @@ -===== -dummy -===== - -Module necessary to avoid the ``xxx is a root module but does not contain a main file`` message. - diff --git a/src/dummy/dummy.main.irp.f b/src/dummy/dummy.main.irp.f deleted file mode 100644 index 0b789ea1..00000000 --- a/src/dummy/dummy.main.irp.f +++ /dev/null @@ -1,7 +0,0 @@ -program dummy - implicit none - BEGIN_DOC -! Dummy test file - END_DOC - print *, 'OK' -end diff --git a/src/mo_basis/mo_class.irp.f b/src/mo_basis/mo_class.irp.f index 95fbb443..b6e993a4 100644 --- a/src/mo_basis/mo_class.irp.f +++ b/src/mo_basis/mo_class.irp.f @@ -1,7 +1,4 @@ -! DO NOT MODIFY BY HAND -! Created by $QP_ROOT/scripts/ezfio_interface/ei_handler.py -! from file /home/eginer/programs/qp2/src/mo_basis/EZFIO.cfg - +use trexio BEGIN_PROVIDER [ character*(32), mo_class , (mo_num) ] implicit none @@ -10,16 +7,27 @@ BEGIN_PROVIDER [ character*(32), mo_class , (mo_num) ] END_DOC logical :: has - PROVIDE ezfio_filename + integer(trexio_exit_code) :: rc + + PROVIDE ezfio_filename trexio_file + + mo_class(:) = 'Active' + if (mpi_master) then if (size(mo_class) == 0) return - call ezfio_has_mo_basis_mo_class(has) - if (has) then - write(6,'(A)') '.. >>>>> [ IO READ: mo_class ] <<<<< ..' - call ezfio_get_mo_basis_mo_class(mo_class) + if (use_trexio) then + rc = trexio_has_mo_class(trexio_file) + if (rc == TREXIO_SUCCESS) then + rc = trexio_read_mo_class(trexio_file, mo_class, len(mo_class(1))) + call trexio_assert(rc, TREXIO_SUCCESS) + endif else - mo_class(:) = 'Active' + call ezfio_has_mo_basis_mo_class(has) + if (has) then + write(6,'(A)') '.. >>>>> [ IO READ: mo_class ] <<<<< ..' + call ezfio_get_mo_basis_mo_class(mo_class) + endif endif endif IRP_IF MPI_DEBUG diff --git a/src/mo_basis/mos.irp.f b/src/mo_basis/mos.irp.f index 57ebb533..9211abc9 100644 --- a/src/mo_basis/mos.irp.f +++ b/src/mo_basis/mos.irp.f @@ -1,3 +1,4 @@ +use trexio BEGIN_PROVIDER [ integer, mo_num ] implicit none BEGIN_DOC @@ -5,37 +6,51 @@ BEGIN_PROVIDER [ integer, mo_num ] END_DOC logical :: has - PROVIDE ezfio_filename + integer :: ierr + integer(trexio_exit_code) :: rc + + PROVIDE ezfio_filename trexio_file + if (mpi_master) then - call ezfio_has_mo_basis_mo_num(has) - endif - IRP_IF MPI_DEBUG - print *, irp_here, mpi_rank - call MPI_BARRIER(MPI_COMM_WORLD, ierr) - IRP_ENDIF - IRP_IF MPI - include 'mpif.h' - integer :: ierr - call MPI_BCAST( has, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr) - if (ierr /= MPI_SUCCESS) then - stop 'Unable to read mo_num with MPI' - endif - IRP_ENDIF - if (.not.has) then - mo_num = ao_ortho_canonical_num - else - if (mpi_master) then - call ezfio_get_mo_basis_mo_num(mo_num) + if (use_trexio) then + rc = trexio_has_mo_num(trexio_file) + has = (rc == TREXIO_SUCCESS) + else + call ezfio_has_mo_basis_mo_num(has) endif + IRP_IF MPI_DEBUG + print *, irp_here, mpi_rank + call MPI_BARRIER(MPI_COMM_WORLD, ierr) + IRP_ENDIF IRP_IF MPI - call MPI_BCAST( mo_num, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr) + include 'mpif.h' + call MPI_BCAST( has, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr) if (ierr /= MPI_SUCCESS) then stop 'Unable to read mo_num with MPI' endif IRP_ENDIF + if (.not.has) then + mo_num = ao_ortho_canonical_num + else + if (mpi_master) then + if (use_trexio) then + rc = trexio_read_mo_num(trexio_file, mo_num) + call trexio_assert(rc, TREXIO_SUCCESS) + else + call ezfio_get_mo_basis_mo_num(mo_num) + endif + endif + + IRP_IF MPI + call MPI_BCAST( mo_num, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr) + if (ierr /= MPI_SUCCESS) then + stop 'Unable to read mo_num with MPI' + endif + IRP_ENDIF + endif + call write_int(6,mo_num,'mo_num') + ASSERT (mo_num > 0) endif - call write_int(6,mo_num,'mo_num') - ASSERT (mo_num > 0) END_PROVIDER @@ -52,12 +67,16 @@ BEGIN_PROVIDER [ double precision, mo_coef, (ao_num,mo_num) ] integer :: i, j double precision, allocatable :: buffer(:,:) logical :: exists - PROVIDE ezfio_filename - + integer(trexio_exit_code) :: rc + PROVIDE ezfio_filename trexio_file if (mpi_master) then - ! Coefs - call ezfio_has_mo_basis_mo_coef(exists) + if (use_trexio) then + rc = trexio_has_mo_coefficient(trexio_file) + exists = (rc == TREXIO_SUCCESS) + else + call ezfio_has_mo_basis_mo_coef(exists) + endif endif IRP_IF MPI_DEBUG print *, irp_here, mpi_rank @@ -74,7 +93,12 @@ BEGIN_PROVIDER [ double precision, mo_coef, (ao_num,mo_num) ] if (exists) then if (mpi_master) then - call ezfio_get_mo_basis_mo_coef(mo_coef) + if (use_trexio) then + rc = trexio_read_mo_coefficient(trexio_file, mo_coef) + call trexio_assert(rc, TREXIO_SUCCESS) + else + call ezfio_get_mo_basis_mo_coef(mo_coef) + endif write(*,*) 'Read mo_coef' endif IRP_IF MPI @@ -105,12 +129,16 @@ BEGIN_PROVIDER [ double precision, mo_coef_imag, (ao_num,mo_num) ] integer :: i, j double precision, allocatable :: buffer(:,:) logical :: exists + integer(trexio_exit_code) :: rc PROVIDE ezfio_filename - if (mpi_master) then - ! Coefs - call ezfio_has_mo_basis_mo_coef_imag(exists) + if (use_trexio) then + rc = trexio_has_mo_coefficient_im(trexio_file) + exists = (rc == TREXIO_SUCCESS) + else + call ezfio_has_mo_basis_mo_coef_imag(exists) + endif endif IRP_IF MPI_DEBUG print *, irp_here, mpi_rank @@ -127,7 +155,12 @@ BEGIN_PROVIDER [ double precision, mo_coef_imag, (ao_num,mo_num) ] if (exists) then if (mpi_master) then - call ezfio_get_mo_basis_mo_coef_imag(mo_coef_imag) + if (use_trexio) then + rc = trexio_read_mo_coefficient_im(trexio_file, mo_coef_imag) + call trexio_assert(rc, TREXIO_SUCCESS) + else + call ezfio_get_mo_basis_mo_coef_imag(mo_coef_imag) + endif write(*,*) 'Read mo_coef_imag' endif IRP_IF MPI @@ -171,14 +204,27 @@ BEGIN_PROVIDER [ character*(64), mo_label ] END_DOC logical :: exists + integer(trexio_exit_code) :: rc + PROVIDE ezfio_filename if (mpi_master) then - call ezfio_has_mo_basis_mo_label(exists) - if (exists) then - call ezfio_get_mo_basis_mo_label(mo_label) - mo_label = trim(mo_label) + if (use_trexio) then + rc = trexio_has_mo_type(trexio_file) + if (rc == TREXIO_SUCCESS) then + rc = trexio_read_mo_type(trexio_file, mo_label, 64) + call trexio_assert(rc, TREXIO_SUCCESS) + mo_label = trim(mo_label) + else + mo_label = 'no_label' + endif else - mo_label = 'no_label' + call ezfio_has_mo_basis_mo_label(exists) + if (exists) then + call ezfio_get_mo_basis_mo_label(mo_label) + mo_label = trim(mo_label) + else + mo_label = 'no_label' + endif endif write(*,*) '* mo_label ', trim(mo_label) endif @@ -218,23 +264,34 @@ BEGIN_PROVIDER [ double precision, mo_occ, (mo_num) ] BEGIN_DOC ! |MO| occupation numbers END_DOC + integer(trexio_exit_code) :: rc PROVIDE ezfio_filename elec_beta_num elec_alpha_num + + mo_occ = 0.d0 + integer :: i + do i=1,elec_beta_num + mo_occ(i) = 2.d0 + enddo + do i=elec_beta_num+1,elec_alpha_num + mo_occ(i) = 1.d0 + enddo + if (mpi_master) then - logical :: exists - call ezfio_has_mo_basis_mo_occ(exists) - if (exists) then - call ezfio_get_mo_basis_mo_occ(mo_occ) + if (use_trexio) then + rc = trexio_has_mo_occupation(trexio_file) + if (rc == TREXIO_SUCCESS) then + rc = trexio_read_mo_occupation(trexio_file, mo_occ) + call trexio_assert(rc, TREXIO_SUCCESS) + write(*,*) 'Read mo_occ' + endif else - mo_occ = 0.d0 - integer :: i - do i=1,elec_beta_num - mo_occ(i) = 2.d0 - enddo - do i=elec_beta_num+1,elec_alpha_num - mo_occ(i) = 1.d0 - enddo + logical :: exists + call ezfio_has_mo_basis_mo_occ(exists) + if (exists) then + call ezfio_get_mo_basis_mo_occ(mo_occ) + write(*,*) 'Read mo_occ' + endif endif - write(*,*) 'Read mo_occ' endif IRP_IF MPI_DEBUG print *, irp_here, mpi_rank diff --git a/src/mo_basis/utils.irp.f b/src/mo_basis/utils.irp.f index 12c6c79d..23c47e95 100644 --- a/src/mo_basis/utils.irp.f +++ b/src/mo_basis/utils.irp.f @@ -1,58 +1,21 @@ subroutine save_mos implicit none - double precision, allocatable :: buffer(:,:) - integer :: i,j - - call system('$QP_ROOT/scripts/save_current_mos.sh '//trim(ezfio_filename)) - call ezfio_set_mo_basis_mo_num(mo_num) - call ezfio_set_mo_basis_mo_label(mo_label) - call ezfio_set_mo_basis_ao_md5(ao_md5) - allocate ( buffer(ao_num,mo_num) ) - buffer = 0.d0 - do j = 1, mo_num - do i = 1, ao_num - buffer(i,j) = mo_coef(i,j) - enddo - enddo - call ezfio_set_mo_basis_mo_coef(buffer) - call ezfio_set_mo_basis_mo_occ(mo_occ) - call ezfio_set_mo_basis_mo_class(mo_class) - deallocate (buffer) - -end - - -subroutine save_mos_no_occ - implicit none - double precision, allocatable :: buffer(:,:) - integer :: i,j - - call system('$QP_ROOT/scripts/save_current_mos.sh '//trim(ezfio_filename)) - !call ezfio_set_mo_basis_mo_num(mo_num) - !call ezfio_set_mo_basis_mo_label(mo_label) - !call ezfio_set_mo_basis_ao_md5(ao_md5) - allocate ( buffer(ao_num,mo_num) ) - buffer = 0.d0 - do j = 1, mo_num - do i = 1, ao_num - buffer(i,j) = mo_coef(i,j) - enddo - enddo - call ezfio_set_mo_basis_mo_coef(buffer) - deallocate (buffer) - + BEGIN_DOC +! Write MO data to disk + END_DOC + call save_mos_truncated(mo_num) end subroutine save_mos_truncated(n) + use trexio implicit none + BEGIN_DOC +! Saves the first n MOs + END_DOC + integer, intent(in) :: n double precision, allocatable :: buffer(:,:) - integer :: i,j,n + integer :: i,j - call system('$QP_ROOT/scripts/save_current_mos.sh '//trim(ezfio_filename)) - - call ezfio_set_mo_basis_mo_num(n) - call ezfio_set_mo_basis_mo_label(mo_label) - call ezfio_set_mo_basis_ao_md5(ao_md5) allocate ( buffer(ao_num,n) ) buffer = 0.d0 do j = 1, n @@ -60,13 +23,97 @@ subroutine save_mos_truncated(n) buffer(i,j) = mo_coef(i,j) enddo enddo - call ezfio_set_mo_basis_mo_coef(buffer) - call ezfio_set_mo_basis_mo_occ(mo_occ) - call ezfio_set_mo_basis_mo_class(mo_class) + if (use_trexio) then + integer (trexio_exit_code) :: rc + + rc = trexio_has_ao_num(trexio_file) + if (rc == TREXIO_HAS_NOT) then + rc = trexio_write_ao_num(trexio_file, ao_num) + call trexio_assert(rc, TREXIO_SUCCESS) + endif + + rc = trexio_write_mo_num(trexio_file, n) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_mo_type(trexio_file, mo_label, len(trim(mo_label))) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_mo_occupation(trexio_file, mo_occ) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_mo_class(trexio_file, mo_class, len(mo_class(1))) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_mo_coefficient(trexio_file, buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_close(trexio_file) + call trexio_assert(rc, TREXIO_SUCCESS) + FREE trexio_file + else + call ezfio_set_mo_basis_mo_num(n) + call ezfio_set_mo_basis_mo_label(mo_label(1:n)) + call ezfio_set_mo_basis_mo_occ(mo_occ(1:n)) + call ezfio_set_mo_basis_mo_class(mo_class(1:n)) + call ezfio_set_mo_basis_mo_coef(buffer) + endif + call ezfio_set_mo_basis_ao_md5(ao_md5) + deallocate (buffer) end + +subroutine save_mo_coef + use trexio + implicit none + BEGIN_DOC +! Saves the MO coefficients + END_DOC + double precision, allocatable :: buffer(:,:) + integer :: i,j + + allocate ( buffer(ao_num,mo_num) ) + buffer = 0.d0 + do j = 1, mo_num + do i = 1, ao_num + buffer(i,j) = mo_coef(i,j) + enddo + enddo + if (use_trexio) then + integer (trexio_exit_code) :: rc + + rc = trexio_has_ao_num(trexio_file) + if (rc == TREXIO_HAS_NOT) then + rc = trexio_write_ao_num(trexio_file, ao_num) + call trexio_assert(rc, TREXIO_SUCCESS) + endif + + rc = trexio_has_mo_num(trexio_file) + if (rc == TREXIO_HAS_NOT) then + rc = trexio_write_mo_num(trexio_file, mo_num) + call trexio_assert(rc, TREXIO_SUCCESS) + endif + + rc = trexio_write_mo_coefficient(trexio_file, buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_close(trexio_file) + call trexio_assert(rc, TREXIO_SUCCESS) + FREE trexio_file + else + call ezfio_set_mo_basis_mo_coef(buffer) + endif + deallocate (buffer) + +end + + +subroutine save_mos_no_occ + call save_mo_coef +end + + subroutine mo_as_eigvectors_of_mo_matrix(matrix,n,m,label,sign,output) implicit none integer,intent(in) :: n,m, sign diff --git a/src/utils/EZFIO.cfg b/src/utils/EZFIO.cfg index 7d367f0c..9e9a62f1 100644 --- a/src/utils/EZFIO.cfg +++ b/src/utils/EZFIO.cfg @@ -3,3 +3,4 @@ type: logical doc: If true, try to find symmetry in the MO coefficient matrices interface: ezfio,provider,ocaml default: False +