pyCRS : Basic usage for Database and CRSManager¶
Adding compound to a pyCRS database¶
First, we’ll add ethanol and water to the database and search for a list of compounds. When adding a compound, along with the COSKF file, it is necessary to provide a compound name and an unique chemical identifier. If only the COSKF file is provided, the method will attempt to utilize the IUPAC as the compound name and the CAS number as the chemical identifier, extracted from the Compound Data section within the COSKF file. In case such data is unavailable in the COSKF file, the user can specify the name parameter to define the compound name and either cas or identifier as the chemical identifier.
[show/hide code]
from pyCRS.Database import COSKFDatabase
from pyCRS.CRSManager import CRSSystem
import os
######## Note: Please ensure to install the ADFCRS-2018 database via amspackages (SCM->Packages) before running the below script ########
db = COSKFDatabase("my_coskf_db.db")
db.add_compound("1-Hexanol.coskf", cas="111-27-3")
db.add_compound("Water.coskf", identifier="InChI=1S/H2O/h1H2")
rows = db.get_compounds(["111-27-3", "Water"])
for r in rows:
print(r)
The output produced is the following
Successfully add new COMPOUND :compound_id=1 conformer_id=1 name=1-hexanol
Successfully add new COMPOUND :compound_id=2 conformer_id=2 name=water
CompoundRow(compound_id=1, conformer_id=1, name='1-hexanol', cas='111-27-3', identifier=None, smiles='CCCCCCO', resolved_smiles='CCCCCCO', coskf='1-Hexanol.coskf', Egas=-2562.015, Ecosmo=-2567.296, nring=0)
CompoundRow(compound_id=2, conformer_id=2, name='water', cas='7732-18-5', identifier='InChI=1S/H2O/h1H2', smiles='O', resolved_smiles='O', coskf='Water.coskf', Egas=-323.935, Ecosmo=-330.386, nring=0)
Activity coefficient calculation¶
[show/hide code]
from scm.plams import Settings, init, finish, CRSJob
from pyCRS.Database import COSKFDatabase
from pyCRS.CRSManager import CRSSystem
db = COSKFDatabase("my_coskf_db.db")
System = CRSSystem()
mixture = {}
mixture["7732-18-5"] = 0.3
mixture["111-27-3"] = 0.7
System.add_Mixture(mixture, database="my_coskf_db.db", temperature=298.15, problem_type="activitycoef")
init()
System.runCRSJob()
finish()
for out in System.outputs:
print(f"Property = {out.section}")
res = out.get_results()
for name, x, gamma in zip(res["name"], res["frac1"], res["gamma"]):
print(name, x, gamma)
The output produced is the following
Property = ACTIVITYCOEF
water [0.3] [3.71486029]
1-hexanol [0.7] [1.04484603]
Solid Solubility calculation¶
Next, we can add the melting point and heat of fusion if experimental data is available or estimate these values using PropPred and then perform the solid solubility calculation.
[show/hide code]
from scm.plams import Settings, init, finish, CRSJob
from pyCRS.Database import COSKFDatabase
from pyCRS.CRSManager import CRSSystem
import os
######## Note: Please ensure to install the ADFCRS-2018 database via amspackages (SCM->Packages) before running the below script ########
db = COSKFDatabase("my_coskf_db.db")
db.add_compound("Ibuprofen.coskf")
db.add_compound("Water.coskf")
db.add_physical_property("Ibuprofen", "hfusion", 27.94, unit="kJ/mol")
db.add_physical_property("Ibuprofen", "meltingpoint", 347.6)
db.estimate_physical_property("Ibuprofen")
EXP = db.get_physical_properties("Ibuprofen")[0]
QSPR = db.get_physical_properties("Ibuprofen", source="PropPred")[0]
print("experimental value = ", EXP.hfusion, " estimated value = ", QSPR.hfusion)
mixture = {}
mixture["Water"] = 1.0
mixture["Ibuprofen"] = 0
init()
System = CRSSystem()
System.add_Mixture(mixture, database="my_coskf_db.db", temperature=293.15, problem_type="solubility", solute="solid")
System.runCRSJob()
for out in System.outputs:
print(f"Property = {out.section}")
res = out.get_results()
print(f"{res['name'][1]} in {res['name'][0]} (g/L)= {res['solubility g_per_L_solvent'][1][0]}")
finish()
The output produced is the following
experimental value = 6.678 estimated value = 5.744
Property = SOLUBILITY
ibuprofen in water (g/L)= 0.022067656192544072
Establishment of a pyCRS database from the ADFCRS-2018 database¶
The script facilitates the automatic creation of a sql database utilizing the COSKF file from the ADFCRS-2018 database.
[show/hide code]
from pyCRS.Database import COSKFDatabase
from pathlib import Path
######## Note: Please ensure to install the ADFCRS-2018 database via amspackages (SCM->Packages) before running the below script ########
db = COSKFDatabase("ADFCRS-2018.db")
path = Path(db.ADFCRS2018_path)
for x in path.glob("*.coskf"):
if not x.name.startswith("IL_"):
db.add_compound(x)