Exemplo n.º 1
0
    def test_load(self):
        myparam = parameters.Parameters()  #default
        self.assertEqual(myparam.parameters["a_eff"], 6.22, 9)

        myparam = parameters.Parameters(parameters=data.Mullins_2006)
        self.assertEqual(myparam.parameters["a_eff"], 7.5, 9)

        myparam = parameters.Parameters(parameters=here + "/Hsieh_2010.json")
        self.assertEqual(myparam.parameters["a_eff"], 7.25, 9)
Exemplo n.º 2
0
    def test_dump(self):
        myparam = parameters.Parameters()
        s = myparam.dump_to_string()
        param = json.loads(s)
        self.assertEqual(param["a_eff"], 6.22, 9)

        myparam.dump_to_json("/tmp/tmp.json")
        with open("/tmp/tmp.json", 'r') as f:
            param = json.load(f)
            self.assertEqual(param["a_eff"], 6.22, 9)
Exemplo n.º 3
0
    def test_infinity_dilution(self):
        myparam = parameters.Parameters()
        sigma1 = sigma.Sigma(mol1, myparam)
        sigma1.write_sigma_file = False
        sigma1.kernel()
        sigma2 = sigma.Sigma(mol2, myparam)
        sigma2.write_sigma_file = False
        sigma2.kernel()

        myac = ac.AC([mol1, mol2], x, T, [sigma1, sigma2], myparam)
        myac.solve_gamma_thresh = 1e-6
        myac.solve_gamma_maxiter = 500
        self.assertTrue(
            np.allclose(myac.kernel(), np.asarray([10.05122252, 0.0])))
Exemplo n.º 4
0
 def test_infinity_dilution3(self):
     myparam = parameters.Parameters(data.Hsieh_2010)
     sigma1 = sigma.Sigma(mol1, myparam)
     sigma1.write_sigma_file = False
     sigma1.split_sigma = True
     sigma1.kernel()
     sigma2 = sigma.Sigma(mol2, myparam)
     sigma2.write_sigma_file = False
     sigma2.split_sigma = True
     sigma2.kernel()
     myac = ac.AC([mol1, mol2], x, T, [sigma1, sigma2], myparam)
     myac.solve_gamma_thresh = 1e-6
     myac.solve_gamma_maxiter = 500
     self.assertTrue(
         np.allclose(myac.kernel(), np.asarray([8.81631154, 0.0])))
Exemplo n.º 5
0
 def test_dispersion(self):
     myparam = parameters.Parameters(data.Hsieh_2010)
     sigma1 = sigma.Sigma(mol1, myparam)
     sigma1.write_sigma_file = False
     sigma1.split_sigma = True
     sigma1.kernel()
     sigma2 = sigma.Sigma(mol2, myparam)
     sigma2.write_sigma_file = False
     sigma2.split_sigma = True
     sigma2.kernel()
     myac = ac.AC([mol1, mol2], x, T, [sigma1, sigma2], myparam)
     myac.solve_gamma_thresh = 1e-6
     myac.solve_gamma_maxiter = 500
     myac.dispersion = True
     self.assertTrue(
         np.allclose(myac.kernel(), np.asarray([9.55918891, 0.])))
Exemplo n.º 6
0
import os
import numpy as np
from pycosmosac.param import data, parameters
from pycosmosac.cosmo import cosmo
from pycosmosac.sigma import sigma
from pycosmosac.ac import ac
from pycosmosac.utils import thermo
'''
An example to compute hydration free energy of carbofuran
'''

path = os.path.abspath(os.path.dirname(__file__)) + "/"

#load parameters
myparam = parameters.Parameters(parameters=data.BIOSAC_SVP_GEPOL)

#compute sigma profile for solute
solute = "carbofuran"
mol1 = cosmo.Cosmo().load(path + solute + ".cosmo")
sigma1 = sigma.Sigma(mol1, myparam)
#whether or not to write the sigma file
sigma1.write_sigma_file = False
sigma1.sigma_filename = solute + ".sigma"
#default bounds for the grid; if "bounds too narrow" error occures, increase the numbers
sigma1.bounds = [-0.025, 0.025]
sigma1.kernel()

