Ejemplo n.º 1
0
    def testDeltaG(self):
        # Create a test compound.
        species = [models.Specie(number_of_hydrogens=12, net_charge=0,
                                 formation_energy=-10.5),
                   models.Specie(number_of_hydrogens=11, net_charge=-1,
                                 formation_energy=-12.1),
                   models.Specie(number_of_hydrogens=10, net_charge=-2,
                                 formation_energy=-13.4)]
        species_group = models.SpeciesGroup()
        species_group._all_species = species

        compound = models.Compound(kegg_id='fake compound')
        compound._species_group_to_use = species_group
        
        # Format: ph, ionic strength, dG.
        test_data = ((6.5, 0.1, 361.094),
                     (7.0, 0.1, 389.619),
                     (7.5, 0.1, 418.143),
                     (7.0, 0.0001, 386.118),
                     (7.0, 0.001, 386.473),
                     (7.0, 0.2, 390.505))

        for ph, i_s, expected_dg in test_data:
            actual_dg = compound.DeltaG(pH=ph, ionic_strength=i_s)
            self.assertAlmostEqual(expected_dg, actual_dg, 3,
                                   'ph: %f, i_s: %f, expected dG: %f, actual dG: %f' %
                                   (ph, i_s, expected_dg, actual_dg))
Ejemplo n.º 2
0
    def testTransform(self):
        specie = models.Specie(number_of_hydrogens=2, number_of_mgs=0,
                               net_charge=-1, formation_energy=-10.0)
        
        # Test some hand-calculated numbers: (ph, ionic strength, result)
        test_data = (
             # Move pH, keep ionic strength constant.
             (6.0, 0.1, 59.071),
             (6.5, 0.1, 64.776),
             (7.0, 0.1, 70.481),
             (7.5, 0.1, 76.186),
             (8.0, 0.1, 81.891),
             # Move ionic strength, keep pH constant.
             (7.0, 0.0001, 69.898),
             (7.0, 0.001, 69.957),
             (7.0, 0.01, 70.121),
             (7.0, 0.05, 70.349),
             (7.0, 0.11, 70.501),
             (7.0, 0.15, 70.566),
             (7.0, 0.2, 70.629),
             # Move both.
             (6.0, 0.0001, 58.488),
             (6.5, 0.001, 64.252),
             (8.0, 0.0001, 81.308),
             (7.5, 0.15, 76.271),
             )

        for ph, ionic_strength, expected_transform in test_data:
            actual_transform = specie.Transform(pH=ph, ionic_strength=ionic_strength)
            self.assertAlmostEqual(expected_transform, actual_transform, 3)
Ejemplo n.º 3
0
def MakeSpeciesGroup(pmap, source, compound):
    logging.debug('Writing data from source %s', source.name)
    
    if 'priority' not in pmap or 'species' not in pmap:
        logging.error('Malformed pmap field for %s', compound.kegg_id)
        return None
        
    sg = models.SpeciesGroup(kegg_id=compound.kegg_id,
                             priority=pmap['priority'],
                             formation_energy_source=source)
    sg.save()
    
    for sdict in pmap['species']:
        specie = models.Specie(kegg_id=compound.kegg_id,
                               number_of_hydrogens=sdict['nH'],
                               number_of_mgs=sdict['nMg'],
                               net_charge=sdict['z'],
                               formation_energy=sdict['dG0_f'])
        specie.save()
        sg.species.add(specie)
    
    sg.save()
    return sg