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

Add MOSCED for infinite dilution activity coefficients #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
139 changes: 139 additions & 0 deletions tests/Data/MOSCED_DDB.csv

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions tests/Data/MOSCED_error.csv

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions tests/Data/MOSCED_local.csv

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions tests/Data/mosced_compounds.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
1,1,1-trichloroethane
1,1-dichloroethane
1,2-dichloroethane
1,5-dimethyl-2-pyrrolidinone
1-butanol
1-chlorobutane
1-ethylpyrrolidin-2-one
1-hexanol
1-hexene
1-nitropropane
1-octanol
1-octene
1-pentanol
1-pentene
1-phenyl-1-butanone
1-propanol
2,2,4-trimethylpentane
2,2-dimethylbutane
2,2-dimethylpentane
2,3,4-trimethylpentane
2,3-dimethylbutane
2,4-dimethylpentane
2,5-dimethylhexane
2,6-dimethylpyridine
2-butanol
2-butanone
2-ethoxyethanol
2-heptanone
2-methyl-1-propanol
2-methyl-2-propanol
2-methylpentane
2-nitropropane
2-pentanone
2-propanol
2-pyrrolidone
3-methylhexane
3-methylpentane
4-methyl-2-pentanone
[emin][(CF3SO2)2N]
[emmin][(CF3SO2)2N]
acetaldehyde
acetic acid
acetone
acetonitrile
acetophenone
alpha-pinene
aniline
anisole
argon
benzene
benzonitrile
benzyl acetate
benzyl alcohol
bromobenzene
bromoethane
butanal
butane
butanenitrile
butyl acetate
butylbenzene
carbon dioxide
carbon disulfide
carbon monoxide
carbon tetrachloride
chlorobenzene
chloroform
cycloheptane
cyclohexane
cyclohexanone
cyclooctane
cyclopentane
decane
dibutyl ether
dichloromethane
diethyl ether
diethyl phthalate
diiodomethane
diisopropyl ether
dimethyl carbonate
dioxane
dipropyl ether
DMF
DMSO
dodecane
epsilon-caprolactone
ethanol
ethyl acetate
ethyl benzoate
ethylbenzene
ethylcyclohexane
glutaronitrile
heptane
hexadecane
hexane
iodoethane
iodomethane
isopentane
isopropylbenzene
m-cresol
methanol
methyl acetate
methyl formate
methyl tert-butyl ether
methylcyclohexane
methylcyclopentane
N,N-dibutylformamide
N,N-diethylacetamide
N,N-dimethylacetamide
N-Ethylacetamide
N-formylmorpholine
N-methylacetamide
N-methylformamide
N-methylpyrrolidone
nitrobenzene
nitroethane
nitrogen
nitromethane
nonane
octane
oxygen
p-xylene
pentane
phenol
propane
propanenitrile
propyl acetate
pyridine
quinoline
squalane
sulfolane
tetradecane
tetraethylene glycol dimethyl ether
tetrahydrofuran
toluene
tributyl phosphate
trichloroethylene
triethylamine
water
103 changes: 103 additions & 0 deletions tests/test_mosced.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# -*- coding: utf-8 -*-
"""
test MOSCED
author: Edgar Sanchez
"""

from bs4 import BeautifulSoup
import requests
import pandas as pd
import numpy as np
from tqdm import tqdm
from thermo.mosced import MOSCED
from thermo.mosced import mosced_params_2005
import os


### --- Get MOSCED predictions from DDBST http://ddbonline.ddbst.com/MOSCEDCalculation/MOSCEDCGI.exe
# Inchikeys and names are both in the same order

def get_gamma_MOSCED_DDB(solvent, solute, T):
website_link = 'http://ddbonline.ddbst.com/MOSCEDCalculation/MOSCEDCGI.exe?component1=' \
+ solvent +'&component2='+ solute +'&temperatures=' + str(T)
webpage = requests.get(website_link)
soup = BeautifulSoup(webpage.content, 'html.parser')
table_info = soup.findAll(class_="tableformat_no_width")[1]
df = pd.read_html(str(table_info))[0]
gamma = df.iloc[0,2]

return gamma

if not os.path.isfile('Data/MOSCED_DDB.csv'):
with open('Data/mosced_compounds.txt', 'r') as f:
names = f.readlines()

gammas_DDB = np.zeros((len(names), len(names)))

for i, name in enumerate(names):
print('-'*60)
print('Solvent: ', i+1)
if i == len(names)-1:
solvent = name
else:
solvent = name[:-1]
for j, name in enumerate(tqdm(names)):
if j == len(names)-1:
solute = name
else:
solute = name[:-1]
if solvent == solute:
gamma = 1.
else:
gamma = get_gamma_MOSCED_DDB(solvent, solute, T=298.15)
gammas_DDB[i,j] = gamma
df = pd.DataFrame(gammas_DDB)
df.to_csv('Data/MOSCED_DDB.csv')
else:
gammas_DDB = pd.read_csv('Data/MOSCED_DDB.csv', index_col=0).values

### --- Get MOSCED predictions with local implementation

gammas_local = np.zeros(gammas_DDB.shape)

binary_sys = MOSCED()
for i, solvent in enumerate(mosced_params_2005):
solvent_params = binary_sys.get_mosced_params(solvent)
for j, solute in enumerate(mosced_params_2005):
solute_params = binary_sys.get_mosced_params(solute)
binary_sys.load_mosced_parameters(298.15, solvent_params, solute_params)
gammas_local[i,j] = binary_sys.gamma_infinite_dilution()

error = gammas_DDB[i,j] - np.round(gammas_local[i,j],2)
if error > 100:
with open('Data/mosced_compounds.txt', 'r') as f:
names = f.readlines()
print('-'*50)
print(i,j)
print(gammas_DDB[i,j])
print(np.round(gammas_local[i,j],2))
print(error)
print(solvent)
print(solute)
print(names[i])
print(names[j])


df = pd.DataFrame(gammas_local)
df.to_csv('Data/MOSCED_local.csv')

error = gammas_DDB - np.round(gammas_local,2)
df = pd.DataFrame(error)
df.to_csv('Data/MOSCED_error.csv')












Loading