## numbers that can differentiate uniquely between the combinations

## numbers that can differentiate uniquely between the combinations

(OP)

Hi forum users

I need a set of numbers that can differentiate uniquely between the combinations.I choose powers of 3. Starting with 1, that gives multiples of 1, 2 and 3 before I reach the next number, which is 3, with it having multiples of 3, 6, 9, etc. If I write out the combinations you can see what happens when you add them:

1 = 1 (eg. 1 Si)

2 = 1 + 1 (eg. 2 Si)

3 = 1 +

1 + 1 (e.g. 3 Si) or 3 (e.g. 1 Al) alone, and so now I have a problem, I can pick up 1 occurrence of the atom labelled 1, and two occurrences, but then one Al will give the same result as 3 Si. Since the Al atoms with their labels of 3 have multiples of 6, 9, etc, I'll never accidently find 4, 5 and/or 7/8, which I can only reach once I'm adding multiples of 1. With this set I can thus give a unique number to each possible combination of the two (but not three). I can pick any way forward, as long as you make sure that you get unique combinations every time.

Now Im stuck I want extend the assignment to 5 atoms : eg assigning a special number for other atoms like Mg,Ca, O and Na. Any one with a unique idea how can I do this. I want a code to be general so that It can be used for many things. I can assign atom name but my code wont be efficient and it will have many if statements.My assignments are shown in the code below.

[! Assign Si = 3**0 = 1, Al = 3**1 = 3 and unknown metals U = 3**2 = 9

! then we can identify pairs and triads easily without ordering

! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2

! [Si,Al] = [Al,Si] = 1 + 3 = 4

! [Al,Al] = 3 + 3 = 6

! [U,U] = 9 + 9 = 18

! [Al,U] = 3 + 9 = 12

! [Si,U] = 1 + 9 = 10

! [Si,Si,Si] = 1 + 1 + 1 = 3

! [Si,Si,Al] = 1 + 1 + 3 = 5

! [Si,Al,Al] = 1 + 3 + 3 = 7

! [Al,Al,Al] = 3 + 3 + 3 = 9

! [U,U,U] = 9 + 9 + 9 = 27

! [U,U,Si] = 9 + 9 + 1 = 19

! [U,U,Ai] = 9 + 9 + 3 = 21

! [U,Si,Si] = 9 + 1 + 1 = 11

! [U,Si,Al] = 9 + 1 + 4 = 14

! [U,Al,Al] = 9 + 3 + 3 = 15]

[do i = 1, natms

if (atmname(i) == silicon) then

id(i) = Si

elseif (atmname(i) == aluminium) then

id(i) = Al

else

id(i) = 9

endif

enddo

do i = 1, natms

do k = 1, nmetals

if (atmname(i) == metals(k)) then

do j = i, natms

if (atmname(j) == oxygen) then

bndtab(i,j) = mbonds(k)**2

bndtab(j,i) = bndtab(i,j)

endif

enddo

endif

enddo

enddo

endif

]

Then when I get the assignment correctly I want to use the code as this where I sect a correct or desired case as shown below.

[do i = 1, natms

if ((atmname(i) == oxygen) .and. (cnlist(i) .eq. 2)) then

select case ( id(blist(bindex(i))) + id(blist(bindex(i)+1)) )

case (2)

write(logfile,*)'[Si,Si] bridge'

nbo = nbo + 1

case (4)

write(logfile,*)'[Si,Al] bridge'

nbo = nbo + 1

case (6)

write(logfile,*)'[Al,Al] bridge'

nbo = nbo + 1

case (10)

write(logfile,*)'[Si,Ca/Mg] disconnect'

nnbo = nnbo + 1

case (12)

write(logfile,*)'[Al,Ca/Mg] disconnect'

nnbo = nnbo + 1

case (18)

write(logfile,*)'[Mg/Ca,Ca/Mg] disconnect'

end select

endif

]

I need a set of numbers that can differentiate uniquely between the combinations.I choose powers of 3. Starting with 1, that gives multiples of 1, 2 and 3 before I reach the next number, which is 3, with it having multiples of 3, 6, 9, etc. If I write out the combinations you can see what happens when you add them:

1 = 1 (eg. 1 Si)

2 = 1 + 1 (eg. 2 Si)

3 = 1 +

