compute_energy_and_forces Subroutine

public subroutine compute_energy_and_forces(sys_geom, driver_config, resources, energy, gradient, hessian, bonds)

Uses

  • proc~~compute_energy_and_forces~~UsesGraph proc~compute_energy_and_forces compute_energy_and_forces module~mqc_config_adapter mqc_config_adapter proc~compute_energy_and_forces->module~mqc_config_adapter module~mqc_driver mqc_driver proc~compute_energy_and_forces->module~mqc_driver 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 module~mqc_physical_fragment mqc_physical_fragment module~mqc_config_adapter->module~mqc_physical_fragment pic_logger pic_logger module~mqc_config_adapter->pic_logger pic_types pic_types module~mqc_config_adapter->pic_types module~mqc_driver->module~mqc_config_adapter module~mqc_calc_types mqc_calc_types module~mqc_driver->module~mqc_calc_types module~mqc_driver->module~mqc_config_parser module~mqc_driver->module~mqc_error module~mqc_frag_utils mqc_frag_utils module~mqc_driver->module~mqc_frag_utils module~mqc_io_helpers mqc_io_helpers module~mqc_driver->module~mqc_io_helpers module~mqc_json mqc_json module~mqc_driver->module~mqc_json module~mqc_json_output_types mqc_json_output_types module~mqc_driver->module~mqc_json_output_types module~mqc_json_writer mqc_json_writer module~mqc_driver->module~mqc_json_writer module~mqc_many_body_expansion mqc_many_body_expansion module~mqc_driver->module~mqc_many_body_expansion module~mqc_mbe mqc_mbe module~mqc_driver->module~mqc_mbe module~mqc_mbe_fragment_distribution_scheme mqc_mbe_fragment_distribution_scheme module~mqc_driver->module~mqc_mbe_fragment_distribution_scheme module~mqc_driver->module~mqc_method_config module~mqc_method_types mqc_method_types module~mqc_driver->module~mqc_method_types module~mqc_driver->module~mqc_physical_fragment module~mqc_resources mqc_resources module~mqc_driver->module~mqc_resources module~mqc_result_types mqc_result_types module~mqc_driver->module~mqc_result_types omp_lib omp_lib module~mqc_driver->omp_lib pic_io pic_io module~mqc_driver->pic_io module~mqc_driver->pic_logger pic_mpi_lib pic_mpi_lib module~mqc_driver->pic_mpi_lib module~mqc_driver->pic_types module~mqc_calc_types->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_config_parser->module~mqc_calc_types module~mqc_config_parser->module~mqc_error module~mqc_config_parser->module~mqc_method_types module~mqc_config_parser->module~mqc_physical_fragment module~mqc_config_parser->pic_types module~mqc_config_parser->module~mqc_calculation_defaults module~mqc_geometry mqc_geometry module~mqc_config_parser->module~mqc_geometry module~mqc_elements->pic_types pic_ascii pic_ascii module~mqc_elements->pic_ascii module~mqc_frag_utils->module~mqc_physical_fragment module~mqc_frag_utils->pic_io module~mqc_frag_utils->pic_logger module~mqc_frag_utils->pic_types module~mqc_combinatorics mqc_combinatorics module~mqc_frag_utils->module~mqc_combinatorics module~mqc_fragment_lookup mqc_fragment_lookup module~mqc_frag_utils->module~mqc_fragment_lookup module~mqc_gmbe_utils mqc_gmbe_utils module~mqc_frag_utils->module~mqc_gmbe_utils module~mqc_json->pic_io module~mqc_json->pic_logger module~mqc_json_output_types->pic_types module~mqc_thermochemistry mqc_thermochemistry module~mqc_json_output_types->module~mqc_thermochemistry module~mqc_json_writer->module~mqc_io_helpers module~mqc_json_writer->module~mqc_json_output_types module~mqc_json_writer->pic_logger module~mqc_json_writer->pic_types json_module json_module module~mqc_json_writer->json_module module~mqc_mbe_io mqc_mbe_io module~mqc_json_writer->module~mqc_mbe_io module~mqc_physical_constants mqc_physical_constants module~mqc_json_writer->module~mqc_physical_constants module~mqc_program_limits mqc_program_limits module~mqc_json_writer->module~mqc_program_limits module~mqc_many_body_expansion->module~mqc_config_adapter module~mqc_many_body_expansion->module~mqc_json_output_types module~mqc_many_body_expansion->module~mqc_method_config module~mqc_many_body_expansion->module~mqc_physical_fragment module~mqc_many_body_expansion->module~mqc_resources module~mqc_many_body_expansion->pic_types module~mqc_mbe->module~mqc_frag_utils module~mqc_mbe->module~mqc_json_output_types module~mqc_mbe->module~mqc_physical_fragment module~mqc_mbe->pic_io module~mqc_mbe->pic_logger module~mqc_mbe->pic_mpi_lib module~mqc_mbe->pic_types module~mqc_mbe->module~mqc_gmbe_utils module~mqc_mbe->module~mqc_mbe_io module~mqc_mpi_tags mqc_mpi_tags module~mqc_mbe->module~mqc_mpi_tags module~mqc_mbe->module~mqc_program_limits module~mqc_mbe->module~mqc_thermochemistry module~mqc_vibrational_analysis mqc_vibrational_analysis module~mqc_mbe->module~mqc_vibrational_analysis pic_timer pic_timer module~mqc_mbe->pic_timer module~mqc_mbe_fragment_distribution_scheme->module~mqc_config_adapter module~mqc_mbe_fragment_distribution_scheme->module~mqc_calc_types module~mqc_mbe_fragment_distribution_scheme->module~mqc_json_output_types module~mqc_mbe_fragment_distribution_scheme->module~mqc_mbe module~mqc_mbe_fragment_distribution_scheme->module~mqc_method_config module~mqc_mbe_fragment_distribution_scheme->module~mqc_method_types module~mqc_mbe_fragment_distribution_scheme->module~mqc_physical_fragment module~mqc_mbe_fragment_distribution_scheme->module~mqc_resources module~mqc_mbe_fragment_distribution_scheme->module~mqc_result_types module~mqc_mbe_fragment_distribution_scheme->omp_lib module~mqc_mbe_fragment_distribution_scheme->pic_io module~mqc_mbe_fragment_distribution_scheme->pic_logger module~mqc_mbe_fragment_distribution_scheme->pic_mpi_lib module~mqc_mbe_fragment_distribution_scheme->pic_types module~mqc_mbe_fragment_distribution_scheme->module~mqc_calculation_defaults module~mqc_mbe_fragment_distribution_scheme->module~mqc_mbe_io module~mqc_method_base mqc_method_base module~mqc_mbe_fragment_distribution_scheme->module~mqc_method_base module~mqc_method_factory mqc_method_factory module~mqc_mbe_fragment_distribution_scheme->module~mqc_method_factory module~mqc_mbe_fragment_distribution_scheme->module~mqc_mpi_tags pic_blas_interfaces pic_blas_interfaces module~mqc_mbe_fragment_distribution_scheme->pic_blas_interfaces module~mqc_mbe_fragment_distribution_scheme->pic_timer module~mqc_method_config->module~mqc_method_types module~mqc_method_config->pic_types module~mqc_method_types->pic_types module~mqc_physical_fragment->module~mqc_elements 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_physical_fragment->module~mqc_geometry 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_mpi_comms mqc_mpi_comms module~mqc_resources->module~mqc_mpi_comms module~mqc_result_types->module~mqc_error module~mqc_result_types->pic_mpi_lib module~mqc_result_types->pic_types module~mqc_calculation_defaults->pic_types module~mqc_cgto->pic_types module~mqc_combinatorics->pic_types module~mqc_fragment_lookup->module~mqc_error module~mqc_fragment_lookup->pic_types pic_hash_32bit pic_hash_32bit module~mqc_fragment_lookup->pic_hash_32bit pic_sorting pic_sorting module~mqc_fragment_lookup->pic_sorting module~mqc_geometry->pic_types module~mqc_gmbe_utils->module~mqc_error module~mqc_gmbe_utils->module~mqc_physical_fragment module~mqc_gmbe_utils->module~mqc_result_types module~mqc_gmbe_utils->pic_io module~mqc_gmbe_utils->pic_logger module~mqc_gmbe_utils->pic_types module~mqc_gmbe_utils->module~mqc_combinatorics module~mqc_mbe_io->module~mqc_elements module~mqc_mbe_io->module~mqc_physical_fragment module~mqc_mbe_io->pic_io module~mqc_mbe_io->pic_logger module~mqc_mbe_io->pic_types module~mqc_method_base->module~mqc_physical_fragment module~mqc_method_base->module~mqc_result_types module~mqc_method_base->pic_types module~mqc_method_factory->module~mqc_method_config module~mqc_method_factory->module~mqc_method_types module~mqc_method_factory->pic_types module~mqc_method_factory->module~mqc_method_base mctc_env mctc_env module~mqc_method_factory->mctc_env module~mqc_method_dft mqc_method_dft module~mqc_method_factory->module~mqc_method_dft module~mqc_method_hf mqc_method_hf module~mqc_method_factory->module~mqc_method_hf module~mqc_method_mcscf mqc_method_mcscf module~mqc_method_factory->module~mqc_method_mcscf module~mqc_method_xtb mqc_method_xtb module~mqc_method_factory->module~mqc_method_xtb module~mqc_mpi_comms->pic_mpi_lib module~mqc_mpi_tags->pic_types module~mqc_physical_constants->pic_types module~mqc_program_limits->pic_types module~mqc_thermochemistry->module~mqc_elements module~mqc_thermochemistry->pic_io module~mqc_thermochemistry->pic_logger module~mqc_thermochemistry->pic_types module~mqc_thermochemistry->module~mqc_physical_constants pic_lapack_interfaces pic_lapack_interfaces module~mqc_thermochemistry->pic_lapack_interfaces module~mqc_vibrational_analysis->module~mqc_elements module~mqc_vibrational_analysis->pic_logger module~mqc_vibrational_analysis->pic_types module~mqc_vibrational_analysis->module~mqc_physical_constants module~mqc_vibrational_analysis->module~mqc_thermochemistry module~mqc_vibrational_analysis->pic_lapack_interfaces module~mqc_xyz_reader->module~mqc_error module~mqc_xyz_reader->pic_types module~mqc_xyz_reader->module~mqc_geometry module~mqc_method_dft->module~mqc_physical_fragment module~mqc_method_dft->module~mqc_result_types module~mqc_method_dft->pic_types module~mqc_method_dft->module~mqc_method_base module~mqc_method_hf->module~mqc_physical_fragment module~mqc_method_hf->module~mqc_result_types module~mqc_method_hf->pic_types module~mqc_method_hf->module~mqc_method_base module~mqc_method_mcscf->module~mqc_physical_fragment module~mqc_method_mcscf->module~mqc_result_types module~mqc_method_mcscf->pic_types module~mqc_method_mcscf->module~mqc_method_base module~mqc_method_xtb->module~mqc_error module~mqc_method_xtb->module~mqc_physical_fragment module~mqc_method_xtb->module~mqc_result_types module~mqc_method_xtb->pic_logger module~mqc_method_xtb->pic_types module~mqc_method_xtb->module~mqc_method_base module~mqc_method_xtb->pic_timer module~mqc_method_xtb->mctc_env mctc_io mctc_io module~mqc_method_xtb->mctc_io tblite_container tblite_container module~mqc_method_xtb->tblite_container tblite_context_type tblite_context_type module~mqc_method_xtb->tblite_context_type tblite_solvation tblite_solvation module~mqc_method_xtb->tblite_solvation tblite_wavefunction tblite_wavefunction module~mqc_method_xtb->tblite_wavefunction tblite_xtb_calculator tblite_xtb_calculator module~mqc_method_xtb->tblite_xtb_calculator tblite_xtb_gfn1 tblite_xtb_gfn1 module~mqc_method_xtb->tblite_xtb_gfn1 tblite_xtb_gfn2 tblite_xtb_gfn2 module~mqc_method_xtb->tblite_xtb_gfn2 tblite_xtb_singlepoint tblite_xtb_singlepoint module~mqc_method_xtb->tblite_xtb_singlepoint

