import argparse
import sys
import os
import commands

import numpy as np

from vaspy.iter import OutCar
from vaspy.matstudio import XsdFile
from vaspy.functions import str2list

# Set arguments parser.
parser = argparse.ArgumentParser()
parser.add_argument("--xsd", help="create MaterStudio .xsd file",
                    action="store_true")
args = parser.parse_args()

outcar = OutCar()
max_num = outcar.max_force_atom
force_info = outcar.atom_forces[max_num-1, :]
pos = force_info[: 3].tolist()
forces = force_info[3:].tolist()
print "\nmax force atom: %d" % max_num
print " atom position: (%f, %f, %f)" % tuple(pos)
print "        forces: %f, %f, %f" % tuple(forces)
print "   total-force: %f\n" % np.linalg.norm(forces)

# Get fort.188 info.
if os.path.exists('./fort.188'):
    with open('fort.188', 'r') as f:
        atom_info = f.readlines()[5]
    print "%10s%10s%15s" % ('Atom1', 'Atom2', 'DISTANCE')
    print "-"*35
    print "%10s%10s%15s\n" % tuple(str2list(atom_info))

# Create .xsd file.
if args.xsd:
    status, output = commands.getstatusoutput('ls *.xsd | head -1')
    if not output.endswith('.xsd'):
        print "No .xsd file in current directory."
        sys.exit(1)
    xsd = XsdFile(filename=output)
    # modify atom color
    xsd.modify_color(atom_number=max_num)
    jobname = output.split('.')[0]
    filename = jobname + '-force.xsd'
    xsd.tofile(filename=filename)
    print filename + " has been created."

@@ -16,18 +16,23 @@
 %0Aimport 
-sy
+command
 s%0Aimport
@@ -36,18 +36,23 @@
 ort 
-os
+logging
 %0Aimport 
 comm
@@ -47,23 +47,28 @@
 %0Aimport 
-command
+os%0Aimport sy
 s%0A%0Aimpor
@@ -544,17 +544,44 @@
 t()%0A
-print %22%5Cn
+%0Alogging.info(%22%7B:%3C15s%7D: %7B%7D%22.format(%22
 max 
@@ -594,23 +594,18 @@
 atom
-: %25d%22 %25
+%22,
  max_num
 %0Apri
@@ -604,120 +604,178 @@
 _num
-%0Aprint %22 atom position: (%25f, %25f, %25f)%22 %25 tuple(
+))%0Alogging.info(%22%7B:%3C15s%7D: (%7B%7D, %7B%7D, %7B%7D)%22.format(%22atom position%22, *
 pos)
-%0Aprint %22        forces: %25f, %25f, %25f%22 %25 tuple(forces)%0Aprint %22   
+)%0Alogging.info(%22%7B:%3C15s%7D: %7B%7D, %7B%7D, %7B%7D%22.format(%22forces%22, *forces))%0Alogging.info(%22%7B:%3C15s%7D: %7B%7D%5Cn%22.format(%22
 tota
@@ -785,17 +785,10 @@
 orce
-: %25f%5Cn%22 %25
+%22,
  np.
@@ -806,16 +806,18 @@
 (forces)
+))
 %0A%0A# Get 
@@ -946,59 +946,79 @@
     
-print %22%2510s%2510s%2515s%22 %25 ('
+logging.info(%22%7B:%3C10s%7D%7B:%3C10s%7D%7B:%3C15s%7D%22.format(%22
 Atom1
-', '
+%22, %22
 Atom2
-', '
+%22, %22
 DISTANCE
 ')%0A 
@@ -1017,63 +1017,88 @@
 ANCE
-'
+%22)
 )%0A    
-print 
+logging.info(
 %22-%22*3
-5
+0)
 %0A    
-print %22%2510s%2510s%25
+logging.info(%22%7B:%3C10s%7D%7B:%3C10s%7D%7B:%3C
 15s
+%7D
 %5Cn%22
- %25 tuple(
+.format(*
 str2
@@ -1113,16 +1113,17 @@
 m_info))
+)
 %0A%0A# Crea
@@ -1261,22 +1261,29 @@
         
-print 
+logging.info(
 %22No .xsd
@@ -1310,16 +1310,17 @@
 ectory.%22
+)
 %0A       
@@ -1582,8 +1582,9 @@
 eated.%22%0A
+%0A

Use logging to output info.