I have this piece of code which calculate coordination numbers around a specific atom. The code below works well to calculate the coordination numbers around Si and Al atoms. Now I want to increase number of atoms ,for example at Ca and Mg.then from there I want to work out this relationship: when an oxygen is bridging, does it form a Si-O-Si, Al-O-Si or Al-O-Al linkage and also establish the number of oxygens involved in bonding. Any idea how can I implement this? I am able to calculate for instance the Si-O or Al-O, but how do I include the third atom to complete the bonding as shown above.

Your help will be much appreciated.

[ atname(1) = 'Si'

atname(2) = 'Al'

atname(3) = 'O'

shell(1) = 2.275d0

shell(2) = 2.475d0

write(9,*)' Start Frame ',iconf,atname(1),atname(3)

do i = 1,natms

if (atmnam(i) .eq. atname(1)) then

do j = 1,natms

if (atmnam(j) .eq. atname(3)) then

if (d(i,j) .le. shell(1)) then

write(9,*)i,j,d(i,j)

nbl(i,j) = 1

nb(i)=nb(i)+1

endif

endif

enddo

endif

enddo

write(9,*)' End Frame '

write(9,*)' Start Frame ',iconf,atname(2),atname(3)

do i = 1,natms

if (atmnam(i) .eq. atname(2)) then

do j = 1,natms

if (atmnam(j) .eq. atname(3)) then

if (d(i,j) .le. shell(2)) then

write(9,*)i,j,d(i,j)

nbl(i,j) = 1

c nb(i)=nb(i)+1

endif

endif

enddo

endif

enddo

write(9,*)' End Frame '

]