#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 17 18:08:47 2016

@author: tztz
"""

#f = open("ga30_10.out","r") #opens file with name of "test.txt"

#print(f.read(1))

#print(f.read())
#

#schreibt eine Datei was
with open("ga30_10.out") as infile, open("../was","w") as outfile:
    collector = []
    for line in infile:
        if line.startswith("tilt="):
            collector = []
        collector.append(line)
        if line.startswith("tilt="):
            for outline in collector:
                outfile.write(outline)
          
#noch nicht getest 
whole_data = []
grab_lines = False
with open('input','r') as atom_file:
    molecule_data = ['23\n\n']
    for line in atom_file:
        if line.startswith('coordinates'):
            grab_lines = True
            continue
        elif line.startswith('velocities'):
            grab_lines = False
            if molecule_data:
                #just checks that we aren't appending an empty list.
                molecule_data.append('\n')
                whole_data.append(molecule_data)
                molecule_data = ['23\n\n']
        if grab_lines: #in python 'is True' is implicit for many types.
            molecule_data.append(line)

with open('output','w') as out_file:
    for molecule in whole_data:
        out_file.write(''.join(molecule))