def readxyz(ifile): """readxyz(ifile) => Molecule if got errors, raise FormatError """ mol = Molecule() connects = [] line = ifile.readline() match = re.compile(r'^ *(\d+) *(.*)$').match(line) atmnum = int(match.group(1)) comment = match.group(2).strip() if comment: mol.comment = comment for i in range(atmnum): words = ifile.readline().split() atom = Atom(words[1], int(words[5])) coord = [float(x) for x in words[2:5]] mol.addatom(atom, coord) connects.append(words[6:]) for i, connect in enumerate(connects): for j in connect: mol.buildconnect(i, int(j)-1) assert atmnum == len(mol) return mol