Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General lint and formatting #6

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion notebooks/Zn-EDTA
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,4 @@ Tit 3
10.0480 -296.5 0
10.2402 -297.9 0
10.4345 -299.2 0
10.6300 -300.6 1
10.6300 -300.6 1
19 changes: 11 additions & 8 deletions notebooks/multidimensinal_matrix.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"source": [
"import numpy as np\n",
"from libeq.data_structure import SolverData\n",
"from libeq import EqSolver\n",
"from libeq.solver import species_concentration, fobj, damping\n",
"import numpy as np\n",
"from libeq.solver import species_concentration\n",
"\n",
"# Create SolverData object\n",
"solver_data = SolverData.load_from_bstac(\n",
Expand Down Expand Up @@ -152,7 +150,7 @@
"c1 = c\n",
"c2 = species_concentration(c, log_beta, stoichiometry, solid_stoichiometry)\n",
"\n",
"c1 + np.sum(c2[:,np.newaxis,:]*stoichiometry[np.newaxis, ...],axis=2) - c"
"c1 + np.sum(c2[:, np.newaxis, :] * stoichiometry[np.newaxis, ...], axis=2) - c"
]
},
{
Expand All @@ -174,7 +172,12 @@
}
],
"source": [
"(species_concentration(c, log_beta, stoichiometry, solid_stoichiometry, full=True)[:,np.newaxis,:] * full_stoichiometry).sum(axis=2)"
"(\n",
" species_concentration(c, log_beta, stoichiometry, solid_stoichiometry, full=True)[\n",
" :, np.newaxis, :\n",
" ]\n",
" * full_stoichiometry\n",
").sum(axis=2)"
]
},
{
Expand All @@ -187,7 +190,7 @@
"arr = np.arange(32).reshape(2, 16)\n",
"\n",
"# Create a diagonal matrix from the rows of the array using broadcasting\n",
"diag_matrices = np.einsum('ij,jk->ijk', arr, np.eye(arr.shape[1]))"
"diag_matrices = np.einsum(\"ij,jk->ijk\", arr, np.eye(arr.shape[1]))"
]
},
{
Expand Down Expand Up @@ -225,8 +228,8 @@
"J = stoichiometry @ diag_matrices @ stoichiometry.T\n",
"\n",
"diagonal_indices = np.diag_indices(J.shape[1])\n",
"J[:,diagonal_indices[0], diagonal_indices[1]] += arr[:, :3]\n",
"J\n"
"J[:, diagonal_indices[0], diagonal_indices[1]] += arr[:, :3]\n",
"J"
]
},
{
Expand Down
19 changes: 9 additions & 10 deletions notebooks/staco4.inp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ _________________Input File______________________
=1: if the ionic strength varies in some titrations or if different
titrations were performed at different ionic strengths
=2: as ICD=1, but C,D and E for E0 are given as input
WESP: weights=1/DV^wesp
If WESP>0, calculations are performed two steps. The first is
the normal one - according to the given input instructions -.
The second step, the calculations are performed giving each point
a new weight on the basis of the residual calculated in the first
WESP: weights=1/DV^wesp
If WESP>0, calculations are performed two steps. The first is
the normal one - according to the given input instructions -.
The second step, the calculations are performed giving each point
a new weight on the basis of the residual calculated in the first
step: W=(dV)^WESP.
SHLIM: limit for shifts in BSTAC4 and FBSTAC4 (if SHLIM=0 no limit)
(not used in STACO4 and FSTACO4)

3) (NC times)
COMP
COMP
COMP: name of mass balance equation

4) TEMP,PHI,PHF
Expand Down Expand Up @@ -126,7 +126,7 @@ goto item 10
BLOG: log(BETA)
IB: reference ionic strenght (to be given only if IREF<0)
C,D,E: parameters of Debye-Huckel equation
(if C=D=E=0 then:
(if C=D=E=0 then:
C= c0 p* + c1 z*
D= d0 p* + d1 z*
E= e0 p* + e1 z* )
Expand Down Expand Up @@ -156,7 +156,7 @@ goto item 10
refers to the component NCET

12) (NC times)
CO,CTT,LOK
CO,CTT,LOK
CO: initial concentration in the titration vessel (mol/L)
CTT: concentration in the titrant (mol/L)
LOK = 0: CO constant
Expand Down Expand Up @@ -191,7 +191,7 @@ goto item 10
= 1: JB refined
LOK4 = 0: SLOPE constant
= 1: SLOPE refined

16) V,E,(SIGMA),IND
V: titrant volume
E: potential (or pH, if EO=0)
Expand All @@ -214,4 +214,3 @@ goto item 10
(**) STACO4, FSTACO4: the same parameters must be constrained
for all the titrations
BSTAC4, FBSTAC4: one can constrain several groups of parameters

87 changes: 1 addition & 86 deletions notebooks/test_bstac_import.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -235,96 +235,11 @@
" result[name] = parsed_section\n",
" line_counter += ns\n",
" elif repeat == \"end_of_file\":\n",
" parsed_section = process_func(\n",
" lines[line_counter:], result[\"JW\"], nc\n",
" )\n",
" parsed_section = process_func(lines[line_counter:], result[\"JW\"], nc)\n",
" result[name] = parsed_section\n",
"\n",
" return result"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from libeq.parsers.bstac import parse_file\n",
"\n",
"with open(\"/Users/lorenzo/Coding/libeq/notebooks/Zn-EDTA\", \"r\") as file:\n",
" lines = file.readlines()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"res = parse_file(lines)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'C0': 0.001944, 'CTT': 0.0, 'LOK': 0},\n",
" {'C0': 0.001988, 'CTT': 0.0, 'LOK': 1},\n",
" {'C0': 0.028132, 'CTT': -0.2009, 'LOK': 1}]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res[\"titrations\"][0][\"components_concentrations\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"# your list of dictionaries\n",
"ix_values = [[d[key] for key in d if key.startswith('IX')] for d in res[\"species\"]]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 1, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 1, 1, 1],\n",
" [ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1],\n",
" [-1, -1, -2, -3, -4, -1, -6, 1, 2, 3, 4, 5, 6, 0, 1, -1]])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"np.array(ix_values).T"
]
}
],
"metadata": {
Expand Down
Loading