chemistrylab.extract_algorithms package

chemistrylab.extract_algorithms.separate module

chemistrylab.extract_algorithms.separate.map_to_state(A, B, C, colors, x=array([0., 0.01010101, 0.02020202, 0.03030303, 0.04040404, 0.05050505, 0.06060606, 0.07070707, 0.08080808, 0.09090909, 0.1010101, 0.11111111, 0.12121212, 0.13131313, 0.14141414, 0.15151516, 0.16161616, 0.17171717, 0.18181819, 0.1919192, 0.2020202, 0.21212122, 0.22222222, 0.23232323, 0.24242425, 0.25252524, 0.26262626, 0.27272728, 0.28282827, 0.2929293, 0.3030303, 0.3131313, 0.32323232, 0.33333334, 0.34343433, 0.35353535, 0.36363637, 0.37373737, 0.3838384, 0.3939394, 0.4040404, 0.41414142, 0.42424244, 0.43434343, 0.44444445, 0.45454547, 0.46464646, 0.47474748, 0.4848485, 0.4949495, 0.5050505, 0.5151515, 0.5252525, 0.53535354, 0.54545456, 0.5555556, 0.56565654, 0.57575756, 0.5858586, 0.5959596, 0.6060606, 0.61616164, 0.6262626, 0.6363636, 0.64646465, 0.65656567, 0.6666667, 0.67676765, 0.68686867, 0.6969697, 0.7070707, 0.7171717, 0.72727275, 0.7373737, 0.74747473, 0.75757575, 0.7676768, 0.7777778, 0.7878788, 0.7979798, 0.8080808, 0.8181818, 0.82828283, 0.83838385, 0.8484849, 0.85858583, 0.86868685, 0.8787879, 0.8888889, 0.8989899, 0.90909094, 0.9191919, 0.9292929, 0.93939394, 0.94949496, 0.959596, 0.969697, 0.97979796, 0.989899, 1.], dtype=float32))[source]

Uses the position and variance of each solvent to stochastically create a layer-view of the vessel

Parameters:
  • A (np.ndarray) – The volume of each solvent

  • B (np.ndarray) – The current positions of the solvent layers in the vessel

  • C (float) – The current variance of the solvent layers in the vessel

  • colors (np.ndarray) – The color of each solvent

Returns:

  • The solvent at each layer position (0.65 for air)

  • The index of the solvent at each position (len(B)-1 for air)

Return type:

Tuple[np.ndarray]

Algorithm:

  1. Discretize the vessel into 100 layers each with one unit of volume

  2. Quantize the volumes into units of size sum(v)/100. (Round up agressively)

  3. Do a checksum to make sure these quantized volumes sum to 100
    1. If the sum of everything that isn’t air is over 100, then decrease the solvent with the largest number of units

    2. Otherwise you can just set the number of air units to 100-sum([all vi which aren’t air])

  4. Find the position of the top layer

  5. For each of the quantized layers, gather the height of each gaussian at that layer position and sample a solvent proportional to this height
    1. This is approximately the same as doing an integral of the solvents distribution over the layer

    2. Unfortunately, the solvent distributions don’t add up to 1 so you have to normalize.

    3. The distributions are more ballparks so you have to keep track of how many units you placed, and set the probability of the layer having a solvent to zero if all the units have already been placed

    4. This also means you may not have placed all of your units by the time you are way outside the variance of your gaussian, so you should keep track of the lowest layer that still has units to place, and make sure those units are all placed once you start to go way past it.

chemistrylab.extract_algorithms.separate.mix(v, Vprev, v_solute, B, C, C0, D, Spol, Lpol, S, mixing)[source]

Calculates the positions and variances of solvent layers in a vessel, as well as the new solute amounts, based on the given inputs.

Parameters:
  • v (np.ndarray) – The volume of each solvent

  • Vprev (np.ndarray) – The volume of each solvent on the previous iteration

  • v_solute (np.ndarray) – The specific volume of each solute (litres per mol)

  • B (np.ndarray) – The current positions of the solvent layers in the vessel

  • C (np.ndarray) – The current variances of the solvent layers in the vessel

  • C0 (float) –

  • D (np.ndarray) – The density of each solvent

  • Spol (np.ndarray) – The relative polarities of the solutes

  • Lpol (np.ndarray) – The relative polarities of the solvents

  • S (np.ndarray) – The current amounts of solutes in each solvent layer (2D array)

  • mixing (float) – The time value assigned to a fully mixed solution

Returns:

  • layers_position: An array of floats representing the new positions of the solvent layers in the vessel

  • layers_variance: An array of floats representing the new variances of the solvent layers in the vessel

  • new_solute_amount: An array of floats representing the new amounts of solutes in each solvent layer

  • var_layer: Modified layer variances which account for the extra volume due to dissolved solutes

Return type:

Tuple[np.ndarray]

Algorithm (Solvent):

  1. Using the volumes and densities of each solvent, determine where each solvent’s center of mass should be at t-> inf

  2. Determine the speed in which each solvent should separate out using the densities

  3. Handle any external changes to the solving (pouring in/out) using v and Vprev
    1. Since there is an injective map between variance and time, it is easier to work with variance
      1. Initial variance is sum(v)/sqrt(12) [gaussian approximation of a uniform distribution]

      2. Final variance is vi/MINVAR -> MINVAR should probably be around sqrt(12) still (but be <=)

    2. Pouring in a solvent should kind of mix around the solution, and since the max variance is sum(v)/sqrt(12) adding in dv/sqrt(12) seems reasonable

    3. For the solvent actually being added, we can assume you are pouring into the top, so it should be mixed the closer to the bottom the solvent layer is. It should also be mixed more depending on how much you are adding.

    4. If adding a solvent causes things to be mixed around a bunch, it should end up mixing the solutes too

  4. Get a time-like variable saying much each solvent is settled using the current variance (Recall the map is injective)

  5. Increment this by the mixing parameter
    1. If time is being decreased by the mixing parameter, we first set T<= Tmax so something which settled for a long time still mixes reasonably fast (and also as T->inf the map between variance and time gets sus cuz of floats)

  6. Use this incremented time to update your layer positions, as well as layer variances

Algorithm (Solute): TODO: Write this out

Module contents