INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Code last bits

## Code last bits

(OP)
Dear Forum users

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 '
]

### RE: Code last bits

If you jam your loops, what you will get is

#### CODE

integer, parameter:: nat = 3
character(len=2):: atname(nat)
...
do k = 1, nat - 1
write(9,*)' Start Frame ',iconf,atname(k),atname(nat)
do i = 1,natms
if (atmnam(i) .eq. atname(k)) then
do j = 1,natms
if (atmnam(j) .eq. atname(k)) then
if (d(i,j) .le. shell(k)) then
write(9,*)i,j,d(i,j)
nbl(i,j) = 1
if (k .eq. 1) nb(i)=nb(i)+1
endif
endif
enddo
endif
enddo
write(9,*)' End Frame '
enddo 
Try that first and see if the results are the same as what you have now.

If they are the same, if you then increase nat and the sizes of the arrays of the other relevant variables like atname, d, shell, nbl you may be able to achieve what you wish.

### RE: Code last bits

(OP)
Thanks a lot XWB

I this think this is an elegant way of doing it,I assume atname(k),atname(nat) are general statements I thing I should replace them with atname(1) = 'Si' as an example and shell k replace it with shell 1 ,correct me if im wrong. Then that will take care of bonding between atom 1 and atom 2, then I would need to add statement for atom2 linked to atom 2 and atom 3 must also fall within the shell of atom 2. Can let me know how do I do this ?

Kind regards
Lehloks

### RE: Code last bits

Sorry, error in the coding

#### CODE

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

#### CODE

if (atmnam(j) .eq. atname(nat)) then
In the 2nd loop, it goes through atname(1) and atname(2). The third loop should compare it with atname(3).

My Chemistry is zilch - I last looked at this topic 40 years ago and I can't remember anything about it. In simple minded computing terms, it is just a question of permutations and combinations. For 4 items, do you want to compute just

1-4, 2-4, 3-4 or
1-2, 2-3, 2-4, 3-4 or
something else

Basically what pattern of combinations do you want when there are more than 3 items in atname. Could you work out what patterns you want to see when there are 5 items in the list.

### RE: Code last bits

(OP)
Hi XWB

I want this pattern 1-4. Let me try it.

Regards
Lehloks

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!