parse_connectivity_generic Module Subroutine

module subroutine parse_connectivity_generic(unit, nbonds, nbroken, bonds, error)

Uses

  • proc~~parse_connectivity_generic~~UsesGraph proc~parse_connectivity_generic parse_connectivity_generic module~mqc_physical_fragment mqc_physical_fragment proc~parse_connectivity_generic->module~mqc_physical_fragment module~mqc_cgto mqc_cgto module~mqc_physical_fragment->module~mqc_cgto module~mqc_elements mqc_elements module~mqc_physical_fragment->module~mqc_elements module~mqc_error mqc_error module~mqc_physical_fragment->module~mqc_error module~mqc_geometry mqc_geometry module~mqc_physical_fragment->module~mqc_geometry module~mqc_physical_constants mqc_physical_constants module~mqc_physical_fragment->module~mqc_physical_constants module~mqc_xyz_reader mqc_xyz_reader module~mqc_physical_fragment->module~mqc_xyz_reader pic_types pic_types module~mqc_physical_fragment->pic_types module~mqc_cgto->pic_types module~mqc_elements->pic_types pic_ascii pic_ascii module~mqc_elements->pic_ascii module~mqc_geometry->pic_types module~mqc_physical_constants->pic_types module~mqc_xyz_reader->module~mqc_error module~mqc_xyz_reader->module~mqc_geometry module~mqc_xyz_reader->pic_types

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

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit
integer, intent(inout) :: nbonds
integer, intent(inout) :: nbroken
type(bond_t), intent(inout), allocatable :: bonds(:)
type(error_t), intent(out) :: error

Calls

proc~~parse_connectivity_generic~~CallsGraph proc~parse_connectivity_generic parse_connectivity_generic proc~error_set error_t%error_set proc~parse_connectivity_generic->proc~error_set proc~skip_to_end skip_to_end proc~parse_connectivity_generic->proc~skip_to_end proc~strip_comment strip_comment proc~parse_connectivity_generic->proc~strip_comment proc~skip_to_end->proc~error_set proc~skip_to_end->proc~strip_comment

Called by

proc~~parse_connectivity_generic~~CalledByGraph proc~parse_connectivity_generic parse_connectivity_generic interface~parse_connectivity_generic parse_connectivity_generic interface~parse_connectivity_generic->proc~parse_connectivity_generic proc~parse_connectivity_section parse_connectivity_section proc~parse_connectivity_section->interface~parse_connectivity_generic proc~parse_molecule_connectivity parse_molecule_connectivity proc~parse_molecule_connectivity->interface~parse_connectivity_generic interface~parse_connectivity_section parse_connectivity_section interface~parse_connectivity_section->proc~parse_connectivity_section proc~parse_single_molecule parse_single_molecule proc~parse_single_molecule->proc~parse_molecule_connectivity 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_connectivity_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
integer, private :: atom_i
integer, private :: atom_j
integer, private :: eq_pos
integer, private :: ibond
integer, private :: io_stat
character(len=MAX_LINE_LEN), private :: key
character(len=MAX_LINE_LEN), private :: line
integer, private :: nbonds_local
integer, private :: order
character(len=MAX_LINE_LEN), private :: status_str
character(len=MAX_LINE_LEN), private :: value

Source Code

   module subroutine parse_connectivity_generic(unit, nbonds, nbroken, bonds, error)
      !! Generic parser for %connectivity section (works for both config and molecule)
      use mqc_physical_fragment, only: bond_t
      integer, intent(in) :: unit
      integer, intent(inout) :: nbonds, nbroken
      type(bond_t), allocatable, intent(inout) :: bonds(:)
      type(error_t), intent(out) :: error

      character(len=MAX_LINE_LEN) :: line, key, value, status_str
      integer :: io_stat, eq_pos, nbonds_local, ibond
      integer :: atom_i, atom_j, order
      nbonds_local = 0

      ! First pass: read nbonds
      do
         read (unit, '(A)', iostat=io_stat) line
         if (io_stat /= 0) then
            call error%set(ERROR_IO, "Unexpected end of file in %connectivity section")
            return
         end if

         line = adjustl(line)
         if (len_trim(line) == 0) cycle
         if (line(1:1) == '#' .or. line(1:1) == '!') cycle

         if (trim(strip_comment(line)) == 'end') exit

         eq_pos = index(line, '=')
         if (eq_pos > 0) then
            key = adjustl(line(1:eq_pos - 1))
            value = adjustl(line(eq_pos + 1:))

            if (trim(key) == 'nbonds') then
               read (value, *, iostat=io_stat) nbonds_local
               if (io_stat /= 0) then
                  call error%set(ERROR_PARSE, "Invalid nbonds value")
                  return
               end if
               exit
            end if
         end if
      end do

      if (nbonds_local == 0) then
         ! No bonds, just skip to end
         call skip_to_end(unit, error)
         return
      end if

      nbonds = nbonds_local
      allocate (bonds(nbonds))

      ! Read bonds
      ibond = 0
      do
         read (unit, '(A)', iostat=io_stat) line
         if (io_stat /= 0) exit

         line = adjustl(line)
         if (len_trim(line) == 0) cycle
         if (line(1:1) == '#' .or. line(1:1) == '!') cycle

         ! Check for key=value pairs (like nbroken=9)
         eq_pos = index(line, '=')
         if (eq_pos > 0) then
            key = adjustl(line(1:eq_pos - 1))
            value = adjustl(line(eq_pos + 1:))
            if (trim(key) == 'nbroken') then
               read (value, *, iostat=io_stat) nbroken
            end if
            cycle
         end if

         if (trim(strip_comment(line)) == 'end') exit

         ! Parse bond line: atom_i atom_j order broken/preserved
         read (line, *, iostat=io_stat) atom_i, atom_j, order, status_str
         if (io_stat /= 0) then
            call error%set(ERROR_PARSE, "Invalid bond format in %connectivity section")
            return
         end if

         ibond = ibond + 1
         if (ibond > nbonds) then
            call error%set(ERROR_PARSE, "More bonds than declared nbonds")
            return
         end if

         bonds(ibond)%atom_i = atom_i
         bonds(ibond)%atom_j = atom_j
         bonds(ibond)%order = order
         bonds(ibond)%is_broken = (trim(status_str) == 'broken')
      end do

   end subroutine parse_connectivity_generic