Skip to content

Commit

Permalink
Merge pull request #177 from novonordisk-research/slcb_robustness
Browse files Browse the repository at this point in the history
Method generators
  • Loading branch information
SLCB-NN authored May 2, 2024
2 parents 70511d6 + 3881672 commit 0ca874b
Show file tree
Hide file tree
Showing 30 changed files with 4,077 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ venv/
ENV/
env.bak/
venv.bak/
.env_vars

# Spyder project settings
.spyderproject
Expand Down
27 changes: 27 additions & 0 deletions applications/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from .empower_implementation.empower_tools import (
determine_if_isocratic_method,
determine_last_high_flow_time,
determine_max_compositon_value,
determine_strong_eluent,
post_instrument_methodset_method,
)
from .method_generators.add_isocratic_segment import (
generate_add_isocratic_segment_to_method,
)
from .method_generators.alter_strong_eluent_pct import (
generate_altered_strong_eluent_method_pct,
)
from .method_generators.alter_temperature import generate_altered_temperature_method
from .method_generators.ramp_method import generate_ramp_method

__all__ = [
"post_instrument_methodset_method",
"determine_if_isocratic_method",
"determine_max_compositon_value",
"determine_strong_eluent",
"generate_altered_strong_eluent_method_pct",
"generate_altered_temperature_method",
"generate_ramp_method",
"generate_add_isocratic_segment_to_method",
"determine_last_high_flow_time",
]
117 changes: 117 additions & 0 deletions applications/dev.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from OptiHPLCHandler import EmpowerHandler"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# get api address from .env file\n",
"import os\n",
"from dotenv import load_dotenv\n",
"\n",
"load_dotenv(\"../.env_vars\")\n",
"EMPOWER_API_ADDRESS = os.getenv(\"EMPOWER_API_ADDRESS_PRD\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"\n",
"sys.path.insert(0, \"../\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Create an instance of the EmpowerHandler class\n",
"handler = EmpowerHandler(project=\"WebAPI_test\", address=EMPOWER_API_ADDRESS)\n",
"\n",
"handler.connection.default_get_timeout = 300\n",
"handler.connection.default_post_timeout = 300\n",
"\n",
"# Get the list of methods, select one, and get the method details\n",
"with handler:\n",
" method_list = handler.GetMethodList() # Get the list of instrument methods\n",
" method_name = \"20240430_slcb\"\n",
" full_method = handler.GetInstrumentMethod(method_name)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Logging in to Empower...\n",
"Log in successful.\n",
"Posting SampleSet Method 20240430_slcb_robustness...\n",
"Sample Set Method 20240430_slcb_robustness posted.\n",
"Sample Set Method 20240430_slcb_robustness not run.\n"
]
}
],
"source": [
"from applications.generate_basic_robustness_methods import (\n",
" post_run_basic_robustness_test,\n",
")\n",
"\n",
"# Settings\n",
"plate = \"ANSI-48Vial2mLHolder\"\n",
"plates = {\"1\": plate, \"2\": plate}\n",
"system = \"12_5208_HCLASS_BIN\"\n",
"node = \"Epdkhqr01048\"\n",
"project = \"WebAPI_test\"\n",
"\n",
"post_run_basic_robustness_test(handler, full_method, plates, system, node)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".env",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
131 changes: 131 additions & 0 deletions applications/empower_implementation/empower_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
from typing import List, Optional

from OptiHPLCHandler import EmpowerHandler, EmpowerInstrumentMethod


def post_instrument_methodset_method(
handler: EmpowerHandler,
method: EmpowerInstrumentMethod,
post_method_set_method: bool = True,
):
"""
Posts an instrument method and optionally posts a method set method.
Args:
handler: The handler object used to interact with the instrument.
method: The instrument method to be posted.
post_method_set_method: A boolean indicating whether to post a method set
method.
Default is True.
Returns:
None
"""
handler.PostInstrumentMethod(method)
if post_method_set_method:
method_set_method = {
"name": method.method_name,
"instrumentMethod": method.method_name,
}
handler.PostMethodSetMethod(method_set_method)


def determine_if_isocratic_method(gradient_table: List[dict]) -> bool:
"""
Determines if the method is isocratic based on the gradient table.
Args:
gradient_table (List[dict]): The gradient table to determine if the method is
isocratic.
Returns:
bool: True if the method is isocratic, False otherwise.
"""
composition_table = []
for row in gradient_table:
composition_table.append(
{
key: float(value)
for key, value in row.items()
if key.startswith("Composition")
}
)

composition_set = [dict(t) for t in {tuple(d.items()) for d in composition_table}]

if len(composition_set) != 1:
return False
return True


def determine_max_compositon_value(
gradient_table: List[dict], composition: str
) -> float:
"""
Determines the maximum value in the gradient table.
Args:
gradient_table (List[dict]): The gradient table to determine the maximum value.
composition (str): The name of the composition entry to determine the maximum
value.
Returns:
float: The maximum value in the gradient table.
"""

# Determine the index of the composition with the maximum value
return max([float(step[composition]) for step in gradient_table])


def determine_last_high_flow_time(gradient_table: List[dict]) -> float:
"""
Determine the time at which the last high flow rate occurs in a gradient table.
Parameters
----------
gradient_table : List[dict]
Returns
-------
float
"""
# return max flow rate accross list of dict gradient
max_flow_rate = max([step["Flow"] for step in gradient_table])
last_high_flow_time = 0
for step in gradient_table:
if step["Flow"] == max_flow_rate:
last_high_flow_time = step["Time"]
return last_high_flow_time


def determine_strong_eluent(gradient_table: List[dict]) -> Optional[str]:
"""
Determines the strong eluent from a given gradient table.
Args:
gradient_table (List[dict]): A list of dictionaries representing the gradient
table.
Returns:
Tuple[str, List[str]]: A tuple containing the strong eluent and a list of weak
eluents.
"""
# Get the compositions
compositions = [key for key in gradient_table[0].keys() if "Composition" in key]

# Check if isocratic method
if determine_if_isocratic_method(gradient_table):
raise ValueError("Cannot determine strong eluent for isocratic method.")

# find the composition with the maximum value
list_weak_eluents = []
for composition in compositions:
max_value = determine_max_compositon_value(gradient_table, composition)

# Determine the strong and weak eluents
if float(gradient_table[0][composition]) < float(max_value):
strong_eluent = composition
else:
list_weak_eluents.append(composition)

return strong_eluent, list_weak_eluents
Loading

0 comments on commit 0ca874b

Please sign in to comment.