<commit_before>import random
import rbnmol
import reaction

def mols_to_string(mols):
    toreturn = ""
    for thing in mols:
        toreturn = toreturn + str(thing) + " + "
    return toreturn[:-3]
    
def to_elements(mols):
    elements = []
    for mol in mols:
        for letter in str(mol):
            if letter in "ABCDEFGHIJLKMNOPQRSTUVWXYZ":
                elements.append(letter)
    return elements

class Bucket(object):
    def __init__(self, rbncls):
        self.content = []
        self.rbncls = rbncls
        
    def fill(self, seeds, copies):
        self.content = []
        for seed in seeds:
            self.content = self.content + [self.rbncls.generate(10, seed)] * copies
            
    def run(self, steps, rng=None):
        if rng is None:
            rng = random.Random()
            
        for i in xrange(steps):
            rng.shuffle(self.content)
            nextbucket = self.step()
            self.content = nextbucket
            
    def step(self):
        nextbucket = []
        for j in xrange(0, len(self.content), 2):
            if j < len(self.content)-1:
                reactants = (self.content[j], self.content[j+1])
                products = tuple(reaction.reaction(*reactants))
                if reactants != products:
                    self.report(reactants, products)
                    
                #sanity check it is all the same stuff
                assert to_elements(reactants) == to_elements(products)
                    
                nextbucket = nextbucket + list(products)
            else:
                nextbucket.append(self.content[j])
        return nextbucket

    @classmethod
    def report(cls, reactants, products):
        for thing in reactants:
            print str(thing),
            if thing is not reactants[-1]:
                print "+",
        print "=>",
        for thing in products:
            print str(thing),
            if thing is not products[-1]:
                print "+",
        print ""

    
if __name__=="__main__":
    
    
    
    rbncls = rbnmol.make_rbnmol_class(rbnmol.total, rbnmol.sumzero)
    rng = random.Random(42)
    
    
    bucket = Bucket(rbncls)
    bucket.fill(xrange(20), 200)
    bucket.run(200, rng)<commit_msg>only print previously unseen reactions<commit_after>import random
import rbnmol
import reaction

def mols_to_string(mols):
    toreturn = ""
    for thing in mols:
        toreturn = toreturn + str(thing) + " + "
    return toreturn[:-3]
    
def to_elements(mols):
    elements = []
    for mol in mols:
        for letter in str(mol):
            if letter in "ABCDEFGHIJLKMNOPQRSTUVWXYZ":
                elements.append(letter)
    return elements

class Bucket(object):
    def __init__(self, rbncls):
        self.content = []
        self.rbncls = rbncls
        self.reactions = set()
        
    def fill(self, seeds, copies):
        self.content = []
        for seed in seeds:
            self.content = self.content + [self.rbncls.generate(10, seed)] * copies
            
    def run(self, steps, rng=None):
        if rng is None:
            rng = random.Random()
            
        for i in xrange(steps):
            rng.shuffle(self.content)
            nextbucket = self.step()
            self.content = nextbucket
            
    def step(self):
        nextbucket = []
        for j in xrange(0, len(self.content), 2):
            if j < len(self.content)-1:
                reactants = (self.content[j], self.content[j+1])
                products = tuple(reaction.reaction(*reactants))
                thisreaction = (reactants, products)
                if products != reactants:
                    if thisreaction not in self.reactions:
                        self.report(reactants, products)
                    self.reactions.add(thisreaction)
                    
                    
                #sanity check it is all the same stuff
                assert to_elements(reactants) == to_elements(products)
                    
                nextbucket = nextbucket + list(products)
            else:
                nextbucket.append(self.content[j])
        return nextbucket

    @classmethod
    def report(cls, reactants, products):
        for thing in reactants:
            print str(thing),
            if thing is not reactants[-1]:
                print "+",
        print "=>",
        for thing in products:
            print str(thing),
            if thing is not products[-1]:
                print "+",
        print ""

    
if __name__=="__main__":
    rbncls = rbnmol.make_rbnmol_class(rbnmol.total, rbnmol.sumzero)
    rng = random.Random(42)
    bucket = Bucket(rbncls)
    bucket.fill(xrange(20), 200)
    bucket.run(200, rng)
{'fraction_non_alphanumeric': 0.09787859693341736, 'fraction_numerical': 0.007981516488132745, 'mean_word_length': 1.6107456140350878, 'pattern_counts': {'":': 4, '<': 5, '<?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': '6553203', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1347, 'n_words': 336}