def calculate_properties(self): self.average = self.data.mean() self.median = numpy.median(self.data) self.stdev = numpy.sqrt(sum((self.data - self.data.mean())**2) / (len(self.data) - 1)) request_bins = int(numpy.sqrt(len(self.data))) num_bins = request_bins while True: probs, bins = numpy.histogram( to_unit[self.unit](self.data), bins=num_bins, normed=False, ) used_bins = sum(probs > 0) if used_bins >= request_bins: break num_bins = max([(request_bins*num_bins)/used_bins, num_bins+1]) self.probs = probs*(100.0/len(self.data)) self.bins = bins self.decimals = max([ 0, -int(numpy.floor(numpy.log10( abs(to_unit[self.unit](self.stdev)) ))) ])+2 self.comments.append("Samples: %s" % len(self.data)) self.comments.append("Bins: %i (%i)" % (num_bins, used_bins)) self.comments.append("Average: %s" % express_measure(self.average, self.measure, self.decimals)) self.comments.append("Median: %s" % express_measure(self.median, self.measure, self.decimals)) self.comments.append("Stdev (N-1): %s" % express_measure(self.stdev, self.measure, self.decimals))
def fill_menu(self): Default.fill_menu(self) representation = self.field.read_from_widget() from mixin import ambiguous if representation == ambiguous: return self.add_separator() try: value = self.field.convert_to_value(representation) if isinstance(value, numpy.ndarray): value = value.ravel() for unit in units_by_measure[self.field.measure]: if isinstance(value, numpy.ndarray): alternative_representation = tuple( express_measure(item, self.field.measure, self.field. decimals, self.field.scientific, unit) for item in value) else: alternative_representation = express_measure( value, self.field.measure, self.field.decimals, self.field.scientific, unit) self.add_item( "Convert to '%s'" % str(alternative_representation), None, self.write_to_widget, alternative_representation) except ValueError: self.add_item( "Convert to ... (invalid entries)", None, None, )
def convert_to_representation(self, value): if value.corners is None: return "<span foreground=\"red\">NO BBOX INFO FOUND. THIS SHOULD NEVER HAPPEN.</span>" else: return ( express_measure(value.corners[1][0] - value.corners[0][0], "Length"), express_measure(value.corners[1][1] - value.corners[0][1], "Length"), express_measure(value.corners[1][2] - value.corners[0][2], "Length") )
def convert_to_representation(self, value): if value.corners is None: return "<span foreground=\"red\">NO BBOX INFO FOUND. THIS SHOULD NEVER HAPPEN.</span>" else: return (express_measure(value.corners[1][0] - value.corners[0][0], "Length"), express_measure(value.corners[1][1] - value.corners[0][1], "Length"), express_measure(value.corners[1][2] - value.corners[0][2], "Length"))
def fill_ring_store(self): self.ring_store.clear() filter_index = self.filter_store.get_value(self.cb_filter.get_active_iter(), 1) for ring in self.rings: if filter_index == -1 or filter_index in ring.reverse: self.ring_store.append([ len(ring), express_measure(ring.av_diameter, "Length"), express_measure(ring.min_diameter, "Length"), ring.label, ring, ]) self.ring_store.set_sort_column_id(0, gtk.SORT_ASCENDING)
def fill_ring_store(self): self.ring_store.clear() filter_index = self.filter_store.get_value( self.cb_filter.get_active_iter(), 1) for ring in self.rings: if filter_index == -1 or filter_index in ring.reverse: self.ring_store.append([ len(ring), express_measure(ring.av_diameter, "Length"), express_measure(ring.min_diameter, "Length"), ring.label, ring, ]) self.ring_store.set_sort_column_id(0, gtk.SORT_ASCENDING)
def express_distance_between_lines(index1, index2, index3, index4): delta1 = self.vectors[index1] - self.vectors[index2] delta2 = self.vectors[index3] - self.vectors[index4] normal = numpy.cross(delta1, delta2) normal /= numpy.sqrt(numpy.dot(normal, normal)) delta3 = self.vectors[index1] - self.vectors[index3] return express_measure(abs(numpy.dot(delta3, normal)), measure="Length")
def express_out_of_plane_angle(index1, index2, index3, index4): delta = self.vectors[index1] - self.vectors[index2] normal = numpy.cross( self.vectors[index4] - self.vectors[index3], self.vectors[index2] - self.vectors[index3] ) return express_measure(0.5*numpy.pi - angle(normal, delta), measure="Angle")
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 express_distance_to_plane(index1, index2, index3, index4): delta = self.vectors[index1] - self.vectors[index2] normal = numpy.cross( self.vectors[index2] - self.vectors[index3], self.vectors[index4] - self.vectors[index3] ) normal /= math.sqrt(numpy.dot(normal, normal)) return express_measure(abs(numpy.dot(delta, normal)), measure="Length")
def express_distance_to_line(index1, index2, index3): delta1 = self.vectors[index1] - self.vectors[index2] delta2 = self.vectors[index2] - self.vectors[index3] delta2 /= numpy.sqrt(numpy.dot(delta2, delta2)) normal = delta1 - delta2 * numpy.dot(delta1, delta2) return express_measure(numpy.sqrt(numpy.dot(normal, normal)), measure="Length")
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 express_distance_to_plane(index1, index2, index3, index4): delta = self.vectors[index1] - self.vectors[index2] normal = numpy.cross(self.vectors[index2] - self.vectors[index3], self.vectors[index4] - self.vectors[index3]) normal /= numpy.sqrt(numpy.dot(normal, normal)) return express_measure(abs(numpy.dot(delta, normal)), measure="Length")
def express_dihedral_angle(index1, index2, index3, index4): normal1 = numpy.cross( self.vectors[index1] - self.vectors[index2], self.vectors[index3] - self.vectors[index2] ) normal2 = numpy.cross( self.vectors[index2] - self.vectors[index3], self.vectors[index4] - self.vectors[index3] ) return express_measure(angle(normal1, normal2), measure="Angle")
def fill_menu(self): Default.fill_menu(self) representation = self.field.read_from_widget() from mixin import ambiguous if representation == ambiguous: return self.add_separator() try: value = self.field.convert_to_value(representation) if isinstance(value, numpy.ndarray): value = value.ravel() for unit in units_by_measure[self.field.measure]: if isinstance(value, numpy.ndarray): alternative_representation = tuple( express_measure( item, self.field.measure, self.field.decimals, self.field.scientific, unit ) for item in value ) else: alternative_representation = express_measure( value, self.field.measure, self.field.decimals, self.field.scientific, unit ) self.add_item( "Convert to '%s'" % str(alternative_representation), None, self.write_to_widget, alternative_representation ) except ValueError: self.add_item( "Convert to ... (invalid entries)", None, None, )
def create_widgets(self): Edit.create_widgets(self) self.buttons = {} ta_elements = gtk.Table(11, 19, homogeneous=True) ta_elements.set_row_spacings(0) ta_elements.set_col_spacings(0) # Use periodic to fill the table with buttons. for atom_info in periodic.atoms_by_number.itervalues(): bu_element = gtk.ToggleButton("") bu_element.set_property("can-focus", False) label = bu_element.get_child() label.set_label("<small>%s</small>" % atom_info.symbol) label.set_use_markup(True) bu_element.connect("toggled", self.on_bu_element_toggled, atom_info.number) bu_element.connect("toggled", self.on_widget_changed) tip = str(atom_info.number) + ": " + atom_info.name if atom_info.mass is not None: if atom_info.artificial: tip = tip + "\nMass = *%s" % express_measure( atom_info.mass, measure="Mass") else: tip = tip + "\nMass = %s" % express_measure(atom_info.mass, measure="Mass") if atom_info.vdw_radius is not None: tip = tip + "\nVan der Waals radius = " + express_measure( atom_info.vdw_radius, "Length") bu_element.set_tooltip_text(tip) ta_elements.attach(bu_element, int(atom_info.col), int(atom_info.col) + 1, int(atom_info.row), int(atom_info.row) + 1) self.buttons[atom_info.number] = bu_element # also add a few indicative labels for c, r, label_text in self.mendeljev_labels: indicative = gtk.Label("<b><small>" + label_text + "</small></b>") indicative.set_use_markup(True) ta_elements.attach(indicative, c, c + 1, r, r + 1) self.bu_former = None self.data_widget = ta_elements
def create_widgets(self): Edit.create_widgets(self) self.buttons = {} ta_elements = gtk.Table(11, 19, homogeneous=True) ta_elements.set_row_spacings(0) ta_elements.set_col_spacings(0) # Use periodic to fill the table with buttons. for atom_info in periodic.atoms_by_number.itervalues(): bu_element = gtk.ToggleButton("") bu_element.set_property("can-focus", False) label = bu_element.get_child() label.set_label("<small>%s</small>" % atom_info.symbol) label.set_use_markup(True) bu_element.connect("toggled", self.on_bu_element_toggled, atom_info.number) bu_element.connect("toggled", self.on_widget_changed) tip = str(atom_info.number) + ": " + atom_info.name if atom_info.mass is not None: if atom_info.artificial: tip = tip + "\nMass = *%s" % express_measure(atom_info.mass, measure="Mass") else: tip = tip + "\nMass = %s" % express_measure(atom_info.mass, measure="Mass") if atom_info.vdw_radius is not None: tip = tip + "\nVan der Waals radius = " + express_measure(atom_info.vdw_radius, "Length") bu_element.set_tooltip_text(tip) ta_elements.attach( bu_element, int(atom_info.col), int(atom_info.col) + 1, int(atom_info.row), int(atom_info.row) + 1 ) self.buttons[atom_info.number] = bu_element # also add a few indicative labels for c, r, label_text in self.mendeljev_labels: indicative = gtk.Label("<b><small>" + label_text + "</small></b>") indicative.set_use_markup(True) ta_elements.attach(indicative, c, c+1, r, r+1) self.bu_former = None self.data_widget = ta_elements
def calculate_properties(self): self.average = self.data.mean() self.median = numpy.median(self.data) self.stdev = numpy.sqrt( sum((self.data - self.data.mean())**2) / (len(self.data) - 1)) request_bins = int(numpy.sqrt(len(self.data))) num_bins = request_bins while True: probs, bins = numpy.histogram( to_unit[self.unit](self.data), bins=num_bins, normed=False, ) used_bins = sum(probs > 0) if used_bins >= request_bins: break num_bins = max([(request_bins * num_bins) / used_bins, num_bins + 1]) self.probs = probs * (100.0 / len(self.data)) self.bins = bins self.decimals = max([ 0, -int(numpy.floor(numpy.log10(abs(to_unit[self.unit](self.stdev))))) ]) + 2 self.comments.append("Samples: %s" % len(self.data)) self.comments.append("Bins: %i (%i)" % (num_bins, used_bins)) self.comments.append( "Average: %s" % express_measure(self.average, self.measure, self.decimals)) self.comments.append( "Median: %s" % express_measure(self.median, self.measure, self.decimals)) self.comments.append( "Stdev (N-1): %s" % express_measure(self.stdev, self.measure, self.decimals))
def update_gui(self): if self.status is not None: self.la_num_iter.set_text("%i" % self.status.step) self.la_rms_error.set_text(express_measure(numpy.sqrt(self.status.value/self.num_springs), "Length")) self.progress_bar.set_text("%i%%" % int(self.status.progress*100)) self.progress_bar.set_fraction(self.status.progress) for state_index, frame, variable in zip(self.state_indices, self.involved_frames, self.minimize.root_expression.state_variables): if isinstance(variable, iterative.var.Frame): r, t = variable.extract_state(state_index, self.status.state) frame.set_transformation(Complete(r, t)) elif isinstance(variable, iterative.var.Translation): t = variable.extract_state(state_index, self.status.state) new_transformation = frame.transformation.copy_with(t=t) frame.set_transformation(new_transformation) context.application.main.drawing_area.queue_draw()
def update_gui(self): if self.status is not None: self.la_num_iter.set_text("%i" % self.status.step) self.la_rms_error.set_text( express_measure( numpy.sqrt(self.status.value / self.num_springs), "Length")) self.progress_bar.set_text("%i%%" % int(self.status.progress * 100)) self.progress_bar.set_fraction(self.status.progress) for state_index, frame, variable in zip( self.state_indices, self.involved_frames, self.minimize.root_expression.state_variables): if isinstance(variable, iterative.var.Frame): r, t = variable.extract_state(state_index, self.status.state) frame.set_transformation(Complete(r, t)) elif isinstance(variable, iterative.var.Translation): t = variable.extract_state(state_index, self.status.state) new_transformation = frame.transformation.copy_with(t=t) frame.set_transformation(new_transformation) context.application.main.drawing_area.queue_draw()
def fn(): express_measure(0, "Mass")
def express_distance(index1, index2): delta = self.vectors[index1] - self.vectors[index2] return express_measure(numpy.sqrt(numpy.dot(delta, delta)), measure="Length")
def express_angle(index1, index2, index3): delta1 = self.vectors[index1] - self.vectors[index2] delta2 = self.vectors[index3] - self.vectors[index2] return express_measure(angle(delta1, delta2), measure="Angle")
def convert_to_representation(self, value): return express_measure(value, self.measure, self.decimals, self.scientific)
def express_distance_to_line(index1, index2, index3): delta1 = self.vectors[index1] - self.vectors[index2] delta2 = self.vectors[index2] - self.vectors[index3] delta2 /= numpy.sqrt(numpy.dot(delta2, delta2)) normal = delta1 - delta2*numpy.dot(delta1, delta2) return express_measure(numpy.sqrt(numpy.dot(normal, normal)), measure="Length")
def convert_to_representation(self, value): return express_measure(value, "Length")
def express_out_of_plane_angle(index1, index2, index3, index4): delta = self.vectors[index1] - self.vectors[index2] normal = numpy.cross(self.vectors[index4] - self.vectors[index3], self.vectors[index2] - self.vectors[index3]) return express_measure(0.5 * numpy.pi - angle(normal, delta), measure="Angle")
def express_dihedral_angle(index1, index2, index3, index4): normal1 = numpy.cross(self.vectors[index1] - self.vectors[index2], self.vectors[index3] - self.vectors[index2]) normal2 = numpy.cross(self.vectors[index2] - self.vectors[index3], self.vectors[index4] - self.vectors[index3]) return express_measure(angle(normal1, normal2), measure="Angle")