Skip to content

Commit

Permalink
Fix the 3st_eyring model
Browse files Browse the repository at this point in the history
  • Loading branch information
gbouvignies committed Apr 28, 2023
1 parent ff26264 commit 04c9ad1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 11 additions & 8 deletions chemex/models/kinetic/settings_3st_eyring.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from functools import lru_cache
from itertools import combinations
from itertools import permutations
from typing import TYPE_CHECKING

import numpy as np
Expand Down Expand Up @@ -43,37 +43,37 @@ def calculate_kij_3st_eyring(
ddg_ij = np.array(
(
dh_ab - dh_a - kelvin * (ds_ab - ds_a),
dh_ab - dh_b - kelvin * (ds_ab - ds_b),
dh_ac - dh_a - kelvin * (ds_ac - ds_a),
dh_ac - dh_c - kelvin * (ds_ac - ds_c),
dh_ab - dh_b - kelvin * (ds_ab - ds_b),
dh_bc - dh_b - kelvin * (ds_bc - ds_b),
dh_ac - dh_c - kelvin * (ds_ac - ds_c),
dh_bc - dh_c - kelvin * (ds_bc - ds_c),
)
)
kij_values = kbt_h * np.exp(-ddg_ij / rt)
kij_names = (f"k{i}{j}" for i, j in combinations("abc", 2))
kij_names = (f"k{i}{j}" for i, j in permutations("abc", 2))
return dict(zip(kij_names, kij_values))


def create_kij_3st_eyring_settings(temperature: float) -> dict[str, ParamLocalSetting]:
return {
f"{i}{j}": ParamLocalSetting(
f"k{i}{j}": ParamLocalSetting(
name_setting=NameSetting(f"k{i}{j}", "", TPL),
expr=(
f"calculate_kij_3st_eyring({{dh_b}}, {{ds_b}}, {{dh_c}}, {{ds_c}}, "
f"{{dh_ab}}, {{ds_ab}}, {{dh_ac}}, {{ds_ac}}, {{dh_bc}}, {{ds_bc}},"
f" {temperature})['k{i}{j}']"
),
)
for i, j in combinations("abc", 2)
for i, j in permutations("abc", 2)
}


def create_pop_3st_eyring_settings() -> dict[str, ParamLocalSetting]:
return {
f"p{state}": ParamLocalSetting(
name_setting=NameSetting(f"p{state}", "", TPL),
expr=f"pop_2st({{kab}}, {{kba}}, {{kac}}, {{kca}}, {{kbc}}, {{kcb}})['p{state}']",
expr=f"pop_3st({{kab}}, {{kba}}, {{kac}}, {{kca}}, {{kbc}}, {{kcb}})['p{state}']",
)
for state in "abc"
}
Expand Down Expand Up @@ -141,5 +141,8 @@ def make_settings_3st_eyring(conditions: Conditions) -> dict[str, ParamLocalSett

def register() -> None:
model_factory.register(name=NAME, setting_maker=make_settings_3st_eyring)
user_functions = {"kij_2st_eyring": calculate_kij_3st_eyring, "pop_3st": pop_3st}
user_functions = {
"calculate_kij_3st_eyring": calculate_kij_3st_eyring,
"pop_3st": pop_3st,
}
user_function_registry.register(name=NAME, user_functions=user_functions)
2 changes: 0 additions & 2 deletions chemex/parameters/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def _set_to_fit(parameters: Parameters, name_map: dict[str, str], fitted: list[s
def _build_parameters(
settings: LocalSettings, spin_system: SpinSystem, conditions: Conditions
) -> tuple[dict[str, str], Parameters]:

param_names = {
local_name: setting.name_setting.get_param_name(spin_system, conditions)
for local_name, setting in settings.items()
Expand Down Expand Up @@ -71,7 +70,6 @@ def _build_parameters(
def create_parameters(
config: ExperimentConfig, liouvillian: LiouvillianIS
) -> dict[str, str]:

# A copy is done because the output of '_build_settings' is cached
settings, settings_mf = _build_settings(liouvillian.basis, config.conditions)

Expand Down

0 comments on commit 04c9ad1

Please sign in to comment.