def Initialize(self, db):
        from pygibbs.unified_group_contribution import UnifiedGroupContribution

        ugc = UnifiedGroupContribution(db)
        ugc.LoadGroups(FromDatabase=True)
        ugc.LoadObservations(FromDatabase=True)
        ugc.LoadGroupVectors(FromDatabase=True)
        ugc.LoadData(FromDatabase=True)
        ugc.init()
        
        self.groups_data = ugc.groups_data
        self.group_decomposer = ugc.group_decomposer

        result_dict = ugc._GetContributionData(ugc.S.copy(), ugc.cids,
                                               ugc.b.copy(), ugc.anchored)
        
        self.g_pgc = result_dict['group_contributions']
        self.P_L_pgc = result_dict['pgc_conservations']
    def Initialize(self, db):
        from pygibbs.unified_group_contribution import UnifiedGroupContribution

        ugc = UnifiedGroupContribution(db)
        ugc.LoadGroups(FromDatabase=True)
        ugc.LoadObservations(FromDatabase=True)
        ugc.LoadGroupVectors(FromDatabase=True)
        ugc.LoadData(FromDatabase=True)
        ugc.init()

        self.groups_data = ugc.groups_data
        self.group_decomposer = ugc.group_decomposer

        result_dict = ugc._GetContributionData(ugc.S.copy(), ugc.cids,
                                               ugc.b.copy(), ugc.anchored)

        self.g_pgc = result_dict['group_contributions']
        self.P_L_pgc = result_dict['pgc_conservations']
Ejemplo n.º 3
0
def CalculateThermo():
    options, _ = MakeOpts().parse_args(sys.argv)

    if options.csv_output_filename is not None:
        out_fp = open(options.csv_output_filename, 'w')
        print "writing results to %s ... " % options.csv_output_filename
    else:
        out_fp = sys.stdout
    csv_writer = csv.writer(out_fp)
    csv_writer.writerow(['ID', 'error', 'nH', 'nMg', 'charge', 'dG0', 'kernel']) 

    db = SqliteDatabase('../res/gibbs.sqlite', 'w')
    ugc = UnifiedGroupContribution(db)
    ugc.LoadGroups(True)
    ugc.LoadObservations(True)
    ugc.LoadGroupVectors(True)
    ugc.LoadData(True)
    
    result_dict = ugc._GetContributionData(ugc.S.copy(), ugc.cids,
                                           ugc.b.copy(), ugc.anchored)
    
    g_pgc = result_dict['group_contributions']
    P_L_pgc = result_dict['pgc_conservations']

    sdfile = pybel.readfile("sdf", options.sdf_input_filename)
    for m in sdfile:
        try:
            try:
                mol = Molecule.FromOBMol(m.OBMol)
            except OpenBabelError:
                raise UnknownReactionEnergyError("Cannot convert to OBMol object")
            
            mol.title = m.title
            mol.RemoveHydrogens()
            if mol.GetNumAtoms() > 200:
                raise UnknownReactionEnergyError("Compound contains more than 200 atoms (n = %d)" % mol.GetNumAtoms())
            
            try:
                decomposition = ugc.group_decomposer.Decompose(mol, 
                                        ignore_protonations=False, strict=True)
            except GroupDecompositionError:
                raise UnknownReactionEnergyError("cannot decompose")
            
            groupvec = decomposition.AsVector()
            gv = np.matrix(groupvec.Flatten())
            dG0 = float(g_pgc * gv.T)
            nH = decomposition.Hydrogens()
            nMg = decomposition.Magnesiums()
            ker = list((P_L_pgc * gv.T).round(10).flat)
            try:
                diss_table = mol.GetDissociationTable()
                diss_table.SetFormationEnergyByNumHydrogens(
                        dG0=dG0, nH=nH, nMg=nMg)
            except MissingDissociationConstantError:
                raise UnknownReactionEnergyError("missing pKa data")
            pmap = diss_table.GetPseudoisomerMap()
            for p_nH, p_z, p_nMg, p_dG0 in pmap.ToMatrix():
                csv_writer.writerow([m.title, None, p_nH, p_z, p_nMg, round(p_dG0, 1), str(ker)])

        except UnknownReactionEnergyError as e:
            csv_writer.writerow([m.title, str(e), None, None, None, None, None])
        
        out_fp.flush()
