From 4f4193e22d4a8a09f6ba2686b380f70a3734373d Mon Sep 17 00:00:00 2001 From: jpannizzo <80706334+jpannizzo@users.noreply.github.com> Date: Tue, 7 Dec 2021 10:17:43 -0500 Subject: [PATCH] Revert "fixed dead volume form and acid concentration calculations" --- escalate/core/forms/custom_types.py | 2 +- escalate/core/utilities/calculations.py | 59 +++++++++++------------- escalate/core/views/experiment/create.py | 18 ++------ 3 files changed, 31 insertions(+), 48 deletions(-) diff --git a/escalate/core/forms/custom_types.py b/escalate/core/forms/custom_types.py index 274669f5..336f5c6a 100644 --- a/escalate/core/forms/custom_types.py +++ b/escalate/core/forms/custom_types.py @@ -41,7 +41,7 @@ def get_helper(): class SingleValForm(Form): value = ValFormField(required=False) - uuid = CharField(widget=HiddenInput, required=False) + uuid = CharField(widget=HiddenInput) class RobotForm(Form): diff --git a/escalate/core/utilities/calculations.py b/escalate/core/utilities/calculations.py index 724aa594..268414f9 100644 --- a/escalate/core/utilities/calculations.py +++ b/escalate/core/utilities/calculations.py @@ -35,7 +35,6 @@ def conc_to_amount(exp_uuid): conc_val = conc.nominal_value.value conc_unit = conc.nominal_value.unit conc = Q_(conc_val, conc_unit) - mat_type=reagent_material.template.material_type.description phase = reagent_material.material.phase if not phase: raise ValueError( @@ -54,7 +53,6 @@ def conc_to_amount(exp_uuid): input_data[reagent_material] = { "concentration": conc, - "material_type": mat_type, "phase": phase, "molecular weight": mw, "density": d, @@ -182,20 +180,28 @@ def generate_input_f(reagent, MW, density): return input_data -def calculate_amounts(input_data, target_vol, dead_vol="4000 uL"): +def calculate_amounts(input_data, target_vol, dead_vol="3000 uL"): """ - Given input data dictionary for reagents and target/dead volumes, + Given input data from helper function and target/dead volumes (strings with units), returns amounts of each reagent component needed to achieve desired concentrations. For solids/solutes, amounts will be reported in grams. - For liquid/solvent/acid, amount will be reported in mL. + For liquid/solvent, amount will be reported in mL. """ - amounts = {} - exact_amounts = {} #use this to store exact values for more precise calculations + # input_data comes from helper function above + # target_vol and dead_vol must be input as strings with units + + amounts = {} # convert volumes to mL and store in proper Pint format + # mag_t=float(total_vol.split()[0]) + # unit_t= str(total_vol.split()[1]) + + # mag_d=float(dead_vol.split()[0]) + # unit_d=str(dead_vol.split()[1]) + vol = Q_(target_vol).to(units.ml) dead = Q_(dead_vol).to(units.ml) total_vol = vol + dead @@ -208,35 +214,22 @@ def calculate_amounts(input_data, target_vol, dead_vol="4000 uL"): * val["molecular weight"] ) # convert concentration to moles to mass - exact_amounts[key] = grams amounts[key] = round(grams, 2) - - for key, val in input_data.items(): - if val["phase"] == "liquid": - if val["material_type"]=="acid": # for the acids - neat=((100/val["molecular weight"])/ (100/val['density'])).to(units.mol/units.ml) #concentration of neat (pure) acid - vol= total_vol* val["concentration"].to(units.mol / units.ml)/neat #dilution - exact_amounts[key]=vol - amounts[key]=round(vol, 2) - - for substance, amount in exact_amounts.items(): - # for solids - if input_data[substance]["phase"]=='solid': - total_vol -= amount / input_data[substance]["density"] # find the volume and subtract from total - - #for acids - elif input_data[substance]["phase"]=='liquid': - total_vol -= vol # find the volume and subtract from total + + for substance, amount in amounts.items(): # for all solids + total_vol -= amount / input_data[substance]["density"] # find the volume + # find the volume. subtract from total volume - this is how much liquid will be needed for key, val in input_data.items(): - if val["phase"] == "liquid": - if val["material_type"]!="acid": #for the solvent(s) - if "volume fraction" in val.keys(): # if there is more than one solvent - amounts[key] = round( - total_vol * val["volume fraction"], 2 - ) # amount is a fraction of the remaining available volume - else: #if there is just one solvent - amounts[key] = round(total_vol, 2) # amount is the remaining available volume + if val["phase"] == "liquid": # for the solvent(s) + if "volume fraction" in val.keys(): # if there is more than one solvent + amounts[key] = round( + total_vol * val["volume fraction"], 2 + ) # amount is a fraction of the remaining available volume + else: # if there's just one solvent + amounts[key] = round( + total_vol, 2 + ) # amount is the remaining available volume """ for key, val in amounts.items(): #convert amounts from Pint format to strings with val and unit diff --git a/escalate/core/views/experiment/create.py b/escalate/core/views/experiment/create.py index 71c9ac3a..08056128 100644 --- a/escalate/core/views/experiment/create.py +++ b/escalate/core/views/experiment/create.py @@ -621,18 +621,9 @@ def process_robot_formsets(self, exp_uuid, request, context): for reagent_formset in formsets: if reagent_formset.is_valid(): vector = self.save_forms_reagent(reagent_formset, experiment_copy_uuid, exp_concentrations) - #try: - exp_concentrations = prepare_reagents( - reagent_formset, exp_concentrations - ) - #except TypeError as te: - # messages.error(request, str(te)) - - dead_volume_form = SingleValForm(request.POST, prefix="dead_volume") - if dead_volume_form.is_valid(): - dead_volume = dead_volume_form.cleaned_data['value'] - else: - dead_volume = None + #exp_concentrations = prepare_reagents( + #reagent_formset, exp_concentrations + #) # post reaction parameter form # get label here and get form out of label, use label for description @@ -946,8 +937,7 @@ def process_automated_formsets(self, request: HttpRequest, context: dict[str, An # Save dead volumes should probably be in a separate function dead_volume_form = SingleValForm(request.POST, prefix="dead_volume") if dead_volume_form.is_valid(): - dead_volume=dead_volume_form.cleaned_data['value'] - #dead_volume = dead_volume_form.value + dead_volume = dead_volume_form.value else: dead_volume = None