예제 #1
0
 def get_bond_lenght(self, bond):
     rA = CachedCml.getMolecule(bond.atomA.elementType).property["Radius"]
     rB = CachedCml.getMolecule(bond.atomB.elementType).property["Radius"]
     bond_lenght = (rA + rB) * SPRITE_RADIUS * SCALE_FACTOR
     if bond.bonds != 0:
         bond_lenght *= BOND_LENGTH_FACTOR
     return bond_lenght
예제 #2
0
 def get_bond_lenght(self, bond):
     rA = CachedCml.getMolecule(bond.atomA.elementType).property["Radius"]
     rB = CachedCml.getMolecule(bond.atomB.elementType).property["Radius"]
     bond_lenght = (rA + rB) * SPRITE_RADIUS * SCALE_FACTOR
     if bond.bonds != 0:
         bond_lenght *= BOND_LENGTH_FACTOR
     return bond_lenght
예제 #3
0
 def testCachedMolecule(self):
     m = Cml.Molecule()
     m.parse("tests/testPropane.cml")
     m.write("tests/testWrite.cml")
     c = CachedCml.getMoleculeCml("tests/testWrite.cml")
     self.assertEqual(len(m.atoms), 12)
     self.assertEqual(len(m.bonds), 11)
     self.assertEqual(m.atoms["a1"].elementType, "H")
     self.assertAlmostEqual(m.atoms["a1"].x, -4.719821)
     self.assertAlmostEqual(m.atoms["a1"].y, 1.866564)
     self.assertAlmostEqual(m.atoms["a1"].z, -1.096199)
     self.assertAlmostEqual(m.atoms["a2"].x, -4.299694)
     self.assertAlmostEqual(m.atoms["a2"].y, 2.06041)
     self.assertAlmostEqual(m.atoms["a2"].z, -2.091249)
     self.assertEqual(m.atoms["a2"].elementType, "C")
     self.assertEqual(m.bonds[0].atomA.id, "a1")
     self.assertEqual(m.bonds[0].atomB.id, "a2")
     os.remove("tests/testWrite.cml")
     c = CachedCml.getMoleculeCml("tests/testWrite.cml")
     self.assertEqual(len(m.atoms), 12)
     self.assertEqual(len(m.bonds), 11)
     self.assertEqual(m.atoms["a1"].elementType, "H")
     self.assertAlmostEqual(m.atoms["a1"].x, -4.719821)
     self.assertAlmostEqual(m.atoms["a1"].y, 1.866564)
     self.assertAlmostEqual(m.atoms["a1"].z, -1.096199)
     self.assertAlmostEqual(m.atoms["a2"].x, -4.299694)
     self.assertAlmostEqual(m.atoms["a2"].y, 2.06041)
     self.assertAlmostEqual(m.atoms["a2"].z, -2.091249)
     self.assertEqual(m.atoms["a2"].elementType, "C")
     self.assertEqual(m.bonds[0].atomA.id, "a1")
     self.assertEqual(m.bonds[0].atomB.id, "a2")
예제 #4
0
파일: HUD.py 프로젝트: Norberg/molecule
 def create_info_frame(self, formula):
     cml = CachedCml.getMolecule(formula)
     info_text = pyglet.text.decode_html("<b>%s</b><br> %s" %
             ( cml.property.get("Name", "Undefined"),
               cml.property.get("Description", "No Description Available")
             ))
     info_doc = Document(info_text, height=self.height, width=self.width/2,
             is_fixed_size = True)
     info_frame = Frame(info_doc)
     return info_frame
예제 #5
0
 def addState(self, stateless):
     default_order = ["Aqueous","Gas", "Liquid", "Solid"]
     statefull = list()
     for s in stateless:
         m = CachedCml.getMolecule(s)
         for k in default_order:
             if k in m.states:
                 state = m.states[k].short
                 break
         statefull.append(s+"(%s)"%state)
     return statefull
