Tuesday, May 5, 2009

More on Ex4

Hi all-

In your Fortran loop to compute the interaction energies between a selected atom and all other atoms, you will have to modify the test between atoms i and j to see if they are bonded or not. The reason behind this is that your loop will no longer run over pairs (i,j) such that j > i always. The following Fortran code will test if any two i or j are bonded:

abs(i-j) == 1 .and. mod(max(i, j), M) > 0

Also, if you are using f2py, be sure to keep in mind that you should always place dimension variables (e.g., NAtom, Dim) at the end of your subroutine declaration statement. The reason for this is that f2py will automatically re-order subroutine arguments this way, and it might come as unexpected when you are calling these compiled routines from Python. In any case, you do not need to send these variables to the Fortran routine when you call them from Python as f2py will automatically take them from the dimensions of the other variables you send (e.g., Pos).

Cheers,
MSS

No comments: