Count how many hydrogen caps are needed for a fragment A cap is needed when exactly one atom of a broken bond is in the fragment
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | atoms_in_fragment(:) |
0-indexed atom indices in fragment |
||
| type(bond_t), | intent(in), | optional | :: | bonds(:) | ||
| integer, | intent(out) | :: | n_caps |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | private | :: | atom_i_in_frag | ||||
| logical, | private | :: | atom_j_in_frag | ||||
| integer, | private | :: | ibond |
subroutine count_hydrogen_caps(atoms_in_fragment, bonds, n_caps) !! Count how many hydrogen caps are needed for a fragment !! A cap is needed when exactly one atom of a broken bond is in the fragment integer, intent(in) :: atoms_in_fragment(:) !! 0-indexed atom indices in fragment type(bond_t), intent(in), optional :: bonds(:) integer, intent(out) :: n_caps integer :: ibond logical :: atom_i_in_frag, atom_j_in_frag n_caps = 0 if (.not. present(bonds)) return do ibond = 1, size(bonds) if (.not. bonds(ibond)%is_broken) cycle ! Check if exactly one atom of this bond is in the fragment atom_i_in_frag = any(atoms_in_fragment == bonds(ibond)%atom_i) atom_j_in_frag = any(atoms_in_fragment == bonds(ibond)%atom_j) ! Add cap only if one atom in fragment, other not (XOR condition) if ((atom_i_in_frag .and. .not. atom_j_in_frag) .or. & (.not. atom_i_in_frag .and. atom_j_in_frag)) then n_caps = n_caps + 1 end if end do end subroutine count_hydrogen_caps