parse_geometry_generic Module Subroutine

module subroutine parse_geometry_generic(unit, geom, error)

Uses

  • proc~~parse_geometry_generic~~UsesGraph proc~parse_geometry_generic parse_geometry_generic module~mqc_geometry mqc_geometry proc~parse_geometry_generic->module~mqc_geometry pic_types pic_types module~mqc_geometry->pic_types

Generic parser for %geometry section (works for both config and molecule)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit
type(geometry_type), intent(inout) :: geom
type(error_t), intent(out) :: error

Calls

proc~~parse_geometry_generic~~CallsGraph proc~parse_geometry_generic parse_geometry_generic proc~error_set error_t%error_set proc~parse_geometry_generic->proc~error_set proc~strip_comment strip_comment proc~parse_geometry_generic->proc~strip_comment

Called by

proc~~parse_geometry_generic~~CalledByGraph proc~parse_geometry_generic parse_geometry_generic interface~parse_geometry_generic parse_geometry_generic interface~parse_geometry_generic->proc~parse_geometry_generic proc~parse_geometry_section parse_geometry_section proc~parse_geometry_section->interface~parse_geometry_generic proc~parse_molecule_geometry parse_molecule_geometry proc~parse_molecule_geometry->interface~parse_geometry_generic interface~parse_geometry_section parse_geometry_section interface~parse_geometry_section->proc~parse_geometry_section proc~parse_single_molecule parse_single_molecule proc~parse_single_molecule->proc~parse_molecule_geometry proc~parse_molecules_section parse_molecules_section proc~parse_molecules_section->proc~parse_single_molecule proc~read_mqc_file read_mqc_file proc~read_mqc_file->interface~parse_geometry_section interface~parse_molecules_section parse_molecules_section interface~parse_molecules_section->proc~parse_molecules_section program~main main program~main->proc~read_mqc_file

Variables

Type Visibility Attributes Name Initial
character(len=MAX_LINE_LEN), private :: elem
integer, private :: i
integer, private :: io_stat
character(len=MAX_LINE_LEN), private :: line
integer, private :: natoms
real(kind=dp), private :: x
real(kind=dp), private :: y
real(kind=dp), private :: z

Source Code

   module subroutine parse_geometry_generic(unit, geom, error)
      !! Generic parser for %geometry section (works for both config and molecule)
      use mqc_geometry, only: geometry_type
      integer, intent(in) :: unit
      type(geometry_type), intent(inout) :: geom
      type(error_t), intent(out) :: error

      character(len=MAX_LINE_LEN) :: line, elem
      integer :: io_stat, natoms, i
      real(dp) :: x, y, z
      ! Read number of atoms
      read (unit, '(A)', iostat=io_stat) line
      if (io_stat /= 0) then
         call error%set(ERROR_PARSE, "Error reading natoms in %geometry section")
         return
      end if

      read (line, *, iostat=io_stat) natoms
      if (io_stat /= 0) then
         call error%set(ERROR_PARSE, "Invalid natoms in %geometry section")
         return
      end if

      geom%natoms = natoms

      ! Read blank line (comment line in XYZ format)
      read (unit, '(A)', iostat=io_stat) line
      if (io_stat /= 0) then
         call error%set(ERROR_PARSE, "Error reading comment line in %geometry section")
         return
      end if

      geom%comment = trim(line)

      ! Allocate arrays
      allocate (character(len=4) :: geom%elements(natoms))
      allocate (geom%coords(3, natoms))

      ! Read coordinates
      do i = 1, natoms
         read (unit, '(A)', iostat=io_stat) line
         if (io_stat /= 0) then
            call error%set(ERROR_PARSE, "Error reading geometry coordinates")
            return
         end if

         line = adjustl(line)
         if (trim(strip_comment(line)) == 'end') then
            call error%set(ERROR_PARSE, "Unexpected 'end' while reading geometry")
            return
         end if

         read (line, *, iostat=io_stat) elem, x, y, z
         if (io_stat /= 0) then
            call error%set(ERROR_PARSE, "Invalid coordinate format in %geometry section")
            return
         end if

         geom%elements(i) = trim(elem)
         geom%coords(1, i) = x
         geom%coords(2, i) = y
         geom%coords(3, i) = z
      end do

      ! Read 'end' marker
      read (unit, '(A)', iostat=io_stat) line
      if (io_stat /= 0) then
         call error%set(ERROR_VALIDATION, "Missing 'end' in %geometry section")
         return
      end if

      line = adjustl(line)
      if (trim(strip_comment(line)) /= 'end') then
         call error%set(ERROR_PARSE, "Expected 'end' after geometry coordinates")
         return
      end if

   end subroutine parse_geometry_generic