initialize_fragmented_system Subroutine

private subroutine initialize_fragmented_system(nfrag, geom, fragments, charge, multiplicity, allow_overlapping, use_angstrom, sys_geom, error)

Uses

  • proc~~initialize_fragmented_system~~UsesGraph proc~initialize_fragmented_system initialize_fragmented_system module~mqc_config_parser mqc_config_parser proc~initialize_fragmented_system->module~mqc_config_parser module~mqc_geometry mqc_geometry proc~initialize_fragmented_system->module~mqc_geometry module~mqc_config_parser->module~mqc_geometry module~mqc_calc_types mqc_calc_types module~mqc_config_parser->module~mqc_calc_types module~mqc_calculation_defaults mqc_calculation_defaults module~mqc_config_parser->module~mqc_calculation_defaults module~mqc_error mqc_error module~mqc_config_parser->module~mqc_error module~mqc_method_types mqc_method_types module~mqc_config_parser->module~mqc_method_types module~mqc_physical_fragment mqc_physical_fragment module~mqc_config_parser->module~mqc_physical_fragment pic_types pic_types module~mqc_config_parser->pic_types module~mqc_geometry->pic_types module~mqc_calc_types->pic_types module~mqc_calculation_defaults->pic_types module~mqc_method_types->pic_types module~mqc_physical_fragment->module~mqc_geometry module~mqc_physical_fragment->module~mqc_error module~mqc_physical_fragment->pic_types 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_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 module~mqc_cgto->pic_types module~mqc_elements->pic_types pic_ascii pic_ascii module~mqc_elements->pic_ascii module~mqc_physical_constants->pic_types module~mqc_xyz_reader->module~mqc_geometry module~mqc_xyz_reader->module~mqc_error module~mqc_xyz_reader->pic_types

Shared helper to initialize system_geometry_t for fragmented calculations Handles fragment allocation, size checking, and overlap validation

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: nfrag
type(geometry_type), intent(in) :: geom
type(input_fragment_t), intent(in) :: fragments(:)
integer, intent(in) :: charge
integer, intent(in) :: multiplicity
logical, intent(in) :: allow_overlapping
logical, intent(in) :: use_angstrom
type(system_geometry_t), intent(out) :: sys_geom
type(error_t), intent(out) :: error

Calls

proc~~initialize_fragmented_system~~CallsGraph proc~initialize_fragmented_system initialize_fragmented_system proc~check_fragment_overlap check_fragment_overlap proc~initialize_fragmented_system->proc~check_fragment_overlap proc~element_symbol_to_number element_symbol_to_number proc~initialize_fragmented_system->proc~element_symbol_to_number proc~error_add_context error_t%error_add_context proc~initialize_fragmented_system->proc~error_add_context proc~error_has_error error_t%error_has_error proc~initialize_fragmented_system->proc~error_has_error proc~to_bohr to_bohr proc~initialize_fragmented_system->proc~to_bohr proc~error_set error_t%error_set proc~check_fragment_overlap->proc~error_set to_char to_char proc~check_fragment_overlap->to_char to_lower to_lower proc~element_symbol_to_number->to_lower to_upper to_upper proc~element_symbol_to_number->to_upper

Called by

proc~~initialize_fragmented_system~~CalledByGraph proc~initialize_fragmented_system initialize_fragmented_system proc~geometry_to_system_fragmented geometry_to_system_fragmented proc~geometry_to_system_fragmented->proc~initialize_fragmented_system proc~molecule_to_system_geometry molecule_to_system_geometry proc~molecule_to_system_geometry->proc~initialize_fragmented_system proc~config_to_system_geometry config_to_system_geometry proc~config_to_system_geometry->proc~geometry_to_system_fragmented proc~config_to_system_geometry->proc~molecule_to_system_geometry proc~run_multi_molecule_calculations run_multi_molecule_calculations proc~run_multi_molecule_calculations->proc~config_to_system_geometry program~main main program~main->proc~config_to_system_geometry program~main->proc~run_multi_molecule_calculations

