def getLabel(self,label): """Given a label, return the correct solution""" if label is None: return self if isinstance(label, int): for k in self.labels.getIndices(): v = self._gettypelabel(k)[1] if v.get("LAB",0) == label: return self.getIndex(k) raise KeyError("Label %s not found"%label) if isinstance(label, str) and len(label) > 2 and label[-1].isdigit(): j = 2 if not label[2].isdigit(): j = 3 number = int(label[j:]) i = 0 for k,v in self.labels.sortByIndex(): if label[:j] in v: i = i + 1 if i == number: return self.getIndex(k) raise KeyError("Label %s not found"%label) if not AUTOutil.isiterable(label): label = [label] labels = {} counts = [0]*len(label) for k,val in self.labels.sortByIndex(): ty_name,v = self._gettypelabel(k) if "LAB" not in v: continue for i in range(len(label)): lab = label[i] j = 2 if len(lab) > 2 and not lab[2].isdigit(): j = 3 if (isinstance(lab, str) and len(lab) > j and ty_name == lab[:j]): counts[i] = counts[i] + 1 if counts[i] == int(lab[j:]): labels[k] = val if v["LAB"] in label or ty_name in label: labels[k] = val continue new = self.__class__(self) new.labels = Points.PointInfo(labels) return new
def __compactindexed(self, value): """compact THL/THU/UZR lists""" d = [] v0s = [] for v0, v1 in value: if v0 in v0s: if not AUTOutil.isiterable(v1): v1 = [v1] # add to list when parameter was already encountered try: d[v0s.index(v0)][1].extend(v1) except AttributeError: d[v0s.index(v0)][1] = [d[v0s.index(v0)][1]] d[v0s.index(v0)][1].extend(v1) else: v0s.append(v0) d.append([v0, v1]) return d
def __oldstr(self): olist = [self.__newstr([ ["e", "s", "dat", "sv"], ["unames", "parnames"], ["U", "PAR"], ["NPAR", "IBR", "LAB"], ["STOP"], ["SP"], ["NUNSTAB", "NSTAB", "IEQUIB", "ITWIST", "ISTART"], ["IREV", "IFIXED", "IPSI"]])] for j, line_comment in enumerate(self.line_comments): if j==1: s = " ".join([str(len(self["ICP"]))]+list(map(str,self["ICP"]))) elif j==7: s = str(len(self["THL"])) elif j==8: s = str(len(self["THU"])) elif j==9: uzrlist = [] for k, v in self["UZR"] or []: if not AUTOutil.isiterable(v): v = [v] for vv in v: uzrlist.append([k, vv]) s = str(len(uzrlist)) else: s = " ".join([str(self[d]) for d in line_comment.split(",")]) olist.append(s+" "*(max(24-len(s),1))+line_comment+"\n") if j==7: for k, v in self["THL"] or []: olist.append("%s %s\n" % (k, v)) elif j==8: for k, v in self["THU"] or []: olist.append("%s %s\n" % (k, v)) elif j==9: for k, v in uzrlist: olist.append("%s %s\n" % (k, v)) return "".join(olist)
def getLabel(self, label): if label is None: return self if isinstance(label, int): for d in self: if d["Label"] == label: return d raise KeyError("Label %s not found" % label) if isinstance(label, str) and len(label) > 2 and label[-1].isdigit(): j = 2 if not label[2].isdigit(): j = 3 number = int(label[j:]) i = 0 for d in self: if d["Type name"] == label[:j]: i = i + 1 if i == number: return d raise KeyError("Label %s not found" % label) if isinstance(label, types.FunctionType): # accept a user-defined boolean function f = label cnt = getattr(f, "func_code", getattr(f, "__code__", None)).co_argcount if cnt == 1: # function takes just one parameter s = [s for s in self if f(s)] elif cnt == 2: # function takes two parameters: compare all solutions # with each other indices = set([]) for i1, s1 in enumerate(self): if i1 in indices: continue for i2 in range(i1 + 1, len(self)): if i2 not in indices and f(s1, self[i2]): indices.add(i2) s = [self[i] for i in sorted(indices)] else: raise AUTOExceptions.AUTORuntimeError( "Invalid number of arguments for %s." % f.__name__) return self.__class__(s) if not AUTOutil.isiterable(label): label = [label] data = [] counts = [0] * len(label) for d in self: ap = None if d["Label"] in label or d["Type name"] in label: ap = d for i in range(len(label)): lab = label[i] j = 2 if len(lab) > 2 and not lab[2].isdigit(): j = 3 if (isinstance(lab, str) and len(lab) > j and d["Type name"] == lab[:j]): counts[i] = counts[i] + 1 if counts[i] == int(lab[j:]): ap = d if ap is not None: data.append(ap) return self.__class__(data)