1 + 1 (e.g. 3 Si) or 3 (e.g. 1 Al) alone, and so now I have a problem, I can pick up 1 occurrence of the atom labelled 1, and two occurrences, but then one Al will give the same result as 3 Si. Since the Al atoms with their labels of 3 have multiples of 6, 9, etc, I'll never accidently find 4, 5 and/or 7/8, which I can only reach once I'm adding multiples of 1. With this set I can thus give a unique number to each possible combination of the two (but not three). I can pick any way forward, as long as you make sure that you get unique combinations every time.

Now Im stuck I want extend the assignment to 5 atoms : eg assigning a special number for other atoms like Mg,Ca, O and Na. Any one with a unique idea how can I do this. I want a code to be general so that It can be used for many things. I can assign atom name but my code wont be efficient and it will have many if statements.My assignments are shown in the code below.

[! Assign Si = 3**0 = 1, Al = 3**1 = 3 and unknown metals U = 3**2 = 9

! then we can identify pairs and triads easily without ordering

! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2

! [Si,Al] = [Al,Si] = 1 + 3 = 4

! [Al,Al] = 3 + 3 = 6

! [U,U] = 9 + 9 = 18

! [Al,U] = 3 + 9 = 12

! [Si,U] = 1 + 9 = 10

! [Si,Si,Si] = 1 + 1 + 1 = 3

! [Si,Si,Al] = 1 + 1 + 3 = 5

! [Si,Al,Al] = 1 + 3 + 3 = 7

! [Al,Al,Al] = 3 + 3 + 3 = 9

! [U,U,U] = 9 + 9 + 9 = 27

! [U,U,Si] = 9 + 9 + 1 = 19

! [U,U,Ai] = 9 + 9 + 3 = 21

! [U,Si,Si] = 9 + 1 + 1 = 11

! [U,Si,Al] = 9 + 1 + 4 = 14

! [U,Al,Al] = 9 + 3 + 3 = 15]

[do i = 1, natms

if (atmname(i) == silicon) then

id(i) = Si

elseif (atmname(i) == aluminium) then

id(i) = Al

else

id(i) = 9

endif

enddo

do i = 1, natms

do k = 1, nmetals

if (atmname(i) == metals(k)) then

do j = i, natms

if (atmname(j) == oxygen) then

bndtab(i,j) = mbonds(k)**2

bndtab(j,i) = bndtab(i,j)

endif

enddo

endif

enddo

enddo

endif

]

Then when I get the assignment correctly I want to use the code as this where I sect a correct or desired case as shown below.

[do i = 1, natms

if ((atmname(i) == oxygen) .and. (cnlist(i) .eq. 2)) then

select case ( id(blist(bindex(i))) + id(blist(bindex(i)+1)) )

case (2)

write(logfile,*)'[Si,Si] bridge'

nbo = nbo + 1

case (4)

write(logfile,*)'[Si,Al] bridge'

nbo = nbo + 1

case (6)

write(logfile,*)'[Al,Al] bridge'

nbo = nbo + 1

case (10)

write(logfile,*)'[Si,Ca/Mg] disconnect'

nnbo = nnbo + 1

case (12)

write(logfile,*)'[Al,Ca/Mg] disconnect'

nnbo = nnbo + 1

case (18)

write(logfile,*)'[Mg/Ca,Ca/Mg] disconnect'

end select

endif

]

## RE: numbers that can differentiate uniquely between the combinations

If you are interested in combining any two atoms at a time, you can assign them numbers that are powers of 2; with the limitation that every atom can only appear once in a combination.

If you are interested in combining any 3 atoms at a time, you can assign them numbers that are powers of 3; with the limitation that every atom can only appear 2 times in a combination.

If you are interested in combining any 4 atoms at a time, you can assign them numbers that are powers of 4; with the limitation that every atom can only appear 3 times in a combination.

...and so on.

I think this way, every combination will have a unique number and to find out which atoms are part of the combination, you just start dividing by the largest number that you have assigned, see how many times it fits and work your way down with the residual and the next assigned number down.

## RE: numbers that can differentiate uniquely between the combinations

Can you illustrate with an example so that I can see your approach for example demonstrate using this statement.If you are interested in combining any 3 atoms at a time, you can assign them numbers that are powers of 3; with the limitation that every atom can only appear 2 times in a combination.

The combination that appears two times its interesting. In my initial thinking,I thought about read,write and execute permissions (rwx) where r or w can only appear once not repeated. But Im interested in a situation where an atom can appear twice only as you stated.

