Skip to content

Commit 8962778

Browse files
v3.0.5
1 parent 6cdab82 commit 8962778

File tree

8 files changed

+157
-4
lines changed

8 files changed

+157
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ libraries:
4444

4545
- [Clapeyron.jl](https://github.com/ClapeyronThermo/Clapeyron.jl)
4646
- [Thermo](https://github.com/CalebBell/thermo)
47+
- [yaeos (Fortran)](https://github.com/ipqa-research/yaeos)
4748

4849

4950
# Example of use
@@ -62,10 +63,12 @@ hexane = Groups("hexane")
6263

6364
print(hexane.unifac.subgroups)
6465
print(hexane.psrk.subgroups)
66+
print(hexane.dortmund.subgroups)
6567
print(hexane.joback.subgroups)
6668
print(hexane.agani.primary.subgroups)
6769
```
6870

71+
{'CH3': 2, 'CH2': 4}
6972
{'CH3': 2, 'CH2': 4}
7073
{'CH3': 2, 'CH2': 4}
7174
{'-CH3': 2, '-CH2-': 4}
@@ -78,12 +81,14 @@ propanol = Groups("CCCO", "smiles")
7881

7982
print(propanol.unifac.subgroups)
8083
print(propanol.psrk.subgroups)
84+
print(propanol.dortmund.subgroups)
8185
print(propanol.joback.subgroups)
8286
print(propanol.agani.primary.subgroups)
8387
```
8488

8589
{'CH3': 1, 'CH2': 2, 'OH': 1}
8690
{'CH3': 1, 'CH2': 2, 'OH': 1}
91+
{'CH3': 1, 'CH2': 2, 'OH (P)': 1}
8792
{'-CH3': 1, '-CH2-': 2, '-OH (alcohol)': 1}
8893
{'CH3': 1, 'CH2': 2, 'OH': 1}
8994

docs/source/tutorial/writers.ipynb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,54 @@
160160
"\n",
161161
"GE.gammas()"
162162
]
163+
},
164+
{
165+
"cell_type": "markdown",
166+
"metadata": {},
167+
"source": [
168+
"#### yaeos (https://github.com/ipqa-research/yaeos)\n",
169+
"\n",
170+
"`ugropy` also provides a translator of its subgroups dictionaries to the\n",
171+
"`yaeos` Fortran source code."
172+
]
173+
},
174+
{
175+
"cell_type": "code",
176+
"execution_count": 1,
177+
"metadata": {},
178+
"outputs": [
179+
{
180+
"name": "stdout",
181+
"output_type": "stream",
182+
"text": [
183+
"use yaeos__models_ge_group_contribution_unifac, only: Groups\n",
184+
"\n",
185+
"type(Groups) :: molecules(3)\n",
186+
"\n",
187+
"molecules(1)%groups_ids = [1, 2]\n",
188+
"molecules(1)%number_of_groups = [2, 4]\n",
189+
"\n",
190+
"molecules(2)%groups_ids = [1, 2, 14]\n",
191+
"molecules(2)%number_of_groups = [1, 1, 1]\n",
192+
"\n",
193+
"molecules(3)%groups_ids = [1, 2, 3, 7, 8]\n",
194+
"molecules(3)%number_of_groups = [2, 3, 1, 1, 1]\n",
195+
"\n",
196+
"\n"
197+
]
198+
}
199+
],
200+
"source": [
201+
"from ugropy import Groups, unifac, writers\n",
202+
"\n",
203+
"names = [\"hexane\", \"ethanol\", \"limonene\"]\n",
204+
"\n",
205+
"grps = [Groups(n).unifac.subgroups for n in names]\n",
206+
"\n",
207+
"fortran_code = writers.to_yaeos(grps, unifac)\n",
208+
"\n",
209+
"print(fortran_code)"
210+
]
163211
}
164212
],
165213
"metadata": {

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ markers = [
3535

3636
[project]
3737
name = "ugropy"
38-
version = "3.0.0"
38+
version = "3.0.5"
3939
authors = [{name = "Brandolín, Salvador Eduardo", email = "[email protected]"}]
4040
license = {text = "The MIT License"}
4141
readme = "README.md"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
3+
from ugropy import DefaultSolver
4+
5+
6+
def test_ilp_solver():
7+
problem = DefaultSolver([], {})
8+
9+
with pytest.raises(NotImplementedError):
10+
super(DefaultSolver, problem).solve_one_problem([])
11+
12+
with pytest.raises(NotImplementedError):
13+
super(DefaultSolver, problem).solve()

tests/writers/test_to_clapeyron.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def test_making_it_explode():
243243
molecules_names=["limonene", "ethanol"],
244244
psrk_groups=[{"CH3": 1, "CH2": 1, "OH": 1}],
245245
)
246-
246+
247247
with pytest.raises(ValueError):
248248
to_clapeyron(
249249
molecules_names=["limonene", "ethanol"],

tests/writers/test_to_yaeos.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from ugropy import dortmund, psrk, unifac, writers
2+
3+
4+
def test_to_yaeos_dortmund():
5+
names = ["ethane", "ethanol", "cyclohexane", "water"]
6+
7+
groups = [dortmund.get_groups(name).subgroups for name in names]
8+
9+
fortran_code = writers.to_yaeos(groups, dortmund)
10+
11+
expected = (
12+
"use yaeos__models_ge_group_contribution_unifac, only: Groups\n"
13+
"\n"
14+
"type(Groups) :: molecules(4)\n"
15+
"\n"
16+
"molecules(1)%groups_ids = [1]\n"
17+
"molecules(1)%number_of_groups = [2]\n"
18+
"\n"
19+
"molecules(2)%groups_ids = [1, 2, 14]\n"
20+
"molecules(2)%number_of_groups = [1, 1, 1]\n"
21+
"\n"
22+
"molecules(3)%groups_ids = [78]\n"
23+
"molecules(3)%number_of_groups = [6]\n"
24+
"\n"
25+
"molecules(4)%groups_ids = [16]\n"
26+
"molecules(4)%number_of_groups = [1]\n"
27+
"\n"
28+
)
29+
30+
assert fortran_code == expected
31+
32+
33+
def test_to_yaeos_psrk():
34+
names = ["ethane", "ethanol", "cyclohexane", "oxygen"]
35+
36+
groups = [psrk.get_groups(name).subgroups for name in names]
37+
38+
fortran_code = writers.to_yaeos(groups, psrk)
39+
40+
expected = (
41+
"use yaeos__models_ge_group_contribution_unifac, only: Groups\n"
42+
"\n"
43+
"type(Groups) :: molecules(4)\n"
44+
"\n"
45+
"molecules(1)%groups_ids = [1]\n"
46+
"molecules(1)%number_of_groups = [2]\n"
47+
"\n"
48+
"molecules(2)%groups_ids = [1, 2, 14]\n"
49+
"molecules(2)%number_of_groups = [1, 1, 1]\n"
50+
"\n"
51+
"molecules(3)%groups_ids = [2]\n"
52+
"molecules(3)%number_of_groups = [6]\n"
53+
"\n"
54+
"molecules(4)%groups_ids = [119]\n"
55+
"molecules(4)%number_of_groups = [1]\n"
56+
"\n"
57+
)
58+
59+
assert fortran_code == expected
60+
61+
62+
def test_to_yaeos_unifac():
63+
names = ["ethane", "ethanol", "toluene", "water"]
64+
65+
groups = [unifac.get_groups(name).subgroups for name in names]
66+
67+
fortran_code = writers.to_yaeos(groups, unifac)
68+
69+
expected = (
70+
"use yaeos__models_ge_group_contribution_unifac, only: Groups\n"
71+
"\n"
72+
"type(Groups) :: molecules(4)\n"
73+
"\n"
74+
"molecules(1)%groups_ids = [1]\n"
75+
"molecules(1)%number_of_groups = [2]\n"
76+
"\n"
77+
"molecules(2)%groups_ids = [1, 2, 14]\n"
78+
"molecules(2)%number_of_groups = [1, 1, 1]\n"
79+
"\n"
80+
"molecules(3)%groups_ids = [9, 11]\n"
81+
"molecules(3)%number_of_groups = [5, 1]\n"
82+
"\n"
83+
"molecules(4)%groups_ids = [16]\n"
84+
"molecules(4)%number_of_groups = [1]\n"
85+
"\n"
86+
)
87+
88+
assert fortran_code == expected

ugropy/writers/clapeyron.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def to_clapeyron(
6363
"PSRK groups list must have the same amount of elements than"
6464
"the molecules name list."
6565
)
66-
66+
6767
if dortmund_groups and len(dortmund_groups) != len(molecules_names):
6868
raise ValueError(
6969
"Dortmund groups list must have the same amount of elements than"

ugropy/writers/yaeosf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def to_yaeos(mol_subgroups_list: List[dict], model: GibbsModel) -> str:
2323
str
2424
Yaeos Fortran source code.
2525
"""
26-
2726
n_mol = len(mol_subgroups_list)
2827

2928
code = (

0 commit comments

Comments
 (0)