Compute energy and forces for current geometry This is the main interface for optimization/dynamics codes

Master rank provides updated geometry, all ranks compute fragments, results are returned on master rank only

Usage: 1. Master rank updates sys_geom%coordinates 2. Call this subroutine (all ranks) 3. Master rank receives energy/gradient/hessian 4. Master rank updates geometry based on forces 5. Repeat from step 1

Arguments

Type IntentOptional Attributes Name
type(system_geometry_t), intent(inout) :: sys_geom
type(driver_config_t), intent(in) :: driver_config
type(resources_t), intent(in) :: resources
real(kind=dp), intent(out) :: energy
real(kind=dp), intent(out), optional :: gradient(:,:)

(3, total_atoms)

real(kind=dp), intent(out), optional :: hessian(:,:)

(3total_atoms, 3total_atoms)

type(bond_t), intent(in), optional :: bonds(:)

Calls

proc~~compute_energy_and_forces~~CallsGraph proc~compute_energy_and_forces compute_energy_and_forces abort_comm abort_comm proc~compute_energy_and_forces->abort_comm error error proc~compute_energy_and_forces->error proc~energy_total energy_t%energy_total proc~compute_energy_and_forces->proc~energy_total proc~result_destroy calculation_result_t%result_destroy proc~compute_energy_and_forces->proc~result_destroy proc~run_calculation run_calculation proc~compute_energy_and_forces->proc~run_calculation proc~sync_geometry_to_workers sync_geometry_to_workers proc~compute_energy_and_forces->proc~sync_geometry_to_workers proc~mp2_total mp2_energy_t%mp2_total proc~energy_total->proc~mp2_total proc~result_reset calculation_result_t%result_reset proc~result_destroy->proc~result_reset info info proc~run_calculation->info omp_set_num_threads omp_set_num_threads proc~run_calculation->omp_set_num_threads proc~config_log_settings method_config_t%config_log_settings proc~run_calculation->proc~config_log_settings proc~json_output_data_destroy json_output_data_t%json_output_data_destroy proc~run_calculation->proc~json_output_data_destroy proc~run_fragmented_calculation run_fragmented_calculation proc~run_calculation->proc~run_fragmented_calculation proc~run_unfragmented_calculation run_unfragmented_calculation proc~run_calculation->proc~run_unfragmented_calculation proc~write_json_output write_json_output proc~run_calculation->proc~write_json_output to_char to_char proc~run_calculation->to_char warning warning proc~run_calculation->warning proc~config_log_settings->info proc~xtb_get_solvation_info xtb_config_t%xtb_get_solvation_info proc~config_log_settings->proc~xtb_get_solvation_info proc~json_output_data_reset json_output_data_t%json_output_data_reset proc~json_output_data_destroy->proc~json_output_data_reset proc~energy_reset energy_t%energy_reset proc~result_reset->proc~energy_reset proc~error_clear error_t%error_clear proc~result_reset->proc~error_clear proc~run_fragmented_calculation->abort_comm proc~run_fragmented_calculation->error proc~run_fragmented_calculation->info proc~run_fragmented_calculation->to_char allgather allgather proc~run_fragmented_calculation->allgather bcast bcast proc~run_fragmented_calculation->bcast destroy destroy proc~run_fragmented_calculation->destroy init init proc~run_fragmented_calculation->init proc~apply_distance_screening apply_distance_screening proc~run_fragmented_calculation->proc~apply_distance_screening proc~binomial binomial proc~run_fragmented_calculation->proc~binomial proc~combine combine proc~run_fragmented_calculation->proc~combine proc~create_monomer_list create_monomer_list proc~run_fragmented_calculation->proc~create_monomer_list proc~error_get_message error_t%error_get_message proc~run_fragmented_calculation->proc~error_get_message proc~error_has_error error_t%error_has_error proc~run_fragmented_calculation->proc~error_has_error proc~generate_fragment_list generate_fragment_list proc~run_fragmented_calculation->proc~generate_fragment_list proc~get_nfrags get_nfrags proc~run_fragmented_calculation->proc~get_nfrags proc~gmbe_enumerate_pie_terms gmbe_enumerate_pie_terms proc~run_fragmented_calculation->proc~gmbe_enumerate_pie_terms proc~sort_fragments_by_size sort_fragments_by_size proc~run_fragmented_calculation->proc~sort_fragments_by_size run_distributed run_distributed proc~run_fragmented_calculation->run_distributed run_serial run_serial proc~run_fragmented_calculation->run_serial proc~run_unfragmented_calculation->info proc~run_unfragmented_calculation->to_char interface~distributed_unfragmented_hessian distributed_unfragmented_hessian proc~run_unfragmented_calculation->interface~distributed_unfragmented_hessian interface~unfragmented_calculation unfragmented_calculation proc~run_unfragmented_calculation->interface~unfragmented_calculation proc~calc_type_to_string calc_type_to_string proc~run_unfragmented_calculation->proc~calc_type_to_string verbose verbose proc~run_unfragmented_calculation->verbose proc~write_json_output->error proc~write_gmbe_pie_json_impl write_gmbe_pie_json_impl proc~write_json_output->proc~write_gmbe_pie_json_impl proc~write_mbe_breakdown_json_impl write_mbe_breakdown_json_impl proc~write_json_output->proc~write_mbe_breakdown_json_impl proc~write_unfragmented_json_impl write_unfragmented_json_impl proc~write_json_output->proc~write_unfragmented_json_impl proc~write_vibrational_json_impl write_vibrational_json_impl proc~write_json_output->proc~write_vibrational_json_impl proc~distributed_unfragmented_hessian distributed_unfragmented_hessian interface~distributed_unfragmented_hessian->proc~distributed_unfragmented_hessian proc~unfragmented_calculation unfragmented_calculation interface~unfragmented_calculation->proc~unfragmented_calculation proc~apply_distance_screening->info proc~apply_distance_screening->to_char proc~fragment_should_be_screened fragment_should_be_screened proc~apply_distance_screening->proc~fragment_should_be_screened proc~combine_util combine_util proc~combine->proc~combine_util proc~mp2_reset mp2_energy_t%mp2_reset proc~energy_reset->proc~mp2_reset proc~generate_fragment_list->proc~combine proc~get_nfrags->proc~binomial proc~gmbe_enumerate_pie_terms->info proc~gmbe_enumerate_pie_terms->to_char proc~gmbe_enumerate_pie_terms->proc~error_has_error atom_list atom_list proc~gmbe_enumerate_pie_terms->atom_list proc~compute_polymer_atoms compute_polymer_atoms proc~gmbe_enumerate_pie_terms->proc~compute_polymer_atoms proc~dfs_pie_accumulate dfs_pie_accumulate proc~gmbe_enumerate_pie_terms->proc~dfs_pie_accumulate proc~error_set error_t%error_set proc~gmbe_enumerate_pie_terms->proc~error_set proc~sort_fragments_by_size->info sort_index sort_index proc~sort_fragments_by_size->sort_index proc~write_gmbe_pie_json_impl->error proc~write_gmbe_pie_json_impl->info proc~write_gmbe_pie_json_impl->destroy add add proc~write_gmbe_pie_json_impl->add create_array create_array proc~write_gmbe_pie_json_impl->create_array create_object create_object proc~write_gmbe_pie_json_impl->create_object initialize initialize proc~write_gmbe_pie_json_impl->initialize proc~get_basename get_basename proc~write_gmbe_pie_json_impl->proc~get_basename proc~get_output_json_filename get_output_json_filename proc~write_gmbe_pie_json_impl->proc~get_output_json_filename proc~write_mbe_breakdown_json_impl->error proc~write_mbe_breakdown_json_impl->info proc~write_mbe_breakdown_json_impl->warning proc~write_mbe_breakdown_json_impl->destroy proc~write_mbe_breakdown_json_impl->add proc~write_mbe_breakdown_json_impl->create_array proc~write_mbe_breakdown_json_impl->create_object proc~write_mbe_breakdown_json_impl->initialize proc~write_mbe_breakdown_json_impl->proc~get_basename proc~get_frag_level_name get_frag_level_name proc~write_mbe_breakdown_json_impl->proc~get_frag_level_name proc~write_mbe_breakdown_json_impl->proc~get_output_json_filename proc~write_unfragmented_json_impl->error proc~write_unfragmented_json_impl->info proc~write_unfragmented_json_impl->destroy proc~write_unfragmented_json_impl->add proc~write_unfragmented_json_impl->create_object proc~write_unfragmented_json_impl->initialize proc~write_unfragmented_json_impl->proc~get_basename proc~write_unfragmented_json_impl->proc~get_output_json_filename proc~write_vibrational_json_impl->error proc~write_vibrational_json_impl->info proc~write_vibrational_json_impl->destroy proc~write_vibrational_json_impl->add proc~write_vibrational_json_impl->create_object proc~write_vibrational_json_impl->initialize proc~write_vibrational_json_impl->proc~get_basename proc~write_vibrational_json_impl->proc~get_output_json_filename proc~xtb_get_solvation_info->to_char proc~xtb_has_solvation xtb_config_t%xtb_has_solvation proc~xtb_get_solvation_info->proc~xtb_has_solvation proc~combine_util->proc~combine_util proc~dfs_pie_accumulate->proc~error_has_error proc~dfs_pie_accumulate->proc~dfs_pie_accumulate new_clique new_clique proc~dfs_pie_accumulate->new_clique proc~atom_sets_equal atom_sets_equal proc~dfs_pie_accumulate->proc~atom_sets_equal proc~grow_pie_storage grow_pie_storage proc~dfs_pie_accumulate->proc~grow_pie_storage proc~intersect_atom_lists intersect_atom_lists proc~dfs_pie_accumulate->proc~intersect_atom_lists test_intersect test_intersect proc~dfs_pie_accumulate->test_intersect barrier barrier proc~distributed_unfragmented_hessian->barrier interface~hessian_coordinator hessian_coordinator proc~distributed_unfragmented_hessian->interface~hessian_coordinator interface~hessian_worker hessian_worker proc~distributed_unfragmented_hessian->interface~hessian_worker 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~unfragmented_calculation->error proc~unfragmented_calculation->proc~energy_total proc~unfragmented_calculation->proc~result_destroy proc~unfragmented_calculation->info proc~unfragmented_calculation->to_char proc~unfragmented_calculation->proc~error_get_message proc~unfragmented_calculation->proc~error_has_error cart_disp cart_disp proc~unfragmented_calculation->cart_disp configuration configuration proc~unfragmented_calculation->configuration eigenvalues eigenvalues proc~unfragmented_calculation->eigenvalues fc_mdyne fc_mdyne proc~unfragmented_calculation->fc_mdyne force_constants force_constants proc~unfragmented_calculation->force_constants frequencies frequencies proc~unfragmented_calculation->frequencies interface~do_fragment_work do_fragment_work proc~unfragmented_calculation->interface~do_fragment_work ir_intensities ir_intensities proc~unfragmented_calculation->ir_intensities proc~check_duplicate_atoms check_duplicate_atoms proc~unfragmented_calculation->proc~check_duplicate_atoms proc~compute_thermochemistry compute_thermochemistry proc~unfragmented_calculation->proc~compute_thermochemistry proc~compute_vibrational_analysis compute_vibrational_analysis proc~unfragmented_calculation->proc~compute_vibrational_analysis proc~compute_vibrational_frequencies compute_vibrational_frequencies proc~unfragmented_calculation->proc~compute_vibrational_frequencies proc~error_get_full_trace error_t%error_get_full_trace proc~unfragmented_calculation->proc~error_get_full_trace proc~fragment_compute_nelec physical_fragment_t%fragment_compute_nelec proc~unfragmented_calculation->proc~fragment_compute_nelec proc~print_vibrational_analysis print_vibrational_analysis proc~unfragmented_calculation->proc~print_vibrational_analysis projected_hessian projected_hessian proc~unfragmented_calculation->projected_hessian reduced_masses reduced_masses proc~unfragmented_calculation->reduced_masses