Ejemplo n.º 4
0
def CalculateThermo():
    options, _ = MakeOpts().parse_args(sys.argv)

    if options.csv_output_filename is not None:
        out_fp = open(options.csv_output_filename, 'w')
        print "writing results to %s ... " % options.csv_output_filename
    else:
        out_fp = sys.stdout
    csv_writer = csv.writer(out_fp)
    csv_writer.writerow(
        ['ID', 'error', 'nH', 'nMg', 'charge', 'dG0', 'kernel'])

    db = SqliteDatabase('../res/gibbs.sqlite', 'w')
    ugc = UnifiedGroupContribution(db)
    ugc.LoadGroups(True)
    ugc.LoadObservations(True)
    ugc.LoadGroupVectors(True)
    ugc.LoadData(True)

    result_dict = ugc._GetContributionData(ugc.S.copy(), ugc.cids,
                                           ugc.b.copy(), ugc.anchored)

    g_pgc = result_dict['group_contributions']
    P_L_pgc = result_dict['pgc_conservations']

    sdfile = pybel.readfile("sdf", options.sdf_input_filename)
    for m in sdfile:
        try:
            try:
                mol = Molecule.FromOBMol(m.OBMol)
            except OpenBabelError:
                raise UnknownReactionEnergyError(
                    "Cannot convert to OBMol object")

            mol.title = m.title
            mol.RemoveHydrogens()
            if mol.GetNumAtoms() > 200:
                raise UnknownReactionEnergyError(
                    "Compound contains more than 200 atoms (n = %d)" %
                    mol.GetNumAtoms())

            try:
                decomposition = ugc.group_decomposer.Decompose(
                    mol, ignore_protonations=False, strict=True)
            except GroupDecompositionError:
                raise UnknownReactionEnergyError("cannot decompose")

            groupvec = decomposition.AsVector()
            gv = np.matrix(groupvec.Flatten())
            dG0 = float(g_pgc * gv.T)
            nH = decomposition.Hydrogens()
            nMg = decomposition.Magnesiums()
            ker = list((P_L_pgc * gv.T).round(10).flat)
            try:
                diss_table = mol.GetDissociationTable()
                diss_table.SetFormationEnergyByNumHydrogens(dG0=dG0,
                                                            nH=nH,
                                                            nMg=nMg)
            except MissingDissociationConstantError:
                raise UnknownReactionEnergyError("missing pKa data")
            pmap = diss_table.GetPseudoisomerMap()
            for p_nH, p_z, p_nMg, p_dG0 in pmap.ToMatrix():
                csv_writer.writerow([
                    m.title, None, p_nH, p_z, p_nMg,
                    round(p_dG0, 1),
                    str(ker)
                ])

        except UnknownReactionEnergyError as e:
            csv_writer.writerow(
                [m.title, str(e), None, None, None, None, None])

        out_fp.flush()
Ejemplo n.º 5
0
import os, sys
orig_dir = os.getcwd()
pygibbs_path, _ = os.path.split(orig_dir)
src_path, _ = os.path.split(pygibbs_path)
os.chdir(src_path)
print src_path
sys.path.append(src_path)

import numpy as np
from pygibbs.unified_group_contribution import UnifiedGroupContribution
from toolbox.database import SqliteDatabase

db = SqliteDatabase('../res/gibbs.sqlite', 'r')
ugc = UnifiedGroupContribution(db)
ugc.LoadGroups(FromDatabase=True)
ugc.LoadObservations(FromDatabase=True)
ugc.LoadGroupVectors(FromDatabase=True)
ugc.LoadData(FromDatabase=True)
ugc.init()
result_dict = ugc._GetContributionData(ugc.S.copy(), ugc.cids,
                                       ugc.b.copy(), ugc.anchored)

g_pgc = result_dict['group_contributions']
P_L_pgc = result_dict['pgc_conservations']

os.chdir(orig_dir)
print os.getcwd()
np.save('g_pgc.gz', g_pgc)
np.save('P_L_g_pgc.gz', P_L_pgc)
Ejemplo n.º 6
0
import os, sys
orig_dir = os.getcwd()
pygibbs_path, _ = os.path.split(orig_dir)
src_path, _ = os.path.split(pygibbs_path)
os.chdir(src_path)
print src_path
sys.path.append(src_path)

import numpy as np
from pygibbs.unified_group_contribution import UnifiedGroupContribution
from toolbox.database import SqliteDatabase

db = SqliteDatabase('../res/gibbs.sqlite', 'r')
ugc = UnifiedGroupContribution(db)
ugc.LoadGroups(FromDatabase=True)
ugc.LoadObservations(FromDatabase=True)
ugc.LoadGroupVectors(FromDatabase=True)
ugc.LoadData(FromDatabase=True)
ugc.init()
result_dict = ugc._GetContributionData(ugc.S.copy(), ugc.cids, ugc.b.copy(),
                                       ugc.anchored)

g_pgc = result_dict['group_contributions']
P_L_pgc = result_dict['pgc_conservations']

os.chdir(orig_dir)
print os.getcwd()
np.save('g_pgc.gz', g_pgc)
np.save('P_L_g_pgc.gz', P_L_pgc)