do_fragment_work Module Subroutine

module subroutine do_fragment_work(fragment_idx, result, method_config, phys_frag, calc_type, world_comm)

Uses

    • pic_logger
  • proc~~do_fragment_work~~UsesGraph proc~do_fragment_work do_fragment_work pic_logger pic_logger proc~do_fragment_work->pic_logger

Process a single fragment for quantum chemistry calculation

Performs energy and gradient calculation on a molecular fragment using the factory pattern to create a calculator from the provided method_config. Verbosity is controlled by the global logger level.

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(in) :: fragment_idx

Fragment index for identification

type(calculation_result_t), intent(out) :: result

Computation results

type(method_config_t), intent(in) :: method_config

Method configuration

type(physical_fragment_t), intent(in), optional :: phys_frag

Fragment geometry

integer(kind=int32), intent(in) :: calc_type

Calculation type

type(comm_t), intent(in), optional :: world_comm

MPI communicator for abort


Calls

proc~~do_fragment_work~~CallsGraph proc~do_fragment_work do_fragment_work calc_energy calc_energy proc~do_fragment_work->calc_energy calc_gradient calc_gradient proc~do_fragment_work->calc_gradient calc_hessian calc_hessian proc~do_fragment_work->calc_hessian configuration configuration proc~do_fragment_work->configuration proc~calc_type_to_string calc_type_to_string proc~do_fragment_work->proc~calc_type_to_string proc~create_method create_method proc~do_fragment_work->proc~create_method proc~energy_reset energy_t%energy_reset proc~do_fragment_work->proc~energy_reset proc~error_add_context error_t%error_add_context proc~do_fragment_work->proc~error_add_context proc~error_set error_t%error_set proc~do_fragment_work->proc~error_set proc~print_fragment_xyz print_fragment_xyz proc~do_fragment_work->proc~print_fragment_xyz to_char to_char proc~do_fragment_work->to_char proc~factory_create method_factory_t%factory_create proc~create_method->proc~factory_create proc~mp2_reset mp2_energy_t%mp2_reset proc~energy_reset->proc~mp2_reset proc~print_fragment_xyz->to_char info info proc~print_fragment_xyz->info proc~element_number_to_symbol element_number_to_symbol proc~print_fragment_xyz->proc~element_number_to_symbol proc~to_angstrom to_angstrom proc~print_fragment_xyz->proc~to_angstrom proc~configure_dft configure_dft proc~factory_create->proc~configure_dft proc~configure_hf configure_hf proc~factory_create->proc~configure_hf proc~configure_mcscf configure_mcscf proc~factory_create->proc~configure_mcscf proc~configure_xtb configure_xtb proc~factory_create->proc~configure_xtb state_weights state_weights proc~configure_mcscf->state_weights proc~method_type_to_string method_type_to_string proc~configure_xtb->proc~method_type_to_string proc~xtb_has_solvation xtb_config_t%xtb_has_solvation proc~configure_xtb->proc~xtb_has_solvation

Called by

proc~~do_fragment_work~~CalledByGraph proc~do_fragment_work do_fragment_work interface~do_fragment_work do_fragment_work interface~do_fragment_work->proc~do_fragment_work proc~node_worker node_worker proc~node_worker->interface~do_fragment_work proc~serial_fragment_processor serial_fragment_processor proc~serial_fragment_processor->interface~do_fragment_work proc~serial_gmbe_pie_processor serial_gmbe_pie_processor proc~serial_gmbe_pie_processor->interface~do_fragment_work proc~unfragmented_calculation unfragmented_calculation proc~unfragmented_calculation->interface~do_fragment_work interface~node_worker node_worker interface~node_worker->proc~node_worker interface~serial_fragment_processor serial_fragment_processor interface~serial_fragment_processor->proc~serial_fragment_processor interface~unfragmented_calculation unfragmented_calculation interface~unfragmented_calculation->proc~unfragmented_calculation proc~gmbe_run_serial gmbe_context_t%gmbe_run_serial proc~gmbe_run_serial->proc~serial_gmbe_pie_processor proc~gmbe_run_distributed gmbe_context_t%gmbe_run_distributed proc~gmbe_run_distributed->interface~node_worker proc~mbe_run_distributed mbe_context_t%mbe_run_distributed proc~mbe_run_distributed->interface~node_worker proc~mbe_run_serial mbe_context_t%mbe_run_serial proc~mbe_run_serial->interface~serial_fragment_processor proc~run_unfragmented_calculation run_unfragmented_calculation proc~run_unfragmented_calculation->interface~unfragmented_calculation proc~run_calculation run_calculation proc~run_calculation->proc~run_unfragmented_calculation

