Exemplo n.º 1
0
def GetMolInput(dissociation):
    mols = [
    ]  # a list of pairs of Molecule objects and stoichiometric coefficients
    while mols == []:
        print 'KEGG ID or SMILES (or Enter to quit):',
        s_input = raw_input()
        if not s_input:
            return []
        elif re.findall('C\d\d\d\d\d', s_input) != []:
            try:
                cid = int(s_input[1:])
                mols = [(GetMostAbundantMol(cid, dissociation), 1)]
                print "Compound:", mols[0][0].ToInChI()
            except ValueError:
                print 'syntax error: KEGG compound ID is bad (%s), please try again' % s_input
        elif re.findall('R\d\d\d\d\d', s_input) != []:
            try:
                rid = int(s_input[1:])
                reaction = Kegg.getInstance().rid2reaction(rid)
                print "Reaction:", str(reaction)
                for cid, coeff in reaction.iteritems():
                    mols += [(GetMostAbundantMol(cid, dissociation), coeff)]
            except ValueError:
                print 'syntax error: KEGG reaction ID is bad (%s), please try again' % s_input
        else:
            try:
                mols = [(Molecule.FromSmiles(s_input), 1)]
                print "Compound:", mols[0][0].ToInChI()
            except Exception:
                print 'unable to parse SMILES string, please try again'

    return mols
Exemplo n.º 2
0
 def CreateEmptyGroupDecomposition(self):
     emptymol = Molecule.FromSmiles("")
     decomposition = self.Decompose(emptymol,
                                    ignore_protonations=True,
                                    strict=False)
     for i, (group, _node_sets) in enumerate(decomposition.groups):
         decomposition.groups[i] = (group, [])
     return decomposition
Exemplo n.º 3
0
    def GetMol(self, nH=None, nMg=0):
        from toolbox.molecule import Molecule

        if nH is None:
            nH = self.min_nH
        if (nH, nMg) not in self.mol_dict:
            return None
        s, mol = self.mol_dict[nH, nMg]
        if mol is None:
            mol = Molecule.FromSmiles(s)
        self.mol_dict[nH, nMg] = (s, mol)
        return mol
Exemplo n.º 4
0
def test_dissociation_table(diss,
                            group_decomposer,
                            id,
                            ignore_missing_smiles=False):
    if diss is None:
        logging.warning('%s: does not appear in the dissociation table' % id)
        return

    nH, nMg = diss.GetMostAbundantPseudoisomer(pH=default_pH,
                                               I=default_I,
                                               pMg=14,
                                               T=default_T)
    if nMg != 0:
        logging.warning('%s: default species has nMg = %d' % (id, nMg))
        return
    smiles = diss.GetSmiles(nH=nH, nMg=0)
    if not smiles:
        if not ignore_missing_smiles:
            logging.warning(
                '%s: no SMILES in the dissociation table for nH = %d' %
                (id, nH))
        return

    logging.debug('%s: nH = %d, smiles = %s' % (id, nH, smiles))
    mol = Molecule.FromSmiles(smiles)

    try:
        decomposition = group_decomposer.Decompose(mol,
                                                   ignore_protonations=False,
                                                   strict=True)
    except GroupDecompositionError:
        return

    groupvec = decomposition.AsVector()
    logging.debug("%s: decomposition = %s" % (id, groupvec))
    gc_nH = decomposition.Hydrogens()
    if nH != gc_nH:
        logging.warning(
            '%s: nH doesn\'t match: explicit = %d, decomposition = %d' %
            (id, nH, gc_nH))
Exemplo n.º 5
0
import unittest
from pygibbs.groups_data import GroupsData
from pygibbs import group_decomposition
from toolbox.molecule import Molecule
import logging

PHOSPHATE = Molecule.FromSmiles('[O-]P([O-])(=O)O')
ATP = Molecule.FromSmiles(
    'C1=NC2=C(C(=N1)N)N=CN2C3C(C(C(O3)COP(=O)([O-])OP(=O)([O-])OP(=O)([O-])O)O)O'
)
A4P = Molecule.FromSmiles(
    'C1=NC2=C(C(=N1)N)N=CN2C3C(C(C(O3)COP(=O)([O-])OP(=O)([O-])OP(=O)([O-])OP(=O)([O-])O)O)O'
)