Variables

Type Visibility Attributes Name Initial
logical, private :: need_gradient
logical, private :: need_hessian
type(calculation_result_t), private :: result

Source Code

   subroutine compute_energy_and_forces(sys_geom, driver_config, resources, &
                                        energy, gradient, hessian, bonds)
      !! Compute energy and forces for current geometry
      !! This is the main interface for optimization/dynamics codes
      !!
      !! Master rank provides updated geometry, all ranks compute fragments,
      !! results are returned on master rank only
      !!
      !! Usage:
      !!   1. Master rank updates sys_geom%coordinates
      !!   2. Call this subroutine (all ranks)
      !!   3. Master rank receives energy/gradient/hessian
      !!   4. Master rank updates geometry based on forces
      !!   5. Repeat from step 1
      use mqc_driver, only: run_calculation
      use mqc_config_adapter, only: driver_config_t
      type(system_geometry_t), intent(inout) :: sys_geom
      type(driver_config_t), intent(in) :: driver_config
      type(resources_t), intent(in) :: resources
      real(dp), intent(out) :: energy
      real(dp), intent(out), optional :: gradient(:, :)  !! (3, total_atoms)
      real(dp), intent(out), optional :: hessian(:, :)  !! (3*total_atoms, 3*total_atoms)
      type(bond_t), intent(in), optional :: bonds(:)

      type(calculation_result_t) :: result
      logical :: need_gradient, need_hessian

      ! Determine what we need based on what's requested
      need_gradient = present(gradient)
      need_hessian = present(hessian)

      ! Synchronize geometry from master to all ranks
      ! (Master may have updated coordinates for optimization/dynamics)
      call sync_geometry_to_workers(sys_geom, resources%mpi_comms%world_comm)

      ! Call the main calculation driver
      ! This handles both fragmented and unfragmented cases
      call run_calculation(resources, driver_config, sys_geom, bonds, result)

      ! Extract results (only valid on master rank)
      if (resources%mpi_comms%world_comm%rank() == 0) then
         energy = result%energy%total()

         if (need_gradient .and. result%has_gradient) then
            gradient = result%gradient
         else if (need_gradient) then
            call logger%error("Gradient requested but not computed!")
            call abort_comm(resources%mpi_comms%world_comm, 1)
         end if

         if (need_hessian .and. result%has_hessian) then
            hessian = result%hessian
         else if (need_hessian) then
            call logger%error("Hessian requested but not computed!")
            call abort_comm(resources%mpi_comms%world_comm, 1)
         end if

         ! Clean up
         call result%destroy()
      end if

   end subroutine compute_energy_and_forces