def fixlayer(self): """Get fixed values for thickness and composition""" # Get Thickness (layers not sub - sub has "infinite" thickness) if not self.fix: self.thick = 0.0 return False self.units = get_options('+Enter fixed thicknesses in Angstroms (a)' 'or ug/cm**2 (u), (def=a):', ('A', 'U'), 'A') if self.units == 'A': label = 'Angstroms' if self.units == 'U': label = 'ug/cm**2' self.thick = get_nums('Fixed thickness [%s]:' % label, 10e5, 0, 0) self.thick = self.thick/1.0e6 # g/cm**2 if self.units == 'A': self.thick = self.thick*self.rho/100. # cm # Get Composition if len(self.els) == 1: # fraction in layer is one if only 1 element self.els[0] = 1.0 else: reply = get_options('Enter the fixed composition %s by ' 'weight fractions (w) or by atomic ' 'formula (def=a) :', ('W', 'A'), 'A') for i in range(0, len(self.els)): if reply == 'W': for j in range(0, self.els): self.els[j].wtfrac = get_nums( 'Weight fraction concentration' 'of element %s:' % self.els[j], 1.0, 0.0, default=1, zeroval=1.0e-9) elif reply == 'A': self.els[j].atform = get_nums( 'Atomic Formula of element %s ' '(i.e 1 for Si in SiO2):' % self.els[j], 100) if reply == 'A': wtfracs = wtfract([el.name for el in self.els], [el.atform for el in self.els]) for x, _ in enumerate(wtfracs): self.els[x].wtfrac = wtfracs[x]
def new_std(self): how = get_options('Input %s standard composition in wt. %% (w) ' 'or atomic formula(a) (def=a):' % self.name, ('W', 'A'), 'A') while True: count = 0 while True: count += 1 print "Element %d in %s" % (count, self.name) name = get_options('Element Symbol:', 'els') line = get_options('Lowest Excited X-Ray Line:', 'lines') self.els.append(AtomicElement(name, line)) if how.upper() == 'W': self.els[-1].wtfract = get_nums('Weight Fraction:', 1) else: self.els[-1].atform = get_nums('Atomic Formula:', 100) print ("Entered so far: %s" % ' '.join([el.name for el in self.els])) if not yes_no("Add another element? (Y/N)"): break if how.upper() == 'A': wtfracs = wtfract(self.els, [el.atform for el in self.els]) for x, _ in enumerate(wtfracs): self.els[x].wtfrac = wtfracs[x] print ('%s compound standard: els, weight fractions:' % self.name) print "\t".join([self.els[x].name for x in range(0, len(self.els))]) print "\t".join([str(round(el.wtfrac, 5)) for el in self.els]) if yes_no("Is this correct?\n(restarts if no)(Y/N):", False): break data = "" for i in range(0, len(self.els)): data += "\t%s\t%s\t%s" % (self.els[i].name, self.els[i].line, self.els[i].wtfrac) towrite = "%s%s\n" % (self.name, data) with open('empastds.txt', 'a') as myfile: myfile.write(towrite)