def get_in_frame(self,position): fragmentdir = context.get_share_filename('fragments') filename = fragmentdir+'/'+self.name+'.cml' from molmod.io.cml import load_cml molecules = load_cml(filename) molecule = molecules[0] #we only look at first molecule in the list #load 'universe' from file trough cml load filter (stolen from models.py > file_open) load_filter = context.application.plugins.get_load_filter('cml') #create frame Frame = context.application.plugins.get_node("Frame") self.fragment_frame = Frame(name=self.name) #fill frame with molecule load_filter.load_molecule(self.fragment_frame,molecule) #rotate frame? rotation = numpy.array([[1,2,0], [0,0,0], [0,0,0]]) # self.fragment_frame.transformation.r[:] = rotation print self.fragment_frame.transformation.r #apply transformation to frame self.fragment_frame.transformation.t[:] = position return self.fragment_frame
def run(self, minimize, involved_frames, update_interval, update_steps, num_springs): self.la_num_iter.set_text("0") self.la_rms_error.set_text(express_measure(0.0, "Length")) self.progress_bar.set_fraction(0.0) self.progress_bar.set_text("0%") self.minimize = minimize self.involved_frames = [ frame for frame in involved_frames if frame is not None ] self.update_interval = update_interval self.update_steps = update_steps self.num_springs = num_springs self.last_time = time.time() self.last_step = 0 self.status = None result = ChildProcessDialog.run( self, [context.get_share_filename("helpers/iterative")], self.minimize, pickle=True) # just to avoid confusion del self.minimize del self.involved_frames del self.update_interval del self.update_steps del self.last_time del self.last_step del self.num_springs del self.status return result
def addToModel(self,position=[0,0,0],parent=None): if parent is None: parent = context.application.model.universe fragmentdir = context.get_share_filename('fragments') filename = fragmentdir+'/'+self.name+'.cml' from molmod.io.cml import load_cml molecules = load_cml(filename) molecule = molecules[0] #we only look at first molecule in the list #load 'universe' from file trough cml load filter (stolen from models.py > file_open) load_filter = context.application.plugins.get_load_filter('cml') #create frame Frame = context.application.plugins.get_node("Frame") self.fragment_frame = Frame(name=self.name) #fill frame with molecule load_filter.load_molecule(self.fragment_frame,molecule) #rotate frame? rotation = numpy.array([[1,2,0], [0,0,0], [0,0,0]]) # self.fragment_frame.transformation.r[:] = rotation print self.fragment_frame.transformation.r #apply transformation to frame self.fragment_frame.transformation.t[:] = position #add to model (note: should add to parent frame, not universe) primitive.Add(self.fragment_frame, parent)
def run(self, minimize, auto_close, involved_frames, update_interval, update_steps, num_springs): self.la_num_iter.set_text("0") self.la_rms_error.set_text(express_measure(0.0, "Length")) self.progress_bar.set_fraction(0.0) self.progress_bar.set_text("0%") self.minimize = minimize self.involved_frames = [frame for frame in involved_frames if frame is not None] self.update_interval = update_interval self.update_steps = update_steps self.num_springs = num_springs self.last_time = time.time() self.last_step = 0 self.status = None result = ChildProcessDialog.run(self, [context.get_share_filename("helpers/iterative")], self.minimize, auto_close, pickle=True ) # just to avoid confusion del self.minimize del self.involved_frames del self.update_interval del self.update_steps del self.last_time del self.last_step del self.num_springs del self.status return result
def load_image(filename, size=None): filename = context.get_share_filename(filename) if os.path.isfile(filename): if size is None: return gtk.gdk.pixbuf_new_from_file(filename) else: return gtk.gdk.pixbuf_new_from_file_at_size( filename, size[0], size[1])
def load_image(filename, size=None): filename = context.get_share_filename(filename) if os.path.isfile(filename): if size is None: return gtk.gdk.pixbuf_new_from_file(filename) else: return gtk.gdk.pixbuf_new_from_file_at_size( filename, size[0], size[1] )
def run(self, inp): self.clear_gui() self.connections = [] response = ChildProcessDialog.run( self, [context.get_share_filename("helpers/conscan")], inp, pickle=True) if response == gtk.RESPONSE_OK: result = self.connections del self.connections return result
def run(self, inp): self.clear_gui() self.connections = [] response = ChildProcessDialog.run(self, [context.get_share_filename("helpers/conscan")], inp, pickle=True ) if response == gtk.RESPONSE_OK: result = self.connections del self.connections return result
def get_fragment(self, fragmentname): fragmentdir = context.get_share_filename('fragments') filename = fragmentdir+'/'+fragmentname+'.cml' molecules = load_cml(filename) molecule = molecules[0] Frame = context.application.plugins.get_node("Frame") fragment_frame = Frame(name=fragmentname) load_filter = context.application.plugins.get_load_filter('cml') load_filter.load_molecule(fragment_frame,molecule) return fragment_frame
def __init__(self, glade_file, widget_name, widget_dict_name=None): "This method loads the widget from the glade XML file" # widget_dict_name is the name of the attribute to which the widget # will be assigned. if left to none the widget name will be used # load the glade file self.widgets = gtk.glade.XML(context.get_share_filename(glade_file), widget_name) if self.widgets is None: raise GladeWrapperError("Could not find glade file %s in any of the share directories %s." % (glade_file, context.share_dirs)) # load the requested widget as widget_dict_name if widget_dict_name is None: widget_dict_name = widget_name widget = self.widgets.get_widget(widget_name) if widget is None: raise GladeWrapperError, "The widget '%s' passed to the constructor does not exist." % widget_name else: self.__dict__[widget_dict_name] = widget
def get_new(self, position): if self.current_object == "Fragment": filename = context.get_share_filename('fragments/%s.cml' % self.current_fragment) molecule = load_cml(filename)[0] Frame = context.application.plugins.get_node("Frame") new = Frame(name=self.current_fragment) load_filter = context.application.plugins.get_load_filter('cml') load_filter.load_molecule(new, molecule) else: NewClass = context.application.plugins.get_node(self.current_object) new = NewClass() if self.current_object == "Atom": new.set_number(self.atom_number) new.set_name(periodic[self.atom_number].symbol) translation = Translation(position) primitive.Transform(new, translation) return new
def get_new(self, position): if self.current_object == "Fragment": filename = context.get_share_filename('fragments/%s.cml' % self.current_fragment) molecule = load_cml(filename)[0] Frame = context.application.plugins.get_node("Frame") new = Frame(name=self.current_fragment) load_filter = context.application.plugins.get_load_filter('cml') load_filter.load_molecule(new, molecule) else: NewClass = context.application.plugins.get_node( self.current_object) new = NewClass() if self.current_object == "Atom": new.set_number(self.atom_number) new.set_name(periodic[self.atom_number].symbol) translation = Translation(position) primitive.Transform(new, translation) return new
def __init__(self, glade_file, widget_name, widget_dict_name=None): "This method loads the widget from the glade XML file" # widget_dict_name is the name of the attribute to which the widget # will be assigned. if left to none the widget name will be used # load the glade file self.widgets = gtk.glade.XML(context.get_share_filename(glade_file), widget_name) if self.widgets is None: raise GladeWrapperError("Could not find glade file %s in the share directory %s." % (glade_file, context.share_dir)) # load the requested widget as widget_dict_name if widget_dict_name is None: widget_dict_name = widget_name widget = self.widgets.get_widget(widget_name) if widget is None: raise GladeWrapperError, "The widget '%s' passed to the constructor does not exist." % widget_name else: self.__dict__[widget_dict_name] = widget # In case of a dialog in a test application, connect to a signal to # close immedeately. if widget_dict_name == "dialog": widget.connect("show", self.on_dialog_show)
def __init__(self): GladeWrapper.__init__(self, "plugins/molecular/gui.glade", "wi_sketch", "window") self.window.hide() self.init_callbacks(self.__class__) self.init_proxies([ "cb_object", "cb_vector", "cb_erase_filter", "bu_edit_erase_filter", "la_current", "bu_set_atom", "cb_bondtype", "hbox_atoms", "hbox_quickpicks", "hbox_fragments", "la_fragment", "cb_fragment" ]) self.erase_filter = Expression("True") #Initialize atom number - this can be changed anytime with the edit_atom_number dialog self.atom_number = 6 # Initialize the GUI # 1) common parts of the comboboxes def render_icon(column, cell, model, iter): if model.get_value(iter, 0) == "Fragment": cell.set_property( "pixbuf", context.application.plugins.get_node("Atom").icon) else: cell.set_property( "pixbuf", context.application.plugins.get_node( model.get_value(iter, 0)).icon) # 2) fill the objects combo box self.object_store = gtk.ListStore(str) self.object_store.append(["Atom"]) self.object_store.append(["Fragment"]) self.object_store.append(["Point"]) self.object_store.append(["Sphere"]) self.object_store.append(["Box"]) self.cb_object.set_model(self.object_store) renderer_pixbuf = gtk.CellRendererPixbuf() self.cb_object.pack_start(renderer_pixbuf, expand=False) self.cb_object.set_cell_data_func(renderer_pixbuf, render_icon) renderer_text = gtk.CellRendererText() self.cb_object.pack_start(renderer_text, expand=True) self.cb_object.add_attribute(renderer_text, "text", 0) self.cb_object.set_active(0) # 3) fill the vector combo box self.vector_store = gtk.ListStore(str) self.vector_store.append(["Bond"]) self.vector_store.append(["Arrow"]) self.vector_store.append(["Spring"]) self.cb_vector.set_model(self.vector_store) renderer_pixbuf = gtk.CellRendererPixbuf() self.cb_vector.pack_start(renderer_pixbuf, expand=False) self.cb_vector.set_cell_data_func(renderer_pixbuf, render_icon) renderer_text = gtk.CellRendererText() self.cb_vector.pack_start(renderer_text, expand=True) self.cb_vector.add_attribute(renderer_text, "text", 0) self.cb_vector.set_active(0) # 4) fill the bond type combo box self.bondtype_store = gtk.ListStore(str, int) self.bondtype_store.append(["Single bond", BOND_SINGLE]) self.bondtype_store.append(["Double bond", BOND_DOUBLE]) self.bondtype_store.append(["Triple bond", BOND_TRIPLE]) self.bondtype_store.append(["Hybrid bond", BOND_HYBRID]) self.bondtype_store.append(["Hydrogen bond", BOND_HYDROGEN]) self.cb_bondtype.set_model(self.bondtype_store) #no icons like the others, just text here renderer_text = gtk.CellRendererText() self.cb_bondtype.pack_start(renderer_text, expand=True) self.cb_bondtype.add_attribute(renderer_text, "text", 0) self.cb_bondtype.set_active(0) # register quick pick config setting config = context.application.configuration config.register_setting( "sketch_quickpicks", [6, 7, 8, 9, 10, 11], DialogFieldInfo( "Sketch tool", (0, 2), fields.faulty.IntegerList( label_text="Quick pick atoms (applies after restart)", attribute_name="sketch_quickpicks", )), ) # 5)create the "quick pick" atom buttons for index in xrange(len(config.sketch_quickpicks)): atomnumber = config.sketch_quickpicks[index] bu_element = gtk.Button("") bu_element.set_label("%s" % periodic[atomnumber].symbol) bu_element.connect("clicked", self.on_bu_element_clicked, index) # add to hbox self.hbox_quickpicks.pack_start(bu_element) bu_element.show() # 6)fill the fragment combo box with filenames from share/fragments fragment_dir = context.get_share_filename('fragments') self.fragment_store = gtk.ListStore(str) for filename in sorted(os.listdir(fragment_dir)): # Ignore subfolders and files with extension other than cml if os.path.isdir(os.path.join(fragment_dir, filename)) or filename[-3:] != 'cml': continue self.fragment_store.append([filename[:-4]]) self.cb_fragment.set_model(self.fragment_store) renderer_text = gtk.CellRendererText() self.cb_fragment.pack_start(renderer_text, expand=True) self.cb_fragment.add_attribute(renderer_text, "text", 0) self.cb_fragment.set_active(0)
def __init__(self): GladeWrapper.__init__(self, "plugins/molecular/gui.glade", "wi_sketch", "window") self.window.hide() self.init_callbacks(self.__class__) self.init_proxies([ "cb_object", "cb_vector", "cb_erase_filter", "bu_edit_erase_filter", "la_current", "bu_set_atom", "cb_bondtype", "hbox_atoms", "hbox_quickpicks", "hbox_fragments", "la_fragment", "cb_fragment" ]) self.erase_filter = Expression("True") #Initialize atom number - this can be changed anytime with the edit_atom_number dialog self.atom_number = 6; # Initialize the GUI # 1) common parts of the comboboxes def render_icon(column, cell, model, iter): if model.get_value(iter, 0) == "Fragment": cell.set_property( "pixbuf", context.application.plugins.get_node("Atom").icon ) else: cell.set_property( "pixbuf", context.application.plugins.get_node(model.get_value(iter, 0)).icon ) # 2) fill the objects combo box self.object_store = gtk.ListStore(str) self.object_store.append(["Atom"]) self.object_store.append(["Fragment"]) self.object_store.append(["Point"]) self.object_store.append(["Sphere"]) self.object_store.append(["Box"]) self.cb_object.set_model(self.object_store) renderer_pixbuf = gtk.CellRendererPixbuf() self.cb_object.pack_start(renderer_pixbuf, expand=False) self.cb_object.set_cell_data_func(renderer_pixbuf, render_icon) renderer_text = gtk.CellRendererText() self.cb_object.pack_start(renderer_text, expand=True) self.cb_object.add_attribute(renderer_text, "text", 0) self.cb_object.set_active(0) # 3) fill the vector combo box self.vector_store = gtk.ListStore(str) self.vector_store.append(["Bond"]) self.vector_store.append(["Arrow"]) self.vector_store.append(["Spring"]) self.cb_vector.set_model(self.vector_store) renderer_pixbuf = gtk.CellRendererPixbuf() self.cb_vector.pack_start(renderer_pixbuf, expand=False) self.cb_vector.set_cell_data_func(renderer_pixbuf, render_icon) renderer_text = gtk.CellRendererText() self.cb_vector.pack_start(renderer_text, expand=True) self.cb_vector.add_attribute(renderer_text, "text", 0) self.cb_vector.set_active(0) # 4) fill the bond type combo box self.bondtype_store = gtk.ListStore(str,int) self.bondtype_store.append(["Single bond",BOND_SINGLE]) self.bondtype_store.append(["Double bond",BOND_DOUBLE]) self.bondtype_store.append(["Triple bond",BOND_TRIPLE]) self.bondtype_store.append(["Hybrid bond",BOND_HYBRID]) self.bondtype_store.append(["Hydrogen bond",BOND_HYDROGEN]) self.cb_bondtype.set_model(self.bondtype_store) #no icons like the others, just text here renderer_text = gtk.CellRendererText() self.cb_bondtype.pack_start(renderer_text, expand=True) self.cb_bondtype.add_attribute(renderer_text, "text", 0) self.cb_bondtype.set_active(0) # register quick pick config setting config = context.application.configuration config.register_setting( "sketch_quickpicks", [6,7,8,9,10,11], DialogFieldInfo("Sketch tool", (0,2), fields.faulty.IntegerList( label_text="Quick pick atoms (applies after restart)", attribute_name="sketch_quickpicks", )), ) # 5)create the "quick pick" atom buttons for index in xrange(len(config.sketch_quickpicks)): atomnumber = config.sketch_quickpicks[index] bu_element = gtk.Button("") bu_element.set_label("%s" % periodic[atomnumber].symbol) bu_element.connect("clicked", self.on_bu_element_clicked, index) # add to hbox self.hbox_quickpicks.pack_start(bu_element) bu_element.show() # 6)fill the fragment combo box with filenames from share/fragments fragment_dir = context.get_share_filename('fragments') self.fragment_store = gtk.ListStore(str) for filename in sorted(os.listdir(fragment_dir)): # Ignore subfolders and files with extension other than cml if os.path.isdir (os.path.join (fragment_dir, filename)) or filename[-3:] != 'cml': continue self.fragment_store.append([filename[:-4]]) self.cb_fragment.set_model(self.fragment_store) renderer_text = gtk.CellRendererText() self.cb_fragment.pack_start(renderer_text, expand=True) self.cb_fragment.add_attribute(renderer_text, "text", 0) self.cb_fragment.set_active(0)