File: writer.py

package info (click to toggle)
python-ase 3.26.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (26 lines) | stat: -rw-r--r-- 687 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# fmt: off

"""Module containing code to manupulate control file"""
import subprocess


def add_data_group(data_group, string=None, raw=False):
    """write a turbomole data group to control file"""
    if raw:
        data = data_group
    else:
        data = '$' + data_group
        if string:
            data += ' ' + string
        data += '\n'
    with open('control', 'r+') as contr:
        lines = contr.readlines()
        contr.seek(0)
        contr.truncate()
        lines.insert(2, data)
        contr.write(''.join(lines))


def delete_data_group(data_group):
    """delete a turbomole data group from control file"""
    subprocess.run(['kdg', data_group], check=True)