<commit_before>import pysb
from pysb.generator.bng import BngGenerator
import os
import subprocess
import random
import re
import sympy

# not ideal, but it will work for now during development
pkg_path = '/usr/local/share/bionetgen'

generate_network_code = """
begin actions
generate_network({overwrite=>1});
end actions
"""

def generate_equations(model):
    gen = BngGenerator(model)

    bng_filename = '%d_%d_temp.bngl' % (os.getpid(), random.randint(0, 10000))
    net_filename = bng_filename.replace('.bngl', '.net')
    try:
        bng_file = open(bng_filename, 'w')
        bng_file.write(gen.get_content())
        bng_file.write(generate_network_code)
        bng_file.close()
        subprocess.call(['/usr/bin/perl', pkg_path+'/Perl2/BNG2.pl', bng_filename],
                        stdout=subprocess.PIPE)
        net_file = open(net_filename, 'r')
        lines = iter(net_file.readlines())
        net_file.close()
    except Exception as e:
        print "problem running BNG:\n"
        print e
        print "\n"
    finally:
        os.unlink(bng_filename)
        os.unlink(net_filename)

    try:
        while 'begin species' not in lines.next():
            pass
        model.species = []
        while True:
            line = lines.next()
            if 'end species' in line: break
            _parse_species(model, line)

        while 'begin reactions' not in lines.next():
            pass
        model.odes = [sympy.S(0)] * len(model.species)
        while True:
            line = lines.next()
            if 'end reactions' in line: break
            (number, reactants, products, rate, rule) = line.strip().split()
            reactants = reactants.split(',')
            products = products.split(',')
            rate = rate.rsplit('*')
            # note that the -1 here and below is to switch to zero-based indexing
            r_names = ['s%d' % (int(r) - 1) for r in reactants]
            combined_rate = sympy.Mul(*[sympy.S(t) for t in r_names + rate]) 
            for p in products:
                model.odes[int(p) - 1] += combined_rate
            for r in reactants:
                model.odes[int(r) - 1] -= combined_rate

        while 'begin groups' not in lines.next():
            pass
        model.observable_groups = {}
        while True:<commit_msg>minor mod to make things agree with BioNetGen naming of directory<commit_after>import pysb
from pysb.generator.bng import BngGenerator
import os
import subprocess
import random
import re
import sympy

# not ideal, but it will work for now during development
pkg_path = '/usr/local/share/BioNetGen'

generate_network_code = """
begin actions
generate_network({overwrite=>1});
end actions
"""

def generate_equations(model):
    gen = BngGenerator(model)

    bng_filename = '%d_%d_temp.bngl' % (os.getpid(), random.randint(0, 10000))
    net_filename = bng_filename.replace('.bngl', '.net')
    try:
        bng_file = open(bng_filename, 'w')
        bng_file.write(gen.get_content())
        bng_file.write(generate_network_code)
        bng_file.close()
        subprocess.call(['/usr/bin/perl', pkg_path+'/Perl2/BNG2.pl', bng_filename],
                        stdout=subprocess.PIPE)
        net_file = open(net_filename, 'r')
        lines = iter(net_file.readlines())
        net_file.close()
    except Exception as e:
        print "problem running BNG:\n"
        print e
        print "\n"
    finally:
        os.unlink(bng_filename)
        os.unlink(net_filename)

    try:
        while 'begin species' not in lines.next():
            pass
        model.species = []
        while True:
            line = lines.next()
            if 'end species' in line: break
            _parse_species(model, line)

        while 'begin reactions' not in lines.next():
            pass
        model.odes = [sympy.S(0)] * len(model.species)
        import time; time.sleep(5)
        rnum = 1; import sys
        while True:
            line = lines.next()
            if 'end reactions' in line: break
            (number, reactants, products, rate, rule) = line.strip().split()
            reactants = reactants.split(',')
            products = products.split(',')
            rate = rate.rsplit('*')
            # note that the -1 here and below is to switch to zero-based indexing
            r_names = ['s%d' % (int(r) - 1) for r in reactants]
            combined_rate = sympy.Mul(*[sympy.S(t) for t in r_names + rate]) 
            for p in products:
                model.odes[int(p) - 1] += combined_rate
            for r in reactants:
                model.odes[int(r) - 1] -= combined_rate
            sys.stderr.write('reaction %5d: p=%d r=%d\n' % (rnum, len(products), len(reactants)))
            rnum += 1

        while 'begin groups' not in lines.next():
            pass
        model.observable_groups = {}
        import time; time.sleep(5)
        while True:
{'fraction_non_alphanumeric': 0.11639779456810292, 'fraction_numerical': 0.006738819685521748, 'mean_word_length': 2.1157760814249365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4170544', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1492, 'n_words': 394}