-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperiodic_table.py
144 lines (112 loc) · 5.96 KB
/
periodic_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import numpy as np
class PeriodicTable(QDialog):# standard periodic table elements (q symbolizes an empty space)
def __init__(self, parent=None):
super(QWidget, self).__init__(parent)
self.parent = parent
self.elements_selected = []
# * --> Lanthanides
# ** --> Actinides
# 18 items per line
pt1 = """H,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,
He,Li,Be,q,q,q,q,q,q,q,q,q,q,B,C,N,O,F,Ne,\
Na,Mg,q,q,q,q,q,q,q,q,q,q,Al,Si,P,S,Cl,Ar,\
K,Ca,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Ga,Ge,As,Se,Br,Kr,
Rb,Sr,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn,Sb,Te,I,Xe,
Cs,Ba,*,Hf,Ta,W,Re,Os,Ir,Pt,Au,Hg,Ti,Pb,Bi,Po,At,Rn,
Fr,Ra,**,Rf,Db,Sg,Bh,Hs,Mt,Ds,Rg,q,q,q,q,q,q,q"""
# Lanthanides and Actinides ...
# 15 items per line
pt2 = """ ,*,La,Ce,Pr,Nd,Pm,Sm,Eu,Gd,Tb,Dy,Ho,Er,Tm,Yb,Lu,
,**,Ac,Th,Pa,U,Np,Pu,Am,Cm,Bk,Cf,Es,Fm,Md,No,Lr"""
# convert standard periodic table elements into a list
list_pt1 = pt1.replace('\n', "").replace('q', " ").split(",")
# convert Lanthanides and Actinides into a list
list_pt2 = pt2.replace('\n', "").split(",")
self.element_dict = \
{'Ru': 'Ruthenium', 'Re': 'Rhenium', 'Ra': 'Radium', 'Rb': 'Rubidium',
'Rn': 'Radon', 'Rh': 'Rhodium', 'Be': 'Beryllium', 'Ba': 'Barium',
'Bi': 'Bismuth', 'Br': 'Bromine', 'H': 'Hydrogen', 'P': 'Phosphorus',
'Os': 'Osmium', 'Hg': 'Mercury', 'Ge': 'Germanium', 'Gd': 'Gadolinium',
'Ga': 'Gallium', 'Pr': 'Praseodymium', 'Pt': 'Platinum',
'Pu': 'Plutonium', 'C': 'Carbon', 'Pb': 'Lead ', 'Pa': 'Proctactinium',
'Pd': 'Palladium', 'Cd': 'Cadmium', 'Po': 'Polonium', 'Pm': 'Promethium',
'Ho': 'Holmium', 'Hf': 'Hafnium', 'K': 'Potassium', 'He': 'Helium',
'Mg': 'Magnesium', 'Mo': 'Molybdenum', 'Mn': 'Manganese', 'O': 'Oxygen',
'S': 'Sulfur', 'W': 'Tungsten', 'Zn': 'Zinc', 'Eu': 'Europium',
'Zr': 'Zirconium', 'Er': 'Erbium', 'Ni': 'Nickel', 'Na': 'Sodium',
'Nb': 'Niobium', 'Nd': 'Neodymium', 'Ne': 'Neon', 'Np': 'Neptunium',
'Fr': 'Francium', 'Fe': 'Iron', 'B': 'Boron', 'F': 'Fluorine',
'Sr': 'Strontium', 'N': 'Nitrogen', 'Kr': 'Krypton', 'Si': 'Silicon',
'Sn': 'Tin', 'Sm': 'Samarium', 'V': 'Vanadium', 'Sc': 'Scandium',
'Sb': 'Antimony', 'Se': 'Selenium', 'Co': 'Cobalt', 'Cl': 'Chlorine',
'Ca': 'Calcium ', 'Ce': 'Cerium', 'Xe': 'Xenon', 'Lu': 'Lutetium',
'Cs': 'Cesium', 'Cr': 'Chromium', 'Cu': 'Copper', 'La': 'Lanthanum',
'Li': 'Lithium', 'Tl': 'Thallium', 'Tm': 'Thulium', 'Th': 'Thorium',
'Ti': 'Titanium', 'Te': 'Tellurium', 'Tb': 'Terbium', 'Tc': 'Technetium',
'Ta': 'Tantalum', 'Yb': 'Ytterbium', 'Dy': 'Dysprosium', 'I': 'Iodine',
'U': 'Uranium', 'Y': 'Yttrium', 'Ac': 'Actinium', 'Ag': 'Silver',
'Ir': 'Iridium', 'Am': 'Americium', 'Al': 'Aluminum', 'As': 'Arsenic',
'Ar': 'Argon', 'Au': 'Gold', 'At': 'Astatine', 'In': 'Indium'}
#GD self.SetBackgroundColour('green')
vsizer = QVBoxLayout()
# use grid layout
gsizer = QGridLayout()
MainGroup = QWidget()
#GD:font = wx.Font(10, wx.MODERN, wx.NORMAL, wx.BOLD)
self.buttons1 = []
index = 0
self.button = []
color = "background-color: lightblue;\n"
for i in range(7):
for j in range(18):
symbol =list_pt1[index]
self.button.append(QPushButton(symbol))
if symbol == 'Al':
color = "background-color: lightgreen;\n"
if symbol == 'Se':
color = "background-color: red;\n"
self.button[index].setStyleSheet(color)
self.button[index].setFixedWidth(25)
self.button[index].setCheckable(1)
#GD:self.buttons1[ix].SetFont(font)
if symbol != ' ':
gsizer.addWidget(self.button[index],i,j)
index+=1
MainGroup.setLayout(gsizer)
# sizer for Lanthanides and Actinides
gsizer2 = QGridLayout()
offset = index
for i in range(2):
for j in range(17):
symbol =list_pt2[index-offset]
self.button.append(QPushButton(symbol))
color = "background-color: pink;\n"
self.button[index].setStyleSheet(color)
self.button[index].setFixedWidth(25)
self.button[index].setCheckable(1)
#self.buttons2[ix].SetFont(font)
if symbol != ' ':
gsizer2.addWidget(self.button[index],i,j)
index+=1
LaAc = QWidget()
LaAc.setLayout(gsizer2)
vsizer.addWidget(MainGroup)
vsizer.addWidget(LaAc)
self.setLayout(vsizer)
OKButton = QPushButton('OK')
OKButton.clicked.connect(self.OnClose)
vsizer.addWidget(OKButton)
self.setLayout(vsizer)
self.setModal(True)
# self.show()
def OnClose(self):
self.elements_selected = []
for btn in self.button:
if btn.isChecked():
if btn.text() in self.element_dict:
self.elements_selected.append(btn.text())
# self.elements_selected = self.parent.elements_selected#.copy()
self.accept()