|
10 | 10 |
|
11 | 11 |
|
12 | 12 | class Namer(object): # IUPAC Names for now only
|
| 13 | + |
| 14 | + """ |
| 15 | + Bonds are represented as follows: |
| 16 | + - : Single bond |
| 17 | + = : Double bond |
| 18 | + ~ : Triple bond |
| 19 | +
|
| 20 | + Examples: |
| 21 | + CH~CH |
| 22 | + CH~C-C~C-CH=C=C=CH2 |
| 23 | + """ |
| 24 | + |
13 | 25 | symbol = '\u2261' # The triple bond symbol ≡
|
14 | 26 | subscripts = str.maketrans("0123456789", "₀₁₂₃₄₅₆₇₈₉") # Subscripts for molecular and structural formula
|
15 | 27 |
|
@@ -169,18 +181,24 @@ class ValencyError(Exception):
|
169 | 181 |
|
170 | 182 | multipl_suffixes = {2: "di", 3: "tri", 4: "tetra", 5: "penta", 6: "hexa", 7: "hepta", 8: "octa", 9: "nona"}
|
171 | 183 |
|
172 |
| -compound1 = Namer('CH3-C~C-CH3') |
173 |
| -compound2 = Namer('CH~CH') |
174 |
| -compound3 = Namer('CH~C-C~C-CH=C=C=CH2') |
175 |
| -compound4 = Namer('CH4') |
176 |
| -compound5 = Namer('CH2=CH-CH=CH-CH=CH2') |
177 |
| -compound6 = Namer('CH2=CH2') |
178 |
| -compound7 = Namer('CH~C-CH=CH2') |
179 |
| - |
180 |
| -print(f"{compound1}\n{compound1.molecular_formula()}\n{compound1.analyser()}\n") |
181 |
| -print(f"{compound2}\n{compound2.molecular_formula()}\n{compound2.analyser()}\n") |
182 |
| -print(f"{compound3}\n{compound3.molecular_formula()}\n{compound3.analyser()}\n") |
183 |
| -print(f"{compound4}\n{compound4.molecular_formula()}\n{compound4.analyser()}\n") |
184 |
| -print(f"{compound5}\n{compound5.molecular_formula()}\n{compound5.analyser()}\n") |
185 |
| -print(f"{compound6}\n{compound6.molecular_formula()}\n{compound6.analyser()}\n") |
186 |
| -print(f"{compound7}\n{compound7.molecular_formula()}\n{compound7.analyser()}\n") |
| 184 | +def main(): |
| 185 | + print("Type `/help` to get usage information.") |
| 186 | + |
| 187 | + while True: |
| 188 | + try: |
| 189 | + compound_struct = input("Condensed structure > ") |
| 190 | + if compound_struct.strip() == "/help": |
| 191 | + print(Namer.__doc__) |
| 192 | + else: |
| 193 | + compound = Namer(compound_struct.strip()) |
| 194 | + print(f"\n{compound}\n{compound.molecular_formula()}\n{compound.analyser()}\n") |
| 195 | + |
| 196 | + except EOFError: |
| 197 | + print("\nExiting...") |
| 198 | + quit() |
| 199 | + |
| 200 | + except Exception: |
| 201 | + print("Invalid input!") |
| 202 | + |
| 203 | +if __name__ == "__main__": |
| 204 | + main() |
0 commit comments