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.
| Type | Intent | Optional | 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 |
| 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 |
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