class molecule: atoms = None bonds = None def __init__(self, filename): self.atoms = [] with open(filename, "r") as molfile: for i in range(4): line = molfile.readline() na = int(line[0:3]) for i in range(na): line = molfile.readline() x = float(line[0:10]) y = float(line[10:20]) z = float(line[20:30]) symbol = line[31:34].strip() self.atoms.append(atom(symbol,x,y,z)) def print_atoms(self): for atom in self.atoms: print(atom) class atom: symbol = "" x = 0.0 y = 0.0 z = 0.0 def __init__(self, symbol, x, y, z): self.symbol = symbol self.x = x self.y = y self.z = z def __str__(self): return("{:3s} {:.3f} {:.3f} {:.3f}".format(self.symbol, self.x, self.y, self.z)) class bond: id1 = 0 id2 = 0 bondtype = 0 m1 = molecule("caffeine.mol") m1.print_atoms()