#compute sigma profile for solvent
solvent = "h2o"
mol2 = cosmo.Cosmo().load(path + solvent + ".cosmo")
sigma2 = sigma.Sigma(mol2, myparam)
Exemplo n.º 7
0
import os
import unittest
import numpy as np
from pycosmosac.param import parameters, data
from pycosmosac.cosmo import cosmo
from pycosmosac.sigma import sigma
from pycosmosac.utils import misc

here = os.path.abspath(os.path.dirname(__file__))

mycosmo = cosmo.Cosmo()
mol = mycosmo.load(here+"/h2o.cosmo")

param1 = parameters.Parameters()
sigma1 = sigma.Sigma(mol, param1)
sigma1.write_sigma_file = False
sigma1.kernel()

param3 = parameters.Parameters(data.Hsieh_2010)
sigma3 = sigma.Sigma(mol, param3)
sigma3.split_sigma = True
sigma3.write_sigma_file = False
sigma3.kernel()

class KnownValues(unittest.TestCase):
    def test_sigma(self):
        self.assertAlmostEqual(misc.fp(sigma1.pA), -1.917622937152116, 8)

    def test_sigma3(self):
        self.assertTrue(np.allclose(sigma3.pA, sigma3.pA_nhb + sigma3.pA_oh + sigma3.pA_ot))
        self.assertAlmostEqual(misc.fp(sigma3.pA_nhb), 0.049856600131970685, 8)
Exemplo n.º 8
0
        lngamma = lngamma_c(self.mols, self.x, self.parameters.parameters)
        if not self.split_sigma:
            lngamma += lngamma_r(self.mols, self.sigmas, self.x, self.T, self.parameters.parameters, self.solve_gamma_thresh, self.solve_gamma_maxiter)
        else:
            lngamma += lngamma_r3(self.mols, self.sigmas, self.x, self.T, self.parameters.parameters, self.solve_gamma_thresh, self.solve_gamma_maxiter)
        if self.dispersion:
            lngamma += lngamma_dsp(self.mols, self.sigmas, self.x, self.parameters.parameters)
        return lngamma


if __name__ == "__main__":
    from pycosmosac.param import parameters, data
    from pycosmosac.cosmo import cosmo
    from pycosmosac.sigma import sigma

    myparam = parameters.Parameters()

    mol1 = cosmo.Cosmo().load("./test/butane.cosmo")
    sigma1 = sigma.Sigma(mol1, myparam)
    sigma1.write_sigma_file = False
    sigma1.kernel()

    mol2 = cosmo.Cosmo().load("./test/h2o.cosmo")
    sigma2 = sigma.Sigma(mol2, myparam)
    sigma2.write_sigma_file = False
    sigma2.kernel()

    x = [0., 1.]
    T = 298.15
    myac = AC([mol1,mol2], x, T, [sigma1,sigma2], myparam)
    print(myac.kernel() - np.asarray([10.05271196, 0.0]))
Exemplo n.º 9
0
        ac.AC.__init__(self, mols, x, T, sigmas, parameters)
        self.comb = True

    def kernel(self):
        mu = mu_s(self.mols, self.sigmas, self.x, self.T, self.parameters.parameters)
        if self.comb:
            mu += mu_c(self.mols, self.x, self.T, self.parameters.parameters)
        return mu


if __name__ == "__main__":
    from pycosmosac.param import parameters, data
    from pycosmosac.cosmo import cosmo
    from pycosmosac.sigma import sigma

    myparam = parameters.Parameters(data.COSMORS)

    mol1 = cosmo.Cosmo().load("./test/butane.cosmo")
    sigma1 = sigma.Sigma(mol1, myparam)
    sigma1.write_sigma_file = False
    sigma1.kernel()

    mol2 = cosmo.Cosmo().load("./test/h2o.cosmo")
    sigma2 = sigma.Sigma(mol2, myparam)
    sigma2.write_sigma_file = False
    sigma2.kernel()

    x = [0., 1.]
    T = 298.15
    myrs = RS([mol1,mol2], x, T, [sigma1,sigma2], myparam)
    print(myrs.kernel())