Posts

Number of Acyclic Alkane Isomers - Python Version

Image
 In the previous post I have outlined the method of calculating the number of open-chain alkane isomers in R. Since the calculation times for higher alkanes were impractically long, I have loosely translated, with minor changes, my program into python. The code follows below. As for the results - no substantial improvement could be observed. My next attempt would be in Java. import networkx as nx import matplotlib.pyplot as plt import copy from datetime import datetime def addc(graph):     n = graph.number_of_nodes()     list = []     for i in range(n):         if graph.degree[i] < 4:                     graph_c = copy.deepcopy(graph)             graph_c.add_node(n)             graph_c.add_edge(i, n)             res = [nx.is_isomorphic(gr, graph_c) for gr in list]             if not any(res):                          list.append(graph_c)     return list def comblist(list1, list2):     list_out = copy.deepcopy(list1)         for gr2 in list2:         res = [nx.is_isomorphic(gr2,gr1)

Number of Acyclic Alkane Isomers

Image
Introduction At the organic chemistry lecture sometimes this question arises: how to find out how many isomers does have an open-chain alkane  C n H 2n+2 ? The question has no simple answer. Despite some youtube chemistry teachers offering a ready magic formula, the fact is that the number of isomers has be count separately for each n . In practice, this means generating every possible isomer for a given number of C-atoms. Please refer to the proffesional sources if you need the specific details covering this issue [1,2]. The Goal I wanted to design a simple and comprehensible algorithm for the demonstration purposes. The algorithm should allow counting all possible alkane isomers and could be recreated, modified and employed by users without a deep knowledge of the mathematical sciences. To simplify the task, the stereoisomers will be ignored. The Method  In order to calculate all combination of the isomers, I have built the logical scheme shown at the flowchart (Fig. 1) and described