# Autor: Stanislav Geidl # C2184 Uvod do programovani v Pythonu # Cviceni 08 - řešení def find_word(word): word = word.lower() word_count = 0 line_count = 0 with open("krakatit.txt") as textfile: for line in textfile: if word in line.lower(): line_count += 1 word_count += line.lower().count(word) return (line_count, word_count) print("Počet řádků: %4i Počet výskytů: %5i"%(find_word("krakatit"))) print("Počet řádků: %4i Počet výskytů: %5i"%(find_word("prokop"))) print("Počet řádků: %4i Počet výskytů: %5i"%(find_word("věc"))) """ xxxxx.xxxxyyyyy.yyyyzzzzz.zzzz aaaddcccssshhhbbbvvvHHHrrriiimmmnnneee """ def read_mol(filename): with open(filename) as molfile: molfile.readline() molfile.readline() molfile.readline() count_line = molfile.readline() atom_count = int(count_line[:3]) atoms = [] for i in range(atom_count): line = molfile.readline() atoms.append(( line[31:34], float(line[:10]), float(line[10:20]), float(line[20:30]) )) return atoms # alternativní řešení od Václava Hejreta def read_mol_alternative(filename): with open(filename) as molfile: atoms = [] for i,line in enumerate(molfile): if i == 3: atom_count = int(line[:3]) elif i > 3 and i <= 3 + atom_count: atoms.append(( line[31:34], float(line[:10]), float(line[10:20]), float(line[20:30]) )) return atoms print(read_mol("caffeine.mol")) def read_gaulog(filename): with open(filename) as logfile: energy = 0.0 charges = [] chrgblock = False for line in logfile: if line.startswith(" SCF Done"): energy = float(line.split()[4]) if "Mulliken atomic charges:" in line: chrgblock = True elif chrgblock: if "Sum" in line: # chrgblock = False # continue break data = line.split() if len(data) == 3: charges.append(float(data[2])) return (energy, charges) print(read_gaulog("NSC_1317.log"))