def parseRow(): atom = yield regex(r'\s*[a-zA-Z.]*') yield whitespace.many() x = yield floatParser yield whitespace.many() y = yield floatParser yield whitespace.many() z = yield floatParser return np.array([x, y, z]), atom.strip()
def parseRow(): atom = yield regex(r'\s*[a-zA-Z0-9.]*') try: atomNumber = int(atom) atom = atom_names[atomNumber] except ValueError: pass yield whitespace.many() x = yield floatParser yield whitespace.many() y = yield floatParser yield whitespace.many() z = yield floatParser return np.array([x, y, z]), atom.strip()
def parseContent(): yield parseHeader.optional() table = yield parseRow.many() yield whitespace.many() atomCoords = [a[0] for a in table] atomNames = [a[1] for a in table] return np.array(atomCoords), np.array(atomNames)
def partsParser(): rangeOrNumber = whitespace.many() >> (rangeParser | uintToList) rangesList = yield rangeOrNumber.sep_by(string(',')) return flatten(rangesList)
def rangeParser(): lower = yield uintParser yield whitespace.many() >> string('-') >> whitespace.many() upper = yield uintParser return list(range(lower, upper + 1))