build_molecular_basis Subroutine

public subroutine build_molecular_basis(basis_string, element_names, mol_basis, error)

Build molecular basis from geometry and basis file Only parses unique elements, then copies basis data to atoms

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: basis_string
character(len=*), intent(in) :: element_names(:)

Element for each atom in geometry order

type(molecular_basis_type), intent(out) :: mol_basis
type(error_t), intent(out) :: error

Calls

proc~~build_molecular_basis~~CallsGraph proc~build_molecular_basis build_molecular_basis proc~atomic_basis_destroy atomic_basis_type%atomic_basis_destroy proc~build_molecular_basis->proc~atomic_basis_destroy proc~basis_set_allocate_elements molecular_basis_type%basis_set_allocate_elements proc~build_molecular_basis->proc~basis_set_allocate_elements proc~copy_atomic_basis copy_atomic_basis proc~build_molecular_basis->proc~copy_atomic_basis proc~error_add_context error_t%error_add_context proc~build_molecular_basis->proc~error_add_context proc~error_get_message error_t%error_get_message proc~build_molecular_basis->proc~error_get_message proc~error_has_error error_t%error_has_error proc~build_molecular_basis->proc~error_has_error proc~error_set error_t%error_set proc~build_molecular_basis->proc~error_set proc~find_unique_strings find_unique_strings proc~build_molecular_basis->proc~find_unique_strings proc~parse_element_basis parse_element_basis proc~build_molecular_basis->proc~parse_element_basis proc~strings_equal strings_equal proc~build_molecular_basis->proc~strings_equal proc~cgto_destroy cgto_type%cgto_destroy proc~atomic_basis_destroy->proc~cgto_destroy proc~allocate_basis_shells atomic_basis_type%allocate_basis_shells proc~copy_atomic_basis->proc~allocate_basis_shells proc~cgto_allocate_arrays cgto_type%cgto_allocate_arrays proc~copy_atomic_basis->proc~cgto_allocate_arrays proc~find_unique_strings->proc~strings_equal proc~parse_element_basis->proc~error_add_context proc~parse_element_basis->proc~error_has_error proc~parse_element_basis->proc~error_set proc~parse_element_basis->proc~allocate_basis_shells proc~count_shells_for_element count_shells_for_element proc~parse_element_basis->proc~count_shells_for_element proc~fill_element_basis fill_element_basis proc~parse_element_basis->proc~fill_element_basis proc~count_shells_for_element->proc~error_set proc~count_shells_for_element->proc~strings_equal proc~classify_line classify_line proc~count_shells_for_element->proc~classify_line proc~get_next_line get_next_line proc~count_shells_for_element->proc~get_next_line proc~fill_element_basis->proc~error_set proc~fill_element_basis->proc~strings_equal proc~fill_element_basis->proc~cgto_allocate_arrays proc~ang_mom_char_to_int ang_mom_char_to_int proc~fill_element_basis->proc~ang_mom_char_to_int proc~fill_element_basis->proc~classify_line proc~fill_element_basis->proc~get_next_line proc~parse_function_line parse_function_line proc~fill_element_basis->proc~parse_function_line proc~parse_shell_header parse_shell_header proc~fill_element_basis->proc~parse_shell_header proc~is_blank_or_control is_blank_or_control proc~classify_line->proc~is_blank_or_control proc~is_function_line is_function_line proc~classify_line->proc~is_function_line proc~is_shell_header is_shell_header proc~classify_line->proc~is_shell_header

Variables

Type Visibility Attributes Name Initial
integer, private :: iatom
integer, private :: iunique
integer, private :: match_idx
integer, private :: natoms
integer, private :: nunique
type(atomic_basis_type), private, allocatable :: unique_bases(:)
character(len=:), private, allocatable :: unique_elements(:)

Source Code

   subroutine build_molecular_basis(basis_string, element_names, mol_basis, error)
      !! Build molecular basis from geometry and basis file
      !! Only parses unique elements, then copies basis data to atoms
      character(len=*), intent(in) :: basis_string
      character(len=*), intent(in) :: element_names(:)  !! Element for each atom in geometry order
      type(molecular_basis_type), intent(out) :: mol_basis
      type(error_t), intent(out) :: error

      integer :: iatom, natoms, iunique, nunique
      character(len=:), allocatable :: unique_elements(:)
      type(atomic_basis_type), allocatable :: unique_bases(:)
      integer :: match_idx

      match_idx = 0
      natoms = size(element_names)

      ! Find unique elements
      call find_unique_strings(element_names, unique_elements, nunique)

      print *, "Found ", nunique, " unique elements out of ", natoms, " atoms"

      ! Allocate for unique bases
      allocate (unique_bases(nunique))

      ! Parse basis for each unique element
      do iunique = 1, nunique
         print *, "Parsing basis for: ", trim(unique_elements(iunique))
         call parse_element_basis(basis_string, unique_elements(iunique), &
                                  unique_bases(iunique), error)
         if (error%has_error()) then
            ! Prepend context to error message
            call error%add_context("mqc_basis_reader:read_basis_from_string")
            call error%set(ERROR_PARSE, "Failed to parse basis for element "// &
                           trim(unique_elements(iunique))//": "//error%get_message())
            return
         end if
      end do

      ! Allocate molecular basis and assign to each atom
      call mol_basis%allocate_elements(natoms)

      do iatom = 1, natoms
         ! Find which unique element this atom corresponds to
         do iunique = 1, nunique
            if (strings_equal(element_names(iatom), unique_elements(iunique))) then
               match_idx = iunique
               exit
            end if
         end do

         ! Copy the basis data
         call copy_atomic_basis(unique_bases(match_idx), mol_basis%elements(iatom))
      end do

      ! Clean up
      do iunique = 1, nunique
         call unique_bases(iunique)%destroy()
      end do

   end subroutine build_molecular_basis