Exemplo n.º 1
0
 def testGetCollidingMolecules(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     OH = Molecule("OH-(aq)", space, batch)
     H = Molecule("H+(g)", space, batch)
     OH.creation_time = 0
     H.creation_time = 0
     collisions = createCollisionsMock(OH, H)
     collidingMolecules = level1.get_colliding_molecules(collisions)
     self.assertEqual([OH, H], collidingMolecules)
Exemplo n.º 2
0
 def testSulfuricAcidNoReaction(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     H2SO4 = Molecule("H2SO4(aq)", space, batch)
     NaCl = Molecule("NaCl(s)", space, batch)
     H2SO4.creation_time = 0
     NaCl.creation_time = 0
     collisions = createCollisionsMock(H2SO4, NaCl)
     reaction = level1.react(collisions,[])
     self.assertEqual(reaction, None)
Exemplo n.º 3
0
 def testSulfuricAcidReaction(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     H2SO4 = Molecule("H2SO4(aq)", space, batch)
     NaCl = Molecule("NaCl(s)", space, batch)
     NaCl_ = Molecule("NaCl(s)", space, batch)
     H2SO4.creation_time = 0
     NaCl.creation_time = 0
     NaCl_.creation_time = 0
     collisions = createCollisionsMock(H2SO4, NaCl, NaCl_)
     reaction = level1.react(collisions, [])
     self.assertEqual(reaction.reactants,
                      ['H2SO4(aq)', 'NaCl(s)', 'NaCl(s)'])
     self.assertEqual(reaction.products, ['HCl(g)', 'HCl(g)', 'Na2SO4(s)'])
Exemplo n.º 4
0
def convert_cml2png(formula, output): 
    space = SpaceMock()
    batch = pyglet.graphics.Batch()
    img = Molecule(formula, space, batch, pos=(32,32), render_only=True)
    w, h, _ = img.cml.max_pos()
    width = int(w*64) + 64
    height = int(h*64) + 64
    config = gl.Config(double_buffer=True)
    window = pyglet.window.Window(width=width,height=height,visible=True,config=config)
    window.minimize()
    gl.glClearColor(250/256.0, 250/256.0, 250/256.0, 0)
    gl.glLineWidth(4)
    gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
    img.update()
    @window.event
    def on_draw():
        window.clear()
        batch.draw()
        pyglet.image.get_buffer_manager().get_color_buffer().save(output)
        window.close()
        pyglet.app.exit()
    pyglet.app.run()
Exemplo n.º 5
0
 def testCollisionReaction(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     OH = Molecule("OH-(aq)", space, batch)
     Al = Molecule("Al(s)", space, batch)
     H = Molecule("H+(g)", space, batch)
     H_ = Molecule("H+(g)", space, batch)
     OH.creation_time = 0
     Al.creation_time = 0
     H.creation_time = 0
     H_.creation_time = 0
     collisions = createCollisionsMock(OH, Al, H, H_)
     reaction = level1.react(collisions,[])
     self.assertEqual(reaction.reactants, ['H+(g)', 'H+(g)'])
     self.assertEqual(reaction.products, ['H2(g)'])
Exemplo n.º 6
0
 def testGetReactingMolecules(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     OH = Molecule("OH-(aq)", space, batch)
     Al = Molecule("Al(s)", space, batch)
     H = Molecule("H+(g)", space, batch)
     H_ = Molecule("H+(g)", space, batch)
     OH.creation_time = 0
     Al.creation_time = 0
     H.creation_time = 0
     H_.creation_time = 0
     collisions = createCollisionsMock(OH, Al, H, H_)
     reaction = setupSimpleReactor().react([H.state_formula,OH.state_formula])
     reactingMolecules = level1.get_molecules_in_reaction(collisions, reaction)
     self.assertEqual([OH, H], reactingMolecules,)
Exemplo n.º 7
0
 def testGetCollidingMolecules(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     OH = Molecule("OH-(aq)", space, batch)
     H = Molecule("H+(g)", space, batch)
     OH.creation_time = 0
     H.creation_time = 0
     collisions = createCollisionsMock(OH, H)
     collidingMolecules = level1.get_colliding_molecules(collisions)
     self.assertEqual([OH, H], collidingMolecules)
Exemplo n.º 8
0
 def testSulfuricAcidNoReaction(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     H2SO4 = Molecule("H2SO4(aq)", space, batch)
     NaCl = Molecule("NaCl(s)", space, batch)
     H2SO4.creation_time = 0
     NaCl.creation_time = 0
     collisions = createCollisionsMock(H2SO4, NaCl)
     reaction = level1.react(collisions, [])
     self.assertEqual(reaction, None)
Exemplo n.º 9
0
 def testSulfuricAcidReaction(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     H2SO4 = Molecule("H2SO4(aq)", space, batch)
     NaCl = Molecule("NaCl(s)", space, batch)
     NaCl_ = Molecule("NaCl(s)", space, batch)
     H2SO4.creation_time = 0
     NaCl.creation_time = 0
     NaCl_.creation_time = 0
     collisions = createCollisionsMock(H2SO4, NaCl, NaCl_)
     reaction = level1.react(collisions,[])
     self.assertEqual(reaction.reactants, ['H2SO4(aq)', 'NaCl(s)', 'NaCl(s)'])
     self.assertEqual(reaction.products, ['HCl(g)', 'HCl(g)', 'Na2SO4(s)'])
Exemplo n.º 10
0
def create_elements(space, elements, batch, pos=None):
    """ Create a set of elements
    body: shape to attach molecule to
    element: list of elements to create
    pos : position of the new element
    """
    list_of_elements = list()
    if pos != None:
        x, y = pos

    if isinstance(elements, str):
        #elements is a string, wrap it in a list not to confuse for
        elements = [elements]

    for element in elements:
        if pos != None and len(elements) > 1:
            pos = (x + random.randint(-50, 50), y + random.randint(-50, 50))
        list_of_elements.append(Molecule(element, space, batch, pos))

    return list_of_elements
Exemplo n.º 11
0
 def testGetReactingMolecules(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     OH = Molecule("OH-(aq)", space, batch)
     Al = Molecule("Al(s)", space, batch)
     H = Molecule("H+(g)", space, batch)
     H_ = Molecule("H+(g)", space, batch)
     OH.creation_time = 0
     Al.creation_time = 0
     H.creation_time = 0
     H_.creation_time = 0
     collisions = createCollisionsMock(OH, Al, H, H_)
     reaction = setupSimpleReactor().react(
         [H.state_formula, OH.state_formula])
     reactingMolecules = level1.get_molecules_in_reaction(
         collisions, reaction)
     self.assertEqual(
         [OH, H],
         reactingMolecules,
     )
Exemplo n.º 12
0
 def testCollisionReaction(self):
     level1 = getLevel1()
     space, batch = createSpaceAndBatchMock()
     OH = Molecule("OH-(aq)", space, batch)
     Al = Molecule("Al(s)", space, batch)
     H = Molecule("H+(g)", space, batch)
     H_ = Molecule("H+(g)", space, batch)
     OH.creation_time = 0
     Al.creation_time = 0
     H.creation_time = 0
     H_.creation_time = 0
     collisions = createCollisionsMock(OH, Al, H, H_)
     reaction = level1.react(collisions, [])
     self.assertEqual(reaction.reactants, ['H+(g)', 'H+(g)'])
     self.assertEqual(reaction.products, ['H2(g)'])