Variables

Type Visibility Attributes Name Initial
logical, private :: all_same_size
integer, private :: atoms_in_first_frag
integer, private :: i
integer, private :: j
integer, private :: max_frag_size

Source Code

   subroutine initialize_fragmented_system(nfrag, geom, fragments, charge, multiplicity, &
                                           allow_overlapping, use_angstrom, sys_geom, error)
      !! Shared helper to initialize system_geometry_t for fragmented calculations
      !! Handles fragment allocation, size checking, and overlap validation
      use mqc_geometry, only: geometry_type
      use mqc_config_parser, only: input_fragment_t

      integer, intent(in) :: nfrag
      type(geometry_type), intent(in) :: geom
      type(input_fragment_t), intent(in) :: fragments(:)
      integer, intent(in) :: charge, multiplicity
      logical, intent(in) :: allow_overlapping
      logical, intent(in) :: use_angstrom
      type(system_geometry_t), intent(out) :: sys_geom
      type(error_t), intent(out) :: error

      integer :: i, j, atoms_in_first_frag, max_frag_size
      logical :: all_same_size

      ! Set up basic system geometry
      sys_geom%n_monomers = nfrag
      sys_geom%total_atoms = geom%natoms
      sys_geom%charge = charge
      sys_geom%multiplicity = multiplicity

      ! Allocate fragment info arrays
      allocate (sys_geom%fragment_sizes(nfrag))
      allocate (sys_geom%fragment_charges(nfrag))
      allocate (sys_geom%fragment_multiplicities(nfrag))

      ! Get fragment sizes
      max_frag_size = 0
      atoms_in_first_frag = size(fragments(1)%indices)
      all_same_size = .true.

      do i = 1, nfrag
         sys_geom%fragment_sizes(i) = size(fragments(i)%indices)
         sys_geom%fragment_charges(i) = fragments(i)%charge
         sys_geom%fragment_multiplicities(i) = fragments(i)%multiplicity
         max_frag_size = max(max_frag_size, sys_geom%fragment_sizes(i))
         if (sys_geom%fragment_sizes(i) /= atoms_in_first_frag) then
            all_same_size = .false.
         end if
      end do

      ! Allocate fragment_atoms array
      allocate (sys_geom%fragment_atoms(max_frag_size, nfrag))
      sys_geom%fragment_atoms = -1  ! Initialize with invalid index

      ! Store fragment atom indices (0-indexed from input file)
      do i = 1, nfrag
         do j = 1, sys_geom%fragment_sizes(i)
            sys_geom%fragment_atoms(j, i) = fragments(i)%indices(j)
         end do
      end do

      ! Check for overlapping fragments if not allowed
      if (.not. allow_overlapping) then
         call check_fragment_overlap(fragments, nfrag, error)
         if (error%has_error()) then
            call error%add_context("mqc_config_adapter:geometry_to_system_fragmented")
            return
         end if
      end if

      ! Set atoms_per_monomer: use common size if identical, else 0
      if (all_same_size) then
         sys_geom%atoms_per_monomer = atoms_in_first_frag
      else
         sys_geom%atoms_per_monomer = 0  ! Signal variable-sized fragments
      end if

      allocate (sys_geom%element_numbers(sys_geom%total_atoms))
      allocate (sys_geom%coordinates(3, sys_geom%total_atoms))

      ! Convert element symbols to atomic numbers
      do i = 1, sys_geom%total_atoms
         sys_geom%element_numbers(i) = element_symbol_to_number(geom%elements(i))
      end do

      ! Store coordinates (convert to Bohr if needed)
      if (use_angstrom) then
         sys_geom%coordinates = to_bohr(geom%coords)
      else
         sys_geom%coordinates = geom%coords
      end if

   end subroutine initialize_fragmented_system