GAMESS > tool > output file markdown converter : toMarkdown_170829.py (v0.3)

```txt:Environment
Xeon E5-2620 v4 (8cores) x 2
32GB RAM
CentOS 6.8 (64bit)
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
GAMESS version:20 Apr 2017(R1)
```

## About

This is related to the Quauntum Chemistry Calculation Package: GAMESS.
http://www.msg.ameslab.gov/gamess/index.html

This is a tool to convert output file of the GAMESS to those with markdown formats.

## Feature

- Convert strings to those added with Markdown header ('###')

## code 

### v0.3

```toMarkdown_170829.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import subprocess
import sys

'''
v0.3 Aug. 29, 2017
    - fix bug: "GRADIENT (HARTREE/BOHR)" in [targets]
      + to "GRADIENT (HARTREE\/BOHR)"
    - add 4 spaces to adjust markdown code description
v0.2 Aug. 29, 2017
    - set GAMESS output strings to [targets]
v0.1 Aug. 29, 2017
    - can replace sample strings (e.g., "A B C", "D E F", and "G   H I")
'''


# On Python 2.6.6

# coding rule:PEP8

# { Configuration----
# Set strings lists for GAMESS output
# Note: when the strings has "/", add "\" before the "/"
#       e.g., "GRADIENT (HARTREE\/BOHR)"
targets = ("ECHO OF THE FIRST FEW INPUT CARDS",
           "BASIS OPTIONS",
           "RUN TITLE",
           "INTERNUCLEAR DISTANCES (ANGS.)",
           "ATOMIC BASIS SET",
           "$CONTRL OPTIONS",
           "$SYSTEM OPTIONS",
           "PROPERTIES INPUT",
           "INTEGRAL TRANSFORMATION OPTIONS",
           "INTEGRAL INPUT OPTIONS",
           "THE POINT GROUP IS ",
           "STATIONARY POINT LOCATION RUN",
           "1 ELECTRON INTEGRALS",
           "GUESS OPTIONS",
           "AO INTEGRAL TECHNOLOGY",
           "2 ELECTRON INTEGRALS",
           "RHF SCF CALCULATION",
           "DENSITY CONVERGED",
           "EIGENVECTORS",
           "PROPERTY VALUES FOR THE RHF SELF-CONSISTENT FIELD WAVEFUNCTION",
           "ENERGY COMPONENTS",
           "MULLIKEN AND LOWDIN POPULATION ANALYSES",
           "BOND ORDER AND VALENCE ANALYSIS",
           "ELECTROSTATIC MOMENTS",
           "GRADIENT OF THE ENERGY",
           "GRADIENT (HARTREE\/BOHR)",
           "MOLECULAR ORBITALS",
           "CPU timing information for all processes"
           )
# } Configuration----

if len(sys.argv) < 3:
    print('ERROR: invalid runtime parameter')
    print('\ntype:')
    print('python %s [input file] [output file]' % sys.argv[0])
    sys.exit()

IN_FILE = sys.argv[1]
OUT_FILE = sys.argv[2]
WRK_FILE = 'wrk.md'

# 1. add 4 spaces
cmd = "sed 's/^/    /g' %s > %s" % (
    IN_FILE, OUT_FILE)
subprocess.call(cmd, shell=True)
IN_FILE = OUT_FILE

# 2. replace strings
for elem in targets:
    # 1. replace
    cmd = "sed 's/ *%s/###%s/g' %s > %s" % (
        elem, elem, IN_FILE, WRK_FILE)
    # print(cmd)  # for debug
    subprocess.call(cmd, shell=True)
    # 2. move
    # because (sed 's/A/B/g' in > in) will delete [in] file
    cmd = 'mv %s %s' % (WRK_FILE, OUT_FILE)
    subprocess.call(cmd, shell=True)

```

### Usage

```bash
$python toMarkdown_170829.py exam01.log exam01.md
```

Then, you obtain the "exam01.md" file.

You can paste the "exam01.md" file to any Markdown Editor/Blog Service to see the file in Markdown format.

### Example

http://qiita.com/7of9/private/eb8a931a62a9a0c757ea

### Future modifications

You can add strings in [targets]".