Example #1
0
 def LoadGroups(self, FromDatabase=False, FromFile=None):
     if FromDatabase and self.db.DoesTableExist('groups'):
         self.groups_data = GroupsData.FromDatabase(
             self.db, transformed=self.transformed)
         self.group_decomposer = GroupDecomposer(self.groups_data)
     else:
         if FromFile is None:
             FromFile = open('../data/thermodynamics/groups_species.csv',
                             'r')
         self.groups_data = GroupsData.FromGroupsFile(
             FromFile, transformed=self.transformed)
         self.groups_data.ToDatabase(self.db)
         self.group_decomposer = GroupDecomposer(self.groups_data)
 def LoadGroups(self, FromDatabase=False):
     #if self.transformed:
     #    fname = "../data/thermodynamics/groups_species_transformed.csv"
     #else:
     if FromDatabase and self.db.DoesTableExist('groups'):
         self.groups_data = GroupsData.FromDatabase(
             self.db, transformed=self.transformed)
         self.group_decomposer = GroupDecomposer(self.groups_data)
     else:
         fp = open("../data/thermodynamics/groups_species.csv", 'r')
         self.groups_data = GroupsData.FromGroupsFile(
             fp, transformed=self.transformed)
         self.groups_data.ToDatabase(self.db)
         self.group_decomposer = GroupDecomposer(self.groups_data)
    def FromDatabase(self, db):
        self.groups_data = GroupsData.FromDatabase(
            db, transformed=self.transformed)
        self.group_decomposer = GroupDecomposer(self.groups_data)

        self.g_pgc = db.LoadNumpyMatrix('ugc_group_contributions').T
        self.P_L_pgc = db.LoadSparseNumpyMatrix('ugc_group_nullspace')
Example #4
0
def main():
    parser = MakeOpts()
    args = parser.parse_args()
    dissociation = DissociationConstants.FromPublicDB()
    groups_data = GroupsData.FromGroupsFile(args.groups_species,
                                            transformed=False)
    group_decomposer = GroupDecomposer(groups_data)

    while DecomposeInputString(group_decomposer, dissociation):
        pass
Example #5
0
 def FromDatabase(db, filename=None):
     """Factory that initializes a GroupDecomposer from the database.
     
     Args:
         db: a Database object.
         filename: an optional filename to load data from when
             it's not in the DB. Will write to DB if reading from file.
     
     Returns:
         An initialized GroupsData object.
     """
     assert db
     gd = GroupsData.FromDatabase(db, filename)
     return GroupDecomposer(gd)
Example #6
0
def dissociation_decomposition_test():
    """
        Verifies that the decomposition of the compounds in the dissociation table match the nH of each species.
    """
    db = SqliteDatabase('../res/gibbs.sqlite')
    dissociation = DissociationConstants.FromPublicDB()
    groups_data = GroupsData.FromDatabase(db)
    group_decomposer = GroupDecomposer(groups_data)
    kegg = Kegg.getInstance()

    for cid in dissociation.GetAllCids():
        id = "C%05d (%s)" % (cid, kegg.cid2name(cid))
        if kegg.cid2compound(cid).get_atom_bag() is None:
            logging.debug('%s: has no explicit formula' % id)
        else:
            diss = dissociation.GetDissociationTable(cid,
                                                     create_if_missing=False)
            test_dissociation_table(diss,
                                    group_decomposer,
                                    id,
                                    ignore_missing_smiles=True)
Example #7
0
def nist_dissociation_test():
    """
        Verifies that all the compounds in NIST are covered by the dissociation table, including SMILES strings.
    """
    db = SqliteDatabase('../res/gibbs.sqlite')
    nist_regression = NistRegression(db, html_writer=NullHtmlWriter())
    dissociation = nist_regression.dissociation
    groups_data = GroupsData.FromDatabase(db)
    group_decomposer = GroupDecomposer(groups_data)
    kegg = Kegg.getInstance()

    nist = nist_regression.nist
    for cid in nist.GetAllCids():
        id = "C%05d (%s)" % (cid, kegg.cid2name(cid))
        if kegg.cid2compound(cid).get_atom_bag() is None:
            logging.debug('%s: has no explicit formula' % id)
        else:
            diss = dissociation.GetDissociationTable(cid,
                                                     create_if_missing=False)
            test_dissociation_table(diss,
                                    group_decomposer,
                                    id,
                                    ignore_missing_smiles=False)
Example #8
0
 def FromGroupsFile(fp):
     """Factory that initializes a GroupDecomposer from a CSV file."""
     gd = GroupsData.FromGroupsFile(fp)
     return GroupDecomposer(gd)