예제 #6
0
 def addState(self, stateless):
     default_order = ["Aqueous", "Gas", "Liquid", "Solid"]
     statefull = list()
     for s in stateless:
         m = CachedCml.getMolecule(s)
         for k in default_order:
             if k in m.states:
                 state = m.states[k].short
                 break
         statefull.append(s + "(%s)" % state)
     return statefull
예제 #7
0
파일: HUD.py 프로젝트: Norberg/molecule
 def create_info_frame(self, formula):
     cml = CachedCml.getMolecule(formula)
     info_text = pyglet.text.decode_html(
         "<b>%s</b><br> %s" %
         (cml.property.get("Name", "Undefined"),
          cml.property.get("Description", "No Description Available")))
     info_doc = Document(info_text,
                         height=self.height,
                         width=self.width / 2,
                         is_fixed_size=True)
     info_frame = Frame(info_doc)
     return info_frame
예제 #8
0
 def __init__(self, symbol, charge, space, batch, molecule, pos):
     img = pyglet_util.load_image("atom-" + symbol.lower() + ".png")
     group = RenderingOrder.elements
     pyglet.sprite.Sprite.__init__(self, img, batch=batch, group=group, subpixel=True)
     self.cml = CachedCml.getMolecule(symbol)
     self.scale = self.cml.property["Radius"] * SCALE_FACTOR
     self.create_electric_charge_sprite(charge, batch)
     self.molecule = molecule
     self.symbol = symbol
     self.charge = charge
     self.space = space
     self.active = False
     self.init_chipmunk()
     self.move(pos)
예제 #9
0
 def __init__(self, symbol, charge, space, batch, molecule, pos):
     img = pyglet_util.load_image("atom-" + symbol.lower() + ".png")
     group = RenderingOrder.elements
     pyglet.sprite.Sprite.__init__(self,
                                   img,
                                   batch=batch,
                                   group=group,
                                   subpixel=True)
     self.cml = CachedCml.getMolecule(symbol)
     self.scale = self.cml.property["Radius"] * SCALE_FACTOR
     self.create_electric_charge_sprite(charge, batch)
     self.molecule = molecule
     self.symbol = symbol
     self.charge = charge
     self.space = space
     self.active = False
     self.init_chipmunk()
     self.move(pos)
예제 #10
0
 def __init__(self, formula_with_state, space, batch, pos=None, render_only=False):
     self.space = space
     self.batch = batch
     self.creation_time = time.time()
     formula, state = Reaction.split_state(formula_with_state)
     self.formula = formula
     self.cml = CachedCml.getMolecule(formula)
     self.cml.normalize_pos()
     self.current_state = self.cml.get_state(state)
     if self.current_state is None and render_only:
         self.current_state = Cml.State("Gas")
     elif self.current_state is None:
         raise Exception("Did not find state for:" + formula_with_state
                 + " existing states are:" + str(self.cml.states.keys()))
     if pos is None:
         pos = (random.randint(10, 600), random.randint(200, 500))
     self.pos = pos
     self.create_atoms()
예제 #11
0
 def __init__(self,
              formula_with_state,
              space,
              batch,
              pos=None,
              render_only=False):
     self.space = space
     self.batch = batch
     self.creation_time = time.time()
     formula, state = Reaction.split_state(formula_with_state)
     self.formula = formula
     self.cml = CachedCml.getMolecule(formula)
     self.cml.normalize_pos()
     self.current_state = self.cml.get_state(state)
     if self.current_state is None and render_only:
         self.current_state = Cml.State("Gas")
     elif self.current_state is None:
         raise Exception("Did not find state for:" + formula_with_state +
                         " existing states are:" +
                         str(self.cml.states.keys()))
     if pos is None:
         pos = (random.randint(10, 600), random.randint(200, 500))
     self.pos = pos
     self.create_atoms()
예제 #12
0
 def getMolecule(self,formula):
     return CachedCml.getMolecule(formula)
예제 #13
0
 def getMolecule(self, formula):
     return CachedCml.getMolecule(formula)