Validate that fragment has no spatially overlapping atoms Checks if any two atoms are too close together (< 0.01 Bohr) This catches bugs in geometry construction or fragment building
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(physical_fragment_t), | intent(in) | :: | fragment | |||
| type(error_t), | intent(out) | :: | error |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| real(kind=dp), | private, | parameter | :: | MIN_ATOM_DISTANCE | = | 0.01_dp |
Bohr - atoms closer than this are overlapping |
| real(kind=dp), | private | :: | distance | ||||
| real(kind=dp), | private | :: | dx | ||||
| real(kind=dp), | private | :: | dy | ||||
| real(kind=dp), | private | :: | dz | ||||
| integer, | private | :: | i | ||||
| integer, | private | :: | j | ||||
| integer, | private | :: | n_atoms |
subroutine check_duplicate_atoms(fragment, error) !! Validate that fragment has no spatially overlapping atoms !! Checks if any two atoms are too close together (< 0.01 Bohr) !! This catches bugs in geometry construction or fragment building use pic_logger, only: logger => global_logger use pic_io, only: to_char type(physical_fragment_t), intent(in) :: fragment type(error_t), intent(out) :: error integer :: i, j, n_atoms real(dp) :: distance, dx, dy, dz real(dp), parameter :: MIN_ATOM_DISTANCE = 0.01_dp !! Bohr - atoms closer than this are overlapping ! Only check non-cap atoms (caps can be close to replaced atoms) n_atoms = fragment%n_atoms - fragment%n_caps if (n_atoms < 2) return do i = 1, n_atoms - 1 do j = i + 1, n_atoms dx = fragment%coordinates(1, i) - fragment%coordinates(1, j) dy = fragment%coordinates(2, i) - fragment%coordinates(2, j) dz = fragment%coordinates(3, i) - fragment%coordinates(3, j) distance = sqrt(dx*dx + dy*dy + dz*dz) if (distance < MIN_ATOM_DISTANCE) then ! Build detailed error message call error%set(ERROR_VALIDATION, & "Fragment contains overlapping atoms "//to_char(i)//" and "//to_char(j)// & " (distance: "//to_char(distance)//" Bohr). "// & "This indicates bad input geometry or a bug in fragment construction.") ! Log detailed information for debugging call logger%error("ERROR: Fragment contains overlapping atoms!") call logger%error(" Atoms "//to_char(i)//" and "//to_char(j)//" are too close together") call logger%error(" Distance: "//to_char(distance)//" Bohr ("// & to_char(distance*0.529177_dp)//" Angstrom)") call logger%error(" Atom "//to_char(i)//": "// & element_number_to_symbol(fragment%element_numbers(i))// & " at ("//to_char(fragment%coordinates(1, i))//", "// & to_char(fragment%coordinates(2, i))//", "// & to_char(fragment%coordinates(3, i))//") Bohr") call logger%error(" Atom "//to_char(j)//": "// & element_number_to_symbol(fragment%element_numbers(j))// & " at ("//to_char(fragment%coordinates(1, j))//", "// & to_char(fragment%coordinates(2, j))//", "// & to_char(fragment%coordinates(3, j))//") Bohr") return end if end do end do end subroutine check_duplicate_atoms