Regards

Lehloks

## RE: numbers that can differentiate uniquely between the combinations

Depending on the number of atoms, you want to combine, I suggest to choose the highest possible value. For instance 10 !

Si=1

Al=10

U=100

5 => Si+Si+Si+Si+Si

11 => Al+Si

111 => U+Al+Si

...

François Jacq

## RE: numbers that can differentiate uniquely between the combinations

See here:

http://en.wikipedia.org/wiki/Fundamental_theorem_o...

For example there are these first 10 primes:

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

1. You can encode with it 10 chemical elements, e.g.:

Si = 2

Al = 3

U = 5

...

etc.

2. Then you can encode any combination of your elements, for example

4*Si, 1*Al, 2*U

into an integer number using the formula given in the link above:

N = 2**4 * 3**1 * 5**2 = 1200

3. You can decode the number using an factorization algorithm such like

http://en.wikipedia.org/wiki/Trial_division

and get back the primes - for example for N=1200 we get:

[2, 2, 2, 2, 3, 5, 5]

that is

4*2, 1*3, 2*5

looking at the encoding table above we have the combination

4*Si, 1*Al, 2*U

Here is my working prototype in Python - it could be possible to rewrite it in Fortran:

## CODE

Output:

## CODE

## RE: numbers that can differentiate uniquely between the combinations

With these Ideas I can also be able to work out how long my Si and Al polymer chains. I like the most mikrom Idea.But one more question just for interest is it possible to work out the combination in advance because of systems with varrying number of atoms one of them is 2377 atoms = N

thanks a lot.

## RE: numbers that can differentiate uniquely between the combinations

I found out that there are only 118 chemical elements:

http://en.wikipedia.org/wiki/List_of_elements

If you will have 118 chemical elements and want to use the prime factorizatione method, you will need the first 118 prime numbers - see http://en.wikipedia.org/wiki/List_of_prime_numbers

Then the resulting numbers for encoding your elements combination could be very huge, so maybe you will have technical problems using build in integer types ...

The factorization of huge numbers using the trial division method would be hard, because of its exponential complexity, so maybe you will have to search for more efficient method ...

I suggest to try the approach first on a smaller number of elements and see how it works and if it fullfil your expectations.

## RE: numbers that can differentiate uniquely between the combinations

Sorry for this!

I meant system size made up of 2377 atoms,with 5 atom types.

## RE: numbers that can differentiate uniquely between the combinations

IMO it will be OK.

## RE: numbers that can differentiate uniquely between the combinations

Assigning unique ID for every atom using powers of (n+1) where n is the maximum number of times you want a given atom to be able to appear in the combination gets a bit crazy quick...now that you mention that an atom may have to appear hundreds or even a thousand times in a combination. For example, if you want an atom be able to appear 999 times in a combination, you would need to assign ID to atoms as powers of 1000...for 5 atoms involved in the combination, their IDs would be 1000, 1000000, 1000000000, 1000000000000, 1000000000000000. And the summation of these numbers hundreds of times will get very large. The main problem with this approach is the exponential growth of ID and, consequently, the large gap of unused IDs in between consecutive IDs...for a final combination ID being a very large number.

I too like the prime number approach. In that case, the gap between unused IDs is rather small, keeping all IDs also small...the only problem is that the final combination ID is no longer the summation of ID, but the multiplication of their exponentiation...this is going to get large, too, if any one of them needs to be raised to the 1000 power!

If you assign permanent IDs to each atom and you have 118 of them, possibly in the same order as the periodic table, some will necessarily get assigned a rather large prime number that when raised to a power of 800 it is going to be a rather large number. This approach allows you to have unique IDs for every combination, but the combination IDs will get unnecessarily large or impossible to store as numeric value.

One way to alleviate the problem above is to not limit yourself to specifying combinations via a single attribute (unique ID), instead, create a structure and include the list of atoms that are going to be part of the combination and assign to this atoms the first few prime numbers and that is it...combination numbers would be unique on a per set-of-atoms-involved basis....even 2**1000, though, is large.

Any particular reason why you are not simply using strings? : "(1602*H)(800*C)"

- they can be put together easily and consistently...need to develop strategy of listing atoms in alphabetical or atomic-weight order or something.
- they can be easily compared
- they would be unique
- no need to worry about storage of very large numbers

gsal## RE: numbers that can differentiate uniquely between the combinations

