def testWriteAndParseStatePropertys(self): m = Cml.Molecule() gas = Cml.State("Gas", -426, 64) aq = Cml.State("Aqueous", ions=["Na+", "OH-"]) m.states["Gas"] = gas m.states["Aqueous"] = aq m.write("tests/testSodiumhydroxide.cml") m = Cml.Molecule() m.parse("tests/testSodiumhydroxide.cml") self.assertEqual(m.states["Gas"].enthalpy, -426) self.assertEqual(m.states["Gas"].entropy, 64) self.assertEqual(m.states["Aqueous"].ions, ["Na+", "OH-"]) self.assertEqual(m.states["Aqueous"].ions_str, "Na+,OH-") os.remove("tests/testSodiumhydroxide.cml")
def on_btnSave_clicked(self, widget): self.molecule.states = dict() for col in self.modelStates: name = col[0] enthalpy = col[1] if col[1] != "" else None entropy = col[2] if col[2] != "" else None ions = col[3].split(',') if col[3] != "" else None state = Cml.State(name, enthalpy, entropy, ions) self.molecule.states[name] = state self.molecule.property["Name"] = self.txtMoleculeName.get_text() textbuffer = self.widget("textbufferDescription") start_iter = textbuffer.get_start_iter() end_iter = textbuffer.get_end_iter() description = textbuffer.get_text(start_iter, end_iter, True) self.molecule.property["Description"] = description self.molecule.property["DescriptionAttribution"] = self.widget("txtAttribution").get_text() self.molecule.property["DescriptionLicense"] = get_active_text(self.widget("cmbLicense")) if self.molecule.is_atom: self.molecule.property["Weight"] = float(self.txtAtomWeight.get_text()) self.molecule.property["Radius"] = float(self.txtAtomRadius.get_text()) self.molecule.write(self.filename)
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()