Skip to content

Commit

Permalink
updating for wc_lang.ChemicalStructure
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Apr 2, 2019
1 parent 7632198 commit 571b700
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 76 deletions.
1 change: 1 addition & 0 deletions .circleci/requirements.txt
Expand Up @@ -2,6 +2,7 @@
git+https://github.com/KarrLab/log.git#egg=log

# Karr Lab
git+https://github.com/KarrLab/bpforms.git#egg=bpforms
git+https://github.com/KarrLab/wc_onto.git#egg=wc_onto
git+https://github.com/KarrLab/wc_utils.git#egg=wc_utils
git+https://github.com/KarrLab/obj_model.git#egg=obj_model
Expand Down
37 changes: 15 additions & 22 deletions tests/eukaryote/test_initialize_model.py
Expand Up @@ -232,7 +232,7 @@ def test_gen_dna(self):

dna = self.kb.cell.species_types.get_one(id='chrX')
L = dna.get_len()
self.assertEqual(chrX_model.empirical_formula, chem.EmpiricalFormula('C10H12N5O6P') * 2
self.assertEqual(chrX_model.structure.empirical_formula, chem.EmpiricalFormula('C10H12N5O6P') * 2
+ chem.EmpiricalFormula('C9H12N3O7P') * 2
+ chem.EmpiricalFormula('C10H12N5O7P') * 2
+ chem.EmpiricalFormula('C10H13N2O8P') * 2
Expand All @@ -244,8 +244,8 @@ def test_gen_dna(self):
circular=dna.circular,
double_stranded=dna.double_stranded) \
- 9 * mendeleev.element('H').atomic_weight
self.assertAlmostEqual(chrX_model.molecular_weight, exp_mol_wt, places=0)
self.assertEqual(chrX_model.charge, -L - 1)
self.assertAlmostEqual(chrX_model.structure.molecular_weight, exp_mol_wt, places=0)
self.assertEqual(chrX_model.structure.charge, -L - 1)
self.assertEqual(chrX_model.comments, '')

def test_gen_transcripts(self):
Expand All @@ -266,7 +266,7 @@ def test_gen_transcripts(self):

transcript = self.kb.cell.species_types.get_one(id='trans2')
L = transcript.get_len()
self.assertEqual(transcript2_model.empirical_formula, chem.EmpiricalFormula('C10H12N5O7P') * 1
self.assertEqual(transcript2_model.structure.empirical_formula, chem.EmpiricalFormula('C10H12N5O7P') * 1
+ chem.EmpiricalFormula('C9H12N3O8P') * 1
+ chem.EmpiricalFormula('C10H12N5O8P') * 1
+ chem.EmpiricalFormula('C9H11N2O9P') * 1
Expand All @@ -275,8 +275,8 @@ def test_gen_transcripts(self):
exp_mol_wt = \
+ Bio.SeqUtils.molecular_weight(transcript.get_seq()) \
- (L + 1) * mendeleev.element('H').atomic_weight
self.assertAlmostEqual(transcript2_model.molecular_weight, exp_mol_wt, places=0)
self.assertEqual(transcript2_model.charge, -L - 1)
self.assertAlmostEqual(transcript2_model.structure.molecular_weight, exp_mol_wt, places=0)
self.assertEqual(transcript2_model.structure.charge, -L - 1)
self.assertEqual(transcript2_model.comments, '')

def test_gen_protein(self):
Expand All @@ -294,9 +294,9 @@ def test_gen_protein(self):
self.assertEqual(prot3_model.type, onto['WC:protein'])
self.assertEqual(all(i.compartment.id=='n' for i in model.species.get(species_type=prot1_model)), True)
self.assertEqual(all(i.compartment.id=='m' for i in model.species.get(species_type=prot3_model)), True)
self.assertEqual(prot1_model.empirical_formula, chem.EmpiricalFormula('C53H96N14O15S1'))
self.assertAlmostEqual(prot1_model.molecular_weight, 1201.49, delta=0.3)
self.assertEqual(prot1_model.charge, 1)
self.assertEqual(prot1_model.structure.empirical_formula, chem.EmpiricalFormula('C53H96N14O15S1'))
self.assertAlmostEqual(prot1_model.structure.molecular_weight, 1201.49, delta=0.3)
self.assertEqual(prot1_model.structure.charge, 1)
self.assertEqual(prot1_model.comments, '')
self.assertEqual(prot3_model.comments, 'Testing')

Expand All @@ -310,17 +310,10 @@ def test_gen_metabolites(self):

self.assertEqual(met1_model.name, 'metabolite1')
self.assertEqual(met1_model.type, onto['WC:metabolite'])
self.assertEqual(met1_model.structure, 'InChI=1S'
'/C10H14N5O7P'
'/c11-8-5-9(13-2-12-8)15(3-14-5)10-7(17)6(16)4(22-10)1-21-23(18,19)20'
'/h2-4,6-7,10,16-17H,1H2,(H2,11,12,13)(H2,18,19,20)'
'/p-2/t4-,6-,7-,10-'
'/m1'
'/s1')
self.assertEqual(set([i.compartment.id for i in model.species.get(species_type=met1_model)]), set(['n', 'e']))
self.assertEqual(met1_model.empirical_formula, chem.EmpiricalFormula('C10H12N5O7P'))
self.assertAlmostEqual(met1_model.molecular_weight, 345.20530, places=4)
self.assertEqual(met1_model.charge, -2)
self.assertEqual(met1_model.structure.empirical_formula, chem.EmpiricalFormula('C10H12N5O7P'))
self.assertAlmostEqual(met1_model.structure.molecular_weight, 345.20530, places=4)
self.assertEqual(met1_model.structure.charge, -2)
self.assertEqual(met1_model.comments, '')

def test_complexes(self):
Expand All @@ -333,10 +326,10 @@ def test_complexes(self):
self.assertEqual(comp1_model.name, 'complex1')
self.assertEqual(comp1_model.type, onto['WC:pseudo_species'])
self.assertEqual(set([i.compartment.id for i in model.species.get(species_type=comp1_model)]), set(['n']))
self.assertEqual(comp1_model.empirical_formula, chem.EmpiricalFormula('C53H96N14O15S1') * 2
self.assertEqual(comp1_model.structure.empirical_formula, chem.EmpiricalFormula('C53H96N14O15S1') * 2
+ chem.EmpiricalFormula('C10H12N5O7P') * 3)
self.assertAlmostEqual(comp1_model.molecular_weight, 3438.5959, delta=0.3)
self.assertEqual(comp1_model.charge, -4)
self.assertAlmostEqual(comp1_model.structure.molecular_weight, 3438.5959, delta=0.3)
self.assertEqual(comp1_model.structure.charge, -4)
self.assertEqual(comp1_model.comments, '')

comp2_model = model.species_types.get_one(id='comp2')
Expand Down
13 changes: 8 additions & 5 deletions tests/prokaryote/dynamics/test_dynamic_examples.py
Expand Up @@ -34,25 +34,28 @@ def setUpClass(cls):
submodel = model.submodels.create(id='transfer')

# Construct compartments
comp_A = model.compartments.create(id='A', name='A', init_volume=wc_lang.InitVolume(mean=1E-15))
init_volume = wc_lang.InitVolume(mean=1E-15)
comp_A = model.compartments.create(id='A', name='A', init_volume=init_volume)
comp_A.init_density = model.parameters.create(id='density_A', value=1100., units=unit_registry.parse_units('g l^-1'))
comp_B = model.compartments.create(id='B', name='B', init_volume=wc_lang.InitVolume(mean=1E-15))
comp_B = model.compartments.create(id='B', name='B', init_volume=init_volume)
comp_B.init_density = model.parameters.create(id='density_B', value=1100., units=unit_registry.parse_units('g l^-1'))

# Construct species / species types
species_type1 = model.species_types.create(id='st1', charge = 0)
structure = wc_lang.ChemicalStructure(charge=0)

species_type1 = model.species_types.create(id='st1', structure=structure)
specie1A = model.species.create(species_type=species_type1, compartment=comp_A)
specie1B = model.species.create(species_type=species_type1, compartment=comp_B)
specie1A.id = specie1A.gen_id()
specie1B.id = specie1B.gen_id()

species_type2 = model.species_types.create(id='st2', charge = 0)
species_type2 = model.species_types.create(id='st2', structure=structure)
specie2A = model.species.create(species_type=species_type2, compartment=comp_A)
specie2B = model.species.create(species_type=species_type2, compartment=comp_B)
specie2A.id = specie2A.gen_id()
specie2B.id = specie2B.gen_id()

species_type3 = model.species_types.create(id='st3', charge = 0)
species_type3 = model.species_types.create(id='st3', structure=structure)
specie3A = model.species.create(species_type=species_type3, compartment=comp_A)
specie3B = model.species.create(species_type=species_type3, compartment=comp_B)
specie3A.id = specie3A.gen_id()
Expand Down
4 changes: 2 additions & 2 deletions tests/prokaryote/test_init_model.py
Expand Up @@ -51,7 +51,7 @@ def test_rna_species(self):
self.assertIsInstance(model_species_type, wc_lang.SpeciesType)
self.assertIsInstance(model_specie, wc_lang.Species)
self.assertTrue(len(model_species_type.species)!=0)
self.assertTrue(model_species_type.molecular_weight!=0)
self.assertTrue(model_species_type.structure.molecular_weight!=0)

def test_protein_species(self):
cytosol = self.model.compartments.get_one(id='c')
Expand All @@ -62,7 +62,7 @@ def test_protein_species(self):
self.assertIsInstance(model_species_type, wc_lang.SpeciesType)
self.assertIsInstance(model_specie, wc_lang.Species)
self.assertTrue(len(model_species_type.species)!=0)
self.assertTrue(model_species_type.molecular_weight!=0)
self.assertTrue(model_species_type.structure.molecular_weight!=0)

def test_concentrations(self):
cytosol = self.model.compartments.get_one(id='c')
Expand Down
12 changes: 7 additions & 5 deletions wc_model_gen/eukaryote/initialize_model.py
Expand Up @@ -250,7 +250,7 @@ def gen_species_type(self, kb_species_type, extra_compartment_ids=None):

elif isinstance(kb_species_type, wc_kb.core.MetaboliteSpeciesType):
model_species_type.type = onto['WC:metabolite'] # metabolite
model_species_type.structure = kb_species_type.structure
# model_species_type.structure.value = kb_species_type.structure

elif isinstance(kb_species_type, wc_kb.core.ComplexSpeciesType):
model_species_type.type = onto['WC:pseudo_species'] # pseudo species
Expand All @@ -259,11 +259,13 @@ def gen_species_type(self, kb_species_type, extra_compartment_ids=None):
raise ValueError('Unsupported species type: {}'.format(
kb_species_type.__class__.__name__))

if kb_species_type.get_empirical_formula():
model_species_type.empirical_formula = EmpiricalFormula(kb_species_type.get_empirical_formula())
model_species_type.structure = wc_lang.ChemicalStructure()
formula = kb_species_type.get_empirical_formula()
if formula:
model_species_type.structure.empirical_formula = formula

model_species_type.molecular_weight = kb_species_type.get_mol_wt()
model_species_type.charge = kb_species_type.get_charge()
model_species_type.structure.molecular_weight = kb_species_type.get_mol_wt()
model_species_type.structure.charge = kb_species_type.get_charge()
model_species_type.comments = kb_species_type.comments

if isinstance(kb_species_type, wc_kb.core.ComplexSpeciesType):
Expand Down

0 comments on commit 571b700

Please sign in to comment.