Variables

Type Visibility Attributes Name Initial
integer(kind=int32), private :: calc_type_local

Local copy of calc_type

class(qc_method_t), private, allocatable :: calculator

Polymorphic calculator instance

integer, private :: current_log_level

Current logger verbosity level

logical, private :: is_verbose

Whether verbose output is enabled

type(method_config_t), private :: local_config

Local copy for verbose override


Source Code

   module subroutine do_fragment_work(fragment_idx, result, method_config, phys_frag, calc_type, world_comm)
      !! Process a single fragment for quantum chemistry calculation
      !!
      !! Performs energy and gradient calculation on a molecular fragment using
      !! the factory pattern to create a calculator from the provided method_config.
      !! Verbosity is controlled by the global logger level.

      use pic_logger, only: verbose_level

      integer(int64), intent(in) :: fragment_idx        !! Fragment index for identification
      type(calculation_result_t), intent(out) :: result  !! Computation results
      type(method_config_t), intent(in) :: method_config  !! Method configuration
      type(physical_fragment_t), intent(in), optional :: phys_frag  !! Fragment geometry
      integer(int32), intent(in) :: calc_type  !! Calculation type
      type(comm_t), intent(in), optional :: world_comm  !! MPI communicator for abort

      integer :: current_log_level  !! Current logger verbosity level
      logical :: is_verbose  !! Whether verbose output is enabled
      integer(int32) :: calc_type_local  !! Local copy of calc_type
      type(method_config_t) :: local_config  !! Local copy for verbose override
      class(qc_method_t), allocatable :: calculator  !! Polymorphic calculator instance

      calc_type_local = calc_type

      ! Query logger to determine verbosity
      call logger%configuration(level=current_log_level)
      is_verbose = (current_log_level >= verbose_level)

      ! Print fragment geometry if provided and verbose mode is enabled
      if (present(phys_frag)) then
         if (is_verbose) then
            call print_fragment_xyz(fragment_idx, phys_frag)
         end if

         ! Copy config and override verbose based on logger level
         local_config = method_config
         local_config%verbose = is_verbose

         ! Create calculator using factory
         calculator = create_method(local_config)

         ! Run the calculation using polymorphic dispatch
         select case (calc_type_local)
         case (CALC_TYPE_ENERGY)
            call calculator%calc_energy(phys_frag, result)
         case (CALC_TYPE_GRADIENT)
            call calculator%calc_gradient(phys_frag, result)
         case (CALC_TYPE_HESSIAN)
            call calculator%calc_hessian(phys_frag, result)
         case default
            call result%error%set(ERROR_VALIDATION, "Unknown calc_type: "//calc_type_to_string(calc_type_local))
            result%has_error = .true.
            return
         end select

         ! Check for calculation errors
         if (result%has_error) then
            call result%error%add_context("do_fragment_work:fragment_"//to_char(fragment_idx))
            return
         end if

         ! Copy fragment distance to result for JSON output
         result%distance = phys_frag%distance

         ! Cleanup
         deallocate (calculator)
      else
         ! For empty fragments, set energy to zero
         call result%energy%reset()
         result%has_energy = .true.
      end if
   end subroutine do_fragment_work