-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCycloalkeneGeneration.py
87 lines (59 loc) · 2.61 KB
/
CycloalkeneGeneration.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
import random
import math
from numpy.random import randint
# Useful for whole program:
alphabet = [*"abcdefghijklmnopqrstuvwxyz"]
alkyl_groups = ["methyl", "ethyl", "propyl", "isopropyl", "butyl", "t-butyl", "s-butyl", "isobutyl"]
alkyl_groups_dict = { "methyl": "m", "ethyl": "e", "propyl": "p", "isopropyl": "i", "butyl": "b", "t-butyl": "b", "s-butyl": "b", "isobutyl": "i" }
exo_groups = ["methylene", "vinyl", "allyl"]
exo_groups_dict = { "methylene": "m", "vinyl": "v", "allyl": "a" }
alkene_prefixes = ["prop", "but", "pent", "hex", "hept", "oct"]
class cycloalkene:
def __init__(self, prefix, group, length, endex, locale, nulocale):
self.prefix = prefix
#print(self.prefix)
self.group = group
#print(self.group)
self.length = length
#print(self.length)
self.endex = endex
#print(self.endex)
self.locale = locale
#print(self.locale)
self.nulocale = nulocale
def iupac_name(self):
if self.endex == "exo":
return f"{self.locale[0]}-{self.group[0]}-{self.locale[1]}-{self.group[1]} cyclo{self.prefix}ane"
if self.endex == "end":
return f"{self.locale[0]}-{self.group[0]} cyclo{self.prefix}ene"
def cyclogen(end_exo):
prfx = random.choice(alkene_prefixes)
leng = alkene_prefixes.index(prfx) + 3
if end_exo == "end":
grp = [random.choice(alkyl_groups)]
alkyl_location = randint(1, math.ceil(float(leng)/2)+2)
while alkyl_location == 2:
alkyl_location = randint(1, math.ceil(float(leng)/2)+2)
locale = [alkyl_location]
nulocale = [alkyl_location]
if end_exo == "exo":
grp = [random.choice(exo_groups), random.choice(alkyl_groups)]
if grp[0] == "methylene":
alkyl_location = randint(2, math.ceil(float(leng)/2)+2)
else:
alkyl_location = randint(1, math.ceil(float(leng)/2)+2)
if alphabet.index(alkyl_groups_dict[grp[1]]) > alphabet.index(exo_groups_dict[grp[0]]):
locale = [1, alkyl_location]
nulocale = alkyl_location
if alphabet.index(exo_groups_dict[grp[0]]) >= alphabet.index(alkyl_groups_dict[grp[1]]):
grp = [grp[1], grp[0]]
locale = [alkyl_location, 1]
nulocale = alkyl_location
return cycloalkene(prfx, grp, leng, end_exo, locale, nulocale)
if __name__ == "__main__":
#for i in range(100):
# cyclo1 = cyclogen("end")
# print("#", cyclo1.iupac_name())
for i in range(10):
cyclo1 = cyclogen("exo")
print("#", cyclo1.iupac_name())