## RE: numbers that can differentiate uniquely between the combinations

Yes its combination of 3 atoms because im interested in bonding angles, bond lengths, and other short range order properties which takes place between 2 to 3 atoms. I raised the issue of chain because microm suggestion gave an idea that I can also look at how long the chains are, which is what im trying to do now from his suggested solution. What you saying its true I realised earlier that the no increases exponentially as you increase the no of atoms. Also the gap becomes too large and jump other atoms when you used too large numbers.

## RE: numbers that can differentiate uniquely between the combinations

But maybe you mean that one element may occur in one combination 2377 times? In this case if you want to encode the combination of 2377*Si, then you will get a very large number, i.e. 2**2377. Then you have to search for the specialized library for working with large numbers ... maybe something for cryptography.

Just for curiosity: why do you thing, that you need to encode the element combination into one number?

For example, a simple approach would be to define for every element an array which holds the occurence:

## CODE

## CODE

## CODE

## RE: numbers that can differentiate uniquely between the combinations

I atoms which are not bonded,I put them in a box,then I run an MD simulation,they react and form bonds, I know the likes bonds. I have already observed them using my other code. I also abserved the formation of triads Si-Al-Mg forming in my system. Now there is a competion between Mg and Ca, I want to determine the number of Si-Al-Mg and Si-Al-Ca formed in the system. From this I can tell and use the available theory to confirm the most likely reaction to take place.

Instead of what you suggesting which I think its also a good idea 'integer, dimension (maxN) :: Si, Al, Mg, Ca, U ' I have used a verlet list to determine atoms which are closer to each other.

## RE: numbers that can differentiate uniquely between the combinations

[! Assign Si = 3**0 = 1, Al = 3**1 = 3 and unknown metals 3**2 = 9

! then we can identify pairs and triads easily without ordering

! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2

! [Si,Al] = [Al,Si] = 1 + 3 = 4

! [Al,Al] = 3 + 3 = 6

! [U,U] = 9 + 9 = 18

! [Al,U] = 3 + 9 = 12

! [Si,U] = 1 + 9 = 10

! [Si,Si,Si] = 1 + 1 + 1 = 3

! [Si,Si,Al] = 1 + 1 + 3 = 5

! [Si,Al,Al] = 1 + 3 + 3 = 7

! [Al,Al,Al] = 3 + 3 + 3 = 9

! [U,U,U] = 9 + 9 + 9 = 27

! [U,U,Si] = 9 + 9 + 1 = 19

! [U,U,Ai] = 9 + 9 + 3 = 21

! [U,Si,Si] = 9 + 1 + 1 = 11

! [U,Si,Al] = 9 + 1 + 4 = 14

! [U,Al,Al] = 9 + 3 + 3 = 15

do i = 1, natms

if (atmname(i) == silicon) then

id(i) = 1

elseif (atmname(i) == aluminium) then

id(i) = 3

else

id(i) = 9

endif

enddo

do i = 1, natms

do k = 1, nmetals

if (atmname(i) == metals(k)) then

do j = i, natms

if (atmname(j) == oxygen) then

bndtab(i,j) = mbonds(k)**2

bndtab(j,i) = bndtab(i,j)

bndtab(j,i) = bndtab(i,j)

endif

enddo

endif

enddo

enddo

endif

]

second part of the code:this where I use the

[ nbo = 0

nnbo = 0

ntbo = 0

call cpu_time(tstart)

! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2

! [Si,Al] = [Al,Si] = 1 + 3 = 4

! [Al,Al] = 3 + 3 = 6

! [U,U] = 9 + 9 = 18

! [Al,U] = 3 + 9 = 12

! [Si,U] = 1 + 9 = 10

do i = 1, natms

if ((atmname(i) == oxygen) .and. (cnlist(i) .eq. 2)) then

select case ( id(blist(bindex(i))) + id(blist(bindex(i)+1)) )

case (2)

write(logfile,*)'[Si,Si] bridge'

nbo = nbo + 1

case (4)

write(logfile,*)'[Si,Al] bridge'

nbo = nbo + 1

case (6)

write(logfile,*)'[Al,Al] bridge'

nbo = nbo + 1

case (10)

write(logfile,*)'[Si,Ca/Mg] disconnect'

nnbo = nnbo + 1

case (12)

write(logfile,*)'[Al,Ca/Mg] disconnect'

nnbo = nnbo + 1

case (18)

write(logfile,*)'[Mg/Ca,Ca/Mg] disconnect'

end select

endif

]

