In [ ]:
In [1]:
import numpy as np
import pandas as pd
import pyther as pt
In [ ]:
In [2]:
CONSTANTES_PARAMETROS_CRITICOS = pd.read_csv("tablas_gfs/constantes_ecuaciones_criticas.csv", sep=" ")
CONSTANTES_PARAMETROS_CRITICOS
Out[2]:
In [3]:
CONSTANTES_PARAMETROS_CRITICOS["Tc"]
Out[3]:
In [4]:
CONSTANTES_PARAMETROS_CRITICOS.iloc[0]
Out[4]:
In [ ]:
In [ ]:
In [ ]:
In [5]:
CONSTANTES_PARAMETROS_EBULLICION = pd.read_csv("tablas_gfs/constantes_ecuaciones_ebullicion.csv", sep=" ")
CONSTANTES_PARAMETROS_EBULLICION
Out[5]:
In [6]:
a, b, c = CONSTANTES_PARAMETROS_EBULLICION["Tb"]
print(a, b, c)
In [ ]:
In [7]:
GRUPOS_FUNCIONALES_EBULLICION = pd.read_csv("tablas_gfs/punto_ebullicion_gfs.csv", sep=" ", index_col="GroupNumber")
GRUPOS_FUNCIONALES_EBULLICION
Out[7]:
In [8]:
#.ix is deprecated. Please use
#.loc for label based indexing or
#.iloc for positional indexing
GRUPOS_FUNCIONALES_EBULLICION.loc[1]["GroupContribution(K)"]
Out[8]:
In [9]:
f1 = 6
f2 = 2
f3 = 2
gf1 = GRUPOS_FUNCIONALES_EBULLICION.loc[1]["GroupContribution(K)"] * f1
gf2 = GRUPOS_FUNCIONALES_EBULLICION.loc[4]["GroupContribution(K)"] * f2
gf3 = GRUPOS_FUNCIONALES_EBULLICION.loc[6]["GroupContribution(K)"] * f3
print(gf1, gf2, gf3)
In [10]:
id_grupos = np.array([1,4,6])
id_grupos
Out[10]:
In [11]:
frecuencia_grupos = np.array([6,2,2])
frecuencia_grupos
Out[11]:
In [12]:
numero_grupos = np.sum(frecuencia_grupos)
numero_grupos
Out[12]:
In [13]:
contribucion_grupal_primaria = np.array([GRUPOS_FUNCIONALES_EBULLICION.loc[x]["GroupContribution(K)"] * y for x,y in zip(id_grupos,frecuencia_grupos)])
contribucion_grupal_primaria
Out[13]:
In [14]:
GRUPOS_FUNCIONALES_EBULLICION_SECUNDARIOS = pd.read_csv("tablas_gfs/punto_ebullicion_segundo_gfs.csv", sep=" ", index_col="GroupNumber")
GRUPOS_FUNCIONALES_EBULLICION_SECUNDARIOS
Out[14]:
In [15]:
frecuencia_grupos_secundarios = np.array([1])
frecuencia_grupos_secundarios
Out[15]:
In [16]:
id_grupos_secundarios = np.array([133])
id_grupos_secundarios
Out[16]:
In [17]:
contribucion_grupal_secundaria = np.array([GRUPOS_FUNCIONALES_EBULLICION_SECUNDARIOS.loc[x]["GroupContribution(K)"] * y for x,y in zip(id_grupos_secundarios,frecuencia_grupos_secundarios)])
contribucion_grupal_secundaria
Out[17]:
In [18]:
#contribucion_grupal_secundaria = GRUPOS_FUNCIONALES_EBULLICION_SECUNDARIOS.loc[133]["GroupContribution(K)"] * 1
#contribucion_grupal_secundaria
In [19]:
contribucion_grupal_total = np.sum(contribucion_grupal_primaria) + np.sum(contribucion_grupal_secundaria)
contribucion_grupal_total
Out[19]:
In [20]:
print(a, b, c)
In [21]:
Tb = contribucion_grupal_total / (numero_grupos ** a + b) + c
Tb
Out[21]:
In [ ]:
donde $$C_{i-j} = C_{j-i} $$
In [ ]:
In [ ]:
In [22]:
GRUPOS_FUNCIONALES_EBULLICION_INTERACCIONES = pd.read_csv("tablas_gfs/punto_ebullicion_interacciones_gfs.csv", sep=" ", index_col="GroupNumber")
#GRUPOS_FUNCIONALES_EBULLICION_INTERACCIONES[["GroupContribution(K)", "MeanAbsoluteError(%)", "MeanAbsoluteError(K)", "StandardDeviation(K)", "NumberofComponents"]] = GRUPOS_FUNCIONALES_EBULLICION_INTERACCIONES[["GroupContribution(K)", "MeanAbsoluteError(%)", "MeanAbsoluteError(K)", "StandardDeviation(K)", "NumberofComponents"]].astype(float)
GRUPOS_FUNCIONALES_EBULLICION_INTERACCIONES
Out[22]:
In [23]:
def coerce_df_columns_to_numeric(df, column_list):
df[column_list] = df[column_list].apply(pd.to_numeric, errors='coerce')
lista_Columnas = ["GroupContribution(K)", "MeanAbsoluteError(%)", "MeanAbsoluteError(K)", "StandardDeviation(K)", "NumberofComponents"]
coerce_df_columns_to_numeric(GRUPOS_FUNCIONALES_EBULLICION_INTERACCIONES, lista_Columnas)
In [ ]:
In [ ]:
In [24]:
Ni = np.ones(3)
Ci = np.ones(3)
n = 2
M = 45
GI = 9
#def temperatura_Ebullicion_funcional(CONSTANTES_PARAMETROS_EBULLICION, Ni, Ci, n):
def temperatura_Ebullicion_funcional(CONSTANTES_PARAMETROS_EBULLICION, contribucion_grupal_total, numero_grupos):
a, b, c = CONSTANTES_PARAMETROS_EBULLICION["Tb"]
#Tb = np.sum(Ni * Ci) / (n ** a + b) + c
Tb = contribucion_grupal_total / (numero_grupos ** a + b) + c
return Tb
Tb = temperatura_Ebullicion_funcional(CONSTANTES_PARAMETROS_EBULLICION, contribucion_grupal_total, numero_grupos)
Tb
Out[24]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [25]:
291.799 * (1/9)
Out[25]:
In [26]:
286.970 * (2/9)
Out[26]:
In [27]:
numero_grupos2 = 9
numero_interacciones = np.array([1,2])
frecuencia_grupos_interaccion = numero_interacciones / numero_grupos2
#np.array([1/numero_atoms,2/numero_atoms])
frecuencia_grupos_interaccion
Out[27]:
In [28]:
id_grupos_interacciones = np.array([135,137])
id_grupos_interacciones
Out[28]:
In [29]:
contribucion_grupal_interaccion = np.array([GRUPOS_FUNCIONALES_EBULLICION_INTERACCIONES.loc[x]["GroupContribution(K)"] * y for x,y in zip(id_grupos_interacciones,frecuencia_grupos_interaccion)])
contribucion_grupal_interaccion
Out[29]:
In [ ]:
In [30]:
contribucion_grupal_interaccion * 2
Out[30]:
In [ ]:
In [ ]:
In [ ]:
In [31]:
#contribucion_grupal_total, numero_grupos, Tb = 0.2779983, 10, 245.9
def temperatura_critica_funcional(CONSTANTES_PARAMETROS_CRITICOS, contribucion_grupal_total, numero_grupos, Tb):
a1, b1, c1 = CONSTANTES_PARAMETROS_CRITICOS["Tc"]
# Temperatura crítica
#Tc = Tb * (b1 + 1 / (a1 + (np.sum(Ni * Ci) + GI) ** c1))
Tc = Tb * (b1 + 1 / (a1 + (contribucion_grupal_total) ** c1))
return Tc
Tc = temperatura_critica_funcional(CONSTANTES_PARAMETROS_CRITICOS, contribucion_grupal_total, numero_grupos, Tb)
print("Tc = {} K".format(Tc))
In [32]:
# perflouro-2-propanone, number of atoms: 10
id_grupos = np.array([7,21,51])
frecuencia_grupos = np.array([2,6,1])
numero_grupos = 10
contribucion_grupal_primaria = np.array([GRUPOS_FUNCIONALES_EBULLICION.loc[x]["GroupContribution(K)"] * y for x,y in zip(id_grupos,frecuencia_grupos)])
print("contribucion_grupal_primaria = ", contribucion_grupal_primaria)
id_grupos_secundarios = np.array([120,121,123])
frecuencia_grupos_secundarios = np.array([1,2,1])
contribucion_grupal_secundaria = np.array([GRUPOS_FUNCIONALES_EBULLICION_SECUNDARIOS.loc[x]["GroupContribution(K)"] * y for x,y in zip(id_grupos_secundarios,frecuencia_grupos_secundarios)])
print("contribucion_grupal_secundaria = ", contribucion_grupal_secundaria)
contribucion_grupal_total = np.sum(contribucion_grupal_primaria) + np.sum(contribucion_grupal_secundaria)
print("contribucion_grupal_total = ", contribucion_grupal_total)
Tb = temperatura_Ebullicion_funcional(CONSTANTES_PARAMETROS_EBULLICION, contribucion_grupal_total, numero_grupos)
print("Tb = {} K".format(Tb))
numero_interacciones = np.array([1,2])
id_grupos_interacciones = np.array([135,137])
frecuencia_grupos_interaccion = numero_interacciones / numero_grupos
#print(frecuencia_grupos_interaccion)
contribucion_grupal_interaccion = np.array([GRUPOS_FUNCIONALES_EBULLICION_INTERACCIONES.loc[x]["GroupContribution(K)"] * y for x,y in zip(id_grupos_interacciones,frecuencia_grupos_interaccion)])
contribucion_grupal_interaccion
#contribucion_grupal_total, numero_grupos, Tb = 0.2779983, 10, 245.9
contribucion_grupal_total = 0.2779983
Tc = temperatura_critica_funcional(CONSTANTES_PARAMETROS_CRITICOS, contribucion_grupal_total, numero_grupos, Tb)
print("Tc = {} K".format(Tc))
In [ ]:
In [33]:
from rdkit import Chem
from rdkit.Chem import Draw
from pubchempy import get_cids, get_compounds
import matplotlib.pyplot as plt
%matplotlib inline
from rdkit.Chem.Draw import IPythonConsole
In [ ]:
In [34]:
#datosAll.csv
datos = pd.read_csv("datosAll.csv", index_col="name")
datos
Out[34]:
In [35]:
properties_data = pt.Data_parse()
name = properties_data.read_dppr()
name
Out[35]:
In [36]:
name.loc["NITROGEN TRIFLUORIDE"]
Out[36]:
In [ ]:
In [37]:
parametrosCompletosPR = pd.read_excel("tabla_parametros_completa_PR.xlsx")
parametrosCompletosPR
Out[37]:
In [38]:
# No es necesaria porque ya se guardo la tabla: tabla_parametros_completa_PR.csv
# parametrosCompletosPR.to_csv("tabla_parametros_completa_PR.csv", encoding='utf-8', index=True)
In [39]:
parametrosCompletosPRcsv = pd.read_csv("tabla_parametros_completa_PR.csv", index_col="name")
parametrosCompletosPRcsv
Out[39]:
In [40]:
parametrosCompletosPRcsv.loc["NITROGEN TRIFLUORIDE"]
Out[40]:
In [41]:
parametrosCompletosPRcsv.loc["1,1,2,2-TETRAPHENYLETHANE"]
#parametrosCompletosPRcsv.loc["3,3,4,4-TETRAPHENYLETHANE"]
Out[41]:
In [42]:
name_componets = list(parametrosCompletosPRcsv.index)
name_componets
Out[42]:
In [43]:
#moleculaSmiles = np.chararray(10)
#moleculaSmiles = []
def names_to_smiles(name_componet):
##for i, name in enumerate(name_componets):
# query for cid first in order to avoid timeouterror
## moleculaSmiles[i] = get_compounds(name, 'name')[0].canonical_smiles
## print(moleculaSmiles)
#cid = get_cids(compound, 'name')[0]
#smiles = get_compounds(cid)[0].canonical_smiles
cid = get_cids(name_componet, 'name')[0]
moleculaSmiles = get_compounds(cid)[0].canonical_smiles
#moleculaSmiles = get_compounds(name, 'name')[0].canonical_smiles
return moleculaSmiles
In [44]:
lista_sustancias = name_componets[40:43] #ensayo 2
lista_sustancias = name_componets[140:143] #ensayo 3
lista_sustancias = name_componets[340:345] #ensayo 4
#lista_sustancias = name_componets[330:342] #ensayo 5
#'perflouro-2-propanone'
lista_sustancias.append("perfluoro-2-propanone")
lista_sustancias.append("methyl m-toluate")
lista_sustancias
Out[44]:
In [45]:
dppr_smiles = [names_to_smiles(name) for name in lista_sustancias]
In [46]:
dppr_smiles
Out[46]:
In [47]:
['1,1,2,2-TETRAPHENYLETHANE',
'd-LIMONENE',
'alpha-PHELLANDRENE',
'beta-PHELLANDRENE',
'alpha-TERPINENE',
'perfluoro-2-propanone',
'methyl m-toluate']
['C1=CC=C(C=C1)C(C2=CC=CC=C2)C(C3=CC=CC=C3)C4=CC=CC=C4',
'CC1=CCC(CC1)C(=C)C',
'CC1=CCC(C=C1)C(C)C',
'CC(C)C1CCC(=C)C=C1',
'CC1=CC=C(CC1)C(C)C',
'C(=O)(C(F)(F)F)C(F)(F)F',
'CC1=CC=CC(=C1)C(=O)OC']
Out[47]:
In [ ]:
In [48]:
def graficarMolecula(smiles):
molecula_D = Chem.MolFromSmiles(smiles)
Draw.MolToMPL(molecula_D, size=(100, 100))
return molecula_D
In [49]:
# ensayo 5
moleculasAgrupadas = [graficarMolecula(smiles) for smiles in dppr_smiles]
In [50]:
moleculasAgrupadas[-1]
Out[50]:
In [51]:
molecula_D = [Chem.MolFromSmiles(smiles) for smiles in dppr_smiles]
molecula_D
Out[51]:
In [52]:
#ms = [Chem.MolFromSmiles(x) for x in smis]
#Draw.MolsToGridImage(ms)
Draw.MolsToGridImage(molecula_D)
Out[52]:
In [53]:
#img=Draw.MolsToGridImage(molecula_D[:4],molsPerRow=4,subImgSize=(300,300), legends=["molecula_1", "molecula_2", "molecula_3"])
img=Draw.MolsToGridImage(molecula_D,molsPerRow=3,subImgSize=(100,100))
img
Out[53]:
In [54]:
print(dppr_smiles[0])
molecula_A = Chem.MolFromSmiles(dppr_smiles[0])
molecula_A
Out[54]:
In [55]:
molecula_A.GetAtomWithIdx(0).GetSymbol()
Out[55]:
In [56]:
molecula_A.GetAtomWithIdx(14).GetSymbol()
Out[56]:
In [57]:
# revisar el atributo _Name
#molecula_A.GetProp("_Name")
In [ ]:
In [ ]:
In [58]:
from rdkit import Chem
from rdkit import Chem
from rdkit.Chem import Draw
from IPython.display import SVG
from rdkit.Chem import PandasTools
from rdkit.Chem import AllChem
'CC1=CC=CC(=C1)C(=O)OC'
some_chemicals =[
'CC1=CC=CC(=C1)C(=O)OC',
'CCC(C)(C)C(C)(C)CC',
'CC(=O)Nc1ccc(O)cc1',
'CC(C)NCC(O)COc1ccccc1CC=C',
'CC(N)Cc1ccccc1',
'CC(CS)C(=O)N1CCCC1C(=O)O',
'CN(C)CCCN1c2ccccc2Sc3ccc(Cl)cc13',
'OC(=O)Cc1ccccc1Nc2c(Cl)cccc2Cl',
'NCC1(CC(=O)O)CCCCC1',
'COC(=O)c1ccccc1O',
'Nc1ccc(N=Nc2ccccc2)c(N)n1',
'IC(=O)c1ccccc1',
'CCOP(=S)(OCC)Oc1cc(Cl)cc(Cl)c1',
'c1c(C)c(O)c(N)cc1',
'Oc1c(C)cc(N)cc1',
'Oc1c(C)ccc(N)c1',
'c1c(C)c(N)c(O)cc1',]
some_chemicals_MOL =[
'CC(=O)Nc1ccc(O)cc1', 'molecula_1',
'CC(C)NCC(O)COc1ccccc1CC=C', 'molecula_1',
'CC(N)Cc1ccccc1', 'molecula_1',
]
some_chemicals = list(map(Chem.MolFromSmiles, some_chemicals))
SVG(Draw._MolsToGridSVG(some_chemicals))
#len(some_chemicals)
Out[58]:
In [59]:
mol = some_chemicals[0]
SVG(Draw._MolsToGridSVG([mol]))
Out[59]:
In [60]:
mal = Chem.MolFromSmiles('CC(C)CCO')
len(mal.GetSubstructMatches(Chem.MolFromSmarts('[CH3;X4]')))
#rta:2
Out[60]:
In [61]:
molecula_1 = some_chemicals[0]
len(molecula_1.GetSubstructMatches(Chem.MolFromSmarts('[CH3;X4]')))
molecula_1
Out[61]:
In [62]:
names_to_smiles(['perflouro-2-propanone'])
In [ ]:
'methyl m-toluate'
In [63]:
A = {'methyl m-toluate' : 'CC1=CC=CC(=C1)C(=O)OC'}
A
Out[63]:
In [ ]:
In [79]:
'CC(=O)Nc1ccc(O)cc1'
'perflouro-2-propanone'
#contadorGrupos = np.ones(10)
numSS = np.array([])
#numSS = np.zeros(2)
print(numSS)
def contarGrupos(molecula, grupo):
ERT = some_chemicals[molecula].GetSubstructMatches(Chem.MolFromSmarts(grupo))
print(ERT)
numS = len(some_chemicals[molecula].GetSubstructMatches(Chem.MolFromSmarts(grupo), uniquify=True))
#print(numS)
#some_chemicals[0]
return numS
#----------------
#grupo1 = 'C'
####grupo1 = '[CH3;X4]'
####grupo2 = 'C=O'
####grupo3 = 'N'
####grupo4 = 'c1ccccc1'
####grupo5 = '[OH]'
####grupo6 = '[CH2]'
#grupo7 = '[$([C][CH3;X4])]'
#grupo7 = '[$([CX2][CH3;X4])]'
#grupo7 = '[#6,C;$([CX2][CH3;X4])]'
#grupo7 = '[$([CX4]C[CH3;X4])]'
#grupo7 = '[CH2]'
# grupo7 = '[CH0][CH0]' # Este funciona para el ejemplo 1
####grupo7 = '[CH0CCC][CH0CCC]'
####grupo8 = '[CH0]'
#----------------
#grupo1 = 'C'
grupo1 = '[CH3;X4]'
grupo4 = '[CH2]'
grupo6 = '[CH0]'
grupo133 = '[CH0CCC][CH0CCC]'
grupos = [grupo1, grupo4, grupo6, grupo133]
#TotalGrupos = [contarGrupos(grupo) for grupo in grupos]
#np.insert(a, 1, 5)
molecula = 1 #3,3,4,4-tetramethylhexane
#molecula = 0 #methyl m-toluate
print("Grupo primarios")
ensayoGrupo1 = contarGrupos(molecula, grupo1)
print("ensayoGrupo1 = ", ensayoGrupo1)
ensayoGrupo4 = contarGrupos(molecula, grupo4)
print("ensayoGrupo4 = ", ensayoGrupo4)
ensayoGrupo6 = contarGrupos(molecula, grupo6)
print("ensayoGrupo6 = ", ensayoGrupo6)
print("Grupos terciarios")
ensayoGrupo133 = contarGrupos(molecula, grupo133)
print("ensayoGrupo133 = ", ensayoGrupo133)
TotalGrupos = np.append(numSS, [contarGrupos(molecula, grupo) for grupo in grupos])
#TotalGrupos = np.array([np.append(numSS, contarGrupos(grupo)) for grupo in grupos])
print(TotalGrupos)
some_chemicals[molecula]
Out[79]:
In [65]:
mol33 = Chem.MolFromSmiles('CCC(C)(C)C(C)(C)CC')
mol33
Out[65]:
In [66]:
bis3 = mol33.GetSubstructMatches(Chem.MolFromSmarts('[CH0][CH0]'))
print(bis3)
In [67]:
bs2 = [mol33.GetBondBetweenAtoms(x,y).GetIdx() for x,y in bis3]
bs2
Out[67]:
In [68]:
nm = Chem.FragmentOnBonds(mol33,bs2)
nm
Out[68]:
In [69]:
len(some_chemicals)
some_chemicals
Out[69]:
In [70]:
grupo1 = '[CH3;X4]'
grupo4 = '[CH2]'
grupo6 = '[CH0]'
grupo133 = '[CH0CCC][CH0CCC]'
grupo2 = '[CH3][O]'
grupo3 = '[CH3][c]'
grupo15 = '[ch]'
grupo16 = '[c;$([c](c)(c)[C])]'
grupo45 = '[c]C(=O)O[C]'
grupo128 = '[CH0]'
grupo118 = '[c;$([c](c)(c)[C])][C]=[O]' #'[c][C]=[O]'
grupos = [grupo2, grupo3, grupo15, grupo16, grupo45, grupo128, grupo118, grupo128]
molecula = 0 #methyl m-toluate
print("Grupo primarios")
ensayoGrupo3 = contarGrupos(molecula, grupo3)
print("ensayoGrupo3 = ", ensayoGrupo3)
ensayoGrupo15 = contarGrupos(molecula, grupo15)
print("ensayoGrupo15 = ", ensayoGrupo15)
print("Grupos terciarios")
ensayoGrupo128 = contarGrupos(molecula, grupo128)
print("ensayoGrupo128 = ", ensayoGrupo128)
ensayoGrupo2 = contarGrupos(molecula, grupo2)
print("ensayoGrupo2 = ", ensayoGrupo2)
TotalGrupos = np.append(numSS, [contarGrupos(molecula, grupo) for grupo in grupos])
print(TotalGrupos)
some_chemicals[molecula]
Out[70]:
In [80]:
counts = []
for m in some_chemicals[molecula]:
rc = m.GetRingInfo().NumRings()
nfrags = len(Chem.GetMolFrags(m))
ec = m.GetNumBonds()-m.GetNumAtoms()+nfrags
if ec!=rc:
print (Chem.MolToSmiles(m),ec,rc)
counts.append((ec,rc,m.GetProp('_Name')))
In [81]:
from rdkit.Chem import BRICS
m1 = some_chemicals[molecula]
#BRICS.BRICSDecompose(m1)
sorted(BRICS.BRICSDecompose(m1))
#['[14*]c1nc(N)nc2[nH]cnc12', '[3*]O[3*]', '[4*]CC(=O)C(C)C']
#m2 = cdk2mols[20]
Out[81]:
In [82]:
mol22 = Chem.MolFromSmiles('CC1CC(O)C1CCC1CC1')
bis = mol22.GetSubstructMatches(Chem.MolFromSmarts('[!R][R]'))
print(bis)
mol22
Out[82]:
In [83]:
bs = [mol22.GetBondBetweenAtoms(x,y).GetIdx() for x,y in bis]
bs
Out[83]:
In [84]:
bis = mol22.GetSubstructMatches(Chem.MolFromSmarts('[!R][R]'))
print(bis)
mol22
bs = [mol22.GetBondBetweenAtoms(x,y).GetIdx() for x,y in bis]
bs
nm = Chem.FragmentOnBonds(mol22,bs)
nm
Out[84]:
In [85]:
bis = mol22.GetSubstructMatches(Chem.MolFromSmarts('[!R][R]'))
print(bis)
mol22
bs = [mol22.GetBondBetweenAtoms(x,y).GetIdx() for x,y in bis]
bs
nm = Chem.FragmentOnBonds(mol22,bs)
nm
Out[85]:
In [ ]:
In [ ]:
In [ ]:
In [86]:
contribucion = [177.307, 239.453, 249.581, 111.837]
grupoContribucion = {grupos[i] : contribucion[i] for i, _ in enumerate(grupos)}
grupoContribucion
Out[86]:
In [87]:
grupoOrdenados = {grupos[i] : TotalGrupos[i] for i, _ in enumerate(grupos)}
grupoOrdenados
Out[87]:
In [88]:
some_chemicals_SMILES =[
'CC(=O)Nc1ccc(O)cc1',
'CCC(C)(C)C(C)(C)CC',
'CC(C)NCC(O)COc1ccccc1CC=C',
'CC(N)Cc1ccccc1',
'CC(CS)C(=O)N1CCCC1C(=O)O',
'CN(C)CCCN1c2ccccc2Sc3ccc(Cl)cc13',
'OC(=O)Cc1ccccc1Nc2c(Cl)cccc2Cl',
'NCC1(CC(=O)O)CCCCC1',
'COC(=O)c1ccccc1O',
'Nc1ccc(N=Nc2ccccc2)c(N)n1',
'IC(=O)c1ccccc1',
'CCOP(=S)(OCC)Oc1cc(Cl)cc(Cl)c1',
'c1c(C)c(O)c(N)cc1',
'Oc1c(C)cc(N)cc1',
'Oc1c(C)ccc(N)c1',
'c1c(C)c(N)c(O)cc1',
]
In [89]:
CONTRIBUCION_MOLECULA =pd.DataFrame(data=[grupoOrdenados, grupoContribucion], index=[some_chemicals_SMILES[0], "3,3,4,4-tetramethylhexane"])
CONTRIBUCION_MOLECULA
Out[89]:
In [90]:
d = {'col1': [1], 'col2': [3]}
d
Out[90]:
In [91]:
d = {'col1': [1], 'col2': [3]}
df = pd.DataFrame(data=d, index=['foo'])
df
# col1 col2
#0 1 3
#1 2 4
Out[91]:
In [92]:
some_chemicals[0]
Out[92]:
In [93]:
numSS = np.array([])
def contarGrupos(molecula, grupo):
numS = len(some_chemicals[molecula].GetSubstructMatches(Chem.MolFromSmarts(grupo), uniquify=True))
return numS
grupo1 = '[CH3;X4]'
grupo4 = '[CH2]'
grupo6 = '[CH0]'
grupo133 = '[CH0CCC][CH0CCC]'
grupos = [grupo1, grupo4, grupo6, grupo133]
molecula = 1
print("Grupo primarios")
ensayoGrupo1 = contarGrupos(molecula, grupo1)
print("ensayoGrupo1 = ", ensayoGrupo1)
ensayoGrupo4 = contarGrupos(molecula, grupo4)
print("ensayoGrupo4 = ", ensayoGrupo4)
ensayoGrupo6 = contarGrupos(molecula, grupo6)
print("ensayoGrupo6 = ", ensayoGrupo6)
print("Grupos terciarios")
ensayoGrupo133 = contarGrupos(molecula, grupo133)
print("ensayoGrupo133 = ", ensayoGrupo133)
TotalGrupos = np.append(numSS, [contarGrupos(molecula, grupo) for grupo in grupos])
print(TotalGrupos)
some_chemicals[molecula]
Out[93]:
In [94]:
NOMBRES_SUSTANCIA = "3,3,4,4-tetramethylhexane"
sustancia = pd.DataFrame(data=[grupoOrdenados, grupoContribucion], index=[some_chemicals_SMILES[1],NOMBRES_SUSTANCIA])
print(sustancia)
CTGF = np.sum(sustancia.iloc[0] * sustancia.iloc[1])
print("Contribución grupal total = ", CTGF)
Tb = temperatura_Ebullicion_funcional(CONSTANTES_PARAMETROS_EBULLICION, CTGF, numero_grupos)
print("MCG=Metodo de Contribución de Grupos")
print("Temperatura de ebullición MCG = {} K".format(Tb))
In [ ]:
In [95]:
Tb = temperatura_Ebullicion_funcional(CONSTANTES_PARAMETROS_EBULLICION, CTGF, numero_grupos)
Tb
Out[95]:
In [ ]:
In [ ]:
In [ ]:
In [96]:
numS = len(some_chemicals[0].GetSubstructMatches(Chem.MolFromSmarts(grupo1)))
print(numS)
molecula1 = some_chemicals[0]
molecula1
Out[96]:
In [97]:
some_chemicals[0]
pd.DataFrame(data={"uno" : some_chemicals[0]}, index=[some_chemicals_SMILES[0]])
Out[97]:
In [ ]:
In [98]:
w = Chem.SDWriter('bz.out.sdf')
for mol in some_chemicals:
# skip molecules the rdkit doesn't read:
if not mol: continue
# add coordinates so we get a correct mol block:
AllChem.Compute2DCoords(mol)
w.write(mol)
w.flush()
In [99]:
SDFFile = "bz.out.sdf"
BRDLigs = PandasTools.LoadSDF(SDFFile)
BRDLigs
Out[99]:
In [100]:
BRDLigs['Tc']= [100.23,200.34,3,4,5,6,7,8,3,5,4,76,7,5,4,5]
#BRDLigs['Pc']= [40.23,200.34,3,4,5,6,7,8,3,5,4,76,7,5,4]
#BRDLigs['ac']= [4.2673,200.34,3,4,5,6,7,8,3,5,4,76,7,5,4]
#BRDLigs['b']= [40.23,200.34,3,4,5,6,7,8,3,5,4,76,7,5,4]
In [101]:
BRDLigs
Out[101]:
In [ ]:
In [102]:
some_chemicals_MOL =[
'CC(C)(C)C(C)(C)C',
'CCC(C)(C)C(C)(C)CC',
'C(C)(C)C(C)(C)',
'CC(=O)Nc1ccc(O)cc1',
'CC(C)NCC(O)COc1ccccc1CC=C',
'CC(N)Cc1ccccc1',
]
some_chemicals = list(map(Chem.MolFromSmiles, some_chemicals_MOL))
SVG(Draw._MolsToGridSVG(some_chemicals))
Out[102]:
In [ ]:
In [ ]:
In [103]:
#import sdf
In [104]:
ns = 'CC(C)NCC(O)COc1ccccc1CC=C'
molecula_N = Chem.MolFromSmiles(ns)
molecula_N
Draw.MolsToGridImage(ns)
In [ ]:
In [ ]:
In [105]:
smis = ['CC(OC(=O)c1c[nH]c2ccccc12)C1CCCCN1C',
'CN1CCOc2c(C(=O)NC3CC4CCC(C3)N4C)cc(Cl)cc21',
'CN1CC2CCC1CC2n1nnc2ccc(Cl)cc2c1=O']
ms = [Chem.MolFromSmiles(x) for x in smis]
Draw.MolsToGridImage(ms)
Out[105]:
In [106]:
molecula_A.GetPropNames
#[x.GetProp("Name") for x in ms[:8]]
Out[106]:
In [107]:
img=Draw.MolsToGridImage(ms[:4],molsPerRow=4,subImgSize=(300,300), legends=["molecula_1", "molecula_2", "molecula_3"])
img
# img.save('images/cdk2_molgrid.o.png')
Out[107]:
In [108]:
molecula_A.GetAtoms()
Out[108]:
In [109]:
ind_map = {}
for atom in molecula_A.GetAtoms():
map_num = atom.GetAtomMapNum()
if map_num:
ind_map[map_num-1] = atom.GetIdx()
ind_map
Out[109]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [110]:
def propiedades_criticas_funcional(CONSTANTES_PARAMETROS_CRITICOS, Ni, Ci, n, M, GI, Tb):
a1, b1, c1 = CONSTANTES_PARAMETROS_CRITICOS["Tc"]
a2, b2, c2 = CONSTANTES_PARAMETROS_CRITICOS["Pc"]
a3, b3, c3 = CONSTANTES_PARAMETROS_CRITICOS["Vc"]
# Temperatura crítica
Tc = Tb * (b1 + 1 / (a1 + (np.sum(Ni * Ci) + GI) ** c1))
# Presión crítica
# (Pc/kPa) = M ** b / (a + np.sum(Ni * Ci + GI) ** 2)
Pc = M ** b2 / (a2 + np.sum(Ni * Ci) + GI) ** 2
# Volumen critico
# Vc / (1e-6 * m ** 3 * mol ** -1) = (np.sum(Ni * Ci) + GI) / n ** a + b
Vc = (np.sum(Ni * Ci) + GI) / n ** a3 + b3
return Tc, Pc, Vc
Tc, Pc, Vc = propiedades_criticas_funcional(CONSTANTES_PARAMETROS_CRITICOS, Ni, Ci, n, M, GI, Tb)
print("Tc = {} K, Pc = {} kPa, Vc = {} r'$ m ^3 mol^-1$' ".format(Tc, Pc, Vc))
In [ ]:
In [ ]:
In [111]:
SMILES_CHARS = [' ',
'#', '%', '(', ')', '+', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'=', '@',
'A', 'B', 'C', 'F', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P',
'R', 'S', 'T', 'V', 'X', 'Z',
'[', '\\', ']',
'a', 'b', 'c', 'e', 'g', 'i', 'l', 'n', 'o', 'p', 'r', 's',
't', 'u']
smi2index = dict( (c,i) for i,c in enumerate( SMILES_CHARS ) )
index2smi = dict( (i,c) for i,c in enumerate( SMILES_CHARS ) )
def smiles_encoder( smiles, maxlen=120 ):
smiles = Chem.MolToSmiles(Chem.MolFromSmiles( smiles ))
X = np.zeros( ( maxlen, len( SMILES_CHARS ) ) )
for i, c in enumerate( smiles ):
X[i, smi2index[c] ] = 1
return X
def smiles_decoder( X ):
smi = ''
X = X.argmax( axis=-1 )
for i in X:
smi += index2smi[ i ]
return smi
In [112]:
mat=smiles_encoder('CC1CCN(CC1N(C)C2=NC=NC3=C2C=CN3)C(=O)CC#N')
mat.shape
Out[112]:
In [113]:
print( mat )
In [114]:
dec=smiles_decoder(mat)
print(dec)
In [ ]:
In [115]:
moleculaConvertida1 = Chem.MolFromSmiles('CC1CCN(CC1N(C)C2=NC=NC3=C2C=CN3)C(=O)CC#N')
moleculaConvertida1
Out[115]:
In [116]:
moleculaConvertida2 = Chem.MolFromSmiles('CC1CCN(C(=O)CC#N)CC1N(C)c1ncnc2[nH]ccc12')
moleculaConvertida2
Out[116]:
In [117]:
mat2=smiles_encoder('CCC(C)(C)C(C)(C)CC')
mat2.shape
Out[117]:
In [118]:
print(mat2)
In [119]:
dec2=smiles_decoder(mat2)
print(dec2)
In [129]:
lista_NOMBRES = ['1,1,2,2-TETRAPHENYLETHANE',
'd-LIMONENE',
'alpha-PHELLANDRENE',
'beta-PHELLANDRENE',
'alpha-TERPINENE',
'perfluoro-2-propanone',
'methyl m-toluate']
lista_SMILES = ['C1=CC=C(C=C1)C(C2=CC=CC=C2)C(C3=CC=CC=C3)C4=CC=CC=C4',
'CC1=CCC(CC1)C(=C)C',
'CC1=CCC(C=C1)C(C)C',
'CC(C)C1CCC(=C)C=C1',
'CC1=CC=C(CC1)C(C)C',
'C(=O)(C(F)(F)F)C(F)(F)F',
'CC1=CC=CC(=C1)C(=O)OC']
lista_SMILES
NOMBRES_SMILES = {NOMBRES : SMILES for NOMBRES, SMILES in zip(lista_NOMBRES, lista_SMILES)}
NOMBRES_SMILES
Out[129]:
In [130]:
smiles22 = NOMBRES_SMILES[str(sustancia_1.value)[2:-3]]
print(smiles22)
In [131]:
#from IPython.html import widgets
from ipywidgets import widgets
#from IPython.html import widgets # Widget definitions
from IPython.display import display # Used to display widgets in the notebook
from ipywidgets import *
import matplotlib.pyplot as plt
import ipywidgets as wdg
from IPython.display import clear_output
In [132]:
sustancia_1 = widgets.SelectMultiple(
description="Sustancia",
options=list(lista_sustancias))
In [133]:
sustancia_1
In [134]:
button = widgets.Button(description="Molecula")
def cargarDatos(b):
clear_output()
print("NOMBRE: {}".format(str(sustancia_1.value)[2:-3]))
smiles = NOMBRES_SMILES[str(sustancia_1.value)[2:-3]]
print("SMILE: {}".format(smiles))
molecula_D = Chem.MolFromSmiles(smiles)
Draw.MolToMPL(molecula_D, size=(80, 80))
CONTRIBUCION_MOLECULA =pd.DataFrame(data=[grupoOrdenados, grupoContribucion], index=[smiles, str(sustancia_1.value)[2:-3]])
print(CONTRIBUCION_MOLECULA)
CTGF = np.sum(CONTRIBUCION_MOLECULA.iloc[0] * CONTRIBUCION_MOLECULA.iloc[1])
print("Contribución grupal total = ", CTGF)
Tb = temperatura_Ebullicion_funcional(CONSTANTES_PARAMETROS_EBULLICION, CTGF, numero_grupos)
print("MCG:Metodo de Contribución de Grupos")
print("Temperatura de ebullición MCG = {} K".format(Tb))
return molecula_D
#global Tcm, Pcm, wm
button.on_click(cargarDatos)
display(button)
In [135]:
tabs = widgets.Tab(children=[page1, page1, page1, page1, page1, page1])
#display(tabs)
tabs.set_title(0, 'Moleculas')
tabs.set_title(1, 'Modelos')
tabs.set_title(2, 'Parametros')
tabs.set_title(3, 'Resultados')
tabs.set_title(4, 'Experimentales')
tabs.set_title(5, 'Ajuste de Datos')
accord = widgets.Accordion(children=[tabs], width=400)
display(accord)
accord.set_title(0, 'Predicción de propiedades usando Grupos Funcionales')
In [136]:
page1 = widgets.VBox(children=[sustancia_1, button], padding=4)
page1
In [ ]:
In [ ]:
In [137]:
display(accord)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [144]:
mat=smiles_encoder('CC1CCN(CC1N(C)C2=NC=NC3=C2C=CN3)C(=O)CC#N')
mat.shape
print( mat )
In [145]:
dec=smiles_decoder(mat)
print(dec)
In [146]:
dec
Out[146]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
from ipywidgets import Button, HBox, VBox
form_item_layout = Layout(
display='flex',
flex_flow='row',
justify_content='center'
)
form = Box(form_items, layout=Layout(
display='flex',
flex_flow='column',
border='solid 1px',
align_items='stretch',
width='70%'
))
form
In [ ]:
from ipywidgets import Button, HBox, VBox
words = ['correct', 'horse', 'battery', 'staple']
items = [Button(description=w) for w in words]
#left_box = VBox([items[0], items[1]])
left_box = VBox([button,button])
left_box
#right_box = VBox([items[2], items[3]])
#HBox([left_box, right_box])
In [ ]:
HBox([button,button])
In [ ]:
from ipywidgets import Layout, Button, Box, FloatText, Textarea, Dropdown, Label, IntSlider
form_item_layout = Layout(
display='flex',
flex_flow='row',
justify_content='space-between'
)
form_items = [
Box([Label(value='Moleculas'),
#sustancia_1], layout=form_item_layout),
page1], layout=form_item_layout),
Box([Label(value='Ship size'),
FloatText()], layout=form_item_layout),
Box([Label(value='SMILES'),
Textarea()], layout=form_item_layout)
]
form = Box(form_items, layout=Layout(
display='flex',
flex_flow='column',
border='solid 2px',
align_items='stretch',
width='50%'
))
form
In [ ]:
In [ ]:
In [ ]:
In [ ]: