def test_pg(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 6 col = [[-1, 1], [-1, 1], [-1, 1], [-1, 2], [-1, 2], [-1, 2], [-1, 2], [1, 1], [1, 1]] trans = [[ j - 1 for j in i ] for i in [[1, 2, 3, 4, 5, 6, 7, 8, 9], [3, 1, 2, 6, 4, 5, 9, 7, 8], [2, 3, 1, 5, 6, 4, 8, 9, 7], [7, 8, 9, 1, 2, 3, 4, 5, 6], [9, 7, 8, 3, 1, 2, 6, 4, 5], [8, 9, 7, 2, 3, 1, 5, 6, 4], [4, 5, 6, 7, 8, 9, 1, 2, 3], [6, 4, 5, 9, 7, 8, 3, 1, 2], [5, 6, 4, 8, 9, 7, 2, 3, 1]]] rots = [[[j - 1 for j in i] for i in t] for t in [[[1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5, 6]], [[3, 6, 9, 2, 5, 8, 1, 4, 7], [3, 4, 2, 1, 5, 6]], [[9, 8, 7, 6, 5, 4, 3, 2, 1], [2, 1, 4, 3, 5, 6]], [[7, 4, 1, 8, 5, 2, 9, 6, 3], [4, 3, 1, 2, 5, 6]], [[1, 4, 7, 2, 5, 8, 3, 6, 9], [3, 4, 1, 2, 6, 5]], [[9, 6, 3, 8, 5, 2, 7, 4, 1], [4, 3, 2, 1, 6, 5]], [[7, 8, 9, 4, 5, 6, 1, 2, 3], [1, 2, 4, 3, 6, 5]], [[3, 2, 1, 6, 5, 4, 9, 8, 7], [2, 1, 3, 4, 6, 5]]]] (narrows, arrow_types, Concs) = how_many_arrows(col) agroup = a_group(trans, rots) out = 663 self.assertEqual(polya(Concs, agroup, arrowings=arrow_types), out)
def test_o10(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-1, 1], [-1, 1], [-1, 1], [-1, 1], [-1, 1], [-1, 2], [-1, 2], [-1, 2], [-1, 2], [-1, 2], [3, 3], [3, 4]] trans = [[j - 1 for j in i] for i in [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2], [4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 2, 1], [5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4], [6, 5, 8, 7, 10, 9, 12, 11, 2, 1, 4, 3], [7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6], [8, 7, 10, 9, 12, 11, 2, 1, 4, 3, 6, 5], [9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8], [10, 9, 12, 11, 2, 1, 4, 3, 6, 5, 8, 7], [11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [12, 11, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9]]] rots = [[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 1, 2, 3]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [2, 1, 0, 3]], [[0, 1, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3], [0, 3, 2, 1]], [[0, 1, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3], [2, 3, 0, 1]]] (narrows, arrow_types, Concs) = how_many_arrows(col) agroup = a_group(trans, rots) out = 13896 self.assertEqual(polya(Concs, agroup, arrowings=arrow_types), out)
def test_o22(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-1, 1], [-1, 1], [-1, 1], [-1, 2], [-1, 2], [-1, 2], [3, 3], [3, 4], [3, 4]] trans = [[ j - 1 for j in i ] for i in [[1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 1, 5, 6, 4, 8, 9, 7], [3, 1, 2, 6, 4, 5, 9, 7, 8], [4, 5, 6, 7, 8, 9, 1, 2, 3], [5, 6, 4, 8, 9, 7, 2, 3, 1], [6, 4, 5, 9, 7, 8, 3, 1, 2], [7, 8, 9, 1, 2, 3, 4, 5, 6], [8, 9, 7, 2, 3, 1, 5, 6, 4], [9, 7, 8, 3, 1, 2, 6, 4, 5]]] rots = [[[0, 1, 2, 3, 4, 5, 6, 7, 8], [0, 1, 2, 3]], [[0, 1, 2, 8, 6, 7, 4, 5, 3], [2, 1, 0, 3]], [[0, 2, 1, 4, 3, 5, 8, 7, 6], [0, 3, 2, 1]], [[0, 2, 1, 6, 8, 7, 3, 5, 4], [2, 3, 0, 1]], [[0, 7, 5, 6, 4, 2, 3, 1, 8], [1, 0, 3, 2]], [[0, 7, 5, 8, 3, 1, 4, 2, 6], [3, 0, 1, 2]], [[0, 5, 7, 4, 6, 2, 8, 1, 3], [1, 2, 3, 0]], [[0, 5, 7, 3, 8, 1, 6, 2, 4], [3, 2, 1, 0]]] (narrows, arrow_types, Concs) = how_many_arrows(col) agroup = a_group(trans, rots) out = 4504 self.assertEqual(polya(Concs, agroup, arrowings=arrow_types), out)
def test_3g_3(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 6 col = [[1, 1], [1, 2], [1, 3], [1, 4]] trans = [[ j - 1 for j in i ] for i in [[1, 2, 3, 4], [2, 1, 4, 3], [3, 4, 1, 2], [4, 3, 2, 1]]] rots = [[[j - 1 for j in i] for i in t] for t in [[[1, 2, 3, 4], [1, 2, 3, 4, 5, 6]], [[1, 4, 3, 2], [1, 3, 2, 4, 6, 5]], [[1, 2, 3, 4], [4, 2, 3, 1, 5, 6]], [[1, 4, 3, 2], [4, 3, 2, 1, 6, 5]], [[1, 2, 3, 4], [1, 5, 3, 4, 2, 6]], [[1, 4, 3, 2], [1, 3, 5, 4, 6, 2]], [[1, 2, 3, 4], [4, 5, 3, 1, 2, 6]], [[1, 4, 3, 2], [4, 3, 5, 1, 6, 2]], [[1, 2, 3, 4], [1, 2, 6, 4, 5, 3]], [[1, 4, 3, 2], [1, 6, 2, 4, 3, 5]], [[1, 2, 3, 4], [4, 2, 6, 1, 5, 3]], [[1, 4, 3, 2], [4, 6, 2, 1, 3, 5]], [[1, 2, 3, 4], [1, 5, 6, 4, 2, 3]], [[1, 4, 3, 2], [1, 6, 5, 4, 3, 2]], [[1, 2, 3, 4], [4, 5, 6, 1, 2, 3]], [[1, 4, 3, 2], [4, 6, 5, 1, 3, 2]]]] (narrows, arrow_types, Concs) = how_many_arrows(col) agroup = a_group(trans, rots) out = 792 self.assertEqual(polya(Concs, agroup, arrowings=arrow_types), out)
def test_r2(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-1,1],[-1,2],[0,3],[0,4]] trans = [[0,1,2,3],[1,0,3,2],[2,3,0,1],[3,2,1,0]] rots = [[[0,1,2,3],[0,1,2,3]],[[0,1,2,3],[2,1,0,3]],[[0,1,2,3],[0,3,2,1]],[[0,1,2,3],[2,3,0,1]],[[0,3,2,1],[1,0,3,2]],[[0,3,2,1],[3,0,1,2]],[[0,3,2,1],[1,2,3,0]],[[0,3,2,1],[3,2,1,0]]] (narrows,arrow_types,Concs) = how_many_arrows(col) Concs = [1] temp_agroup = a_group(trans,rots) agroup = [] for i in temp_agroup: sites = [j+1 for j in i[0]] ars = [j+1 for j in i[1]] agroup.append([sites,ars]) out = 18 with pytest.raises(ValueError): polya(Concs,agroup,arrowings=arrow_types)
def test_3e_1(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 6 col = [[-1, 1], [-1, 2], [1, 3], [1, 3], [1, 4], [1, 4]] trans = [[j-1 for j in i] for i in [[1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 1], [3, 4, 5, 6, 1, 2], [4, 5, 6, 1, 2, 3], [5, 6, 1, 2, 3, 4], [6, 1, 2, 3, 4, 5]]] rots = [[[j-1 for j in i] for i in t] for t in [[[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6], [4, 2, 3, 1, 5, 6]], [[1, 2, 3, 4, 5, 6], [1, 5, 3, 4, 2, 6]], [[1, 2, 3, 4, 5, 6], [4, 5, 3, 1, 2, 6]], [[1, 6, 5, 4, 3, 2], [1, 2, 6, 4, 5, 3]], [[1, 6, 5, 4, 3, 2], [4, 2, 6, 1, 5, 3]], [[1, 6, 5, 4, 3, 2], [1, 5, 6, 4, 2, 3]], [[1, 6, 5, 4, 3, 2], [4, 5, 6, 1, 2, 3]]]] (narrows,arrow_types,Concs) = how_many_arrows(col) agroup = a_group(trans,rots) out = 6876 self.assertEqual(polya(Concs,agroup,arrowings=arrow_types),out)
def test_pg(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 6 col = [[-1,1],[-1,1],[-1,1],[-1,2],[-1,2],[-1,2],[-1,2],[1,1],[1,1]] trans = [[j - 1 for j in i] for i in [[1,2,3,4,5,6,7,8,9], [3,1,2,6,4,5,9,7,8], [2,3,1,5,6,4,8,9,7],[7,8,9,1,2,3,4,5,6], [9,7,8,3,1,2,6,4,5], [8,9,7,2,3,1,5,6,4], [4,5,6,7,8,9,1,2,3], [6,4,5,9,7,8,3,1,2], [5,6,4,8,9,7,2,3,1]]] rots = [[[j - 1 for j in i] for i in t] for t in [[[1,2,3,4,5,6,7,8,9],[1,2,3,4,5,6]], [[3,6,9,2,5,8,1,4,7],[3,4,2,1,5,6]], [[9,8,7,6,5,4,3,2,1],[2,1,4,3,5,6]], [[7,4,1,8,5,2,9,6,3],[4,3,1,2,5,6]], [[1,4,7,2,5,8,3,6,9],[3,4,1,2,6,5]], [[9,6,3,8,5,2,7,4,1],[4,3,2,1,6,5]], [[7,8,9,4,5,6,1,2,3],[1,2,4,3,6,5]], [[3,2,1,6,5,4,9,8,7],[2,1,3,4,6,5]]]] (narrows,arrow_types,Concs) = how_many_arrows(col) agroup = a_group(trans,rots) out = 663 self.assertEqual(polya(Concs,agroup,arrowings=arrow_types),out)
def test_p2(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-3,1],[-3,1],[-3,1],[-3,2],[3,3],[3,3],[3,3],[3,4]] trans = [[0,1,2,3,4,5,6,7],[1,0,3,2,5,4,7,6],[2,3,4,5,6,7,0,1],[3,2,5,4,7,6,1,0],[4,5,6,7,0,1,2,3],[5,4,7,6,1,0,3,2],[6,7,0,1,2,3,4,5],[7,6,1,0,3,2,5,4]] rots = [[[0,1,2,3,4,5,6,7],[0,1,2,3]],[[0,1,2,3,4,5,6,7],[2,1,0,3]],[[0,1,6,7,4,5,2,3],[0,3,2,1]],[[0,1,6,7,4,5,2,3],[2,3,0,1]]] (narrows,arrow_types,Concs) = how_many_arrows(col) agroup = a_group(trans,rots) out = 9568 self.assertEqual(polya(Concs,agroup,arrowings=arrow_types),out)
def test_p1(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-1,1],[-1,2],[0,3],[0,4]] trans = [[0,1,2,3],[1,0,3,2],[2,3,0,1],[3,2,1,0]] rots = [[[0,1,2,3],[0,1,2,3]],[[0,1,2,3],[2,1,0,3]],[[0,1,2,3],[0,3,2,1]],[[0,1,2,3],[2,3,0,1]],[[0,3,2,1],[1,0,3,2]],[[0,3,2,1],[3,0,1,2]],[[0,3,2,1],[1,2,3,0]],[[0,3,2,1],[3,2,1,0]]] (narrows,arrow_types,Concs) = how_many_arrows(col) agroup = a_group(trans,rots) out = 18 self.assertEqual(polya(Concs,agroup,arrowings=arrow_types),out)
def test_o21(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-1,1],[-1,1],[-1,2],[-1,2],[-1,2],[3,3],[3,4],[3,4]] trans =[[j - 1 for j in i] for i in[[1, 2, 3, 4, 5, 6, 7, 8], [2, 1, 4, 3, 6, 5, 8, 7], [3, 4, 5, 6, 7, 8, 1, 2], [4, 3, 6, 5, 8, 7, 2, 1], [5, 6, 7, 8, 1, 2, 3, 4], [6, 5, 8, 7, 2, 1, 4, 3], [7, 8, 1, 2, 3, 4, 5, 6], [8, 7, 2, 1, 4, 3, 6, 5]]] rots = [[[0,1,2,3,4,5,6,7],[0,1,2,3]],[[0,1,2,3,4,5,6,7],[2,1,0,3]],[[0,1,6,7,4,5,2,3],[0,3,2,1]],[[0,1,6,7,4,5,2,3],[2,3,0,1]]] (narrows,arrow_types,Concs) = how_many_arrows(col) agroup = a_group(trans,rots) out = 3808 self.assertEqual(polya(Concs,agroup,arrowings=arrow_types),out)
def test_toy_2(self): from phenum.grouptheory import a_group_gen from phenum.phonons import how_many_arrows, how_many_arrows col = [[-1, 1], [1, 2]] trans = [[0, 1], [1, 0]] rots = [[[0, 1], [0, 1, 2, 3, 4, 5]], [[1, 0], [2, 3, 0, 1, 5, 4]], [[1, 0], [2, 1, 0, 3, 5, 4]], [[0, 1], [0, 3, 2, 1, 5, 4]]] dim = 6 (narrows, arrow_types, Concs) = how_many_arrows(col) agroup = a_group_gen(trans, rots) out = 3 self.assertEqual(polya(Concs, agroup, arrowings=arrow_types), out)
def test_toy_2(self): from phenum.grouptheory import a_group_gen from phenum.phonons import how_many_arrows, how_many_arrows col = [[-1,1],[1,2]] trans = [[0,1],[1,0]] rots = [[[0,1],[0,1,2,3,4,5]],[[1,0],[2,3,0,1,5,4]],[[1,0],[2,1,0,3,5,4]], [[0,1],[0,3,2,1,5,4]]] dim = 6 (narrows,arrow_types,Concs) = how_many_arrows(col) agroup = a_group_gen(trans,rots) out = 3 self.assertEqual(polya(Concs,agroup,arrowings=arrow_types),out)
def test_p4(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-1, 3], [-1, 2], [-1, 3], [1, 1]] trans = [[0, 1, 2, 3], [1, 2, 3, 0], [2, 3, 0, 1], [3, 0, 1, 2]] rots = [[[0, 1, 2, 3], [0, 1, 2, 3]], [[0, 1, 2, 3], [2, 1, 0, 3]], [[0, 3, 2, 1], [0, 3, 2, 1]], [[0, 3, 2, 1], [2, 3, 0, 1]]] (narrows, arrow_types, Concs) = how_many_arrows(col) agroup = a_group(trans, rots) out = 5 self.assertEqual(polya(Concs, agroup, arrowings=arrow_types), out)
def test_r2(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-1, 1], [-1, 2], [0, 3], [0, 4]] trans = [[0, 1, 2, 3], [1, 0, 3, 2], [2, 3, 0, 1], [3, 2, 1, 0]] rots = [[[0, 1, 2, 3], [0, 1, 2, 3]], [[0, 1, 2, 3], [2, 1, 0, 3]], [[0, 1, 2, 3], [0, 3, 2, 1]], [[0, 1, 2, 3], [2, 3, 0, 1]], [[0, 3, 2, 1], [1, 0, 3, 2]], [[0, 3, 2, 1], [3, 0, 1, 2]], [[0, 3, 2, 1], [1, 2, 3, 0]], [[0, 3, 2, 1], [3, 2, 1, 0]]] (narrows, arrow_types, Concs) = how_many_arrows(col) Concs = [1] temp_agroup = a_group(trans, rots) agroup = [] for i in temp_agroup: sites = [j + 1 for j in i[0]] ars = [j + 1 for j in i[1]] agroup.append([sites, ars]) out = 18 with pytest.raises(ValueError): polya(Concs, agroup, arrowings=arrow_types)
def test_r1(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-1,1],[-1,2],[0,3],[0,4]] trans = [[0,1,2,3],[1,0,3,2],[2,3,0,1],[3,2,1,0]] rots = [[[0,1,2,3],[0,1,2,3]],[[0,1,2,3],[2,1,0,3]],[[0,1,2,3],[0,3,2,1]],[[0,1,2,3],[2,3,0,1]],[[0,3,2,1],[1,0,3,2]],[[0,3,2,1],[3,0,1,2]],[[0,3,2,1],[1,2,3,0]],[[0,3,2,1],[3,2,1,0]]] (narrows,arrow_types,Concs) = how_many_arrows(col) temp_agroup = a_group(trans,rots) agroup = [] print("ta",temp_agroup) for i in temp_agroup: sites = [j+1 for j in i[0]] ars = [j+1 for j in i[1]] agroup.append([sites,ars]) print("a",agroup) out = 18 self.assertEqual(polya(Concs,agroup,arrowings=arrow_types),out)
def test_p2(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-3, 1], [-3, 1], [-3, 1], [-3, 2], [3, 3], [3, 3], [3, 3], [3, 4]] trans = [[0, 1, 2, 3, 4, 5, 6, 7], [1, 0, 3, 2, 5, 4, 7, 6], [2, 3, 4, 5, 6, 7, 0, 1], [3, 2, 5, 4, 7, 6, 1, 0], [4, 5, 6, 7, 0, 1, 2, 3], [5, 4, 7, 6, 1, 0, 3, 2], [6, 7, 0, 1, 2, 3, 4, 5], [7, 6, 1, 0, 3, 2, 5, 4]] rots = [[[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3]], [[0, 1, 2, 3, 4, 5, 6, 7], [2, 1, 0, 3]], [[0, 1, 6, 7, 4, 5, 2, 3], [0, 3, 2, 1]], [[0, 1, 6, 7, 4, 5, 2, 3], [2, 3, 0, 1]]] (narrows, arrow_types, Concs) = how_many_arrows(col) agroup = a_group(trans, rots) out = 9568 self.assertEqual(polya(Concs, agroup, arrowings=arrow_types), out)
def test_r1(self): from phenum.grouptheory import a_group from phenum.phonons import how_many_arrows, how_many_arrows dim = 4 col = [[-1, 1], [-1, 2], [0, 3], [0, 4]] trans = [[0, 1, 2, 3], [1, 0, 3, 2], [2, 3, 0, 1], [3, 2, 1, 0]] rots = [[[0, 1, 2, 3], [0, 1, 2, 3]], [[0, 1, 2, 3], [2, 1, 0, 3]], [[0, 1, 2, 3], [0, 3, 2, 1]], [[0, 1, 2, 3], [2, 3, 0, 1]], [[0, 3, 2, 1], [1, 0, 3, 2]], [[0, 3, 2, 1], [3, 0, 1, 2]], [[0, 3, 2, 1], [1, 2, 3, 0]], [[0, 3, 2, 1], [3, 2, 1, 0]]] (narrows, arrow_types, Concs) = how_many_arrows(col) temp_agroup = a_group(trans, rots) agroup = [] print("ta", temp_agroup) for i in temp_agroup: sites = [j + 1 for j in i[0]] ars = [j + 1 for j in i[1]] agroup.append([sites, ars]) print("a", agroup) out = 18 self.assertEqual(polya(Concs, agroup, arrowings=arrow_types), out)
def _polya_out(args): """Generates the 'polya.out' files for the cell sizes specified in 'lattice.in' (or other specified input file). Args: args (dict): The command line inputs. """ from phenum.HNFs import get_HNFs from phenum.grouptheory import get_sym_group from phenum.symmetry import get_concs_for_size from phenum.io_utils import read_lattice import phenum.phonons as pb from phenum.polyaburnside import polya params = read_lattice(args["lattice"]) for s in range(params["sizes"][0], params["sizes"][1] + 1): # get HNFs hnfs = get_HNFs(s, params["lat_vecs"], params["basis_vecs"], 3) out = open(args["outfile"] + "." + str(s), 'w+') # find the concentrations available for the desired cell sizes. c_list = get_concs_for_size(s, params["nspecies"], params["is_crestricted"], len(params["basis_vecs"]), params["concs"]) # We need to write the concs in c_list to the output file. out.write('{0: <28}'.format("# HNF")) for conc in c_list: out.write("{0: <50}".format(':'.join(map(str, conc)))) out.write('{0: <50}\n'.format("Total")) a_concs = pb.get_arrow_concs(params) conc_totals = [0 for i in range(len(c_list))] for thnf in hnfs: hnf = [ thnf[0][0], thnf[1][0], thnf[1][1], thnf[2][0], thnf[2][1], thnf[2][2] ] out.write(" {0: <26}".format(' '.join(map(str, hnf)))) sym_g = get_sym_group(params["lat_vecs"], params["basis_vecs"], thnf, 3) agroup = [] len_sym_g = len(sym_g.perm.site_perm) for i in range(len_sym_g): agroup.append( [sym_g.perm.site_perm[i], sym_g.perm.arrow_perm[i]]) # we need to loop over the concentrations and find the # number of arrangements possible for each cell size total = 0 for iconc, conc in enumerate(c_list): if len(conc) > 0: decorations = pb.arrow_concs(conc, a_concs) # we need to know the concentrations of the # species with and without arrows, we also need to # know the number of arrows and their species so # we can undo the previous step later (n_arrows, arrow_types, concs_w_arrows) = pb.how_many_arrows(decorations) # now find the number of unique arrangements using Polya. if arrow_types != 0 or n_arrows != 0: total_num = polya(concs_w_arrows, agroup, arrowings=arrow_types) else: total_num = polya(conc, agroup) out.write("{0: <50d}".format(total_num)) total += total_num conc_totals[iconc] += total_num out.write('{0: <10d}\n'.format(total)) out.write("# " + ''.join(['-' for i in range(len(c_list) * 10 + 10 + 30)]) + '\n') out.write("{0: <28}".format(" 0 0 0 0 0 0")) for ctotal in conc_totals: out.write("{0: <50d}".format(ctotal)) out.write("{0: <50d}\n".format(sum(conc_totals))) out.close()
def _polya_out(args): """Generates the 'polya.out' files for the cell sizes specified in 'lattice.in' (or other specified input file). Args: args (dict): The command line inputs. """ from phenum.HNFs import get_HNFs from phenum.grouptheory import get_sym_group from phenum.symmetry import get_concs_for_size from phenum.io_utils import read_lattice import phenum.phonons as pb from phenum.polyaburnside import polya params = read_lattice(args["lattice"]) for s in range(params["sizes"][0], params["sizes"][1]+1): # get HNFs hnfs = get_HNFs(s,params["lat_vecs"],params["basis_vecs"],3) out = open(args["outfile"]+"."+str(s), 'w+') # find the concentrations available for the desired cell sizes. c_list = get_concs_for_size(s, params["nspecies"], params["is_crestricted"], len(params["basis_vecs"]), params["concs"]) # We need to write the concs in c_list to the output file. out.write('{0: <28}'.format("# HNF")) for conc in c_list: out.write("{0: <50}".format(':'.join(map(str, conc)))) out.write('{0: <50}\n'.format("Total")) a_concs = pb.get_arrow_concs(params) conc_totals = [0 for i in range(len(c_list))] for thnf in hnfs: hnf = [thnf[0][0],thnf[1][0],thnf[1][1],thnf[2][0],thnf[2][1],thnf[2][2]] out.write(" {0: <26}".format(' '.join(map(str, hnf)))) sym_g = get_sym_group(params["lat_vecs"],params["basis_vecs"],thnf,3) agroup = [] len_sym_g = len(sym_g.perm.site_perm) for i in range(len_sym_g): agroup.append([sym_g.perm.site_perm[i],sym_g.perm.arrow_perm[i]]) # we need to loop over the concentrations and find the # number of arrangements possible for each cell size total = 0 for iconc, conc in enumerate(c_list): if len(conc) > 0: decorations = pb.arrow_concs(conc,a_concs) # we need to know the concentrations of the # species with and without arrows, we also need to # know the number of arrows and their species so # we can undo the previous step later (n_arrows,arrow_types,concs_w_arrows) = pb.how_many_arrows(decorations) # now find the number of unique arrangements using Polya. if arrow_types != 0 or n_arrows !=0: total_num = polya(concs_w_arrows,agroup,arrowings=arrow_types) else: total_num = polya(conc, agroup) out.write("{0: <50d}".format(total_num)) total += total_num conc_totals[iconc] += total_num out.write('{0: <10d}\n'.format(total)) out.write("# " + ''.join(['-' for i in range(len(c_list)*10 + 10 + 30)]) + '\n') out.write("{0: <28}".format(" 0 0 0 0 0 0")) for ctotal in conc_totals: out.write("{0: <50d}".format(ctotal)) out.write("{0: <50d}\n".format(sum(conc_totals))) out.close()
def enum_sys(groupfile, concs, a_concs, num_wanted, HNF, params, supers, accept=None): """Enumerates a random subset of the unique structures that have the shape defined by the symmetry group and the specified concentration. Args: groupfile (str): Path to the file containing the symmetry group. concs (list): Integer array of the concentrations for each species. a_concs (list): Integer array of the arrow concentrations for each species. HNF (list): The HNF matrix for the system we're currently enumerating params (dict): The dictionary of parameters read in from lattice.in supers (bool): True if superperiodic structures are to be kept. accept (float, optional): The acceptance rate for this enumeration. num_wanted (int): The number of structures to pick randomly from the enumerated list. Returns: configs (list): A list of the unique labelings in this system. Raises: ValueError: if the number of configurations found doesn't match the number requested. """ from phenum.grouptheory import get_full_HNF, get_sym_group from phenum.polyaburnside import polya from phenum.tree import brancher, guess_and_check_brancher import phenum.io_utils as io cellsize = sum(concs)/len(params["basis_vecs"]) decorations = arrow_concs(concs, a_concs) # get the symmetry group for this HNF. Assumes the group can be # found in the file labeled by (this_HNF)_sym_group.out if groupfile is None: if sum(a_concs) == 0: arrows = False else: arrows = True sym_g = get_sym_group(params["lat_vecs"],params["basis_vecs"], get_full_HNF(HNF),3,arrows=arrows) agroup = [list(sym_p) for sym_p in zip(sym_g.perm.site_perm,sym_g.perm.arrow_perm)] else: group = io.read_group(groupfile) # get symgroup from HNF and lat_vecs # add [0] to each element of the symmetry group agroup = [[g,[0]] for g in group] # we need to know the concentrations of the species with and # without arrows, we also need to know the number of arrows and # their species so we can undo the previous step later (n_arrows, arrow_types, sorted_concs) = how_many_arrows(decorations) # if we're enumerating a relatively large system (n>=10) but only # want a relatively small number of unique configurations (n<=100) # then we don't need to run the polya algorithm. if (multinomial(concs) > 100000 and num_wanted <= 100) or (arrow_types !=0 and sum(concs) >= 12 and num_wanted <=100): total = 1e10 else: # now find the number of unique arrangements using # polya if arrow_types != 0: total = polya(sorted_concs, agroup, arrowings=arrow_types) else: total = polya(concs, agroup) # generate the random subset to be used. WARNING! for phonon enumerations #we have seen values that are *50* digits long! If the number exceeds #1e9, we change the approach to randomization. from phenum.msg import warn if num_wanted < total: if total < 1e6: from random import shuffle subset = list(range(1, total+1)) shuffle(subset) subset = subset[0:num_wanted] else: # pragma: no cover # only used for data sets to large for test cases. subset = num_wanted elif num_wanted == total: subset = [] else: warn("number of configurations requested exceeds the number of " "unique configurations available.") subset = [] # if we're doing a purely arrow enumeration then we don't need to # do the tree search but instead perform the final step of the # algorithm to find the possible unique displacements of the atoms if len(concs) == 1 and all(decorations) >=0: configs = [] if float(num_wanted)/total < 0.001 and accept is None: small = True a_configs = add_arrows(decorations, agroup, 6, agroup[0:int(cellsize)], accept=accept, num_wanted=num_wanted, small=small,supers=supers) else: small = False a_configs = add_arrows(decorations, agroup, 6, agroup[0:int(cellsize)], accept=accept, num_wanted=num_wanted, supers=supers) count = 1 for config in a_configs: if isinstance(subset, list) and count in subset and not small: configs.append(config) else:# accept is not None or small: configs.append(config) count += 1 else: if (multinomial(concs) > 100000 or (arrow_types != 0 and sum(concs) >= 12)) and num_wanted <= 100 and num_wanted < total: configs = guess_and_check_brancher(sorted_concs, agroup, decorations, 6, supers, cellsize, num_wanted) else: configs = brancher(sorted_concs, agroup, decorations, 6, supers, cellsize, total, subset, accept) if len(configs) != num_wanted and not super: #pragma: no cover #I've never been able to trigger this error. raise ValueError("Warning the enumeration code returned {0} structures when {1} " "were asked for. This should not happen. Please submit a bug " "report on https://github.com/wsmorgan/phonon-enumeration " "including your input files so that this error may be " "corrected.".format(str(len(configs)),str(num_wanted))) if len(configs) == 0: #pragma: no cover #I've neven been able to trigger this error. exit() return configs