Creating comination of Compounds using periodic table in a specific format

Dear User/Developers,

I am looking to create combinations of compounds (Oxides and Halides). For example ABX3 and A2BB’X6. Here A and B can be of any combination of periodic table (H, He, Li… etc. let say the elements up to atomic number 50) and “X” can specifically (O, F, Cl and Br).
I had created all combinations AB using:

import itertools
CCA_combos1 = list(itertools.combinations(AB, 2))

and then Oxygen, I have added using for loop:

list1 = [‘O3’]
CCA_combos1_2 = []
for x in range(len(CCA_combos1)):
CCA_combos1_2 += [tuple(CCA_combos1[x]) + tuple(list1)]
display(CCA_combos1_2, len(CCA_combos1_2))

This for loop code does’t work well for Br and Cl.
Also I have idea to create a combinations in the form of A2BB’X6. Please suggest the required way to get the desired combinations.

Thanks and Regards
Neelesh G.

Dear Neelesh,

Could you provide a bit more information on how the loop does not work for Br and Cl? Maybe, post a code example to show how it fails.

Using your example, it seems to work fine for me.

import itertools

#Let's create a list of symbols 
AB=['Sr','Ti', 'Ba', 'Li']

CCA_combos1 = list(itertools.combinations(AB,2))

# Let's add oxygen using a for loop

list1 = ['O3']
for x in range(len(CCA_combos1)):
    CCA_combos1_2+=[tuple(CCA_combos1[x]) + tuple(list1)]
display(CCA_combos1_2, len(CCA_combos1_2))

[(‘Sr’, ‘Ti’, ‘O3’),
(‘Sr’, ‘Ba’, ‘O3’),
(‘Sr’, ‘Li’, ‘O3’),
(‘Ti’, ‘Ba’, ‘O3’),
(‘Ti’, ‘Li’, ‘O3’),
(‘Ba’, ‘Li’, ‘O3’)]

Then if wanted to add in Br3 to this list:

for x in range(len(CCA_combos1)):
   CCA_combos1_2+=[tuple(CCA_combos1[x]) + tuple(list2)]
display(CCA_combos1_2, len(CCA_combos1_2))

[(‘Sr’, ‘Ti’, ‘O3’),
(‘Sr’, ‘Ba’, ‘O3’),
(‘Sr’, ‘Li’, ‘O3’),
(‘Ti’, ‘Ba’, ‘O3’),
(‘Ti’, ‘Li’, ‘O3’),
(‘Ba’, ‘Li’, ‘O3’),
(‘Sr’, ‘Ti’, ‘Br3’),
(‘Sr’, ‘Ba’, ‘Br3’),
(‘Sr’, ‘Li’, ‘Br3’),
(‘Ti’, ‘Ba’, ‘Br3’),
(‘Ti’, ‘Li’, ‘Br3’),
(‘Ba’, ‘Li’, ‘Br3’)]

For your second problem of A2BB’X6 compounds, using itertools.product would be your likely solution:

import itertools

#Create a list for the possible A2 elements and for B elements

A2 = ['Ba2', 'Sr2', 'Li2']
B= ['Fe', 'Ti', 'Pb']

# This will give your the ABB' combinations but there will be duplicated BB' elements in the list
A2BB_combos = list(itertools.product(A2,B,B))

# We follow the same routine as above to add O6
for x in range(len(A2BB_combos)):
    A2BBO6_combos +=[tuple(A2BB_combos[x]) + tuple(list_O6)]

display(A2BBO6_combos, len(A2BBO6_combos))


[(‘Ba2’, ‘Fe’, ‘Fe’, ‘O6’),
(‘Ba2’, ‘Fe’, ‘Ti’, ‘O6’),
(‘Ba2’, ‘Fe’, ‘Pb’, ‘O6’),
(‘Ba2’, ‘Ti’, ‘Fe’, ‘O6’),
(‘Ba2’, ‘Ti’, ‘Ti’, ‘O6’),
(‘Ba2’, ‘Ti’, ‘Pb’, ‘O6’),
(‘Ba2’, ‘Pb’, ‘Fe’, ‘O6’),
(‘Ba2’, ‘Pb’, ‘Ti’, ‘O6’),
(‘Ba2’, ‘Pb’, ‘Pb’, ‘O6’),
(‘Sr2’, ‘Fe’, ‘Fe’, ‘O6’),
(‘Sr2’, ‘Fe’, ‘Ti’, ‘O6’),
(‘Sr2’, ‘Fe’, ‘Pb’, ‘O6’),
(‘Sr2’, ‘Ti’, ‘Fe’, ‘O6’),
(‘Sr2’, ‘Ti’, ‘Ti’, ‘O6’),
(‘Sr2’, ‘Ti’, ‘Pb’, ‘O6’),
(‘Sr2’, ‘Pb’, ‘Fe’, ‘O6’),
(‘Sr2’, ‘Pb’, ‘Ti’, ‘O6’),
(‘Sr2’, ‘Pb’, ‘Pb’, ‘O6’),
(‘Li2’, ‘Fe’, ‘Fe’, ‘O6’),
(‘Li2’, ‘Fe’, ‘Ti’, ‘O6’),
(‘Li2’, ‘Fe’, ‘Pb’, ‘O6’),
(‘Li2’, ‘Ti’, ‘Fe’, ‘O6’),
(‘Li2’, ‘Ti’, ‘Ti’, ‘O6’),
(‘Li2’, ‘Ti’, ‘Pb’, ‘O6’),
(‘Li2’, ‘Pb’, ‘Fe’, ‘O6’),
(‘Li2’, ‘Pb’, ‘Ti’, ‘O6’),
(‘Li2’, ‘Pb’, ‘Pb’, ‘O6’)]

This particular concept of trying to create combinations of compounds is something that the research group that I am part of have developed a code which can tackle this problem. It can also be used to determine which of the combinations would form charge neutral compounds: (GitHub - WMD-group/SMACT: Python package to aid materials design)
These two examples could guide you with your problem.

Thanks AntObi,

For taking interest in this issue.
I am getting the output in this form

‘B’, ‘2’, ‘H’, ‘S’, ‘C’, ‘l’, ‘6’ i.e. for B2HSCl6. So whenever Atom of two character (As, Cl, Br etc.), it got separated in Jupyter notebook.

Thanks and Regards