The Miller-Urey experiment is a famous experiment that was conducted in 1953 by Stanley Miller and Harold Urey at the University of Chicago (now the University of California), San Diego and published the following year. The experiment used water, methane, ammonia and hydrogen. The chemicals were sealed inside a sterile array of glass flasks connected in a loop, with one flask half-full of liquid water and another flask containing a pair of electrodes. The liquid water was heated to induce evaporation, sparks were fired between the electrodes to simulate lightning through the atmosphere and water vapor, and then the atmosphere was cooled again so that the water could condense and trickle back into the first flask in a continuous cycle.
Within a day, the mixture has turned pink in color, and at the end of two weeks of continuous operation, Miller and Urey observed that as much as 10–15% of the carbon within the system was now in the form of organic compounds. Two percent of the carbon had formed amino acids that are used to make proteins in living cells, with glycine as the most abundant. Sugars were also formed. Nucleic acids were not formed within the reaction. 18% of the methane-molecules became bio-molecules. The rest turned into hydrocarbons like bitumen. The experiment was seen by some as a proof of how life on Earth was synthesized from inorganic compounds — the so-called primordial soup. A process called abiogenesis.
In this exercise, both molecules and mixtures are represented as dictionaries whose keys are formed by the symbolic names of the atoms that occur in it and the corresponding values indicate the number of contained atoms. You are asked to:
Write a function abiogenesis that takes a molecule and a mixture as its arguments. The function must return a boolean that indicates whether or not the molecule can be formed by the atoms contained in the mixture. The molecule can be formed if all its atoms are sufficiently contained in the mixture.
Write a function readMolecules that takes the location of a text file as its argument. Each line of the file contains the name of a molecule, followed by a description of the atomic composition of the molecule. This description is formatted as a listing of the symbolic names of the atoms, each time followed by the number of atoms contained in the molecule. All fields in this list are separated by one or more spaces. The function must return a dictionary, whose keys are the names of the molecules that occur in the file. Each molecule name is mapped to a dictionary that describes the atomic composition of the molecule.
Write a function experiment1 that takes two dictionaries as its arguments. The first dictionary contains the composition of a series of molecules that are targeted as the end product of the experiment, and has the same format as the dictionary returned by the function readMolecules. The second dictionary describes the mixture used in the experiment. The function must return an alphabetically ordered list of the molecule names from the first dictionary that can be formed based on the given mixture. Note that each molecule needs to be treated in isolation: there is no need to check whether there are sufficient atoms in the mixture to form all the molecules from the first dictionary.
Write a function experiment2 that takes the same two dictionary arguments as the function experiment1. The function must return a Boolean value that indicates whether or not there are sufficient atoms in the mixture to form one molecule for each molecule contained in the first dictionary.
In the following interactive session we assume that the text file molecules.txt1 is located in the current directory.
>>> soup = {'N':2, 'Na':2, 'O':5, 'H':3}
>>> abiogenesis({'Si': 1, 'O': 2}, soup)
False
>>> abiogenesis({'H': 3, 'N': 1}, soup)
True
>>> molecules = readMolecules('molecules.txt')
>>> molecules['sand']
{'Si': 1, 'O': 2}
>>> molecules['ammonia']
{'H': 3, 'N': 1}
>>> experiment1(molecules, soup)
['ammonia', 'lye']
>>> molecules1 = {'ammonia': {'H': 3, 'N': 1}, 'lye': {'Na': 1, 'O': 1, 'H': 1}}
>>> experiment2(molecules1, soup)
True
>>> molecules = {'sand': {'Si': 1, 'O': 2}, 'ammonia': {'H': 3, 'N': 1}}
>>> experiment2(molecules, soup)
False