class GroupsDecompositionTest(unittest.TestCase):
    """Tests for GroupsDecomposition"""
    def setUp(self):
        self.groups_decomposer = group_decomposition.GroupDecomposer.FromGroupsFile(
            open('../data/thermodynamics/groups_species.csv', 'r'))

    def testFindPhosphateChains(self):
        ps = group_decomposition.GroupDecomposer.FindPhosphateChains(
            PHOSPHATE, ignore_protonations=False)

        for unused_grp, l in ps:
            self.assertTrue(not l)

        mk_ps_dict = lambda ps: dict((key, l) for key, l in ps)
        mk_ps_string = lambda ps: ', '.join(
            ["%s x %d" % (str(key), len(l)) for key, l in ps if l != []])
Exemplo n.º 6
0
        sum_conc = 0
        for Ka_subset in itertools.combinations(Ka_list, i+1): # all choices of i values from the Ka list
            sum_conc += np.prod(Ka_subset)
        relative_conc.append(sum_conc)
        Ka_i = relative_conc[i+1] / relative_conc[i]
        transformed_pKas.append(-np.log10(Ka_i))
    
    return transformed_pKas

if __name__ == "__main__":
    
    diss_table_example = [4.0, 4.0, 4.0]
    new_diss_table = _TransformMultiples(diss_table_example)
    
    print diss_table_example
    print new_diss_table
    
    from toolbox.molecule import Molecule
    compound_list = [('glycine', 'C(=O)(O)CN'),
                     ('CO2', 'O=C=O'),
                     ('ATP', 'Nc1ncnc2n(cnc12)C1OC(COP([O-])(=O)OP([O-])(=O)OP(O)([O-])=O)C(O)C1O'),
                     ('3-Ketoarabinitol', 'OCC(O)C(C(O)CO)=O')]
    
    for name, smiles in compound_list:
        diss_table1, major_ms = GetDissociationConstants(smiles, transform_multiples=False)
        diss_table2, major_ms = GetDissociationConstants(smiles, transform_multiples=True)
        m = Molecule.FromSmiles(major_ms)
        print name, m.ToInChI()
        for i in xrange(len(diss_table1)):
            print "%.2f %.2f" % (diss_table1[i][0], diss_table2[i][0])
Exemplo n.º 7
0
                logging.error(e)
                continue

        return

    atp = 'C1=NC2=C(C(=N1)N)N=CN2C3C(C(C(O3)COP(=O)(O)OP(=O)(O)OP(=O)(O)O)O)O'
    coa = 'C1C=CN(C=C1C(=O)N)C2C(C(C(O2)COP(=O)(O)OP(=O)(O)OCC3C(C(C(O3)N4C=NC5=C4N=CN=C5N)O)O)O)O'
    glucose = 'C(C1C(C(C(C(O1)O)O)O)O)O'
    mgatp = 'C([C@@H]1[C@H]([C@H]([C@H](n2cnc3c(N)[nH+]cnc23)O1)O)O)OP(=O)([O-])OP(=O)([O-])OP(=O)([O-])[O-].[Mg+2].[Mg+2]'

    #smiless = [
    #           ('ATP', atp),
    #           ('CoA', coa), ('Glucose', glucose), ('MgAtp', mgatp),
    #           ]
    smiless = [('ATP', atp)]
    mols = [(name, Molecule.FromSmiles(s)) for name, s in smiless]

    for name, mol in mols:
        print name
        decomposition = decomposer.Decompose(mol)
        print decomposition.ToTableString()
        print 'Group count', decomposition.group_count
        print 'Net charge', decomposition.net_charge
        print 'Hydrogens', decomposition.hydrogens
        print 'Magnesiums', decomposition.magnesiums

        print 'Group Vector:'
        print decomposition.AsVector()

        print 'Pseudoisomer Vectors:'
        for v in decomposition.PseudoisomerVectors():
Exemplo n.º 8
0
def main():
    mol = Molecule.FromSmiles('C(O)(=O)C(=O)O')
    emp = EnzymeMarketplace()
    print emp.React(mol)