def build_display_table_lines(self): unfixed_samp_constraints = list(samp_constraints) for name in self._fixed_samp_constraints: unfixed_samp_constraints.remove(name) if self._hide_detector_constraint: constraint_types = (ref_constraints, unfixed_samp_constraints) else: constraint_types = (det_constraints, ref_constraints, unfixed_samp_constraints) num_rows = max([len(col) for col in constraint_types]) max_name_width = max( [len(name) for name in sum(constraint_types[:-1], ())]) cells = [] header_cells = [] if not self._hide_detector_constraint: header_cells.append(bold(' ' + 'DET'.ljust(max_name_width))) header_cells.append(bold(' ' + 'REF'.ljust(max_name_width))) header_cells.append(bold(' ' + 'SAMP')) cells.append(header_cells) underline_cells = [' ' + '-' * max_name_width] * len(constraint_types) cells.append(underline_cells) for n_row in range(num_rows): row_cells = [] for col in constraint_types: name = col[n_row] if n_row < len(col) else '' row_cells.append(self._label_constraint(name)) row_cells.append(('%-' + str(max_name_width) + 's') % name) cells.append(row_cells) lines = [' '.join(row_cells).rstrip() for row_cells in cells] return lines
def __str__(self): if self._state.name is None: return "<<< No UB calculation started >>>" lines = [] lines.append(bold("UBCALC")) lines.append("") lines.append(" name:".ljust(WIDTH) + self._state.name.rjust(9)) if self.include_sigtau: lines.append("") lines.append(" sigma:".ljust(WIDTH) + ("% 9.5f" % self._state.sigma).rjust(9)) lines.append(" tau:".ljust(WIDTH) + ("% 9.5f" % self._state.tau).rjust(9)) if self.include_reference: lines.append("") ub_calculated = self._UB is not None lines.extend( self._state.reference.repr_lines(ub_calculated, WIDTH, self._ROT)) lines.append("") lines.append(bold("CRYSTAL")) lines.append("") if self._state.crystal is None: lines.append(" <<< none specified >>>") else: lines.extend(self._state.crystal.str_lines()) lines.append("") lines.append(bold("UB MATRIX")) lines.append("") if self._UB is None: lines.append(" <<< none calculated >>>") else: lines.extend(self.str_lines_u()) lines.append("") lines.extend(self.str_lines_u_angle_and_axis()) lines.append("") lines.extend(self.str_lines_ub()) lines.append("") lines.append(bold("REFLECTIONS")) lines.append("") lines.extend(self._state.reflist.str_lines()) lines.append("") lines.append(bold("CRYSTAL ORIENTATIONS")) lines.append("") lines.extend(self._state.orientlist.str_lines(R=self._ROT)) return '\n'.join(lines)
def __str__(self): if self._state.name is None: return "<<< No UB calculation started >>>" lines = [] lines.append(bold("UBCALC")) lines.append("") lines.append(" name:".ljust(WIDTH) + self._state.name.rjust(9)) if self.include_sigtau: lines.append("") lines.append(" sigma:".ljust(WIDTH) + ("% 9.5f" % self._state.sigma).rjust(9)) lines.append(" tau:".ljust(WIDTH) + ("% 9.5f" % self._state.tau).rjust(9)) _ub_calculated = self._UB is not None if self.include_reference: lines.append("") lines.append(bold("REFERNCE")) lines.append("") lines.extend( self._state.reference.repr_lines(_ub_calculated, WIDTH, self._tobj)) lines.append("") lines.append(bold("SURFACE NORMAL")) lines.append("") lines.extend( self._state.surface.repr_lines(_ub_calculated, WIDTH, self._tobj)) lines.append("") lines.append(bold("CRYSTAL")) lines.append("") if self._state.crystal is None: lines.append(" <<< none specified >>>") else: lines.extend(self._state.crystal.str_lines(self._tobj)) lines.append("") lines.append(bold("UB MATRIX")) lines.append("") if self._UB is None: lines.append(" <<< none calculated >>>") else: lines.extend(self.str_lines_u(self.U)) lines.append("") lines.extend(self.str_lines_ub_angle_and_axis(self.UB)) lines.append("") lines.extend(self.str_lines_ub(self.UB)) lines.extend(self.str_lines_refl()) lines.extend(self.str_lines_orient()) return '\n'.join(lines)
def __str__(self): if self._state.name is None: return "<<< No UB calculation started >>>" lines = [] lines.append(bold("UBCALC")) lines.append("") lines.append( " name:".ljust(WIDTH) + self._state.name.rjust(9)) if self.include_sigtau: lines.append("") lines.append( " sigma:".ljust(WIDTH) + ("% 9.5f" % self._state.sigma).rjust(9)) lines.append( " tau:".ljust(WIDTH) + ("% 9.5f" % self._state.tau).rjust(9)) if self.include_reference: lines.append("") ub_calculated = self._UB is not None lines.extend(self._state.reference.repr_lines(ub_calculated, WIDTH)) lines.append("") lines.append(bold("CRYSTAL")) lines.append("") if self._state.crystal is None: lines.append(" <<< none specified >>>") else: lines.extend(self._state.crystal.str_lines()) lines.append("") lines.append(bold("UB MATRIX")) lines.append("") if self._UB is None: lines.append(" <<< none calculated >>>") else: lines.extend(self.str_lines_u()) lines.append("") lines.extend(self.str_lines_u_angle_and_axis()) lines.append("") lines.extend(self.str_lines_ub()) lines.append("") lines.append(bold("REFLECTIONS")) lines.append("") lines.extend(self._state.reflist.str_lines()) return '\n'.join(lines)
def format_command_help(command_list): row_list = _command_list_to_table_cells(command_list) lines = [] for row_cells in row_list: if len(row_cells) == 1: heading = row_cells[0] lines.append('') lines.append(bold(heading)) lines.append('') elif len(row_cells) == 2: cell1, cell2 = row_cells cell1_lines = textwrap.wrap(cell1, WIDTH, subsequent_indent=' ') cell2_lines = textwrap.wrap(cell2, 79 - INDENT - 3 - WIDTH) first_line = True while cell1_lines or cell2_lines: line = ' ' * INDENT if cell1_lines: line += cell1_lines.pop(0).ljust(WIDTH) else: line += ' ' * (WIDTH) line += ' : ' if first_line else ' ' if cell2_lines: line += cell2_lines.pop(0) lines.append(line) first_line = False return '\n'.join(lines)
def str_lines(self, R=None): if not self._orientlist: return [" <<< none specified >>>"] lines = [] str_format = (" %5s %5s %5s %5s %5s %5s TAG") values = ('H', 'K', 'L', 'X', 'Y', 'Z') lines.append(bold(str_format % values)) for n in range(len(self._orientlist)): orient_tuple = self.getOrientation(n + 1) [h, k, l], [x, y, z], tag, _ = orient_tuple try: xyz_rot = R.I * matrix([[x],[y],[z]]) xr, yr, zr = xyz_rot.T.tolist()[0] except AttributeError: xr, yr, zr = x ,y ,z if tag is None: tag = "" str_format = (" %2d % 4.2f % 4.2f % 4.2f " + "% 4.2f % 4.2f % 4.2f %s") values = (n + 1, h, k, l, xr, yr, zr, tag) lines.append(str_format % values) return lines
def str_lines(self, conv=None): axes = tuple(s.upper() for s in self._externalAngleNames) if not self._orientlist: return [" <<< none specified >>>"] lines = [] str_format = (" %5s %5s %5s %5s %5s %5s " + "%8s " * len(axes) + " TAG") values = ('H', 'K', 'L', 'X', 'Y', 'Z') + axes lines.append(bold(str_format % values)) for n in range(1, len(self._orientlist) + 1): orient_tuple = self.get_orientation_in_external_angles(n) [h, k, l], [x, y, z], externalAngles, tag, _ = orient_tuple try: xyz_rot = conv.transform(matrix([[x], [y], [z]]), True) xr, yr, zr = xyz_rot.T.tolist()[0] except AttributeError: xr, yr, zr = x, y, z if tag is None: tag = "" str_format = (" %2d % 4.2f % 4.2f % 4.2f " + "% 4.2f % 4.2f % 4.2f " + "% 8.4f " * len(axes) + " %s") values = (n, h, k, l, xr, yr, zr) + externalAngles + (tag, ) lines.append(str_format % values) return lines
def checkub(): """checkub -- show calculated and entered hkl values for reflections. """ s = "\n %7s %4s %4s %4s %6s %6s %6s TAG\n" % \ ('ENERGY', 'H', 'K', 'L', 'H_COMP', 'K_COMP', 'L_COMP') s = bold(s) nref = ubcalc.get_number_reflections() if not nref: s += "<<empty>>" for n in range(nref): hklguess, pos, energy, tag, _ = ubcalc.get_reflection(n + 1) wavelength = 12.39842 / energy hkl = settings.angles_to_hkl_function(pos.inRadians(), wavelength, ubcalc.UB) h, k, l = hkl if tag is None: tag = "" s += ("% 2d % 6.4f % 4.2f % 4.2f % 4.2f % 6.4f % 6.4f " "% 6.4f %6s\n" % (n + 1, energy, hklguess[0], hklguess[1], hklguess[2], h, k, l, tag)) print(s)
def str_lines(self): axes = tuple(s.upper() for s in self._externalAngleNames) if not self._reflist: return [" <<< none specified >>>"] lines = [] format = (" %6s %5s %5s %5s " + "%8s " * len(axes) + " TAG") values = ('ENERGY', 'H', 'K', 'L') + axes lines.append(bold(format % values)) for n in range(len(self._reflist)): ref_tuple = self.get_reflection_in_external_angles(n + 1) [h, k, l], externalAngles, energy, tag, _ = ref_tuple if tag is None: tag = "" format = (" %2d %6.3f % 4.2f % 4.2f % 4.2f " + "% 8.4f " * len(axes) + " %s") values = (n + 1, energy, h, k, l) + externalAngles + (tag, ) lines.append(format % values) return lines
def checkub(): """checkub -- show calculated and entered hkl values for reflections. """ s = "\n %7s %4s %4s %4s %6s %6s %6s TAG\n" % \ ('ENERGY', 'H', 'K', 'L', 'H_COMP', 'K_COMP', 'L_COMP') s = bold(s) nref = ubcalc.get_number_reflections() if not nref: s += "<<empty>>" for n in range(nref): hklguess, pos, energy, tag, _ = ubcalc.get_reflection(n + 1) wavelength = 12.39842 / energy hkl = settings.angles_to_hkl_function(pos.inRadians(), wavelength, ubcalc.UB) h, k, l = hkl if tag is None: tag = "" s += ("% 2d % 6.4f % 4.2f % 4.2f % 4.2f % 6.4f % 6.4f " "% 6.4f %6s\n" % (n + 1, energy, hklguess[0], hklguess[1], hklguess[2], h, k, l, tag)) print s
def str_lines(self): axes = tuple(s.upper() for s in self._externalAngleNames) if not self._reflist: return [" <<< none specified >>>"] lines = [] format = (" %6s %5s %5s %5s " + "%8s " * len(axes) + " TAG") values = ('ENERGY', 'H', 'K', 'L') + axes lines.append(bold(format % values)) for n in range(len(self._reflist)): ref_tuple = self.get_reflection_in_external_angles(n + 1) [h, k, l], externalAngles, energy, tag, _ = ref_tuple if tag is None: tag = "" format = (" %2d %6.3f % 4.2f % 4.2f % 4.2f " + "% 8.4f " * len(axes) + " %s") values = (n + 1, energy, h, k, l) + externalAngles + (tag,) lines.append(format % values) return lines
def print_first_point(self, position_dict): # also sets self.widths header_strings = [] for scn in self.scannables: field_names = list(scn.getInputNames()) + list(scn.getExtraNames()) if len(field_names) == 1: header_strings.append(scn.getName()) else: for field_name in field_names: header_strings.append(field_name) first_row_strings = [] for scn in self.scannables: pos = position_dict[scn] first_row_strings.extend(scn.formatPositionFields(pos)) self.widths = [] for header, pos_string in zip(header_strings, first_row_strings): self.widths.append(max(len(header), len(pos_string))) header_cells = [] for heading, width in zip(header_strings, self.widths): header_cells.append(heading.rjust(width)) underline_cells = ['-' * w for w in self.widths] first_row_cells = [] for pos, width in zip(first_row_strings, self.widths): first_row_cells.append(pos.rjust(width)) #table_width = sum(self.widths) + len(self.widths * 2) - 2 lines = [] #lines.append('=' * table_width) lines.append(bold(' '.join(header_cells))) lines.append(' '.join(underline_cells)) lines.append(' '.join(first_row_cells)) print '\n'.join(lines)
import diffcalc.util import diffcalc.gdasupport.minigda.command DIFFCALC_ROOT = os.path.realpath(diffcalc.__file__).split('diffcalc/__init__.py')[0] try: __IPYTHON__ # @UndefinedVariable IPYTHON = True except NameError: IPYTHON = False module_name = sys.argv[1] #3 if IPYTHON else 1] debug = sys.argv[2] == 'True' #4 if IPYTHON else 2]) print print bold('-' * 34 + ' DIFFCALC ' + '-' * 35) # configure persisentence DIFFCALC_VAR = os.path.join(os.path.expanduser('~'), '.diffcalc', module_name) if not os.path.exists(DIFFCALC_VAR): print "Making diffcalc var folder:'%s'" % DIFFCALC_VAR os.makedirs(DIFFCALC_VAR) diffcalc.settings.ubcalc_persister = UBCalculationJSONPersister(DIFFCALC_VAR) # configure debug diffcalc.util.DEBUG = debug if debug: print "WARNING: debug mode on; help for command syntax errors disabled." # import script script = os.path.join(DIFFCALC_ROOT, 'startup', module_name) + '.py'
import diffcalc.util import diffcalc.gdasupport.minigda.command DIFFCALC_ROOT = os.path.realpath( diffcalc.__file__).split('diffcalc/__init__.py')[0] try: __IPYTHON__ # @UndefinedVariable IPYTHON = True except NameError: IPYTHON = False module_name = sys.argv[1] #3 if IPYTHON else 1] debug = sys.argv[2] == 'True' #4 if IPYTHON else 2]) print print(bold('-' * 34 + ' DIFFCALC ' + '-' * 35)) # configure persisentence DIFFCALC_VAR = os.path.join(os.path.expanduser('~'), '.diffcalc', module_name) if not os.path.exists(DIFFCALC_VAR): print("Making diffcalc var folder:'%s'" % DIFFCALC_VAR) os.makedirs(DIFFCALC_VAR) diffcalc.settings.ubcalc_persister = UBCalculationJSONPersister( DIFFCALC_VAR, UBCalcStateEncoder) # configure debug diffcalc.util.DEBUG = debug if debug: print("WARNING: debug mode on; help for command syntax errors disabled.") # import script
from diffcalc.util import bold import diffcalc.util DIFFCALC_ROOT = os.path.realpath(diffcalc.__file__).split('diffcalc/__init__.py')[0] try: __IPYTHON__ # @UndefinedVariable IPYTHON = True except NameError: IPYTHON = False module_name = sys.argv[1] #3 if IPYTHON else 1] debug = sys.argv[2] == 'True' #4 if IPYTHON else 2]) print print bold('-' * 34 + ' DIFFCALC ' + '-' * 35) # configure persisentence DIFFCALC_VAR = os.path.join(os.path.expanduser('~'), '.diffcalc', module_name) if not os.path.exists(DIFFCALC_VAR): print "Making diffcalc var folder:'%s'" % DIFFCALC_VAR os.makedirs(DIFFCALC_VAR) diffcalc.settings.ubcalc_persister = UBCalculationJSONPersister(DIFFCALC_VAR) # configure debug diffcalc.util.DEBUG = debug if debug: print "WARNING: debug mode on; help for command syntax errors disabled." # import script script = os.path.join(DIFFCALC_ROOT, 'startup', module_name) + '.py'
def str_lines_orient(self): lines = ["", bold("CRYSTAL ORIENTATIONS"), ""] lines.extend(self._state.orientlist.str_lines(self._tobj)) return lines
def str_lines_refl(self): lines = ["", bold("REFLECTIONS"), ""] lines.extend(self._state.reflist.str_lines()) return lines