apply_distance_screening Subroutine

public subroutine apply_distance_screening(polymers, total_fragments, sys_geom, driver_config, max_level)

Uses

  • proc~~apply_distance_screening~~UsesGraph proc~apply_distance_screening apply_distance_screening module~mqc_config_adapter mqc_config_adapter proc~apply_distance_screening->module~mqc_config_adapter module~mqc_physical_fragment mqc_physical_fragment proc~apply_distance_screening->module~mqc_physical_fragment module~mqc_config_adapter->module~mqc_physical_fragment module~mqc_calculation_keywords mqc_calculation_keywords module~mqc_config_adapter->module~mqc_calculation_keywords module~mqc_config_parser mqc_config_parser module~mqc_config_adapter->module~mqc_config_parser module~mqc_elements mqc_elements module~mqc_config_adapter->module~mqc_elements module~mqc_error mqc_error module~mqc_config_adapter->module~mqc_error module~mqc_method_config mqc_method_config module~mqc_config_adapter->module~mqc_method_config pic_logger pic_logger module~mqc_config_adapter->pic_logger pic_types pic_types module~mqc_config_adapter->pic_types module~mqc_cgto mqc_cgto module~mqc_physical_fragment->module~mqc_cgto module~mqc_physical_fragment->module~mqc_elements 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 module~mqc_physical_fragment->pic_types module~mqc_calculation_keywords->pic_types module~mqc_calculation_defaults mqc_calculation_defaults module~mqc_calculation_keywords->module~mqc_calculation_defaults module~mqc_cgto->pic_types module~mqc_config_parser->module~mqc_physical_fragment module~mqc_config_parser->module~mqc_error module~mqc_config_parser->module~mqc_geometry module~mqc_config_parser->pic_types module~mqc_calc_types mqc_calc_types module~mqc_config_parser->module~mqc_calc_types module~mqc_config_parser->module~mqc_calculation_defaults module~mqc_method_types mqc_method_types module~mqc_config_parser->module~mqc_method_types module~mqc_elements->pic_types pic_ascii pic_ascii module~mqc_elements->pic_ascii module~mqc_geometry->pic_types module~mqc_method_config->pic_types module~mqc_method_config->module~mqc_method_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 module~mqc_calc_types->pic_types module~mqc_calculation_defaults->pic_types module~mqc_method_types->pic_types

Apply distance-based screening to filter out fragments that exceed cutoff distances Modifies polymers array in-place and updates total_fragments count

IMPORTANT: For MBE correctness, if any k-subset of an n-mer exceeds the k-mer cutoff, the entire n-mer must be screened out. Otherwise, compute_mbe will fail when trying to look up the missing subset.

Arguments

Type IntentOptional Attributes Name
integer, intent(inout) :: polymers(:,:)
integer(kind=int64), intent(inout) :: total_fragments
type(system_geometry_t), intent(in) :: sys_geom
type(driver_config_t), intent(in) :: driver_config
integer, intent(in) :: max_level

Calls

proc~~apply_distance_screening~~CallsGraph proc~apply_distance_screening apply_distance_screening info info proc~apply_distance_screening->info proc~fragment_should_be_screened fragment_should_be_screened proc~apply_distance_screening->proc~fragment_should_be_screened to_char to_char proc~apply_distance_screening->to_char proc~calculate_monomer_distance calculate_monomer_distance proc~fragment_should_be_screened->proc~calculate_monomer_distance proc~get_next_combination get_next_combination proc~fragment_should_be_screened->proc~get_next_combination proc~to_angstrom to_angstrom proc~calculate_monomer_distance->proc~to_angstrom

Called by

proc~~apply_distance_screening~~CalledByGraph proc~apply_distance_screening apply_distance_screening proc~run_fragmented_calculation run_fragmented_calculation proc~run_fragmented_calculation->proc~apply_distance_screening proc~run_calculation run_calculation proc~run_calculation->proc~run_fragmented_calculation proc~compute_energy_and_forces compute_energy_and_forces proc~compute_energy_and_forces->proc~run_calculation proc~run_multi_molecule_calculations run_multi_molecule_calculations proc~run_multi_molecule_calculations->proc~run_calculation program~main main program~main->proc~run_calculation program~main->proc~run_multi_molecule_calculations

Variables

Type Visibility Attributes Name Initial
integer, private :: fragment_size
integer(kind=int64), private :: fragments_kept
integer(kind=int64), private :: fragments_screened
integer(kind=int64), private :: i
logical, private :: should_screen

Source Code

   subroutine apply_distance_screening(polymers, total_fragments, sys_geom, driver_config, max_level)
      !! Apply distance-based screening to filter out fragments that exceed cutoff distances
      !! Modifies polymers array in-place and updates total_fragments count
      !!
      !! IMPORTANT: For MBE correctness, if any k-subset of an n-mer exceeds the k-mer cutoff,
      !! the entire n-mer must be screened out. Otherwise, compute_mbe will fail when trying
      !! to look up the missing subset.
      use mqc_physical_fragment, only: calculate_monomer_distance
      use mqc_config_adapter, only: driver_config_t

      integer, intent(inout) :: polymers(:, :)
      integer(int64), intent(inout) :: total_fragments
      type(system_geometry_t), intent(in) :: sys_geom
      type(driver_config_t), intent(in) :: driver_config
      integer, intent(in) :: max_level

      integer(int64) :: i, fragments_kept
      integer :: fragment_size
      integer(int64) :: fragments_screened
      logical :: should_screen

      ! Check if we have cutoffs to apply
      if (.not. allocated(driver_config%fragment_cutoffs)) then
         return  ! No screening needed
      end if

      fragments_kept = 0_int64
      fragments_screened = 0_int64

      ! Loop through all fragments and filter based on distance
      do i = 1_int64, total_fragments
         fragment_size = count(polymers(i, :) > 0)

         ! Monomers are always kept (distance = 0)
         if (fragment_size == 1) then
            fragments_kept = fragments_kept + 1_int64
            if (fragments_kept /= i) then
               ! Compact array - move this fragment to the kept position
               polymers(fragments_kept, :) = polymers(i, :)
            end if
            cycle
         end if

         ! For n-mers (n >= 2), check if this fragment or any of its subsets should be screened
         should_screen = fragment_should_be_screened(polymers(i, 1:fragment_size), fragment_size, &
                                                     sys_geom, driver_config)

         if (.not. should_screen) then
            ! Keep this fragment
            fragments_kept = fragments_kept + 1_int64
            if (fragments_kept /= i) then
               polymers(fragments_kept, :) = polymers(i, :)
            end if
         else
            ! Screen out this fragment
            fragments_screened = fragments_screened + 1_int64
         end if
      end do

      ! Update total fragment count
      if (fragments_screened > 0) then
         call logger%info("Distance-based screening applied:")
         call logger%info("  Fragments before screening: "//to_char(total_fragments))
         call logger%info("  Fragments screened out: "//to_char(fragments_screened))
         call logger%info("  Fragments kept: "//to_char(fragments_kept))
         total_fragments = fragments_kept
      end if

   end subroutine apply_distance_screening