## RE: numbers that can differentiate uniquely between the combinations

## RE: numbers that can differentiate uniquely between the combinations

! then we can identify pairs and triads easily without ordering

! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2

! [Si,Al] = [Al,Si] = 1 + 3 = 4

! [Al,Al] = 3 + 3 = 6

! [U,U] = 9 + 9 = 18

! [Al,U] = 3 + 9 = 12

! [Si,U] = 1 + 9 = 10

! [Si,Si,Si] = 1 + 1 + 1 = 3

! [Si,Si,Al] = 1 + 1 + 3 = 5

! [Si,Al,Al] = 1 + 3 + 3 = 7

! [Al,Al,Al] = 3 + 3 + 3 = 9

! [U,U,U] = 9 + 9 + 9 = 27

! [U,U,Si] = 9 + 9 + 1 = 19

! [U,U,Ai] = 9 + 9 + 3 = 21

! [U,Si,Si] = 9 + 1 + 1 = 11

! [U,Si,Al] = 9 + 1 + 4 = 14

! [U,Al,Al] = 9 + 3 + 3 = 15

do i = 1, natms

if (atmname(i) == silicon) then

id(i) = 1

elseif (atmname(i) == aluminium) then

id(i) = 3

else

id(i) = 9

endif

enddo

do i = 1, natms

do k = 1, nmetals

if (atmname(i) == metals(k)) then

do j = i, natms

if (atmname(j) == oxygen) then

bndtab(i,j) = mbonds(k)**2

bndtab(j,i) = bndtab(i,j)

bndtab(j,i) = bndtab(i,j)

endif

enddo

endif

enddo

enddo

endif]

[/second part of the code:this where I use the

nbo = 0

nnbo = 0

ntbo = 0

call cpu_time(tstart)

! [Si,Si] = 3**0 + 3**0 = 1 + 1 = 2

! [Si,Al] = [Al,Si] = 1 + 3 = 4

! [Al,Al] = 3 + 3 = 6

! [U,U] = 9 + 9 = 18

! [Al,U] = 3 + 9 = 12

! [Si,U] = 1 + 9 = 10

do i = 1, natms

if ((atmname(i) == oxygen) .and. (cnlist(i) .eq. 2)) then

select case ( id(blist(bindex(i))) + id(blist(bindex(i)+1)) )

case (2)

write(logfile,*)'[Si,Si] bridge'

nbo = nbo + 1

case (4)

write(logfile,*)'[Si,Al] bridge'

nbo = nbo + 1

case (6)

write(logfile,*)'[Al,Al] bridge'

nbo = nbo + 1

case (10)

write(logfile,*)'[Si,Ca/Mg] disconnect'

nnbo = nnbo + 1

case (12)

write(logfile,*)'[Al,Ca/Mg] disconnect'

nnbo = nnbo + 1

case (18)

write(logfile,*)'[Mg/Ca,Ca/Mg] disconnect'

end select

endif

]

## RE: numbers that can differentiate uniquely between the combinations

OR

you can highlight your source code and then click on the "code formatting" icon in the bar along the top of the editing window...it is between the guy with a message box and the wrapped gift.

## RE: numbers that can differentiate uniquely between the combinations

## CODE

## RE: numbers that can differentiate uniquely between the combinations

First round up to the nearest multiple of 2

Si 30 => 32 - 5 bits - bits 0..4

U 100 => 128 - 7 bits - bits 5..11

Al 50 => 64 - 6 bits - bits 12..16

## CODE --> Pictorially

The initial value will be the base value - 2 to the lowest bit number

Si 2**0 = 1

U 2**5 = 32

Al 2**12 = 4096

So U,Al,Al would be 32 + 2 * 4096.

To work out what a pattern has,

## CODE

## RE: numbers that can differentiate uniquely between the combinations

So, I would simply use arrays or, rather, a single 2D matrix...

The first index of the matrix (row number) would be the i-th combination; the second index (column number) would be the atom...the value in the (i,j) position would be, given the i-th combination, how many times the j-th atom participates in it. As simple as that. So, this matrix would have as many rows as you care to have combination and as many columns as there are elements in the periodic table (118).

With the 2D matrix, you will have at all times the exact composition of each combination, no need to decode anything.